     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 08/08/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                                  ; 04/07/2016
    40                                  KEND    equ KERNELFSIZE + KLOAD
    41                                  
    42                                  
    43                                  
    44                                  ; IBM PC/AT BIOS ----- 10/06/85 (postequ.inc)
    45                                  ;--------- CMOS TABLE LOCATION ADDRESS'S -------------------------------------
    46                                  CMOS_SECONDS	EQU	00H		; SECONDS (BCD)
    47                                  CMOS_SEC_ALARM	EQU	01H		; SECONDS ALARM (BCD)
    48                                  CMOS_MINUTES	EQU	02H		; MINUTES (BCD)
    49                                  CMOS_MIN_ALARM	EQU	03H		; MINUTES ALARM (BCD) 	
    50                                  CMOS_HOURS	EQU	04H		; HOURS (BCD
    51                                  CMOS_HR_ALARM	EQU	005H		; HOURS ALARM   (BCD)
    52                                  CMOS_DAY_WEEK	EQU	06H		; DAY OF THE WEEK  (BCD)
    53                                  CMOS_DAY_MONTH	EQU	07H		; DAY OF THE MONTH (BCD) 
    54                                  CMOS_MONTH	EQU	08H		; MONTH (BCD)
    55                                  CMOS_YEAR	EQU	09H		; YEAR (TWO DIGITS) (BCD)
    56                                  CMOS_CENTURY	EQU	32H		; DATE CENTURY BYTE (BCD)
    57                                  CMOS_REG_A	EQU	0AH		; STATUS REGISTER A
    58                                  CMOS_REG_B	EQU	00BH		; STATUS REGISTER B  ALARM
    59                                  CMOS_REG_C	EQU	00CH		; STATUS REGISTER C  FLAGS
    60                                  CMOS_REG_D	EQU	0DH		; STATUS REGISTER D  BATTERY
    61                                  CMOS_SHUT_DOWN	EQU	0FH		; SHUTDOWN STATUS COMMAND BYTE
    62                                  ;----------------------------------------
    63                                  ;	CMOS EQUATES FOR THIS SYSTEM	;
    64                                  ;-----------------------------------------------------------------------------
    65                                  CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
    66                                  CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
    67                                  NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
    68                                  					; HIGH BIT OF CMOS LOCATION ADDRESS
    69                                  
    70                                  ; Memory Allocation Table Address
    71                                  ; 05/11/2014
    72                                  ; 31/10/2014
    73                                  MEM_ALLOC_TBL	equ	100000h		; Memory Allocation Table at the end of
    74                                  					; the 1st 1 MB memory space.
    75                                  					; (This address must be aligned
    76                                  					;  on 128 KB boundary, if it will be
    77                                  					;  changed later.)
    78                                  					; ((lower 17 bits of 32 bit M.A.T.
    79                                  					;   address must be ZERO)).
    80                                  					; ((((Reason: 32 bit allocation 
    81                                  					;     instructions, dword steps)))
    82                                  					; (((byte >> 12 --> page >> 5)))  
    83                                  ;04/11/2014	
    84                                  PDE_A_PRESENT	equ	1		; Present flag for PDE
    85                                  PDE_A_WRITE	equ 	2		; Writable (write permission) flag
    86                                  PDE_A_USER	equ	4		; User (non-system/kernel) page flag
    87                                  ;
    88                                  PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
    89                                  PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
    90                                  PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
    91                                  PTE_A_ACCESS    equ	32		; Accessed flag (bit 5) ; 09/03/2015
    92                                  
    93                                  ; 17/02/2015 (unix386.s)
    94                                  ; 10/12/2014 - 30/12/2014 (0B000h -> 9000h) (dsectrm2.s)
    95                                  DPT_SEGM equ 09000h  ; FDPT segment (EDD v1.1, EDD v3)
    96                                  ;
    97                                  HD0_DPT	 equ 0	    ; Disk parameter table address for hd0
    98                                  HD1_DPT	 equ 32	    ; Disk parameter table address for hd1
    99                                  HD2_DPT	 equ 64	    ; Disk parameter table address for hd2
   100                                  HD3_DPT	 equ 96	    ; Disk parameter table address for hd3
   101                                  
   102                                  
   103                                  ; FDPT (Phoenix, Enhanced Disk Drive Specification v1.1, v3.0)
   104                                  ;      (HDPT: Programmer's Guide to the AMIBIOS, 1993)
   105                                  ;
   106                                  FDPT_CYLS	equ 0 ; 1 word, number of cylinders
   107                                  FDPT_HDS	equ 2 ; 1 byte, number of heads
   108                                  FDPT_TT		equ 3 ; 1 byte, A0h = translated FDPT with logical values
   109                                  		      ; otherwise it is standard FDPT with physical values 	
   110                                  FDPT_PCMP	equ 5 ; 1 word, starting write precompensation cylinder
   111                                  		      ; (obsolete for IDE/ATA drives)
   112                                  FDPT_CB		equ 8 ; 1 byte, drive control byte
   113                                  			; Bits 7-6 : Enable or disable retries (00h = enable)
   114                                  			; Bit 5	: 1 = Defect map is located at last cyl. + 1
   115                                  			; Bit 4 : Reserved. Always 0
   116                                  			; Bit 3 : Set to 1 if more than 8 heads
   117                                  			; Bit 2-0 : Reserved. Alsways 0
   118                                  FDPT_LZ		equ 12 ; 1 word, landing zone (obsolete for IDE/ATA drives)
   119                                  FDPT_SPT	equ 14 ; 1 byte, sectors per track
   120                                  
   121                                  ; Floppy Drive Parameters Table (Programmer's Guide to the AMIBIOS, 1993)
   122                                  ; (11 bytes long) will be used by diskette handler/bios
   123                                  ; which is derived from IBM PC-AT BIOS (DISKETTE.ASM, 21/04/1986).
   124                                  
   125                                  ; 01/02/2016
   126                                  Logical_DOSDisks equ 90000h + 100h ; 26*256 = 6656 bytes
   127                                  Directory_Buffer equ 80000h ; max = 64K Bytes
   128                                  FAT_Buffer	 equ 91C00h ; 1536 bytes (3 sectors)
   129                                  ; 15/02/2016
   130                                  Cluster_Buffer	 equ 70000h ; max = 64K Bytes ; buffer for file read & write
   131                                  ; 11/04/2016
   132                                  Env_Page:	 equ 93000h ; 512 bytes (4096 bytes)
   133                                  Env_Page_Size	 equ 512    ; (4096 bytes)
   134                                  ; 30/07/2016
   135                                  Video_Pg_Backup	 equ 98000h ; Mode 3h, video page backup (32K, 8 pages)				 	  		 	  
   136                                  
   137                                  [BITS 16]       ; We need 16-bit intructions for Real mode
   138                                  
   139                                  [ORG 0] 
   140                                  	; 12/11/2014
   141                                  	; Save boot drive number (that is default root drive)
   142 00000000 8816[14ED]              	mov	[boot_drv], dl ; physical drv number
   143                                  
   144                                  	; Determine installed memory
   145                                  	; 31/10/2014
   146                                  	;
   147 00000004 B801E8                  	mov	ax, 0E801h ; Get memory size 
   148 00000007 CD15                    	int	15h	   ; for large configurations
   149 00000009 7308                    	jnc	short chk_ms
   150 0000000B B488                    	mov	ah, 88h    ; Get extended memory size 
   151 0000000D CD15                    	int	15h
   152                                  	;	   
   153                                  	;mov	al, 17h	; Extended memory (1K blocks) low byte
   154                                  	;out	70h, al ; select CMOS register
   155                                  	;in	al, 71h ; read data (1 byte)
   156                                  	;mov	cl, al
   157                                  	;mov	al, 18h ; Extended memory (1K blocks) high byte
   158                                  	;out	70h, al ; select CMOS register
   159                                  	;in	al, 71h ; read data (1 byte)
   160                                  	;mov	ch, al
   161                                   	;      
   162 0000000F 89C1                    	mov	cx, ax
   163 00000011 31D2                    	xor	dx, dx
   164                                  chk_ms:
   165 00000013 890E[EEEE]              	mov	[mem_1m_1k], cx
   166 00000017 8916[F0EE]              	mov	[mem_16m_64k], dx
   167                                  	; 05/11/2014
   168                                  	;and	dx, dx
   169                                  	;jz	short L2
   170 0000001B 81F90004                        cmp     cx, 1024
   171 0000001F 7315                    	jnb	short L0
   172                                  		 ; insufficient memory_error	
   173                                  		 ; Minimum 2 MB memory is needed... 
   174                                  	; 05/11/2014
   175                                  	; (real mode error printing)
   176 00000021 FB                      	sti
   177 00000022 BE[B7ED]                	mov	si, msg_out_of_memory
   178 00000025 BB0700                  	mov	bx, 7
   179 00000028 B40E                    	mov	ah, 0Eh	; write tty
   180                                  oom_1:
   181 0000002A AC                      	lodsb
   182 0000002B 08C0                    	or	al, al
   183 0000002D 7404                    	jz	short oom_2
   184 0000002F CD10                    	int	10h
   185 00000031 EBF7                    	jmp	short oom_1
   186                                  oom_2:
   187 00000033 F4                              hlt
   188 00000034 EBFD                    	jmp	short oom_2
   189                                  
   190                                  L0:
   191                                  %include 'diskinit.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskinit.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 09/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; diskinit.inc (10/07/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - DISKINIT.INC
    20                              <1> ; Last Modification: 10/07/2015
    21                              <1> 
    22                              <1> ; DISK I/O SYSTEM INITIALIZATION - Erdogan Tan (Retro UNIX 386 v1 project)
    23                              <1> 
    24                              <1> ; ///////// DISK I/O SYSTEM STRUCTURE INITIALIZATION ///////////////
    25                              <1> 
    26                              <1> 	; 10/12/2014 - 02/02/2015 - dsectrm2.s
    27                              <1> ;L0:
    28                              <1> 	; 12/11/2014 (Retro UNIX 386 v1 - beginning)
    29                              <1> 	; Detecting disk drives... (by help of ROM-BIOS)
    30 00000036 BA7F00              <1> 	mov	dx, 7Fh
    31                              <1> L1:	
    32 00000039 FEC2                <1> 	inc	dl
    33 0000003B B441                <1> 	mov	ah, 41h ; Check extensions present
    34                              <1> 			; Phoenix EDD v1.1 - EDD v3
    35 0000003D BBAA55              <1> 	mov	bx, 55AAh
    36 00000040 CD13                <1> 	int 	13h
    37 00000042 721A                <1> 	jc	short L2
    38                              <1> 
    39 00000044 81FB55AA            <1> 	cmp	bx, 0AA55h
    40 00000048 7514                <1> 	jne	short L2
    41 0000004A FE06[17ED]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
    42 0000004E 8816[16ED]          <1>         mov     [last_drv], dl  ; last hard disk number
    43 00000052 BB[9AEC]            <1> 	mov	bx, hd0_type - 80h
    44 00000055 01D3                <1> 	add	bx, dx	 
    45 00000057 880F                <1> 	mov	[bx], cl ; Interface support bit map in CX
    46                              <1> 			 ; Bit 0 - 1, Fixed disk access subset ready
    47                              <1> 			 ; Bit 1 - 1, Drv locking and ejecting ready
    48                              <1> 			 ; Bit 2 - 1, Enhanced Disk Drive Support
    49                              <1>                          ;            (EDD) ready (DPTE ready)
    50                              <1> 			 ; Bit 3 - 1, 64bit extensions are present
    51                              <1>                          ;            (EDD-3)
    52                              <1> 			 ; Bit 4 to 15 - 0, Reserved
    53 00000059 80FA83              <1> 	cmp	dl, 83h	 ; drive number < 83h
    54 0000005C 72DB                <1> 	jb	short L1
    55                              <1> L2:
    56                              <1> 	; 23/11/2014
    57                              <1> 	; 19/11/2014
    58 0000005E 30D2                <1> 	xor	dl, dl  ; 0
    59                              <1> 	; 04/02/2016 (esi -> si)
    60 00000060 BE[18ED]            <1> 	mov	si, fd0_type
    61                              <1> L3:
    62                              <1> 	; 14/01/2015
    63 00000063 8816[15ED]          <1> 	mov	[drv], dl
    64                              <1> 	;
    65 00000067 B408                <1> 	mov 	ah, 08h ; Return drive parameters
    66 00000069 CD13                <1> 	int	13h	
    67 0000006B 7210                <1> 	jc	short L4
    68                              <1> 		; BL = drive type (for floppy drives)
    69                              <1> 		; DL = number of floppy drives
    70                              <1> 		;		
    71                              <1> 		; ES:DI = Address of DPT from BIOS
    72                              <1> 		;
    73 0000006D 881C                <1> 	mov	[si], bl ;  Drive type
    74                              <1> 			; 4 = 1.44 MB, 80 track, 3 1/2"
    75                              <1> 	; 14/01/2015
    76 0000006F E8BC01              <1> 	call	set_disk_parms
    77                              <1> 	; 10/12/2014
    78 00000072 81FE[18ED]          <1> 	cmp	si, fd0_type
    79 00000076 7705                <1> 	ja	short L4
    80 00000078 46                  <1> 	inc	si ; fd1_type
    81 00000079 B201                <1> 	mov	dl, 1
    82 0000007B EBE6                <1> 	jmp	short L3
    83                              <1> L4:
    84                              <1> 	; Older BIOS (INT 13h, AH = 48h is not available)
    85 0000007D B27F                <1> 	mov	dl, 7Fh
    86                              <1> 	; 24/12/2014 (Temporary)
    87 0000007F 803E[17ED]00        <1> 	cmp	byte [hdc], 0 ; EDD present or not ?	
    88 00000084 0F879000            <1>         ja      L10       ; yes, all fixed disk operations
    89                              <1> 			  ; will be performed according to
    90                              <1> 			  ; present EDD specification
    91                              <1> L6:
    92 00000088 FEC2                <1> 	inc 	dl
    93 0000008A 8816[15ED]          <1>         mov     [drv], dl
    94 0000008E 8816[16ED]          <1>         mov     [last_drv], dl ; 14/01/2015
    95 00000092 B408                <1> 	mov 	ah, 08h ; Return drive parameters
    96 00000094 CD13                <1> 	int	13h	; (conventional function)
    97 00000096 0F828601            <1>         jc      L13	; fixed disk drive not ready
    98 0000009A 8816[17ED]          <1>         mov     [hdc], dl ; number of drives
    99                              <1> 	;; 14/01/2013
   100                              <1> 	;;push	cx
   101 0000009E E88D01              <1> 	call	set_disk_parms
   102                              <1> 	;;pop	cx
   103                              <1> 	;
   104                              <1> 	;;and	cl, 3Fh	 ; sectors per track (bits 0-6)
   105 000000A1 8A16[15ED]          <1>         mov     dl, [drv]
   106 000000A5 BB0401              <1> 	mov	bx, 65*4 ; hd0 parameters table (INT 41h)	
   107 000000A8 80FA80              <1> 	cmp	dl, 80h
   108 000000AB 7603                <1> 	jna	short L7
   109 000000AD 83C314              <1> 	add	bx, 5*4	 ; hd1 parameters table (INT 46h)
   110                              <1> L7:	
   111 000000B0 31C0                <1> 	xor	ax, ax
   112 000000B2 8ED8                <1> 	mov	ds, ax
   113 000000B4 8B37                <1>         mov     si, [bx]
   114 000000B6 8B4702              <1>         mov     ax, [bx+2] 
   115 000000B9 8ED8                <1> 	mov	ds, ax
   116 000000BB 3A4C0E              <1>         cmp     cl, [si+FDPT_SPT] ; sectors per track 
   117 000000BE 0F855A01            <1>         jne     L12 ; invalid FDPT
   118 000000C2 BF0000              <1> 	mov	di, HD0_DPT
   119 000000C5 80FA80              <1> 	cmp	dl, 80h
   120 000000C8 7603                <1> 	jna	short L8
   121 000000CA BF2000              <1> 	mov	di, HD1_DPT 
   122                              <1> L8:
   123                              <1> 	; 30/12/2014
   124 000000CD B80090              <1> 	mov	ax, DPT_SEGM
   125 000000D0 8EC0                <1> 	mov	es, ax
   126                              <1> 	; 24/12/2014
   127 000000D2 B90800              <1> 	mov	cx, 8
   128 000000D5 F3A5                <1> 	rep	movsw  ; copy 16 bytes to the kernel's DPT location
   129 000000D7 8CC8                <1> 	mov	ax, cs
   130 000000D9 8ED8                <1> 	mov	ds, ax
   131                              <1> 	; 02/02/2015
   132 000000DB 8A0E[15ED]          <1>         mov     cl, [drv]
   133 000000DF 88CB                <1> 	mov	bl, cl
   134 000000E1 B8F001              <1> 	mov	ax, 1F0h
   135 000000E4 80E301              <1> 	and	bl, 1
   136 000000E7 7406                <1> 	jz	short L9
   137 000000E9 C0E304              <1> 	shl	bl, 4
   138 000000EC 2D8000              <1> 	sub	ax, 1F0h-170h
   139                              <1> L9:
   140 000000EF AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   141 000000F0 050602              <1> 	add	ax, 206h
   142 000000F3 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   143 000000F4 88D8                <1> 	mov	al, bl
   144 000000F6 04A0                <1> 	add	al, 0A0h
   145 000000F8 AA                  <1> 	stosb	; Device/Head Register upper nibble
   146                              <1> 	;
   147 000000F9 FE06[15ED]          <1> 	inc	byte [drv]
   148 000000FD BB[9AEC]            <1> 	mov	bx, hd0_type - 80h
   149 00000100 01CB                <1> 	add	bx, cx
   150 00000102 800F80              <1>         or      byte [bx], 80h  ; present sign (when lower nibble is 0)
   151 00000105 A0[17ED]            <1> 	mov	al, [hdc]
   152 00000108 FEC8                <1> 	dec	al
   153 0000010A 0F841201            <1>         jz      L13
   154 0000010E 80FA80              <1> 	cmp	dl, 80h
   155 00000111 0F8673FF            <1>         jna     L6
   156 00000115 E90801              <1>         jmp     L13
   157                              <1> L10:
   158 00000118 FEC2                <1> 	inc 	dl
   159                              <1> 	; 25/12/2014
   160 0000011A 8816[15ED]          <1> 	mov	[drv], dl
   161 0000011E B408                <1> 	mov 	ah, 08h ; Return drive parameters
   162 00000120 CD13                <1> 	int	13h	; (conventional function)
   163 00000122 0F82FA00            <1>         jc      L13
   164                              <1> 	; 14/01/2015
   165 00000126 8A16[15ED]          <1> 	mov	dl, [drv]
   166 0000012A 52                  <1> 	push	dx
   167 0000012B 51                  <1> 	push	cx
   168 0000012C E8FF00              <1> 	call	set_disk_parms
   169 0000012F 59                  <1> 	pop	cx
   170 00000130 5A                  <1> 	pop	dx
   171                              <1> 	; 06/07/2016 (BugFix for >64K kernel files)
   172                              <1> 	; 04/02/2016 (esi -> si)
   173                              <1> 	;mov	si, _end ; 30 byte temporary buffer address 	
   174                              <1> 	;		 ; at the '_end' of kernel.
   175                              <1> 	;mov	word [si], 30
   176                              <1> 	; 06/07/2016
   177 00000131 BE[D1ED]            <1> 	mov	si, _int13h_48h_buffer
   178                              <1> 	; 09/07/2016
   179 00000134 B81E00              <1> 	mov	ax, 001Eh
   180 00000137 8824                <1> 	mov	[si], ah ; 0
   181 00000139 46                  <1> 	inc	si
   182 0000013A 8904                <1> 	mov	word [si], ax
   183                              <1>  	; word [si] = 30
   184                              <1> 	;
   185 0000013C B448                <1> 	mov	ah, 48h	 ; Get drive parameters (EDD function)
   186 0000013E CD13                <1> 	int	13h
   187 00000140 0F82DC00            <1>         jc      L13
   188                              <1> 	; 04/02/2016 (ebx -> bx)
   189                              <1> 	; 14/01/2015
   190 00000144 28FF                <1> 	sub	bh, bh
   191 00000146 88D3                <1> 	mov	bl, dl
   192 00000148 80EB80              <1> 	sub	bl, 80h
   193 0000014B 81C3[1AED]          <1> 	add	bx, hd0_type
   194 0000014F 8A07                <1> 	mov 	al, [bx]
   195 00000151 0C80                <1> 	or	al, 80h
   196 00000153 8807                <1> 	mov 	[bx], al	
   197 00000155 81EB[18ED]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   198 00000159 81C3[64ED]          <1> 	add	bx, drv.status
   199 0000015D 8807                <1> 	mov	[bx], al
   200                              <1> 	; 04/02/2016 (eax -> ax)
   201 0000015F 8B4410              <1> 	mov	ax, [si+16]
   202 00000162 854412              <1> 	test	ax, [si+18]
   203 00000165 7412                <1> 	jz	short L10_A0h 
   204                              <1> 			; 'CHS only' disks on EDD system 
   205                              <1> 			;  are reported with ZERO disk size
   206 00000167 81EB[64ED]          <1> 	sub	bx, drv.status
   207 0000016B C1E302              <1> 	shl	bx, 2
   208 0000016E 81C3[48ED]          <1> 	add	bx, drv.size ; disk size (in sectors)
   209 00000172 8907                <1> 	mov	[bx], ax
   210 00000174 8B4412              <1> 	mov	ax, [si+18]
   211 00000177 8907                <1> 	mov	[bx], ax
   212                              <1> 
   213                              <1> L10_A0h: ; Jump here to fix a ZERO (LBA) disk size problem 
   214                              <1> 	 ; for CHS disks (28/02/2015)
   215                              <1> 	; 30/12/2014
   216 00000179 BF0000              <1> 	mov	di, HD0_DPT
   217 0000017C 88D0                <1> 	mov	al, dl
   218 0000017E 83E003              <1> 	and 	ax, 3
   219 00000181 C0E005              <1> 	shl	al, 5 ; *32
   220 00000184 01C7                <1> 	add 	di, ax
   221 00000186 B80090              <1> 	mov	ax, DPT_SEGM
   222 00000189 8EC0                <1> 	mov	es, ax
   223                              <1> 	;
   224 0000018B 88E8                <1> 	mov	al, ch	; max. cylinder number (bits 0-7)
   225 0000018D 88CC                <1> 	mov	ah, cl	
   226 0000018F C0EC06              <1> 	shr	ah, 6	; max. cylinder number (bits 8-9)
   227 00000192 40                  <1>  	inc	ax	; logical cylinders (limit 1024)
   228 00000193 AB                  <1> 	stosw		
   229 00000194 88F0                <1> 	mov	al, dh	; max. head number
   230 00000196 FEC0                <1> 	inc	al
   231 00000198 AA                  <1> 	stosb		; logical heads (limits 256)
   232 00000199 B0A0                <1> 	mov	al, 0A0h ; Indicates translated table
   233 0000019B AA                  <1> 	stosb
   234 0000019C 8A440C              <1> 	mov	al, [si+12]
   235 0000019F AA                  <1> 	stosb		 ; physical sectors per track
   236 000001A0 31C0                <1>  	xor	ax, ax
   237                              <1> 	;dec	ax	 ; 02/01/2015 
   238 000001A2 AB                  <1> 	stosw		 ; precompensation (obsolete)
   239                              <1> 	;xor	al, al	 ; 02/01/2015	
   240 000001A3 AA                  <1> 	stosb		 ; reserved
   241 000001A4 B008                <1> 	mov	al, 8	 ; drive control byte
   242                              <1> 		         ; (do not disable retries, 
   243                              <1> 			 ; more than 8 heads)
   244 000001A6 AA                  <1> 	stosb
   245 000001A7 8B4404              <1> 	mov	ax, [si+4]
   246 000001AA AB                  <1> 	stosw		 ; physical number of cylinders	
   247                              <1> 	;push	ax	 ; 02/01/2015
   248 000001AB 8A4408              <1> 	mov	al, [si+8]
   249 000001AE AA                  <1> 	stosb		 ; physical num. of heads (limit 16)
   250 000001AF 29C0                <1> 	sub 	ax, ax
   251                              <1> 	;pop	ax	 ; 02/01/2015	
   252 000001B1 AB                  <1> 	stosw		 ; landing zone (obsolete)
   253 000001B2 88C8                <1> 	mov	al, cl	 ; logical sectors per track (limit 63)
   254 000001B4 243F                <1> 	and 	al, 3Fh	
   255 000001B6 AA                  <1> 	stosb
   256                              <1> 	;sub	al, al	 ; checksum
   257                              <1> 	;stosb
   258                              <1> 	;
   259 000001B7 83C61A              <1> 	add	si, 26   ; (BIOS) DPTE address pointer
   260 000001BA AD                  <1> 	lodsw
   261 000001BB 50                  <1> 	push	ax	 ; (BIOS) DPTE offset
   262 000001BC AD                  <1> 	lodsw
   263 000001BD 50                  <1> 	push	ax	 ; (BIOS) DPTE segment
   264                              <1> 	;
   265                              <1> 	; checksum calculation
   266 000001BE 89FE                <1> 	mov	si, di
   267 000001C0 06                  <1> 	push	es
   268 000001C1 1F                  <1> 	pop	ds
   269                              <1> 	;mov	cx, 16
   270 000001C2 B90F00              <1> 	mov 	cx, 15
   271 000001C5 29CE                <1> 	sub	si, cx
   272 000001C7 30E4                <1> 	xor	ah, ah
   273                              <1> 	;del	cl
   274                              <1> L11:		
   275 000001C9 AC                  <1> 	lodsb
   276 000001CA 00C4                <1> 	add	ah, al
   277 000001CC E2FB                <1> 	loop	L11
   278                              <1> 	;
   279 000001CE 88E0                <1> 	mov	al, ah
   280 000001D0 F6D8                <1> 	neg	al	; -x+x = 0
   281 000001D2 AA                  <1> 	stosb		; put checksum in byte 15 of the tbl
   282                              <1> 	;
   283 000001D3 1F                  <1> 	pop	ds	; (BIOS) DPTE segment
   284 000001D4 5E                  <1> 	pop	si	; (BIOS) DPTE offset	
   285                              <1> 	;
   286                              <1> 	; 23/02/2015
   287 000001D5 57                  <1> 	push	di
   288                              <1> 	; ES:DI points to DPTE (FDPTE) location
   289                              <1> 	;mov	cx, 8
   290 000001D6 B108                <1> 	mov	cl, 8
   291 000001D8 F3A5                <1> 	rep	movsw	
   292                              <1> 	;
   293                              <1> 	; 23/02/2015
   294                              <1> 	; (P)ATA drive and LBA validation
   295                              <1> 	; (invalidating SATA drives and setting
   296                              <1> 	; CHS type I/O for old type fixed disks)
   297 000001DA 5B                  <1> 	pop	bx
   298 000001DB 8CC8                <1> 	mov	ax, cs
   299 000001DD 8ED8                <1> 	mov	ds, ax
   300 000001DF 268B07              <1> 	mov	ax, [es:bx]
   301 000001E2 3DF001              <1> 	cmp	ax, 1F0h
   302 000001E5 7418                <1> 	je	short L11a
   303 000001E7 3D7001              <1> 	cmp	ax, 170h
   304 000001EA 7413                <1> 	je	short L11a
   305                              <1> 	; invalidation 
   306                              <1> 	; (because base port address is not 1F0h or 170h)
   307 000001EC 30FF                <1> 	xor	bh, bh
   308 000001EE 88D3                <1> 	mov	bl, dl
   309 000001F0 80EB80              <1> 	sub	bl, 80h
   310 000001F3 C687[1AED]00        <1> 	mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   311 000001F8 808F[66ED]F0        <1>         or      byte [bx+drv.status+2], 0F0h ; (failure sign)
   312 000001FD EB14                <1> 	jmp	short L11b
   313                              <1> L11a:	
   314                              <1> 	; LBA validation
   315 000001FF 268A4704            <1> 	mov	al, [es:bx+4] ; Head register upper nibble
   316 00000203 A840                <1> 	test	al, 40h ; LBA bit (bit 6)
   317 00000205 750C                <1> 	jnz	short L11b ; LBA type I/O is OK! (E0h or F0h)
   318                              <1> 	; force CHS type I/O for this drive (A0h or B0h)
   319 00000207 28FF                <1> 	sub	bh, bh
   320 00000209 88D3                <1> 	mov	bl, dl
   321 0000020B 80EB80              <1> 	sub	bl, 80h ; 26/02/2015
   322 0000020E 80A7[66ED]FE        <1>         and     byte [bx+drv.status+2], 0FEh ; clear bit 0
   323                              <1> 				; bit 0 = LBA ready bit
   324                              <1> 	; 'diskio' procedure will check this bit !
   325                              <1> L11b:
   326 00000213 3A16[16ED]          <1> 	cmp	dl, [last_drv] ; 25/12/2014
   327 00000217 7307                <1>         jnb     short L13
   328 00000219 E9FCFE              <1>         jmp     L10
   329                              <1> L12:
   330                              <1> 	; Restore data registers
   331 0000021C 8CC8                <1> 	mov	ax, cs
   332 0000021E 8ED8                <1> 	mov	ds, ax	
   333                              <1> L13:
   334                              <1> 	; 13/12/2014
   335 00000220 0E                  <1> 	push	cs
   336 00000221 07                  <1> 	pop	es
   337                              <1> L14:
   338 00000222 B411                <1> 	mov 	ah, 11h
   339 00000224 CD16                <1> 	int 	16h
   340 00000226 7466                <1> 	jz 	short L16 ; no keys in keyboard buffer
   341 00000228 B010                <1> 	mov	al, 10h
   342 0000022A CD16                <1> 	int 	16h
   343 0000022C EBF4                <1> 	jmp 	short L14
   344                              <1> 
   345                              <1> set_disk_parms:
   346                              <1> 	; 04/02/2016 (ebx -> bx)
   347                              <1> 	; 10/07/2015
   348                              <1> 	; 14/01/2015
   349                              <1> 	;push	bx
   350 0000022E 28FF                <1> 	sub	bh, bh
   351 00000230 8A1E[15ED]          <1> 	mov	bl, [drv]
   352 00000234 80FB80              <1> 	cmp	bl, 80h
   353 00000237 7203                <1> 	jb	short sdp0
   354 00000239 80EB7E              <1> 	sub	bl, 7Eh
   355                              <1> sdp0:	
   356 0000023C 81C3[64ED]          <1> 	add	bx, drv.status
   357 00000240 C60780              <1>   	mov	byte [bx], 80h ; 'Present' flag
   358                              <1> 	;
   359 00000243 88E8                <1> 	mov	al, ch ; last cylinder (bits 0-7)
   360 00000245 88CC                <1> 	mov	ah, cl ; 
   361 00000247 C0EC06              <1> 	shr	ah, 6  ; last cylinder (bits 8-9)
   362 0000024A 81EB[64ED]          <1> 	sub	bx, drv.status
   363 0000024E D0E3                <1> 	shl	bl, 1
   364 00000250 81C3[1EED]          <1> 	add	bx, drv.cylinders
   365 00000254 40                  <1> 	inc	ax  ; convert max. cyl number to cyl count		
   366 00000255 8907                <1> 	mov	[bx], ax
   367 00000257 50                  <1> 	push	ax ; ** cylinders
   368 00000258 81EB[1EED]          <1> 	sub	bx, drv.cylinders
   369 0000025C 81C3[2CED]          <1> 	add	bx, drv.heads
   370 00000260 30E4                <1> 	xor	ah, ah
   371 00000262 88F0                <1> 	mov	al, dh ; heads
   372 00000264 40                  <1> 	inc	ax
   373 00000265 8907                <1> 	mov	[bx], ax
   374 00000267 81EB[2CED]          <1>         sub     bx, drv.heads
   375 0000026B 81C3[3AED]          <1>         add     bx, drv.spt
   376 0000026F 30ED                <1> 	xor	ch, ch
   377 00000271 80E13F              <1> 	and	cl, 3Fh	; sectors (bits 0-6)
   378 00000274 890F                <1> 	mov	[bx], cx
   379 00000276 81EB[3AED]          <1>         sub     bx, drv.spt
   380 0000027A D1E3                <1> 	shl	bx, 1
   381 0000027C 81C3[48ED]          <1> 	add	bx, drv.size ; disk size (in sectors)
   382                              <1> 	; LBA size = cylinders * heads * secpertrack
   383 00000280 F7E1                <1> 	mul	cx 
   384 00000282 89C2                <1> 	mov	dx, ax	; heads*spt					
   385 00000284 58                  <1> 	pop	ax ; ** cylinders
   386 00000285 48                  <1> 	dec	ax ; 1 cylinder reserved (!?)
   387 00000286 F7E2                <1> 	mul	dx ; cylinders * (heads*spt)		
   388 00000288 8907                <1> 	mov	[bx], ax
   389 0000028A 895702              <1> 	mov	[bx+2], dx
   390                              <1> 	;
   391                              <1> 	;pop	bx
   392 0000028D C3                  <1> 	retn
   393                              <1> 
   394                              <1> L16:	; 28/05/2016
   192                                  
   193                                  	; 10/11/2014
   194 0000028E FA                           	cli	; Disable interrupts (clear interrupt flag)
   195                                  		; Reset Interrupt MASK Registers (Master&Slave)
   196                                  	;mov	al, 0FFh	; mask off all interrupts
   197                                  	;out	21h, al		; on master PIC (8259)
   198                                  	;jmp 	$+2  ; (delay)
   199                                  	;out	0A1h, al	; on slave PIC (8259)
   200                                  	;
   201                                  	; Disable NMI 
   202 0000028F B080                    	mov   	al, 80h 
   203 00000291 E670                    	out   	70h, al		; set bit 7 to 1 for disabling NMI
   204                                  	;23/02/2015
   205                                  	;nop			;
   206                                  	;in	al, 71h		; read in 71h just after writing out to 70h
   207                                  				; for preventing unknown state (!?)
   208                                  	;
   209                                   	; 20/08/2014
   210                                  	; Moving the kernel 64 KB back (to physical address 0)
   211                                  	; DS = CS = 1000h
   212                                  	; 05/11/2014
   213 00000293 31C0                    	xor	ax, ax
   214 00000295 8EC0                    	mov	es, ax ; ES = 0
   215                                  	;
   216                                  	; 04/07/2016 -  TRDOS 386 (64K - 128K kernel)
   217 00000297 31F6                          	xor	si, si
   218 00000299 31FF                    	xor	di, di
   219 0000029B B90040                  	mov	cx, 16384
   220 0000029E F366A5                  	rep	movsd
   221                                  	;
   222 000002A1 06                      	push	es ; 0
   223 000002A2 68[A602]                	push	L17
   224 000002A5 CB                      	retf
   225                                  L17:
   226 000002A6 B90010                  	mov	cx, 1000h
   227 000002A9 8EC1                    	mov	es, cx  ; 1000h 
   228 000002AB 01C9                    	add	cx, cx
   229 000002AD 8ED9                    	mov	ds, cx  ; 2000h
   230 000002AF 29F6                    	sub	si, si
   231 000002B1 29FF                    	sub	di, di
   232 000002B3 B90040                  	mov	cx, 16384
   233 000002B6 F366A5                  	rep	movsd
   234                                  	
   235                                  	; Turn off the floppy drive motor
   236 000002B9 BAF203                          mov     dx, 3F2h
   237 000002BC EE                              out     dx, al ; 0 ; 31/12/2013
   238                                  
   239                                  	; Enable access to memory above one megabyte
   240                                  L18:
   241 000002BD E464                    	in	al, 64h
   242 000002BF A802                    	test	al, 2
   243 000002C1 75FA                            jnz     short L18
   244 000002C3 B0D1                    	mov	al, 0D1h	; Write output port
   245 000002C5 E664                    	out	64h, al
   246                                  L19:
   247 000002C7 E464                    	in	al, 64h
   248 000002C9 A802                    	test	al, 2
   249 000002CB 75FA                            jnz     short L19
   250 000002CD B0DF                    	mov	al, 0DFh	; Enable A20 line
   251 000002CF E660                    	out	60h, al
   252                                  ;L20:
   253                                  	;
   254                                  	; Load global descriptor table register
   255                                  
   256                                          ;mov     ax, cs
   257                                          ;mov     ds, ax
   258                                  
   259 000002D1 2E0F0116[80E6]                  lgdt    [cs:gdtd]
   260                                  
   261 000002D7 0F20C0                          mov     eax, cr0
   262                                  	; or 	eax, 1
   263 000002DA 40                      	inc     ax
   264 000002DB 0F22C0                  	mov     cr0, eax
   265                                  
   266                                  	; Jump to 32 bit code
   267                                  	
   268 000002DE 66                      	db 66h 			; Prefix for 32-bit
   269 000002DF EA                      	db 0EAh 		; Opcode for far jump
   270 000002E0 [E6020000]              	dd StartPM 		; Offset to start, 32-bit
   271                                  				; (1000h:StartPM = StartPM + 10000h)
   272 000002E4 0800                    	dw KCODE		; This is the selector for CODE32_DESCRIPTOR,
   273                                  				; assuming that StartPM resides in code32
   274                                  
   275                                  [BITS 32] 
   276                                  
   277                                  StartPM:
   278                                  	; Kernel Base Address = 0 ; 30/12/2013
   279 000002E6 66B81000                	mov ax, KDATA           ; Save data segment identifier
   280 000002EA 8ED8                            mov ds, ax              ; Move a valid data segment into DS register
   281 000002EC 8EC0                           	mov es, ax              ; Move data segment into ES register
   282 000002EE 8EE0                           	mov fs, ax              ; Move data segment into FS register
   283 000002F0 8EE8                          	mov gs, ax              ; Move data segment into GS register
   284 000002F2 8ED0                            mov ss, ax              ; Move data segment into SS register
   285 000002F4 BC00000900                      mov esp, 90000h         ; Move the stack pointer to 090000h
   286                                  
   287                                  clear_bss: ; Clear uninitialized data area
   288                                  	; 11/03/2015
   289 000002F9 31C0                    	xor  eax, eax ; 0
   290 000002FB B96C080000              	mov  ecx, (bss_end - bss_start)/4
   291                                  	;shr  ecx, 2 ; bss section is already aligned for double words
   292 00000300 BF[E01C0100]            	mov  edi, bss_start	
   293 00000305 F3AB                    	rep  stosd  		
   294                                  
   295                                  memory_init:
   296                                  	; Initialize memory allocation table and page tables
   297                                  	; 16/11/2014
   298                                  	; 15/11/2014
   299                                  	; 07/11/2014
   300                                  	; 06/11/2014
   301                                  	; 05/11/2014
   302                                  	; 04/11/2014
   303                                  	; 31/10/2014 (Retro UNIX 386 v1 - Beginning) 
   304                                  	;
   305                                  ;	xor	eax, eax
   306                                  ;	xor 	ecx, ecx
   307 00000307 B108                    	mov	cl, 8
   308 00000309 BF00001000              	mov	edi, MEM_ALLOC_TBL	
   309 0000030E F3AB                    	rep	stosd		   ; clear Memory Allocation Table
   310                                  				   ; for the first 1 MB memory
   311                                  	;
   312 00000310 668B0D[EEEE0000]        	mov	cx, [mem_1m_1k]	   ; Number of contiguous KB between
   313                                  				   ; 1 and 16 MB, max. 3C00h = 15 MB.
   314 00000317 66C1E902                	shr	cx, 2		   ; convert 1 KB count to 4 KB count
   315 0000031B 890D[D01F0100]          	mov	[free_pages], ecx
   316 00000321 668B15[F0EE0000]        	mov	dx, [mem_16m_64k]  ; Number of contiguous 64 KB blocks
   317                                  				   ; between 16 MB and 4 GB.	
   318 00000328 6609D2                  	or	dx, dx
   319 0000032B 7413                    	jz	short mi_0
   320                                  	;
   321 0000032D 6689D0                  	mov	ax, dx
   322 00000330 C1E004                  	shl	eax, 4		   ; 64 KB -> 4 KB (page count)
   323 00000333 0105[D01F0100]          	add	[free_pages], eax
   324 00000339 0500100000              	add	eax, 4096	   ; 16 MB = 4096 pages
   325 0000033E EB07                    	jmp	short mi_1
   326                                  mi_0:
   327 00000340 6689C8                  	mov	ax, cx
   328 00000343 66050001                	add	ax, 256		   ; add 256 pages for the first 1 MB		 
   329                                  mi_1:
   330 00000347 A3[CC1F0100]            	mov	[memory_size], eax ; Total available memory in pages
   331                                  				   ; 1 alloc. tbl. bit = 1 memory page
   332                                  				   ; 32 allocation bits = 32 mem. pages   
   333                                  	;
   334 0000034C 05FF7F0000              	add	eax, 32767	   ; 32768 memory pages per 1 M.A.T. page 	
   335 00000351 C1E80F                  	shr	eax, 15		   ; ((32768 * x) + y) pages (y < 32768)
   336                                  				   ;  --> x + 1 M.A.T. pages, if y > 0
   337                                  				   ;  --> x M.A.T. pages, if y = 0
   338 00000354 66A3[E01F0100]          	mov	[mat_size], ax	   ; Memory Alloc. Table Size in pages		
   339 0000035A C1E00C                  	shl	eax, 12		   ; 1 M.A.T. page = 4096 bytes
   340                                  	;			   ; Max. 32 M.A.T. pages (4 GB memory)
   341 0000035D 89C3                    	mov	ebx, eax	   ; M.A.T. size in bytes
   342                                  	; Set/Calculate Kernel's Page Directory Address
   343 0000035F 81C300001000            	add	ebx, MEM_ALLOC_TBL
   344 00000365 891D[C81F0100]          	mov	[k_page_dir], ebx  ; Kernel's Page Directory address
   345                                  				   ; just after the last M.A.T. page
   346                                  	;
   347 0000036B 83E804                  	sub	eax, 4		   ; convert M.A.T. size to offset value
   348 0000036E A3[D81F0100]            	mov	[last_page], eax   ; last page ofset in the M.A.T.
   349                                  	;			   ; (allocation status search must be 
   350                                  				   ; stopped after here)	
   351 00000373 31C0                    	xor	eax, eax
   352 00000375 48                      	dec	eax		   ; FFFFFFFFh (set all bits to 1)	
   353 00000376 6651                    	push	cx
   354 00000378 C1E905                  	shr	ecx, 5		   ; convert 1 - 16 MB page count to 
   355                                  				   ; count of 32 allocation bits
   356 0000037B F3AB                    	rep	stosd
   357 0000037D 6659                    	pop	cx
   358 0000037F 40                      	inc	eax		   ; 0	
   359 00000380 80E11F                  	and	cl, 31		   ; remain bits
   360 00000383 7412                    	jz	short mi_4
   361 00000385 8907                    	mov	[edi], eax	   ; reset	
   362                                  mi_2:
   363 00000387 0FAB07                  	bts	[edi], eax	   ; 06/11/2014		
   364 0000038A FEC9                    	dec	cl
   365 0000038C 7404                    	jz	short mi_3
   366 0000038E FEC0                    	inc	al
   367 00000390 EBF5                    	jmp	short mi_2
   368                                  mi_3:
   369 00000392 28C0                    	sub	al, al	   	   ; 0
   370 00000394 83C704                  	add	edi, 4		   ; 15/11/2014
   371                                  mi_4:
   372 00000397 6609D2                  	or	dx, dx		  ; check 16M to 4G memory space	
   373 0000039A 7421                    	jz	short mi_6	  ; max. 16 MB memory, no more...
   374                                  	;	
   375 0000039C B900021000              	mov	ecx, MEM_ALLOC_TBL + 512 ; End of first 16 MB memory
   376                                  	;	
   377 000003A1 29F9                    	sub	ecx, edi	  ; displacement (to end of 16 MB)
   378 000003A3 7406                    	jz	short mi_5	  ; jump if EDI points to 
   379                                  				  ;         end of first 16 MB	
   380 000003A5 D1E9                    	shr	ecx, 1		  ; convert to dword count
   381 000003A7 D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   382 000003A9 F3AB                    	rep 	stosd		  ; reset all bits for reserved pages
   383                                  				  ; (memory hole under 16 MB)
   384                                  mi_5:
   385 000003AB 6689D1                  	mov	cx, dx		  ; count of 64 KB memory blocks
   386 000003AE D1E9                    	shr	ecx, 1		  ; 1 alloc. dword per 128 KB memory
   387 000003B0 9C                      	pushf			  ; 16/11/2014		
   388 000003B1 48                      	dec	eax		  ; FFFFFFFFh (set all bits to 1)
   389 000003B2 F3AB                    	rep	stosd
   390 000003B4 40                      	inc	eax		  ; 0
   391 000003B5 9D                      	popf			  ; 16/11/2014
   392 000003B6 7305                    	jnc	short mi_6
   393 000003B8 6648                    	dec	ax		  ; eax = 0000FFFFh
   394 000003BA AB                      	stosd
   395 000003BB 6640                    	inc	ax		  ; 0		
   396                                  mi_6:
   397 000003BD 39DF                    	cmp	edi, ebx	  ; check if EDI points to 	
   398 000003BF 730A                    	jnb	short mi_7	  ; end of memory allocation table
   399                                  	;			  ; (>= MEM_ALLOC_TBL + 4906) 
   400 000003C1 89D9                    	mov	ecx, ebx	  ; end of memory allocation table
   401 000003C3 29F9                    	sub	ecx, edi	  ; convert displacement/offset
   402 000003C5 D1E9                    	shr	ecx, 1		  ; to dword count 	 		
   403 000003C7 D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   404 000003C9 F3AB                    	rep 	stosd		  ; reset all remain M.A.T. bits
   405                                  mi_7:
   406                                  	; Reset M.A.T. bits in M.A.T. (allocate M.A.T. pages)
   407 000003CB BA00001000              	mov	edx, MEM_ALLOC_TBL
   408                                  	;sub	ebx, edx	  ; Mem. Alloc. Tbl. size in bytes
   409                                  	;shr	ebx, 12		  ; Mem. Alloc. Tbl. size in pages	
   410 000003D0 668B0D[E01F0100]        	mov	cx, [mat_size]	  ; Mem. Alloc. Tbl. size in pages
   411 000003D7 89D7                    	mov	edi, edx
   412 000003D9 C1EF0F                  	shr	edi, 15		  ; convert M.A.T. address to
   413                                  				  ; byte offset in M.A.T.
   414                                  				  ; (1 M.A.T. byte points to 
   415                                  				  ;	      32768 bytes)
   416                                  				  ; Note: MEM_ALLOC_TBL address 
   417                                  				  ; must be aligned on 128 KB 
   418                                  				  ; boundary!
   419 000003DC 01D7                    	add	edi, edx	  ; points to M.A.T.'s itself	
   420                                  	; eax = 0
   421 000003DE 290D[D01F0100]          	sub	[free_pages], ecx ; 07/11/2014
   422                                  mi_8:
   423 000003E4 0FB307                  	btr	[edi], eax	  ; clear bit 0 to bit x (1 to 31)
   424                                  	;dec	bl
   425 000003E7 FEC9                    	dec	cl
   426 000003E9 7404                    	jz	short mi_9
   427 000003EB FEC0                    	inc	al
   428 000003ED EBF5                    	jmp	short mi_8
   429                                  mi_9:
   430                                  	;
   431                                  	; Reset Kernel's Page Dir. and Page Table bits in M.A.T.
   432                                  	;		(allocate pages for system page tables)
   433                                  
   434                                  	; edx = MEM_ALLOC_TBL
   435 000003EF 8B0D[CC1F0100]          	mov	ecx, [memory_size] ; memory size in pages (PTEs)
   436 000003F5 81C1FF030000            	add	ecx, 1023	 ; round up (1024 PTEs per table)	 	
   437 000003FB C1E90A                  	shr	ecx, 10		 ; convert memory page count to 
   438                                  				 ; page table count (PDE count)
   439                                  	;
   440 000003FE 51                      	push	ecx		 ; (**) PDE count (<= 1024)
   441                                  	;
   442 000003FF 41                      	inc	ecx		 ; +1 for kernel page directory	
   443                                  	;
   444 00000400 290D[D01F0100]          	sub	[free_pages], ecx ; 07/11/2014
   445                                  	;
   446 00000406 8B35[C81F0100]          	mov	esi, [k_page_dir] ; Kernel's Page Directory address
   447 0000040C C1EE0C                  	shr	esi, 12		 ; convert to page number
   448                                  mi_10:
   449 0000040F 89F0                    	mov	eax, esi	 ; allocation bit offset		 
   450 00000411 89C3                    	mov	ebx, eax
   451 00000413 C1EB03                  	shr	ebx, 3		 ; convert to alloc. byte offset
   452 00000416 80E3FC                  	and	bl,  0FCh	 ; clear bit 0 and bit 1
   453                                  				 ;   to align on dword boundary
   454 00000419 83E01F                  	and	eax, 31		 ; set allocation bit position 
   455                                  				 ;  (bit 0 to bit 31)
   456                                  	;
   457 0000041C 01D3                    	add	ebx, edx	 ; offset in M.A.T. + M.A.T. address 
   458                                  	;
   459 0000041E 0FB303                  	btr 	[ebx], eax	 ; reset relevant bit (0 to 31)
   460                                  	;
   461 00000421 46                      	inc	esi		 ; next page table
   462 00000422 E2EB                    	loop	mi_10		 ; allocate next kernel page table 
   463                                  				 ; (ecx = page table count + 1)		
   464                                  	;
   465 00000424 59                      	pop	ecx		 ; (**) PDE count (= pg. tbl. count)
   466                                  	;
   467                                  	; Initialize Kernel Page Directory and Kernel Page Tables
   468                                  	;
   469                                  	; Initialize Kernel's Page Directory
   470 00000425 8B3D[C81F0100]          	mov	edi, [k_page_dir]
   471 0000042B 89F8                    	mov	eax, edi
   472 0000042D 0C03                    	or	al, PDE_A_PRESENT + PDE_A_WRITE
   473                                  		     	      ; supervisor + read&write + present
   474 0000042F 89CA                    	mov	edx, ecx 	; (**) PDE count (= pg. tbl. count)	
   475                                  mi_11:
   476 00000431 0500100000              	add	eax, 4096	; Add page size (PGSZ)
   477                                  			        ; EAX points to next page table
   478 00000436 AB                      	stosd
   479 00000437 E2F8                    	loop	mi_11
   480 00000439 29C0                    	sub	eax, eax	; Empty PDE
   481 0000043B 66B90004                	mov	cx, 1024	; Entry count (PGSZ/4)
   482 0000043F 29D1                    	sub	ecx, edx
   483 00000441 7402                    	jz	short mi_12
   484 00000443 F3AB                    	rep	stosd 		; clear remain (empty) PDEs
   485                                  	;
   486                                  	; Initialization of Kernel's Page Directory is OK, here.
   487                                  mi_12:
   488                                  	; Initialize Kernel's Page Tables
   489                                  	;
   490                                  	; (EDI points to address of page table 0)
   491                                  	; eax = 0
   492 00000445 8B0D[CC1F0100]          	mov	ecx, [memory_size] ; memory size in pages
   493 0000044B 89CA                    	mov	edx, ecx	; (***)
   494 0000044D B003                    	mov	al, PTE_A_PRESENT + PTE_A_WRITE
   495                                  			     ; supervisor + read&write + present 	
   496                                  mi_13:
   497 0000044F AB                      	stosd
   498 00000450 0500100000              	add	eax, 4096	
   499 00000455 E2F8                    	loop	mi_13	
   500 00000457 6681E2FF03              	and	dx, 1023	; (***)
   501 0000045C 740B                    	jz	short mi_14
   502 0000045E 66B90004                	mov	cx, 1024	
   503 00000462 6629D1                  	sub	cx, dx		; from dx (<= 1023) to 1024
   504 00000465 31C0                    	xor	eax, eax
   505 00000467 F3AB                    	rep	stosd		; clear remain (empty) PTEs 
   506                                  				; of the last page table
   507                                  mi_14:
   508                                  	;  Initialization of Kernel's Page Tables is OK, here.
   509                                  	;
   510 00000469 89F8                    	mov	eax, edi	; end of the last page table page
   511                                  			        ; (beginging of user space pages)
   512 0000046B C1E80F                  	shr	eax, 15		; convert to M.A.T. byte offset
   513 0000046E 24FC                    	and	al, 0FCh	; clear bit 0 and bit 1 for
   514                                  				; aligning on dword boundary	
   515                                  	 
   516 00000470 A3[DC1F0100]            	mov	[first_page], eax
   517 00000475 A3[D41F0100]            	mov	[next_page], eax ; The first free page pointer
   518                                  				 ; for user programs
   519                                  				 ; (Offset in Mem. Alloc. Tbl.)	
   520                                  	;
   521                                  	; Linear/FLAT (1 to 1) memory paging for the kernel is OK, here.
   522                                  	;
   523                                  	
   524                                  	; Enable paging
   525                                  	;
   526 0000047A A1[C81F0100]                    mov     eax, [k_page_dir]
   527 0000047F 0F22D8                  	mov	cr3, eax
   528 00000482 0F20C0                  	mov	eax, cr0
   529 00000485 0D00000080              	or	eax, 80000000h	; set paging bit (bit 31)
   530 0000048A 0F22C0                  	mov	cr0, eax
   531                                          ;jmp    KCODE:StartPMP
   532                                  
   533 0000048D EA                      	db 0EAh 		; Opcode for far jump
   534 0000048E [94040000]                      dd StartPMP		; 32 bit offset
   535 00000492 0800                    	dw KCODE		; kernel code segment descriptor
   536                                  
   537                                  
   538                                  StartPMP:
   539                                  	; 06/11//2014
   540                                  	; Clear video page 0
   541                                  	;
   542                                  	; Temporary Code
   543                                  	;
   544 00000494 B9E8030000              	mov	ecx, 80*25/2
   545 00000499 BF00800B00              	mov	edi, 0B8000h
   546                                  	; 30/01/2016
   547                                  	;xor	eax, eax	; black background, black fore color
   548 0000049E B800070007              	mov	eax, 07000700h  ; black background, light gray fore color
   549 000004A3 F3AB                    	rep	stosd
   550                                  	
   551                                  	; 19/08/2014
   552                                  	; Kernel Base Address = 0
   553                                  	; It is mapped to (physically) 0 in the page table.
   554                                  	; So, here is exactly 'StartPMP' address.
   555                                  
   556                                   	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
   557 000004A5 BE[F2EE0000]            	mov	esi, starting_msg
   558                                  	;; 14/08/2015 (kernel version message will appear
   559                                  	;;	       when protected mode and paging is enabled)
   560 000004AA BF00800B00              	mov	edi, 0B8000h ; 27/08/2014
   561 000004AF B40A                    	mov	ah, 0Ah ; Black background, light green forecolor
   562                                  	; 20/08/2014
   563 000004B1 E880010000              	call	printk
   564                                  
   565                                  	; 'UNIX v7/x86' source code by Robert Nordier (1999)
   566                                  	; // Set IRQ offsets
   567                                  	;
   568                                  	;  Linux (v0.12) source code by Linus Torvalds (1991)
   569                                  	;
   570                                  					;; ICW1
   571 000004B6 B011                    	mov	al, 11h			; Initialization sequence
   572 000004B8 E620                    	out	20h, al			; 	8259A-1
   573                                  	; jmp 	$+2
   574 000004BA E6A0                    	out	0A0h, al		; 	8259A-2
   575                                  					;; ICW2
   576 000004BC B020                    	mov	al, 20h			; Start of hardware ints (20h)
   577 000004BE E621                    	out	21h, al			;	for 8259A-1
   578                                  	; jmp 	$+2
   579 000004C0 B028                    	mov	al, 28h			; Start of hardware ints (28h)
   580 000004C2 E6A1                    	out	0A1h, al		; 	for 8259A-2
   581                                  					;
   582 000004C4 B004                    	mov	al, 04h			;; ICW3
   583 000004C6 E621                    	out	21h, al			; 	IRQ2 of 8259A-1 (master)
   584                                  	; jmp 	$+2
   585 000004C8 B002                    	mov	al, 02h			; 	is 8259A-2 (slave)
   586 000004CA E6A1                    	out	0A1h, al		;
   587                                  					;; ICW4
   588 000004CC B001                    	mov	al, 01h	 		;
   589 000004CE E621                    	out	21h, al			; 	8086 mode, normal EOI	
   590                                  	; jmp 	$+2
   591 000004D0 E6A1                    	out	0A1h, al		;	for both chips.
   592                                  
   593                                  	;mov	al, 0FFh	; mask off all interrupts for now
   594                                  	;out	21h, al
   595                                  	;; jmp 	$+2
   596                                  	;out	0A1h, al
   597                                  
   598                                  	; 02/04/2015
   599                                  	; 26/03/2015 System call (INT 30h) modification
   600                                  	;  DPL = 3 (Interrupt service routine can be called from user mode)			
   601                                  	;
   602                                  	;; Linux (v0.12) source code by Linus Torvalds (1991)
   603                                  	;  setup_idt:
   604                                  	;
   605                                          ;; 16/02/2015
   606                                  	;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
   607                                  	; 21/08/2014 (timer_int)
   608 000004D2 BE[8CE60000]            	mov	esi, ilist
   609 000004D7 8D3D[E01C0100]          	lea	edi, [idt]
   610                                  	; 26/03/2015
   611 000004DD B930000000              	mov	ecx, 48		; 48 hardware interrupts (INT 0 to INT 2Fh)
   612                                  	; 02/04/2015
   613 000004E2 BB00000800              	mov	ebx,  80000h
   614                                  rp_sidt1:
   615 000004E7 AD                      	lodsd
   616 000004E8 89C2                    	mov	edx, eax
   617 000004EA 66BA008E                	mov	dx, 8E00h
   618 000004EE 6689C3                  	mov	bx, ax
   619 000004F1 89D8                    	mov	eax, ebx	; /* selector = 0x0008 = cs */
   620                                         			        ; /* interrupt gate - dpl=0, present */
   621 000004F3 AB                      	stosd	; selector & offset bits 0-15 	
   622 000004F4 89D0                    	mov	eax, edx
   623 000004F6 AB                      	stosd	; attributes & offset bits 16-23
   624 000004F7 E2EE                    	loop	rp_sidt1
   625                                  	; 15/04/2016
   626                                  	; TRDOS 386 (TRDOS v2.0) /// 32 sofware interrupts ///
   627                                  	;mov	cl, 16        ; 16 software interrupts (INT 30h to INT 3Fh)
   628 000004F9 B120                    	mov	cl, 32	      ;  16 software interrupts (INT 30h to INT 4Fh)	
   629                                  rp_sidt2:
   630 000004FB AD                      	lodsd
   631 000004FC 21C0                    	and	eax, eax
   632 000004FE 7413                    	jz	short rp_sidt3
   633 00000500 89C2                    	mov	edx, eax
   634 00000502 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   635 00000506 6689C3                  	mov	bx, ax
   636 00000509 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   637 0000050B AB                      	stosd
   638 0000050C 89D0                    	mov	eax, edx
   639 0000050E AB                      	stosd
   640 0000050F E2EA                    	loop	rp_sidt2
   641 00000511 EB16                    	jmp	short sidt_OK
   642                                  rp_sidt3:
   643 00000513 B8[A1090000]            	mov	eax, ignore_int
   644 00000518 89C2                    	mov	edx, eax
   645 0000051A 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   646 0000051E 6689C3                  	mov	bx, ax
   647 00000521 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   648                                  rp_sidt4:
   649 00000523 AB                      	stosd
   650 00000524 92                      	xchg	eax, edx
   651 00000525 AB                      	stosd
   652 00000526 92                      	xchg	edx, eax
   653 00000527 E2FA                    	loop	rp_sidt4
   654                                  sidt_OK: 
   655 00000529 0F011D[86E60000]        	lidt 	[idtd]
   656                                  	;
   657                                  	; TSS descriptor setup ; 24/03/2015
   658 00000530 B8[601F0100]            	mov	eax, task_state_segment
   659 00000535 66A3[7AE60000]          	mov	[gdt_tss0], ax
   660 0000053B C1C010                  	rol	eax, 16
   661 0000053E A2[7CE60000]            	mov	[gdt_tss1], al
   662 00000543 8825[7FE60000]          	mov	[gdt_tss2], ah
   663 00000549 66C705[C61F0100]68-     	mov	word [tss.IOPB], tss_end - task_state_segment
   663 00000551 00                 
   664                                  		; 
   665                                  		; IO Map Base address (When this address points
   666                                  		; to end of the TSS, CPU does not use IO port 
   667                                  		; permission bit map for RING 3 IO permissions, 
   668                                  		; access to any IO ports in ring 3 will be forbidden.)
   669                                   		;
   670                                  	;mov	[tss.esp0], esp ; TSS offset 4
   671                                  	;mov	word [tss.ss0], KDATA ; TSS offset 8 (SS)
   672 00000552 66B82800                   	mov	ax, TSS  ; It is needed when an interrupt 
   673                                  			 ; occurs (or a system call -software INT- is requested)
   674                                  			 ; while cpu running in ring 3 (in user mode).				
   675                                  			 ; (Kernel stack pointer and segment will be loaded
   676                                  			 ; from offset 4 and 8 of the TSS, by the CPU.)	 
   677 00000556 0F00D8                  	ltr	ax  ; Load task register
   678                                  	;
   679                                  esp0_set0:
   680                                  	; 30/07/2015
   681 00000559 8B0D[CC1F0100]          	mov 	ecx, [memory_size] ; memory size in pages
   682 0000055F C1E10C                  	shl 	ecx, 12 ; convert page count to byte count
   683 00000562 81F900004000            	cmp	ecx, CORE ; beginning of user's memory space (400000h)
   684                                  			  ; (kernel mode virtual address)
   685 00000568 7605                    	jna	short esp0_set1
   686                                  	;
   687                                  	; If available memory > CORE (end of the 1st 4 MB)
   688                                  	; set stack pointer to CORE
   689                                  	;(Because, PDE 0 is reserved for kernel space in user's page directory)
   690                                  	;(PDE 0 points to page table of the 1st 4 MB virtual address space)
   691 0000056A B900004000              	mov	ecx, CORE
   692                                  esp0_set1:
   693 0000056F 89CC                    	mov	esp, ecx ; top of kernel stack (**tss.esp0**)
   694                                  esp0_set_ok:
   695                                  	; 30/07/2015 (**tss.esp0**) 
   696 00000571 8925[641F0100]          	mov	[tss.esp0], esp
   697 00000577 66C705[681F0100]10-             mov     word [tss.ss0], KDATA
   697 0000057F 00                 
   698                                  	; 14/08/2015
   699                                  	; 10/11/2014 (Retro UNIX 386 v1 - Erdogan Tan)
   700                                  	;
   701                                  	;cli	; Disable interrupts (for CPU)
   702                                  	;    (CPU will not handle hardware interrupts, except NMI!)
   703                                  	;
   704 00000580 30C0                    	xor	al, al		; Enable all hardware interrupts!
   705 00000582 E621                    	out	21h, al		; (IBM PC-AT compatibility)
   706 00000584 EB00                    	jmp 	$+2		; (All conventional PC-AT hardware
   707 00000586 E6A1                    	out	0A1h, al	;  interrupts will be in use.)	
   708                                  				; (Even if related hardware component
   709                                  				;  does not exist!)
   710                                  	; Enable NMI 
   711 00000588 B07F                    	mov	al, 7Fh		; Clear bit 7 to enable NMI (again)
   712 0000058A E670                    	out  	70h, al
   713                                  	; 23/02/2015
   714 0000058C 90                      	nop
   715 0000058D E471                    	in	al, 71h		; read in 71h just after writing out to 70h
   716                                  				; for preventing unknown state (!?)
   717                                  	;
   718                                  	; Only a NMI can occur here... (Before a 'STI' instruction)
   719                                  	;
   720                                  	; 02/09/2014
   721 0000058F 6631DB                  	xor	bx, bx
   722 00000592 66BA0002                	mov	dx, 0200h	; Row 2, column 0  ; 07/03/2015
   723 00000596 E81C160000              	call	_set_cpos	; 24/01/2016
   724                                  	;
   725                                  	; 06/11/2014
   726 0000059B E823270000              	call	memory_info
   727                                  	; 14/08/2015
   728                                  	;call getch ; 28/02/2015
   729                                  drv_init:
   730 000005A0 FB                      	sti	; Enable Interrupts 
   731                                  	; 06/02/2015
   732 000005A1 8B15[1AED0000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
   733 000005A7 668B1D[18ED0000]        	mov	bx, [fd0_type] ; fd0, fd1
   734                                  	; 22/02/2015
   735 000005AE 6621DB                  	and	bx, bx
   736 000005B1 751C                    	jnz	short di1
   737                                  	;
   738 000005B3 09D2                    	or 	edx, edx
   739 000005B5 752A                    	jnz	short di2
   740                                  	;
   741                                  setup_error:
   742 000005B7 BE[F3ED0000]            	mov 	esi, setup_error_msg
   743                                  psem:	
   744 000005BC AC                      	lodsb
   745 000005BD 08C0                    	or	al, al
   746                                  	;jz	short haltx ; 22/02/2015
   747 000005BF 7427                    	jz	short di3
   748 000005C1 56                      	push	esi
   749                                  	; 13/05/2016
   750 000005C2 BB07000000              	mov	ebx, 7	; Black background, 
   751                                  			; light gray forecolor
   752                                  			; Video page 0 (BH=0)
   753 000005C7 E855150000              	call	_write_tty
   754 000005CC 5E                      	pop	esi
   755 000005CD EBED                    	jmp	short psem
   756                                  
   757                                  di1:
   758                                  	; supress 'jmp short T6'
   759                                  	;  (activate fdc motor control code)
   760 000005CF 66C705[B7060000]90-     	mov	word [T5], 9090h ; nop
   760 000005D7 90                 
   761                                  	;
   762                                  	;mov	ax, int_0Eh	; IRQ 6 handler
   763                                  	;mov	di, 0Eh*4	; IRQ 6 vector
   764                                  	;stosw
   765                                  	;mov 	ax, cs
   766                                  	;stosw
   767                                  	;; 16/02/2015
   768                                          ;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
   769                                  	;
   770 000005D8 E85A360000              	CALL	DSKETTE_SETUP	; Initialize Floppy Disks
   771                                  	;
   772 000005DD 09D2                    	or	edx, edx
   773 000005DF 7407                            jz      short di3
   774                                  di2:
   775 000005E1 E898360000              	call   	DISK_SETUP	; Initialize Fixed Disks
   776 000005E6 72CF                            jc      short setup_error
   777                                  di3:
   778 000005E8 E8AA260000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
   779                                  	;
   780 000005ED E8B4DF0000              	call	display_disks ; 07/03/2015  (Temporary)
   781                                  ;haltx:
   782                                  	; 14/08/2015
   783                                  	;call	getch ; 22/02/2015
   784                                  	;sti	; Enable interrupts (for CPU)
   785                                  ;	; 29/01/2016
   786                                  ;	sub	ah, ah ;  read time count
   787                                  ;	call	int1Ah
   788                                  ;	mov	edx, ecx ; 18.2 * seconds
   789                                  ;md_info_msg_wait1:
   790                                  ;	; 29/01/2016
   791                                  ;	mov	ah, 1
   792                                  ;	call	int16h
   793                                  ;	jz	short md_info_msg_wait2
   794                                  ;	xor	ah, ah ; 0
   795                                  ;       call    int16h
   796                                  ;	jmp 	short md_info_msg_ok
   797                                  ;md_info_msg_wait2:
   798                                  ;	sub	ah, ah  ; read time count
   799                                  ;	call	int1Ah
   800                                  ;	cmp	edx, ecx ; ; 18.2 * seconds
   801                                  ;	jna	short md_info_msg_wait3
   802                                  ;	xchg 	edx, ecx	
   803                                  ;md_info_msg_wait3:
   804                                  ;	sub	ecx, edx
   805                                  ;	cmp	ecx, 127 ; 7 seconds (18.2 * 7)
   806                                  ;	jb	short md_info_msg_wait1		
   807                                  ;md_info_msg_ok:
   808                                  	; 30/06/2015
   809 000005F2 E8584E0000              	call	sys_init
   810                                  	;
   811                                  	;jmp 	cpu_reset ; 22/02/2015
   812                                  hang:  
   813                                  	; 23/02/2015
   814                                  	;sti			; Enable interrupts
   815 000005F7 F4                      	hlt
   816                                  	;
   817                                  	;nop
   818                                  	;; 03/12/2014
   819                                  	;; 28/08/2014
   820                                  	;mov	ah, 11h
   821                                  	;call	getc
   822                                  	;jz      _c8
   823                                  	;
   824                                  	; 23/02/2015
   825                                  	; 06/02/2015
   826                                  	; 07/09/2014
   827 000005F8 31DB                    	xor	ebx, ebx
   828 000005FA 8A1D[F61F0100]          	mov	bl, [ptty]	; active_page
   829 00000600 89DE                    	mov	esi, ebx
   830 00000602 66D1E6                  	shl 	si, 1
   831 00000605 81C6[F81F0100]          	add	esi, ttychr
   832 0000060B 668B06                  	mov	ax, [esi]
   833 0000060E 6621C0                  	and	ax, ax
   834                                  	;jz	short _c8
   835 00000611 74E4                    	jz	short hang
   836 00000613 66C7060000              	mov	word [esi], 0
   837 00000618 80FB03                  	cmp	bl, 3		; Video page 3
   838                                  	;jb	short _c8
   839 0000061B 72DA                    	jb	short hang
   840                                  	;	
   841                                  	; 13/05/2016
   842                                  	; 07/09/2014
   843                                  nxtl:
   844 0000061D 6653                    	push	bx
   845 0000061F 66BB0E00                	mov	bx, 0Eh 	; Yellow character 
   846                                  				; on black background
   847                                  				; bh = 0 (video page 0)
   848                                  				; Retro UNIX 386 v1 - Video Mode 0
   849                                  				; (PC/AT Video Mode 3 - 80x25 Alpha.)
   850 00000623 6650                    	push	ax
   851 00000625 E8F7140000              	call 	_write_tty
   852 0000062A 6658                    	pop	ax
   853 0000062C 665B                    	pop	bx
   854 0000062E 3C0D                    	cmp	al, 0Dh		; carriage return (enter)
   855                                  	;jne	short _c8
   856 00000630 75C5                    	jne	short hang
   857 00000632 B00A                    	mov	al, 0Ah		; next line
   858 00000634 EBE7                    	jmp	short nxtl
   859                                  	
   860                                  ;_c8:
   861                                  ;	; 25/08/2014
   862                                  ;	cli				; Disable interrupts
   863                                  ;	mov	al, [scounter + 1]
   864                                  ;	and	al, al
   865                                  ;	jnz	hang
   866                                  ;	call	rtc_p
   867                                  ;	jmp     hang
   868                                  
   869                                  
   870                                  	; 27/08/2014
   871                                  	; 20/08/2014
   872                                  printk:
   873                                          ;mov    edi, [scr_row]
   874                                  pkl:
   875 00000636 AC                      	lodsb
   876 00000637 08C0                    	or 	al, al
   877 00000639 7404                    	jz	short pkr
   878 0000063B 66AB                    	stosw
   879 0000063D EBF7                    	jmp	short pkl
   880                                  pkr:
   881 0000063F C3                      	retn
   882                                  
   883                                  ; 06/06/2016
   884                                  ; 23/05/2016
   885                                  ; 22/05/2016 - TRDOS 386 (TRDOS v2.0) Timer Event Modifications
   886                                  ; 25/07/2015
   887                                  ; 14/05/2015 (multi tasking -time sharing- 'clock', x_timer)
   888                                  ; 17/02/2015
   889                                  ; 06/02/2015 (unix386.s)
   890                                  ; 11/12/2014 - 22/12/2014 (dsectrm2.s) 
   891                                  ;
   892                                  ; IBM PC-XT Model 286 Source Code - BIOS2.ASM (06/10/85)
   893                                  ;
   894                                  ;-- HARDWARE INT  08 H - ( IRQ LEVEL 0 ) ---------------------------------------
   895                                  ;	THIS ROUTINE HANDLES THE TIMER INTERRUPT FROM FROM CHANNEL 0 OF        :
   896                                  ;	THE 8254 TIMER.  INPUT FREQUENCY IS 1.19318 MHZ AND THE DIVISOR        :
   897                                  ;	IS 65536, RESULTING IN APPROXIMATELY 18.2 INTERRUPTS EVERY SECOND.     :
   898                                  ;									       :
   899                                  ;	THE INTERRUPT HANDLER MAINTAINS A COUNT (40:6C) OF INTERRUPTS SINCE    :
   900                                  ;	POWER ON TIME, WHICH MAY BE USED TO ESTABLISH TIME OF DAY.	       :
   901                                  ;	THE INTERRUPT HANDLER ALSO DECREMENTS THE MOTOR CONTROL COUNT (40:40)  :
   902                                  ;	OF THE DISKETTE, AND WHEN IT EXPIRES, WILL TURN OFF THE 	       :
   903                                  ;	DISKETTE MOTOR(s), AND RESET THE MOTOR RUNNING FLAGS.		       :
   904                                  ;	THE INTERRUPT HANDLER WILL ALSO INVOKE A USER ROUTINE THROUGH	       :
   905                                  ;	INTERRUPT 1CH AT EVERY TIME TICK.  THE USER MUST CODE A 	       :
   906                                  ;	ROUTINE AND PLACE THE CORRECT ADDRESS IN THE VECTOR TABLE.	       :
   907                                  ;-------------------------------------------------------------------------------
   908                                  ;
   909                                  
   910                                  timer_int:	; IRQ 0
   911                                  ;int_08h:	; Timer
   912                                  	; 14/10/2015
   913                                  	; Here, we are simulating system call entry (for task switch)
   914                                  	; (If multitasking is enabled, 
   915                                  	; 'clock' procedure may jump to 'sysrelease')
   916 00000640 1E                      	push	ds
   917 00000641 06                      	push	es
   918 00000642 0FA0                    	push	fs
   919 00000644 0FA8                    	push	gs
   920 00000646 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
   921 00000647 66B91000                	mov     cx, KDATA
   922 0000064B 8ED9                            mov     ds, cx
   923 0000064D 8EC1                            mov     es, cx
   924 0000064F 8EE1                            mov     fs, cx
   925 00000651 8EE9                            mov     gs, cx
   926                                  	;
   927 00000653 0F20D9                  	mov	ecx, cr3
   928 00000656 890D[683D0100]          	mov	[cr3reg], ecx ; save current cr3 register value/content
   929                                  	;
   930 0000065C 3B0D[C81F0100]          	cmp 	ecx, [k_page_dir]
   931 00000662 7420                    	je	short T3
   932                                  	;
   933                                  	; timer interrupt has been occurred while OS is in user mode
   934 00000664 FC                      	cld	; 06/06/2016
   935 00000665 A3[A8300100]            	mov 	[u.r0], eax
   936 0000066A 89E1                    	mov	ecx, esp
   937 0000066C 83C130                  	add	ecx, ESPACE ; 4 * 12 (stack frame)	
   938 0000066F 890D[A0300100]          	mov	[u.sp], ecx ; kernel stack pointer at the start of interrupt
   939 00000675 8925[A4300100]          	mov	[u.usp], esp ; kernel stack points to user's registers   
   940                                  	;
   941 0000067B 8B0D[C81F0100]          	mov	ecx, [k_page_dir]
   942 00000681 0F22D9                  	mov	cr3, ecx
   943                                  T3:
   944                                  	;sti				; INTERRUPTS BACK ON
   945 00000684 66FF05[48200100]        	INC	word [TIMER_LOW]	; INCREMENT TIME
   946 0000068B 7507                    	JNZ	short T4		; GO TO TEST_DAY
   947 0000068D 66FF05[4A200100]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
   948                                  T4:					; TEST_DAY
   949 00000694 66833D[4A200100]18      	CMP	word [TIMER_HIGH],018H	; TEST FOR COUNT EQUALING 24 HOURS
   950 0000069C 7519                    	JNZ	short T5		; GO TO DISKETTE_CTL
   951 0000069E 66813D[48200100]B0-     	CMP	word [TIMER_LOW],0B0H
   951 000006A6 00                 
   952 000006A7 750E                    	JNZ	short T5		; GO TO DISKETTE_CTL
   953                                  
   954                                  ;-----	TIMER HAS GONE 24 HOURS
   955                                  	;;SUB	AX,AX
   956                                  	;MOV	[TIMER_HIGH],AX
   957                                  	;MOV	[TIMER_LOW],AX
   958 000006A9 29C0                    	sub	eax, eax
   959 000006AB A3[48200100]            	mov	[TIMER_LH], eax
   960                                  	;	
   961 000006B0 C605[4C200100]01        	MOV	byte [TIMER_OFL],1
   962                                  
   963                                  ;-----	TEST FOR DISKETTE TIME OUT
   964                                  
   965                                  T5:
   966                                  	; 23/12/2014
   967 000006B7 EB1D                    	jmp	short T6		; will be replaced with nop, nop
   968                                  					; (9090h) if a floppy disk
   969                                  					; is detected.
   970                                  	;mov	al,[CS:MOTOR_COUNT]
   971 000006B9 A0[4F200100]            	mov	al, [MOTOR_COUNT]
   972 000006BE FEC8                    	dec	al
   973                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
   974 000006C0 A2[4F200100]            	mov	[MOTOR_COUNT], al
   975                                  	;mov	[ORG_MOTOR_COUNT], al
   976 000006C5 750F                    	JNZ	short T6		; RETURN IF COUNT NOT OUT
   977 000006C7 B0F0                    	mov 	al,0F0h
   978                                  	;AND	[CS:MOTOR_STATUS],al 	; TURN OFF MOTOR RUNNING BITS
   979 000006C9 2005[4E200100]          	and	[MOTOR_STATUS], al
   980                                  	;and	[ORG_MOTOR_STATUS], al
   981 000006CF B00C                    	MOV	AL,0CH			; bit 3 = enable IRQ & DMA, 
   982                                  					; bit 2 = enable controller
   983                                  					;	1 = normal operation
   984                                  					;	0 = reset	
   985                                  					; bit 0, 1 = drive select
   986                                  					; bit 4-7 = motor running bits 
   987 000006D1 66BAF203                	MOV	DX,03F2H		; FDC CTL PORT
   988 000006D5 EE                      	OUT	DX,AL			; TURN OFF THE MOTOR
   989                                  T6:	
   990                                  	;inc	word [CS:wait_count]	; 22/12/2014 (byte -> word)
   991                                  					; TIMER TICK INTERRUPT
   992                                  	;;inc	word [wait_count] ;;27/02/2015
   993                                  	;INT	1CH			; TRANSFER CONTROL TO A USER ROUTINE
   994                                  	;cli
   995 000006D6 E87E030000              	call 	u_timer			; TRANSFER CONTROL TO A USER ROUTINE
   996                                  	; 23/05/2016
   997 000006DB E8ACD40000              	call	clock			; Multi Tasking control procedure
   998                                  T7:
   999                                  	; 14/10/2015
  1000 000006E0 B020                    	MOV	AL,EOI			; GET END OF INTERRUPT MASK
  1001                                  	;CLI				; DISABLE INTERRUPTS TILL STACK CLEARED
  1002 000006E2 E620                    	OUT	INTA00,AL		; END OF INTERRUPT TO 8259 - 1	
  1003                                  	;
  1004                                  	; 23/05/2016
  1005                                  rtc_int_2:
  1006                                  	; 22/05/2016
  1007 000006E4 803D[4D2D0100]00        	cmp	byte [p_change], 0 ; in 'set_run_sequence', in 'rtc_p'
  1008 000006EB 7615                    	jna	short timer_int_return ; 23/05/2016	
  1009                                  	; present process must be changed with high priority process	
  1010 000006ED 30C0                    	xor	al, al
  1011 000006EF A2[4D2D0100]            	mov	[p_change], al ; 0
  1012                                  	;
  1013 000006F4 803D[9F300100]FF        	cmp     byte [sysflg], 0FFh ; user or system space ?
  1014 000006FB 7415                    	je	short rtc_int_3     ; user space ([sysflg]= 0FFh)
  1015                                  
  1016                                  	; system space, wait for 'sysret'
  1017                                  	; to change running process 	
  1018                                  	; with high priority (event) process
  1019                                  
  1020 000006FD A2[EA300100]            	mov	[u.quant], al ; 0
  1021                                  
  1022                                  timer_int_return: ; 23/05/2016 - jump from 'rtc_int' ('rtc_int_2')
  1023 00000702 A1[683D0100]            	mov 	eax, [cr3reg] 		; previous value/content of cr3 register
  1024 00000707 0F22D8                   	mov	cr3, eax  ; restore cr3 register content
  1025                                  	;
  1026 0000070A 61                      	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
  1027                                  	;
  1028 0000070B 0FA9                    	pop	gs
  1029 0000070D 0FA1                    	pop	fs
  1030 0000070F 07                      	pop	es
  1031 00000710 1F                      	pop	ds
  1032 00000711 CF                      	iretd	; return from interrupt
  1033                                  
  1034                                  rtc_int_3:
  1035 00000712 FE05[9F300100]          	inc	byte [sysflg] 	; now, we are in system space
  1036                                  	;
  1037 00000718 E983AF0000                      jmp     sysrelease ; change running process immediatelly 
  1038                                  
  1039                                  	; 06/06/2016
  1040                                  	; 23/05/2016
  1041                                  	; 22/05/2016
  1042                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1043                                  	; 26/02/2015
  1044                                  	; 07/09/2014
  1045                                  	; 25/08/2014
  1046                                  rtc_int:       ; Real Time Clock Interrupt (IRQ 8)
  1047                                  	; 22/05/2016
  1048 0000071D 1E                      	push	ds ; ** ; 23/05/2016
  1049 0000071E 50                      	push	eax ; *
  1050 0000071F 66B81000                	mov	ax, KDATA
  1051 00000723 8ED8                    	mov	ds, ax
  1052                                  	;
  1053 00000725 8A25[46200100]          	mov	ah, [RTC_2Hz] ;  2 Hz interrupt to 1 Hz function
  1054 0000072B 80F401                  	xor	ah, 1
  1055 0000072E 8825[46200100]          	mov	[RTC_2Hz], ah ; 1 = 0.5 second, 0 = 1 second
  1056 00000734 7549                    	jnz	short rtc_int_return ; half second
  1057                                  	; 1 second
  1058                                  rtc_int_0:
  1059                                  	; 22/05/2016
  1060 00000736 58                      	pop	eax ; *
  1061                                  	;
  1062                                  	; 14/10/2015 ('timer_int')
  1063                                  	; Here, we are simulating system call entry (for task switch)
  1064                                  	; (If multitasking is enabled, 
  1065                                  	; 'clock' procedure may jump to 'sysrelease')
  1066                                  	;push	ds ; ** ; 23/05/2016
  1067 00000737 06                      	push	es
  1068 00000738 0FA0                    	push	fs
  1069 0000073A 0FA8                    	push	gs
  1070 0000073C 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  1071 0000073D 66B91000                	mov     cx, KDATA
  1072                                          ;mov    ds, cx ; 06/06/2016
  1073 00000741 8EC1                            mov     es, cx
  1074 00000743 8EE1                            mov     fs, cx
  1075 00000745 8EE9                            mov     gs, cx
  1076                                  	;
  1077 00000747 0F20D9                  	mov	ecx, cr3
  1078 0000074A 890D[683D0100]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  1079                                  	;
  1080 00000750 3B0D[C81F0100]          	cmp 	ecx, [k_page_dir]
  1081 00000756 7420                    	je	short rtc_int_1
  1082                                  	;
  1083                                  	; timer interrupt has been occurred while OS is in user mode
  1084 00000758 FC                      	cld 	; 06/06/2016
  1085 00000759 A3[A8300100]            	mov 	[u.r0], eax
  1086 0000075E 89E1                    	mov	ecx, esp
  1087 00000760 83C130                  	add	ecx, ESPACE ; 4 * 12 (stack frame)	
  1088 00000763 890D[A0300100]          	mov	[u.sp], ecx ; kernel stack pointer at the start of interrupt
  1089 00000769 8925[A4300100]          	mov	[u.usp], esp ; kernel stack points to user's registers   
  1090                                  	;
  1091 0000076F 8B0D[C81F0100]          	mov	ecx, [k_page_dir]
  1092 00000775 0F22D9                  	mov	cr3, ecx
  1093                                  
  1094                                  rtc_int_1:
  1095                                  	; Timer event (kernel) functions must be performed with
  1096                                  	; 1 second intervals - TRDOS 386 (TRDOS v2.0) feature ! -
  1097                                   	;	
  1098                                  	; 25/08/2014
  1099 00000778 E8DC020000              	call	rtc_p  ; 19/05/2016 - major modification 
  1100                                  	; 23/05/2016
  1101 0000077D 28E4                    	sub	ah, ah ; 0
  1102                                  	; 22/05/2016 - TRDOS 386 timer event modifications
  1103                                  rtc_int_return: ; 19/05/2016
  1104                                  	; 22/02/2015 - dsectpm.s
  1105                                  	; [ source: http://wiki.osdev.org/RTC ]
  1106                                  	; read status register C to complete procedure
  1107                                  	;(it is needed to get a next IRQ 8) 
  1108 0000077F B00C                    	mov	al, 0Ch ; 
  1109 00000781 E670                    	out	70h, al ; select register C
  1110 00000783 90                      	nop
  1111 00000784 E471                    	in	al, 71h ; just throw away contents
  1112                                  	; 22/02/2015
  1113 00000786 B020                    	MOV	AL,EOI		; END OF INTERRUPT
  1114                                  	;CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  1115 00000788 E6A0                    	OUT	INTB00,AL	; FOR CONTROLLER #2
  1116                                  
  1117                                  	; 23/05/2016
  1118 0000078A B020                    	MOV	AL,EOI		; GET END OF INTERRUPT MASK
  1119                                  	;CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  1120 0000078C E620                    	OUT	INTA00,AL	; END OF INTERRUPT TO 8259 - 1	
  1121                                  	;
  1122                                  	; 23/05/2016
  1123 0000078E 20E4                    	and	ah, ah
  1124 00000790 0F844EFFFFFF                    jz      rtc_int_2
  1125                                  	
  1126                                  	; ah = 1 (half second)
  1127 00000796 58                      	pop	eax ; *
  1128 00000797 1F                      	pop	ds  ; **
  1129 00000798 CF                      	iretd
  1130                                  
  1131                                  ; ////////////////
  1132                                  
  1133                                  	; 28/08/2014
  1134                                  irq0:
  1135 00000799 6A00                            push 	dword 0
  1136 0000079B EB48                    	jmp	short which_irq
  1137                                  irq1:
  1138 0000079D 6A01                            push 	dword 1
  1139 0000079F EB44                    	jmp	short which_irq
  1140                                  irq2:
  1141 000007A1 6A02                            push 	dword 2
  1142 000007A3 EB40                    	jmp	short which_irq
  1143                                  irq3:
  1144                                  	; 20/11/2015
  1145                                  	; 24/10/2015
  1146 000007A5 2EFF15[01DE0000]        	call	dword [cs:com2_irq3]
  1147 000007AC 6A03                    	push 	dword 3
  1148 000007AE EB35                    	jmp	short which_irq
  1149                                  irq4:
  1150                                  	; 20/11/2015
  1151                                  	; 24/10/2015
  1152 000007B0 2EFF15[FDDD0000]        	call	dword [cs:com1_irq4]
  1153 000007B7 6A04                            push 	dword 4
  1154 000007B9 EB2A                    	jmp	short which_irq
  1155                                  irq5:
  1156 000007BB 6A05                            push 	dword 5
  1157 000007BD EB26                    	jmp	short which_irq
  1158                                  irq6:
  1159 000007BF 6A06                            push 	dword 6
  1160 000007C1 EB22                    	jmp	short which_irq
  1161                                  irq7:
  1162 000007C3 6A07                            push 	dword 7
  1163 000007C5 EB1E                    	jmp	short which_irq
  1164                                  irq8:
  1165 000007C7 6A08                            push 	dword 8
  1166 000007C9 EB1A                    	jmp	short which_irq
  1167                                  irq9:
  1168 000007CB 6A09                            push 	dword 9
  1169 000007CD EB16                    	jmp	short which_irq
  1170                                  irq10:
  1171 000007CF 6A0A                            push 	dword 10
  1172 000007D1 EB12                    	jmp	short which_irq
  1173                                  irq11:
  1174 000007D3 6A0B                            push 	dword 11
  1175 000007D5 EB0E                    	jmp	short which_irq
  1176                                  irq12:
  1177 000007D7 6A0C                            push 	dword 12
  1178 000007D9 EB0A                    	jmp	short which_irq
  1179                                  irq13:
  1180 000007DB 6A0D                            push 	dword 13
  1181 000007DD EB06                    	jmp	short which_irq
  1182                                  irq14:
  1183 000007DF 6A0E                            push 	dword 14
  1184 000007E1 EB02                    	jmp	short which_irq
  1185                                  irq15:
  1186 000007E3 6A0F                            push 	dword 15
  1187                                  	;jmp	short which_irq
  1188                                  
  1189                                  	; 19/10/2015
  1190                                  	; 29/08/2014
  1191                                  	; 21/08/2014
  1192                                  which_irq:
  1193 000007E5 870424                  	xchg	eax, [esp]  ; 28/08/2014
  1194 000007E8 53                      	push	ebx
  1195 000007E9 56                      	push	esi
  1196 000007EA 57                      	push	edi
  1197 000007EB 1E                      	push 	ds
  1198 000007EC 06                      	push 	es
  1199                                  	;
  1200 000007ED 88C3                    	mov	bl, al
  1201                                  	;
  1202 000007EF B810000000              	mov	eax, KDATA
  1203 000007F4 8ED8                    	mov	ds, ax
  1204 000007F6 8EC0                    	mov	es, ax
  1205                                  	; 19/10/2015
  1206 000007F8 FC                      	cld
  1207                                          ; 27/08/2014
  1208 000007F9 8105[72ED0000]A000-             add     dword [scr_row], 0A0h
  1208 00000801 0000               
  1209                                  	;
  1210 00000803 B417                    	mov	ah, 17h	; blue (1) background, 
  1211                                  			; light gray (7) forecolor
  1212 00000805 8B3D[72ED0000]                  mov     edi, [scr_row]
  1213 0000080B B049                    	mov	al, 'I'
  1214 0000080D 66AB                    	stosw
  1215 0000080F B052                    	mov	al, 'R'
  1216 00000811 66AB                    	stosw
  1217 00000813 B051                    	mov	al, 'Q'
  1218 00000815 66AB                    	stosw
  1219 00000817 B020                    	mov	al, ' '
  1220 00000819 66AB                    	stosw
  1221 0000081B 88D8                    	mov	al, bl
  1222 0000081D 3C0A                    	cmp	al, 10
  1223 0000081F 7208                    	jb	short iix
  1224 00000821 B031                    	mov	al, '1'
  1225 00000823 66AB                    	stosw
  1226 00000825 88D8                    	mov	al, bl
  1227 00000827 2C0A                    	sub	al, 10
  1228                                  iix:
  1229 00000829 0430                    	add	al, '0'
  1230 0000082B 66AB                    	stosw
  1231 0000082D B020                    	mov	al, ' '
  1232 0000082F 66AB                    	stosw
  1233 00000831 B021                    	mov	al, '!'
  1234 00000833 66AB                    	stosw
  1235 00000835 B020                    	mov	al, ' '
  1236 00000837 66AB                    	stosw
  1237                                  	; 23/02/2015
  1238 00000839 80FB07                  	cmp	bl, 7 ; check for IRQ 8 to IRQ 15 
  1239 0000083C 0F8695010000            	jna	iiret
  1240 00000842 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1241 00000844 E6A0                    	out	0A0h, al ; the 2nd 8259
  1242 00000846 E98C010000              	jmp     iiret
  1243                                  	;
  1244                                  	; 22/08/2014
  1245                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1246                                  	;out	20h, al	; 8259 PORT
  1247                                  	;
  1248                                  	;pop	es
  1249                                  	;pop	ds
  1250                                  	;pop	edi
  1251                                  	;pop	esi
  1252                                  	;pop	ebx
  1253                                  	;pop 	eax
  1254                                  	;iret
  1255                                  
  1256                                  	; 02/04/2015
  1257                                  	; 25/08/2014
  1258                                  exc0:
  1259 0000084B 6A00                            push 	dword 0
  1260 0000084D E990000000                      jmp     cpu_except
  1261                                  exc1:
  1262 00000852 6A01                            push 	dword 1
  1263 00000854 E989000000                      jmp     cpu_except
  1264                                  exc2:
  1265 00000859 6A02                            push 	dword 2
  1266 0000085B E982000000                      jmp     cpu_except
  1267                                  exc3:
  1268 00000860 6A03                            push 	dword 3
  1269 00000862 EB7E                            jmp     cpu_except
  1270                                  exc4:
  1271 00000864 6A04                            push 	dword 4
  1272 00000866 EB7A                            jmp     cpu_except
  1273                                  exc5:
  1274 00000868 6A05                            push 	dword 5
  1275 0000086A EB76                            jmp     cpu_except
  1276                                  exc6:
  1277 0000086C 6A06                            push 	dword 6
  1278 0000086E EB72                            jmp     cpu_except
  1279                                  exc7:
  1280 00000870 6A07                            push 	dword 7
  1281 00000872 EB6E                            jmp     cpu_except
  1282                                  exc8:
  1283                                  	; [esp] = Error code
  1284 00000874 6A08                            push 	dword 8
  1285 00000876 EB5C                            jmp     cpu_except_en
  1286                                  exc9:
  1287 00000878 6A09                            push 	dword 9
  1288 0000087A EB66                            jmp     cpu_except
  1289                                  exc10:
  1290                                  	; [esp] = Error code
  1291 0000087C 6A0A                            push 	dword 10
  1292 0000087E EB54                            jmp     cpu_except_en
  1293                                  exc11:
  1294                                  	; [esp] = Error code
  1295 00000880 6A0B                            push 	dword 11
  1296 00000882 EB50                            jmp     cpu_except_en
  1297                                  exc12:
  1298                                  	; [esp] = Error code
  1299 00000884 6A0C                            push 	dword 12
  1300 00000886 EB4C                            jmp     cpu_except_en
  1301                                  exc13:
  1302                                  	; [esp] = Error code
  1303 00000888 6A0D                            push 	dword 13
  1304 0000088A EB48                            jmp     cpu_except_en
  1305                                  exc14:
  1306                                  	; [esp] = Error code
  1307 0000088C 6A0E                            push 	dword 14
  1308 0000088E EB44                    	jmp	short cpu_except_en
  1309                                  exc15:
  1310 00000890 6A0F                            push 	dword 15
  1311 00000892 EB4E                            jmp     cpu_except
  1312                                  exc16:
  1313 00000894 6A10                            push 	dword 16
  1314 00000896 EB4A                            jmp     cpu_except
  1315                                  exc17:
  1316                                  	; [esp] = Error code
  1317 00000898 6A11                            push 	dword 17
  1318 0000089A EB38                    	jmp	short cpu_except_en
  1319                                  exc18:
  1320 0000089C 6A12                            push 	dword 18
  1321 0000089E EB42                    	jmp	short cpu_except
  1322                                  exc19:
  1323 000008A0 6A13                            push 	dword 19
  1324 000008A2 EB3E                    	jmp	short cpu_except
  1325                                  exc20:
  1326 000008A4 6A14                            push 	dword 20
  1327 000008A6 EB3A                    	jmp	short cpu_except
  1328                                  exc21:
  1329 000008A8 6A15                            push 	dword 21
  1330 000008AA EB36                    	jmp	short cpu_except
  1331                                  exc22:
  1332 000008AC 6A16                            push 	dword 22
  1333 000008AE EB32                    	jmp	short cpu_except
  1334                                  exc23:
  1335 000008B0 6A17                            push 	dword 23
  1336 000008B2 EB2E                    	jmp	short cpu_except
  1337                                  exc24:
  1338 000008B4 6A18                            push 	dword 24
  1339 000008B6 EB2A                    	jmp	short cpu_except
  1340                                  exc25:
  1341 000008B8 6A19                            push 	dword 25
  1342 000008BA EB26                    	jmp	short cpu_except
  1343                                  exc26:
  1344 000008BC 6A1A                            push 	dword 26
  1345 000008BE EB22                    	jmp	short cpu_except
  1346                                  exc27:
  1347 000008C0 6A1B                            push 	dword 27
  1348 000008C2 EB1E                    	jmp	short cpu_except
  1349                                  exc28:
  1350 000008C4 6A1C                            push 	dword 28
  1351 000008C6 EB1A                    	jmp	short cpu_except
  1352                                  exc29:
  1353 000008C8 6A1D                            push 	dword 29
  1354 000008CA EB16                    	jmp	short cpu_except
  1355                                  exc30:
  1356 000008CC 6A1E                            push 	dword 30
  1357 000008CE EB04                    	jmp	short cpu_except_en
  1358                                  exc31:
  1359 000008D0 6A1F                            push 	dword 31
  1360 000008D2 EB0E                            jmp     short cpu_except
  1361                                  
  1362                                  	; 19/10/2015
  1363                                  	; 19/09/2015
  1364                                  	; 01/09/2015
  1365                                  	; 28/08/2015
  1366                                  	; 28/08/2014
  1367                                  cpu_except_en:
  1368 000008D4 87442404                	xchg	eax, [esp+4] ; Error code
  1369 000008D8 36A3[843E0100]          	mov	[ss:error_code], eax
  1370 000008DE 58                      	pop	eax  ; Exception number
  1371 000008DF 870424                  	xchg	eax, [esp]
  1372                                  		; eax = eax before exception
  1373                                  		; [esp] -> exception number
  1374                                  		; [esp+4] -> EIP to return
  1375                                  	; 19/10/2015
  1376                                  	; 19/09/2015
  1377                                  	; 01/09/2015
  1378                                  	; 28/08/2015
  1379                                  	; 29/08/2014
  1380                                  	; 28/08/2014
  1381                                  	; 25/08/2014
  1382                                  	; 21/08/2014
  1383                                  cpu_except:	; CPU Exceptions
  1384 000008E2 FC                      	cld
  1385 000008E3 870424                  	xchg	eax, [esp] 
  1386                                  		; eax = Exception number
  1387                                  		; [esp] = eax (before exception)	
  1388 000008E6 53                      	push	ebx
  1389 000008E7 56                      	push	esi
  1390 000008E8 57                      	push	edi
  1391 000008E9 1E                      	push 	ds
  1392 000008EA 06                      	push 	es
  1393                                  	; 28/08/2015
  1394 000008EB 66BB1000                	mov	bx, KDATA
  1395 000008EF 8EDB                    	mov	ds, bx
  1396 000008F1 8EC3                    	mov	es, bx
  1397 000008F3 0F20DB                  	mov	ebx, cr3
  1398 000008F6 53                      	push	ebx ; (*) page directory
  1399                                  	; 19/10/2015
  1400 000008F7 FC                      	cld
  1401                                  	; 25/03/2015
  1402 000008F8 8B1D[C81F0100]          	mov	ebx, [k_page_dir]
  1403 000008FE 0F22DB                  	mov	cr3, ebx
  1404                                  	; 28/08/2015
  1405 00000901 83F80E                  	cmp	eax, 0Eh ; 14, PAGE FAULT	
  1406 00000904 7512                    	jne	short cpu_except_nfp
  1407 00000906 E8B33F0000              	call	page_fault_handler
  1408 0000090B 21C0                    	and 	eax, eax
  1409 0000090D 0F84C0000000                    jz	iiretp ; 01/09/2015
  1410 00000913 B80E000000              	mov	eax, 0Eh ; 14
  1411                                  cpu_except_nfp:
  1412                                  	; 02/04/2015
  1413 00000918 BB[F7050000]            	mov	ebx, hang
  1414 0000091D 875C241C                	xchg	ebx, [esp+28]
  1415                                  		; EIP (points to instruction which faults)
  1416                                  	  	; New EIP (hang)
  1417 00000921 891D[883E0100]          	mov	[FaultOffset], ebx
  1418 00000927 C744242008000000        	mov	dword [esp+32], KCODE ; kernel's code segment
  1419 0000092F 814C242400020000        	or	dword [esp+36], 200h ; enable interrupts (set IF)
  1420                                  	;
  1421 00000937 88C4                    	mov	ah, al
  1422 00000939 240F                    	and	al, 0Fh
  1423 0000093B 3C09                    	cmp	al, 9
  1424 0000093D 7602                    	jna	short h1ok
  1425 0000093F 0407                    	add	al, 'A'-':'
  1426                                  h1ok:
  1427 00000941 D0EC                    	shr	ah, 1
  1428 00000943 D0EC                    	shr	ah, 1
  1429 00000945 D0EC                    	shr	ah, 1
  1430 00000947 D0EC                    	shr	ah, 1
  1431 00000949 80FC09                  	cmp	ah, 9
  1432 0000094C 7603                    	jna	short h2ok
  1433 0000094E 80C407                  	add	ah, 'A'-':'
  1434                                  h2ok:	
  1435 00000951 86E0                    	xchg 	ah, al	
  1436 00000953 66053030                	add	ax, '00'
  1437 00000957 66A3[A0ED0000]          	mov	[excnstr], ax
  1438                                  	;
  1439                                  	; 29/08/2014
  1440 0000095D A1[883E0100]            	mov	eax, [FaultOffset]
  1441 00000962 51                      	push	ecx
  1442 00000963 52                      	push	edx
  1443 00000964 89E3                    	mov	ebx, esp
  1444                                  	; 28/08/2015
  1445 00000966 B910000000              	mov	ecx, 16	  ; divisor value to convert binary number
  1446                                  			  ; to hexadecimal string
  1447                                  	;mov	ecx, 10	    ; divisor to convert	
  1448                                  			    ; binary number to decimal string
  1449                                  b2d1:
  1450 0000096B 31D2                    	xor	edx, edx
  1451 0000096D F7F1                    	div	ecx
  1452 0000096F 6652                    	push	dx
  1453 00000971 39C8                    	cmp	eax, ecx
  1454 00000973 73F6                    	jnb	short b2d1
  1455 00000975 BF[ABED0000]            	mov	edi, EIPstr ; EIP value
  1456                                  			    ; points to instruction which faults	
  1457                                  	; 28/08/2015
  1458 0000097A 89C2                    	mov	edx, eax
  1459                                  b2d2:
  1460                                  	;add	al, '0'
  1461 0000097C 8A82[8A2D0000]          	mov	al, [edx+hexchrs]
  1462 00000982 AA                      	stosb		    ; write hexadecimal digit to its place	
  1463 00000983 39E3                    	cmp	ebx, esp
  1464 00000985 7606                    	jna	short b2d3
  1465 00000987 6658                    	pop	ax
  1466 00000989 88C2                    	mov	dl, al
  1467 0000098B EBEF                    	jmp	short b2d2
  1468                                  b2d3:
  1469 0000098D B068                    	mov 	al, 'h' ; 28/08/2015
  1470 0000098F AA                      	stosb
  1471 00000990 B020                    	mov	al, 20h	    ; space
  1472 00000992 AA                      	stosb
  1473 00000993 30C0                    	xor	al, al	    ; to do it an ASCIIZ string	
  1474 00000995 AA                      	stosb
  1475                                  	;
  1476 00000996 5A                      	pop	edx
  1477 00000997 59                      	pop	ecx
  1478                                  	;
  1479 00000998 B44F                    	mov	ah, 4Fh	; red (4) background, 
  1480                                  			; white (F) forecolor
  1481 0000099A BE[90ED0000]            	mov	esi, exc_msg ; message offset
  1482                                  	;
  1483 0000099F EB19                    	jmp	short piemsg
  1484                                  	;
  1485                                          ;add    dword [scr_row], 0A0h
  1486                                          ;mov    edi, [scr_row]
  1487                                          ;
  1488                                  	;call 	printk
  1489                                  	;
  1490                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1491                                  	;out	20h, al	; 8259 PORT
  1492                                  	;
  1493                                  	;pop	es
  1494                                  	;pop	ds
  1495                                  	;pop	edi
  1496                                  	;pop	esi
  1497                                  	;pop 	eax
  1498                                  	;iret
  1499                                  	
  1500                                  	; 18/04/2016
  1501                                  	; 28/08/2015
  1502                                  	; 23/02/2015
  1503                                  	; 20/08/2014
  1504                                  ignore_int:
  1505 000009A1 50                      	push	eax
  1506 000009A2 53                      	push	ebx ; 23/02/2015
  1507 000009A3 56                      	push	esi
  1508 000009A4 57                      	push	edi
  1509 000009A5 1E                      	push 	ds
  1510 000009A6 06                      	push 	es
  1511                                  	; 18/04/2016
  1512 000009A7 66B81000                	mov	ax, KDATA
  1513 000009AB 8ED8                    	mov	ds, ax
  1514 000009AD 8EC0                    	mov	es, ax
  1515                                  	; 28/08/2015
  1516 000009AF 0F20D8                  	mov	eax, cr3
  1517 000009B2 50                      	push	eax ; (*) page directory
  1518                                  	;
  1519 000009B3 B467                    	mov	ah, 67h	; brown (6) background, 
  1520                                  			; light gray (7) forecolor
  1521 000009B5 BE[7AED0000]            	mov	esi, int_msg ; message offset
  1522                                  piemsg:
  1523                                          ; 27/08/2014
  1524 000009BA 8105[72ED0000]A000-             add     dword [scr_row], 0A0h
  1524 000009C2 0000               
  1525 000009C4 8B3D[72ED0000]                  mov     edi, [scr_row]
  1526                                          ;
  1527 000009CA E867FCFFFF              	call 	printk
  1528                                  	;
  1529                                  	; 23/02/2015
  1530 000009CF B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1531 000009D1 E6A0                    	out	0A0h, al ; the 2nd 8259
  1532                                  iiretp: ; 01/09/2015
  1533                                  	; 28/08/2015
  1534 000009D3 58                      	pop	eax ; (*) page directory
  1535 000009D4 0F22D8                  	mov	cr3, eax
  1536                                  	;
  1537                                  iiret:
  1538                                  	; 22/08/2014
  1539 000009D7 B020                    	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1540 000009D9 E620                    	out	20h, al	; 8259 PORT
  1541                                  	;
  1542 000009DB 07                      	pop	es
  1543 000009DC 1F                      	pop	ds
  1544 000009DD 5F                      	pop	edi
  1545 000009DE 5E                      	pop	esi
  1546 000009DF 5B                      	pop	ebx ; 29/08/2014
  1547 000009E0 58                      	pop 	eax
  1548 000009E1 CF                      	iretd
  1549                                  
  1550                                  	; 23/05/2016
  1551                                  	; 22/08/2014
  1552                                  	; IBM PC/AT BIOS source code ----- 10/06/85 (bios.asm)
  1553                                  	; (INT 1Ah)
  1554                                  	;; Linux (v0.12) source code (main.c) by Linus Torvalds (1991)
  1555                                  time_of_day:
  1556 000009E2 E8184A0000              	call	UPD_IPR			; WAIT TILL UPDATE NOT IN PROGRESS
  1557 000009E7 726F                            jc      short time_of_day_retn ; 23/05/2016
  1558 000009E9 B000                    	mov	al, CMOS_SECONDS
  1559 000009EB E82A4A0000              	call	CMOS_READ
  1560 000009F0 A2[38200100]            	mov	[time_seconds], al 
  1561 000009F5 B002                    	mov	al, CMOS_MINUTES
  1562 000009F7 E81E4A0000              	call	CMOS_READ
  1563 000009FC A2[39200100]            	mov	[time_minutes], al 
  1564 00000A01 B004                    	mov	al, CMOS_HOURS
  1565 00000A03 E8124A0000              	call	CMOS_READ
  1566 00000A08 A2[3A200100]                    mov     [time_hours], al
  1567 00000A0D B006                    	mov	al, CMOS_DAY_WEEK 
  1568 00000A0F E8064A0000              	call	CMOS_READ
  1569 00000A14 A2[3B200100]            	mov	[date_wday], al
  1570 00000A19 B007                     	mov	al, CMOS_DAY_MONTH
  1571 00000A1B E8FA490000              	call	CMOS_READ
  1572 00000A20 A2[3C200100]            	mov	[date_day], al
  1573 00000A25 B008                    	mov	al, CMOS_MONTH
  1574 00000A27 E8EE490000              	call	CMOS_READ
  1575 00000A2C A2[3D200100]            	mov	[date_month], al
  1576 00000A31 B009                    	mov	al, CMOS_YEAR
  1577 00000A33 E8E2490000              	call	CMOS_READ
  1578 00000A38 A2[3E200100]            	mov	[date_year], al
  1579 00000A3D B032                    	mov	al, CMOS_CENTURY
  1580 00000A3F E8D6490000              	call	CMOS_READ
  1581 00000A44 A2[3F200100]            	mov	[date_century], al
  1582                                  	;
  1583 00000A49 B000                    	mov	al, CMOS_SECONDS
  1584 00000A4B E8CA490000              	call 	CMOS_READ
  1585 00000A50 3A05[38200100]          	cmp	al, [time_seconds]
  1586 00000A56 758A                    	jne	short time_of_day
  1587                                  
  1588                                  time_of_day_retn:
  1589 00000A58 C3                      	retn
  1590                                  
  1591                                  	; 10/06/2016
  1592                                  	; 07/06/2016
  1593                                  	; 06/06/2016
  1594                                  	; 23/05/2016
  1595                                  u_timer: 
  1596                                  	; Timer Events with 18.2 Hz Timer Ticks
  1597                                  	; (and also timer events with RTC seconds)
  1598                                  rtc_p:
  1599                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1600                                  	; Major Modification:
  1601                                  	; Check and Perform Timer Events (for RTC)
  1602                                  	; 25/08/2014 - 07/09/2014
  1603                                  	; Retro UNIX 386 v1:
  1604                                   	; Print Real Time Clock content
  1605                                  	
  1606 00000A59 803D[4F2D0100]00        	cmp	byte [timer_events], 0 ; 07/06/2016
  1607 00000A60 7649                    	jna	short rtc_p5
  1608                                  
  1609 00000A62 8A0D[4F2D0100]          	mov	cl, [timer_events]
  1610                                  
  1611 00000A68 BE[6C3D0100]            	mov	esi, timer_set  ; beginning address of
  1612                                  				; timer events space
  1613                                  rtc_p0:
  1614 00000A6D 8B06                    	mov	eax, [esi]	
  1615 00000A6F 20C0                    	and	al, al ; 0 = free, >0 = process ID
  1616 00000A71 7413                    	jz	short rtc_p2
  1617                                  	;
  1618 00000A73 C1C810                  	ror	eax, 16
  1619                                  	; ah = response value, al = interrupt type
  1620 00000A76 3C01                    	cmp	al, 1 ; RTC interrupt ?
  1621 00000A78 7411                    	je	short rtc_p3 ; yes, check for response
  1622                                  	; 06/06/2016 - 18.2 Hz Timer Ticks
  1623 00000A7A 7706                    	ja	short rtc_p1 ; undefined ! ; 10/06/2016
  1624 00000A7C 836E080A                	sub	dword [esi+8], 10 ; 1 tick = 10
  1625 00000A80 7612                    	jna	short rtc_p4  ; continue for responding
  1626                                  rtc_p1:
  1627                                  	; 07/06/2016
  1628 00000A82 FEC9                    	dec	cl    ; remain count of timer events	
  1629 00000A84 7425                    	jz	short rtc_p5 
  1630                                  rtc_p2:	
  1631                                  	;cmp	esi, timer_set + 240 ; 15*16 (last event)
  1632                                  	;jnb	short rtc_p5 ; end of timer event space
  1633 00000A86 83C610                  	add	esi, 16 ; next timer event
  1634 00000A89 EBE2                    	jmp	short rtc_p0
  1635                                  rtc_p3:	 
  1636                                  	; current timer count ; 06/06/2016 (182)
  1637 00000A8B 816E08B6000000          	sub	dword [esi+8], 182 ; 1 second (10*18.2)
  1638 00000A92 77EE                    	ja	short rtc_p1  ; check for the next 
  1639                                  rtc_p4:	
  1640                                  	; it is the time of response! 
  1641 00000A94 8B5E04                  	mov	ebx, [esi+4] ; set (count limit) value
  1642 00000A97 895E08                  	mov	[esi+8], ebx ; reset count down value
  1643                                  			     ; to count limit
  1644                                  	; response address is physical address of
  1645                                  	; the program's response (signal return) byte
  1646                                  	; 06/06/2016
  1647 00000A9A 8B7E0C                  	mov	edi, [esi+12] ; response address
  1648 00000A9D 8827                    	mov	[edi], ah     ; response value 
  1649                                  	;
  1650 00000A9F C1C010                  	rol	eax, 16
  1651                                  	; al = process number  ; 10/06/2016
  1652 00000AA2 B202                    	mov	dl, 2 ; priority, 2 = event (high)	
  1653 00000AA4 E886D00000              	call	set_run_sequence ; 19/05/2016
  1654 00000AA9 EBD7                    	jmp	short rtc_p1 ; 10/06/2016
  1655                                  rtc_p5:	 
  1656 00000AAB C3                      	retn
  1657                                  
  1658                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  1659                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  1660                                  default_irq7:
  1661 00000AAC 6650                    	push	ax
  1662 00000AAE B00B                    	mov	al, 0Bh  ; In-Service register
  1663 00000AB0 E620                    	out	20h, al
  1664 00000AB2 EB00                            jmp short $+2
  1665 00000AB4 EB00                    	jmp short $+2
  1666 00000AB6 E420                    	in	al, 20h
  1667 00000AB8 2480                    	and 	al, 80h ; bit 7 (is it real IRQ 7 or fake?)
  1668 00000ABA 7404                            jz      short irq7_iret ; Fake (spurious) IRQ, do not send EOI 
  1669 00000ABC B020                            mov     al, 20h ; EOI
  1670 00000ABE E620                    	out	20h, al 
  1671                                  irq7_iret:
  1672 00000AC0 6658                    	pop	ax
  1673 00000AC2 CF                      	iretd
  1674                                  	
  1675                                  bcd_to_ascii:
  1676                                  	; 25/08/2014
  1677                                  	; INPUT ->
  1678                                  	;	al = Packed BCD number
  1679                                  	; OUTPUT ->
  1680                                  	;	ax  = ASCII word/number
  1681                                  	;
  1682                                  	; Erdogan Tan - 1998 (proc_hex) - TRDOS.ASM (2004-2011)
  1683                                  	;
  1684 00000AC3 D410                    	db 0D4h,10h                     ; Undocumented inst. AAM
  1685                                  					; AH = AL / 10h
  1686                                  					; AL = AL MOD 10h
  1687 00000AC5 660D3030                	or ax,'00'                      ; Make it ASCII based
  1688                                  
  1689 00000AC9 86E0                            xchg ah, al 
  1690                                  	
  1691 00000ACB C3                      	retn	
  1692                                  	
  1693                                  
  1694                                  %include 'keyboard.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - keyboard.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; keyboard.inc (17/10/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - KEYBOARD.INC
    20                              <1> ; Last Modification: 17/10/2015
    21                              <1> ;		    (Keyboard Data is in 'KYBDATA.INC')	
    22                              <1> ;
    23                              <1> ; ///////// KEYBOARD FUNCTIONS (PROCEDURES) ///////////////
    24                              <1> 
    25                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
    26                              <1> 
    27                              <1> ; 03/12/2014
    28                              <1> ; 26/08/2014
    29                              <1> ; KEYBOARD I/O
    30                              <1> ; (INT_16h - Retro UNIX 8086 v1 - U9.ASM, 30/06/2014)
    31                              <1> 
    32                              <1> ;NOTE: 'k0' to 'k7' are name of OPMASK registers.
    33                              <1> ;	(The reason of using '_k' labels!!!) (27/08/2014)    
    34                              <1> ;NOTE: 'NOT' keyword is '~' unary operator in NASM.
    35                              <1> ;	('NOT LC_HC' --> '~LC_HC') (bit reversing operator)
    36                              <1> 
    37                              <1> int16h:	; 30/06/2015
    38                              <1> ;getc:
    39 00000ACC 9C                  <1> 	pushfd	; 28/08/2014
    40 00000ACD 0E                  <1> 	push 	cs
    41 00000ACE E801000000          <1> 	call 	KEYBOARD_IO_1 ; getc_int
    42 00000AD3 C3                  <1> 	retn	
    43                              <1> 
    44                              <1> getc_int:
    45                              <1> 	; 28/02/2015
    46                              <1> 	; 03/12/2014 (derivation from pc-xt-286 bios source code -1986-, 
    47                              <1> 	;	      instead of pc-at bios - 1985-)
    48                              <1> 	; 28/08/2014 (_k1d)
    49                              <1> 	; 30/06/2014
    50                              <1> 	; 03/03/2014
    51                              <1> 	; 28/02/2014
    52                              <1> 	; Derived from "KEYBOARD_IO_1" procedure of IBM "pc-xt-286" 
    53                              <1> 	; rombios source code (21/04/1986)
    54                              <1> 	;	 'keybd.asm', INT 16H, KEYBOARD_IO
    55                              <1> 	;
    56                              <1> 	; KYBD --- 03/06/86  KEYBOARD BIOS
    57                              <1> 	;
    58                              <1> 	;--- INT 16 H -----------------------------------------------------------------
    59                              <1> 	; KEYBOARD I/O								      :
    60                              <1> 	;	THESE ROUTINES PROVIDE READ KEYBOARD SUPPORT			      :
    61                              <1> 	; INPUT									      :
    62                              <1> 	;	(AH)= 00H  READ THE NEXT ASCII CHARACTER ENTERED FROM THE KEYBOARD,   :
    63                              <1> 	;		   RETURN THE RESULT IN (AL), SCAN CODE IN (AH).              :
    64                              <1> 	;		   THIS IS THE COMPATIBLE READ INTERFACE, EQUIVALENT TO THE   :
    65                              <1> 	;                  STANDARD PC OR PCAT KEYBOARD				      :	
    66                              <1> 	;-----------------------------------------------------------------------------:
    67                              <1> 	;	(AH)= 01H  SET THE ZERO FLAG TO INDICATE IF AN ASCII CHARACTER IS     :
    68                              <1> 	;		   AVAILABLE TO BE READ FROM THE KEYBOARD BUFFER.	      :
    69                              <1> 	;		   (ZF)= 1 -- NO CODE AVAILABLE			              :
    70                              <1> 	;		   (ZF)= 0 -- CODE IS AVAILABLE  (AX)= CHARACTER              :
    71                              <1> 	;		   IF (ZF)= 0, THE NEXT CHARACTER IN THE BUFFER TO BE READ IS :
    72                              <1> 	;		   IN (AX), AND THE ENTRY REMAINS IN THE BUFFER.              :
    73                              <1> 	;		   THIS WILL RETURN ONLY PC/PCAT KEYBOARD COMPATIBLE CODES    :
    74                              <1> 	;-----------------------------------------------------------------------------:	
    75                              <1> 	;	(AH)= 02H  RETURN THE CURRENT SHIFT STATUS IN AL REGISTER             :
    76                              <1> 	;		   THE BIT SETTINGS FOR THIS CODE ARE INDICATED IN THE        :
    77                              <1> 	;		   EQUATES FOR @KB_FLAG		                              :
    78                              <1> 	;-----------------------------------------------------------------------------:	
    79                              <1> 	;	(AH)= 03H  SET TYPAMATIC RATE AND DELAY                               :
    80                              <1> 	;	      (AL) = 05H                                                      :
    81                              <1> 	;	      (BL) = TYPAMATIC RATE (BITS 5 - 7 MUST BE RESET TO 0)           :
    82                              <1> 	;		       							      :
    83                              <1> 	;                     REGISTER     RATE      REGISTER     RATE                :
    84                              <1> 	;                      VALUE     SELECTED     VALUE     SELECTED              :
    85                              <1> 	;                     --------------------------------------------            :
    86                              <1> 	;			00H        30.0        10H        7.5                 :
    87                              <1> 	;			01H        26.7        11H        6.7                 :
    88                              <1> 	;			02H        24.0        12H        6.0                 :
    89                              <1> 	;			03H        21.8        13H        5.5                 :
    90                              <1> 	;			04H        20.0        14H        5.0                 :
    91                              <1> 	;			05H        18.5        15H        4.6                 :
    92                              <1> 	;			06H        17.1        16H        4.3                 :
    93                              <1> 	;			07H        16.0        17H        4.0                 :
    94                              <1> 	;			08H        15.0        18H        3.7                 :
    95                              <1> 	;			09H        13.3        19H        3.3                 :
    96                              <1> 	;			0AH        12.0        1AH        3.0                 :
    97                              <1> 	;			0BH        10.9        1BH        2.7                 :
    98                              <1>         ;			0CH        10.0        1CH        2.5                 :
    99                              <1> 	;			0DH         9.2        1DH        2.3                 :
   100                              <1> 	;			0EH         8.6        1EH        2.1                 :
   101                              <1> 	;			0FH         8.0        1FH        2.0                 :
   102                              <1> 	;									      :
   103                              <1> 	;	      (BH) = TYPAMATIC DELAY  (BITS 2 - 7 MUST BE RESET TO 0)         :
   104                              <1> 	;		       							      :
   105                              <1> 	;                     REGISTER     DELAY                                      :
   106                              <1> 	;                      VALUE       VALUE                                      :
   107                              <1> 	;                     ------------------                                      :
   108                              <1> 	;			00H        250 ms                                     :
   109                              <1> 	;			01H        500 ms                                     :
   110                              <1> 	;			02H        750 ms                                     :
   111                              <1> 	;			03H       1000 ms                                     :
   112                              <1> 	;-----------------------------------------------------------------------------:
   113                              <1> 	;	(AH)= 05H  PLACE ASCII CHARACTER/SCAN CODE COMBINATION IN KEYBOARD    :
   114                              <1> 	;		   BUFFER AS IF STRUCK FROM KEYBOARD                          :
   115                              <1> 	;		   ENTRY:  (CL) = ASCII CHARACTER		              :
   116                              <1> 	;		           (CH) = SCAN CODE                                   :
   117                              <1> 	;		   EXIT:   (AH) = 00H = SUCCESSFUL OPERATION                  :
   118                              <1> 	;		           (AL) = 01H = UNSUCCESSFUL - BUFFER FULL            :
   119                              <1> 	;		   FLAGS:  CARRY IF ERROR                                     :
   120                              <1> 	;-----------------------------------------------------------------------------:		
   121                              <1> 	;	(AH)= 10H  EXTENDED READ INTERFACE FOR THE ENHANCED KEYBOARD,         :
   122                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=0                            :
   123                              <1> 	;-----------------------------------------------------------------------------:
   124                              <1> 	;	(AH)= 11H  EXTENDED ASCII STATUS FOR THE ENHANCED KEYBOARD,           :
   125                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=1                            :
   126                              <1> 	;-----------------------------------------------------------------------------:	
   127                              <1> 	;	(AH)= 12H  RETURN THE EXTENDED SHIFT STATUS IN AX REGISTER            :
   128                              <1> 	;		   AL = BITS FROM KB_FLAG, AH = BITS FOR LEFT AND RIGHT       :
   129                              <1> 	;		   CTL AND ALT KEYS FROM KB_FLAG_1 AND KB_FLAG_3              :
   130                              <1> 	; OUTPUT					                              :
   131                              <1> 	;	AS NOTED ABOVE, ONLY (AX) AND FLAGS CHANGED	                      :
   132                              <1> 	;	ALL REGISTERS RETAINED		                                      :
   133                              <1> 	;------------------------------------------------------------------------------
   134                              <1> 
   135                              <1> ; 29/05/2016
   136                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   137                              <1> int32h:  ; Keyboard BIOS
   138                              <1> 
   139                              <1> KEYBOARD_IO_1:	
   140 00000AD4 FB                  <1> 	sti				; INTERRUPTS BACK ON
   141                              <1> 	; 29/05/2016
   142 00000AD5 80642408BE          <1>         and     byte [esp+8], 10111110b ; clear zero flag and cary flag
   143                              <1> 	;
   144 00000ADA 1E                  <1> 	push	ds			; SAVE CURRENT DS
   145 00000ADB 53                  <1> 	push	ebx			; SAVE BX TEMPORARILY
   146                              <1> 	;push	ecx			; SAVE CX TEMPORARILY
   147 00000ADC 66BB1000            <1>         mov     bx, KDATA 
   148 00000AE0 8EDB                <1> 	mov	ds, bx			; PUT SEGMENT VALUE OF DATA AREA INTO DS
   149 00000AE2 08E4                <1> 	or	ah, ah			; CHECK FOR (AH)= 00H
   150 00000AE4 7439                <1> 	jz	short _K1		; ASCII_READ
   151 00000AE6 FECC                <1> 	dec	ah                      ; CHECK FOR (AH)= 01H
   152 00000AE8 7452                <1>         jz      short _K2               ; ASCII_STATUS
   153 00000AEA FECC                <1> 	dec	ah			; CHECK FOR (AH)= 02H
   154 00000AEC 0F8492000000        <1>         jz      _K3                     ; SHIFT STATUS
   155 00000AF2 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 03H	
   156 00000AF4 0F8491000000        <1>         jz      _K300                   ; SET TYPAMATIC RATE/DELAY
   157 00000AFA 80EC02              <1> 	sub	ah, 2			; CHECK FOR (AH)= 05H	
   158 00000AFD 0F84B6000000        <1>         jz      _K500                   ; KEYBOARD WRITE         
   159                              <1> _KIO1:	
   160 00000B03 80EC0B              <1> 	sub	ah, 11			; AH =  10H
   161 00000B06 740B                <1> 	jz	short _K1E		; EXTENDED ASCII READ
   162 00000B08 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 11H
   163 00000B0A 7421                <1> 	jz	short _K2E		; EXTENDED_ASCII_STATUS
   164 00000B0C FECC                <1> 	dec	ah			; CHECK FOR (AH)= 12H
   165 00000B0E 7456                <1> 	jz	short _K3E		; EXTENDED_SHIFT_STATUS
   166                              <1> _KIO_EXIT:
   167                              <1> 	;pop	ecx			; RECOVER REGISTER
   168 00000B10 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   169 00000B11 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   170 00000B12 CF                  <1> 	iretd				; INVALID COMMAND, EXIT
   171                              <1> 
   172                              <1> 	;-----	ASCII CHARACTER
   173                              <1> _K1E:	
   174 00000B13 E8CE000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER (EXTENDED)
   175 00000B18 E843010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   176 00000B1D EBF1                <1> 	jmp	short _KIO_EXIT         ; GIVE IT TO THE CALLER
   177                              <1> _K1:	
   178 00000B1F E8C2000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER
   179 00000B24 E842010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   180 00000B29 72F4                <1> 	jc	short _K1		; CARRY SET MEANS TROW CODE AWAY
   181                              <1> _K1A:
   182 00000B2B EBE3                <1> 	jmp	short _KIO_EXIT         ; RETURN TO CALLER
   183                              <1> 
   184                              <1> 	;-----	ASCII STATUS
   185                              <1> _K2E:	
   186 00000B2D E8FF000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER (EXTENDED)
   187 00000B32 7420                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   188 00000B34 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   189 00000B35 E826010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   190 00000B3A EB17                <1> 	jmp	short _K2A	        ; GIVE IT TO THE CALLER
   191                              <1> _K2:	
   192 00000B3C E8F0000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER
   193 00000B41 7411                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   194 00000B43 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   195 00000B44 E822010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   196 00000B49 7308                <1> 	jnc	short _K2A	        ; CARRY CLEAR MEANS PASS VALID CODE
   197 00000B4B 9D                  <1> 	popf				; INVALID CODE FOR THIS TYPE OF CALL
   198 00000B4C E895000000          <1> 	call	_K1S			; THROW THE CHARACTER AWAY
   199 00000B51 EBE9                <1> 	jmp	short _K2		; GO LOOK FOR NEXT CHAR, IF ANY
   200                              <1> _K2A:
   201 00000B53 9D                  <1> 	popf				; RESTORE ZF FROM TEST
   202                              <1> _K2B:
   203                              <1> 	;pop	ecx			; RECOVER REGISTER
   204 00000B54 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   205 00000B55 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   206                              <1> 	; (*) 29/05/2016
   207                              <1> 	; (*) retf 4			; THROW AWAY (e)FLAGS
   208 00000B56 7208                <1> 	jc	short _k2d
   209 00000B58 7505                <1> 	jnz	short _k2c
   210 00000B5A 804C240840          <1> 	or	byte [esp+8], 01000000b	; set zero flag bit of eflags register
   211                              <1> _k2c:
   212 00000B5F CF                  <1> 	iretd
   213                              <1> _k2d:
   214                              <1> 	; 29/05/2016 -set carry flag on stack-
   215                              <1> 	; [esp] = EIP
   216                              <1> 	; [esp+4] = CS
   217                              <1> 	; [esp+8] = E-FLAGS
   218 00000B60 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
   219                              <1> 	; [esp+12] = ESP (user)
   220                              <1> 	; [esp+16] = SS (User)
   221 00000B65 CF                  <1> 	iretd
   222                              <1> 
   223                              <1> 	
   224                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
   225                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   226                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   227                              <1> 	; // RETF instruction:
   228                              <1> 	;
   229                              <1> 	; IF OperandMode=32 THEN
   230                              <1>  	;    Load CS:EIP from stack;
   231                              <1>  	;    Set CS RPL to CPL;
   232                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
   233                              <1>  	;    Load SS:eSP from stack;
   234                              <1>  	; ELSE (* OperandMode=16 *)
   235                              <1>  	;    Load CS:IP from stack;
   236                              <1>  	;    Set CS RPL to CPL;
   237                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
   238                              <1> 	;    Load SS:eSP from stack;
   239                              <1>  	; FI;
   240                              <1> 	;
   241                              <1> 	; //
   242                              <1> 
   243                              <1> 	;-----	SHIFT STATUS
   244                              <1> _K3E:                                   ; GET THE EXTENDED SHIFT STATUS FLAGS
   245 00000B66 8A25[D2E80000]      <1> 	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
   246 00000B6C 80E404              <1> 	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
   247                              <1> 	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
   248                              <1> 	;shl	ah, cl			; BIT 7 POSITION
   249 00000B6F C0E405              <1>         shl	ah, 5
   250 00000B72 A0[D2E80000]        <1> 	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
   251 00000B77 2473                <1> 	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
   252 00000B79 08C4                <1> 	or	ah, al                  ; MERGE REMAINING BITS INTO AH
   253 00000B7B A0[D4E80000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
   254 00000B80 240C                <1> 	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
   255 00000B82 08C4                <1> 	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
   256                              <1> _K3:
   257 00000B84 A0[D1E80000]        <1> 	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
   258 00000B89 EB85                <1> 	jmp	short _KIO_EXIT		; RETURN TO CALLER
   259                              <1> 
   260                              <1> 	;-----	SET TYPAMATIC RATE AND DELAY
   261                              <1> _K300:
   262 00000B8B 3C05                <1> 	cmp	al, 5			; CORRECT FUNCTION CALL?
   263 00000B8D 7581                <1> 	jne	short _KIO_EXIT		; NO, RETURN
   264 00000B8F F6C3E0              <1>      	test	bl, 0E0h		; TEST FOR OUT-OF-RANGE RATE
   265 00000B92 0F8578FFFFFF        <1>         jnz     _KIO_EXIT               ; RETURN IF SO
   266 00000B98 F6C7FC              <1> 	test	BH, 0FCh		; TEST FOR OUT-OF-RANGE DELAY
   267 00000B9B 0F856FFFFFFF        <1>         jnz     _KIO_EXIT               ; RETURN IF SO
   268 00000BA1 B0F3                <1> 	mov	al, KB_TYPA_RD		; COMMAND FOR TYPAMATIC RATE/DELAY		
   269 00000BA3 E8DA060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   270                              <1> 	;mov	cx, 5			; SHIFT COUNT
   271                              <1> 	;shl	bh, cl			; SHIFT DELAY OVER
   272 00000BA8 C0E705              <1> 	shl	bh, 5
   273 00000BAB 88D8                <1> 	mov	al, bl			; PUT IN RATE
   274 00000BAD 08F8                <1> 	or	al, bh			; AND DELAY
   275 00000BAF E8CE060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   276 00000BB4 E957FFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER
   277                              <1> 
   278                              <1> 	;-----	WRITE TO KEYBOARD BUFFER
   279                              <1> _K500:
   280 00000BB9 56                  <1> 	push	esi			; SAVE SI (esi)
   281 00000BBA FA                  <1> 	cli				; 
   282 00000BBB 8B1D[E2E80000]      <1>      	mov	ebx, [BUFFER_TAIL]	; GET THE 'IN TO' POINTER TO THE BUFFER
   283 00000BC1 89DE                <1> 	mov	esi, ebx		; SAVE A COPY IN CASE BUFFER NOT FULL
   284 00000BC3 E8D3000000          <1> 	call	_K4			; BUMP THE POINTER TO SEE IF BUFFER IS FULL
   285 00000BC8 3B1D[DEE80000]      <1> 	cmp	ebx, [BUFFER_HEAD]	; WILL THE BUFFER OVERRUN IF WE STORE THIS?
   286 00000BCE 740D                <1> 	je	short _K502		; YES - INFORM CALLER OF ERROR		
   287 00000BD0 66890E              <1> 	mov	[esi], cx		; NO - PUT ASCII/SCAN CODE INTO BUFFER	
   288 00000BD3 891D[E2E80000]      <1> 	mov	[BUFFER_TAIL], ebx	; ADJUST 'IN TO' POINTER TO REFLECT CHANGE
   289 00000BD9 28C0                <1> 	sub	al, al			; TELL CALLER THAT OPERATION WAS SUCCESSFUL
   290 00000BDB EB02                <1> 	jmp	short _K504		; SUB INSTRUCTION ALSO RESETS CARRY FLAG
   291                              <1> _K502:
   292 00000BDD B001                <1> 	mov	al, 01h			; BUFFER FULL INDICATION
   293                              <1> _K504:
   294 00000BDF FB                  <1> 	sti				
   295 00000BE0 5E                  <1> 	pop	esi			; RECOVER SI (esi)
   296 00000BE1 E92AFFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER WITH STATUS IN AL
   297                              <1> 
   298                              <1> 	;-----	READ THE KEY TO FIGURE OUT WHAT TO DO -----
   299                              <1> _K1S:
   300 00000BE6 FA                  <1> 	cli	; 03/12/2014
   301 00000BE7 8B1D[DEE80000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   302 00000BED 3B1D[E2E80000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   303                              <1> 	;jne	short _K1U		; IF ANYTHING IN BUFFER SKIP INTERRUPT
   304 00000BF3 750F                <1> 	jne	short _k1x ; 03/12/2014
   305                              <1> 	;
   306                              <1> 	; 03/12/2014
   307                              <1> 	; 28/08/2014
   308                              <1> 	; PERFORM OTHER FUNCTION ?? here !
   309                              <1> 	;; MOV	AX, 9002h		; MOVE IN WAIT CODE & TYPE
   310                              <1> 	;; INT 	15H			; PERFORM OTHER FUNCTION
   311                              <1> _K1T:                                   ; ASCII READ
   312 00000BF5 FB                  <1> 	sti				; INTERRUPTS BACK ON DURING LOOP
   313 00000BF6 90                  <1> 	nop				; ALLOW AN INTERRUPT TO OCCUR
   314                              <1> _K1U:	
   315 00000BF7 FA                  <1> 	cli				; INTERRUPTS BACK OFF
   316 00000BF8 8B1D[DEE80000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   317 00000BFE 3B1D[E2E80000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   318                              <1> _k1x:
   319 00000C04 53                  <1> 	push	ebx			; SAVE ADDRESS		
   320 00000C05 9C                  <1> 	pushf				; SAVE FLAGS
   321 00000C06 E82F070000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   322 00000C0B 8A1D[D3E80000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   323 00000C11 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   324 00000C13 80E307              <1> 	and	bl, 07h	; KB_LEDS	; ISOLATE INDICATOR BITS
   325 00000C16 7406                <1> 	jz	short _K1V		; IF NO CHANGE BYPASS UPDATE
   326 00000C18 E8C9060000          <1> 	call	SND_LED1
   327 00000C1D FA                  <1> 	cli				; DISABLE INTERRUPTS
   328                              <1> _K1V:
   329 00000C1E 9D                  <1> 	popf				; RESTORE FLAGS
   330 00000C1F 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
   331 00000C20 74D3                <1>         je      short _K1T              ; LOOP UNTIL SOMETHING IN BUFFER
   332                              <1> 	;
   333 00000C22 668B03              <1> 	mov	ax, [ebx] 		; GET SCAN CODE AND ASCII CODE
   334 00000C25 E871000000          <1>         call    _K4                     ; MOVE POINTER TO NEXT POSITION
   335 00000C2A 891D[DEE80000]      <1>         mov     [BUFFER_HEAD], ebx      ; STORE VALUE IN VARIABLE
   336 00000C30 C3                  <1> 	retn				; RETURN
   337                              <1> 
   338                              <1> 	;-----	READ THE KEY TO SEE IF ONE IS PRESENT -----
   339                              <1> _K2S:
   340 00000C31 FA                  <1> 	cli				; INTERRUPTS OFF
   341 00000C32 8B1D[DEE80000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
   342 00000C38 3B1D[E2E80000]      <1>         cmp     ebx, [BUFFER_TAIL]      ; IF EQUAL (Z=1) THEN NOTHING THERE
   343 00000C3E 668B03              <1> 	mov	ax, [ebx]
   344 00000C41 9C                  <1> 	pushf				; SAVE FLAGS
   345 00000C42 6650                <1> 	push	ax			; SAVE CODE
   346 00000C44 E8F1060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   347 00000C49 8A1D[D3E80000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   348 00000C4F 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   349 00000C51 80E307              <1> 	and	bl, 07h ; KB_LEDS	; ISOLATE INDICATOR BITS
   350 00000C54 7405                <1> 	jz	short _K2T		; IF NO CHANGE BYPASS UPDATE
   351 00000C56 E874060000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   352                              <1> _K2T:
   353 00000C5B 6658                <1> 	pop	ax			; RESTORE CODE
   354 00000C5D 9D                  <1> 	popf				; RESTORE FLAGS
   355 00000C5E FB                  <1> 	sti				; INTERRUPTS BACK ON
   356 00000C5F C3                  <1> 	retn				; RETURN
   357                              <1> 
   358                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR EXTENDED CALLS -----
   359                              <1> _KIO_E_XLAT:
   360 00000C60 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   361 00000C62 7506                <1> 	jne	short _KIO_E_RET	; NO, PASS IT ON
   362 00000C64 08E4                <1>         or 	ah, ah			; AH = 0 IS SPECIAL CASE
   363 00000C66 7402                <1>         jz	short _KIO_E_RET        ; PASS THIS ON UNCHANGED
   364 00000C68 30C0                <1> 	xor	al, al			; OTHERWISE SET AL = 0
   365                              <1> _KIO_E_RET:				
   366 00000C6A C3                  <1> 	retn				; GO BACK
   367                              <1> 
   368                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR STANDARD CALLS -----
   369                              <1> _KIO_S_XLAT:
   370 00000C6B 80FCE0              <1> 	cmp	ah, 0E0h		; IS IT KEYPAD ENTER OR / ?
   371 00000C6E 750F                <1> 	jne	short _KIO_S2		; NO, CONTINUE
   372 00000C70 3C0D                <1> 	cmp	al, 0Dh			; KEYPAD ENTER CODE?
   373 00000C72 7408                <1>         je	short _KIO_S1		; YES, MASSAGE A BIT
   374 00000C74 3C0A                <1> 	cmp	al, 0Ah			; CTRL KEYPAD ENTER CODE?
   375 00000C76 7404                <1>         je	short _KIO_S1		; YES, MASSAGE THE SAME
   376 00000C78 B435                <1> 	mov	ah, 35h			; NO, MUST BE KEYPAD /
   377                              <1> _kio_ret: ; 03/12/2014
   378 00000C7A F8                  <1> 	clc
   379 00000C7B C3                  <1> 	retn
   380                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   381                              <1> _KIO_S1:				
   382 00000C7C B41C                <1> 	mov	ah, 1Ch			; CONVERT TO COMPATIBLE OUTPUT
   383                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   384 00000C7E C3                  <1> 	retn
   385                              <1> _KIO_S2:		
   386 00000C7F 80FC84              <1> 	cmp	ah, 84h			; IS IT ONE OF EXTENDED ONES?
   387 00000C82 7715                <1> 	ja	short _KIO_DIS		; YES, THROW AWAY AND GET ANOTHER CHAR
   388 00000C84 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   389 00000C86 7506                <1>         jne	short _KIO_S3		; NO, TRY LAST TEST
   390 00000C88 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   391 00000C8A 740C                <1>         jz	short _KIO_USE		; PASS THIS ON UNCHANGED
   392 00000C8C EB0B                <1> 	jmp	short _KIO_DIS		; THROW AWAY THE REST
   393                              <1> _KIO_S3:
   394 00000C8E 3CE0                <1> 	cmp	al, 0E0h		; IS IT AN EXTENSION OF A PREVIOUS ONE?
   395                              <1> 	;jne	short _KIO_USE		; NO, MUST BE A STANDARD CODE
   396 00000C90 75E8                <1> 	jne	short _kio_ret
   397 00000C92 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   398 00000C94 7402                <1>         jz	short _KIO_USE		; JUMP IF AH = 0
   399 00000C96 30C0                <1> 	xor	al, al			; CONVERT TO COMPATIBLE OUTPUT
   400                              <1> 	;jmp	short _KIO_USE		; PASS IT ON TO CALLER
   401                              <1> _KIO_USE:
   402                              <1> 	;clc				; CLEAR CARRY TO INDICATE GOOD CODE
   403 00000C98 C3                  <1> 	retn				; RETURN	
   404                              <1> _KIO_DIS:
   405 00000C99 F9                  <1> 	stc				; SET CARRY TO INDICATE DISCARD CODE
   406 00000C9A C3                  <1> 	retn				; RETURN
   407                              <1> 
   408                              <1> 	;-----	INCREMENT BUFFER POINTER ROUTINE -----
   409                              <1> _K4:    
   410 00000C9B 43                  <1> 	inc     ebx
   411 00000C9C 43                  <1> 	inc	ebx			; MOVE TO NEXT WORD IN LIST
   412 00000C9D 3B1D[DAE80000]      <1>         cmp     ebx, [BUFFER_END] 	; AT END OF BUFFER?
   413                              <1>         ;jne    short _K5               ; NO, CONTINUE
   414 00000CA3 7206                <1> 	jb	short _K5
   415 00000CA5 8B1D[D6E80000]      <1>         mov     ebx, [BUFFER_START]     ; YES, RESET TO BUFFER BEGINNING
   416                              <1> _K5:
   417 00000CAB C3                  <1> 	retn
   418                              <1> 
   419                              <1> ; 20/02/2015
   420                              <1> ; 05/12/2014
   421                              <1> ; 26/08/2014
   422                              <1> ; KEYBOARD (HARDWARE) INTERRUPT -  IRQ LEVEL 1
   423                              <1> ; (INT_09h - Retro UNIX 8086 v1 - U9.ASM, 07/03/2014)
   424                              <1> ;
   425                              <1> ; Derived from "KB_INT_1" procedure of IBM "pc-at" 
   426                              <1> ; rombios source code (06/10/1985)
   427                              <1> ; 'keybd.asm', HARDWARE INT 09h - (IRQ Level 1)
   428                              <1> 
   429                              <1> ; EQUATES (IBM PC-XT-286 BIOS, 1986, 'POSQEQU.INC')
   430                              <1> 
   431                              <1> ;--------- 8042 COMMANDS -------------------------------------------------------
   432                              <1> ENA_KBD		equ	0AEh		; ENABLE KEYBOARD COMMAND
   433                              <1> DIS_KBD		equ	0ADh		; DISABLE KEYBOARD COMMAND
   434                              <1> SHUT_CMD	equ	0FEh		; CAUSE A SHUTDOWN COMMAND
   435                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   436                              <1> STATUS_PORT	equ	064h		; 8042 STATUS PORT
   437                              <1> INPT_BUF_FULL	equ	00000010b 	; 1 = +INPUT BUFFER FULL
   438                              <1> PORT_A		equ	060h		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   439                              <1> ;---------- 8042 KEYBOARD RESPONSE ---------------------------------------------
   440                              <1> KB_ACK		equ	0FAh		; ACKNOWLEDGE PROM TRANSMISSION
   441                              <1> KB_RESEND	equ	0FEh		; RESEND REQUEST
   442                              <1> KB_OVER_RUN	equ	0FFh		; OVER RUN SCAN CODE
   443                              <1> ;---------- KEYBOARD/LED COMMANDS ----------------------------------------------
   444                              <1> KB_ENABLE	equ	0F4h		; KEYBOARD ENABLE
   445                              <1> LED_CMD		equ	0EDh		; LED WRITE COMMAND
   446                              <1> KB_TYPA_RD	equ	0F3h		; TYPAMATIC RATE/DELAY COMMAND
   447                              <1> ;---------- KEYBOARD SCAN CODES ------------------------------------------------
   448                              <1> NUM_KEY		equ	69		; SCAN CODE FOR	 NUMBER LOCK KEY
   449                              <1> SCROLL_KEY	equ	70		; SCAN CODE FOR	 SCROLL LOCK KEY
   450                              <1> ALT_KEY		equ	56		; SCAN CODE FOR	 ALTERNATE SHIFT KEY
   451                              <1> CTL_KEY		equ	29		; SCAN CODE FOR	 CONTROL KEY
   452                              <1> CAPS_KEY	equ	58		; SCAN CODE FOR	 SHIFT LOCK KEY
   453                              <1> DEL_KEY		equ	83		; SCAN CODE FOR	 DELETE KEY
   454                              <1> INS_KEY		equ	82		; SCAN CODE FOR	 INSERT KEY
   455                              <1> LEFT_KEY	equ	42		; SCAN CODE FOR	 LEFT SHIFT
   456                              <1> RIGHT_KEY	equ	54		; SCAN CODE FOR	 RIGHT SHIFT
   457                              <1> SYS_KEY		equ	84		; SCAN CODE FOR	 SYSTEM KEY
   458                              <1> ;---------- ENHANCED KEYBOARD SCAN CODES ---------------------------------------
   459                              <1> ID_1		equ	0ABh		; 1ST ID CHARACTER FOR KBX
   460                              <1> ID_2		equ	041h		; 2ND ID CHARACTER FOR KBX
   461                              <1> ID_2A		equ	054h		; ALTERNATE 2ND ID CHARACTER FOR KBX
   462                              <1> F11_M		equ	87		; F11 KEY MAKE
   463                              <1> F12_M		equ	88		; F12 KEY MAKE
   464                              <1> MC_E0		equ	224		; GENERAL MARKER CODE
   465                              <1> MC_E1		equ	225		; PAUSE KEY MARKER CODE
   466                              <1> ;---------- FLAG EQUATES WITHIN @KB_FLAG----------------------------------------
   467                              <1> RIGHT_SHIFT	equ	00000001b	; RIGHT SHIFT KEY DEPRESSED
   468                              <1> LEFT_SHIFT	equ	00000010b	; LEFT SHIFT KEY DEPRESSED
   469                              <1> CTL_SHIFT	equ	00000100b	; CONTROL SHIFT KEY DEPRESSED
   470                              <1> ALT_SHIFT	equ	00001000b	; ALTERNATE SHIFT KEY DEPRESSED
   471                              <1> SCROLL_STATE	equ	00010000b	; SCROLL LOCK STATE IS ACTIVE
   472                              <1> NUM_STATE	equ	00100000b	; NUM LOCK STATE IS ACTIVE
   473                              <1> CAPS_STATE	equ	01000000b	; CAPS LOCK STATE IS ACTIVE
   474                              <1> INS_STATE	equ	10000000b	; INSERT STATE IS ACTIVE
   475                              <1> ;---------- FLAG EQUATES WITHIN	@KB_FLAG_1 -------------------------------------
   476                              <1> L_CTL_SHIFT	equ	00000001b	; LEFT CTL KEY DOWN
   477                              <1> L_ALT_SHIFT	equ	00000010b	; LEFT ALT KEY DOWN
   478                              <1> SYS_SHIFT	equ	00000100b	; SYSTEM KEY DEPRESSED AND HELD
   479                              <1> HOLD_STATE	equ	00001000b	; SUSPEND KEY HAS BEEN TOGGLED
   480                              <1> SCROLL_SHIFT	equ	00010000b	; SCROLL LOCK KEY IS DEPRESSED
   481                              <1> NUM_SHIFT	equ	00100000b	; NUM LOCK KEY IS DEPRESSED
   482                              <1> CAPS_SHIFT	equ	01000000b	; CAPS LOCK KEY IS DEPRE55ED
   483                              <1> INS_SHIFT	equ	10000000b	; INSERT KEY IS DEPRESSED
   484                              <1> ;---------- FLAGS EQUATES WITHIN @KB_FLAG_2 -----------------------------------
   485                              <1> KB_LEDS		equ	00000111b	; KEYBOARD LED STATE BITS
   486                              <1> ;		equ	00000001b	; SCROLL LOCK INDICATOR
   487                              <1> ;		equ	00000010b	; NUM LOCK INDICATOR
   488                              <1> ;		equ	00000100b	; CAPS LOCK INDICATOR
   489                              <1> ;		equ	00001000b	; RESERVED (MUST BE ZERO)
   490                              <1> KB_FA		equ	00010000b	; ACKNOWLEDGMENT RECEIVED
   491                              <1> KB_FE		equ	00100000b	; RESEND RECEIVED FLAG
   492                              <1> KB_PR_LED	equ	01000000b	; MODE INDICATOR UPDATE
   493                              <1> KB_ERR		equ	10000000b	; KEYBOARD TRANSMIT ERROR FLAG
   494                              <1> ;----------- FLAGS EQUATES WITHIN @KB_FLAG_3 -----------------------------------
   495                              <1> LC_E1		equ	00000001b	; LAST CODE WAS THE E1 HIDDEN CODE
   496                              <1> LC_E0		equ	00000010b	; LAST CODE WAS THE E0 HIDDEN CODE
   497                              <1> R_CTL_SHIFT	equ	00000100b	; RIGHT CTL KEY DOWN
   498                              <1> R_ALT_SHIFT	equ	00001000b	; RIGHT ALT KEY DOWN
   499                              <1> GRAPH_ON	equ	00001000b	; ALT GRAPHICS KEY DOWN (WT ONLY)	
   500                              <1> KBX		equ	00010000b	; ENHANCED KEYBOARD INSTALLED
   501                              <1> SET_NUM_LK	equ	00100000b	; FORCE NUM LOCK IF READ ID AND KBX
   502                              <1> LC_AB		equ	01000000b	; LAST CHARACTER WAS FIRST ID CHARACTER
   503                              <1> RD_ID		equ	10000000b	; DOING A READ ID (MUST BE BIT0)
   504                              <1> ;
   505                              <1> ;----------- INTERRUPT EQUATES -------------------------------------------------
   506                              <1> EOI		equ	020h		; END OF INTERRUPT COMMAND TO 8259
   507                              <1> INTA00		equ	020h		; 8259 PORT
   508                              <1> 
   509                              <1> 
   510                              <1> kb_int:
   511                              <1> 
   512                              <1> ; 17/10/2015 ('ctrlbrk') 
   513                              <1> ; 05/12/2014
   514                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-)
   515                              <1> ; 26/08/2014
   516                              <1> ;
   517                              <1> ; 03/06/86  KEYBOARD BIOS
   518                              <1> ;
   519                              <1> ;--- HARDWARE INT 09H -- (IRQ LEVEL 1) ------------------------------------------
   520                              <1> ;										;
   521                              <1> ;	KEYBOARD INTERRUPT ROUTINE						;
   522                              <1> ;										;
   523                              <1> ;--------------------------------------------------------------------------------
   524                              <1> 
   525                              <1> KB_INT_1:
   526 00000CAC FB                  <1> 	sti				; ENABLE INTERRUPTS
   527                              <1> 	;push	ebp
   528 00000CAD 50                  <1> 	push	eax
   529 00000CAE 53                  <1> 	push	ebx
   530 00000CAF 51                  <1> 	push	ecx
   531 00000CB0 52                  <1> 	push	edx
   532 00000CB1 56                  <1> 	push	esi
   533 00000CB2 57                  <1> 	push	edi
   534 00000CB3 1E                  <1> 	push	ds
   535 00000CB4 06                  <1> 	push	es
   536 00000CB5 FC                  <1> 	cld				; FORWARD DIRECTION
   537 00000CB6 66B81000            <1> 	mov	ax, KDATA
   538 00000CBA 8ED8                <1> 	mov	ds, ax
   539 00000CBC 8EC0                <1> 	mov	es, ax
   540                              <1> 	;
   541                              <1> 	;-----	WAIT FOR KEYBOARD DISABLE COMMAND TO BE ACCEPTED
   542 00000CBE B0AD                <1> 	mov	al, DIS_KBD		; DISABLE THE KEYBOARD COMMAND
   543 00000CC0 E8A9050000          <1> 	call	SHIP_IT			; EXECUTE DISABLE
   544 00000CC5 FA                  <1> 	cli				; DISABLE INTERRUPTS
   545 00000CC6 B900000100          <1> 	mov	ecx, 10000h		; SET MAXIMUM TIMEOUT
   546                              <1> KB_INT_01:
   547 00000CCB E464                <1> 	in	al, STATUS_PORT		; READ ADAPTER STATUS
   548 00000CCD A802                <1> 	test	al, INPT_BUF_FULL	; CHECK INPUT BUFFER FULL STATUS BIT
   549 00000CCF E0FA                <1> 	loopnz	KB_INT_01		; WAIT FOR COMMAND TO BE ACCEPTED
   550                              <1> 	;
   551                              <1> 	;-----	READ CHARACTER FROM KEYBOARD INTERFACE
   552 00000CD1 E460                <1> 	in	al, PORT_A		; READ IN THE CHARACTER
   553                              <1> 	;
   554                              <1> 	;-----	SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INT LEVEL 9H) 	
   555                              <1> 	;MOV	AH, 04FH		; SYSTEM INTERCEPT - KEY CODE FUNCTION
   556                              <1> 	;STC				; SET CY=1 (IN CASE OF IRET)
   557                              <1> 	;INT	15H			; CASETTE CALL (AL)=KEY SCAN CODE
   558                              <1> 	;				; RETURNS CY=1 FOR INVALID FUNCTION
   559                              <1> 	;JC	KB_INT_02		; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
   560                              <1> 	;JMP	K26			; EXIT IF SYSTEM HANDLES SCAN CODE
   561                              <1> 	;				; EXT HANDLES HARDWARE EOI AND ENABLE		
   562                              <1> 	;
   563                              <1> 	;-----	CHECK FOR A RESEND COMMAND TO KEYBOARD
   564                              <1> KB_INT_02:				; 	  (AL)= SCAN CODE
   565 00000CD3 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
   566 00000CD4 3CFE                <1> 	cmp	al, KB_RESEND		; IS THE INPUT A RESEND
   567 00000CD6 7411                <1>         je      short KB_INT_4          ; GO IF RESEND
   568                              <1> 	;
   569                              <1> 	;-----	CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
   570 00000CD8 3CFA                <1> 	cmp	al, KB_ACK		; IS THE INPUT AN ACKNOWLEDGE
   571 00000CDA 751A                <1>         jne     short KB_INT_2          ; GO IF NOT
   572                              <1> 	;
   573                              <1> 	;-----	A COMMAND TO THE KEYBOARD WAS ISSUED
   574 00000CDC FA                  <1> 	cli				; DISABLE INTERRUPTS
   575 00000CDD 800D[D3E80000]10    <1> 	or	byte [KB_FLAG_2], KB_FA ; INDICATE ACK RECEIVED
   576 00000CE4 E97A020000          <1>         jmp     K26                     ; RETURN IF NOT (ACK RETURNED FOR DATA)
   577                              <1> 	;
   578                              <1> 	;-----	RESEND THE LAST BYTE
   579                              <1> KB_INT_4:
   580 00000CE9 FA                  <1> 	cli				; DISABLE INTERRUPTS
   581 00000CEA 800D[D3E80000]20    <1> 	or	byte [KB_FLAG_2], KB_FE ; INDICATE RESEND RECEIVED
   582 00000CF1 E96D020000          <1>         jmp     K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
   583                              <1> 	;
   584                              <1> ;-----	UPDATE MODE INDICATORS IF CHANGE IN STATE
   585                              <1> KB_INT_2:
   586 00000CF6 6650                <1> 	push 	ax			; SAVE DATA IN
   587 00000CF8 E83D060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   588 00000CFD 8A1D[D3E80000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   589 00000D03 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   590 00000D05 80E307              <1> 	and	bl, KB_LEDS		; ISOLATE INDICATOR BITS
   591 00000D08 7405                <1> 	jz	short UP0		; IF NO CHANGE BYPASS UPDATE
   592 00000D0A E8C0050000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   593                              <1> UP0:
   594 00000D0F 6658                <1> 	pop	ax			; RESTORE DATA IN
   595                              <1> ;------------------------------------------------------------------------
   596                              <1> ;	START OF KEY PROCESSING						;
   597                              <1> ;------------------------------------------------------------------------
   598 00000D11 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE IN AH ALSO
   599                              <1> 	;
   600                              <1> 	;-----	TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
   601 00000D13 3CFF                <1> 	cmp	al, KB_OVER_RUN		; IS THIS AN OVERRUN CHAR
   602 00000D15 0F843F050000        <1>         je      K62			; BUFFER_FULL_BEEP
   603                              <1> 	;
   604                              <1> K16:	
   605 00000D1B 8A3D[D4E80000]      <1> 	mov	bh, [KB_FLAG_3]		; LOAD FLAGS FOR TESTING
   606                              <1> 	;
   607                              <1> 	;-----	TEST TO SEE IF A READ_ID IS IN PROGRESS
   608 00000D21 F6C7C0              <1> 	test 	bh, RD_ID+LC_AB 	; ARE WE DOING A READ ID?
   609 00000D24 7449                <1> 	jz	short NOT_ID		; CONTINUE IF NOT
   610 00000D26 7917                <1> 	jns	short TST_ID_2		; IS THE RD_ID FLAG ON?
   611 00000D28 3CAB                <1> 	cmp	al, ID_1		; IS THIS THE 1ST ID CHARACTER?
   612 00000D2A 7507                <1> 	jne	short RST_RD_ID
   613 00000D2C 800D[D4E80000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
   614                              <1> RST_RD_ID:
   615 00000D33 8025[D4E80000]7F    <1> 	and	byte [KB_FLAG_3], ~RD_ID ; RESET THE READ ID FLAG
   616                              <1>         ;jmp    short ID_EX		; AND EXIT
   617 00000D3A E924020000          <1> 	jmp	K26
   618                              <1> 	;
   619                              <1> TST_ID_2:
   620 00000D3F 8025[D4E80000]BF    <1> 	and	byte [KB_FLAG_3], ~LC_AB ; RESET FLAG
   621 00000D46 3C54                <1> 	cmp	al, ID_2A		; IS THIS THE 2ND ID CHARACTER?
   622 00000D48 7419                <1>         je	short KX_BIT		; JUMP IF SO
   623 00000D4A 3C41                <1> 	cmp	al, ID_2		; IS THIS THE 2ND ID CHARACTER?
   624                              <1>         ;jne	short ID_EX		; LEAVE IF NOT
   625 00000D4C 0F8511020000        <1> 	jne	K26
   626                              <1> 	;
   627                              <1> 	;-----	A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
   628 00000D52 F6C720              <1> 	test	bh, SET_NUM_LK 		; SHOULD WE SET NUM LOCK?
   629 00000D55 740C                <1>         jz      short KX_BIT		; EXIT IF NOT
   630 00000D57 800D[D1E80000]20    <1> 	or	byte [KB_FLAG], NUM_STATE ; FORCE NUM LOCK ON
   631 00000D5E E86C050000          <1> 	call	SND_LED			; GO SET THE NUM LOCK INDICATOR
   632                              <1> KX_BIT:
   633 00000D63 800D[D4E80000]10    <1> 	or	byte [KB_FLAG_3], KBX	; INDICATE ENHANCED KEYBOARD WAS FOUND
   634 00000D6A E9F4010000          <1> ID_EX:	jmp     K26			; EXIT
   635                              <1> 	;
   636                              <1> NOT_ID:
   637 00000D6F 3CE0                <1> 	cmp	al, MC_E0		; IS THIS THE GENERAL MARKER CODE?
   638 00000D71 750C                <1> 	jne	short TEST_E1
   639 00000D73 800D[D4E80000]12    <1> 	or	byte [KB_FLAG_3], LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
   640                              <1> 	;jmp	short EXIT		; THROW AWAY THIS CODE
   641 00000D7A E9EB010000          <1> 	jmp	K26A	
   642                              <1> TEST_E1:	
   643 00000D7F 3CE1                <1> 	cmp	al, MC_E1		; IS THIS THE PAUSE KEY?
   644 00000D81 750C                <1> 	jne	short NOT_HC
   645 00000D83 800D[D4E80000]11    <1> 	or	byte [KB_FLAG_3], LC_E1+KBX ; SET FLAG BIT, SET KBX, AND
   646 00000D8A E9DB010000          <1> EXIT:	jmp	K26A			; THROW AWAY THIS CODE
   647                              <1> 	;
   648                              <1> NOT_HC:
   649 00000D8F 247F                <1> 	and	al, 07Fh		; TURN OFF THE BREAK BIT
   650 00000D91 F6C702              <1> 	test	bh, LC_E0		; LAST CODE THE E0 MARKER CODE
   651 00000D94 7414                <1> 	jz	short NOT_LC_E0		; JUMP IF NOT
   652                              <1> 	;
   653 00000D96 BF[BEE70000]        <1> 	mov	edi, _K6+6		; IS THIS A SHIFT KEY?
   654 00000D9B AE                  <1> 	scasb
   655 00000D9C 0F84C1010000        <1>         je      K26 ; K16B              ; YES, THROW AWAY & RESET FLAG
   656 00000DA2 AE                  <1> 	scasb
   657 00000DA3 757C                <1> 	jne	short K16A		; NO, CONTINUE KEY PROCESSING
   658                              <1> 	;jmp	short K16B		; YES, THROW AWAY & RESET FLAG
   659 00000DA5 E9B9010000          <1> 	jmp	K26
   660                              <1> 	;
   661                              <1> NOT_LC_E0:
   662 00000DAA F6C701              <1> 	test	bh, LC_E1		; LAST CODE THE E1 MARKER CODE?
   663 00000DAD 7435                <1> 	jz	short T_SYS_KEY		; JUMP IF NOT
   664 00000DAF B904000000          <1> 	mov	ecx, 4			; LENGHT OF SEARCH
   665 00000DB4 BF[BCE70000]        <1> 	mov	edi, _K6+4		; IS THIS AN ALT, CTL, OR SHIFT?
   666 00000DB9 F2AE                <1> 	repne	scasb			; CHECK IT
   667                              <1> 	;je	short EXIT		; THROW AWAY IF SO
   668 00000DBB 0F84A9010000        <1> 	je	K26A			
   669                              <1> 	;
   670 00000DC1 3C45                <1> 	cmp	al, NUM_KEY		; IS IT THE PAUSE KEY?
   671                              <1> 	;jne	short K16B		; NO, THROW AWAY & RESET FLAG
   672 00000DC3 0F859A010000        <1> 	jne	K26
   673 00000DC9 F6C480              <1> 	test	ah, 80h			; YES, IS IT THE BREAK OF THE KEY?
   674                              <1> 	;jnz	short K16B		; YES, THROW THIS AWAY, TOO	
   675 00000DCC 0F8591010000        <1> 	jnz	K26
   676                              <1>         ; 20/02/2015 
   677 00000DD2 F605[D2E80000]08    <1> 	test	byte [KB_FLAG_1],HOLD_STATE ;  NO, ARE WE PAUSED ALREADY?
   678                              <1> 	;jnz	short K16B		;  YES, THROW AWAY
   679 00000DD9 0F8584010000        <1> 	jnz	K26
   680 00000DDF E9E1020000          <1> 	jmp     K39P                    ; NO, THIS IS THE REAL PAUSE STATE
   681                              <1> 	;
   682                              <1> 	;-----	TEST FOR SYSTEM KEY
   683                              <1> T_SYS_KEY:
   684 00000DE4 3C54                <1> 	cmp	al, SYS_KEY		; IS IT THE SYSTEM KEY?
   685 00000DE6 7539                <1> 	jnz	short K16A		; CONTINUE IF NOT
   686                              <1> 	;
   687 00000DE8 F6C480              <1> 	test	ah, 80h			; CHECK IF THIS A BREAK CODE
   688 00000DEB 7524                <1> 	jnz	short K16C		; DO NOT TOUCH SYSTEM INDICATOR IF TRUE
   689                              <1> 	;
   690 00000DED F605[D2E80000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN 
   691                              <1>         ;jnz	short K16B		; IF YES, DO NOT PROCESS SYSTEM INDICATOR	
   692 00000DF4 0F8569010000        <1> 	jnz     K26			
   693                              <1> 	;
   694 00000DFA 800D[D2E80000]04    <1> 	or	byte [KB_FLAG_1], SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
   695 00000E01 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   696 00000E03 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   697                              <1> 					; INTERRUPT-RETURN-NO-EOI
   698 00000E05 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   699 00000E07 E862040000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   700                              <1> 	; !!! SYSREQ !!! function/system call (INTERRUPT) must be here !!!
   701                              <1> 	;MOV	AL, 8500H		; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
   702                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   703                              <1> 	;INT	15H			; USER INTERRUPT	
   704 00000E0C E965010000          <1>         jmp     K27A                    ; END PROCESSING
   705                              <1> 	;
   706                              <1> ;K16B:	jmp	K26			; IGNORE SYSTEM KEY
   707                              <1> 	;
   708                              <1> K16C:
   709 00000E11 8025[D2E80000]FB    <1> 	and	byte [KB_FLAG_1], ~SYS_SHIFT ; TURN OFF SHIFT KEY HELD DOWN
   710 00000E18 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   711 00000E1A E620                <1> 	out	20h, al ;out INTA00, al ; SEND COMMAND TO INTERRUPT CONTROL PORT
   712                              <1> 					; INTERRUPT-RETURN-NO-EOI
   713                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   714                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
   715                              <1> 	;
   716                              <1> 	;MOV	AX, 8501H		; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
   717                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   718                              <1> 	;INT	15H			; USER INTERRUPT
   719                              <1> 	;JMP	K27A			; INGONRE SYSTEM KEY				
   720                              <1> 	;
   721 00000E1C E94E010000          <1> 	jmp     K27			; IGNORE SYSTEM KEY
   722                              <1> 	;
   723                              <1> 	;-----	TEST FOR SHIFT KEYS
   724                              <1> K16A:
   725 00000E21 8A1D[D1E80000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
   726 00000E27 BF[B8E70000]        <1> 	mov	edi, _K6		; SHIFT KEY TABLE offset
   727 00000E2C B908000000          <1> 	mov	ecx, _K6L		; LENGTH
   728 00000E31 F2AE                <1> 	repne	scasb			; LOOK THROUGH THE TABLE FOR A MATCH
   729 00000E33 88E0                <1> 	mov	al, ah			; RECOVER SCAN CODE
   730 00000E35 0F8510010000        <1>         jne     K25                     ; IF NO MATCH, THEN SHIFT NOT FOUND
   731                              <1> 	;
   732                              <1> 	;------	SHIFT KEY FOUND
   733                              <1> K17:
   734 00000E3B 81EF[B9E70000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
   735 00000E41 8AA7[C0E70000]      <1>        	mov     ah, [edi+_K7]       	; GET MASK INTO AH
   736 00000E47 B102                <1> 	mov	cl, 2			; SETUP COUNT FOR FLAG SHIFTS
   737 00000E49 A880                <1> 	test	al, 80h			; TEST FOR BREAK KEY
   738 00000E4B 0F8596000000        <1>         jnz     K23                     ; JUMP OF BREAK
   739                              <1> 	;
   740                              <1> 	;-----	SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
   741                              <1> K17C:
   742 00000E51 80FC10              <1> 	cmp	ah, SCROLL_SHIFT
   743 00000E54 732B                <1> 	jae	short K18		; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
   744                              <1> 	;
   745                              <1> 	;-----	PLAIN SHIFT KEY, SET SHIFT ON
   746 00000E56 0825[D1E80000]      <1> 	or	[KB_FLAG], ah		; TURN ON SHIFT BIT
   747 00000E5C A80C                <1>         test	al, CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
   748                              <1> 	;jnz	short K17D		; YES, MORE FLAGS TO SET
   749 00000E5E 0F84FF000000        <1> 	jz	K26			; NO, INTERRUPT RETURN
   750                              <1> K17D:
   751 00000E64 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF NEW KEYS?
   752 00000E67 740B                <1> 	jz 	short K17E		; NO, JUMP
   753 00000E69 0825[D4E80000]      <1> 	or	[KB_FLAG_3], ah		; SET BITS FOR RIGHT CTRL, ALT
   754 00000E6F E9EF000000          <1> 	jmp	K26			; INTERRUPT RETURN
   755                              <1> K17E:
   756 00000E74 D2EC                <1> 	shr	ah, cl			; MOVE FLAG BITS TWO POSITIONS
   757 00000E76 0825[D2E80000]      <1> 	or	[KB_FLAG_1], ah		; SET BITS FOR LEFT CTRL, ALT
   758 00000E7C E9E2000000          <1> 	jmp	K26
   759                              <1> 	;
   760                              <1> 	;-----	TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
   761                              <1> K18:					; SHIFT-TOGGLE
   762 00000E81 F6C304              <1> 	test	bl, CTL_SHIFT 		; CHECK CTL SHIFT STATE
   763                              <1>         ;jz    	short K18A              ; JUMP IF NOT CTL STATE
   764 00000E84 0F85C1000000        <1>         jnz     K25                     ; JUMP IF CTL STATE
   765                              <1> K18A:
   766 00000E8A 3C52                <1> 	cmp	al, INS_KEY		; CHECK FOR INSERT KEY
   767 00000E8C 7524                <1> 	jne	short K22		; JUMP IF NOT INSERT KEY
   768 00000E8E F6C308              <1> 	test	bl, ALT_SHIFT 		; CHECK FOR ALTERNATE SHIFT
   769                              <1>       	;jz	short K18B		; JUMP IF NOT ALTERNATE SHIFT	
   770 00000E91 0F85B4000000        <1>         jnz     K25                     ; JUMP IF ALTERNATE SHIFT
   771                              <1> K18B:
   772 00000E97 F6C702              <1> 	test	bh, LC_E0 ;20/02/2015	; IS THIS NEW INSERT KEY?
   773 00000E9A 7516                <1> 	jnz	short K22		; YES, THIS ONE'S NEVER A '0'
   774                              <1> K19:	
   775 00000E9C F6C320              <1> 	test	bl, NUM_STATE 		; CHECK FOR BASE STATE
   776 00000E9F 750C                <1> 	jnz	short K21		; JUMP IF NUM LOCK IS ON
   777 00000EA1 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
   778 00000EA4 740C                <1> 	jz	short K22		; JUMP IF BASE STATE
   779                              <1> K20:					; NUMERIC ZERO, NOT INSERT KEY
   780 00000EA6 88C4                <1> 	mov	ah, al			; PUT SCAN CODE BACK IN AH
   781 00000EA8 E99E000000          <1>         jmp     K25                     ; NUMERAL '0', STNDRD. PROCESSING
   782                              <1> K21:					; MIGHT BE NUMERIC
   783 00000EAD F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT
   784 00000EB0 74F4                <1> 	jz	short K20		; IS NUMERIC, STD. PROC.
   785                              <1> 	;
   786                              <1> K22:					; SHIFT TOGGLE KEY HIT; PROCESS IT
   787 00000EB2 8425[D2E80000]      <1> 	test	ah, [KB_FLAG_1] 	; IS KEY ALREADY DEPRESSED
   788 00000EB8 0F85A5000000        <1>         jnz     K26                     ; JUMP IF KEY ALREADY DEPRESSED
   789                              <1> K22A:
   790 00000EBE 0825[D2E80000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
   791 00000EC4 3025[D1E80000]      <1> 	xor	[KB_FLAG], ah		; TOGGLE THE SHIFT STATE
   792                              <1> 	;
   793                              <1> 	;-----	TOGGLE LED IF CAPS, NUM  OR SCROLL KEY DEPRESSED
   794 00000ECA F6C470              <1> 	test	ah, CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
   795 00000ECD 7409                <1> 	jz	short K22B		; GO IF NOT
   796                              <1> 	;
   797 00000ECF 6650                <1> 	push	ax			; SAVE SCAN CODE AND SHIFT MASK
   798 00000ED1 E8F9030000          <1> 	call	SND_LED			; GO TURN MODE INDICATORS ON
   799 00000ED6 6658                <1> 	pop	ax			; RESTORE SCAN CODE
   800                              <1> K22B:
   801 00000ED8 3C52                <1> 	cmp	al, INS_KEY		; TEST FOR 1ST MAKE OF INSERT KEY
   802 00000EDA 0F8583000000        <1>         jne     K26                     ; JUMP IF NOT INSERT KEY
   803 00000EE0 88C4                <1> 	mov	ah, al		        ; SCAN CODE IN BOTH HALVES OF AX
   804 00000EE2 E999000000          <1>         jmp     K28                     ; FLAGS UPDATED, PROC. FOR BUFFER
   805                              <1> 	;
   806                              <1> 	;-----	BREAK SHIFT FOUND
   807                              <1> K23:					; BREAK-SHIFT-FOUND
   808 00000EE7 80FC10              <1> 	cmp	ah, SCROLL_SHIFT	; IS THIS A TOGGLE KEY
   809 00000EEA F6D4                <1> 	not	ah			; INVERT MASK
   810 00000EEC 7355                <1> 	jae	short K24		; YES, HANDLE BREAK TOGGLE
   811 00000EEE 2025[D1E80000]      <1> 	and	[KB_FLAG], ah		; TURN OFF SHIFT BIT
   812 00000EF4 80FCFB              <1> 	cmp	ah, ~CTL_SHIFT		; IS THIS ALT OR CTL?
   813 00000EF7 7730                <1> 	ja	short K23D		; NO, ALL DONE
   814                              <1> 	;
   815 00000EF9 F6C702              <1> 	test	bh, LC_E0		; 2ND ALT OR CTL?
   816 00000EFC 7408                <1> 	jz	short K23A		; NO, HANSLE NORMALLY
   817 00000EFE 2025[D4E80000]      <1> 	and 	[KB_FLAG_3], ah		; RESET BIT FOR RIGHT ALT OR CTL
   818 00000F04 EB08                <1> 	jmp	short K23B		; CONTINUE
   819                              <1> K23A:
   820 00000F06 D2FC                <1> 	sar	ah, cl			; MOVE THE MASK BIT TWO POSITIONS
   821 00000F08 2025[D2E80000]      <1> 	and	[KB_FLAG_1], ah		; RESET BIT FOR LEFT ALT AND CTL
   822                              <1> K23B:
   823 00000F0E 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE
   824 00000F10 A0[D4E80000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT ALT & CTRL FLAGS
   825 00000F15 D2E8                <1> 	shr	al, cl			; MOVE TO BITS 1 & 0
   826 00000F17 0A05[D2E80000]      <1> 	or	al, [KB_FLAG_1]		; PUT IN LEFT ALT & CTL FLAGS
   827 00000F1D D2E0                <1> 	shl	al, cl			; MOVE BACK TO BITS 3 & 2
   828 00000F1F 240C                <1> 	and	al, ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
   829 00000F21 0805[D1E80000]      <1> 	or	[KB_FLAG], al		; PUT RESULT IN THE REAL FLAGS	
   830 00000F27 88E0                <1> 	mov	al, ah
   831                              <1> K23D:
   832 00000F29 3CB8                <1> 	cmp	al, ALT_KEY+80h		; IS THIS ALTERNATE SHIFT RELEASE
   833 00000F2B 7536                <1> 	jne	short K26		; INTERRUPT RETURN
   834                              <1> 	;	
   835                              <1> 	;-----	ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
   836 00000F2D A0[D5E80000]        <1> 	mov	al, [ALT_INPUT]
   837 00000F32 B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
   838 00000F34 8825[D5E80000]      <1> 	mov	[ALT_INPUT], ah 	; ZERO OUT THE FIELD
   839 00000F3A 3C00                <1> 	cmp	al, 0			; WAS THE INPUT = 0?
   840 00000F3C 7425                <1> 	je	short K26		; INTERRUPT_RETURN
   841                              <1>         ; 29/01/2016
   842                              <1> 	;jmp     K61                    ; IT WASN'T, SO PUT IN BUFFER
   843 00000F3E E9D0020000          <1> 	jmp	_K60
   844                              <1> 	;
   845                              <1> K24:					; BREAK-TOGGLE
   846 00000F43 2025[D2E80000]      <1> 	and	[KB_FLAG_1], ah 	; INDICATE NO LONGER DEPRESSED
   847 00000F49 EB18                <1> 	jmp	short K26		; INTERRUPT_RETURN
   848                              <1> 	;
   849                              <1> 	;-----	TEST FOR HOLD STATE
   850                              <1> 					; AL, AH = SCAN CODE
   851                              <1> K25:					; NO-SHIFT-FOUND
   852 00000F4B 3C80                <1> 	cmp	al, 80h			; TEST FOR BREAK KEY
   853 00000F4D 7314                <1> 	jae	short K26		; NOTHING FOR BREAK CHARS FROM HERE ON
   854 00000F4F F605[D2E80000]08    <1> 	test	byte [KB_FLAG_1], HOLD_STATE ; ARE WE IN HOLD STATE
   855 00000F56 7428                <1> 	jz	short K28		; BRANCH AROUND TEST IF NOT
   856 00000F58 3C45                <1> 	cmp	al, NUM_KEY
   857 00000F5A 7407                <1> 	je	short K26		; CAN'T END HOLD ON NUM_LOCK
   858 00000F5C 8025[D2E80000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
   859                              <1> 	;
   860                              <1> K26:
   861 00000F63 8025[D4E80000]FC    <1> 	and	byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
   862                              <1> K26A:					; INTERRUPT-RETURN
   863 00000F6A FA                  <1> 	cli				; TURN OFF INTERRUPTS
   864 00000F6B B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   865 00000F6D E620                <1> 	out	20h, al	;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   866                              <1> K27:					; INTERRUPT-RETURN-NO-EOI
   867 00000F6F B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   868 00000F71 E8F8020000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   869                              <1> K27A:
   870 00000F76 FA                  <1> 	cli				; DISABLE INTERRUPTS
   871 00000F77 07                  <1> 	pop	es			; RESTORE REGISTERS
   872 00000F78 1F                  <1> 	pop	ds
   873 00000F79 5F                  <1> 	pop	edi
   874 00000F7A 5E                  <1> 	pop	esi
   875 00000F7B 5A                  <1> 	pop	edx
   876 00000F7C 59                  <1> 	pop	ecx
   877 00000F7D 5B                  <1> 	pop	ebx
   878 00000F7E 58                  <1> 	pop	eax
   879                              <1> 	;pop	ebp
   880 00000F7F CF                  <1> 	iret				; RETURN
   881                              <1> 
   882                              <1> 	;-----	NOT IN	HOLD STATE
   883                              <1> K28:					; NO-HOLD-STATE
   884 00000F80 3C58                <1> 	cmp	al, 88			; TEST FOR OUT-OF-RANGE SCAN CODES
   885 00000F82 77DF                <1> 	ja	short K26		; IGNORE IF OUT-OF-RANGE	
   886                              <1> 	;
   887 00000F84 F6C308              <1> 	test	bl, ALT_SHIFT 		; ARE WE IN ALTERNATE SHIFT
   888                              <1>         ;jz	short K28A		; IF NOT ALTERNATE
   889 00000F87 0F84F1000000        <1>         jz      K38
   890                              <1> 	;
   891 00000F8D F6C710              <1> 	test	bh, KBX			; IS THIS THE ENCHANCED KEYBOARD?
   892 00000F90 740D                <1> 	jz	short K29		; NO, ALT STATE IS REAL
   893                              <1> 	 ;28/02/2015
   894 00000F92 F605[D2E80000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
   895                              <1> 	;jz	short K29		;  NO, ALT STATE IS REAL
   896 00000F99 0F85DF000000        <1> 	jnz	K38			; YES, THIS IS PHONY ALT STATE 
   897                              <1>         ;				; DUE TO PRESSING SYSREQ	
   898                              <1> ;K28A:	jmp	short K38
   899                              <1> 	;
   900                              <1> 	;-----	TEST FOR RESET KEY SEQUENCE (CTL ALT DEL)
   901                              <1> K29:					; TEST-RESET
   902 00000F9F F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT ALSO?
   903 00000FA2 740B                <1> 	jz	short K31		; NO_RESET
   904 00000FA4 3C53                <1> 	cmp	al, DEL_KEY		; CTL-ALT STATE, TEST FOR DELETE KEY
   905 00000FA6 7507                <1> 	jne	short K31		; NO_RESET, IGNORE
   906                              <1> 	;
   907                              <1> 	;-----	CTL-ALT-DEL HAS BEEN FOUND
   908                              <1>  	; 26/08/2014
   909                              <1> cpu_reset:
   910                              <1> 	; IBM PC/AT ROM BIOS source code - 10/06/85 (TEST4.ASM - PROC_SHUTDOWN)
   911                              <1> 	; Send FEh (system reset command) to the keyboard controller.
   912 00000FA8 B0FE                <1> 	mov	al, SHUT_CMD		; SHUTDOWN COMMAND
   913 00000FAA E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROL PORT
   914                              <1> khere:
   915 00000FAC F4                  <1> 	hlt				; WAIT FOR 80286 RESET
   916 00000FAD EBFD                <1> 	jmp 	short khere		; INSURE HALT
   917                              <1> 
   918                              <1> 	;
   919                              <1> 	;-----	IN ALTERNATE SHIFT, RESET NOT FOUND
   920                              <1> K31:					; NO-RESET
   921 00000FAF 3C39                <1> 	cmp	al, 57			; TEST FOR SPACE KEY
   922 00000FB1 7507                <1> 	jne	short K311		; NOT THERE
   923 00000FB3 B020                <1> 	mov	al, ' '			; SET SPACE CHAR
   924 00000FB5 E948020000          <1>         jmp     K57                     ; BUFFER_FILL
   925                              <1> K311:
   926 00000FBA 3C0F                <1> 	cmp	al, 15			; TEST FOR TAB KEY
   927 00000FBC 7509                <1> 	jne	short K312		; NOT THERE
   928 00000FBE 66B800A5            <1> 	mov	ax, 0A500h		; SET SPECIAL CODE FOR ALT-TAB
   929 00000FC2 E93B020000          <1>         jmp     K57                     ; BUFFER_FILL
   930                              <1> K312:
   931 00000FC7 3C4A                <1> 	cmp	al, 74			; TEST FOR KEY PAD -
   932 00000FC9 0F84A2000000        <1>         je      K37B                    ; GO PROCESS
   933 00000FCF 3C4E                <1> 	cmp	al, 78			; TEST FOR KEY PAD +
   934 00000FD1 0F849A000000        <1>         je      K37B                    ; GO PROCESS
   935                              <1> 	;
   936                              <1> 	;-----	LOOK FOR KEY PAD ENTRY
   937                              <1> K32:					; ALT-KEY-PAD
   938 00000FD7 BF[94E70000]        <1> 	mov	edi, K30		; ALT-INPUT-TABLE offset
   939 00000FDC B90A000000          <1> 	mov	ecx, 10			; LOOK FOR ENTRY USING KEYPAD
   940 00000FE1 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH
   941 00000FE3 7525                <1> 	jne	short K33		; NO_ALT_KEYPAD
   942 00000FE5 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF THE NEW KEYS?
   943 00000FE8 0F858A000000        <1>         jnz     K37C                    ; YES, JUMP, NOT NUMPAD KEY
   944 00000FEE 81EF[95E70000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
   945 00000FF4 A0[D5E80000]        <1> 	mov	al, [ALT_INPUT] 	; GET THE CURRENT BYTE
   946 00000FF9 B40A                <1> 	mov	ah, 10			; MULTIPLY BY 10
   947 00000FFB F6E4                <1> 	mul	ah
   948 00000FFD 6601F8              <1> 	add	ax, di			; ADD IN THE LATEST ENTRY
   949 00001000 A2[D5E80000]        <1> 	mov	[ALT_INPUT], al 	; STORE IT AWAY
   950                              <1> ;K32A:
   951 00001005 E959FFFFFF          <1>         jmp     K26                     ; THROW AWAY THAT KEYSTROKE
   952                              <1> 	;
   953                              <1> 	;-----	LOOK FOR SUPERSHIFT ENTRY
   954                              <1> K33:					; NO-ALT-KEYPAD
   955 0000100A C605[D5E80000]00    <1>         mov     byte [ALT_INPUT], 0     ; ZERO ANY PREVIOUS ENTRY INTO INPUT
   956 00001011 B91A000000          <1> 	mov	ecx, 26			; (DI),(ES) ALREADY POINTING
   957 00001016 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH IN ALPHABET
   958 00001018 7450                <1> 	je	short K37A		; MATCH FOUND, GO FILLL THE BUFFER
   959                              <1> 	;
   960                              <1> 	;-----	LOOK FOR TOP ROW OF ALTERNATE SHIFT
   961                              <1> K34:					; ALT-TOP-ROW
   962 0000101A 3C02                <1> 	cmp	al, 2			; KEY WITH '1' ON IT
   963 0000101C 7253                <1> 	jb	short K37B		; MUST BE ESCAPE
   964 0000101E 3C0D                <1> 	cmp	al, 13			; IS IT IN THE REGION
   965 00001020 7705                <1> 	ja	short K35		; NO, ALT SOMETHING ELSE
   966 00001022 80C476              <1> 	add	ah, 118			; CONVERT PSEUDO SCAN CODE TO RANGE
   967 00001025 EB43                <1> 	jmp	short K37A		; GO FILL THE BUFFER
   968                              <1> 	;
   969                              <1> 	;-----	TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
   970                              <1> K35:					; ALT-FUNCTION
   971 00001027 3C57                <1> 	cmp	al, F11_M		; IS IT F11?	
   972 00001029 7209                <1> 	jb	short K35A ; 20/02/2015	; NO, BRANCH
   973 0000102B 3C58                <1> 	cmp	al, F12_M		; IS IT F12?
   974 0000102D 7705                <1> 	ja	short K35A ; 20/02/2015	; NO, BRANCH
   975 0000102F 80C434              <1> 	add	ah, 52			; CONVERT TO PSEUDO SCAN CODE
   976 00001032 EB36                <1> 	jmp	short K37A		; GO FILL THE BUFFER
   977                              <1> K35A:
   978 00001034 F6C702              <1> 	test	bh, LC_E0		; DO WE HAVE ONE OF THE NEW KEYS?
   979 00001037 7422                <1> 	jz	short K37		; NO, JUMP
   980 00001039 3C1C                <1> 	cmp	al, 28			; TEST FOR KEYPAD ENTER
   981 0000103B 7509                <1>         jne     short K35B              ; NOT THERE
   982 0000103D 66B800A6            <1> 	mov	ax, 0A600h		; SPECIAL CODE
   983 00001041 E9BC010000          <1> 	jmp	K57			; BUFFER FILL
   984                              <1> K35B:
   985 00001046 3C53                <1> 	cmp	al, 83			; TEST FOR DELETE KEY
   986 00001048 742E                <1> 	je	short K37C		; HANDLE WITH OTHER EDIT KEYS
   987 0000104A 3C35                <1> 	cmp	al, 53			; TEST FOR KEYPAD /
   988                              <1> 	;jne	short K32A		; NOT THERE, NO OTHER E0 SPECIALS	
   989 0000104C 0F8511FFFFFF        <1>         jne     K26
   990 00001052 66B800A4            <1> 	mov	ax, 0A400h		; SPECIAL CODE
   991 00001056 E9A7010000          <1> 	jmp	K57			; BUFFER FILL
   992                              <1> K37:
   993 0000105B 3C3B                <1> 	cmp	al, 59			; TEST FOR FUNCTION KEYS (F1)
   994 0000105D 7212                <1>         jb      short K37B		; NO FN, HANDLE W/OTHER EXTENDED
   995 0000105F 3C44                <1> 	cmp	al, 68			; IN KEYPAD REGION?
   996                              <1>         ;ja	short K32A		; IF SO, IGNORE
   997 00001061 0F87FCFEFFFF        <1>         ja      K26
   998 00001067 80C42D              <1> 	add	ah, 45			; CONVERT TO PSEUDO SCAN CODE
   999                              <1> K37A:
  1000 0000106A B000                <1> 	mov	al, 0			; ASCII CODE OF ZERO
  1001 0000106C E991010000          <1>         jmp     K57                     ; PUT IT IN THE BUFFER
  1002                              <1> K37B:
  1003 00001071 B0F0                <1> 	mov	al, 0F0h		; USE SPECIAL ASCII CODE
  1004 00001073 E98A010000          <1> 	jmp     K57                     ; PUT IT IN THE BUFFER
  1005                              <1> K37C:
  1006 00001078 0450                <1> 	add	al, 80			; CONVERT SCAN CODE (EDIT KEYS)
  1007 0000107A 88C4                <1> 	mov	ah, al			; (SCAN CODE NOT IN AH FOR INSERT)
  1008 0000107C EBEC                <1> 	jmp     short K37A              ; PUT IT IN THE BUFFER
  1009                              <1> 	;
  1010                              <1> 	;-----	NOT IN ALTERNATE SHIFT
  1011                              <1> K38:					; NOT-ALT-SHIFT
  1012                              <1> 					; BL STILL HAS SHIFT FLAGS
  1013 0000107E F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT?
  1014                              <1> 	;jnz	short K38A		; YES, START PROCESSING	
  1015 00001081 0F84B0000000        <1>         jz      K44                     ; NOT-CTL-SHIFT
  1016                              <1> 	;
  1017                              <1> 	;-----	CONTROL SHIFT, TEST SPECIAL CHARACTERS
  1018                              <1> 	;-----	TEST FOR BREAK
  1019                              <1> K38A:
  1020 00001087 3C46                <1> 	cmp	al, SCROLL_KEY		; TEST FOR BREAK
  1021 00001089 7531                <1> 	jne	short K39		; JUMP, NO-BREAK
  1022 0000108B F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1023 0000108E 7405                <1> 	jz	short K38B		; NO, BREAK IS VALID	
  1024 00001090 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1025 00001093 7427                <1> 	jz	short K39		; NO-BREAK, TEST FOR PAUSE	
  1026                              <1> K38B:
  1027 00001095 8B1D[DEE80000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  1028 0000109B 891D[E2E80000]      <1> 	mov	[BUFFER_TAIL], ebx
  1029 000010A1 C605[D0E80000]80    <1> 	mov	byte [BIOS_BREAK], 80h  ; TURN ON BIOS_BREAK BIT
  1030                              <1> 	;
  1031                              <1> 	;-----	ENABLE KEYBOARD
  1032 000010A8 B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1033 000010AA E8BF010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1034                              <1> 	;
  1035                              <1> 	; CTRL+BREAK code here !!!
  1036                              <1> 	;INT	1BH			; BREAK INTERRUPT VECTOR
  1037                              <1> 	; 17/10/2015	
  1038 000010AF E81B450000          <1> 	call	ctrlbrk ; control+break subroutine
  1039                              <1> 	;
  1040 000010B4 6629C0              <1> 	sub	ax, ax			; PUT OUT DUMMY CHARACTER
  1041 000010B7 E946010000          <1>         jmp     K57                     ; BUFFER_FILL
  1042                              <1> 	;
  1043                              <1> 	;-----	TEST FOR PAUSE
  1044                              <1> K39:					; NO_BREAK
  1045 000010BC F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1046 000010BF 7537                <1> 	jnz	short K41		; YES, THEN THIS CAN'T BE PAUSE	
  1047 000010C1 3C45                <1> 	cmp	al, NUM_KEY		; LOOK FOR PAUSE KEY
  1048 000010C3 7533                <1> 	jne	short K41		; NO-PAUSE
  1049                              <1> K39P:
  1050 000010C5 800D[D2E80000]08    <1> 	or	byte [KB_FLAG_1], HOLD_STATE ; TURN ON THE HOLD FLAG
  1051                              <1> 	;
  1052                              <1> 	;-----	ENABLE KEYBOARD
  1053 000010CC B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1054 000010CE E89B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1055                              <1> K39A:
  1056 000010D3 B020                <1> 	mov	al, EOI			; END OF INTERRUPT TO CONTROL PORT
  1057 000010D5 E620                <1> 	out	20h, al ;out INTA00, al	; ALLOW FURTHER KEYSTROKE INTERRUPTS
  1058                              <1> 	;
  1059                              <1> 	;-----	DURING PAUSE INTERVAL, TURN COLOR CRT BACK ON
  1060 000010D7 803D[06E90000]07    <1>         cmp     byte [CRT_MODE], 7      ; IS THIS BLACK AND WHITE CARD
  1061 000010DE 740A                <1>         je      short K40              	; YES, NOTHING TO DO
  1062 000010E0 66BAD803            <1> 	mov	dx, 03D8h		; PORT FOR COLOR CARD
  1063 000010E4 A0[07E90000]        <1>         mov     al, [CRT_MODE_SET] 	; GET THE VALUE OF THE CURRENT MODE
  1064 000010E9 EE                  <1> 	out	dx, al			; SET THE CRT MODE, SO THAT CRT IS ON
  1065                              <1> 	;
  1066                              <1> K40:					; PAUSE-LOOP
  1067 000010EA F605[D2E80000]08    <1>         test    byte [KB_FLAG_1], HOLD_STATE ; CHECK HOLD STATE FLAG
  1068 000010F1 75F7                <1> 	jnz	short K40		; LOOP UNTIL FLAG TURNED OFF
  1069                              <1> 	;
  1070 000010F3 E977FEFFFF          <1>         jmp     K27                     ; INTERRUPT_RETURN_NO_EOI
  1071                              <1>         ;
  1072                              <1> 	;-----	TEST SPECIAL CASE KEY 55
  1073                              <1> K41:					; NO-PAUSE
  1074 000010F8 3C37                <1> 	cmp	al, 55			; TEST FOR */PRTSC KEY
  1075 000010FA 7513                <1> 	jne	short K42		; NOT-KEY-55
  1076 000010FC F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1077 000010FF 7405                <1> 	jz	short K41A		; NO, CTL-PRTSC IS VALID	
  1078 00001101 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1079 00001104 7421                <1> 	jz	short K42B		; NO, TRANSLATE TO A FUNCTION
  1080                              <1> K41A:	
  1081 00001106 66B80072            <1> 	mov	ax, 114*256		; START/STOP PRINTING SWITCH
  1082 0000110A E9F3000000          <1>         jmp     K57                     ; BUFFER_FILL
  1083                              <1> 	;
  1084                              <1> 	;-----	SET UP TO TRANSLATE CONTROL SHIFT
  1085                              <1> K42:					; NOT-KEY-55
  1086 0000110F 3C0F                <1> 	cmp	al, 15			; IS IT THE TAB KEY?
  1087 00001111 7414                <1> 	je	short K42B		; YES, XLATE TO FUNCTION CODE
  1088 00001113 3C35                <1> 	cmp	al, 53			; IS IT THE / KEY?
  1089 00001115 750E                <1> 	jne	short K42A		; NO, NO MORE SPECIAL CASES	
  1090 00001117 F6C702              <1> 	test	bh, LC_E0		; YES, IS IT FROM THE KEY PAD?
  1091 0000111A 7409                <1> 	jz	short K42A		; NO, JUST TRANSLATE
  1092 0000111C 66B80095            <1> 	mov	ax, 9500h		; YES, SPECIAL CODE FOR THIS ONE
  1093 00001120 E9DD000000          <1> 	jmp	K57			; BUFFER FILL	
  1094                              <1> K42A: 
  1095                              <1> 	;;mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1096 00001125 3C3B                <1> 	cmp	al, 59			; IS IT IN CHARACTER TABLE?
  1097                              <1>         ;jb	short K45F              ; YES, GO TRANSLATE CHAR
  1098                              <1> 	;;jb	K56 ; 20/02/2015
  1099                              <1> 	;;jmp	K64 ; 20/02/2015
  1100                              <1> K42B:
  1101 00001127 BB[C8E70000]        <1> 	mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1102 0000112C 0F82AE000000        <1> 	jb	K56 ;; 20/02/2015	
  1103 00001132 E9B9000000          <1> 	jmp	K64	
  1104                              <1>         ;
  1105                              <1> 	;-----	NOT IN CONTROL SHIFT
  1106                              <1> K44:					; NOT-CTL-SHIFT
  1107 00001137 3C37                <1> 	cmp	al, 55			; PRINT SCREEN KEY?
  1108 00001139 7528                <1> 	jne	short K45		; NOT PRINT SCREEN
  1109 0000113B F6C710              <1> 	test	bh, KBX			; IS THIS ENHANCED KEYBOARD?
  1110 0000113E 7407                <1> 	jz	short K44A		; NO, TEST FOR SHIFT STATE	
  1111 00001140 F6C702              <1> 	test	bh, LC_E0		; YES, LAST CODE A MARKER?
  1112 00001143 7507                <1> 	jnz	short K44B		; YES, IS PRINT SCREEN
  1113 00001145 EB41                <1> 	jmp	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1114                              <1> K44A:
  1115 00001147 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; NOT 101 KBD, SHIFT KEY DOWN?
  1116 0000114A 743C                <1> 	jz	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1117                              <1> 	;
  1118                              <1> 	;-----	ISSUE INTERRUPT TO INDICATE PRINT SCREEN FUNCTION
  1119                              <1> K44B:
  1120 0000114C B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1121 0000114E E81B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1122 00001153 B020                <1> 	mov	al, EOI			; END OF CURRENT INTERRUPT
  1123 00001155 E620                <1> 	out	20h, al ;out INTA00, al	; SO FURTHER THINGS CAN HAPPEN
  1124                              <1> 	; Print Screen !!!		; ISSUE PRINT SCREEN INTERRUPT (INT 05h)
  1125                              <1> 	;PUSH 	BP			; SAVE POINTER
  1126                              <1> 	;INT 	5H			; ISSUE PRINT SCREEN INTERRUPT
  1127                              <1> 	;POP	BP			; RESTORE POINTER
  1128 00001157 8025[D4E80000]FC    <1>         and     byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; ZERO OUT THESE FLAGS
  1129 0000115E E90CFEFFFF          <1>         jmp     K27                     ; GO BACK WITHOUT EOI OCCURRING
  1130                              <1> 	;
  1131                              <1> 	;-----	HANDLE IN-CORE KEYS
  1132                              <1> K45:					; NOT-PRINT-SCREEN
  1133 00001163 3C3A                <1> 	cmp	al, 58			; TEST FOR IN-CORE AREA
  1134 00001165 7734                <1> 	ja	short K46		; JUMP IF NOT
  1135 00001167 3C35                <1> 	cmp	al, 53			; IS THIS THE '/' KEY?
  1136 00001169 7505                <1> 	jne	short K45A		; NO, JUMP
  1137 0000116B F6C702              <1> 	test	bh, LC_E0		; WAS THE LAST CODE THE MARKER?
  1138 0000116E 7518                <1> 	jnz	short K45C		; YES, TRANSLATE TO CHARACTER
  1139                              <1> K45A:
  1140 00001170 B91A000000          <1> 	mov	ecx, 26			; LENGHT OF SEARCH
  1141 00001175 BF[9EE70000]        <1> 	mov	edi, K30+10		; POINT TO TABLE OF A-Z CHARS
  1142 0000117A F2AE                <1> 	repne	scasb			; IS THIS A LETTER KEY?
  1143                              <1> 		; 20/02/2015
  1144 0000117C 7505                <1> 	jne	short K45B              ; NO, SYMBOL KEY
  1145                              <1> 	;
  1146 0000117E F6C340              <1> 	test	bl, CAPS_STATE		; ARE WE IN CAPS_LOCK?
  1147 00001181 750C                <1> 	jnz	short K45D		; TEST FOR SURE
  1148                              <1> K45B:
  1149 00001183 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1150 00001186 750C                <1> 	jnz	short K45E		; YES, UPPERCASE
  1151                              <1> 					; NO, LOWERCASE
  1152                              <1> K45C:
  1153 00001188 BB[20E80000]        <1> 	mov	ebx, K10		; TRANSLATE TO LOWERCASE LETTERS
  1154 0000118D EB51                <1> 	jmp	short K56	
  1155                              <1> K45D:					; ALMOST-CAPS-STATE
  1156 0000118F F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  1157 00001192 75F4                <1> 	jnz	short K45C		; SHIFTED TEMP OUT OF CAPS STATE
  1158                              <1> K45E:
  1159 00001194 BB[78E80000]        <1> 	mov	ebx, K11		; TRANSLATE TO UPPER CASE LETTERS
  1160 00001199 EB45                <1> K45F:	jmp	short K56
  1161                              <1> 	;
  1162                              <1> 	;-----	TEST FOR KEYS F1 - F10
  1163                              <1> K46:					; NOT IN-CORE AREA
  1164 0000119B 3C44                <1> 	cmp	al, 68			; TEST FOR F1 - F10
  1165                              <1> 	;ja	short K47		; JUMP IF NOT
  1166                              <1> 	;jmp	short K53		; YES, GO DO FN KEY PROCESS			
  1167 0000119D 7635                <1> 	jna	short K53		
  1168                              <1> 	;
  1169                              <1> 	;-----	HANDLE THE NUMERIC PAD KEYS
  1170                              <1> K47:					; NOT F1 - F10
  1171 0000119F 3C53                <1> 	cmp	al, 83			; TEST NUMPAD KEYS
  1172 000011A1 772D                <1> 	ja	short K52		; JUMP IF NOT
  1173                              <1> 	;
  1174                              <1> 	;-----	KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  1175                              <1> K48:
  1176 000011A3 3C4A                <1> 	cmp	al , 74			; SPECIAL CASE FOR MINUS
  1177 000011A5 74ED                <1> 	je	short K45E		; GO TRANSLATE
  1178 000011A7 3C4E                <1> 	cmp	al , 78			; SPECIAL CASE FOR PLUS
  1179 000011A9 74E9                <1> 	je	short K45E		; GO TRANSLATE
  1180 000011AB F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OFTHE NEW KEYS?
  1181 000011AE 750A                <1> 	jnz	short K49		; YES, TRANSLATE TO BASE STATE
  1182                              <1> 	;		
  1183 000011B0 F6C320              <1> 	test 	bl, NUM_STATE		; ARE WE IN NUM LOCK
  1184 000011B3 7514                <1> 	jnz	short K50		; TEST FOR SURE
  1185 000011B5 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1186                              <1> 	;jnz	short K51		; IF SHIFTED, REALLY NUM STATE
  1187 000011B8 75DA                <1> 	jnz	short K45E
  1188                              <1> 	;
  1189                              <1> 	;-----	BASE CASE FOR KEYPAD
  1190                              <1> K49:					
  1191 000011BA 3C4C                <1> 	cmp	al, 76			; SPECIAL CASE FOR BASE STATE 5
  1192 000011BC 7504                <1> 	jne	short K49A		; CONTINUE IF NOT KEYPAD 5
  1193 000011BE B0F0                <1> 	mov	al, 0F0h		; SPECIAL ASCII CODE	
  1194 000011C0 EB40                <1> 	jmp	short K57		; BUFFER FILL
  1195                              <1> K49A:
  1196 000011C2 BB[20E80000]        <1> 	mov	ebx, K10		; BASE CASE TABLE	
  1197 000011C7 EB27                <1> 	jmp	short K64		; CONVERT TO PSEUDO SCAN
  1198                              <1> 	;
  1199                              <1> 	;-----	MIGHT BE NUM LOCK, TEST SHIFT STATUS
  1200                              <1> K50:					; ALMOST-NUM-STATE
  1201 000011C9 F6C303              <1>         test    bl, LEFT_SHIFT+RIGHT_SHIFT
  1202 000011CC 75EC                <1> 	jnz 	short K49		; SHIFTED TEMP OUT OF NUM STATE
  1203 000011CE EBC4                <1> K51:	jmp	short K45E		; REALLY NUM STATE
  1204                              <1> 	;
  1205                              <1> 	;-----	TEST FOR THE NEW KEYS ON WT KEYBOARDS 
  1206                              <1> K52:					; NOT A NUMPAD KEY
  1207 000011D0 3C56                <1> 	cmp	al, 86			; IS IT THE NEW WT KEY?
  1208                              <1> 	;jne	short K53		; JUMP IF NOT
  1209                              <1> 	;jmp	short K45B		; HANDLE WITH REST OF LETTER KEYS
  1210 000011D2 74AF                <1> 	je	short K45B		
  1211                              <1> 	;
  1212                              <1> 	;-----	MUST BE F11 OR F12 
  1213                              <1> K53:					; F1 - F10 COME HERE, TOO
  1214 000011D4 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST SHIFT STATE
  1215 000011D7 74E1                <1> 	jz	short K49		; JUMP, LOWER CASE PSEUDO SC'S
  1216                              <1> 		; 20/02/2015 
  1217 000011D9 BB[78E80000]        <1> 	mov	ebx, K11		; UPPER CASE PSEUDO SCAN CODES
  1218 000011DE EB10                <1> 	jmp	short K64		; TRANSLATE SCAN
  1219                              <1> 	;
  1220                              <1> 	;-----	TRANSLATE THE CHARACTER
  1221                              <1> K56:					; TRANSLATE-CHAR
  1222 000011E0 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1223 000011E2 D7                  <1> 	xlat    			; CONVERT THE SCAN CODE TO ASCII
  1224 000011E3 F605[D4E80000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1225 000011EA 7416                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1226 000011EC B4E0                <1> 	mov	ah, MC_E0		; YES, PUT SPECIAL MARKER IN AH
  1227 000011EE EB12                <1> 	jmp	short K57		; PUT IT INTO THE BUFFER	
  1228                              <1> 	;
  1229                              <1> 	;-----	TRANSLATE SCAN FOR PSEUDO SCAN CODES
  1230                              <1> K64:					; TRANSLATE-SCAN-ORGD
  1231 000011F0 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1232 000011F2 D7                  <1>        	xlat    	                ; CTL TABLE SCAN
  1233 000011F3 88C4                <1> 	mov	ah, al			; PUT VALUE INTO AH
  1234 000011F5 B000                <1> 	mov	al, 0			; ZERO ASCII CODE
  1235 000011F7 F605[D4E80000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1236 000011FE 7402                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1237 00001200 B0E0                <1> 	mov	al, MC_E0		; YES, PUT SPECIAL MARKER IN AL
  1238                              <1> 	;
  1239                              <1> 	;-----	PUT CHARACTER INTO BUFFER
  1240                              <1> K57:					; BUFFER_FILL
  1241 00001202 3CFF                <1> 	cmp	al, -1			; IS THIS AN IGNORE CHAR
  1242                              <1>         ;je	short K59		; YES, DO NOTHING WITH IT
  1243 00001204 0F8459FDFFFF        <1> 	je      K26			; YES, DO NOTHING WITH IT
  1244 0000120A 80FCFF              <1> 	cmp	ah, -1			; LOOK FOR -1 PSEUDO SCAN
  1245                              <1>         ;jne	short K61		; NEAR_INTERRUPT_RETURN
  1246 0000120D 0F8450FDFFFF        <1> 	je      K26			; INTERRUPT_RETURN
  1247                              <1> ;K59:					; NEAR_INTERRUPT_RETURN
  1248                              <1> ;	jmp	K26			; INTERRUPT_RETURN
  1249                              <1> 
  1250                              <1> _K60: ; 29/01/2016
  1251 00001213 80FC68              <1> 	cmp	ah, 68h	; ALT + F1 key
  1252 00001216 721F                <1> 	jb	short K61
  1253 00001218 80FC6F              <1> 	cmp	ah, 6Fh ; ALT + F8 key	
  1254 0000121B 771A                <1> 	ja	short K61
  1255                              <1> 	;
  1256 0000121D 8A1D[F61F0100]      <1> 	mov	bl, [ACTIVE_PAGE]
  1257 00001223 80C368              <1> 	add	bl, 68h
  1258 00001226 38E3                <1> 	cmp	bl, ah
  1259 00001228 740D                <1> 	je	short K61
  1260 0000122A 6650                <1> 	push	ax
  1261 0000122C 88E0                <1> 	mov	al, ah
  1262 0000122E 2C68                <1> 	sub	al, 68h
  1263 00001230 E8B6050000          <1> 	call	set_active_page
  1264 00001235 6658                <1> 	pop	ax
  1265                              <1> K61:					; NOT-CAPS-STATE
  1266 00001237 8B1D[E2E80000]      <1> 	mov	ebx, [BUFFER_TAIL] 	; GET THE END POINTER TO THE BUFFER
  1267 0000123D 89DE                <1> 	mov	esi, ebx		; SAVE THE VALUE
  1268 0000123F E857FAFFFF          <1> 	call	_K4			; ADVANCE THE TAIL
  1269 00001244 3B1D[DEE80000]      <1> 	cmp	ebx, [BUFFER_HEAD] 	; HAS THE BUFFER WRAPPED AROUND
  1270 0000124A 740E                <1> 	je	short K62		; BUFFER_FULL_BEEP
  1271 0000124C 668906              <1> 	mov	[esi], ax		; STORE THE VALUE
  1272 0000124F 891D[E2E80000]      <1> 	mov	[BUFFER_TAIL], ebx 	; MOVE THE POINTER UP
  1273 00001255 E909FDFFFF          <1> 	jmp	K26
  1274                              <1> 	;;cli				; TURN OFF INTERRUPTS
  1275                              <1> 	;;mov	al, EOI			; END OF INTERRUPT COMMAND
  1276                              <1> 	;;out	INTA00, al		; SEND COMMAND TO INTERRUPT CONTROL PORT
  1277                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1278                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  1279                              <1> 	;MOV	AX, 9102H		; MOVE IN POST CODE & TYPE
  1280                              <1> 	;INT	15H			; PERFORM OTHER FUNCTION
  1281                              <1> 	;;and	byte [KB_FLAG_3],~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  1282                              <1> 	;JMP	K27A			; INTERRUPT_RETURN
  1283                              <1> 	;;jmp   K27                    
  1284                              <1> 	;
  1285                              <1> 	;-----	BUFFER IS FULL SOUND THE BEEPER
  1286                              <1> K62:
  1287 0000125A B020                <1> 	mov	al, EOI			; ENABLE INTERRUPT CONTROLLER CHIP
  1288 0000125C E620                <1> 	out	INTA00, al
  1289 0000125E 66B9A602            <1> 	mov	cx, 678			; DIVISOR FOR 1760 HZ
  1290 00001262 B304                <1> 	mov	bl, 4			; SHORT BEEP COUNT (1/16 + 1/64 DELAY)
  1291 00001264 E8A7090000          <1> 	call	beep			; GO TO COMMON BEEP HANDLER
  1292 00001269 E901FDFFFF          <1> 	jmp     K27			; EXIT   
  1293                              <1> 
  1294                              <1> SHIP_IT:
  1295                              <1> 	;---------------------------------------------------------------------------------
  1296                              <1> 	; SHIP_IT
  1297                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1298                              <1> 	;	TO THE KEYBOARD CONTROLLER.
  1299                              <1> 	;---------------------------------------------------------------------------------
  1300                              <1> 	;
  1301 0000126E 6650                <1> 	push	ax			; SAVE DATA TO SEND
  1302                              <1> 
  1303                              <1> 	;-----	WAIT FOR COMMAND TO ACCEPTED
  1304 00001270 FA                  <1> 	cli				; DISABLE INTERRUPTS TILL DATA SENT
  1305                              <1> 	; xor	ecx, ecx		; CLEAR TIMEOUT COUNTER
  1306 00001271 B900000100          <1> 	mov	ecx, 10000h			
  1307                              <1> S10:
  1308 00001276 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD CONTROLLER STATUS
  1309 00001278 A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ITS INPUT BUFFER BUSY
  1310 0000127A E0FA                <1> 	loopnz	S10			; WAIT FOR COMMAND TO BE ACCEPTED
  1311                              <1> 
  1312 0000127C 6658                <1> 	pop	ax			; GET DATA TO SEND
  1313 0000127E E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROLLER
  1314 00001280 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  1315 00001281 C3                  <1> 	retn				; RETURN TO CALLER
  1316                              <1> 
  1317                              <1> SND_DATA:
  1318                              <1> 	; ---------------------------------------------------------------------------------
  1319                              <1> 	; SND_DATA
  1320                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1321                              <1> 	;	TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  1322                              <1> 	;	HANDLES ANY RETRIES IF REQUIRED
  1323                              <1> 	; ---------------------------------------------------------------------------------
  1324                              <1> 	;
  1325 00001282 6650                <1> 	push	ax			; SAVE REGISTERS
  1326 00001284 6653                <1> 	push	bx
  1327 00001286 51                  <1> 	push	ecx
  1328 00001287 88C7                <1> 	mov	bh, al			; SAVE TRANSMITTED BYTE FOR RETRIES
  1329 00001289 B303                <1> 	mov	bl, 3			; LOAD RETRY COUNT
  1330                              <1> SD0:
  1331 0000128B FA                  <1> 	cli				; DISABLE INTERRUPTS
  1332 0000128C 8025[D3E80000]CF    <1> 	and	byte [KB_FLAG_2], ~(KB_FE+KB_FA) ; CLEAR ACK AND RESEND FLAGS
  1333                              <1> 	;
  1334                              <1> 	;-----	WAIT FOR COMMAND TO BE ACCEPTED
  1335 00001293 B900000100          <1> 	mov	ecx, 10000h		; MAXIMUM WAIT COUNT
  1336                              <1> SD5:
  1337 00001298 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD PROCESSOR STATUS PORT
  1338 0000129A A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ANY PENDING COMMAND
  1339 0000129C E0FA                <1> 	loopnz	SD5			; WAIT FOR COMMAND TO BE ACCEPTED
  1340                              <1> 	;
  1341 0000129E 88F8                <1> 	mov	al, bh			; REESTABLISH BYTE TO TRANSMIT
  1342 000012A0 E660                <1> 	out	PORT_A, al		; SEND BYTE
  1343 000012A2 FB                  <1> 	sti				; ENABLE INTERRUPTS
  1344                              <1> 	;mov	cx, 01A00h		; LOAD COUNT FOR 10 ms+
  1345 000012A3 B9FFFF0000          <1> 	mov	ecx, 0FFFFh
  1346                              <1> SD1:
  1347 000012A8 F605[D3E80000]30    <1> 	test	byte [KB_FLAG_2], KB_FE+KB_FA ; SEE IF EITHER BIT SET
  1348 000012AF 750F                <1> 	jnz	short SD3		; IF SET, SOMETHING RECEIVED GO PROCESS
  1349 000012B1 E2F5                <1> 	loop	SD1			; OTHERWISE WAIT
  1350                              <1> SD2:
  1351 000012B3 FECB                <1> 	dec	bl			; DECREMENT RETRY COUNT
  1352 000012B5 75D4                <1> 	jnz	short SD0		; RETRY TRANSMISSION
  1353 000012B7 800D[D3E80000]80    <1> 	or	byte [KB_FLAG_2], KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  1354 000012BE EB09                <1> 	jmp	short SD4		; RETRIES EXHAUSTED FORGET TRANSMISSION
  1355                              <1> SD3:
  1356 000012C0 F605[D3E80000]10    <1> 	test	byte [KB_FLAG_2], KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  1357 000012C7 74EA                <1> 	jz	short SD2		; IF NOT, GO RESEND
  1358                              <1> SD4:	
  1359 000012C9 59                  <1> 	pop	ecx			; RESTORE REGISTERS
  1360 000012CA 665B                <1> 	pop	bx
  1361 000012CC 6658                <1> 	pop	ax
  1362 000012CE C3                  <1> 	retn				; RETURN, GOOD TRANSMISSION
  1363                              <1> 
  1364                              <1> SND_LED:
  1365                              <1> 	; ---------------------------------------------------------------------------------
  1366                              <1> 	; SND_LED
  1367                              <1> 	;	THIS ROUTINES TURNS ON THE MODE INDICATORS.
  1368                              <1> 	;
  1369                              <1> 	;----------------------------------------------------------------------------------
  1370                              <1> 	;
  1371 000012CF FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1372 000012D0 F605[D3E80000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1373 000012D7 755F                <1> 	jnz 	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1374                              <1> 	;
  1375 000012D9 800D[D3E80000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1376 000012E0 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  1377 000012E2 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  1378 000012E4 EB11                <1> 	jmp	short SL0		; GO SEND MODE INDICATOR COMMAND
  1379                              <1> SND_LED1:
  1380 000012E6 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1381 000012E7 F605[D3E80000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1382 000012EE 7548                <1> 	jnz	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1383                              <1> 	;
  1384 000012F0 800D[D3E80000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1385                              <1> SL0:
  1386 000012F7 B0ED                <1> 	mov	al, LED_CMD		; LED CMD BYTE
  1387 000012F9 E884FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1388 000012FE FA                  <1> 	cli
  1389 000012FF E836000000          <1> 	call	MAKE_LED		; GO FORM INDICATOR DATA BYTE
  1390 00001304 8025[D3E80000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  1391 0000130B 0805[D3E80000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  1392 00001311 F605[D3E80000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1393 00001318 750F                <1> 	jnz	short SL2		; IF SO, BYPASS SECOND BYTE TRANSMISSION
  1394                              <1> 	;
  1395 0000131A E863FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1396 0000131F FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1397 00001320 F605[D3E80000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1398 00001327 7408                <1> 	jz	short SL3		; IF NOT, DON'T SEND AN ENABLE COMMAND
  1399                              <1> SL2:
  1400 00001329 B0F4                <1> 	mov	al, KB_ENABLE		; GET KEYBOARD CSA ENABLE COMMAND
  1401 0000132B E852FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1402 00001330 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1403                              <1> SL3:
  1404 00001331 8025[D3E80000]3F    <1> 	and	byte [KB_FLAG_2], ~(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  1405                              <1> SL1:					; UPDATE AND TRANSMIT ERROR FLAG
  1406 00001338 FB                  <1> 	sti				; ENABLE INTERRUPTS
  1407 00001339 C3                  <1> 	retn				; RETURN TO CALLER
  1408                              <1> 
  1409                              <1> MAKE_LED:
  1410                              <1> 	;---------------------------------------------------------------------------------
  1411                              <1> 	; MAKE_LED
  1412                              <1> 	;	THIS ROUTINES FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  1413                              <1> 	;	THE MODE INDICATORS.
  1414                              <1> 	;---------------------------------------------------------------------------------
  1415                              <1> 	;
  1416                              <1> 	;push 	cx			; SAVE CX
  1417 0000133A A0[D1E80000]        <1> 	mov	al, [KB_FLAG]		; GET CAPS & NUM LOCK INDICATORS
  1418 0000133F 2470                <1> 	and	al, CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  1419                              <1> 	;mov	cl, 4			; SHIFT COUNT
  1420                              <1> 	;rol	al, cl			; SHIFT BITS OVER TO TURN ON INDICATORS
  1421 00001341 C0C004              <1> 	rol	al, 4 ; 20/02/2015
  1422 00001344 2407                <1> 	and	al, 07h			; MAKE SURE ONLY MODE BITS ON
  1423                              <1> 	;pop	cx
  1424 00001346 C3                  <1> 	retn				; RETURN TO CALLER
  1425                              <1> 
  1426                              <1> ; % include 'kybdata.s'   ; KEYBOARD DATA
  1427                              <1> 
  1428                              <1> 
  1429                              <1> ; /// End Of KEYBOARD FUNCTIONS ///
  1695                                  
  1696                                  %include 'video.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - video.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 08/08/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; video.inc (13/08/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - VIDEO.INC
    20                              <1> ; Last Modification: 13/08/2015
    21                              <1> ;		  (Video Data is in 'VIDATA.INC')
    22                              <1> ;
    23                              <1> ; ///////// VIDEO (CGA) FUNCTIONS ///////////////
    24                              <1> 
    25                              <1> ; 16/01/2016 (32 bit modifications, TRDOS386 - TRDOS v2.0, video.s)
    26                              <1> ; INT 31H (TRDOS 386) = INT 10H (IBM PC/AT REAL MODE)
    27                              <1> 
    28                              <1> ; IBM PC-AT BIOS Source Code
    29                              <1> ; TITLE VIDEO1 --- 06/10/85  VIDEO DISPLAY BIOS
    30                              <1> 
    31                              <1> _int10h:
    32                              <1> 	; 23/03/2016
    33                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
    34 00001347 9C                  <1> 	pushfd
    35 00001348 0E                  <1> 	push 	cs
    36 00001349 E851000000          <1> 	call 	VIDEO_IO_1
    37 0000134E C3                  <1> 	retn
    38                              <1> 
    39                              <1> ;--- INT 10 H -------------------------------------------------------------------
    40                              <1> ; VIDEO_IO									:	
    41                              <1> ;	THESE ROUTINES PROVIDE THE CRT DISPLAY INTERFACE			:
    42                              <1> ;	THE FOLLOWING FUNCTIONS ARE PROVIDED:					:
    43                              <1> ;										:
    44                              <1> ;    (AH)= 00H	SET MODE (AL) CONTAINS MODE VALUE				:
    45                              <1> ;		(AL) = 00H  40X25 BW MODE (POWER ON DEFAULT)			:
    46                              <1> ;		(AL) = 01H  40X25 COLOR						:
    47                              <1> ;		(AL) = 02H  80X25 BW						:
    48                              <1> ;		(AL) = 03H  80X25 COLOR						:
    49                              <1> ;		              GRAPHICS MODES					:
    50                              <1> ;		(AL) = 04H  320X200 COLOR					:
    51                              <1> ;		(AL) = 05H  320X200 BW MODE					:
    52                              <1> ;		(AL) = 06H  640X200 BW MODE					:
    53                              <1> ;		(AL) = 07H   80X25 MONOCHROME (USED INTERNAL TO VIDEO ONLY)	:
    54                              <1> ;		*** NOTES -BW MODES OPERATE SAME AS COLOR MODES, BUT COLOR	:
    55                              <1> ;		           BURST IS NOT ENABLED					:
    56                              <1> ;		          -CURSOR IS NOT DISPLAYED IN GRAPHICS MODE		:
    57                              <1> ;    (AH)= 01H	SET CURSOR TYPE							:
    58                              <1> ;		(CH) = BITS 4-0 = START LINE FOR CURSOR				:
    59                              <1> ;		       ** HARDWARE WILL ALWAYS CAUSE BLINK			:
    60                              <1> ;		       ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING	:
    61                              <1> ;		          OR NO CURSOR AT ALL					:
    62                              <1> ;		(CL) = BITS 4-0 = END LINE FOR CURSOR				:
    63                              <1> ;    (AH)= 02H	SET CURSOR POSITION						:
    64                              <1> ;		(DH,DL) = ROW,COLUMN  (00H,00H) IS UPPER LEFT			:
    65                              <1> ;		(BH) = A PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
    66                              <1> ;    (AH)= 03H	READ CURSOR POSITION						:
    67                              <1> ;		(BH) = PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
    68                              <1> ;		ON EXIT (DH,DL) = ROW,COLUMN OF CURRENT CURSOR			:
    69                              <1> ;		        (CH,CL) = CURSOR MODE CURRENTLY SET			:
    70                              <1> ;    (AH)= 04H	READ LIGHT PEN POSITION						:
    71                              <1> ;		ON EXIT:							:
    72                              <1> ;		(AH) = 00H -- LIGHT PEN SWITCH NOT DOWN/NOT TRIGGERED		:
    73                              <1> ;		(AH) = 01H -- VALID LIGHT PEN VALUE IN REGISTERS		:
    74                              <1> ;		        (DH,DL) = ROW,COLUMN OF CHARACTER LP POSITION		:
    75                              <1> ;		        (CH) = RASTER LINE (0-199)				:
    76                              <1> ;		        (BX) = PIXEL COLUMN (0-319,639)				:
    77                              <1> ;    (AH)= 05H	SELECT ACTIVE DISPLAY PAGE (VALID ONLY FOR ALPHA MODES)		:
    78                              <1> ;		(AL) = NEW PAGE VALUE (0-7 FOR MODES 0&1, 0-3 FOR MODES 2&3)	:
    79                              <1> ;    (AH)= 06H	SCROLL ACTIVE PAGE UP						:
    80                              <1> ;		(AL) = NUMBER OF LINES. ( LINES BLANKED AT BOTTOM OF WINDOW )	:
    81                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
    82                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
    83                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
    84                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
    85                              <1> ;    (AH)= 07H	SCROLL ACTIVE PAGE DOWN						:
    86                              <1> ;		(AL) = NUMBER OF LINES, INPUT LINES BLANKED AT TOP OF WINDOW	:
    87                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
    88                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
    89                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
    90                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
    91                              <1> ;										:
    92                              <1> ;   CHARACTER HANDLING ROUTINES							:
    93                              <1> ;										:
    94                              <1> ;    (AH)= 08H	READ ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
    95                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
    96                              <1> ;		ON EXIT:							:
    97                              <1> ;		(AL) = CHAR READ						:
    98                              <1> ;		(AH) = ATTRIBUTE OF CHARACTER READ (ALPHA MODES ONLY)		:
    99                              <1> ;    (AH)= 09H	WRITE ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
   100                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
   101                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
   102                              <1> ;		(AL) = CHAR TO WRITE						:
   103                              <1> ;		(BL) = ATTRIBUTE OF CHARACTER (ALPHA)/COLOR OF CHAR (GRAPHICS)	:
   104                              <1> ;		         SEE NOTE ON WRITE DOT FOR BIT 7 OF BL = 1.		:
   105                              <1> ;    (AH) = 0AH	WRITE CHARACTER ONLY AT CURRENT CURSOR POSITION			:
   106                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
   107                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
   108                              <1> ;		(AL) = CHAR TO WRITE						:
   109                              <1> ;		       NOTE: USE FUNCTION (AH)= 09H IN GRAPHICS MODES		:
   110                              <1> ;	FOR READ/WRITE CHARACTER INTERFACE WHILE IN GRAPHICS MODE, THE		:
   111                              <1> ;		CHARACTERS ARE FORMED FROM A CHARACTER GENERATOR IMAGE		:
   112                              <1> ;		MAINTAINED IN THE SYSTEM ROM. ONLY THE 1ST 128 CHARS		:
   113                              <1> ;		ARE CONTAINED THERE. TO READ/WRITE THE SECOND 128 CHARS,	:
   114                              <1> ;		THE USER MUST INITIALIZE THE POINTER AT INTERRUPT 1FH		:
   115                              <1> ;		(LOCATION 0007CH) TO POINT TO THE 1K BYTE TABLE CONTAINING	:
   116                              <1> ;		THE CODE POINTS FOR THE SECOND 128 CHARS (128-255).		:
   117                              <1> ;	FOR WRITE CHARACTER INTERFACE IN GRAPHICS MODE, THE REPLICATION FACTOR	:
   118                              <1> ;		CONTAINED IN (CX) ON ENTRY WILL PRODUCE VALID RESULTS ONLY	:
   119                              <1> ;		FOR CHARACTERS CONTAINED ON THE SAME ROW. CONTINUATION TO	:
   120                              <1> ;		SUCCEEDING LINES WILL NOT PRODUCE CORRECTLY.			:
   121                              <1> ;										:
   122                              <1> ;    GRAPHICS INTERFACE								:
   123                              <1> ;    (AH)= 0BH	SET COLOR PALETTE						:
   124                              <1> ;		(BH) = PALETTE COLOR ID BEING SET (0-127)			:
   125                              <1> ;		(BL) = COLOR VALUE TO BE USED WITH THAT COLOR ID		:
   126                              <1> ;		       NOTE: FOR THE CURRENT COLOR CARD, THIS ENTRY POINT HAS	:
   127                              <1> ;		               MEANING ONLY FOR 320X200 GRAPHICS.		:
   128                              <1> ;		       COLOR ID = 0 SELECTS THE BACKGROUND COLOR (0-15)		:
   129                              <1> ;		       COLOR ID = 1 SELECTS THE PALETTE TO BE USED:		:
   130                              <1> ;		               0 = GREEN(1)/RED(2)/YELLOW(3)			:
   131                              <1> ;		               1 = CYAN(1)/MAGENTA(2)/WHITE(3)			:
   132                              <1> ;		       IN 40X25 OR 80X25 ALPHA MODES, THE VALUE SET FOR 	:
   133                              <1> ;		               PALETTE COLOR 0 INDICATES THE BORDER COLOR	:
   134                              <1> ;		               TO BE USED (VALUES 0-31, WHERE 16-31 SELECT	:
   135                              <1> ;		               THE HIGH INTENSITY BACKGROUND SET.		:
   136                              <1> ;    (AH)= 0CH	WRITE DOT							:
   137                              <1> ;		(DX) = ROW NUMBER						:
   138                              <1> ;		(CX) = COLUMN NUMBER						:
   139                              <1> ;		(AL) = COLOR VALUE						:
   140                              <1> ;		        IF BIT 7 OF AL = 1, THEN THE COLOR VALUE IS EXCLUSIVE	:
   141                              <1> ;		        ORed WITH THE CURRENT CONTENTS OF THE DOT		:
   142                              <1> ;    (AH)= ODH	READ DOT							:
   143                              <1> ;		(DX) = ROW NUMBER						:
   144                              <1> ;		(CX) = COLUMN NUMBER						:
   145                              <1> ;		(AL) = RETURNS THE DOT READ					:
   146                              <1> ;										:
   147                              <1> ;    ASCII TELETYPE ROUTINE FOR OUTPUT						:
   148                              <1> ;										:
   149                              <1> ;    (AH)= 0EH	WRITE TELETYPE TO ACTIVE PAGE					:
   150                              <1> ;		(AL) = CHAR TO WRITE						:
   151                              <1> ;		(BL) = FOREGROUND COLOR IN GRAPHICS MODE			:
   152                              <1> ;		NOTE -- SCREEN WIDTH IS CONTROLLED BY PREVIOUS MODE SET		:
   153                              <1> ;    (AH)= 0FH	CURRENT VIDEO STATE						:
   154                              <1> ;		RETURNS THE CURRENT VIDEO STATE					:
   155                              <1> ;		(AL) = MODE CURRENTLY SET ( SEE (AH)=00H FOR EXPLANATION)	:
   156                              <1> ;		(AH) = NUMBER OR CHARACTER COLUMNS ON SCREEN			:
   157                              <1> ;		(BH) = CURRENT ACTIVE DISPLAY PAGE				:
   158                              <1> ;    (AH)= 10H	RESERVED							:
   159                              <1> ;    (AH)= 11H	RESERVED							:
   160                              <1> ;    (AH)= 12H	RESERVED							:
   161                              <1> ;    (AH)= 13H	WRITE STRING							:
   162                              <1> ;			ES:BP  -  POINTER T0 STRING TO BE WRITTEN		:
   163                              <1> ;			CX     -  LENGTH OF CHARACTER STRING TO WRITTEN		:
   164                              <1> ;			DX     -  CURSOR POSITION FOR STRING TO BE WRITTEN	:
   165                              <1> ;			BH     -  PAGE NUMBER					:
   166                              <1> ;		(AL)= 00H	WRITE CHARACTER STRING				:
   167                              <1> ;			BL     -  ATTRIBUTE					:
   168                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
   169                              <1> ;			CURSOR NOT MOVED					:
   170                              <1> ;		(AL)= 01H	WRITE CHARACTER STRING AND MOVE CURSOR		:
   171                              <1> ;			BL     -  ATTRIBUTE					:
   172                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
   173                              <1> ;			CURSOR MOVED						:
   174                              <1> ;		(AL)= 02H	WRITE CHARACTER AND ATTRIBUTE STRING		:
   175                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
   176                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
   177                              <1> ;			CURSOR IS NOT MOVED					:
   178                              <1> ;		(AL)= 03H WRITE CHARACTER AND ATTRIBUTE STRING AND MOVE CURSOR	:
   179                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
   180                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
   181                              <1> ;			CURSOR IS MOVED						:
   182                              <1> ;		 NOTE:  CARRIAGE RETURN, LINE FEED, BACKSPACE, AND BELL ARE	:
   183                              <1> ;		        TREATED AS COMMANDS RATHER THAN PRINTABLE CHARACTERS.	:
   184                              <1> ;										:
   185                              <1> ;	BX,CX,DX,SI,DI,BP,SP,DS,ES,SS PRESERVED DURING CALLS EXCEPT FOR		:
   186                              <1> ;	BX,CX,DX RETURN VALUES ON FUNCTIONS 03H,04H,0DH AND 0FH. ON ALL CALLS	:
   187                              <1> ;	AX IS MODIFIED.								:
   188                              <1> ;--------------------------------------------------------------------------------
   189                              <1> 
   190 0000134F [FB130000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
   191 00001353 [5C170000]          <1> 	dd	SET_CTYPE
   192 00001357 [83170000]          <1> 	dd	SET_CPOS
   193 0000135B [96170000]          <1> 	dd	READ_CURSOR
   194                              <1> 	;dd	VIDEO_RETURN	; READ_LPEN
   195 0000135F [E4130000]          <1> 	dd	set_mode_ncm	; Set mode without clearing video memory
   196 00001363 [C8170000]          <1> 	dd	ACT_DISP_PAGE
   197 00001367 [5F180000]          <1> 	dd	SCROLL_UP
   198 0000136B [83190000]          <1> 	dd	SCROLL_DOWN
   199 0000136F [041A0000]          <1> 	dd	READ_AC_CURRENT
   200 00001373 [5C1A0000]          <1> 	dd	WRITE_AC_CURRENT
   201 00001377 [821A0000]          <1> 	dd	WRITE_C_CURRENT
   202 0000137B [3F230000]          <1> 	dd	SET_COLOR
   203 0000137F [AA230000]          <1> 	dd	WRITE_DOT
   204 00001383 [75230000]          <1> 	dd	READ_DOT
   205 00001387 [041B0000]          <1> 	dd	WRITE_TTY
   206 0000138B [CD130000]          <1> 	dd	VIDEO_STATE
   207 0000138F [00140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
   208 00001393 [AB280000]          <1> 	dd	font_setup    ; 10/07/2016 (TRDOS 386)
   209 00001397 [00140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
   210 0000139B [711C0000]          <1> 	dd	WRITE_STRING  ; 23/06/2016 (TRDOS 386)
   211                              <1> M1L	EQU	$ - M1
   212                              <1> 
   213                              <1> ; 04/07/2016
   214                              <1> ; 12/05/2016
   215                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   216                              <1> int31h:  ; Video BIOS
   217                              <1> 
   218                              <1> ; BH = Video page number
   219                              <1> ; BL = Color/Attribute
   220                              <1> ; AH = Function number
   221                              <1> ; AL = Character
   222                              <1> 
   223                              <1> VIDEO_IO_1:
   224 0000139F FB                  <1> 	sti				; INTERRUPTS BACK ON
   225 000013A0 FC                  <1> 	cld				; SET DIRECTION FORWARD
   226 000013A1 80FC14              <1> 	cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
   227 000013A4 7326                <1> 	jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
   228                              <1> 
   229 000013A6 06                  <1> 	push	es
   230 000013A7 1E                  <1> 	push	ds			; SAVE WORK AND PARAMETER REGISTERS
   231 000013A8 52                  <1> 	push	edx
   232 000013A9 51                  <1> 	push	ecx
   233 000013AA 53                  <1> 	push	ebx
   234 000013AB 56                  <1> 	push	esi
   235 000013AC 57                  <1> 	push	edi
   236 000013AD 55                  <1> 	push	ebp
   237 000013AE 66BE1000            <1> 	mov	si, KDATA 		; POINT DS: TO DATA SEGMENT
   238 000013B2 8EDE                <1> 	mov	ds, si
   239 000013B4 8EC6                <1> 	mov	es, si
   240 000013B6 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
   241 000013BB A3[442D0100]        <1> 	mov	[video_eax], eax ; 12/05/2016 
   242                              <1> 	; 23/03/2016
   243 000013C0 C0E402              <1> 	shl	ah, 2  ; dword		; TIMES 2 FOR WORD TABLE LOOKUP
   244 000013C3 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
   245                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
   246                              <1> 
   247 000013C6 FFA6[4F130000]      <1> 	JMP	dword [esi+M1]		; GO TO SELECTED FUNCTION
   248                              <1> 
   249                              <1> M4:					; COMMAND NOT VALID
   250 000013CC CF                  <1> 	iret				; DO NOTHING IF NOT IN VALID RANGE
   251                              <1> 
   252                              <1> VIDEO_STATE:
   253                              <1> 	; 26/06/2016
   254                              <1> 	; 12/05/2016
   255                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   256                              <1> 
   257                              <1> ;---------------------------------------------------
   258                              <1> ; VIDEO STATE
   259                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
   260                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
   261                              <1> ;  AL = CURRENT VIDEO MODE
   262                              <1> ;  BH = CURRENT ACTIVE PAGE
   263                              <1> ;---------------------------------------------------
   264                              <1> 
   265 000013CD 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
   266 000013D3 A0[06E90000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
   267                              <1> 	;movzx	esi, al
   268                              <1> 	;mov	ah, [esi+M6] 
   269                              <1> 	; BH = active page
   270 000013D8 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
   271 000013DE 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
   272 000013DF 5F                  <1> 	pop	edi
   273 000013E0 5E                  <1> 	pop	esi
   274 000013E1 59                  <1> 	pop	ecx		; DISCARD SAVED BX
   275 000013E2 EB25                <1> 	jmp	short M15	; RETURN TO CALLER
   276                              <1> 
   277                              <1> set_mode_ncm:
   278                              <1> 	; 04/07/2016 - TRDOS 386 (TRDOS v2.0)
   279                              <1> 	; set mode without clearing the video memory
   280                              <1> 	; (ony for graphics modes)
   281 000013E4 3C07                <1> 	cmp	al, 7 ; IBM PC CGA modes
   282 000013E6 7613                <1> 	jna	short SET_MODE ; normal function (clear)
   283                              <1> 	; do not clear memory
   284 000013E8 A2[532D0100]        <1> 	mov	[noclearmem], al ; > 0
   285 000013ED E81E000000          <1> 	call	_set_mode
   286 000013F2 C605[532D0100]00    <1> 	mov	byte [noclearmem], 0
   287 000013F9 EB05                <1>         jmp     short VIDEO_RETURN
   288                              <1> 
   289                              <1> 	; 08/08/2016
   290                              <1> 	; 30/07/2016
   291                              <1> 	; 29/07/2016
   292                              <1> 	; 27/07/2016
   293                              <1> 	; 26/07/2016
   294                              <1> 	; 25/07/2016
   295                              <1> 	; 23/07/2016
   296                              <1> 	; 18/07/2016
   297                              <1> 	; 02/07/2016
   298                              <1> 	; 26/06/2016
   299                              <1> 	; 24/06/2016
   300                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
   301                              <1> SET_MODE:
   302                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
   303                              <1> 	;	valid video mode: 03h only!
   304                              <1> 	;	(VGA modes will be selected with another routine)
   305                              <1> 	;
   306                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
   307                              <1> 
   308                              <1> ;------------------------------------------------------
   309                              <1> ; SET MODE					      :
   310                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
   311                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
   312                              <1> ; INPUT						      :
   313                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
   314                              <1> ; OUTPUT					      :
   315                              <1> ;	NONE					      :
   316                              <1> ;------------------------------------------------------
   317                              <1> 
   318 000013FB E810000000          <1> 	call	_set_mode ; 24/06/2016 (set_txt_mode)
   319                              <1> 
   320                              <1> ; 12/05/2016
   321                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   322                              <1> 
   323                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
   324                              <1> 
   325                              <1> VIDEO_RETURN:
   326 00001400 A1[442D0100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
   327                              <1> _video_return:
   328 00001405 5D                  <1> 	pop	ebp
   329 00001406 5F                  <1> 	pop	edi
   330 00001407 5E                  <1> 	pop	esi
   331 00001408 5B                  <1> 	pop	ebx
   332                              <1> M15:	; VIDEO_RETURN_C
   333 00001409 59                  <1> 	pop	ecx
   334 0000140A 5A                  <1> 	pop	edx
   335 0000140B 1F                  <1> 	pop	ds
   336 0000140C 07                  <1> 	pop	es	; RECOVER SEGMENTS
   337 0000140D CF                  <1> 	iret		; ALL DONE
   338                              <1> 
   339                              <1> set_txt_mode:
   340                              <1> 	; 29/07/2016
   341                              <1> 	; 27/06/2016
   342 0000140E B003                <1> 	mov	al, 3
   343                              <1> 
   344                              <1> ; 08/08/2016
   345                              <1> ; 30/07/2016
   346                              <1> ; 29/07/2016
   347                              <1> ; 27/07/2016
   348                              <1> ; 26/07/2016
   349                              <1> ; 25/07/2016
   350                              <1> ; 23/07/2016
   351                              <1> ; 18/07/2016
   352                              <1> ; 07/07/2016
   353                              <1> ; 04/07/2016
   354                              <1> ; 03/07/2016
   355                              <1> ; 02/07/2016
   356                              <1> ; 26/06/2016
   357                              <1> ; 24/06/2016 (set_txt_mode -> _set_mode)
   358                              <1> ; 17/06/2016
   359                              <1> ; 29/05/2016
   360                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   361                              <1> _set_mode:
   362                              <1> 	; 24/06/2016
   363 00001410 3805[06E90000]      <1> 	cmp	[CRT_MODE], al  ; current mode = requested mode ?
   364 00001416 750D                <1> 	jne	short _sm_0
   365 00001418 3C03                <1> 	cmp	al, 3		; text, 80*25 color, default mode
   366                              <1> 				; for TRDOS 386 MainProg
   367 0000141A 755F                <1>         jne     short _sm_2	;  multiscreen is only for mode 3
   368                              <1> 
   369                              <1> 	; If '_set_mode' procedure is called for video mode 3
   370                              <1> 	;     while video mode is 3, video page will be cleared
   371                              <1> 	;     and cursor position of video page will be reset.	  
   372                              <1> 	
   373                              <1> 	; 29/07/2016
   374 0000141C 800D[512D0100]80    <1> 	or	byte [p_crt_mode], 80h ; clear page indicator
   375 00001423 EB5B                <1>         jmp     short _sm_3
   376                              <1> _sm_0:  
   377 00001425 803D[06E90000]03    <1> 	cmp	byte [CRT_MODE], 3
   378 0000142C 7534                <1>         jne     short _sm_1
   379                              <1> 
   380                              <1> 	; If '_set_mode' procedure is called for a video mode
   381                              <1> 	;     except video mode 3, while current video mode
   382                              <1> 	;     is 3; all video pages of mode 3 will be copied 
   383                              <1> 	;     to 98000h address as backup, before mode change.	
   384                              <1> 
   385                              <1> _sm_save_pm:
   386                              <1> 	; 03/07/2016
   387                              <1> 	; save video pages
   388 0000142E BE00800B00          <1> 	mov	esi, 0B8000h
   389 00001433 BF00800900          <1> 	mov	edi, 98000h ; 30/07/2016
   390 00001438 B900200000          <1> 	mov	ecx, (0B8000h-0B0000h)/4
   391 0000143D F3A5                <1> 	rep	movsd
   392                              <1> 
   393 0000143F C605[512D0100]03    <1> 	mov	byte [p_crt_mode], 3 ; previous mode, backup sign
   394                              <1> 	;mov	cl, [ACTIVE_PAGE]
   395                              <1> 	;mov	[p_crt_page], cl
   396                              <1> 
   397                              <1> 	; save cursor positions
   398 00001446 BE[E61F0100]        <1> 	mov	esi, CURSOR_POSN
   399 0000144B BF[562D0100]        <1> 	mov	edi, cursor_pposn    ; cursor positions backup
   400 00001450 B104                <1> 	mov	cl, 4
   401 00001452 F3A5                <1> 	rep	movsd
   402                              <1> 
   403                              <1> 	; 29/07/2016
   404                              <1> 	;mov	[ACTIVE_PAGE], cl ; 0
   405 00001454 860D[F61F0100]      <1> 	xchg	cl, [ACTIVE_PAGE]
   406 0000145A 880D[522D0100]      <1> 	mov	[p_crt_page], cl     ; previous page (for mode 3)	
   407                              <1> 	; [ACTIVE_PAGE] = 0 
   408 00001460 EB19                <1> 	jmp	short _sm_2
   409                              <1> 
   410                              <1> _sm_1:
   411 00001462 3C03                <1> 	cmp	al, 3		; text, 80*25 color, default mode
   412                              <1> 				; for TRDOS 386 MainProg
   413 00001464 7515                <1> 	jne	short _sm_2  ;  multiscreen is only for mode 3
   414                              <1> 
   415                              <1> 	; If '_set_mode' procedure is called for video mode 3
   416                              <1> 	;     while video mode is not 3 and if there is video
   417                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
   418                              <1> 	;     video pages will be restored from 98000h.
   419                              <1> 
   420 00001466 803D[512D0100]03    <1> 	cmp	byte [p_crt_mode], 3 ; previous mode, backup sign
   421 0000146D 750C                <1> 	jne	short _sm_2 ; there is no (multiscreen) video pages
   422                              <1> 			 ; to be restored
   423 0000146F 8A0D[522D0100]      <1> 	mov	cl, [p_crt_page]
   424 00001475 880D[F61F0100]      <1> 	mov	[ACTIVE_PAGE], cl
   425                              <1> 
   426                              <1> _sm_2:
   427 0000147B A2[06E90000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
   428                              <1> _sm_3:
   429                              <1> 	; 30/07/2016
   430                              <1> 	; 26/07/2016
   431                              <1> 	; 25/07/2016
   432                              <1> 	; set_mode_vga:
   433                              <1> 	; 18/07/2016
   434                              <1> 	; 14/07/2016
   435                              <1> 	; 09/07/2016
   436                              <1> 	; 04/07/2016
   437                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
   438                              <1> 	; /// video mode 13h ///
   439                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   440                              <1> 	; vgabios-0.7a (2011)
   441                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
   442                              <1> 	; 'vgabios.c', 'vgatables.h'
   443                              <1> 	;
   444                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
   445                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
   446                              <1> 	;
   447 00001480 88C4                <1> 	mov	ah, al
   448 00001482 B910000000          <1> 	mov	ecx, vga_mode_count 	
   449 00001487 BE[22E90000]        <1> 	mov	esi, vga_modes
   450 0000148C 31DB                <1> 	xor	ebx, ebx
   451                              <1> _sm_4:
   452 0000148E AC                  <1> 	lodsb
   453 0000148F 38C4                <1> 	cmp	ah, al
   454 00001491 740C                <1> 	je	short _sm_5
   455 00001493 FEC3                <1> 	inc	bl
   456 00001495 E2F7                <1> 	loop	_sm_4
   457                              <1> 
   458                              <1> 	; UNIMPLEMENTED VIDEO MODE !
   459 00001497 31C0                <1> 	xor	eax, eax
   460 00001499 A3[442D0100]        <1>         mov     [video_eax], eax ; 0 
   461 0000149E C3                  <1> 	retn
   462                              <1> 
   463                              <1> ;-----	eBX POINTS TO CORRECT ROW OF INITIALIZATION TABLE	
   464                              <1> 
   465                              <1> _sm_5: 	; 25/07/2016
   466 0000149F 89DE                <1> 	mov	esi, ebx
   467 000014A1 81C6[72E90000]      <1> 	add	esi, vga_memmodel
   468 000014A7 8A06                <1> 	mov	al, [esi]
   469 000014A9 A2[6A2D0100]        <1> 	mov	[VGA_MTYPE], al
   470                              <1> 
   471 000014AE 89DF                <1> 	mov	edi, ebx
   472 000014B0 81C7[82E90000]      <1> 	add	edi, vga_dac_s 	
   473 000014B6 C0E302              <1> 	shl	bl, 2 ; byte -> dword
   474 000014B9 81C3[32E90000]      <1> 	add	ebx, vga_mode_tbl_ptr
   475                              <1> 
   476                              <1> 	;mov	dword [VGA_BASE], 0B8000h
   477                              <1> 	;cmp	ah, 0Dh ; [CRT_MODE]
   478                              <1> 	;jb	short M9 
   479                              <1> 	;mov	dword [VGA_BASE], 0A0000h
   480                              <1> ;M9:
   481 000014BF 8B33                <1> 	mov	esi, [ebx]
   482 000014C1 89F3                <1> 	mov	ebx, esi
   483 000014C3 83C614              <1> 	add	esi, vga_p_cm_pos ; ebx + 20
   484 000014C6 668B06              <1> 	mov	ax, [esi]       ; get the cursor mode from the table
   485 000014C9 66A3[1FE90000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode (initial value)
   486                              <1> 	; al = 6, ah = 7
   487                              <1> 	; al = 0Dh, ah = 0Eh ; 25/07/2016
   488 000014CF E835020000          <1> 	call	cursor_shape_fix
   489                              <1> 	; al = 14, ah = 15  (If [CHAR_HEIGHT] = 16)
   490 000014D4 668906              <1> 	mov	[esi], ax
   491                              <1> 
   492 000014D7 56                  <1> 	push	esi ; *	
   493                              <1> 
   494 000014D8 8A25[0DE90000]      <1> 	mov	ah, [VGA_MODESET_CTL]
   495 000014DE 80E408              <1> 	and	ah, 8 ; default palette loading ?
   496 000014E1 7524                <1> 	jnz	short _sm_6
   497 000014E3 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK (DAC mask register)
   498 000014E7 B0FF                <1> 	mov	al, 0FFh ; PEL mask
   499 000014E9 EE                  <1> 	out	dx, al
   500 000014EA 8A27                <1> 	mov	ah, [edi] ; DAC model (selection number)
   501 000014EC E8480F0000          <1> 	call	load_dac_palette
   502                              <1> 	; ecx = 0
   503 000014F1 F605[0DE90000]02    <1> 	test	byte [VGA_MODESET_CTL], 2 ; gray scale summing
   504 000014F8 740D                <1> 	jz	short _sm_6
   505 000014FA 53                  <1> 	push	ebx
   506 000014FB 29DB                <1> 	sub	ebx, ebx ; sub bl, bl
   507 000014FD 66B90001            <1>         mov     cx, 256 
   508 00001501 E8860F0000          <1> 	call	gray_scale_summing
   509 00001506 5B                  <1> 	pop	ebx	
   510                              <1> _sm_6:
   511                              <1> 	; Reset Attribute Ctl flip-flop
   512 00001507 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
   513 0000150B EC                  <1>  	in	al, dx
   514                              <1> 	; Set Attribute Ctl
   515 0000150C 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   516 0000150E 83C623              <1> 	add	esi, 35  ; actl regs
   517 00001511 30E4                <1> 	xor	ah, ah ; 0
   518 00001513 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
   519                              <1> _sm_7:
   520 00001517 88E0                <1> 	mov	al, ah
   521 00001519 EE                  <1> 	out	dx, al ; index
   522 0000151A AC                  <1> 	lodsb
   523                              <1> 	; DX = 3C0h = VGAREG_ACTL_WRITE_DATA
   524 0000151B EE                  <1> 	out	dx, al ; value
   525 0000151C FEC4                <1> 	inc	ah
   526 0000151E 80FC14              <1> 	cmp	ah, 20 ; number of actl registers
   527 00001521 72F4                <1> 	jb	short _sm_7
   528                              <1> 	;
   529 00001523 88E0                <1> 	mov	al, ah ; 20
   530 00001525 EE                  <1> 	out	dx, al ; index
   531 00001526 28C0                <1> 	sub	al, al ; 0
   532 00001528 EE                  <1> 	out	dx, al ; value
   533                              <1> 	;
   534                              <1> 	; Set Sequencer Ctl
   535 00001529 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   536 0000152B 83C605              <1> 	add	esi, 5 ; sequ regs
   537                              <1> 	;
   538 0000152E 66BAC403            <1> 	mov	dx, 3C4h  ; VGAREG_SEQU_ADDRESS
   539 00001532 EE                  <1> 	out	dx, al ; 0
   540 00001533 6642                <1> 	inc	dx ; 3C5h ; VGAREG_SEQU_DATA
   541 00001535 B003                <1> 	mov	al, 3
   542 00001537 EE                  <1> 	out	dx, al
   543 00001538 B401                <1> 	mov	ah, 1	
   544                              <1> _sm_8:
   545 0000153A 88E0                <1> 	mov	al, ah
   546                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   547 0000153C 664A                <1> 	dec	dx
   548 0000153E EE                  <1> 	out	dx, al ; index
   549 0000153F AC                  <1> 	lodsb
   550 00001540 6642                <1> 	inc	dx ; 3C5h ; VGAREG_SEQU_DATA
   551 00001542 EE                  <1> 	out	dx, al
   552 00001543 80FC04              <1> 	cmp	ah, 4 ; number of sequ regs
   553 00001546 7304                <1> 	jnb	short _sm_9		
   554 00001548 FEC4                <1> 	inc	ah 
   555 0000154A EBEE                <1> 	jmp	short _sm_8
   556                              <1> _sm_9:
   557                              <1> 	; Set Grafx Ctl
   558 0000154C 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   559 0000154E 83C637              <1> 	add	esi, 55 ; grdc regs
   560 00001551 30E4                <1> 	xor	ah, ah ; 0
   561                              <1> _sm_10:
   562 00001553 88E0                <1> 	mov	al, ah
   563 00001555 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
   564 00001559 EE                  <1> 	out	dx, al	
   565 0000155A AC                  <1> 	lodsb
   566 0000155B 6642                <1> 	inc	dx ; 3CFh ; VGAREG_GRDC_DATA
   567 0000155D EE                  <1> 	out	dx, al
   568 0000155E FEC4                <1> 	inc	ah
   569 00001560 80FC09              <1> 	cmp	ah, 9 ; number of grdc regs
   570 00001563 72EE                <1> 	jb	short _sm_10
   571                              <1> 	;
   572                              <1> 	; Disable CRTC write protection
   573 00001565 66BAD403            <1> 	mov	dx, 3D4h  ; VGAREG_VGA_CRTC_ADDRESS
   574                              <1> 	;mov	al, 11h
   575                              <1> 	;our	dx, al
   576                              <1> 	;inc	dx
   577                              <1> 	;sub	al, al
   578                              <1> 	;out	dx, al
   579 00001569 66B81100            <1> 	mov	ax, 11h
   580 0000156D 66EF                <1> 	out	dx, ax
   581 0000156F 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   582 00001571 83C60A              <1> 	add	esi, 10 ; crtc regs
   583                              <1> 	; ah = 0
   584                              <1> _sm_11:
   585 00001574 88E0                <1> 	mov	al, ah
   586                              <1> 	; dx = 3D4h = VGAREG_VGA_CRTC_ADDRESS
   587 00001576 EE                  <1> 	out	dx, al ; index
   588 00001577 AC                  <1> 	lodsb
   589 00001578 6642                <1> 	inc	dx  ; VGAREG_VGA_CRTC_ADDRESS + 1
   590 0000157A EE                  <1> 	out	dx, al ; value
   591 0000157B 80FC18              <1> 	cmp	ah, 24 ; number of crtc registers - 1
   592 0000157E 7306                <1> 	jnb	short _sm_12
   593 00001580 FEC4                <1> 	inc	ah
   594 00001582 664A                <1> 	dec	dx ; 3D4h
   595 00001584 EBEE                <1> 	jmp	short _sm_11
   596                              <1> _sm_12:
   597                              <1> 	; Set the misc register
   598 00001586 66BACC03            <1> 	mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
   599 0000158A 8A4309              <1> 	mov	al, [ebx+9] ; misc reg
   600 0000158D EE                  <1> 	out	dx, al
   601                              <1> 	;
   602                              <1> 	; Enable video
   603 0000158E 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
   604 00001592 B020                <1> 	mov	al, 20h  
   605 00001594 EE                  <1>         out     dx, al   ; set bit 5 to 1
   606 00001595 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
   607 00001599 EC                  <1> 	in	al, dx
   608                              <1> 	;
   609 0000159A 803D[532D0100]00    <1> 	cmp	byte [noclearmem], 0
   610 000015A1 7740                <1>         ja      short _sm_15
   611                              <1> 
   612                              <1> 	; 29/07/2016
   613 000015A3 31C0                <1> 	xor	eax, eax
   614 000015A5 B900400000          <1> 	mov	ecx, 4000h ; 16K words (32K)
   615 000015AA 803D[6A2D0100]02    <1> 	cmp     byte [VGA_MTYPE], 2  ; CTEXT, MTEXT, CGA
   616 000015B1 7715                <1> 	ja	short _sm_14    ; no ? (0A0000h)
   617 000015B3 BF00800B00          <1> 	mov	edi, 0B8000h
   618 000015B8 7409                <1> 	je	short _sm_13	; CGA graphics mode
   619                              <1> 	; 08/08/2016
   620 000015BA A3[662D0100]        <1> 	mov	[VGA_INT43H], eax ; 0 ; default font 
   621 000015BF 66B82007            <1> 	mov	ax, 0720h	; CGA text mode
   622                              <1> _sm_13:
   623 000015C3 F366AB              <1> 	rep	stosw
   624 000015C6 EB1B                <1> 	jmp	short _sm_15		
   625                              <1> 
   626                              <1> _sm_14:
   627 000015C8 BF00000A00          <1> 	mov	edi, 0A0000h
   628                              <1> 	; ecx = 16384 dwords  (64K)
   629 000015CD 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   630 000015D1 B002                <1> 	mov	al, 2
   631 000015D3 EE                  <1> 	out	dx, al
   632                              <1> 	;mov	dx, 3C5h ; VGAREG_SEQU_DATA
   633 000015D4 6642                <1> 	inc	dx
   634 000015D6 EC                  <1> 	in	al, dx ; mmask
   635 000015D7 6650                <1> 	push	ax
   636 000015D9 B00F                <1> 	mov	al, 0Fh ; all planes
   637 000015DB EE                  <1> 	out	dx, al
   638 000015DC 30C0                <1> 	xor	al, al ; 0
   639 000015DE F3AB                <1> 	rep	stosd	; ecx = 163684 (64K)
   640 000015E0 6658                <1> 	pop	ax
   641 000015E2 EE                  <1> 	out	dx, al  ; mmask
   642                              <1> _sm_15:
   643                              <1> 	; ebx = addr of params tbl for selected mode
   644 000015E3 8A03                <1> 	mov	al, [ebx] ; num of columns, 'twidth'
   645 000015E5 A2[08E90000]        <1> 	mov	[CRT_COLS], al
   646                              <1> 	; 26/07/2016
   647                              <1> 	; CRTC_ADDRESS = 3D4h (always)
   648 000015EA 8A6301              <1> 	mov	ah, [ebx+1] ; num of rows, 'theightm1'
   649 000015ED FEC4                <1> 	inc	ah ; 09/07/2016
   650 000015EF 8825[0EE90000]      <1> 	mov	[VGA_ROWS], ah
   651                              <1> 	; 29/07/2016
   652                              <1> 	; length of regen buffer in bytes
   653 000015F5 668B4B03            <1> 	mov	cx, [ebx+3] ; 'slength_l'
   654 000015F9 66890D[542D0100]    <1> 	mov	[CRT_LEN], cx
   655                              <1> 	;
   656                              <1> 	; 27/07/2016
   657 00001600 30E4                <1> 	xor	ah, ah
   658 00001602 A0[F61F0100]        <1> 	mov	al, [ACTIVE_PAGE] ; may be > 0 for mode 3
   659                              <1> 	;mul	word [CRT_LEN] ; 4096 for mode 3
   660 00001607 66F7E1              <1> 	mul	cx ; 29/07/2016
   661 0000160A 66A3[E41F0100]      <1> 	mov	[CRT_START], ax
   662                              <1> 	;
   663 00001610 B060                <1> 	mov	al, 60h
   664 00001612 803D[532D0100]00    <1> 	cmp	byte [noclearmem], 0
   665 00001619 7602                <1> 	jna	short _sm_16
   666 0000161B 0480                <1> 	add	al, 80h
   667                              <1> _sm_16:
   668 0000161D A2[0BE90000]        <1> 	mov	[VGA_VIDEO_CTL], al
   669 00001622 C605[0CE90000]F9    <1> 	mov	byte [VGA_SWITCHES], 0F9h
   670 00001629 8025[0DE90000]7F    <1> 	and	byte [VGA_MODESET_CTL], 7Fh
   671                              <1> 
   672 00001630 5E                  <1> 	pop	esi ; *
   673                              <1> 
   674                              <1> 	; 26/07/2016
   675                              <1> 	; 07/07/2016
   676 00001631 668B0D[1FE90000]    <1> 	mov	cx, [CURSOR_MODE] ; restore cursor mode (initial value)
   677 00001638 66870E              <1> 	xchg	cx, [esi] ; cl = start line, ch = end line
   678                              <1> 			  ; reset to initial value
   679 0000163B 86E9                <1> 	xchg 	ch, cl  ; ch = start line, cl = end line  
   680 0000163D 66890D[1FE90000]    <1> 	mov	[CURSOR_MODE], cx ; save (fixed) cursor mode
   681                              <1> 
   682                              <1> 	; 27/07/2016
   683 00001644 803D[6A2D0100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
   684 0000164B 7317                <1> 	jnb	short _sm_17
   685                              <1> 
   686                              <1> 	; Set cursor shape
   687                              <1> 	;mov	cx, 0607h
   688                              <1> 	;call	_set_ctype
   689                              <1> 
   690                              <1> 	; 29/07/2016
   691 0000164D B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
   692 0000164F E88E050000          <1> 	call	m16	; output cx register
   693                              <1> 	
   694                              <1> 	; 25/07/2016
   695 00001654 803D[06E90000]03    <1>         cmp     byte [CRT_MODE], 03h
   696 0000165B 7507                <1> 	jne	short _sm_17
   697                              <1> 	; 26/07/2016
   698                              <1> 
   699 0000165D A0[F61F0100]        <1> 	mov	al, [ACTIVE_PAGE]
   700 00001662 EB0C                <1> 	jmp	short _sm_18
   701                              <1> _sm_17:
   702                              <1> 	; Set cursor pos for page 0..7
   703 00001664 6629C0              <1> 	sub	ax, ax ; eax = 0
   704 00001667 BF[E61F0100]        <1> 	mov	edi, CURSOR_POSN
   705 0000166C AB                  <1> 	stosd	
   706 0000166D AB                  <1> 	stosd
   707 0000166E AB                  <1> 	stosd
   708 0000166F AB                  <1> 	stosd
   709                              <1> 	;; Set active page 0
   710                              <1> 	;mov	[ACTIVE_PAGE], al ; 0
   711                              <1> _sm_18:
   712                              <1> 	; 29/07/2016
   713 00001670 803D[6A2D0100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
   714 00001677 0F8386000000        <1>         jnb	_sm_23
   715                              <1> 
   716                              <1> 	;cmp	byte [CHAR_HEIGHT], 16
   717                              <1> 	;je	short _sm_19
   718                              <1> 
   719                              <1>  	;; copy and activate 8x16 font
   720                              <1> 	
   721                              <1> 	; 26/07/2016
   722 0000167D B004                <1> 	mov	al, 04h
   723                              <1> 	;sub	bl, bl
   724                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set
   725                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
   726 0000167F E89B140000          <1> 	call	load_text_8_16_pat
   727                              <1> 
   728                              <1> 	; video_func_1103h:
   729                              <1> 	; biosfn_set_text_block_specifier:
   730                              <1> 	; BL = font block selector code	
   731                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
   732                              <1> 	; (It is as BL = 0 for TRDOS 386)
   733 00001684 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   734                              <1> 	;mov	ah, bl
   735 00001688 28E4                <1> 	sub	ah, ah ; 0
   736 0000168A B003                <1> 	mov	al, 03h
   737 0000168C 66EF                <1> 	out	dx, ax
   738                              <1> _sm_19:
   739                              <1> 	; 29/07/2016
   740                              <1> 	; 26/07/2016
   741                              <1> 	; 24/06/2016
   742                              <1> 	;mov	edi, 0B8000h
   743                              <1> 	;mov	cx, 4000h ; 16K words (32K)
   744                              <1> 	;
   745 0000168E 30C0                <1> 	xor	al, al
   746 00001690 3805[512D0100]      <1>         cmp     byte [p_crt_mode], al ; 0 
   747 00001696 7707                <1>         ja      short _sm_20 ; 3h, 80h or 83h
   748                              <1> 
   749                              <1> 	; 30/07/2016
   750                              <1> 	; 24/06/2016
   751                              <1> 	; TRDOS 386 (TRDOS v2) 'set mode' modification
   752                              <1> 	; (for multiscreen feature):
   753                              <1> 	; If '_set_mode' procedure is called for video mode 3
   754                              <1> 	;     while video mode is 3, video page will be cleared
   755                              <1> 	;     and cursor position of video page will be reset.	  
   756                              <1> 	; If '_set_mode' procedure is called for a video mode
   757                              <1> 	;     except video mode 3, while current video mode
   758                              <1> 	;     is 3; all video pages of mode 3 will be copied 
   759                              <1> 	;     to 98000h address as backup, before mode change.	 	
   760                              <1> 	; If '_set_mode' procedure is called for video mode 3
   761                              <1> 	;     while video mode is not 3 and if there is video
   762                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
   763                              <1> 	;     video pages will be restored from 98000h.
   764                              <1> 
   765 00001698 A2[F61F0100]        <1> 	mov	[ACTIVE_PAGE], al ; 0
   766                              <1> 	;mov	ax, 0720h
   767                              <1> 	;;mov	cx, 4000h ; 16K words (32K)
   768                              <1> 	;;mov	edi, 0B8000h
   769                              <1> 	;rep	stosw
   770                              <1> 	;sub	al, al
   771 0000169D EB64                <1> 	jmp	short _sm_23
   772                              <1> _sm_20:
   773                              <1> 	; Previous video mode is 3
   774                              <1> 	; New video mode is 3 while current video mode is not 3
   775                              <1> 	; (multi screen) video pages will be restored from 0B0000h
   776                              <1> 
   777 0000169F 0FB61D[F61F0100]    <1> 	movzx	ebx, byte [ACTIVE_PAGE]
   778 000016A6 D0E3                <1> 	shl	bl, 1 ; * 2
   779 000016A8 81C3[E61F0100]      <1> 	add	ebx, CURSOR_POSN
   780                              <1> 
   781                              <1> 	; 29/07/2016
   782 000016AE F605[512D0100]7F    <1> 	test    byte [p_crt_mode], 7Fh ; 83h or 3h
   783 000016B5 7427                <1> 	jz	short _sm_21	; do not restore video pages
   784                              <1> 
   785                              <1> 	;; restore video pages
   786 000016B7 BE00800900          <1> 	mov	esi, 98000h ; 30/07/2016 
   787 000016BC BF00800B00          <1> 	mov	edi, 0B8000h
   788 000016C1 66B90020            <1> 	mov	cx, 2000h ; 8K dwords (32K)
   789 000016C5 F3A5                <1> 	rep	movsd
   790                              <1> 
   791                              <1> 	; restore cursor positions
   792 000016C7 BE[562D0100]        <1> 	mov	esi, cursor_pposn
   793 000016CC BF[E61F0100]        <1> 	mov	edi, CURSOR_POSN
   794                              <1> 	;mov	ecx, 4	; restore all cursor positions (16 bytes)
   795 000016D1 B104                <1> 	mov	cl, 4
   796 000016D3 F3A5                <1> 	rep 	movsd
   797                              <1> 
   798 000016D5 F605[512D0100]80    <1>         test    byte [p_crt_mode], 80h
   799 000016DC 7420                <1> 	jz	short _sm_22 ; do not clear current video pages
   800                              <1> _sm_21:
   801                              <1> 	; clear video page
   802 000016DE 668B0D[542D0100]    <1> 	mov	cx, [CRT_LEN] ; 4096 
   803 000016E5 66D1E9              <1> 	shr	cx, 1 ; 2072
   804 000016E8 66B82007            <1> 	mov	ax, 0720h
   805 000016EC BF00800B00          <1> 	mov	edi, 0B8000h ; [crt_base]
   806 000016F1 66033D[E41F0100]    <1> 	add	di, [CRT_START]
   807 000016F8 F366AB              <1> 	rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
   808                              <1> 	;
   809 000016FB 66890B              <1> 	mov	[ebx], cx ; reset cursor position
   810                              <1> _sm_22:
   811 000016FE A2[512D0100]        <1> 	mov	[p_crt_mode], al ; 0
   812                              <1> _sm_23:
   813                              <1> 	; al = video page number
   814                              <1> 	; [CRT_LEN] = length of regen buffer in bytes
   815 00001703 E8E8000000          <1> 	call	_set_active_page
   816                              <1> 
   817                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
   818 00001708 C3                  <1> 	retn
   819                              <1> 
   820                              <1> cursor_shape_fix:
   821                              <1> 	; 07/07/2016
   822                              <1> 	; (Cursor start and cursor end line values -6,7-
   823                              <1> 	; will be fixed depending on character height)
   824                              <1> 	;
   825                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   826                              <1> 	; vgabios-0.7a (2011)
   827                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
   828                              <1> 	; 'vgabios.c', ' biosfn_set_cursor_shape (CH,CL)'
   829                              <1> 	;
   830                              <1> 	; INPUT ->
   831                              <1> 	;	AL = cursor start line (=6)
   832                              <1> 	;	AH = cursor end line (=7)
   833                              <1> 	; OUTPUT ->
   834                              <1> 	;	AL = cursor start line (=14)
   835                              <1> 	;	AH = cursor end line (=15)
   836                              <1> 	;
   837                              <1> 	;; if((modeset_ctl&0x01)&&(cheight>8)&&(CL<8)&&(CH<0x20))
   838                              <1> 
   839                              <1> 	;test	byte [VGA_MODESET_CTL], 1 ; VGA active
   840                              <1> 	;jz	short csf_3
   841 00001709 803D[0AE90000]08    <1> 	cmp	byte [CHAR_HEIGHT], 8
   842 00001710 7649                <1> 	jna	short csf_3
   843 00001712 80FC08              <1> 	cmp	ah, 8
   844 00001715 7344                <1> 	jnb	short csf_3
   845 00001717 3C20                <1> 	cmp	al, 20h
   846 00001719 7340                <1> 	jnb	short csf_3
   847                              <1> 	;
   848 0000171B 6650                <1> 	push	ax
   849                              <1> 	; {
   850                              <1>    	; if(CL!=(CH+1))	
   851 0000171D FEC0                <1> 	inc	al
   852 0000171F 38C4                <1> 	cmp	ah, al   ; ah != al + 1
   853 00001721 740F                <1>         je      short csf_1
   854                              <1> 	; CH = ((CH+1) * cheight / 8) -1;
   855 00001723 8A25[0AE90000]      <1> 	mov	ah, [CHAR_HEIGHT]
   856 00001729 F6E4                <1> 	mul	ah
   857 0000172B C0E803              <1> 	shr	al, 3 ; / 8
   858 0000172E FEC8                <1> 	dec	al ; - 1
   859 00001730 EB0E                <1> 	jmp	short csf_2 
   860                              <1> csf_1: 	
   861                              <1>  	; }
   862                              <1>    	; else		; ah = al + 1
   863                              <1>     	; {
   864 00001732 FEC4                <1> 	inc	ah	; ah = ah + 1   
   865                              <1> 	; CH = ((CL+1) * cheight / 8) - 2;
   866 00001734 A0[0AE90000]        <1> 	mov	al, [CHAR_HEIGHT]
   867 00001739 F6E4                <1> 	mul	ah
   868 0000173B C0E803              <1> 	shr	al, 3 ; / 8
   869 0000173E 2C02                <1> 	sub	al, 2 ; - 2
   870                              <1> 	; al = 14 (if [CHAR_HEIGHT] = 16)
   871                              <1> csf_2:
   872 00001740 880424              <1> 	mov	[esp], al
   873 00001743 8A642401            <1> 	mov	ah, [esp+1]
   874                              <1> 	; CL = ((CL+1) * cheight / 8) - 1;
   875 00001747 FEC4                <1> 	inc	ah 
   876 00001749 A0[0AE90000]        <1> 	mov	al, [CHAR_HEIGHT]
   877 0000174E F6E4                <1> 	mul	ah
   878 00001750 C0E803              <1> 	shr	al, 3 ; / 8
   879 00001753 FEC8                <1> 	dec	al ; - 1
   880 00001755 88442401            <1> 	mov	[esp+1], al
   881                              <1> 	; ah = 15 (if [CHAR_HEIGHT] = 16)
   882                              <1> 	;
   883 00001759 6658                <1> 	pop	ax
   884                              <1> csf_3:
   885 0000175B C3                  <1> 	retn
   886                              <1> 
   887                              <1> SET_CTYPE:
   888                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   889 0000175C E805000000          <1> 	call	_set_ctype
   890 00001761 E99AFCFFFF          <1>         jmp     VIDEO_RETURN
   891                              <1> 
   892                              <1> _set_ctype:
   893                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
   894                              <1> 	;
   895                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
   896                              <1> 
   897                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
   898                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
   899                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
   900                              <1> 	;     OR NO CURSOR AT ALL
   901                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
   902                              <1> 
   903                              <1> ;------------------------------------------------
   904                              <1> ; SET_CTYPE
   905                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
   906                              <1> ; INPUT
   907                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
   908                              <1> ; OUTPUT	
   909                              <1> ;	NONE
   910                              <1> ;------------------------------------------------
   911                              <1> 
   912                              <1> 	; 07/07/2016
   913                              <1> 	; Fixing cursor start and stop line depending on
   914                              <1> 	; current character height (=16)
   915                              <1> 	; (Note: Default/initial values are 6 and 7.
   916                              <1> 	; If set values are 6 (start) & 7 (stop) and 
   917                              <1> 	; [CHAR_HEIGHT] = 16 :
   918                              <1> 	; After fixing, start line will be 14, stop line
   919                              <1> 	; will be 15.)
   920 00001766 6689C8              <1> 	mov	ax, cx
   921 00001769 86C4                <1> 	xchg	al, ah
   922                              <1> 	; AL = start line, AH = stop line
   923 0000176B E899FFFFFF          <1> 	call	cursor_shape_fix
   924                              <1> 	; AL = start line (fixed), AH = stop line (fixed)
   925 00001770 6689C1              <1> 	mov	cx, ax
   926 00001773 86E9                <1> 	xchg	ch, cl
   927                              <1> 	; CH = start line (fixed), CL = stop line (fixed)
   928                              <1> 	;
   929 00001775 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
   930 00001777 66890D[1FE90000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
   931                              <1> 	;call	m16	; output cx register
   932                              <1> 	;retn
   933 0000177E E95F040000          <1>         jmp     m16
   934                              <1> 
   935                              <1> SET_CPOS:
   936                              <1> 	; 07/07/2016
   937                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   938 00001783 80FF07              <1> 	cmp	bh, 7 ; video page > 7 ; 07/07/2016
   939 00001786 0F8774FCFFFF        <1> 	ja	VIDEO_RETURN
   940                              <1> 	;
   941 0000178C E826040000          <1> 	call	_set_cpos
   942 00001791 E96AFCFFFF          <1>         jmp     VIDEO_RETURN
   943                              <1> 
   944                              <1> READ_CURSOR:
   945                              <1> 	; 07/07/2016
   946                              <1> 	; 12/05/2016
   947                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   948                              <1> 	;
   949                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
   950                              <1> 
   951                              <1> ;------------------------------------------------------
   952                              <1> ; READ_CURSOR
   953                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
   954                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
   955                              <1> ; INPUT
   956                              <1> ;	BH - PAGE OF CURSOR
   957                              <1> ; OUTPUT
   958                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
   959                              <1> ;	CX - CURRENT CURSOR MODE
   960                              <1> ;------------------------------------------------------
   961                              <1> 
   962                              <1> 	; BH = Video page number (0 to 7)
   963                              <1> 
   964                              <1> 	; 07/07/2016
   965 00001796 80FF07              <1> 	cmp	bh, 7 ; video page > 7 (invalid)
   966 00001799 7606                <1> 	jna	short read_cursor_1
   967                              <1> 	; invalid video page (input) 
   968 0000179B 31C9                <1> 	xor	ecx, ecx ; 0
   969 0000179D 31D2                <1> 	xor	edx, edx ; 0
   970 0000179F EB0C                <1> 	jmp	short read_cursor_2
   971                              <1> read_cursor_1:
   972 000017A1 E815000000          <1> 	call	get_cpos
   973 000017A6 0FB70D[1FE90000]    <1> 	movzx	ecx, word [CURSOR_MODE]
   974                              <1> read_cursor_2:
   975 000017AD 5D                  <1> 	pop	ebp
   976 000017AE 5F                  <1> 	pop	edi
   977 000017AF 5E                  <1> 	pop	esi
   978 000017B0 5B                  <1> 	pop	ebx
   979 000017B1 58                  <1> 	pop	eax  ; DISCARD SAVED CX AND DX
   980 000017B2 58                  <1> 	pop	eax
   981 000017B3 A1[442D0100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
   982 000017B8 1F                  <1> 	pop	ds
   983 000017B9 07                  <1> 	pop	es
   984 000017BA CF                  <1> 	iret
   985                              <1> 
   986                              <1> get_cpos:
   987                              <1> 	; 12/05/2016
   988                              <1> 	; 16/01/2016
   989                              <1> 	; BH = Video page number (0 to 7)
   990                              <1> 	;
   991 000017BB D0E7                <1> 	shl	bh, 1 ; WORD OFFSET
   992 000017BD 0FB6F7              <1> 	movzx	esi, bh 
   993 000017C0 0FB796[E61F0100]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
   994 000017C7 C3                  <1> 	retn
   995                              <1> 
   996                              <1> ACT_DISP_PAGE:
   997                              <1> 	; 07/07/2016
   998                              <1> 	; 26/06/2016
   999                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1000                              <1> 	;
  1001                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1002                              <1> 	;
  1003                              <1> ;-----------------------------------------------------
  1004                              <1> ; ACT_DISP_PAGE
  1005                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  1006                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  1007                              <1> ; INPUT
  1008                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  1009                              <1> ; OUTPUT
  1010                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  1011                              <1> ;-----------------------------------------------------
  1012                              <1> 	; 07/07/2016
  1013 000017C8 3C07                <1> 	cmp	al, 7	; > 7 = invalid video page number
  1014 000017CA 0F8730FCFFFF        <1> 	ja	VIDEO_RETURN
  1015 000017D0 803D[06E90000]03    <1>         cmp     byte [CRT_MODE], 3
  1016 000017D7 7408                <1> 	je	short adp_1
  1017 000017D9 20C0                <1> 	and 	al, al
  1018 000017DB 0F851FFCFFFF        <1>         jnz     VIDEO_RETURN
  1019                              <1> 	;sub	al, al ; 0 ; force to page 0
  1020                              <1> adp_1:	
  1021 000017E1 E805000000          <1> 	call	set_active_page
  1022 000017E6 E915FCFFFF          <1>         jmp     VIDEO_RETURN
  1023                              <1> 
  1024                              <1> set_active_page:   ; tty_sw
  1025                              <1> 	; 26/07/2016
  1026                              <1> 	; 26/06/2016
  1027                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1028                              <1> 	; 30/06/2015
  1029                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  1030                              <1> 	; 10/12/2013
  1031                              <1> 	; 04/12/2013
  1032                              <1> 	;
  1033 000017EB A2[F61F0100]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  1034                              <1> _set_active_page:
  1035                              <1> 	; 27/06/2015
  1036 000017F0 0FB6D8              <1> 	movzx	ebx, al
  1037                              <1> 	;
  1038 000017F3 6698                <1> 	cbw	; 07/09/2014 (ah=0)
  1039 000017F5 66F725[542D0100]    <1> 	mul	word [CRT_LEN]  ; get saved length of regen buffer
  1040                              <1> 				; display page times regen length
  1041                              <1> 	; 10/12/2013
  1042 000017FC 66A3[E41F0100]      <1> 	mov	[CRT_START], ax ; save start address for later
  1043 00001802 6689C1              <1> 	mov	cx, ax ; start address to cx
  1044                              <1> _M16:
  1045                              <1> 	;sar	cx, 1
  1046 00001805 66D1E9              <1> 	shr	cx, 1	; divide by 2 for 6845 handling
  1047 00001808 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  1048 0000180A E8D3030000          <1> 	call	m16
  1049                              <1> 	;sal	bx, 1
  1050                              <1> 	; 01/09/2014
  1051 0000180F D0E3                <1> 	shl	bl, 1	; *2 for word offset
  1052 00001811 81C3[E61F0100]      <1> 	add	ebx, CURSOR_POSN
  1053 00001817 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  1054                              <1> 	; 16/01/2016
  1055                              <1> 	;call	m18
  1056                              <1> 	;retn
  1057 0000181A E9AF030000          <1> 	jmp	m18
  1058                              <1> 
  1059                              <1> position:
  1060                              <1> 	; 24/06/2016
  1061                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1062                              <1> 	; 27/06/2015
  1063                              <1> 	; 02/09/2014
  1064                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1065                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  1066                              <1> 	;
  1067                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1068                              <1> 	;
  1069                              <1> ;-----------------------------------------
  1070                              <1> ; POSITION
  1071                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  1072                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  1073                              <1> ; INPUT
  1074                              <1> ;	AX = ROW, COLUMN POSITION
  1075                              <1> ; OUTPUT
  1076                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  1077                              <1> ;-----------------------------------------
  1078                              <1> 
  1079                              <1> 	; DX = ROW, COLUMN POSITION
  1080 0000181F 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS] ; 24/06/2016
  1081 00001826 F6E6                <1> 	mul	dh	 ; row value
  1082 00001828 30F6                <1> 	xor	dh, dh   ; 0	
  1083 0000182A 6601D0              <1> 	add	ax, dx	 ; add column value to the result
  1084 0000182D 66D1E0              <1> 	shl	ax, 1	; * 2 for attribute bytes
  1085                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  1086 00001830 C3                  <1> 	retn
  1087                              <1> 
  1088                              <1> find_position:
  1089                              <1> 	; 24/06/2016
  1090                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1091                              <1> 	; 27/06/2015
  1092                              <1> 	; 07/09/2014
  1093                              <1> 	; 02/09/2014
  1094                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1095                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1096                              <1> 
  1097 00001831 0FB6CF              <1> 	movzx	ecx, bh ; video page number
  1098 00001834 89CE                <1> 	mov	esi, ecx
  1099 00001836 66D1E6              <1> 	shl	si, 1
  1100 00001839 668B96[E61F0100]    <1> 	mov	dx, [esi+CURSOR_POSN]
  1101 00001840 740C                <1> 	jz	short p21
  1102 00001842 6631F6              <1> 	xor	si, si
  1103                              <1> p20:
  1104 00001845 660335[542D0100]    <1> 	add	si, [CRT_LEN] ; 24/06/2016
  1105                              <1> 	;add	si, 80*25*2 ; add length of buffer for one page		
  1106 0000184C E2F7                <1> 	loop	p20
  1107                              <1> p21:
  1108 0000184E 6621D2              <1> 	and	dx, dx
  1109 00001851 7407                <1> 	jz	short p22
  1110 00001853 E8C7FFFFFF          <1> 	call 	position ; determine location in regen in page
  1111 00001858 01C6                <1> 	add	esi, eax ; add location to start of regen page
  1112                              <1> p22:	
  1113                              <1> 	;mov	dx, [addr_6845] ; get base address of active display			
  1114                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  1115                              <1> 	;add	dx, 6	; point at status port
  1116 0000185A 66BADA03            <1> 	mov	dx, 03DAh ; status port
  1117                              <1> 	; cx = 0
  1118 0000185E C3                  <1> 	retn
  1119                              <1> 
  1120                              <1> SCROLL_UP:
  1121                              <1> 	; 07/07/2016
  1122                              <1> 	; 26/06/2016
  1123                              <1> 	; 12/05/2016
  1124                              <1> 	; 30/01/2016
  1125                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1126                              <1> 	; 07/09/2014
  1127                              <1> 	; 02/09/2014
  1128                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  1129                              <1> 	; 04/04/2014
  1130                              <1> 	; 04/12/2013
  1131                              <1> 	;
  1132                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1133                              <1> 	;
  1134                              <1> ;----------------------------------------------
  1135                              <1> ; SCROLL UP
  1136                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  1137                              <1> ;	ON THE SCREEN
  1138                              <1> ; INPUT
  1139                              <1> ;	(AH) = CURRENT CRT MODE
  1140                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  1141                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  1142                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  1143                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  1144                              <1> ;	(DS) = DATA SEGMENT
  1145                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  1146                              <1> ; OUTPUT
  1147                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  1148                              <1> ;--------------------------------------------
  1149                              <1> 
  1150                              <1> 	; 07/07/2016
  1151 0000185F 38F5                <1> 	cmp	ch, dh
  1152 00001861 0F8799FBFFFF        <1> 	ja	VIDEO_RETURN
  1153 00001867 38D1                <1> 	cmp	cl, dl
  1154 00001869 0F8791FBFFFF        <1> 	ja	VIDEO_RETURN
  1155                              <1> 	;
  1156 0000186F E805000000          <1> 	call	_scroll_up
  1157 00001874 E987FBFFFF          <1>         jmp     VIDEO_RETURN
  1158                              <1> 
  1159                              <1> _scroll_up:  ; from 'write_tty'
  1160                              <1> 	;
  1161                              <1> 	; cl = left upper column
  1162                              <1> 	; ch = left upper row
  1163                              <1> 	; dl = right lower column
  1164                              <1> 	; dh = right lower row
  1165                              <1> 	;
  1166                              <1> 	; al = line count 
  1167                              <1> 	; bl = attribute to be used on blanked line	
  1168                              <1> 	; bh = video page number (0 to 7)
  1169                              <1> 
  1170 00001879 E896000000          <1> 	call	test_line_count ; 16/01/2016
  1171                              <1> 
  1172 0000187E 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  1173                              <1> 	;cmp	ah, 4
  1174                              <1>  	;jb	short n0
  1175                              <1> 	;cmp	byte [CRT_MODE], 4
  1176 00001884 80FC04              <1>         cmp	ah, 4 ; 07/07/2016
  1177 00001887 0F83B7040000        <1> 	jnb     GRAPHICS_UP ; 26/06/2016
  1178                              <1> 
  1179                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1180                              <1> 	;jne	GRAPHICS_UP
  1181                              <1> n0:
  1182                              <1> 	; 07/07/2016
  1183 0000188D 80FF07              <1> 	cmp	bh, 7 ; video page number
  1184 00001890 7606                <1> 	jna	short n1
  1185 00001892 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  1186                              <1> n1:
  1187 00001898 88DC                <1> 	mov	ah, bl ; attribute
  1188 0000189A 6650                <1> 	push	ax ; *
  1189                              <1> 	;mov 	esi, [CRT_BASE]
  1190 0000189C BE00800B00          <1>         mov     esi, 0B8000h  
  1191 000018A1 3A3D[F61F0100]      <1>         cmp     bh, [ACTIVE_PAGE]
  1192 000018A7 750B                <1> 	jne	short n2
  1193                              <1> 	;
  1194 000018A9 66A1[E41F0100]      <1>         mov     ax, [CRT_START]
  1195 000018AF 6601C6              <1>         add     si, ax
  1196 000018B2 EB11                <1>         jmp     short n4
  1197                              <1> n2:
  1198 000018B4 20FF                <1>         and     bh, bh
  1199 000018B6 740D                <1> 	jz	short n4
  1200 000018B8 88F8                <1> 	mov	al, bh
  1201                              <1> n3:
  1202 000018BA 660335[542D0100]    <1>         add	si, [CRT_LEN]
  1203 000018C1 FEC8                <1>         dec	al
  1204 000018C3 75F5                <1> 	jnz	short n3
  1205                              <1> n4:	
  1206 000018C5 E85D000000          <1> 	call	scroll_position ; 16/01/2016
  1207 000018CA 7420                <1>         jz      short n6 
  1208                              <1> 
  1209 000018CC 01CE                <1>         add     esi, ecx ; from address for scroll
  1210 000018CE 88F5                <1> 	mov	ch, dh  ; #rows in block
  1211 000018D0 28C5                <1> 	sub	ch, al	; #rows to be moved
  1212                              <1> n5:
  1213 000018D2 E894000000          <1> 	call	n10 ; 16/01/2016
  1214                              <1> 	
  1215 000018D7 51                  <1>         push	ecx
  1216 000018D8 0FB60D[08E90000]    <1> 	movzx	ecx, byte [CRT_COLS] 
  1217 000018DF 00C9                <1> 	add	cl, cl
  1218 000018E1 01CE                <1>         add	esi, ecx  ; next line
  1219 000018E3 01CF                <1>         add	edi, ecx
  1220 000018E5 59                  <1> 	pop	ecx
  1221                              <1> 
  1222 000018E6 FECD                <1> 	dec	ch	 ; count of lines to move
  1223 000018E8 75E8                <1> 	jnz	short n5 ; row loop
  1224                              <1> 	; ch = 0
  1225 000018EA 88C6                <1> 	mov	dh, al	 ; #rows	
  1226                              <1> n6:
  1227                              <1> 	; attribute in ah
  1228 000018EC B020                <1> 	mov	al, ' '	 ; fill with blanks
  1229                              <1> n7:
  1230 000018EE E885000000          <1> 	call	n11 ; 16/01/2016
  1231                              <1> 
  1232 000018F3 8A0D[08E90000]      <1> 	mov	cl, [CRT_COLS]
  1233 000018F9 00C9                <1> 	add	cl, cl
  1234 000018FB 01CF                <1>         add	edi, ecx
  1235                              <1> 
  1236 000018FD FECE                <1> 	dec	dh
  1237 000018FF 75ED                <1> 	jnz	short n7
  1238                              <1> n16:
  1239 00001901 3A3D[F61F0100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  1240 00001907 750A                <1> 	jne	short n8
  1241                              <1> 	
  1242                              <1> 	;cmp	byte [CRT_MODE], 7	; is this the black and white card
  1243                              <1> 	;je	short n8		; if so, skip the mode reset
  1244                              <1> 
  1245 00001909 A0[07E90000]        <1> 	mov	al, [CRT_MODE_SET] ; get the value of mode set
  1246 0000190E 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  1247 00001912 EE                  <1> 	out	dx, al
  1248                              <1> n8:
  1249 00001913 C3                  <1> 	retn
  1250                              <1> 
  1251                              <1> test_line_count:
  1252                              <1> 	; 12/05/2016
  1253                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1254                              <1> 	; 07/09/2014 (scroll_up)
  1255 00001914 08C0                <1> 	or	al, al
  1256 00001916 740E                <1> 	jz	short al_set2
  1257 00001918 6652                <1> 	push	dx
  1258 0000191A 28EE                <1> 	sub	dh, ch  ; subtract upper row from lower row number
  1259 0000191C FEC6                <1> 	inc	dh	; adjust difference by 1
  1260 0000191E 38C6                <1> 	cmp	dh, al 	; line count = amount of rows in window?
  1261 00001920 7502                <1> 	jne	short al_set1 ; if not the we're all set
  1262 00001922 30C0                <1> 	xor	al, al	; otherwise set al to zero
  1263                              <1> al_set1:
  1264 00001924 665A                <1> 	pop	dx
  1265                              <1> al_set2:
  1266 00001926 C3                  <1> 	retn
  1267                              <1> 
  1268                              <1> scroll_position:
  1269                              <1> 	; 26/06/2016
  1270                              <1> 	; 30/01/2016
  1271                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1272                              <1> 	; 07/09/2014 (scroll_up)
  1273                              <1> 
  1274 00001927 6652                <1> 	push	dx
  1275 00001929 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  1276 0000192C E8EEFEFFFF          <1> 	call	position
  1277 00001931 01C6                <1> 	add	esi, eax
  1278 00001933 89F7                <1> 	mov	edi, esi
  1279 00001935 665A                <1> 	pop	dx	; lower right position in DX
  1280 00001937 6629CA              <1> 	sub	dx, cx
  1281 0000193A FEC6                <1> 	inc	dh	; dh = #rows 
  1282 0000193C FEC2                <1> 	inc	dl	; dl = #cols in block
  1283 0000193E 59                  <1> 	pop	ecx 	; return address
  1284 0000193F 6658                <1> 	pop	ax	; * ; al = line count, ah = attribute
  1285 00001941 51                  <1> 	push	ecx	; return address
  1286 00001942 0FB7C8              <1> 	movzx	ecx, ax
  1287 00001945 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS]
  1288 0000194B F6E4                <1> 	mul	ah	; determine offset to from address
  1289 0000194D 6601C0              <1> 	add	ax, ax  ; *2 for attribute byte
  1290                              <1> 	;
  1291 00001950 6650                <1> 	push	ax	; offset 
  1292 00001952 6652                <1> 	push	dx
  1293                              <1> 	;
  1294                              <1> 	; 04/04/2014
  1295 00001954 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  1296                              <1> n9:                      ; wait_display_enable
  1297 00001958 EC                  <1>         in      al, dx   ; get port
  1298 00001959 A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  1299 0000195B 74FB                <1> 	jz	short n9 ; wait_display_enable
  1300 0000195D B025                <1> 	mov	al, 25h
  1301 0000195F B2D8                <1> 	mov	dl, 0D8h ; address control port
  1302 00001961 EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  1303 00001962 665A                <1> 	pop	dx	; #rows, #cols
  1304 00001964 6658                <1>        	pop	ax	; offset
  1305 00001966 6691                <1> 	xchg	ax, cx	; 
  1306                              <1> 	; ecx = offset, al = line count, ah = attribute
  1307                              <1> 	;
  1308 00001968 08C0                <1> 	or	al, al
  1309 0000196A C3                  <1> 	retn
  1310                              <1> n10:
  1311                              <1> 	; Move rows
  1312 0000196B 88D1                <1> 	mov	cl, dl	; get # of cols to move
  1313 0000196D 56                  <1> 	push	esi
  1314 0000196E 57                  <1> 	push	edi	; save start address
  1315                              <1> n10r:
  1316 0000196F 66A5                <1> 	movsw		; move that line on screen
  1317 00001971 FEC9                <1> 	dec	cl
  1318 00001973 75FA                <1>         jnz     short n10r
  1319 00001975 5F                  <1> 	pop	edi
  1320 00001976 5E                  <1> 	pop	esi	; recover addresses
  1321 00001977 C3                  <1> 	retn
  1322                              <1> n11:
  1323                              <1> 	; Clear rows
  1324                              <1>                 	; dh =  #rows
  1325 00001978 88D1                <1>         mov	cl, dl	; get # of cols to clear
  1326 0000197A 57                  <1>         push    edi     ; save address
  1327                              <1> n11r:
  1328 0000197B 66AB                <1>         stosw           ; store fill character
  1329 0000197D FEC9                <1> 	dec	cl
  1330 0000197F 75FA                <1>         jnz     short n11r
  1331 00001981 5F                  <1>         pop     edi     ; recover address
  1332 00001982 C3                  <1> 	retn
  1333                              <1> 
  1334                              <1> SCROLL_DOWN:
  1335                              <1> 	; 07/07/2016
  1336                              <1> 	; 27/06/2016
  1337                              <1> 	; 26/06/2016
  1338                              <1> 	; 12/05/2016
  1339                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1340                              <1> 	;
  1341                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1342                              <1> 
  1343                              <1> ;------------------------------------------
  1344                              <1> ; SCROLL DOWN
  1345                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  1346                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  1347                              <1> ;	WITH A DEFINED CHARACTER
  1348                              <1> ; INPUT
  1349                              <1> ;	(AH) = CURRENT CRT MODE
  1350                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  1351                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  1352                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  1353                              <1> ;	(BH) = FILL CHARACTER
  1354                              <1> ;	(DS) = DATA SEGMENT
  1355                              <1> ;	(ES) = REGEN SEGMENT
  1356                              <1> ; OUTPUT
  1357                              <1> ;	NONE -- SCREEN IS SCROLLED
  1358                              <1> ;------------------------------------------
  1359                              <1> 
  1360                              <1> 	; 07/07/2016
  1361 00001983 38F5                <1> 	cmp	ch, dh
  1362 00001985 0F8775FAFFFF        <1> 	ja	VIDEO_RETURN
  1363 0000198B 38D1                <1> 	cmp	cl, dl
  1364 0000198D 0F876DFAFFFF        <1> 	ja	VIDEO_RETURN
  1365                              <1> 	;
  1366 00001993 E805000000          <1> 	call	_scroll_down
  1367 00001998 E963FAFFFF          <1>         jmp     VIDEO_RETURN
  1368                              <1> 
  1369                              <1> _scroll_down: ; 27/06/2016
  1370                              <1> 
  1371                              <1> 	; cl = left upper column
  1372                              <1> 	; ch = left upper row
  1373                              <1> 	; dl = right lower column
  1374                              <1> 	; dh = right lower row
  1375                              <1> 	;
  1376                              <1> 	; al = line count 
  1377                              <1> 	; bl = attribute to be used on blanked line	
  1378                              <1> 	; bh = video page number (0 to 7)
  1379                              <1> 
  1380                              <1> 	; !!!!
  1381 0000199D FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  1382                              <1> 	; !!!!
  1383 0000199E E871FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  1384                              <1> 	
  1385 000019A3 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  1386                              <1> 	;cmp	ah, 4
  1387                              <1>  	;jb	short _n0
  1388                              <1> 	;cmp	byte [CRT_MODE], 4
  1389 000019A9 80FC04              <1>         cmp	ah, 4 ; 07/07/2016
  1390 000019AC 0F8376070000        <1> 	jnb     GRAPHICS_DOWN ; 26/06/2016
  1391                              <1> 
  1392                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1393                              <1> 	;jne	GRAPHICS_DOWN
  1394                              <1> _n0:
  1395                              <1> 	; 07/07/2016
  1396 000019B2 80FF07              <1> 	cmp	bh, 7 ; video page number
  1397 000019B5 7606                <1> 	jna	short n12
  1398 000019B7 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  1399                              <1> 	;
  1400                              <1> n12:			; CONTINUE_DOWN
  1401 000019BD 88DC                <1> 	mov	ah, bl
  1402 000019BF 6650                <1> 	push	ax	; * ; save attribute in ah
  1403 000019C1 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  1404 000019C4 E85EFFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  1405 000019C9 741F                <1> 	jz	short n14
  1406 000019CB 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  1407 000019CD 88F5                <1> 	mov	ch, dh  ; #rows in block
  1408 000019CF 28C5                <1> 	sub	ch, al	; #rows to be moved
  1409                              <1> n13:
  1410 000019D1 E895FFFFFF          <1> 	call	n10	; MOVE ONE ROW
  1411                              <1> 
  1412 000019D6 51                  <1> 	push	ecx
  1413 000019D7 8A0D[08E90000]      <1> 	mov	cl, [CRT_COLS] 
  1414 000019DD 00C9                <1> 	add	cl, cl
  1415 000019DF 29CE                <1>         sub	esi, ecx  ; next line
  1416 000019E1 29CF                <1>         sub	edi, ecx
  1417 000019E3 59                  <1>         pop	ecx
  1418                              <1> 	
  1419 000019E4 FECD                <1> 	dec	ch	 ; count of lines to move
  1420 000019E6 75E9                <1> 	jnz	short n13 ; row loop
  1421                              <1> 	; ch = 0
  1422 000019E8 88C6                <1> 	mov	dh, al	 ; #rows
  1423                              <1> n14:
  1424                              <1> 	; attribute in ah
  1425 000019EA B020                <1> 	mov	al, ' '	 ; fill with blanks
  1426                              <1> n15:
  1427 000019EC E887FFFFFF          <1> 	call	n11 ; 16/01/2016
  1428                              <1> 
  1429 000019F1 8A0D[08E90000]      <1> 	mov	cl, [CRT_COLS]
  1430 000019F7 00C9                <1> 	add	cl, cl
  1431 000019F9 29CF                <1>         sub	edi, ecx
  1432                              <1>         
  1433 000019FB FECE                <1> 	dec	dh
  1434 000019FD 75ED                <1> 	jnz	short n15
  1435                              <1> 	;
  1436 000019FF E9FDFEFFFF          <1> 	jmp	n16 ; 27/06/2016
  1437                              <1> 
  1438                              <1> ;	cmp	bh, [ACTIVE_PAGE]
  1439                              <1> ;	jne	short n16
  1440                              <1> ;
  1441                              <1> ;	;cmp	byte [CRT_MODE], 7	; is this the black and white card
  1442                              <1> ;	;je	short n16		; if so, skip the mode reset
  1443                              <1> ;
  1444                              <1> ;	mov	al, [CRT_MODE_SET] ; get the value of mode set
  1445                              <1> ;	mov	dx, 03D8h ; always set color card port
  1446                              <1> ;	out	dx, al
  1447                              <1> ;n16:
  1448                              <1> ;	; !!!!
  1449                              <1> ;	cld		; Clear direction flag !
  1450                              <1> ;	; !!!!
  1451                              <1> ;	retn
  1452                              <1> 
  1453                              <1> READ_AC_CURRENT:
  1454                              <1> 	; 08/07/2016
  1455                              <1> 	; 26/06/2016
  1456                              <1> 	; 12/05/2016
  1457                              <1> 	; 18/01/2016
  1458                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1459                              <1> 	;
  1460                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1461                              <1> 	;
  1462                              <1> 	; 08/07/2016
  1463 00001A04 803D[06E90000]07    <1>         cmp     byte [CRT_MODE], 7 ; 6!?
  1464 00001A0B 7607                <1> 	jna	short read_ac_c
  1465 00001A0D 31C0                <1> 	xor	eax, eax
  1466 00001A0F E9F1F9FFFF          <1>         jmp     _video_return 
  1467                              <1> read_ac_c:
  1468 00001A14 E805000000          <1> 	call	_read_ac_current
  1469                              <1> 	; 12/05/2016
  1470                              <1>         ;jmp     VIDEO_RETURN
  1471 00001A19 E9E7F9FFFF          <1> 	jmp	_video_return
  1472                              <1> 
  1473                              <1> ;------------------------------------------------------------------------
  1474                              <1> ; READ_AC_CURRENT							:
  1475                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  1476                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  1477                              <1> ; INPUT									:
  1478                              <1> ;	(AH) = CURRENT CRT MODE						:
  1479                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  1480                              <1> ;	(DS) = DATA SEGMENT						:
  1481                              <1> ;	(ES) = REGEN SEGMENT						:
  1482                              <1> ; OUTPUT								:
  1483                              <1> ;	(AL) = CHARACTER READ						:
  1484                              <1> ;	(AH) = ATTRIBUTE READ						:
  1485                              <1> ;------------------------------------------------------------------------
  1486                              <1> 
  1487                              <1> _read_ac_current:
  1488                              <1> 	; 26/06/2016
  1489                              <1> 	; 12/05/2016 
  1490                              <1> 	; 18/01/2016
  1491                              <1> 
  1492                              <1> 	;mov	ah, [CRT_MODE] ; current video mode	
  1493                              <1> 	;cmp	ah, 4
  1494                              <1>  	;jb	short p10
  1495 00001A1E 803D[06E90000]04    <1> 	cmp	byte [CRT_MODE], 4
  1496 00001A25 0F8352080000        <1> 	jnb     GRAPHICS_READ ; 26/06/2016
  1497                              <1> 
  1498                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1499                              <1> 	;jne	GRAPHICS_READ
  1500                              <1> p10:
  1501 00001A2B E801FEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  1502                              <1> 	;
  1503                              <1> 	; esi = regen location
  1504                              <1> 	; dx = status port
  1505                              <1> 	;
  1506 00001A30 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE]	
  1507 00001A36 80EC02              <1> 	sub	ah, 2
  1508 00001A39 D0EC                <1> 	shr	ah, 1
  1509 00001A3B 7515                <1> 	jnz	short p13
  1510                              <1> 
  1511                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  1512                              <1> p11:
  1513 00001A3D FB                  <1> 	sti		; enable interrupts first
  1514 00001A3E 3A3D[F61F0100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  1515 00001A44 750C                <1> 	jne	short p13 
  1516 00001A46 FA                  <1> 	cli 		; block interrupts for single loop
  1517 00001A47 EC                  <1> 	in	al, dx	; get status from the adapter
  1518 00001A48 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  1519 00001A4A 75F1                <1> 	jnz	short p11 ; wait until it is
  1520                              <1> p12:			;  wait for either retrace high
  1521 00001A4C EC                  <1> 	in	al, dx ; get status again
  1522 00001A4D A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  1523 00001A4F 74FB                <1> 	jz	short p12 ; wait until either retrace active
  1524 00001A51 FB                  <1> 	sti
  1525                              <1> p13:
  1526 00001A52 81C600800B00        <1> 	add	esi, 0B8000h 
  1527 00001A58 668B06              <1> 	mov	ax, [esi]
  1528                              <1> 
  1529 00001A5B C3                  <1> 	retn	; 18/01/2016
  1530                              <1> 
  1531                              <1> WRITE_AC_CURRENT:
  1532                              <1> 	; 08/07/2016
  1533                              <1> 	; 26/06/2016
  1534                              <1> 	; 24/06/2016
  1535                              <1> 	; 12/05/2016
  1536                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1537                              <1> 	;
  1538                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1539                              <1> 	;
  1540                              <1> ;----------------------------------------------------------------
  1541                              <1> ; WRITE_AC_CURRENT						:
  1542                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  1543                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  1544                              <1> ; INPUT								:
  1545                              <1> ;	(AH) = CURRENT CRT MODE					:
  1546                              <1> ;	(BH) = DISPLAY PAGE					:
  1547                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  1548                              <1> ;	(AL) = CHAR TO WRITE					:
  1549                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  1550                              <1> ;	(DS) = DATA SEGMENT					:
  1551                              <1> ;	(ES) = REGEN SEGMENT					:
  1552                              <1> ; OUTPUT							:
  1553                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  1554                              <1> ;----------------------------------------------------------------
  1555                              <1> 
  1556                              <1> 	; 08/07/2016
  1557 00001A5C 803D[06E90000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  1558 00001A63 760A                <1> 	jna	short write_ac_c
  1559                              <1> 
  1560 00001A65 E8890A0000          <1> 	call	vga_write_char_attr
  1561 00001A6A E991F9FFFF          <1> 	jmp     VIDEO_RETURN	
  1562                              <1> 
  1563                              <1> write_ac_c:
  1564 00001A6F E834000000          <1> 	call	_write_c_current
  1565                              <1> 
  1566 00001A74 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  1567 00001A77 889E[0FE90000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  1568                              <1> 
  1569 00001A7D E97EF9FFFF          <1>         jmp     VIDEO_RETURN
  1570                              <1> 
  1571                              <1> WRITE_C_CURRENT:
  1572                              <1> 	; 08/07/2016
  1573                              <1> 	; 26/06/2016
  1574                              <1> 	; 12/05/2016
  1575                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1576                              <1> 	;
  1577                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1578                              <1> 	;
  1579                              <1> ;----------------------------------------------------------------
  1580                              <1> ; WRITE_C_CURRENT						:
  1581                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  1582                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  1583                              <1> ; INPUT								:
  1584                              <1> ;	(AH) = CURRENT CRT MODE					:
  1585                              <1> ;	(BH) = DISPLAY PAGE					:
  1586                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  1587                              <1> ;	(AL) = CHAR TO WRITE					:
  1588                              <1> ;	(DS) = DATA SEGMENT					:
  1589                              <1> ;	(ES) = REGEN SEGMENT					:
  1590                              <1> ; OUTPUT							:
  1591                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  1592                              <1> ;----------------------------------------------------------------
  1593                              <1> 
  1594                              <1> 	; 08/07/2016
  1595 00001A82 803D[06E90000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  1596 00001A89 760A                <1> 	jna	short write_c_c
  1597                              <1> 
  1598 00001A8B E8630A0000          <1> 	call	vga_write_char_only
  1599 00001A90 E96BF9FFFF          <1> 	jmp     VIDEO_RETURN	
  1600                              <1> 
  1601                              <1> write_c_c:
  1602                              <1> 	;and	bh, 7 ; video page number (<= 7)
  1603 00001A95 0FB6F7              <1> 	movzx	esi, bh	
  1604 00001A98 8A9E[0FE90000]      <1> 	mov	bl, [esi+chr_attrib]
  1605                              <1> 
  1606 00001A9E E805000000          <1> 	call	_write_c_current
  1607 00001AA3 E958F9FFFF          <1>         jmp     VIDEO_RETURN
  1608                              <1> 
  1609                              <1> _write_c_current:  ; from 'write_tty'
  1610                              <1> 	; 26/06/2016
  1611                              <1> 	; 24/06/2016
  1612                              <1> 	; 12/05/2016
  1613                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1614                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1615                              <1> 	; 18/01/2014
  1616                              <1> 	; 04/12/2013
  1617                              <1> 	;
  1618                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1619                              <1> 
  1620                              <1> 	;mov	ah, [CRT_MODE] ; current video mode	
  1621                              <1> 	;cmp	ah, 4
  1622                              <1>  	;jb	short p40
  1623 00001AA8 803D[06E90000]04    <1> 	cmp	byte [CRT_MODE], 4
  1624 00001AAF 0F8318070000        <1>         jnb     GRAPHICS_WRITE ; 26/06/2016
  1625                              <1> 
  1626                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1627                              <1> 	;jne	GRAPHICS_WRITE
  1628                              <1> p40:
  1629                              <1> 	; al = character
  1630                              <1> 	; bl = color/attribute
  1631                              <1> 	; bh = video page
  1632                              <1> 	; cx = count of characters to write
  1633 00001AB5 6652                <1> 	push	dx
  1634 00001AB7 88DC                <1> 	mov	ah, bl  ; color/attribute (12/05/2016)
  1635 00001AB9 6650                <1> 	push	ax	; save character & attribute/color
  1636 00001ABB 6651                <1> 	push	cx
  1637 00001ABD E86FFDFFFF          <1> 	call 	find_position  ; get regen location and port address
  1638 00001AC2 6659                <1> 	pop	cx
  1639                              <1> 	; esi = regen location
  1640                              <1> 	; dx = status port
  1641                              <1> 	;
  1642 00001AC4 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  1643                              <1> 	;
  1644 00001ACA 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE]	
  1645 00001AD0 80EC02              <1> 	sub	ah, 2
  1646 00001AD3 D0EC                <1> 	shr	ah, 1
  1647 00001AD5 7519                <1> 	jnz	short p44    ; 26/06/2016
  1648                              <1> 
  1649                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  1650                              <1> p41:
  1651 00001AD7 FB                  <1> 	sti		; enable interrupts first
  1652 00001AD8 3A3D[F61F0100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  1653 00001ADE 7510                <1> 	jne	short p44 
  1654 00001AE0 FA                  <1> 	cli 		; block interrupts for single loop
  1655 00001AE1 EC                  <1> 	in	al, dx	; get status from the adapter
  1656 00001AE2 A808                <1> 	test	al, RVRT ; check for vertical retrace first
  1657 00001AE4 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  1658 00001AE6 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  1659 00001AE8 75ED                <1> 	jnz	short p41 ; wait until it is
  1660                              <1> p42:			;  wait for either retrace high
  1661 00001AEA EC                  <1> 	in	al, dx ; get status again
  1662 00001AEB A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  1663 00001AED 74FB                <1> 	jz	short p42 ; wait until either retrace active
  1664                              <1> p43:	
  1665 00001AEF FB                  <1> 	sti
  1666                              <1> p44:
  1667 00001AF0 668B0424            <1> 	mov	ax, [esp] ; restore the character (al) & attribute (ah)
  1668 00001AF4 668906              <1> 	mov	[esi], ax
  1669                              <1> 
  1670 00001AF7 6649                <1> 	dec	cx
  1671 00001AF9 7404                <1> 	jz	short p45
  1672                              <1> 
  1673 00001AFB 46                  <1> 	inc	esi
  1674 00001AFC 46                  <1> 	inc	esi
  1675 00001AFD EBD8                <1> 	jmp	short p41
  1676                              <1> p45:	
  1677 00001AFF 6658                <1> 	pop	ax
  1678 00001B01 665A                <1> 	pop	dx
  1679 00001B03 C3                  <1> 	retn
  1680                              <1> 
  1681                              <1> ; 09/07/2016
  1682                              <1> ; 26/06/2016
  1683                              <1> ; 24/06/2016
  1684                              <1> ; 12/05/2016
  1685                              <1> ; 18/01/2016
  1686                              <1> ; 16/01/2016 - TRDOS 386 (TRDOS v2.0)
  1687                              <1> ; 30/06/2015
  1688                              <1> ; 27/06/2015
  1689                              <1> ; 11/03/2015
  1690                              <1> ; 02/09/2014
  1691                              <1> ; 30/08/2014
  1692                              <1> ; VIDEO FUNCTIONS
  1693                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  1694                              <1> 
  1695                              <1> WRITE_TTY:
  1696                              <1> 	; 09/07/2016
  1697                              <1> 	; 01/07/2016
  1698                              <1> 	; 26/06/2016
  1699                              <1> 	; 24/06/2016
  1700                              <1> 	; 13/05/2016
  1701                              <1> 	; 12/05/2016
  1702                              <1> 	; 30/01/2016
  1703                              <1> 	; 18/01/2016
  1704                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1705                              <1> 	; 13/08/2015
  1706                              <1> 	; 02/09/2014
  1707                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  1708                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  1709                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  1710                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  1711                              <1> 	;
  1712                              <1> 	; INPUT -> AL = Character to be written
  1713                              <1> 	;	   BL = Color (Forecolor, Backcolor)
  1714                              <1> 	;	   BH = Video Page (0 to 7)
  1715                              <1> 
  1716                              <1> 	; 09/07/2016
  1717 00001B04 803D[06E90000]07    <1>         cmp     byte [CRT_MODE], 7
  1718 00001B0B 760A                <1> 	jna 	short write_tty_cga
  1719                              <1> 
  1720 00001B0D E8C00C0000          <1> 	call	vga_write_teletype
  1721 00001B12 E9E9F8FFFF          <1> 	jmp	VIDEO_RETURN
  1722                              <1> 
  1723                              <1> write_tty_cga:
  1724                              <1> 	; 13/05/2016
  1725                              <1> 	;call	_write_tty
  1726                              <1> 	; 01/07/2016
  1727 00001B17 E818000000          <1> 	call	_write_tty_m3
  1728 00001B1C E9DFF8FFFF          <1> 	jmp	VIDEO_RETURN
  1729                              <1> 
  1730                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  1731                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  1732                              <1> 
  1733                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  1734                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  1735                              <1> ;
  1736                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  1737                              <1> ;
  1738                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  1739                              <1> ;										:
  1740                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  1741                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  1742                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  1743                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  1744                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  1745                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  1746                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  1747                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  1748                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  1749                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  1750                              <1> ;   THE 0 COLOR IS USED.							:
  1751                              <1> ;   ENTRY --									:
  1752                              <1> ;     (AH) = CURRENT CRT MODE							:
  1753                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  1754                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  1755                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  1756                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  1757                              <1> ;   EXIT -- 									:
  1758                              <1> ;     ALL REGISTERS SAVED							:
  1759                              <1> ;--------------------------------------------------------------------------------
  1760                              <1> 
  1761                              <1> ; 08/07/2016
  1762                              <1> ; 26/06/2016
  1763                              <1> ; 24/06/2016
  1764                              <1> _write_tty:	; 13/05/2016
  1765 00001B21 FA                  <1> 	cli
  1766                              <1> 	;
  1767                              <1> 	; 01/09/2014
  1768 00001B22 803D[06E90000]03    <1> 	cmp	byte [CRT_MODE], 3
  1769 00001B29 7409                <1> 	je	short _write_tty_m3
  1770                              <1> 	;
  1771                              <1> set_mode_3:
  1772 00001B2B 53                  <1> 	push	ebx
  1773 00001B2C 50                  <1> 	push	eax
  1774 00001B2D E8DEF8FFFF          <1> 	call	_set_mode
  1775 00001B32 58                  <1> 	pop	eax
  1776 00001B33 5B                  <1> 	pop	ebx
  1777                              <1> 	;
  1778                              <1> _write_tty_m3: ; 24/06/2016 (m3 -> _write_tty_m3)
  1779 00001B34 0FB6F7              <1> 	movzx 	esi, bh ; 12/05/2016
  1780 00001B37 66D1E6              <1> 	shl	si, 1
  1781 00001B3A 81C6[E61F0100]      <1> 	add	esi, CURSOR_POSN
  1782 00001B40 668B16              <1> 	mov	dx, [esi]
  1783                              <1> 	;
  1784                              <1> 	; dx now has the current cursor position
  1785                              <1> 	;
  1786 00001B43 3C0D                <1> 	cmp	al, 0Dh	; CR	; is it carriage return or control character
  1787 00001B45 7636                <1> 	jbe	short u8
  1788                              <1> 	;
  1789                              <1> 	; write the char to the screen
  1790                              <1> u0:	
  1791                              <1> 	; al = character
  1792                              <1> 	; bl = attribute/color
  1793                              <1> 	; bh = video page number (0 to 7)
  1794                              <1> 	;
  1795 00001B47 66B90100            <1> 	mov	cx, 1  ; 24/06/2016
  1796                              <1> 	; cx = count of characters to write
  1797                              <1> 	;
  1798 00001B4B E858FFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  1799                              <1> 	;
  1800                              <1> 	; position the cursor for next char
  1801 00001B50 FEC2                <1> 	inc	dl		; next column
  1802 00001B52 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS]  ; test for column overflow 
  1803 00001B58 755D                <1>         jne     _set_cpos
  1804 00001B5A B200                <1> 	mov	dl, 0		; column = 0
  1805                              <1> u10:				; (line feed found)
  1806 00001B5C 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  1807 00001B5F 7218                <1> 	jb 	short u6
  1808                              <1> 	;
  1809                              <1> 	; scroll required
  1810                              <1> u1:	
  1811                              <1> 	; SET CURSOR POSITION (04/12/2013)
  1812 00001B61 E851000000          <1> 	call	_set_cpos
  1813                              <1> 	;
  1814                              <1> 	; determine value to fill with during scroll
  1815                              <1> u2:
  1816                              <1> 	; bh = video page number
  1817                              <1> 	;
  1818 00001B66 E8B3FEFFFF          <1> 	call	_read_ac_current ; 18/01/2016
  1819                              <1> 	;
  1820                              <1> 	; al = character, ah = attribute
  1821                              <1> 	; bh = video page number 	
  1822                              <1> u3:
  1823                              <1> 	;;mov	ax, 0601h 	; scroll one line
  1824                              <1> 	;;sub	cx, cx		; upper left corner
  1825                              <1> 	;;mov	dh, 25-1 	; lower right row
  1826                              <1> 	;;;mov	dl, [CRT_COLS]
  1827                              <1> 	;mov	dl, 80		; lower right column	
  1828                              <1> 	;;dec	dl
  1829                              <1> 	;;mov	dl, 79
  1830                              <1> 
  1831                              <1> 	;;call	scroll_up	; 04/12/2013
  1832                              <1> 	;;; 11/03/2015
  1833                              <1> 	; 02/09/2014
  1834                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  1835                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  1836                              <1> 	; 11/03/2015
  1837 00001B6B 6629C9              <1> 	sub	cx, cx
  1838 00001B6E 66BA4F18            <1> 	mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  1839                              <1> 	;
  1840 00001B72 B001                <1> 	mov	al, 1		; scroll 1 line up
  1841                              <1> 		; ah = attribute
  1842                              <1> 	;mov	bl, al ; 12/05/2016
  1843 00001B74 E900FDFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  1844                              <1> ;u4:
  1845                              <1> 	;;int	10h		; video-call return
  1846                              <1> 				; scroll up the screen
  1847                              <1> 				; tty return
  1848                              <1> ;u5:
  1849                              <1> 	;retn			; return to the caller
  1850                              <1> 
  1851                              <1> u6:				; set-cursor-inc
  1852 00001B79 FEC6                <1> 	inc	dh		; next row
  1853                              <1> 				; set cursor
  1854                              <1> ;u7:					
  1855                              <1> 	;;mov	ah, 02h
  1856                              <1> 	;;jmp	short u4 	; establish the new cursor
  1857                              <1> 	;call	_set_cpos
  1858                              <1> 	;jmp 	short u5
  1859 00001B7B EB3A                <1> 	jmp     _set_cpos
  1860                              <1> 
  1861                              <1> 	; check for control characters
  1862                              <1> u8:
  1863 00001B7D 7436                <1> 	je	short u9
  1864 00001B7F 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  1865 00001B81 74D9                <1> 	je	short u10
  1866 00001B83 3C07                <1> 	cmp	al, 07h 	; is it a bell
  1867 00001B85 747A                <1> 	je	short u11
  1868 00001B87 3C08                <1> 	cmp	al, 08h		; is it a backspace
  1869                              <1> 	;jne	short u0
  1870 00001B89 7422                <1> 	je	short bs	; 12/12/2013
  1871                              <1> 	; 12/12/2013 (tab stop)
  1872 00001B8B 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  1873 00001B8D 75B8                <1> 	jne	short u0
  1874 00001B8F 88D0                <1> 	mov	al, dl
  1875 00001B91 6698                <1> 	cbw
  1876 00001B93 B108                <1> 	mov	cl, 8
  1877 00001B95 F6F1                <1> 	div	cl
  1878 00001B97 28E1                <1> 	sub	cl, ah
  1879                              <1> ts:
  1880                              <1> 	; 02/09/2014
  1881                              <1> 	; 01/09/2014
  1882 00001B99 B020                <1> 	mov	al, 20h
  1883                              <1> tsloop:
  1884 00001B9B 6651                <1> 	push	cx
  1885 00001B9D 6650                <1> 	push	ax
  1886                              <1> 	;mov	bh, [ACTIVE_PAGE]
  1887 00001B9F E890FFFFFF          <1> 	call	_write_tty_m3 ; 24/06/2016 (m3 -> _write_tty_m3)
  1888 00001BA4 6658                <1> 	pop	ax  ; ah = attribute/color
  1889 00001BA6 6659                <1> 	pop	cx
  1890 00001BA8 FEC9                <1> 	dec	cl
  1891 00001BAA 75EF                <1> 	jnz	short tsloop
  1892 00001BAC C3                  <1> 	retn
  1893                              <1> bs:	
  1894                              <1> 	; back space found
  1895                              <1> 
  1896 00001BAD 08D2                <1> 	or	dl, dl 		; is it already at start of line
  1897                              <1> 	;je	short u7 	; set_cursor
  1898 00001BAF 7406                <1> 	jz	short _set_cpos
  1899 00001BB1 664A                <1> 	dec	dx     		; no -- just move it back
  1900                              <1> 	;jmp	short u7
  1901 00001BB3 EB02                <1> 	jmp	short _set_cpos
  1902                              <1> 
  1903                              <1> 	; carriage return found
  1904                              <1> u9:
  1905 00001BB5 B200                <1> 	mov	dl, 0 		; move to first column
  1906                              <1> 	;jmp	short u7
  1907                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  1908                              <1> 
  1909                              <1> 	; line feed found
  1910                              <1> ;u10:
  1911                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  1912                              <1> ;	jne	short u6 	; no, just set the cursor
  1913                              <1> ;       jmp     u1              ; yes, scroll the screen
  1914                              <1> 
  1915                              <1> _set_cpos:
  1916                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1917                              <1> 	; 27/06/2015
  1918                              <1> 	; 01/09/2014
  1919                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1920                              <1> 	;
  1921                              <1> 	; 04/12/2013 - 12/12/2013 (Retro UNIX 8086 v1) 
  1922                              <1> 	;
  1923                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1924                              <1> 	;
  1925                              <1> ;----------------------------------------------
  1926                              <1> ; SET_CPOS
  1927                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  1928                              <1> ;	NEW X-Y VALUES PASSED
  1929                              <1> ; INPUT
  1930                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  1931                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  1932                              <1> ; OUTPUT
  1933                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  1934                              <1> ;----------------------------------------------
  1935                              <1> 	;
  1936 00001BB7 BE[E61F0100]        <1> 	mov	esi, CURSOR_POSN
  1937 00001BBC 0FB6C7              <1>         movzx   eax, bh	; BH = video page number
  1938                              <1> ;	or	al, al
  1939                              <1> ;	jz	short _set_cpos_0
  1940 00001BBF D0E0                <1>         shl     al, 1   ; word offset
  1941 00001BC1 01C6                <1>         add     esi, eax
  1942                              <1> ;_set_cpos_0:
  1943 00001BC3 668916              <1> 	mov	[esi], dx ; save the pointer
  1944 00001BC6 383D[F61F0100]      <1> 	cmp	[ACTIVE_PAGE], bh
  1945 00001BCC 7532                <1> 	jne	short m17
  1946                              <1> 	;call	m18	; CURSOR SET
  1947                              <1> ;m17:			; SET_CPOS_RETURN
  1948                              <1> 	; 01/09/2014
  1949                              <1> ;	retn
  1950                              <1> 		; DX  = row/column
  1951                              <1> m18:
  1952 00001BCE E84CFCFFFF          <1> 	call	position ; determine location in regen buffer	
  1953 00001BD3 668B0D[E41F0100]    <1> 	mov	cx, [CRT_START]
  1954 00001BDA 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  1955                              <1> 			; to the start address (offset) for this page
  1956 00001BDD 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  1957 00001BE0 B40E                <1> 	mov	ah, 14	; register number for cursor
  1958                              <1> 	;call	m16	; output value to the 6845	
  1959                              <1> 	;retn
  1960                              <1> 
  1961                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  1962                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  1963                              <1> m16:
  1964 00001BE2 FA                  <1> 	cli
  1965                              <1> 	;mov	dx, [addr_6845] ; address register
  1966 00001BE3 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  1967 00001BE7 88E0                <1> 	mov	al, ah	; get value
  1968 00001BE9 EE                  <1> 	out	dx, al	; register set
  1969 00001BEA 6642                <1> 	inc	dx	; data register
  1970 00001BEC EB00                <1> 	jmp	$+2	; i/o delay
  1971 00001BEE 88E8                <1> 	mov	al, ch	; data
  1972 00001BF0 EE                  <1> 	out	dx, al	
  1973 00001BF1 664A                <1> 	dec	dx	
  1974 00001BF3 88E0                <1> 	mov	al, ah
  1975 00001BF5 FEC0                <1> 	inc	al	; point to other data register
  1976 00001BF7 EE                  <1> 	out	dx, al	; set for second register
  1977 00001BF8 6642                <1> 	inc	dx
  1978 00001BFA EB00                <1> 	jmp	$+2	; i/o delay
  1979 00001BFC 88C8                <1> 	mov	al, cl	; second data value
  1980 00001BFE EE                  <1> 	out	dx, al
  1981 00001BFF FB                  <1> 	sti
  1982                              <1> m17:
  1983 00001C00 C3                  <1> 	retn
  1984                              <1> 
  1985                              <1> beeper: 
  1986                              <1> 	; 04/08/2016
  1987                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1988                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1989                              <1> 	; 18/01/2014
  1990                              <1> 	; 03/12/2013
  1991                              <1> 	; bell found
  1992                              <1> u11:
  1993 00001C01 FB                  <1> 	sti
  1994 00001C02 3A3D[F61F0100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  1995 00001C08 7551                <1> 	jne	short u12	; Do not sound the beep 
  1996                              <1> 				; if it is not written on the active page
  1997                              <1> beeper_gfx: ; 04/08/2016
  1998 00001C0A 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  1999 00001C0E B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  2000                              <1> 	;call	beep		; sound the pod bell
  2001                              <1> 	;jmp	short u5 	; tty_return
  2002                              <1> 	;retn
  2003                              <1> 	
  2004                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  2005                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  2006                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  2007                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  2008                              <1> 
  2009                              <1> beep:
  2010                              <1> 	; 07/02/2015
  2011                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2012                              <1> 	; 18/01/2014
  2013                              <1> 	; 03/12/2013
  2014                              <1> 	;
  2015                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  2016                              <1> 	;
  2017                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  2018                              <1> 	;
  2019                              <1> 	; ENTRY:
  2020                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  2021                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  2022                              <1> 	; EXIT:				:
  2023                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  2024                              <1> 
  2025 00001C10 9C                  <1> 	pushf  ; 18/01/2014	; save interrupt status
  2026 00001C11 FA                  <1> 	cli			; block interrupts during update
  2027 00001C12 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  2028 00001C14 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  2029 00001C16 EB00                <1> 	jmp	$+2		; I/O delay
  2030 00001C18 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  2031 00001C1A E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  2032 00001C1C EB00                <1> 	jmp	$+2		; I/O delay
  2033 00001C1E 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  2034 00001C20 E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  2035 00001C22 E461                <1> 	in	al, PORT_B	; get current setting of port
  2036 00001C24 88C4                <1> 	mov	ah, al		; save that setting
  2037 00001C26 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  2038 00001C28 E661                <1> 	out	PORT_B, al	; and restore interrupt status
  2039                              <1> 	;popf	; 18/01/2014
  2040 00001C2A FB                  <1> 	sti
  2041                              <1> g7:				; 1/64 second per count (bl)
  2042 00001C2B B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second	
  2043 00001C30 E827000000          <1> 	call	waitf		; go to beep delay 1/64 count
  2044 00001C35 FECB                <1> 	dec	bl		; (bl) length count expired?
  2045 00001C37 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  2046                              <1> 	;
  2047                              <1> 	;pushf			; save interrupt status
  2048 00001C39 FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  2049 00001C3A E461                <1> 	in	al, PORT_B	; get current port value
  2050                              <1>         ;or      al, not (GATE2+SPK2) ; isolate current speaker bits in case
  2051 00001C3C 0CFC                <1>         or      al, ~(GATE2+SPK2)
  2052 00001C3E 20C4                <1>         and	ah, al		; someone turned them off during beep
  2053 00001C40 88E0                <1> 	mov	al, ah		; recover value of port
  2054                              <1>         ;or      al, not (GATE2+SPK2) ; force speaker data off
  2055 00001C42 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  2056 00001C44 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  2057                              <1> 	;popf			; restore interrupt flag state
  2058 00001C46 FB                  <1> 	sti
  2059 00001C47 B90B040000          <1> 	mov	ecx, 1035	; force 1/64 second delay (short)
  2060 00001C4C E80B000000          <1> 	call	waitf		; minimum delay between all beeps
  2061                              <1> 	;pushf			; save interrupt status
  2062 00001C51 FA                  <1> 	cli			; block interrupts during update
  2063 00001C52 E461                <1> 	in	al, PORT_B	; get current port value in case	
  2064 00001C54 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  2065 00001C56 08E0                <1> 	or	al, ah		; recover value of port_b
  2066 00001C58 E661                <1> 	out	PORT_B, al	; restore speaker status
  2067 00001C5A 9D                  <1> 	popf			; restore interrupt flag state
  2068                              <1> u12:	
  2069 00001C5B C3                  <1> 	retn
  2070                              <1> 
  2071                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  2072                              <1> 
  2073                              <1> WAITF:
  2074                              <1> waitf:
  2075                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2076                              <1> 	; 03/12/2013
  2077                              <1> 	;
  2078                              <1> ;	push ax			; save work register (ah)	
  2079                              <1> ;waitf1:
  2080                              <1> 				; use timer 1 output bits
  2081                              <1> ;	in	al, PORT_B	; read current counter output status
  2082                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  2083                              <1> ;	cmp	al, ah		; did it just change
  2084                              <1> ;	je	short waitf1	; wait for a change in output line
  2085                              <1> ;	;
  2086                              <1> ;	mov	ah, al		; save new lflag state
  2087                              <1> ;	loop	waitf1		; decrement half cycles till count end		
  2088                              <1> ;	;
  2089                              <1> ;	pop	ax		; restore (ah)
  2090                              <1> ;	retn			; return (cx)=0
  2091                              <1> 
  2092                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  2093                              <1> ; 17/12/2014 (dsectrm2.s)
  2094                              <1> ; WAITF
  2095                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  2096                              <1> ;
  2097                              <1> ;---WAITF-----------------------------------------------------------------------
  2098                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  2099                              <1> ; ENTRY:
  2100                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  2101                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  2102                              <1> ; EXIT:
  2103                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  2104                              <1> ;	(CX) = 0	
  2105                              <1> ;-------------------------------------------------------------------------------
  2106                              <1> 
  2107                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  2108                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  2109                              <1> 
  2110                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  2111 00001C5C 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER (AH)
  2112                              <1> 	; 16/12/2014
  2113                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  2114 00001C5E D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  2115                              <1> ;17/12/2014	
  2116                              <1> ;WAITF1:
  2117                              <1> ;	IN	AL, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  2118                              <1> ;	AND	AL, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  2119                              <1> ;	CMP	AL, AH			; DID IT JUST CHANGE
  2120                              <1> ;	JE	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  2121                              <1> ;	MOV	AH, AL			; SAVE NEW FLAG STATE
  2122                              <1> ;	LOOP	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  2123                              <1> 	;
  2124                              <1> 	; 17/12/2014
  2125                              <1> 	;
  2126                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  2127                              <1> 	;
  2128                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  2129                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  2130                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  2131                              <1> WR_STATE_0:
  2132 00001C60 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  2133 00001C62 A810                <1> 	TEST	AL,010H
  2134 00001C64 74FA                <1> 	JZ	SHORT WR_STATE_0
  2135                              <1> WR_STATE_1:
  2136 00001C66 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  2137 00001C68 A810                <1> 	TEST	AL,010H
  2138 00001C6A 75FA                <1> 	JNZ	SHORT WR_STATE_1
  2139 00001C6C E2F2                <1>         LOOP    WR_STATE_0
  2140                              <1> 	;
  2141 00001C6E 6658                <1> 	POP	AX			; RESTORE (AH)
  2142 00001C70 C3                  <1> 	RETn				; (CX) = 0
  2143                              <1> 
  2144                              <1> ; 09/07/2016
  2145                              <1> ; 01/07/2016
  2146                              <1> ; 24/06/2016
  2147                              <1> ; 23/06/2016 - TRDOS 386 (TRDOS v2.0)
  2148                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  2149                              <1> ;-------------------------------------------------------------------------------
  2150                              <1> ; WRITE_STRING								       :
  2151                              <1> ;	THIS ROUTINE WRITES A STRING OF CHARACTERS TO THE CRT.		       :
  2152                              <1> ; INPUT 								       :
  2153                              <1> ;	(AL) = WRITE STRING COMMAND  0 - 3				       :
  2154                              <1> ;	(BH) = DISPLAY PAGE (ACTIVE PAGE)				       :
  2155                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE, IF (CX) = 0 THEN RETURN	       :
  2156                              <1> ;	(DX) = CURSOR POSITION FOR START OF STRING WRITE		       :
  2157                              <1> ;	(BL) = ATTRIBUTE OF CHARACTER TO WRITE IF (AL) = 0  OR	(AL) = 1       :
  2158                              <1> ;	(eBP) = SOURCE STRING OFFSET					       :
  2159                              <1> ; OUTPUT								       :
  2160                              <1> ;	NONE								       :
  2161                              <1> ;-------------------------------------------------------------------------------
  2162                              <1> 
  2163                              <1> ; AL = 00h: Assign all characters the attribute in BL; do not update cursor
  2164                              <1> ; AL = 01h: Assign all characters the attribute in BL; update cursor
  2165                              <1> ; AL = 02h: Use attributes in string; do not update cursor
  2166                              <1> ; AL = 03h: Use attributes in string; update cursor
  2167                              <1> 
  2168                              <1> WRITE_STRING:
  2169                              <1> 	; 09/07/2016
  2170 00001C71 803D[06E90000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6?!
  2171 00001C78 0F8782F7FFFF        <1> 	ja	VIDEO_RETURN		; not a valid function for VGA modes
  2172                              <1> 	;
  2173 00001C7E A2[502D0100]        <1> 	mov	[w_str_cmd], al		; save (AL) command
  2174 00001C83 3C04                <1> 	CMP	AL, 4			; TEST FOR INVALID WRITE STRING OPTION
  2175 00001C85 0F8375F7FFFF        <1> 	JNB	VIDEO_RETURN		; IF OPTION INVALID THEN RETURN
  2176                              <1> 
  2177                              <1>         ;JCXZ   VIDEO_RETURN            ; IF ZERO LENGTH STRING THEN RETURN
  2178                              <1> 
  2179 00001C8B 67E351              <1>         jcxz    P55			; 01/07/2016
  2180                              <1> 
  2181                              <1> 
  2182                              <1> 	; 01/07/2016
  2183                              <1> 	;and	ecx, 0FFFFh
  2184                              <1> 	; ECX = byte count
  2185                              <1> 	;push	ecx
  2186 00001C8E 89EE                <1> 	mov	esi, ebp ; user buffer
  2187 00001C90 BF00000700          <1> 	mov	edi, Cluster_Buffer  ; system buffer
  2188 00001C95 E824BD0000          <1> 	call	transfer_from_user_buffer
  2189                              <1> 	;pop	ecx
  2190 00001C9A 0F8260F7FFFF        <1> 	jc	VIDEO_RETURN
  2191                              <1> 	; ecx = transfer (byte) count = character count
  2192 00001CA0 BD00000700          <1> 	mov	ebp, Cluster_Buffer
  2193                              <1> 	;
  2194 00001CA5 0FB6F7              <1> 	movzx	esi, bh			; GET CURRENT CURSOR PAGE
  2195 00001CA8 66D1E6              <1> 	SAL	SI,1			; CONVERT TO PAGE OFFSET  (SI= PAGE)
  2196                              <1> 	; *****
  2197 00001CAB 66FFB6[E61F0100]    <1> 	PUSH	word [eSI+CURSOR_POSN]	; SAVE CURRENT CURSOR POSITION IN STACK
  2198                              <1> 
  2199                              <1> 	;MOV	AX,0200H		; SET NEW CURSOR POSITION
  2200                              <1> 	;INT	10H
  2201                              <1> P50next:	
  2202 00001CB2 53                  <1> 	push	ebx ; ****
  2203 00001CB3 51                  <1> 	push	ecx ; ***
  2204 00001CB4 56                  <1> 	push	esi ; **
  2205 00001CB5 52                  <1> 	push	edx ; *
  2206 00001CB6 E8FCFEFFFF          <1> 	call	_set_cpos
  2207                              <1> P50:
  2208 00001CBB 8A4500              <1> 	MOV	AL, [eBP]		; GET CHARACTER FROM INPUT STRING
  2209 00001CBE 45                  <1> 	INC	eBP			; BUMP POINTER TO CHARACTER
  2210                              <1> 
  2211                              <1> ;-----	TEST FOR SPECIAL CHARACTER'S
  2212                              <1> 
  2213 00001CBF 3C08                <1> 	CMP	AL, 08H			; IS IT A BACKSPACE
  2214 00001CC1 740C                <1> 	JE	short P51		; BACK_SPACE
  2215 00001CC3 3C0D                <1> 	CMP	AL, 0Dh ; CR		; IS IT CARRIAGE RETURN
  2216 00001CC5 7408                <1> 	JE	short P51		; CAR_RET
  2217 00001CC7 3C0A                <1> 	CMP	AL, 0Ah ; LF		; IS IT A LINE FEED
  2218 00001CC9 7404                <1> 	JE	short P51		; LINE_FEED
  2219 00001CCB 3C07                <1> 	CMP	AL, 07h			; IS IT A BELL
  2220 00001CCD 7515                <1> 	JNE	short P52		; IF NOT THEN DO WRITE CHARACTER
  2221                              <1> P51:
  2222                              <1> 	;MOV	AH,0EH			; TTY_CHARACTER_WRITE
  2223                              <1> 	;INT	10H			; WRITE TTY CHARACTER TO THE CRT
  2224                              <1> 	
  2225 00001CCF E860FEFFFF          <1> 	call	_write_tty_m3
  2226                              <1> 
  2227 00001CD4 5A                  <1> 	pop	edx ; *
  2228 00001CD5 5E                  <1> 	pop	esi ; **
  2229                              <1> 
  2230 00001CD6 668B96[E61F0100]    <1> 	MOV	DX, [eSI+CURSOR_POSN]	; GET CURRENT CURSOR POSITION
  2231 00001CDD EB46                <1> 	JMP	SHORT P54		; SET CURSOR POSITION AND CONTINUE
  2232                              <1> P55:
  2233 00001CDF E91CF7FFFF          <1> 	JMP	VIDEO_RETURN
  2234                              <1> P52:
  2235 00001CE4 66B90100            <1> 	MOV	CX, 1			; SET CHARACTER WRITE AMOUNT TO ONE
  2236 00001CE8 803D[502D0100]02    <1> 	CMP	byte [w_str_cmd], 2	; IS THE ATTRIBUTE IN THE STRING
  2237 00001CEF 7204                <1> 	JB	short P53		; IF NOT THEN SKIP
  2238 00001CF1 8A5D00              <1> 	MOV	BL, [eBP]		; ELSE GET NEW ATTRIBUTE
  2239 00001CF4 45                  <1> 	INC	eBP			; BUMP STRING POINTER
  2240                              <1> P53:
  2241                              <1> 	;MOV	AH,09H			; GOT_CHARACTER
  2242                              <1> 	;INT	10H			; WRITE CHARACTER TO THE CRT
  2243                              <1> 
  2244 00001CF5 E8AEFDFFFF          <1> 	call	_write_c_current
  2245                              <1> 	
  2246 00001CFA 5A                  <1> 	pop	edx ; *	
  2247                              <1> 	
  2248 00001CFB 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  2249 00001CFE 889E[0FE90000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  2250                              <1> 
  2251 00001D04 FEC2                <1> 	INC	DL			; INCREMENT COLUMN COUNTER
  2252 00001D06 3A15[08E90000]      <1> 	CMP	DL, [CRT_COLS]		; IF COLS ARE WITHIN RANGE FOR THIS MODE
  2253 00001D0C 7217                <1> 	JB	short P54		;    THEN GO TO COLUMNS SET
  2254 00001D0E FEC6                <1> 	INC	DH			; BUMP ROW COUNTER BY ONE
  2255 00001D10 28D2                <1> 	SUB	DL, DL			; SET COLUMN COUNTER TO ZERO
  2256 00001D12 80FE19              <1> 	CMP	DH, 25			; IF ROWS ARE LESS THAN 25 THEN
  2257 00001D15 720E                <1> 	JB	short P54		; GO TO ROWS_COLUMNS_SET
  2258                              <1> 
  2259 00001D17 66B80A0E            <1> 	MOV	AX,0E0AH		; ELSE SCROLL SCREEN
  2260                              <1> 	;INT	10H			; RESET ROW COUNTER TO 24
  2261                              <1> 
  2262 00001D1B E814FEFFFF          <1> 	call	_write_tty_m3
  2263                              <1> 	
  2264 00001D20 66BA0018            <1> 	mov	dx, 1800h		; Column = 0, Row = 24
  2265 00001D24 5E                  <1> 	pop	esi ; **
  2266                              <1> P54:
  2267                              <1> 					; ROW_COLUMNS_SET
  2268                              <1> 	;MOV	AX,0200H		; SET NEW CURSOR POSITION COMMAND
  2269                              <1> 	;INT	10H			; ESTABLISH NEW CURSOR POSITION
  2270                              <1> 
  2271 00001D25 59                  <1> 	pop	ecx ; ***
  2272 00001D26 5B                  <1> 	pop	ebx ; ****
  2273                              <1> 
  2274                              <1> 	;LOOP	P50			; DO IT ONCE MORE UNTIL (CX) = ZERO
  2275 00001D27 6649                <1> 	dec	cx
  2276 00001D29 7587                <1> 	jnz	short P50next
  2277                              <1> 
  2278 00001D2B 665A                <1> 	POP	DX  ; *****		; RESTORE OLD CURSOR COORDINATES
  2279                              <1> 	
  2280 00001D2D F605[502D0100]01    <1> 	test	byte [w_str_cmd], 1	; IF CURSOR WAS NOT TO BE MOVED
  2281 00001D34 0F85C6F6FFFF        <1> 	JNZ	VIDEO_RETURN		; THEN EXIT WITHOUT RESETTING OLD VALUE
  2282                              <1> 	
  2283                              <1> 	;MOV	AX,0200H		; ELSE RESTORE OLD CURSOR POSITION
  2284                              <1> 	;INT	10H
  2285                              <1> 					; DONE - EXIT WRITE STRING
  2286 00001D3A E878FEFFFF          <1> 	call	_set_cpos
  2287 00001D3F E9BCF6FFFF          <1> 	JMP	VIDEO_RETURN		; RETURN TO CALLER
  2288                              <1> 
  2289                              <1> 
  2290                              <1> ; 07/07/2016
  2291                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  2292                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  2293                              <1> ;------------------------------------------------------
  2294                              <1> ;  SCROLL UP
  2295                              <1> ;   THIS ROUTINE SCROLLS UP THE INFORMATION ON THE CRT
  2296                              <1> ; ENTRY ---
  2297                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  2298                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  2299                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  2300                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  2301                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  2302                              <1> ;  DS = DATA SEGMENT
  2303                              <1> ;  ES = REGEN SEGMENT
  2304                              <1> ; EXIT --
  2305                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  2306                              <1> ;--------------------------------------------------------
  2307                              <1> 
  2308                              <1> 	; cl = upper left column
  2309                              <1> 	; ch = upper left row
  2310                              <1> 	; dl = lower rigth column
  2311                              <1> 	; dh = lower right row
  2312                              <1> 	;
  2313                              <1> 	; al = line count (AL=0 means blank entire fields)
  2314                              <1> 	; bl = fill value for blanked lines	
  2315                              <1> 	; bh = unused
  2316                              <1> 
  2317                              <1> GRAPHICS_UP:
  2318                              <1> 	; 07/07/2016
  2319                              <1> 	;AH = Current video mode, [CRT_MODE]
  2320 00001D44 80FC07              <1> 	cmp	ah, 7
  2321 00001D47 7766                <1> 	ja	short vga_graphics_up
  2322                              <1> 	;je	n0
  2323                              <1> 
  2324 00001D49 88C7                <1> 	MOV	bh, al			; save line count in BH
  2325 00001D4B 6689C8              <1> 	MOV	AX, CX			; GET UPPER LEFT POSITION INTO AX REG
  2326                              <1> 
  2327                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  2328                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  2329                              <1> 
  2330 00001D4E E8D9050000          <1> 	CALL	GRAPH_POSN
  2331 00001D53 0FB7F8              <1> 	MOVzx	eDI, AX			; SAVE RESULT AS DESTINATION ADDRESS
  2332                              <1> 
  2333                              <1> ;-----	DETERMINE SIZE OF WINDOW
  2334                              <1> 
  2335 00001D56 6629CA              <1> 	SUB	DX, CX
  2336 00001D59 6681C20101          <1>         ADD     DX, 101h                ; ADJUST VALUES
  2337 00001D5E C0E602              <1> 	SAL	DH, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  2338                              <1> 					; AND EVEN/ODD ROWS
  2339                              <1> ;-----	DETERMINE CRT MODE
  2340                              <1> 
  2341 00001D61 803D[06E90000]06    <1> 	CMP	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  2342 00001D68 7305                <1>         JNC     short _R7_              ; FIND_SOURCE
  2343                              <1> 
  2344                              <1> ;-----	MEDIUM RES UP
  2345 00001D6A D0E2                <1> 	SAL	DL, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  2346 00001D6C 66D1E7              <1> 	SAL	DI, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  2347                              <1> 
  2348                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  2349                              <1> _R7_:                                   ; FIND_SOURCE
  2350 00001D6F 81C700800B00        <1> 	add	edi, 0B8000h
  2351 00001D75 C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  2352 00001D78 7431                <1>         JZ      short _R11              ; IF ZERO, THEN BLANK ENTIRE FIELD
  2353 00001D7A B050                <1> 	MOV	AL, 80			; 80 BYTES/ROW
  2354 00001D7C F6E7                <1> 	mul	bh			; determine offset to source
  2355 00001D7E 0FB7F0              <1> 	movzx	esi, ax			; offset to source
  2356 00001D81 01FE                <1> 	add	eSI, eDI		; SET UP SOURCE
  2357 00001D83 88F4                <1> 	MOV	AH, DH			; NUMBER OF ROWS IN FIELD
  2358 00001D85 28FC                <1> 	sub	ah, bh			; determine number to move
  2359                              <1> 
  2360                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  2361                              <1> _R8:                                    ; ROW_LOOP
  2362 00001D87 E812040000          <1>         CALL    _R17                    ; MOVE ONE ROW
  2363 00001D8C 6681EEB01F          <1> 	SUB	SI, 2000h-80		; MOVE TO NEXT ROW
  2364 00001D91 6681EFB01F          <1> 	SUB	DI, 2000h-80
  2365 00001D96 FECC                <1> 	DEC	AH			; NUMBER OF ROWS TO MOVE
  2366 00001D98 75ED                <1>         JNZ     short _R8               ; CONTINUE TILL ALL MOVED
  2367                              <1> 
  2368                              <1> ;-----	FILL IN THE VACATED LINE(S)
  2369                              <1> _R9:                                    ; CLEAR ENTRY
  2370 00001D9A 88D8                <1> 	mov	al, bl			; attribute to fill with
  2371                              <1> _R10_:
  2372 00001D9C E819040000          <1>         CALL    _R18                    ; CLEAR THAT ROW
  2373 00001DA1 6681EFB01F          <1> 	SUB	DI, 2000h-80		; POINT TO NEXT LINE
  2374 00001DA6 FECF                <1> 	dec	bh			; number of lines to fill
  2375 00001DA8 75F2                <1>         JNZ     short _R10_             ; CLEAR LOOP
  2376 00001DAA C3                  <1> 	retn				; EVERYYHING DONE
  2377                              <1> 
  2378                              <1> _R11:                                   ; BLANK_FIELD
  2379 00001DAB 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  2380 00001DAD EBEB                <1>         JMP     short _R9               ; CLEAR THE FIELD
  2381                              <1> 
  2382                              <1> vga_graphics_up:
  2383                              <1> 	; 08/08/2016
  2384                              <1> 	; 07/08/2016
  2385                              <1> 	; 04/08/2016
  2386                              <1> 	; 01/08/2016
  2387                              <1> 	; 31/07/2016
  2388                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2389                              <1> 	;
  2390                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2391                              <1> 	; vgabios-0.7a (2011)
  2392                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2393                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  2394                              <1> 	;
  2395                              <1> 
  2396                              <1> 	; cl = upper left column
  2397                              <1> 	; ch = upper left row
  2398                              <1> 	; dl = lower rigth column
  2399                              <1> 	; dh = lower right row
  2400                              <1> 	;
  2401                              <1> 	; al = line count (AL=0 means blank entire fields)
  2402                              <1> 	; bl = fill value for blanked lines	
  2403                              <1> 	; bh = unused
  2404                              <1> 	;
  2405                              <1> 	; ah = [CRT_MODE], current video mode	
  2406                              <1> 
  2407 00001DAF 88C7                <1> 	mov	bh, al ; 31/07/2016
  2408 00001DB1 BE[2AE90000]        <1> 	mov	esi, vga_g_modes
  2409 00001DB6 89F7                <1> 	mov	edi, esi
  2410 00001DB8 83C708              <1> 	add	edi, vga_g_mode_count
  2411                              <1> vga_g_up_0:
  2412 00001DBB AC                  <1> 	lodsb
  2413 00001DBC 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  2414 00001DBE 7405                <1> 	je	short vga_g_up_1
  2415 00001DC0 39FE                <1> 	cmp	esi, edi
  2416 00001DC2 72F7                <1> 	jb	short vga_g_up_0
  2417                              <1> 	;xor	bh, bh ; 31/07/2016)
  2418 00001DC4 C3                  <1> 	retn	; nothing to do
  2419                              <1> vga_g_up_1:
  2420 00001DC5 88F8                <1> 	mov	al, bh ; 31/07/2016
  2421 00001DC7 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  2422                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  2423                              <1> 	
  2424                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  2425                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  2426                              <1>  	; if(nblines>nbrows)nblines=0;
  2427                              <1>  	; cols=clr-cul+1;
  2428                              <1> 
  2429 00001DCA 3A35[0EE90000]      <1> 	cmp	dh, [VGA_ROWS]
  2430 00001DD0 7208                <1> 	jb	short vga_g_up_2
  2431 00001DD2 8A35[0EE90000]      <1> 	mov	dh, [VGA_ROWS]
  2432 00001DD8 FECE                <1> 	dec	dh
  2433                              <1> vga_g_up_2:
  2434 00001DDA 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  2435 00001DE0 7208                <1> 	jb	short vga_g_up_3
  2436 00001DE2 8A15[08E90000]      <1> 	mov	dl, [CRT_COLS]
  2437 00001DE8 FECA                <1> 	dec	dl
  2438                              <1> vga_g_up_3:	
  2439 00001DEA 3A05[0EE90000]      <1> 	cmp	al, [VGA_ROWS]
  2440 00001DF0 7602                <1> 	jna	short vga_g_up_4
  2441 00001DF2 28C0                <1> 	sub	al, al ; 0
  2442                              <1> vga_g_up_4:
  2443 00001DF4 88D7                <1> 	mov	bh, dl ; clr
  2444 00001DF6 28CF                <1> 	sub	bh, cl ; cul
  2445 00001DF8 FEC7                <1> 	inc	bh ; cols = clr-cul+1
  2446                              <1> 
  2447 00001DFA 20C0                <1> 	and	al, al ; nblines = 0
  2448 00001DFC 755D                <1> 	jnz	short vga_g_up_6
  2449 00001DFE 20ED                <1> 	and	ch, ch ; rul = 0
  2450 00001E00 7559                <1> 	jnz	short vga_g_up_6
  2451 00001E02 20C9                <1> 	and	cl, cl ; cul = 0
  2452 00001E04 7555                <1> 	jnz	short vga_g_up_6
  2453                              <1> 
  2454 00001E06 6650                <1> 	push	ax
  2455 00001E08 A0[0EE90000]        <1> 	mov	al, [VGA_ROWS]
  2456 00001E0D FEC8                <1> 	dec	al  
  2457 00001E0F 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  2458 00001E11 7546                <1> 	jne	short vga_g_up_5
  2459 00001E13 A0[08E90000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  2460 00001E18 FEC8                <1> 	dec	al 
  2461 00001E1A 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  2462 00001E1C 753B                <1> 	jne	short vga_g_up_5
  2463 00001E1E 6658                <1> 	pop	ax
  2464                              <1> 
  2465 00001E20 66B80502            <1> 	mov	ax, 0205h
  2466 00001E24 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2467 00001E28 66EF                <1> 	out	dx, ax
  2468 00001E2A A0[0EE90000]        <1> 	mov	al, [VGA_ROWS]
  2469 00001E2F 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  2470 00001E35 F6E4                <1> 	mul	ah
  2471 00001E37 0FB7D0              <1> 	movzx	edx, ax
  2472                              <1> 	; 08/08/2016
  2473 00001E3A 0FB605[0AE90000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2474 00001E41 F7E2                <1> 	mul	edx
  2475                              <1> 	; eax = byte count	
  2476 00001E43 89C1                <1> 	mov	ecx, eax
  2477                              <1> 	;; 07/08/2016
  2478                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  2479                              <1> 	;mov	ecx, edx
  2480 00001E45 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  2481 00001E47 BF00000A00          <1> 	mov	edi, 0A0000h
  2482 00001E4C F3AA                <1> 	rep	stosb		
  2483                              <1> 	
  2484 00001E4E 66B80500            <1> 	mov	ax, 5
  2485 00001E52 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2486 00001E56 66EF                <1> 	out	dx, ax ; 0005h	
  2487                              <1> 
  2488 00001E58 C3                  <1> 	retn
  2489                              <1> 
  2490                              <1> vga_g_up_5:
  2491 00001E59 6658                <1> 	pop	ax
  2492                              <1> 
  2493                              <1> vga_g_up_6:
  2494                              <1> 	; [ESI] = VGA memory model number for current video mode
  2495                              <1>         ;
  2496                              <1>         ; LINEAR8 equ 5
  2497                              <1>         ; PLANAR4 equ 4
  2498                              <1>         ; PLANAR1 equ 3
  2499                              <1> 
  2500 00001E5B 803E04              <1> 	cmp	byte [esi], PLANAR4
  2501 00001E5E 7424                <1> 	je	short vga_g_up_planar
  2502 00001E60 803E03              <1> 	cmp	byte [esi], PLANAR1
  2503 00001E63 741F                <1> 	je	short vga_g_up_planar
  2504                              <1> vga_g_up_linear8:
  2505                              <1> 	; 07/07/2016 (TEMPORARY)
  2506                              <1> 	;
  2507                              <1> 	; cl = upper left column ; cul
  2508                              <1> 	; ch = upper left row ; rul
  2509                              <1> 	; dl = lower rigth column ; clr
  2510                              <1> 	; dh = lower right row ; rlr
  2511                              <1> 
  2512                              <1> vga_g_up_l0:
  2513                              <1>  	;{for(i=rul;i<=rlr;i++)
  2514                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  2515 00001E65 08C0                <1> 	or	al, al
  2516 00001E67 7414                <1> 	jz	short vga_g_up_l2
  2517 00001E69 88C4                <1> 	mov	ah, al
  2518 00001E6B 00EC                <1> 	add	ah, ch ; i+nblines
  2519                              <1> 	;jc	short vga_g_up_l2	
  2520 00001E6D 38F4                <1> 	cmp	ah, dh
  2521 00001E6F 770C                <1> 	ja	short vga_g_up_l2
  2522                              <1> 	; else
  2523                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  2524 00001E71 E8F2000000          <1> 	call	vgamem_copy_l8
  2525                              <1> vga_g_up_l1:
  2526 00001E76 FEC5                <1> 	inc	ch
  2527 00001E78 38F5                <1> 	cmp	ch, dh
  2528 00001E7A 76E9                <1> 	jna	short vga_g_up_l0
  2529 00001E7C C3                  <1> 	retn
  2530                              <1> vga_g_up_l2:
  2531                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  2532 00001E7D E850010000          <1> 	call	vgamem_fill_l8
  2533 00001E82 EBF2                <1> 	jmp	short vga_g_up_l1
  2534                              <1> 
  2535                              <1> vga_g_up_planar:
  2536                              <1> 	; cl = upper left column ; cul
  2537                              <1> 	; ch = upper left row ; rul
  2538                              <1> 	; dl = lower rigth column ; clr
  2539                              <1> 	; dh = lower right row ; rlr
  2540                              <1> vga_g_up_pl0:
  2541                              <1>  	;{for(i=rul;i<=rlr;i++)
  2542                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  2543 00001E84 20C0                <1> 	and	al, al
  2544 00001E86 7414                <1> 	jz	short vga_g_up_pl2	
  2545 00001E88 88C4                <1> 	mov	ah, al
  2546 00001E8A 00EC                <1> 	add	ah, ch ; i+nblines
  2547                              <1> 	;jc	short vga_g_up_pl2
  2548 00001E8C 38F4                <1> 	cmp	ah, dh
  2549 00001E8E 770C                <1> 	ja	short vga_g_up_pl2
  2550                              <1> 	; else
  2551                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  2552 00001E90 E80E000000          <1> 	call	vgamem_copy_pl4
  2553                              <1> vga_g_up_pl1:
  2554 00001E95 FEC5                <1> 	inc	ch 
  2555 00001E97 38F5                <1> 	cmp	ch, dh
  2556 00001E99 76E9                <1> 	jna	short vga_g_up_pl0
  2557 00001E9B C3                  <1> 	retn
  2558                              <1> vga_g_up_pl2:
  2559                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  2560 00001E9C E870000000          <1> 	call	vgamem_fill_pl4
  2561 00001EA1 EBF2                <1> 	jmp	short vga_g_up_pl1
  2562                              <1> 
  2563                              <1> vgamem_copy_pl4:
  2564                              <1> 	; 08/08/2016
  2565                              <1> 	; 07/08/2016
  2566                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2567                              <1> 	;
  2568                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2569                              <1> 	; vgabios-0.7a (2011)
  2570                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2571                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  2572                              <1> 	;
  2573                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  2574                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  2575                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  2576                              <1> 
  2577                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  2578                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  2579                              <1> 
  2580 00001EA3 52                  <1> 	push	edx
  2581 00001EA4 50                  <1> 	push	eax
  2582                              <1> 
  2583                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  2584 00001EA5 66B80501            <1> 	mov	ax, 0105h
  2585 00001EA9 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2586 00001EAD 66EF                <1> 	out	dx, ax
  2587                              <1> 
  2588                              <1> 	; 07/08/2016
  2589                              <1>  	;mov     ah, [esp+1]
  2590                              <1> 	;movzx	edx, ah ; ysrc
  2591 00001EAF 0FB6542401          <1> 	movzx	edx, byte [esp+1]
  2592                              <1> 	; 08/08/2016
  2593 00001EB4 0FB605[0AE90000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2594 00001EBB 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  2595 00001EC1 F6E4                <1> 	mul	ah 
  2596                              <1> 	;; 07/08/2016
  2597                              <1> 	;movzx	eax, byte [CRT_COLS]
  2598                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2599 00001EC3 50                  <1> 	push	eax ; cheight * nbcols
  2600 00001EC4 F7E2                <1> 	mul	edx ; * ysrc
  2601                              <1> 	; eax = ysrc * cheight * nbcols
  2602                              <1> 	; edx = 0
  2603 00001EC6 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2604 00001EC8 01D0                <1>  	add	eax, edx
  2605 00001ECA 89C6                <1> 	mov	esi, eax ; src
  2606 00001ECC 88EA                <1> 	mov	dl, ch ; ydest
  2607 00001ECE 58                  <1> 	pop	eax ; cheight * nbcols
  2608 00001ECF F7E2                <1> 	mul	edx
  2609                              <1> 	; eax = ydest * cheight * nbcols
  2610 00001ED1 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2611 00001ED3 01D0                <1>  	add	eax, edx
  2612 00001ED5 89C7                <1> 	mov	edi, eax ; dest
  2613                              <1> 	; esi = src
  2614                              <1> 	; edi = dest
  2615                              <1> 	; for(i=0;i<cheight;i++)
  2616                              <1>   	; {
  2617                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  2618                              <1>   	; }
  2619 00001ED7 51                  <1> 	push	ecx
  2620 00001ED8 B900000A00          <1> 	mov	ecx, 0A0000h
  2621 00001EDD 01CE                <1> 	add	esi, ecx
  2622 00001EDF 01CF                <1> 	add	edi, ecx
  2623                              <1> 	; 08/08/2016
  2624 00001EE1 8A35[0AE90000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2625                              <1> 	;; 07/08/2016
  2626                              <1> 	;mov	dh, 8 ; 07/08/2016
  2627 00001EE7 28D2                <1> 	sub	dl, dl ; i
  2628                              <1> vgamem_copy_pl4_0:
  2629 00001EE9 56                  <1> 	push	esi
  2630 00001EEA 57                  <1> 	push	edi
  2631 00001EEB 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS]
  2632 00001EF2 F6E2                <1> 	mul	dl
  2633                              <1> 	; eax = i * nbcols
  2634 00001EF4 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2635 00001EF6 01C6                <1> 	add	esi, eax
  2636 00001EF8 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2637 00001EFB F3A4                <1> 	rep	movsb
  2638 00001EFD 5F                  <1> 	pop	edi
  2639 00001EFE 5E                  <1> 	pop	esi
  2640 00001EFF FECE                <1> 	dec	dh
  2641 00001F01 75E6                <1> 	jnz	short vgamem_copy_pl4_0
  2642                              <1> vgamem_copy_pl4_1:
  2643 00001F03 59                  <1> 	pop	ecx
  2644                              <1> 
  2645                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2646 00001F04 66B80500            <1> 	mov	ax, 0005h
  2647 00001F08 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2648 00001F0C 66EF                <1> 	out	dx, ax
  2649                              <1> 
  2650 00001F0E 58                  <1> 	pop	eax
  2651 00001F0F 5A                  <1> 	pop	edx
  2652                              <1> 
  2653 00001F10 C3                  <1> 	retn	
  2654                              <1> 
  2655                              <1> vgamem_fill_pl4:
  2656                              <1> 	; 08/08/2016
  2657                              <1> 	; 07/08/2016
  2658                              <1> 	; 04/08/2016
  2659                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2660                              <1> 	;
  2661                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2662                              <1> 	; vgabios-0.7a (2011)
  2663                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2664                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  2665                              <1> 	;
  2666                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  2667                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  2668                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  2669                              <1> 
  2670                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  2671 00001F11 52                  <1> 	push	edx
  2672 00001F12 50                  <1> 	push	eax
  2673                              <1> 
  2674                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  2675 00001F13 66B80502            <1> 	mov	ax, 0205h
  2676 00001F17 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2677 00001F1B 66EF                <1> 	out	dx, ax
  2678                              <1> 
  2679                              <1>       	; 08/08/2016
  2680 00001F1D 0FB605[0AE90000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  2681 00001F24 F6E5                <1> 	mul	ch
  2682                              <1> 	;; 07/08/2016
  2683                              <1> 	;movzx	eax, ch
  2684                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2685 00001F26 0FB615[08E90000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  2686 00001F2D F7E2                <1> 	mul	edx
  2687                              <1> 	; edx  = 0
  2688 00001F2F 88CA                <1> 	mov	dl, cl 
  2689 00001F31 01D0                <1> 	add	eax, edx
  2690 00001F33 89C7                <1> 	mov	edi, eax
  2691                              <1> 	; edi = dest
  2692                              <1> 	; for(i=0;i<cheight;i++)
  2693                              <1>   	; {
  2694                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  2695                              <1>   	; }
  2696 00001F35 81C700000A00        <1> 	add	edi, 0A0000h
  2697 00001F3B 51                  <1> 	push	ecx
  2698                              <1> 	; 08/08/2016
  2699 00001F3C 8A35[0AE90000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2700                              <1> 	;; 07/08/2016
  2701                              <1> 	;mov	dh, 8 ; 07/08/2016
  2702 00001F42 28D2                <1> 	sub	dl, dl ; i
  2703                              <1> vgamem_fill_pl4_0:
  2704 00001F44 57                  <1> 	push	edi
  2705 00001F45 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS]
  2706 00001F4C F6E2                <1> 	mul	dl
  2707                              <1> 	; eax = i * nbcols
  2708 00001F4E 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2709 00001F50 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  2710 00001F52 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2711 00001F55 F3AA                <1>  	rep	stosb
  2712 00001F57 5F                  <1> 	pop	edi
  2713 00001F58 75EA                <1> 	jnz	short vgamem_fill_pl4_0
  2714                              <1> vgamem_fill_pl4_1:
  2715 00001F5A 59                  <1> 	pop	ecx
  2716                              <1> 
  2717                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2718 00001F5B 66B80500            <1> 	mov	ax, 0005h
  2719 00001F5F 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2720 00001F63 66EF                <1> 	out	dx, ax
  2721                              <1> 
  2722 00001F65 58                  <1> 	pop	eax
  2723 00001F66 5A                  <1> 	pop	edx 
  2724                              <1> 	
  2725 00001F67 C3                  <1> 	retn
  2726                              <1> 
  2727                              <1> vgamem_copy_l8:
  2728                              <1> 	; 08/08/2016
  2729                              <1> 	; 07/08/2016
  2730                              <1> 	; 06/08/2016
  2731                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2732                              <1> 	;
  2733                              <1> 	; TEMPORARY
  2734                              <1> 	;
  2735                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2736                              <1> 	; vgabios-0.7a (2011)
  2737                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2738                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  2739                              <1> 	;
  2740                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  2741                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  2742                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  2743                              <1> 
  2744                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  2745                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  2746                              <1> 
  2747 00001F68 52                  <1> 	push	edx
  2748 00001F69 50                  <1> 	push	eax
  2749                              <1> 
  2750                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  2751                              <1> 	;mov	ax, 0105h
  2752                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2753                              <1> 	;out	dx, ax
  2754                              <1> 
  2755                              <1> 	;mov	ah, [esp+1]
  2756                              <1> 
  2757 00001F6A 0FB6D4              <1> 	movzx	edx, ah ; ysrc
  2758                              <1> 	; 08/08/2016
  2759 00001F6D 0FB605[0AE90000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2760 00001F74 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  2761 00001F7A F6E4                <1> 	mul	ah 
  2762                              <1> 	;; 07/08/2016
  2763                              <1> 	;movzx	eax, byte [CRT_COLS]
  2764                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2765 00001F7C 50                  <1> 	push	eax ; cheight * nbcols
  2766 00001F7D F7E2                <1> 	mul	edx ; * ysrc
  2767                              <1> 	; eax = ysrc * cheight * nbcols
  2768                              <1> 	; edx = 0
  2769 00001F7F 88CA                <1> 	mov	dl, cl ; edx = xstart
  2770 00001F81 01D0                <1>  	add	eax, edx
  2771 00001F83 89C6                <1> 	mov	esi, eax ; src
  2772 00001F85 66C1E603            <1> 	shl	si, 3 ; * 8 ; 06/08/2016
  2773 00001F89 88EA                <1> 	mov	dl, ch ; ydest
  2774 00001F8B 58                  <1> 	pop	eax ; cheight * nbcols
  2775 00001F8C F7E2                <1> 	mul	edx
  2776                              <1> 	; eax = ydest * cheight * nbcols
  2777 00001F8E 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2778 00001F90 01D0                <1>  	add	eax, edx
  2779 00001F92 89C7                <1> 	mov	edi, eax ; dest
  2780 00001F94 66C1E703            <1> 	shl	di, 3 ; * 8 ; 06/08/2016
  2781                              <1> 	; esi = src
  2782                              <1> 	; edi = dest
  2783                              <1> 	; for(i=0;i<cheight;i++)
  2784                              <1>   	; {
  2785                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  2786                              <1>   	; }
  2787 00001F98 51                  <1> 	push	ecx
  2788 00001F99 B900000A00          <1> 	mov	ecx, 0A0000h
  2789 00001F9E 01CE                <1> 	add	esi, ecx
  2790 00001FA0 01CF                <1> 	add	edi, ecx
  2791                              <1> 	; 08/08/2016
  2792 00001FA2 8A35[0AE90000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2793                              <1> 	;; 07/08/2016
  2794                              <1> 	;mov	dh, 8 ; 07/08/2016
  2795 00001FA8 28D2                <1> 	sub	dl, dl ; i
  2796                              <1> vgamem_copy_l8_0:
  2797 00001FAA 56                  <1> 	push	esi
  2798 00001FAB 57                  <1> 	push	edi
  2799 00001FAC 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS]
  2800 00001FB3 F6E2                <1> 	mul	dl
  2801                              <1> 	; eax = i * nbcols
  2802 00001FB5 66C1E003            <1> 	shl	ax, 3 ; * 8 ; 06/08/2016
  2803 00001FB9 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2804 00001FBB 01C6                <1> 	add	esi, eax
  2805 00001FBD 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2806 00001FC0 66C1E103            <1> 	shl	cx, 3 ; * 8 ; 06/08/2016
  2807 00001FC4 F3A4                <1> 	rep	movsb
  2808 00001FC6 5F                  <1> 	pop	edi
  2809 00001FC7 5E                  <1> 	pop	esi
  2810 00001FC8 FEC2                <1> 	inc	dl ; 06/08/2016
  2811 00001FCA FECE                <1> 	dec	dh
  2812 00001FCC 75DC                <1> 	jnz	short vgamem_copy_l8_0
  2813                              <1> vgamem_copy_l8_1:
  2814 00001FCE 59                  <1> 	pop	ecx
  2815                              <1> 
  2816                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2817                              <1> 	;mov	ax, 0005h
  2818                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2819                              <1> 	;out	dx, ax
  2820                              <1> 
  2821 00001FCF 58                  <1> 	pop	eax
  2822 00001FD0 5A                  <1> 	pop	edx
  2823                              <1> 
  2824 00001FD1 C3                  <1> 	retn
  2825                              <1> 
  2826                              <1> vgamem_fill_l8:
  2827                              <1> 	; 08/08/2016
  2828                              <1> 	; 07/08/2016
  2829                              <1> 	; 06/08/2016
  2830                              <1> 	; 04/08/2016
  2831                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2832                              <1> 	;
  2833                              <1> 	; TEMPORARY
  2834                              <1> 	;
  2835                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2836                              <1> 	; vgabios-0.7a (2011)
  2837                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2838                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  2839                              <1> 	;
  2840                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  2841                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  2842                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  2843                              <1> 
  2844                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  2845 00001FD2 52                  <1> 	push	edx
  2846 00001FD3 50                  <1> 	push	eax
  2847                              <1> 
  2848                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  2849                              <1> 	;mov	ax, 0205h
  2850                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2851                              <1> 	;out	dx, ax
  2852                              <1> 
  2853                              <1>         ; 08/08/2016
  2854 00001FD4 0FB605[0AE90000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  2855 00001FDB F6E5                <1> 	mul	ch
  2856                              <1> 	;; 07/08/2016
  2857                              <1> 	;movzx	eax, ch
  2858                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2859 00001FDD 0FB615[08E90000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  2860 00001FE4 F7E2                <1> 	mul	edx
  2861                              <1> 	; edx  = 0
  2862 00001FE6 88CA                <1> 	mov	dl, cl 
  2863 00001FE8 01D0                <1> 	add	eax, edx
  2864 00001FEA 89C7                <1> 	mov	edi, eax
  2865 00001FEC 66C1E703            <1> 	shl	di, 3 ; * 8 ; 06/08/2016
  2866                              <1> 	; edi = dest
  2867                              <1> 	; for(i=0;i<cheight;i++)
  2868                              <1>   	; {
  2869                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  2870                              <1>   	; }
  2871 00001FF0 81C700000A00        <1> 	add	edi, 0A0000h
  2872 00001FF6 51                  <1> 	push	ecx
  2873                              <1> 	; 08/08/2016
  2874 00001FF7 8A35[0AE90000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2875                              <1> 	;; 07/08/2016
  2876                              <1> 	;mov	dh, 8 ; 07/08/2016
  2877 00001FFD 28D2                <1> 	sub	dl, dl ; i
  2878                              <1> vgamem_fill_l8_0:
  2879 00001FFF 57                  <1> 	push	edi
  2880 00002000 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS]
  2881 00002007 F6E2                <1> 	mul	dl
  2882                              <1> 	; eax = i * nbcols
  2883 00002009 66C1E003            <1> 	shl	ax, 3 ; * 8 ; 06/08/2016
  2884 0000200D 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2885 0000200F 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  2886 00002011 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2887 00002014 66C1E103            <1> 	shl	cx, 3 ; * 8 ; 06/08/2016
  2888 00002018 F3AA                <1>  	rep	stosb
  2889 0000201A 5F                  <1> 	pop	edi
  2890 0000201B FEC2                <1> 	inc	dl ; 06/08/2016
  2891 0000201D FECE                <1> 	dec	dh
  2892 0000201F 75DE                <1> 	jnz	short vgamem_fill_l8_0
  2893                              <1> vgamem_fill_l8_1:
  2894 00002021 59                  <1> 	pop	ecx
  2895                              <1> 
  2896                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2897                              <1> 	;mov	ax, 0005h
  2898                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2899                              <1> 	;out	dx, ax
  2900                              <1> 
  2901 00002022 58                  <1> 	pop	eax
  2902 00002023 5A                  <1> 	pop	edx 
  2903                              <1> 
  2904 00002024 C3                  <1> 	retn
  2905                              <1> 
  2906                              <1> vga_graphics_down:
  2907                              <1> 	; 08/08/2016
  2908                              <1> 	; 07/08/2016
  2909                              <1> 	; 31/07/2016
  2910                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2911                              <1> 	;
  2912                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2913                              <1> 	; vgabios-0.7a (2011)
  2914                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2915                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  2916                              <1> 	;
  2917                              <1> 
  2918                              <1> 	; cl = upper left column
  2919                              <1> 	; ch = upper left row
  2920                              <1> 	; dl = lower rigth column
  2921                              <1> 	; dh = lower right row
  2922                              <1> 	;
  2923                              <1> 	; al = line count (AL=0 means blank entire fields)
  2924                              <1> 	; bl = fill value for blanked lines	
  2925                              <1> 	; bh = unused
  2926                              <1> 	;
  2927                              <1> 	; ah = [CRT_MODE], current video mode	
  2928                              <1> 
  2929 00002025 FC                  <1>         cld     ; !!! Clear direction flag !!! 
  2930                              <1> 
  2931 00002026 88C7                <1> 	mov	bh, al ; 31/07/2016
  2932                              <1> 
  2933 00002028 BE[22E90000]        <1> 	mov	esi, vga_modes
  2934 0000202D 89F7                <1> 	mov	edi, esi
  2935 0000202F 83C710              <1> 	add	edi, vga_mode_count
  2936                              <1> vga_g_down_0:
  2937 00002032 AC                  <1> 	lodsb
  2938 00002033 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  2939 00002035 7405                <1> 	je	short vga_g_down_1
  2940 00002037 39FE                <1> 	cmp	esi, edi
  2941 00002039 72F7                <1> 	jb	short vga_g_down_0
  2942                              <1> 	; xor 	bh, bh	; 31/07/2016
  2943 0000203B C3                  <1> 	retn	; nothing to do
  2944                              <1> vga_g_down_1:
  2945 0000203C 88F8                <1> 	mov	al, bh ; 31/07/2016
  2946 0000203E 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  2947                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  2948                              <1> 	
  2949                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  2950                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  2951                              <1>  	; if(nblines>nbrows)nblines=0;
  2952                              <1>  	; cols=clr-cul+1;
  2953                              <1> 
  2954 00002041 3A35[0EE90000]      <1> 	cmp	dh, [VGA_ROWS]
  2955 00002047 7208                <1> 	jb	short vga_g_down_2
  2956 00002049 8A35[0EE90000]      <1> 	mov	dh, [VGA_ROWS]
  2957 0000204F FECE                <1> 	dec	dh
  2958                              <1> vga_g_down_2:
  2959 00002051 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  2960 00002057 7208                <1> 	jb	short vga_g_down_3
  2961 00002059 8A15[08E90000]      <1> 	mov	dl, [CRT_COLS]
  2962 0000205F FECA                <1> 	dec	dl
  2963                              <1> vga_g_down_3:	
  2964 00002061 3A05[0EE90000]      <1> 	cmp	al, [VGA_ROWS]
  2965 00002067 7602                <1> 	jna	short vga_g_down_4
  2966 00002069 28C0                <1> 	sub	al, al ; 0
  2967                              <1> vga_g_down_4:
  2968 0000206B 88F7                <1> 	mov	bh, dh ; clr
  2969 0000206D 28CF                <1> 	sub	bh, cl ; cul
  2970 0000206F FEC7                <1> 	inc	bh ; cols = clr-cul+1
  2971                              <1> 
  2972 00002071 20C0                <1> 	and	al, al ; nblines = 0
  2973 00002073 755B                <1> 	jnz	short vga_g_down_6
  2974 00002075 20ED                <1> 	and	ch, ch ; rul = 0
  2975 00002077 7557                <1> 	jnz	short vga_g_down_6
  2976 00002079 20C9                <1> 	and	cl, cl ; cul = 0
  2977 0000207B 7553                <1> 	jnz	short vga_g_down_6
  2978                              <1> 
  2979 0000207D 6650                <1> 	push	ax
  2980 0000207F A0[0EE90000]        <1> 	mov	al, [VGA_ROWS]
  2981 00002084 FEC8                <1> 	dec	al  
  2982 00002086 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  2983 00002088 7544                <1> 	jne	short vga_g_down_5
  2984 0000208A A0[08E90000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  2985 0000208F FEC8                <1> 	dec	al 
  2986 00002091 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  2987 00002093 7539                <1> 	jne	short vga_g_down_5
  2988 00002095 6658                <1> 	pop	ax
  2989                              <1> 
  2990 00002097 66B80502            <1> 	mov	ax, 0205h
  2991 0000209B 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2992 0000209F 66EF                <1> 	out	dx, ax
  2993 000020A1 A0[0EE90000]        <1> 	mov	al, [VGA_ROWS]
  2994 000020A6 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  2995 000020AC F6E4                <1> 	mul	ah
  2996 000020AE 0FB7D0              <1> 	movzx	edx, ax
  2997                              <1> 	; 08/08/2016
  2998 000020B1 0FB605[0AE90000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2999 000020B8 F7E2                <1> 	mul	edx
  3000                              <1> 	; eax = byte count	
  3001 000020BA 89C1                <1> 	mov	ecx, eax
  3002                              <1> 	;; 07/08/2016
  3003                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  3004                              <1> 	;mov	ecx, edx
  3005 000020BC 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  3006 000020BE BF00000A00          <1> 	mov	edi, 0A0000h
  3007 000020C3 F3AA                <1> 	rep	stosb			
  3008                              <1> 	
  3009 000020C5 B005                <1> 	mov	al, 5
  3010 000020C7 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  3011 000020CB 66EF                <1> 	out	dx, ax ; 0005h	
  3012                              <1> 
  3013 000020CD C3                  <1> 	retn
  3014                              <1> 
  3015                              <1> vga_g_down_5:
  3016 000020CE 6658                <1> 	pop	ax
  3017                              <1> 
  3018                              <1> vga_g_down_6:
  3019                              <1> 	; [ESI] = VGA memory model number for current video mode
  3020                              <1>         ;
  3021                              <1>         ; LINEAR8 equ 5
  3022                              <1>         ; PLANAR4 equ 4
  3023                              <1>         ; PLANAR1 equ 3
  3024                              <1> 
  3025 000020D0 803E04              <1> 	cmp	byte [esi], PLANAR4
  3026 000020D3 742C                <1> 	je	short vga_g_down_planar
  3027 000020D5 803E03              <1> 	cmp	byte [esi], PLANAR1
  3028 000020D8 7427                <1> 	je	short vga_g_down_planar
  3029                              <1> vga_g_down_linear8:
  3030                              <1> 	; 07/07/2016 (TEMPORARY)
  3031                              <1> 	;
  3032                              <1> 	; cl = upper left column ; cul
  3033                              <1> 	; ch = upper left row ; rul
  3034                              <1> 	; dl = lower rigth column ; clr
  3035                              <1> 	; dh = lower right row ; rlr
  3036                              <1> 
  3037                              <1> vga_g_down_l0:
  3038                              <1> 	;{for(i=rlr;i>=rul;i--)
  3039                              <1>         ; if((i<rul+nblines)||(nblines==0))
  3040 000020DA 08C0                <1> 	or	al, al
  3041 000020DC 741C                <1> 	jz	short vga_g_down_l2
  3042 000020DE 88C4                <1> 	mov	ah, al
  3043 000020E0 00EC                <1> 	add	ah, ch
  3044                              <1> 	;jc	short vga_g_down_l2	
  3045 000020E2 86EE                <1> 	xchg	ch, dh
  3046 000020E4 38E5                <1> 	cmp	ch, ah
  3047 000020E6 7212                <1> 	jb	short vga_g_down_l2
  3048 000020E8 88EC                <1> 	mov	ah, ch
  3049 000020EA 28C4                <1> 	sub	ah, al ; ah = i - nblines
  3050                              <1> 	; else
  3051                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  3052 000020EC E877FEFFFF          <1> 	call	vgamem_copy_l8
  3053                              <1> vga_g_down_l1:
  3054 000020F1 86F5                <1> 	xchg	dh, ch
  3055 000020F3 FECE                <1> 	dec	dh 
  3056 000020F5 38EE                <1> 	cmp	dh, ch
  3057 000020F7 73E1                <1> 	jnb	short vga_g_down_l0
  3058 000020F9 C3                  <1> 	retn
  3059                              <1> 
  3060                              <1> vga_g_down_l2:
  3061                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  3062 000020FA E8D3FEFFFF          <1> 	call	vgamem_fill_l8
  3063 000020FF EBF0                <1> 	jmp	short vga_g_down_l1
  3064                              <1> 		 
  3065                              <1> vga_g_down_planar:
  3066                              <1> 	; cl = upper left column ; cul
  3067                              <1> 	; ch = upper left row ; rul
  3068                              <1> 	; dl = lower rigth column ; clr
  3069                              <1> 	; dh = lower right row ; rlr
  3070                              <1> vga_g_down_pl0:
  3071                              <1>  	;{for(i=rlr;i>=rul;i--)
  3072                              <1>         ; if((i<rul+nblines)||(nblines==0))
  3073 00002101 08C0                <1> 	or	al, al
  3074 00002103 741C                <1> 	jz	short vga_g_down_pl2
  3075 00002105 88C4                <1> 	mov	ah, al
  3076 00002107 00EC                <1> 	add	ah, ch
  3077                              <1> 	;jc	short vga_g_down_pl2	
  3078 00002109 86EE                <1> 	xchg	ch, dh
  3079 0000210B 38E5                <1> 	cmp	ch, ah
  3080 0000210D 7212                <1> 	jb	short vga_g_down_pl2
  3081 0000210F 88EC                <1> 	mov	ah, ch
  3082 00002111 28C4                <1> 	sub	ah, al ; ah = i - nblines
  3083                              <1> 	; else
  3084                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  3085 00002113 E88BFDFFFF          <1> 	call	vgamem_copy_pl4
  3086                              <1> vga_g_down_pl1:
  3087 00002118 86F5                <1> 	xchg	dh, ch
  3088 0000211A FECE                <1> 	dec	dh 
  3089 0000211C 38EE                <1> 	cmp	dh, ch
  3090 0000211E 73E1                <1> 	jnb	short vga_g_down_pl0
  3091 00002120 C3                  <1> 	retn
  3092                              <1> 
  3093                              <1> vga_g_down_pl2:
  3094                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  3095 00002121 E8EBFDFFFF          <1> 	call	vgamem_fill_pl4
  3096 00002126 EBF0                <1> 	jmp	short vga_g_down_pl1
  3097                              <1> 
  3098                              <1> ; 07/07/2016
  3099                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  3100                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3101                              <1> ;------------------------------------------------------
  3102                              <1> ; SCROLL DOWN
  3103                              <1> ;  THIS ROUTINE SCROLLS DOWN THE INFORMATION ON THE CRT
  3104                              <1> ; ENTRY --
  3105                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  3106                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  3107                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  3108                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  3109                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  3110                              <1> ;  DS = DATA SEGMENT
  3111                              <1> ;  ES = REGEN SEGMENT
  3112                              <1> ; EXIT --
  3113                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  3114                              <1> ;--------------------------------------------------------
  3115                              <1> 
  3116                              <1> 	; cl = upper left column
  3117                              <1> 	; ch = upper left row
  3118                              <1> 	; dl = lower rigth column
  3119                              <1> 	; dh = lower right row
  3120                              <1> 	;
  3121                              <1> 	; al = line count (AL=0 means blank entire fields)
  3122                              <1> 	; bl = fill value for blanked lines	
  3123                              <1> 	; bh = unused
  3124                              <1> 
  3125                              <1> GRAPHICS_DOWN:
  3126                              <1> 	; 07/07/2016
  3127                              <1> 	;AH = Current video mode, [CRT_MODE]
  3128                              <1> 	;STD				; SET DIRECTION
  3129 00002128 80FC07              <1> 	cmp	ah, 7
  3130 0000212B 0F87F4FEFFFF        <1>         ja      vga_graphics_down
  3131                              <1> 	;je	_n0
  3132                              <1> 
  3133 00002131 88C7                <1> 	MOV	bh, al			; save line count in BH
  3134 00002133 6689D0              <1> 	MOV	AX, DX			; GET LOWER RIGHT POSITION INTO AX REG
  3135                              <1> 
  3136                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  3137                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  3138                              <1> 
  3139 00002136 E8F1010000          <1> 	CALL	GRAPH_POSN
  3140 0000213B 0FB7F8              <1> 	MOVzx	eDI, AX			; SAVE RESULT AS DESTINATION ADDRESS
  3141                              <1> 
  3142                              <1> ;-----	DETERMINE SIZE OF WINDOW
  3143                              <1> 
  3144 0000213E 6629CA              <1> 	SUB	DX, CX
  3145 00002141 6681C20101          <1>         ADD     DX, 101h                ; ADJUST VALUES
  3146 00002146 C0E602              <1> 	SAL	DH, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  3147                              <1> 					; AND EVEN/ODD ROWS
  3148                              <1> 
  3149                              <1> ;-----	DETERMINE CRT MODE
  3150                              <1> 
  3151 00002149 803D[06E90000]06    <1> 	CMP	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  3152 00002150 7307                <1>         JNC     short _R12              ; FIND_SOURCE_DOWN
  3153                              <1> 
  3154                              <1> ;-----	MEDIUM RES DOWN
  3155 00002152 D0E2                <1> 	SAL	DL, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  3156 00002154 66D1E7              <1> 	SAL	DI, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  3157 00002157 6647                <1> 	INC	DI			; POINT TO LAST BYTE
  3158                              <1> 
  3159                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  3160                              <1> 
  3161                              <1> _R12:                                   ; FIND_SOURCE_DOWN
  3162 00002159 81C700800B00        <1> 	add	edi, 0B8000h		
  3163 0000215F 6681C7F000          <1> 	ADD	DI, 240			; POINT TO LAST ROW OF PIXELS
  3164 00002164 C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  3165 00002167 74(06)              <1> 	JZ	short 6			; IF ZERO, THEN BLANK ENTIRE FIELD
  3166 00002169 B050                <1> 	MOV	AL, 80			; 80 BYTES/ROW
  3167 0000216B F6E7                <1> 	mul	bh			; determine offset to source
  3168 0000216D 89FE                <1> 	MOV	eSI, eDI		; SET UP SOURCE
  3169 0000216F 6629C6              <1> 	SUB	SI, AX			; SUBTRACT THE OFFSET
  3170 00002172 88F4                <1> 	MOV	AH, DH			; NUMBER OF ROWS IN FIELD
  3171 00002174 28FC                <1> 	sub	ah, bh			; determine number to move
  3172                              <1> 
  3173                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  3174                              <1> 
  3175                              <1> _R13:                                   ; ROW_LOOP_DOWN
  3176 00002176 E823000000          <1>         CALL    _R17                    ; MOVE ONE ROW
  3177 0000217B 6681EE5020          <1> 	SUB	SI, 2000h+80		; MOVE TO NEXT ROW
  3178 00002180 6681EF5020          <1> 	SUB	DI, 2000h+80
  3179 00002185 FECC                <1> 	DEC	AH			; NUMBER OF ROWS TO MOVE
  3180 00002187 75ED                <1>         JNZ     short _R13              ; CONTINUE TILL ALL MOVED
  3181                              <1> 
  3182                              <1> ;-----	FILL IN THE VACATED LINE(S)
  3183                              <1> _R14:                                   ; CLEAR_ENTRY_DOWN
  3184 00002189 88D8                <1> 	mov	al, bl			; attribute to fill with
  3185                              <1> _R15_:                                  ; CLEAR_LOOP_DOWN
  3186 0000218B E82A000000          <1> 	CALL	_R18			; CLEAR A ROW
  3187 00002190 6681EF5020          <1> 	SUB	DI, 2000h+80		; POINT TO NEXT LINE
  3188 00002195 FECF                <1> 	dec	bh			; number of lines to fill
  3189 00002197 75F2                <1>         JNZ     short _R15_             ; CLEAR_LOOP_DOWN
  3190                              <1> 
  3191 00002199 C3                  <1> 	retn				; EVERYYHING DONE
  3192                              <1> 
  3193                              <1> _R16:                                   ; BLANK_FIELD_DOWN
  3194 0000219A 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  3195 0000219C EBEB                <1>         JMP     short _R14              ; CLEAR THE FIELD
  3196                              <1> 
  3197                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  3198                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3199                              <1> 
  3200                              <1> ;-----	ROUTINE TO MOVE ONE ROW OF INFORMATION
  3201                              <1> 
  3202                              <1> _R17:
  3203 0000219E 0FB6CA              <1> 	MOVzx	ecx, DL			; NUMBER OF BYTES IN THE ROW
  3204 000021A1 56                  <1> 	PUSH	eSI
  3205 000021A2 57                  <1> 	PUSH	eDI			; SAVE POINTERS
  3206 000021A3 F3A4                <1> 	REP	MOVSB			; MOVE THE EVEN FIELD
  3207 000021A5 5F                  <1> 	POP	eDI
  3208 000021A6 5E                  <1> 	POP	eSI
  3209 000021A7 6681C60020          <1> 	ADD	SI, 2000h
  3210 000021AC 6681C70020          <1> 	ADD	DI, 2000h		; POINT TO THE ODD FIELD
  3211 000021B1 56                  <1> 	PUSH	eSI
  3212 000021B2 57                  <1> 	PUSH	eDI			; SAVE THE POINTERS
  3213 000021B3 88D1                <1> 	MOV	CL, DL			; COUNT BACK
  3214 000021B5 F3A4                <1> 	REP	MOVSB			; MOVE THE ODD FIELD
  3215 000021B7 5F                  <1> 	POP	eDI
  3216 000021B8 5E                  <1> 	POP	eSI			; POINTERS BACK
  3217 000021B9 C3                  <1> 	RETn				; RETURN TO CALLER
  3218                              <1> 
  3219                              <1> ;-----	CLEAR A SINGLE ROW
  3220                              <1> 
  3221                              <1> _R18:
  3222 000021BA 0FB6CA              <1> 	MOVzx	ecx, DL			; NUMBER OF BYTES IN FIELD
  3223 000021BD 57                  <1> 	PUSH	eDI			; SAVE POINTER
  3224 000021BE F3AA                <1> 	REP	STOSB			; STORE THE NEW VALUE
  3225 000021C0 5F                  <1> 	POP	eDI			; POINTER BACK
  3226 000021C1 6681C70020          <1> 	ADD	DI, 2000h		; POINT TO ODD FIELD
  3227 000021C6 57                  <1> 	PUSH	eDI
  3228 000021C7 88D1                <1> 	MOV	CL, DL
  3229 000021C9 F3AA                <1> 	REP	STOSB			; FILL THE ODD FIELD
  3230 000021CB 5F                  <1> 	POP	eDI
  3231 000021CC C3                  <1> 	RETn				; RETURN TO CALLER
  3232                              <1> 
  3233                              <1> ; 04/07/2016
  3234                              <1> ; 01/07/2016
  3235                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3236                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3237                              <1> ;--------------------------------------------------
  3238                              <1> ; GRAPHICS WRITE
  3239                              <1> ;  THIS ROUTINE WRITES THE ASCII CHARACTER TO THE CURRENT
  3240                              <1> ;  POSITION ON THE SCREEN.
  3241                              <1> ; ENTRY --
  3242                              <1> ;  AL = CHARACTER TO WRITE
  3243                              <1> ;  BL = COLOR ATTRIBUTE TO BE USED FOR FOREGROUND COLOR
  3244                              <1> ;	IF BIT 7 IS SET, THE CHAR IS XOR'D INTO THE REGEN BUFFER
  3245                              <1> ;	(0 IS USED FOR THE BACKGROUND COLOR)
  3246                              <1> ;  CX = NUMBER OF CHARS TO WRITE
  3247                              <1> ;  DS = DATA SEGMENT
  3248                              <1> ;  ES = REGEN SEGMENT
  3249                              <1> ; EXIT --
  3250                              <1> ;  NOTHING IS RETURNED
  3251                              <1> ;
  3252                              <1> ; GRAPHICS READ
  3253                              <1> ;  THIS ROUTINE READS THE ASCII CHARACTER AT THE CURRENT CURSOR
  3254                              <1> ;  POSITION ON THE SCREEN BY MATCHING THE DOTS ON THE SCREEN TO THE
  3255                              <1> ;  CHARACTER GENERATOR CODE POINTS
  3256                              <1> ; ENTRY --
  3257                              <1> ;  NONE (0 IS ASSUMED AS THE BACKGROUND COLOR)
  3258                              <1> ; EXIT --
  3259                              <1> ;  AL = CHARACTER READ AT THAT POSITION (0 RETURNED IF NONE FOUND)
  3260                              <1> ;
  3261                              <1> ; FOR BOTH ROUTINES, THE IMAGES USED TO FORM CHARS ARE CONTAINED IN ROM
  3262                              <1> ;  FOR THE 1ST 128 CHARS.  TO ACCESS CHARS IN THE SECOND HALF, THE USER
  3263                              <1> ;  MUST INITIALIZE THE VECTOR AT INTERRUPT 1FH (LOCATION 0007CH) TO
  3264                              <1> ;  POINT TO THE USER SUPPLIED TABLE OF GRAPHIC IMAGES (8X8 BOXES).
  3265                              <1> ;  FAILURE TO DO SO WILL CAUSE IN STRANGE RESULTS
  3266                              <1> ;-----------------------------------------------------
  3267                              <1> 
  3268                              <1> GRAPHICS_WRITE:
  3269 000021CD 25FF000000          <1> 	and 	eax, 0FFh		; ZERO TO HIGH OF CODE POINT
  3270 000021D2 50                  <1> 	PUSH	eAX			; SAVE CODE POINT VALUE
  3271                              <1> 
  3272                              <1> ;-----	DETERMINE POSITION IN REGEN BUFFER TO PUT CODE POINTS
  3273                              <1> 
  3274 000021D3 E84D010000          <1> 	CALL	S26			; FIND LOCATION IN REGEN BUFFER
  3275 000021D8 89C7                <1> 	MOV	eDI, eAX		; REGEN POINTER IN DI
  3276                              <1> 
  3277                              <1> ;-----	DETERMINE REGION TO GET CODE POINTS FROM
  3278                              <1> 
  3279 000021DA 58                  <1> 	POP	eAX			; RECOVER CODE POINT
  3280                              <1> 
  3281 000021DB BE[60F40000]        <1> 	MOV	eSI, CRT_CHAR_GEN	; OFFSET OF IMAGES
  3282                              <1> 
  3283                              <1> ;-----	DETERMINE GRAPHICS MODE IN OPERATION
  3284                              <1> 					; DETERMINE_MODE
  3285 000021E0 66C1E003            <1> 	SAL	AX, 3			; MULTIPLY CODE POINT VALUE BY 8
  3286 000021E4 01C6                <1> 	ADD	eSI, eAX		; SI HAS OFFSET OF DESIRED CODES
  3287                              <1> 	
  3288 000021E6 803D[06E90000]06    <1> 	CMP	byte [CRT_MODE], 6
  3289 000021ED 7231                <1> 	JC	short S6		; TEST FOR MEDIUM RESOLUTION MODE
  3290                              <1> 
  3291                              <1> ;-----	HIGH RESOLUTION MODE
  3292                              <1> 
  3293 000021EF 81C700800B00        <1> 	add	edi, 0B8000h
  3294                              <1> S1:					; HIGH_CHAR
  3295 000021F5 57                  <1> 	PUSH	eDI			; SAVE REGEN POINTER
  3296 000021F6 56                  <1> 	PUSH	eSI			; SAVE CODE POINTER
  3297 000021F7 B604                <1> 	MOV	DH, 4			; NUMBER OF TIMES THROUGH LOOP
  3298                              <1> S2:
  3299 000021F9 AC                  <1> 	LODSB				; GET BYTE FROM CODE POINTS
  3300 000021FA F6C380              <1> 	TEST	BL, 80H			; SHOULD WE USE THE FUNCTION
  3301 000021FD 7515                <1> 	JNZ	short S5		; TO PUT CHAR IN
  3302 000021FF AA                  <1> 	STOSB				; STORE IN REGEN BUFFER
  3303 00002200 AC                  <1> 	LODSB
  3304                              <1> S4:
  3305 00002201 8887FF1F0000        <1> 	MOV	[eDI+2000H-1], AL ; STORE IN SECOND HALF
  3306 00002207 83C74F              <1> 	ADD	eDI, 79			; MOVE TO NEXT ROW IN REGEN
  3307 0000220A FECE                <1> 	DEC	DH			; DONE WITH LOOP
  3308 0000220C 75EB                <1> 	JNZ	short S2
  3309 0000220E 5E                  <1> 	POP	eSI
  3310 0000220F 5F                  <1> 	POP	eDI			; RECOVER REGEN POINTER
  3311 00002210 47                  <1> 	INC	eDI			; POINT TO NEXT CHAR POSITION
  3312 00002211 E2E2                <1> 	LOOP	S1			; MORE CHARS TO WRITE
  3313 00002213 C3                  <1> 	retn
  3314                              <1> 
  3315                              <1> S5:
  3316 00002214 3207                <1> 	XOR	AL, [eDI]		; EXCLUSIVE OR WITH CURRENT
  3317 00002216 AA                  <1> 	STOSB				; STORE THE CODE POINT
  3318 00002217 AC                  <1> 	LODSB				; AGAIN FOR ODD FIELD
  3319 00002218 3287FF1F0000        <1> 	XOR	AL, [eDI+2000H-1]
  3320 0000221E EBE1                <1> 	JMP	short S4		; BACK TO MAINSTREAM
  3321                              <1> 
  3322                              <1> ;-----	MEDIUM RESOLUTION WRITE
  3323                              <1> S6:					; MED_RES_WRITE
  3324 00002220 88DA                <1> 	MOV	DL, BL			; SAVE HIGH COLOR BIT
  3325 00002222 66D1E7              <1> 	SAL	DI, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  3326                              <1> 					; EXPAND BL TO FULL WORD OF COLOR
  3327 00002225 80E303              <1> 	AND	BL, 3			; ISOLATE THE COLOR BITS ( LOW 2 BITS )
  3328 00002228 B055                <1> 	MOV	AL, 055H 		; GET BIT CONVERSION MULTIPLIER
  3329 0000222A F6E3                <1> 	MUL	BL			; EXPAND 2 COLOR BITS TO 4 REPLICATIONS
  3330 0000222C 88C3                <1> 	MOV	BL, AL			; PLACE BACK IN WORK REGISTER
  3331 0000222E 88C7                <1> 	MOV	BH, AL			; EXPAND TO 8 REPLICATIONS OF COLOR BITS
  3332 00002230 81C700800B00        <1> 	add	edi, 0B8000h
  3333                              <1> S7:                                     ; MED_CHAR
  3334 00002236 57                  <1> 	PUSH	eDI			; SAVE REGEN POINTER
  3335 00002237 56                  <1> 	PUSH	eSI			; SAVE THE CODE POINTER
  3336 00002238 B604                <1> 	MOV	DH, 4			; NUMBER OF LOOPS
  3337                              <1> S8:
  3338 0000223A AC                  <1> 	LODSB				; GET CODE POINT
  3339 0000223B E8B3000000          <1> 	CALL	S21			; DOUBLE UP ALL THE BITS
  3340 00002240 6621D8              <1> 	AND	AX, BX			; CONVERT TO FOREGROUND COLOR ( 0 BACK )
  3341 00002243 86E0                <1> 	XCHG	AH, AL			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  3342 00002245 F6C280              <1> 	TEST	DL, 80H			; IS THIS XOR FUNCTION
  3343 00002248 7403                <1> 	JZ	short S9		; NO, STORE IT IN AS IS
  3344 0000224A 663307              <1> 	XOR	AX, [eDI]		; DO FUNCTION WITH LOW/HIGH
  3345                              <1> S9:
  3346 0000224D 668907              <1> 	MOV	[eDI], AX		; STORE FIRST BYTE HIGH, SECOND LOW
  3347 00002250 AC                  <1> 	LODSB				; GET CODE POINT
  3348 00002251 E89D000000          <1> 	CALL	S21
  3349 00002256 6621D8              <1> 	AND	AX, BX			; CONVERT TO COLOR
  3350 00002259 86E0                <1> 	XCHG	AH, AL			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  3351 0000225B F6C280              <1> 	TEST	DL, 80H			; AGAIN, IS THIS XOR FUNCTION
  3352 0000225E 7407                <1> 	JZ	short _S10		; NO, JUST STORE THE VALUES
  3353 00002260 66338700200000      <1> 	XOR	AX, [eDI+2000H]		; FUNCTION WITH FIRST HALF LOW
  3354                              <1> _S10:
  3355 00002267 66898700200000      <1> 	MOV	[eDI+2000H], AX		; STORE SECOND PORTION HIGH
  3356 0000226E 6683C750            <1> 	ADD	DI, 80			; POINT TO NEXT LOCATION
  3357 00002272 FECE                <1> 	DEC	DH
  3358 00002274 75C4                <1> 	JNZ	short S8		; KEEP GOING
  3359 00002276 5E                  <1> 	POP	eSI			; RECOVER CODE POINTER
  3360 00002277 5F                  <1> 	POP	eDI			; RECOVER REGEN POINTER
  3361 00002278 47                  <1> 	INC	eDI			; POINT TO NEXT CHAR POSITION
  3362 00002279 47                  <1> 	INC	eDI
  3363 0000227A E2BA                <1> 	LOOP	S7			; MORE TO WRITE
  3364 0000227C C3                  <1> 	retn
  3365                              <1> 
  3366                              <1> ; 04/07/2016
  3367                              <1> ; 01/07/2016
  3368                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3369                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3370                              <1> ;----------------------------------------
  3371                              <1> ; GRAPHICS READ
  3372                              <1> ;----------------------------------------
  3373                              <1> GRAPHICS_READ:
  3374 0000227D E8A3000000          <1> 	CALL	S26			; CONVERTED TO OFFSET IN REGEN
  3375 00002282 89C6                <1> 	MOV	eSI, eAX		; SAVE IN SI
  3376 00002284 81C600800B00        <1> 	add	esi, 0B8000h		; 01/07/2016
  3377 0000228A 83EC08              <1> 	SUB	eSP, 8			; ALLOCATE SPACE FOR THE READ CODE POINT
  3378 0000228D 89E5                <1> 	MOV	eBP, eSP		; POINTER TO SAVE AREA
  3379                              <1> 
  3380                              <1> ;-----	DETERMINE GRAPHICS MODES
  3381 0000228F B604                <1> 	mov	dh, 4			; number of passes ; 01/07/2016
  3382 00002291 803D[06E90000]06    <1> 	CMP	byte [CRT_MODE], 6
  3383 00002298 7219                <1> 	JC	short S12		; MEDIUM RESOLUTION
  3384                              <1> 
  3385                              <1> ;-----	HIGH RESOLUTION READ
  3386                              <1> ;-----	GET VALUES FROM REGEN BUFFER AND CONVERT TO CODE POINT
  3387                              <1> 	;MOV	DH,4			; NUMBER OF PASSES
  3388                              <1> S11:
  3389 0000229A 8A06                <1> 	MOV	AL, [eSI] 		; GET FIRST BYTE
  3390 0000229C 884500              <1> 	MOV	[eBP], AL 		; SAVE IN STORAGE AREA
  3391 0000229F 45                  <1> 	INC	eBP			; NEXT LOCATION
  3392 000022A0 8A8600200000        <1> 	MOV	AL, [eSI+2000H]		; GET LOWER REGION BYTE
  3393 000022A6 884500              <1> 	MOV	[eBP], AL 		; ADJUST AND STORE
  3394 000022A9 45                  <1> 	INC	eBP
  3395 000022AA 83C650              <1> 	ADD	eSI, 80			; POINTER INTO REGEN
  3396 000022AD FECE                <1> 	DEC	DH			; LOOP CONTROL
  3397 000022AF 75E9                <1> 	JNZ	short S11		; DO IT SOME MORE
  3398 000022B1 EB1D                <1> 	JMP	SHORT S14		; GO MATCH THE SAVED CODE POINTS
  3399                              <1> 
  3400                              <1> ;-----	MEDIUM RESOLUTION READ
  3401                              <1> S12:	
  3402 000022B3 66D1E6              <1> 	SAL	SI, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  3403                              <1> 	;MOV	DH, 4			; NUMBER OF PASSES
  3404                              <1> S13:
  3405 000022B6 E84D000000          <1> 	CALL	S23			; GET BYTES FROM REGEN INTO SINGLE SAVE
  3406 000022BB 81C6FE1F0000        <1> 	ADD	eSI, 2000H-2		; GO TO LOWER REGION
  3407 000022C1 E842000000          <1> 	CALL	S23			; GET THIS PAIR INTO SAVE
  3408 000022C6 81EEB21F0000        <1> 	SUB	eSI, 2000H-80+2		; ADJUST POINTER BACK INTO UPPER
  3409 000022CC FECE                <1> 	DEC	DH
  3410 000022CE 75E6                <1> 	JNZ	short S13		; KEEP GOING UNTIL ALL 8 DONE
  3411                              <1> 
  3412                              <1> ;-----	SAVE AREA HAS CHARACTER IN IT, MATCH IT
  3413                              <1> S14:					; FIND_CHAR
  3414 000022D0 BF[60F40000]        <1> 	MOV	eDI, CRT_CHAR_GEN	; ESTABLISH ADDRESSING
  3415 000022D5 83ED08              <1> 	SUB	eBP, 8			; ADJUST POINTER TO START OF SAVE AREA
  3416 000022D8 89EE                <1> 	MOV	eSI, eBP
  3417                              <1> S15:
  3418 000022DA 66B80001            <1> 	mov	ax, 256			; NUMBER TO TEST AGAINST
  3419                              <1> S16:
  3420 000022DE 56                  <1> 	PUSH	eSI			; SAVE SAVE AREA POINTER
  3421 000022DF 57                  <1> 	PUSH	eDI			; SAVE CODE POINTER
  3422                              <1> 	;MOV	eCX, 4			; NUMBER OF WORDS TO MATCH
  3423                              <1> 	;REPE	CMPSW			; COMPARE THE 8 BYTES AS WORDS
  3424 000022E0 A7                  <1> 	cmpsd				; compare first 4 bytes 
  3425 000022E1 7501                <1> 	jne	short S17		; 
  3426 000022E3 A7                  <1> 	cmpsd				; compare last 4 bytes
  3427                              <1> S17:
  3428 000022E4 5F                  <1> 	POP	eDI			; RECOVER THE POINTERS
  3429 000022E5 5E                  <1> 	POP	eSI
  3430                              <1> 	;JZ	short S18		; IF ZERO FLAG SET, THEN MATCH OCCURRED
  3431 000022E6 7407                <1> 	je	short S18
  3432                              <1> 	;				; NO MATCH, MOVE ON TO NEXT
  3433 000022E8 83C708              <1> 	ADD	eDI, 8			; NEXT CODE POINT
  3434 000022EB 6648                <1> 	dec	ax			; LOOP CONTROL
  3435 000022ED 75EF                <1> 	JNZ	short S16		; DO ALL OF THEM
  3436                              <1> 
  3437                              <1> ;-----	CHARACTER IS FOUND ( AL=0 IF NOT FOUND )
  3438                              <1> S18:	
  3439 000022EF 83C408              <1> 	ADD	eSP, 8			; READJUST THE STACK, THROW AWAY SAVE
  3440 000022F2 C3                  <1> 	retn				; ALL DONE
  3441                              <1> 
  3442                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3443                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3444                              <1> ;--------------------------------------------
  3445                              <1> ; EXPAND BYTE
  3446                              <1> ;  THIS ROUTINE TAKES THE BYTE IN AL AND DOUBLES ALL
  3447                              <1> ;  OF THE BITS, TURNING THE 8 BITS INTO 16 BITS.
  3448                              <1> ;  THE RESULT IS LEFT IN AX
  3449                              <1> ;--------------------------------------------
  3450                              <1> S21:
  3451 000022F3 6651                <1> 	PUSH	CX			; SAVE REGISTER
  3452                              <1> 	;MOV	CX, 8			; SHIFT COUNT REGISTER FOR ONE BYTE
  3453 000022F5 B108                <1> 	mov	cl, 8
  3454                              <1> S22:
  3455 000022F7 D0C8                <1> 	ROR	AL,1			; SHIFT BITS, LOW BIT INTO CARRY FLAG
  3456 000022F9 66D1DD              <1> 	RCR	BP,1			; MOVE CARRY FLAG (LOW BIT INTO RESULTS
  3457 000022FC 66D1FD              <1> 	SAR	BP,1			; SIGN EXTEND HIGH BIT (DOUBLE IT)
  3458                              <1> 	;LOOP	S22			; REPEAT FOR ALL 8 BITS
  3459 000022FF FEC9                <1> 	dec	cl
  3460 00002301 75F4                <1> 	jnz	short S22
  3461 00002303 6695                <1> 	XCHG	AX, BP			; MOVE RESULTS TO PARAMETER REGISTER
  3462 00002305 6659                <1> 	POP	CX			; RECOVER REGISTER
  3463 00002307 C3                  <1> 	RETn				; ALL DONE
  3464                              <1> 
  3465                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3466                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3467                              <1> ;--------------------------------------------------
  3468                              <1> ; MED_READ_BYTE
  3469                              <1> ; THIS ROUTINE WILL TAKE 2 BYTES FROM THE REGEN BUFFER,
  3470                              <1> ;  COMPARE AGAINST THE CURRENT FOREGROUND COLOR, AND PLACE
  3471                              <1> ;  THE CORRESPONDING ON/OFF BIT PATTERN INTO THE CURRENT
  3472                              <1> ;  POSITION IN THE SAVE AREA
  3473                              <1> ; ENTRY --
  3474                              <1> ;  SI,DS = POINTER TO REGEN AREA OF INTEREST
  3475                              <1> ;  BX = EXPANDED FOREGROUND COLOR
  3476                              <1> ;  BP = POINTER TO SAVE AREA
  3477                              <1> ; EXIT --
  3478                              <1> ;  SI AND BP ARE INCREMENTED
  3479                              <1> ;----------------------------------------------------
  3480                              <1> S23:
  3481 00002308 66AD                <1> 	LODSW				; GET FIRST BYTE AND SECOND BYTES
  3482 0000230A 86C4                <1> 	XCHG	AL, AH			; SWAP FOR COMPARE
  3483 0000230C 66B900C0            <1> 	MOV	CX, 0C000H		; 2 BIT MASK TO TEST THE ENTRIES
  3484 00002310 B200                <1> 	MOV	DL, 0			; RESULT REGISTER
  3485                              <1> S24:
  3486 00002312 6685C8              <1> 	TEST	AX, CX			; IS THIS SECTION BACKCROUND?
  3487 00002315 7401                <1>         JZ      short S25               ; IF ZERO, IT IS BACKGROUND (CARRY=0)
  3488 00002317 F9                  <1> 	STC				; WASN'T, SO SET CARRY
  3489                              <1> S25:
  3490 00002318 D0D2                <1> 	RCL	DL, 1			; MOVE THAT BIT INTO THE RESULT
  3491 0000231A 66C1E902            <1> 	SHR	CX, 2			; MOVE THE MASK TO THE RIGHT BY 2 BITS
  3492 0000231E 73F2                <1> 	JNC	short S24		; DO IT AGAIN IF MASK DIDN'T FALL OUT
  3493 00002320 885500              <1> 	MOV	[eBP], DL 		; STORE RESULT IN SAVE AREA
  3494 00002323 45                  <1> 	INC	eBP			; ADJUST POINTER
  3495 00002324 C3                  <1> 	RETn				; ALL DONE
  3496                              <1> 
  3497                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3498                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3499                              <1> ;-----------------------------------------
  3500                              <1> ; V4_POSITION
  3501                              <1> ;  THIS ROUTINE TAKES THE CURSOR POSITION CONTAINED IN
  3502                              <1> ;  THE MEMORY LOCATION, AND CONVERTS IT INTO AN OFFSET
  3503                              <1> ;  INTO THE REGEN BUFFER, ASSUMING ONE BYTE/CHAR.
  3504                              <1> ;  FOR MEDIUM RESOLUTION GRAPHICS, THE NUMBER MUST
  3505                              <1> ;  BE DOUBLED.
  3506                              <1> ; ENTRY -- NO REGISTERS,MEMORY LOCATION @CURSOR_POSN IS USED
  3507                              <1> ; EXIT--
  3508                              <1> ;  AX CONTAINS OFFSET INTO REGEN BUFFER
  3509                              <1> ;-----------------------------------------
  3510                              <1> S26:
  3511 00002325 0FB705[E61F0100]    <1> 	movzx	eax, word [CURSOR_POSN]	; GET CURRENT CURSOR
  3512                              <1> GRAPH_POSN:
  3513 0000232C 53                  <1> 	PUSH	eBX			; SAVE REGISTER
  3514 0000232D 0FB6D8              <1> 	movzx	ebx, al			; SAVE A COPY OF CURRENT CURSOR
  3515 00002330 A0[08E90000]        <1> 	MOV	AL, [CRT_COLS]		; GET BYTES PER COLUMN
  3516 00002335 F6E4                <1> 	MUL	AH			; MULTIPLY BY ROWS
  3517 00002337 66C1E002            <1> 	SHL	AX, 2			; MULTIPLY * 4 SINCE 4 ROWS/BYTE
  3518 0000233B 01D8                <1> 	ADD	eAX, eBX		; DETERMINE OFFSET
  3519 0000233D 5B                  <1> 	POP	eBX			; RECOVER POINTER
  3520 0000233E C3                  <1> 	RETn				; ALL DONE
  3521                              <1> 
  3522                              <1> ; 09/07/2016
  3523                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3524                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3525                              <1> ;---------------------------------------------
  3526                              <1> ; SET_COLOR
  3527                              <1> ;	THIS ROUTINE WILL ESTABLISH THE BACKGROUND COLOR, THE OVERSCAN COLOR,
  3528                              <1> ;	AND THE FOREGROUND COLOR SET FOR MEDIUM RESOLUTION GRAPHICS
  3529                              <1> ; INPUT
  3530                              <1> ;	(BH) HAS COLOR ID
  3531                              <1> ;		IF BH=0, THE BACKGROUND COLOR VALUE IS SET
  3532                              <1> ;			FROM THE LOW BITS OF BL (0-31)
  3533                              <1> ;		IF BH=1, THE PALETTE SELECTION IS MADE
  3534                              <1> ;			BASED ON THE LOW BIT OF BL:
  3535                              <1> ;				0 = GREEN, RED, YELLOW FOR COLORS 1,2,3
  3536                              <1> ;				1 = BLUE, CYAN, MAGENTA FOR COLORS 1,2,3
  3537                              <1> ;	(BL) HAS THE COLOR VALUE TO BE USED
  3538                              <1> ; OUTPUT
  3539                              <1> ;	THE COLOR SELECTION IS UPDATED
  3540                              <1> ;----------------------------------------------
  3541                              <1> SET_COLOR:
  3542 0000233F 803D[06E90000]07    <1>         cmp     byte [CRT_MODE], 7      ; 09/07/2016
  3543 00002346 0F87B4F0FFFF        <1> 	ja	VIDEO_RETURN		; nothing to do for VGA modes	 
  3544                              <1> 
  3545                              <1> 	;MOV	DX, [ADDR_6845]		; I/O PORT FOR PALETTE
  3546                              <1> 	;mov	dx, 3D4h
  3547                              <1> 	;ADD	DX,5			; OVERSCAN PORT
  3548 0000234C 66BAD903            <1> 	mov	dx, 3D9h
  3549 00002350 A0[09E90000]        <1> 	MOV	AL, [CRT_PALETTE] 	; GET THE CURRENT PALETTE VALUE
  3550 00002355 08FF                <1> 	OR	BH, BH			; IS THIS COLOR 0?
  3551 00002357 7512                <1> 	JNZ	short M20		; OUTPUT COLOR 1
  3552                              <1> 
  3553                              <1> ;-----	HANDLE COLOR 0 BY SETTING THE BACKGROUND COLOR
  3554                              <1> 
  3555 00002359 24E0                <1> 	AND	AL, 0E0H 		; TURN OFF LOW 5 BITS OF CURRENT
  3556 0000235B 80E31F              <1> 	AND	BL, 01FH 		; TURN OFF HIGH 3 BITS OF INPUT VALUE
  3557 0000235E 08D8                <1> 	OR	AL, BL			; PUT VALUE INTO REGISTER
  3558                              <1> M19:					; OUTPUT THE PALETTE
  3559 00002360 EE                  <1> 	OUT	DX, AL			; OUTPUT COLOR SELECTION TO 3D9 PORT
  3560 00002361 A2[09E90000]        <1> 	MOV	[CRT_PALETTE], AL 	; SAVE THE COLOR VALUE
  3561 00002366 E995F0FFFF          <1> 	JMP	VIDEO_RETURN
  3562                              <1> 
  3563                              <1> ;-----	HANDLE COLOR 1 BY SELECTING THE PALETTE TO BE USED
  3564                              <1> 
  3565                              <1> M20:
  3566 0000236B 24DF                <1> 	AND	AL, 0DFH 		; TURN OFF PALETTE SELECT BIT
  3567 0000236D D0EB                <1> 	SHR	BL, 1			; TEST THE LOW ORDER BIT OF BL
  3568 0000236F 73EF                <1> 	JNC	short M19		; ALREADY DONE
  3569 00002371 0C20                <1> 	OR	AL, 20H			; TURN ON PALETTE SELECT BIT
  3570 00002373 EBEB                <1> 	JMP	short M19		; GO DO IT
  3571                              <1> 
  3572                              <1> ; 09/07/2016
  3573                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3574                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3575                              <1> ;--------------------------------------------
  3576                              <1> ; READ DOT -- WRITE DOT
  3577                              <1> ; THESE ROUTINES WILL WRITE A DOT, OR READ THE
  3578                              <1> ;  DOT AT THE INDICATED LOCATION
  3579                              <1> ; ENTRY --
  3580                              <1> ;   DX = ROW (0-199)	(THE ACTUAL VALUE DEPENDS ON THE MODE)
  3581                              <1> ;   CX = COLUMN ( 0-639) ( THE VALUES ARE NOT RANGE CHECKED )
  3582                              <1> ;   AL = DOT VALUE TO WRITE (1,2 OR 4 BITS DEPENDING ON MODE,
  3583                              <1> ;	REQUIRED FOR WRITE DOT ONLY, RIGHT JUSTIFIED)
  3584                              <1> ;	BIT 7 OF AL = 1 INDICATES XOR THE VALUE INTO THE LOCATION
  3585                              <1> ;   DS = DATA SEGMENT
  3586                              <1> ;   ES = REGEN SEGMENT
  3587                              <1> ;
  3588                              <1> ; EXIT
  3589                              <1> ;	AL = DOT VALUE READ, RIGHT JUSTIFIED, READ ONLY
  3590                              <1> ;----------------------------------------------
  3591                              <1> 
  3592                              <1> READ_DOT:
  3593                              <1> 	; 09/07/2016
  3594 00002375 8A25[06E90000]      <1> 	mov	ah,  [CRT_MODE]
  3595 0000237B 80FC07              <1> 	cmp	ah, 7 ; 6!?
  3596 0000237E 760A                <1> 	jna	short read_dot_cga
  3597                              <1> 
  3598 00002380 E8CB030000          <1> 	call	vga_read_pixel
  3599                              <1> 	; al = pixel value
  3600 00002385 E97BF0FFFF          <1> 	jmp	_video_return
  3601                              <1> 
  3602                              <1> read_dot_cga:
  3603                              <1> 	;je	VIDEO_RETURN ; 7	
  3604 0000238A 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  3605 0000238D 0F826DF0FFFF        <1> 	jb	VIDEO_RETURN ; no, text mode, nothing to do
  3606                              <1> 
  3607 00002393 E855000000          <1> 	CALL	R3			; DETERMINE BYTE POSITION OF DOT
  3608 00002398 8A06                <1> 	MOV	AL, [eSI]		; GET THE BYTE
  3609 0000239A 20E0                <1> 	AND	AL, AH			; MASK OFF THE OTHER BITS IN THE BYTE
  3610 0000239C D2E0                <1> 	SHL	AL, CL			; LEFT JUSTIFY THE VALUE
  3611 0000239E 88F1                <1> 	MOV	CL, DH			; GET NUMBER OF BITS IN RESULT
  3612 000023A0 D2C0                <1> 	ROL	AL, CL			; RIGHT JUSTIFY THE RESULT
  3613                              <1> 	;JMP	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  3614 000023A2 0FB6C0              <1> 	movzx	eax, al
  3615 000023A5 E95BF0FFFF          <1> 	jmp	_video_return
  3616                              <1> 
  3617                              <1> ; 09/07/2016
  3618                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3619                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3620                              <1> 
  3621                              <1> WRITE_DOT:
  3622                              <1> 	; 09/07/2016
  3623 000023AA 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE]
  3624 000023B0 80FC07              <1> 	cmp	ah, 7 ; 6!?
  3625 000023B3 760A                <1> 	jna	short write_dot_cga
  3626                              <1> 	
  3627 000023B5 E805030000          <1> 	call	vga_write_pixel
  3628 000023BA E941F0FFFF          <1> 	jmp	VIDEO_RETURN
  3629                              <1> 
  3630                              <1> write_dot_cga:
  3631                              <1> 	;je	VIDEO_RETURN ; 7	
  3632 000023BF 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  3633 000023C2 0F8238F0FFFF        <1> 	jb	VIDEO_RETURN ; no, text mode, nothing to do
  3634                              <1> 
  3635                              <1> 	;PUSH	AX			; SAVE DOT VALUE
  3636 000023C8 6650                <1> 	PUSH	AX			; TWICE
  3637 000023CA E81E000000          <1> 	CALL	R3			; DETERMINE BYTE POSITION OF THE DOT
  3638 000023CF D2E8                <1> 	SHR	AL, CL			; SHIFT TO SET UP THE BITS FOR OUTPUT
  3639 000023D1 20E0                <1> 	AND	AL, AH			; STRIP OFF THE OTHER BITS
  3640 000023D3 8A0E                <1> 	MOV	CL, [eSI]		; GET THE CURRENT BYTE
  3641 000023D5 665B                <1> 	POP	BX			; RECOVER XOR FLAG
  3642 000023D7 F6C380              <1> 	TEST	BL, 80H			; IS IT ON
  3643 000023DA 750D                <1> 	JNZ	short R2		; YES, XOR THE DOT
  3644 000023DC F6D4                <1> 	NOT	AH			; SET MASK TO REMOVE THE INDICATED BITS
  3645 000023DE 20E1                <1> 	AND	CL, AH
  3646 000023E0 08C8                <1> 	OR	AL, CL			; OR IN THE NEW VALUE OF THOSE BITS
  3647                              <1> R1:					; FINISH_DOT
  3648 000023E2 8806                <1> 	MOV	[eSI], AL		; RESTORE THE BYTE IN MEMORY
  3649                              <1> 	;POP	AX
  3650 000023E4 E917F0FFFF          <1> 	JMP	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  3651                              <1> R2:					; XOR_DOT
  3652 000023E9 30C8                <1> 	XOR	AL, CL			; EXCLUSIVE OR THE DOTS
  3653 000023EB EBF5                <1> 	JMP	short R1		; FINISH UP THE WRITING
  3654                              <1> 
  3655                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3656                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3657                              <1> 
  3658                              <1> ;----------------------------------------------
  3659                              <1> ; THIS SUBROUTINE DETERMINES THE REGEN BYTE LOCATION OF THE
  3660                              <1> ; INDICATED ROW COLUMN VALUE IN GRAPHICS MODE.
  3661                              <1> ; ENTRY --
  3662                              <1> ;  DX = ROW VALUE (0-199)
  3663                              <1> ;  CX = COLUMN VALUE (0-639)
  3664                              <1> ; EXIT --
  3665                              <1> ;  SI = OFFSET INTO REGEN BUFFER FOR BYTE OF INTEREST
  3666                              <1> ;  AH = MASK TO STRIP OFF THE BITS OF INTEREST
  3667                              <1> ;  CL = BITS TO SHIFT TO RIGHT JUSTIFY THE MASK IN AH
  3668                              <1> ;  DH = # BITS IN RESULT
  3669                              <1> ;  BX = MODIFIED
  3670                              <1> ;-----------------------------------------------
  3671                              <1> R3:
  3672                              <1> 
  3673                              <1> ;-----	DETERMINE 1ST BYTE IN INDICATED ROW BY MULTIPLYING ROW VALUE BY 40
  3674                              <1> ;-----	 ( LOW BIT OF ROW DETERMINES EVEN/ODD, 80 BYTES/ROW )
  3675                              <1> 
  3676 000023ED 0FB7F0              <1> 	movzx	esi, ax			; WILL SAVE AL AND AH DURING OPERATION
  3677 000023F0 B028                <1> 	MOV	AL, 40
  3678 000023F2 F6E2                <1> 	MUL	DL			; AX= ADDRESS OF START OF INDICATED ROW
  3679 000023F4 A808                <1> 	TEST	AL, 08H 		; TEST FOR EVEN/ODD ROW CALCULATED
  3680 000023F6 7404                <1> 	JZ	short R4		; JUMP IF EVEN ROW
  3681 000023F8 6605D81F            <1> 	ADD	AX, 2000H-40		; OFFSET TO LOCATION OF ODD ROWS ADJUST
  3682                              <1> R4:					; EVEN_ROW
  3683 000023FC 6696                <1> 	XCHG	SI, AX			; MOVE POINTER TO (SI) AND RECOVER (AX)
  3684 000023FE 81C600800B00        <1> 	add	esi, 0B8000h
  3685 00002404 6689CA              <1> 	MOV	DX, CX			; COLUMN VALUE TO DX
  3686                              <1> 
  3687                              <1> ;-----	DETERMINE GRAPHICS MODE CURRENTLY IN EFFECT
  3688                              <1> 
  3689                              <1> ; SET UP THE REGISTERS ACCORDING TO THE MODE
  3690                              <1> ; CH = MASK FOR LOW OF COLUMN ADDRESS ( 7/3 FOR HIGH/MED RES )
  3691                              <1> ; CL = # OF ADDRESS BITS IN COLUMN VALUE ( 3/2 FOR H/M )
  3692                              <1> ; BL = MASK TO SELECT BITS FROM POINTED BYTE ( 80H/C0H FOR H/M )
  3693                              <1> ; BH = NUMBER OF VALID BITS IN POINTED BYTE ( 1/2 FOR H/M )
  3694                              <1> 
  3695 00002407 66BBC002            <1> 	MOV	BX, 2C0H
  3696 0000240B 66B90203            <1> 	MOV	CX, 302H 		; SET PARMS FOR MED RES
  3697 0000240F 803D[06E90000]06    <1> 	CMP	byte [CRT_MODE], 6
  3698 00002416 7208                <1> 	JC	short R5		; HANDLE IF MED RES
  3699 00002418 66BB8001            <1> 	MOV	BX, 180H
  3700 0000241C 66B90307            <1> 	MOV	CX, 703H 		; SET PARMS FOR HIGH RES
  3701                              <1> 
  3702                              <1> ;-----	DETERMINE BIT OFFSET IN BYTE FROM COLUMN MASK
  3703                              <1> R5:
  3704 00002420 20D5                <1> 	AND	CH, DL			; ADDRESS OF PEL WITHIN BYTE TO CH
  3705                              <1> 
  3706                              <1> ;-----	DETERMINE BYTE OFFSET FOR THIS LOCATION IN COLUMN
  3707                              <1> 
  3708 00002422 66D3EA              <1> 	SHR	DX, CL			; SHIFT BY CORRECT AMOUNT
  3709 00002425 6601D6              <1> 	ADD	SI, DX			; INCREMENT THE POINTER
  3710 00002428 88FE                <1> 	MOV	DH, BH			; GET THE # OF BITS IN RESULT TO DH
  3711                              <1> 
  3712                              <1> ;-----	MULTIPLY BH (VALID BITS IN BYTE) BY CH (BIT OFFSET)
  3713                              <1> 
  3714 0000242A 28C9                <1> 	SUB	CL, CL			; ZERO INTO STORAGE LOCATION
  3715                              <1> R6:
  3716 0000242C D0C8                <1> 	ROR	AL, 1			; LEFT JUSTIFY VALUE IN AL (FOR WRITE)
  3717 0000242E 00E9                <1> 	ADD	CL, CH			; ADD IN THE BIT OFFSET VALUE
  3718 00002430 FECF                <1> 	DEC	BH			; LOOP CONTROL
  3719 00002432 75F8                <1> 	JNZ	short R6		; ON EXIT, CL HAS COUNT TO RESTORE BITS
  3720 00002434 88DC                <1> 	MOV	AH, BL			;  GET MASK TO AH
  3721 00002436 D2EC                <1> 	SHR	AH, CL			;  MOVE THE MASK TO CORRECT LOCATION
  3722 00002438 C3                  <1> 	RETn				;  RETURN WITH EVERYTHING SET UP
  3723                              <1> 
  3724                              <1> load_dac_palette:
  3725                              <1> 	; 29/07/2016
  3726                              <1> 	; 23/07/2016
  3727                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  3728                              <1> 	; (set_mode_vga)
  3729                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3730                              <1> 	; vgabios-0.7a (2011)
  3731                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3732                              <1> 	; 'vgabios.c', 'load_dac_palette'
  3733                              <1> 	;
  3734                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  3735                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  3736                              <1> 	;
  3737                              <1> 	; INPUT -> AH = DAC selection number (3, 2 or 1)
  3738                              <1> 	; OUTPUT -> ECX = 0, AX = 0
  3739                              <1> 	; (Modifed registers: EAX, ECX, EDX, ESI)
  3740                              <1> 	;
  3741 00002439 66BAC803            <1> 	mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  3742 0000243D 28C0                <1> 	sub	al, al ; 0
  3743 0000243F EE                  <1> 	out	dx, al ; 0 ; color index, always 0 at the beginning	
  3744 00002440 6642                <1> 	inc	dx   ; 3C9h ; VGAREG_DAC_DATA
  3745 00002442 B900010000          <1> 	mov	ecx, 256   ; always 256*3 values
  3746                              <1> 	;push	esi
  3747 00002447 88E0                <1> 	mov	al, ah
  3748 00002449 B43F                <1> 	mov	ah, 3Fh	; 3Fh except DAC selection number 3
  3749 0000244B 3C02                <1> 	cmp 	al, 2
  3750 0000244D 7414                <1> 	je	short l_dac_p_2
  3751 0000244F 7719                <1> 	ja	short l_dac_p_3
  3752 00002451 20C0                <1> 	and	al, al
  3753 00002453 7507                <1> 	jnz	short l_dac_p_1
  3754                              <1> l_dac_p_0:
  3755 00002455 BE[20EF0000]        <1> 	mov	esi, palette0
  3756 0000245A EB15                <1> 	jmp	short l_dac_p_4	
  3757                              <1> l_dac_p_1:
  3758 0000245C BE[E0EF0000]        <1> 	mov	esi, palette1
  3759 00002461 EB0E                <1> 	jmp	short l_dac_p_4
  3760                              <1> l_dac_p_2:
  3761 00002463 BE[A0F00000]        <1> 	mov	esi, palette2
  3762 00002468 EB07                <1> 	jmp	short l_dac_p_4
  3763                              <1> l_dac_p_3:
  3764 0000246A B4FF                <1> 	mov	ah, 0FFh ; dac registers
  3765 0000246C BE[60F10000]        <1> 	mov	esi, palette3
  3766                              <1> l_dac_p_4:
  3767 00002471 AC                  <1> 	lodsb
  3768 00002472 EE                  <1> 	out	dx, al  ; Red
  3769 00002473 AC                  <1> 	lodsb
  3770 00002474 EE                  <1> 	out	dx, al	; Green
  3771 00002475 AC                  <1> 	lodsb
  3772 00002476 EE                  <1> 	out	dx, al	; Blue
  3773 00002477 20E4                <1> 	and	ah, ah
  3774 00002479 7405                <1> 	jz	short l_dac_p_5	
  3775 0000247B FECC                <1> 	dec	ah
  3776 0000247D E2F2                <1> 	loop	l_dac_p_4
  3777                              <1> 	;pop	esi
  3778 0000247F C3                  <1> 	retn
  3779                              <1> l_dac_p_5:
  3780                              <1> 	; 29/07/2016
  3781 00002480 FEC9                <1> 	dec	cl
  3782 00002482 7407                <1> 	jz	short l_dac_p_7
  3783                              <1> 	;
  3784 00002484 28C0                <1> 	sub	al, al ; 0
  3785                              <1> l_dac_p_6:
  3786 00002486 EE                  <1> 	out	dx, al ; outb(VGAREG_DAC_DATA,0);
  3787 00002487 EE                  <1> 	out	dx, al
  3788 00002488 EE                  <1> 	out	dx, al
  3789 00002489 E2FB                <1> 	loop	l_dac_p_6
  3790                              <1> l_dac_p_7:
  3791                              <1> 	;pop	esi
  3792 0000248B C3                  <1> 	retn
  3793                              <1> 
  3794                              <1> gray_scale_summing:
  3795                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  3796                              <1> 	; (set_mode_vga)
  3797                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3798                              <1> 	; vgabios-0.7a (2011)
  3799                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3800                              <1> 	; 'vgabios.c', 'biosfn_perform_gray_scale_summing'
  3801                              <1> 	;
  3802                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  3803                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  3804                              <1> 	;
  3805                              <1> 
  3806                              <1> 	; INPUT -> EBX = Start address (color index <= 255)
  3807                              <1> 	;	   ECX = Count (<= 256)
  3808                              <1> 	; OUTPUT -> (E)CX = 0
  3809                              <1> 	; (Modifed registers: EAX, ECX, EDX, EBX)
  3810                              <1> 
  3811 0000248C 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  3812 00002490 EC                  <1> 	in	al, dx
  3813 00002491 30C0                <1> 	xor	al, al ; 0
  3814 00002493 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  3815 00002497 EE                  <1> 	out	dx, al	; clear bit 5
  3816                              <1> 			; (while loading palette registers)
  3817                              <1> 	; set read address and switch to read mode
  3818                              <1> g_s_s_1:
  3819 00002498 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  3820 0000249C 88D8                <1> 	mov	al, bl
  3821 0000249E EE                  <1> 	out	dx, al
  3822                              <1> 	; get 6-bit wide RGB data values
  3823                              <1>  	; intensity = (0.3*Red)+(0.59*Green)+(0.11*Blue)
  3824                              <1> 	; i = ( ( 77*r + 151*g + 28*b ) + 0x80 ) >> 8;
  3825 0000249F 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  3826 000024A3 EC                  <1> 	in	al, dx ; red
  3827 000024A4 B44D                <1> 	mov	ah, 77 ; 0.3* Red
  3828 000024A6 F6E4                <1> 	mul	ah
  3829 000024A8 6650                <1> 	push	ax
  3830 000024AA EC                  <1> 	in	al, dx ; green
  3831 000024AB B497                <1> 	mov	ah, 151  ; 0.59 * Green
  3832 000024AD F6E4                <1> 	mul	ah
  3833 000024AF 6650                <1> 	push	ax
  3834 000024B1 EC                  <1> 	in	al, dx ; blue
  3835 000024B2 B41C                <1> 	mov	ah, 28 ; 0.11 * Blue
  3836 000024B4 F6E4                <1> 	mul	ah
  3837 000024B6 665A                <1> 	pop	dx
  3838 000024B8 6601D0              <1> 	add	ax, dx
  3839 000024BB 665A                <1> 	pop	dx
  3840 000024BD 6601D0              <1> 	add	ax, dx
  3841 000024C0 66058000            <1> 	add	ax, 80h  
  3842 000024C4 B03F                <1> 	mov	al, 3Fh
  3843 000024C6 38C4                <1> 	cmp	ah, al
  3844 000024C8 7602                <1> 	jna	short g_s_s_2
  3845 000024CA 88C4                <1> 	mov	ah, al
  3846                              <1> g_s_s_2:
  3847 000024CC 66BAC803            <1> 	mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  3848 000024D0 88D8                <1> 	mov	al, bl ; color index
  3849 000024D2 EE                  <1> 	out	dx, al
  3850 000024D3 88E0                <1> 	mov	al, ah ; intensity
  3851 000024D5 6642                <1> 	inc	dx ; 3C9h ; VGAREG_DAC_DATA
  3852 000024D7 EE                  <1> 	out	dx, al ; R (R=G=B)
  3853 000024D8 88E0                <1> 	mov	al, ah ; intensity
  3854 000024DA EE                  <1> 	out	dx, al ; G (R=G=B)
  3855 000024DB 88E0                <1>  	mov	al, ah ; intensity
  3856 000024DD EE                  <1> 	out	dx, al ; B (R=G=B)
  3857 000024DE 6649                <1> 	dec	cx
  3858 000024E0 7404                <1> 	jz	short g_s_s_3
  3859 000024E2 FEC3                <1> 	inc	bl    ; next color index value
  3860 000024E4 EBB2                <1> 	jmp	short g_s_s_1
  3861                              <1> g_s_s_3:
  3862 000024E6 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  3863 000024EA EC                  <1> 	in	al, dx
  3864 000024EB B020                <1> 	mov	al, 20h
  3865 000024ED 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  3866 000024F1 EE                  <1> 	out	dx, al ; 20h -> set bit 5
  3867                              <1> 		        ; (after loading palette regs)	
  3868 000024F2 C3                  <1> 	retn
  3869                              <1> 
  3870                              <1> vga_write_char_attr:
  3871                              <1> vga_write_char_only: 
  3872                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  3873                              <1> 	;
  3874                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3875                              <1> 	; vgabios-0.7a (2011)
  3876                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3877                              <1> 	; 'vgabios.c', 'biosfn_write_char_attr'
  3878                              <1> 	; 'biosfn_write_char_only'
  3879                              <1> 
  3880                              <1> 	; INPUT ->
  3881                              <1> 	; [CRT_MODE] = current video mode (>7)
  3882                              <1> 	; CX = Count of characters to write
  3883                              <1> 	; AL = Character to write
  3884                              <1> 	; BL = Color of character
  3885                              <1> 	; OUTPUT ->
  3886                              <1> 	; Regen buffer updated
  3887                              <1>  
  3888 000024F3 8A25[06E90000]      <1> 	mov 	ah, [CRT_MODE]
  3889 000024F9 668B15[E61F0100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  3890                              <1> 
  3891 00002500 BE[22E90000]        <1> 	mov	esi, vga_modes
  3892 00002505 89F7                <1> 	mov	edi, esi
  3893 00002507 83C710              <1> 	add	edi, vga_mode_count
  3894                              <1> vga_wca_0:
  3895 0000250A AC                  <1> 	lodsb
  3896 0000250B 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  3897 0000250D 7405                <1> 	je	short vga_wca_2
  3898 0000250F 39FE                <1> 	cmp	esi, edi
  3899 00002511 72F7                <1> 	jb	short vga_wca_0
  3900                              <1> vga_wca_1:
  3901 00002513 C3                  <1> 	retn	; nothing to do
  3902                              <1> vga_wca_2:
  3903 00002514 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  3904                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  3905                              <1> 
  3906                              <1> 	; biosfn_write_char_attr (car,page,attr,count) 
  3907                              <1> 	; AL = car, page = 0, BL = attr, CX = count
  3908 00002517 803E04              <1> 	cmp	byte [esi], PLANAR4
  3909 0000251A 741D                <1> 	je	short vga_wca_planar
  3910 0000251C 803E03              <1> 	cmp	byte [esi], PLANAR1
  3911 0000251F 7418                <1> 	je	short vga_wca_planar
  3912                              <1> vga_wca_linear8:
  3913                              <1> 	; while((count-->0) && (xcurs<nbcols))
  3914                              <1> 	; CX = count
  3915 00002521 6621C9              <1> 	and	cx, cx
  3916 00002524 74ED                <1> 	jz	short vga_wca_1
  3917 00002526 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS]
  3918 0000252C 73E5                <1> 	jnb	short vga_wca_1
  3919                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  3920                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  3921                              <1> 	; [CRT_COLS] = nbcols
  3922 0000252E E81E000000          <1> 	call	write_gfx_char_lin	 
  3923 00002533 6649                <1> 	dec	cx ; count
  3924 00002535 FEC2                <1> 	inc	dl ; xcurs
  3925 00002537 EBE8                <1> 	jmp	short vga_wca_linear8
  3926                              <1> vga_wca_planar:
  3927                              <1> 	; while((count-->0) && (xcurs<nbcols))
  3928                              <1> 	; CX = count
  3929 00002539 6621C9              <1> 	and	cx, cx
  3930 0000253C 74D5                <1> 	jz	short vga_wca_1
  3931 0000253E 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS]
  3932 00002544 73CD                <1> 	jnb	short vga_wca_1
  3933                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  3934                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  3935                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  3936 00002546 E89D000000          <1> 	call	write_gfx_char_pl4
  3937 0000254B 6649                <1> 	dec	cx ; count
  3938 0000254D FEC2                <1> 	inc	dl ; xcurs
  3939 0000254F EBE8                <1> 	jmp	short vga_wca_planar
  3940                              <1> 
  3941                              <1> write_gfx_char_lin:
  3942                              <1> 	; 08/08/2016
  3943                              <1> 	; 31/07/2016
  3944                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  3945                              <1> 	;
  3946                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3947                              <1> 	; vgabios-0.7a (2011)
  3948                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3949                              <1> 	; 'vgabios.c', 'write_gfx_char_lin'
  3950                              <1> 
  3951                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols)
  3952                              <1> 	; INPUT ->
  3953                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  3954                              <1> 	; [CRT_COLS] = nbcols
  3955                              <1> 	; OUTPUT ->
  3956                              <1> 	; Regen buffer updated
  3957                              <1> 
  3958 00002551 51                  <1> 	push	ecx
  3959 00002552 53                  <1> 	push	ebx
  3960 00002553 52                  <1> 	push	edx
  3961 00002554 50                  <1> 	push	eax
  3962                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  3963                              <1> 	; 08/08/2016
  3964 00002555 0FB6F0              <1> 	movzx	esi, al ; car
  3965 00002558 0FB6C6              <1> 	movzx	eax, dh ; ycurs
  3966 0000255B 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  3967 00002561 F6E4                <1> 	mul	ah
  3968                              <1> 	;shl	ax, 6 ; * 64
  3969 00002563 66C1E003            <1>  	shl	ax, 3 ; * 8
  3970                              <1> 	;sub	dh, dh
  3971                              <1> 	;shl	dx, 3 ; xcurs * 8
  3972                              <1> 	;movzx	edi, dx
  3973 00002567 0FB6FA              <1> 	movzx	edi, dl
  3974 0000256A 66C1E703            <1> 	shl	di, 3 ; xcurs * 8
  3975 0000256E 30F6                <1> 	xor	dh, dh
  3976 00002570 8A15[0AE90000]      <1> 	mov	dl, [CHAR_HEIGHT]
  3977 00002576 66F7E2              <1> 	mul	dx
  3978                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  3979 00002579 01C7                <1> 	add	edi, eax ; addr
  3980 0000257B 81C700000A00        <1> 	add	edi, 0A0000h
  3981                              <1> 	;shl	si, 3 ; car * 8
  3982 00002581 30E4                <1> 	xor	ah, ah
  3983 00002583 A0[0AE90000]        <1> 	mov	al, [CHAR_HEIGHT]
  3984 00002588 66F7E6              <1> 	mul	si
  3985 0000258B 6689C6              <1> 	mov	si, ax
  3986                              <1> 	;; esi = src = car * 8
  3987                              <1> 	; esi = src = car * [CHAR_HEIGHT]
  3988                              <1> 	; i = 0
  3989                              <1> 	;add	esi, vgafont8 ; fdata [src+i]
  3990                              <1> 	; 08/08/2016
  3991 0000258E A1[662D0100]        <1> 	mov	eax, [VGA_INT43H]
  3992 00002593 3D[600A0100]        <1> 	cmp	eax, vgafont16
  3993 00002598 740F                <1>         je      short wgfxl_0
  3994 0000259A 3D[60FC0000]        <1> 	cmp	eax, vgafont14
  3995 0000259F 7408                <1> 	je	short wgfxl_0
  3996 000025A1 81C6[60F40000]      <1> 	add	esi, vgafont8
  3997 000025A7 EB02                <1> 	jmp	short wgfxl_1
  3998                              <1> wgfxl_0:
  3999 000025A9 01C6                <1> 	add	esi, eax
  4000                              <1> wgfxl_1:
  4001 000025AB 28FF                <1> 	sub	bh, bh ; i = 0
  4002                              <1> wgfxl_2:
  4003                              <1> 	; for(i=0;i<8;i++)
  4004 000025AD 57                  <1> 	push	edi ; addr
  4005 000025AE 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  4006 000025B5 F6E7                <1> 	mul	bh ; nbcols*i
  4007 000025B7 66C1E003            <1> 	shl	ax, 3 ; i*nbcols*8
  4008                              <1>  	; dest=addr+i*nbcols*8;
  4009 000025BB 01C7                <1> 	add	edi, eax ; dest + j ; j = 0
  4010 000025BD B180                <1> 	mov	cl, 80h ; mask = 0x80;
  4011                              <1> 	; esi = fdata + src + i
  4012                              <1> 	; for(j=0;j<8;j++)
  4013 000025BF 29D2                <1> 	sub	edx, edx ; j = 0
  4014                              <1> wgfxl_3:
  4015 000025C1 8A06                <1> 	mov	al, [esi] ; al = fdata[src+i]
  4016 000025C3 20C8                <1> 	and	al, cl ; if (fdata[src+i] & mask)
  4017 000025C5 7402                <1> 	jz	short wgfxl_4  ; data = 0, zf = 1
  4018 000025C7 88D8                <1> 	mov	al, bl ; data = attr;
  4019                              <1> wgfxl_4:
  4020                              <1> 	; write_byte(0xa000,dest+j,data);		
  4021 000025C9 AA                  <1> 	stosb  ; dest + j (+ 0A0000h)
  4022                              <1> 	;inc	dl ; j++
  4023                              <1> 	;cmp	dl, 8
  4024 000025CA 80FA07              <1> 	cmp	dl, 7
  4025 000025CD 720E                <1> 	jb	short wgfxl_5
  4026 000025CF 5F                  <1> 	pop	edi
  4027                              <1> 	; 08/08/2016
  4028                              <1> 	;cmp	bh, 7
  4029                              <1> 	;jnb	short wgfxl_6
  4030 000025D0 FEC7                <1> 	inc	bh ; i++
  4031 000025D2 3A3D[0AE90000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  4032 000025D8 7309                <1> 	jnb	short wgfxl_6
  4033 000025DA 46                  <1> 	inc	esi
  4034 000025DB EBD0                <1> 	jmp	short wgfxl_2
  4035                              <1> wgfxl_5:
  4036 000025DD D0E9                <1> 	shr	cl, 1 ; mask >>= 1;
  4037 000025DF FEC2                <1> 	inc	dl ; j++
  4038 000025E1 EBDE                <1>         jmp     short wgfxl_3
  4039                              <1> wgfxl_6:
  4040 000025E3 58                  <1> 	pop	eax
  4041 000025E4 5A                  <1> 	pop	edx
  4042 000025E5 5B                  <1> 	pop	ebx
  4043 000025E6 59                  <1> 	pop	ecx
  4044 000025E7 C3                  <1> 	retn
  4045                              <1> 
  4046                              <1> write_gfx_char_pl4:
  4047                              <1> 	; 08/08/2016
  4048                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  4049                              <1> 	;
  4050                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4051                              <1> 	; vgabios-0.7a (2011)
  4052                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4053                              <1> 	; 'vgabios.c', 'write_gfx_char_pl4'
  4054                              <1> 
  4055                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight)
  4056                              <1> 	; INPUT ->
  4057                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  4058                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  4059                              <1> 	; OUTPUT ->
  4060                              <1> 	; Regen buffer updated
  4061                              <1> 
  4062 000025E8 51                  <1> 	push	ecx
  4063 000025E9 53                  <1> 	push	ebx
  4064 000025EA 52                  <1> 	push	edx
  4065 000025EB 50                  <1> 	push	eax
  4066                              <1> wgfxpl_f0:
  4067                              <1> 	; switch(cheight)
  4068 000025EC 8A25[0AE90000]      <1> 	mov	ah, [CHAR_HEIGHT]
  4069 000025F2 80FC10              <1> 	cmp	ah, 16 ; case 16:
  4070 000025F5 7507                <1> 	jne	short wgfxpl_f1
  4071                              <1> 	; fdata = &vgafont16;
  4072 000025F7 BE[600A0100]        <1> 	mov	esi, vgafont16
  4073 000025FC EB13                <1> 	jmp	short wgfxpl_f3
  4074                              <1> wgfxpl_f1:
  4075 000025FE 80FC0E              <1> 	cmp	ah, 14 ; case 14:
  4076 00002601 7507                <1> 	jne	short wgfxpl_f2
  4077 00002603 BE[60FC0000]        <1> 	mov	esi, vgafont14
  4078 00002608 EB07                <1> 	jmp	short wgfxpl_f3
  4079                              <1> wgfxpl_f2:
  4080                              <1> 	; default:
  4081                              <1> 	;  fdata = &vgafont8;
  4082 0000260A BE[60F40000]        <1> 	mov	esi, vgafont8
  4083 0000260F B408                <1> 	mov	ah, 8	
  4084                              <1> wgfxpl_f3:
  4085                              <1> 	; al = car
  4086 00002611 F6E4                <1> 	mul	ah ; ah = cheight
  4087 00002613 25FFFF0000          <1> 	and	eax, 0FFFFh ; car * cheight
  4088                              <1> 	; src = car * cheight;
  4089 00002618 01C6                <1> 	add	esi, eax ; esi = fdata[src+i]
  4090                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  4091 0000261A 88F0                <1> 	mov	al, dh ; ycurs
  4092 0000261C 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  4093 00002622 F6E4                <1> 	mul	ah
  4094                              <1> 	; 08/08/2016
  4095                              <1> 	;shl	ax, 6 ; * 64
  4096 00002624 66C1E003            <1> 	shl	ax, 3 ; * 8
  4097                              <1> 	;sub	dh, dh ; 0
  4098                              <1> 	;shl	dx, 3 ; xcurs * 8
  4099                              <1> 	;movzx	edi, dx
  4100 00002628 0FB6FA              <1> 	movzx	edi, dl
  4101 0000262B 66C1E703            <1> 	shl	di, 3 ; xcurs * 8
  4102 0000262F 30F6                <1> 	xor	dh, dh
  4103 00002631 8A15[0AE90000]      <1> 	mov	dl, [CHAR_HEIGHT]
  4104 00002637 66F7E2              <1> 	mul	dx
  4105                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  4106 0000263A 01C7                <1> 	add	edi, eax ; addr
  4107 0000263C 81C700000A00        <1> 	add	edi, 0A0000h
  4108                              <1> 	;
  4109                              <1> 	; outw(VGAREG_SEQU_ADDRESS, 0x0f02);
  4110                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  4111 00002642 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4112 00002646 66B8020F            <1> 	mov	ax, 0F02h
  4113 0000264A 66EF                <1> 	out	dx, ax
  4114 0000264C 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4115 00002650 66B80502            <1> 	mov	ax, 0205h
  4116 00002654 66EF                <1> 	out	dx, ax
  4117                              <1> 	;
  4118 00002656 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4119 0000265A F6C380              <1> 	test	bl, 80h ; if(attr&0x80)
  4120 0000265D 7406                <1> 	jz	short wgfxpl_f4 ; else
  4121                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x1803);
  4122 0000265F 66B80318            <1> 	mov	ax, 1803h
  4123 00002663 EB04                <1> 	jmp	short wgfxpl_f5
  4124                              <1> wgfxpl_f4:
  4125                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0003);
  4126 00002665 66B80300            <1> 	mov	ax, 0003h	
  4127                              <1> wgfxpl_f5:
  4128 00002669 66EF                <1> 	out	dx, ax
  4129                              <1> 	;	
  4130 0000266B 28FF                <1> 	sub	bh, bh ; i = 0
  4131                              <1> wgfxpl_0:
  4132                              <1> 	; for(i=0;i<cheight;i++)
  4133 0000266D 57                  <1> 	push	edi ; addr
  4134 0000266E 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  4135 00002675 F6E7                <1> 	mul	bh ; nbcols*i
  4136                              <1> 	; dest=addr+i*nbcols
  4137 00002677 01C7                <1> 	add	edi, eax ; dest
  4138 00002679 B580                <1> 	mov	ch, 80h ; mask = 0x80;
  4139                              <1> 	; for(j=0;j<8;j++)
  4140 0000267B 28C9                <1> 	sub	cl, cl ; j = 0
  4141                              <1> wgfxpl_1:
  4142 0000267D D2ED                <1> 	shr	ch, cl ; mask=0x80>>j;
  4143                              <1> 	;
  4144                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  4145                              <1>      	; read_byte(0xa000,dest);
  4146                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4147 0000267F 88EC                <1> 	mov	ah, ch
  4148 00002681 B008                <1> 	mov	al, 8
  4149 00002683 66EF                <1> 	out	dx, ax
  4150 00002685 8A07                <1> 	mov	al, [edi] ; ? (io delay?)
  4151                              <1> 	;
  4152 00002687 28C0                <1> 	sub	al, al ; attr = 0
  4153                              <1> 	; if (fdata[src+i] & mask)
  4154 00002689 842E                <1> 	test	byte [esi], ch
  4155 0000268B 7404                <1> 	jz	short wgfxpl_2  ; zf = 1
  4156                              <1> 	; write_byte(0xa000,dest,attr&0x0f);
  4157 0000268D 88D8                <1> 	mov	al, bl ; attr;
  4158 0000268F 240F                <1> 	and	al, 0Fh	; attr&0x0f
  4159                              <1> wgfxpl_2:
  4160                              <1> 	; write_byte(0xa000,dest,0x00);		
  4161 00002691 8807                <1> 	mov	[edi], al ; dest (+ 0A0000h)
  4162 00002693 FEC1                <1> 	inc	cl ; j++
  4163 00002695 80F908              <1> 	cmp	cl, 8
  4164 00002698 72E3                <1> 	jb	short wgfxpl_1
  4165 0000269A 5F                  <1> 	pop	edi
  4166                              <1> 	; 08/08/2016
  4167                              <1> 	;cmp	bh, 7
  4168                              <1> 	;jnb	short wgfxpl_3
  4169 0000269B FEC7                <1> 	inc	bh ; i++
  4170 0000269D 3A3D[0AE90000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  4171 000026A3 7303                <1> 	jnb	short wgfxpl_3
  4172 000026A5 46                  <1> 	inc	esi
  4173 000026A6 EBC5                <1> 	jmp	short wgfxpl_0
  4174                              <1> wgfxpl_3:
  4175                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4176 000026A8 66B808FF            <1>   	mov	ax, 0FF08h
  4177 000026AC 66EF                <1> 	out	dx, ax
  4178 000026AE 66B80500            <1> 	mov	ax, 0005h
  4179 000026B2 66EF                <1> 	out	dx, ax
  4180 000026B4 66B80300            <1> 	mov	ax, 0003h
  4181 000026B8 66EF                <1> 	out	dx, ax
  4182                              <1> 	;
  4183 000026BA 58                  <1> 	pop	eax
  4184 000026BB 5A                  <1> 	pop	edx
  4185 000026BC 5B                  <1> 	pop	ebx
  4186 000026BD 59                  <1> 	pop	ecx
  4187 000026BE C3                  <1> 	retn
  4188                              <1> 
  4189                              <1> vga_write_pixel: 
  4190                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4191                              <1> 	;
  4192                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4193                              <1> 	; vgabios-0.7a (2011)
  4194                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4195                              <1> 	; 'vgabios.c', 'biosfn_write_pixel'
  4196                              <1> 
  4197                              <1> 	; INPUT ->
  4198                              <1> 	; 	DX = row (0-239)
  4199                              <1> 	; 	CX = column (0-799)
  4200                              <1> 	; 	AL = pixel value
  4201                              <1> 	;	(AH = [CRT_MODE])
  4202                              <1> 	; OUTPUT ->
  4203                              <1> 	; 	none
  4204                              <1>  
  4205 000026BF 88C3                <1> 	mov	bl, al ; pixel value
  4206                              <1> 	;mov 	ah, [CRT_MODE]
  4207 000026C1 BE[22E90000]        <1> 	mov	esi, vga_modes
  4208 000026C6 89F7                <1> 	mov	edi, esi
  4209 000026C8 83C710              <1> 	add	edi, vga_mode_count
  4210                              <1> vga_wp_0:
  4211 000026CB AC                  <1> 	lodsb
  4212 000026CC 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4213 000026CE 7405                <1> 	je	short vga_wp_1
  4214 000026D0 39FE                <1> 	cmp	esi, edi
  4215 000026D2 72F7                <1> 	jb	short vga_wp_0
  4216 000026D4 C3                  <1> 	retn	; nothing to do
  4217                              <1> vga_wp_1:
  4218 000026D5 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  4219                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4220 000026D8 BF00000A00          <1> 	mov	edi, 0A0000h
  4221                              <1> 	;
  4222 000026DD 803E04              <1> 	cmp	byte [esi], PLANAR4
  4223 000026E0 741D                <1> 	je	short vga_wp_planar
  4224 000026E2 803E03              <1> 	cmp	byte [esi], PLANAR1
  4225 000026E5 7418                <1> 	je	short vga_wp_planar
  4226                              <1> vga_wp_linear8:
  4227                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  4228 000026E7 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4229 000026EE 66C1E003            <1>      	shl	ax, 3 ; * 8
  4230 000026F2 66F7E2              <1> 	mul	dx
  4231 000026F5 50                  <1> 	push	eax
  4232                              <1> 	;mov	edi, 0A0000h
  4233 000026F6 6601CF              <1> 	add	di, cx
  4234 000026F9 58                  <1> 	pop	eax
  4235 000026FA 01C7                <1> 	add	edi, eax ; addr
  4236                              <1> 	; write_byte(0xa000,addr,AL);
  4237 000026FC 881F                <1> 	mov	[edi], bl
  4238 000026FE C3                  <1> 	retn    
  4239                              <1> vga_wp_planar:
  4240                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  4241 000026FF 0FB7C1              <1> 	movzx	eax, cx
  4242 00002702 66C1E803            <1> 	shr	ax, 3 ; CX/8
  4243 00002706 50                  <1> 	push	eax
  4244 00002707 28E4                <1> 	sub	ah, ah ; 0
  4245 00002709 A0[08E90000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4246 0000270E 66F7E2              <1> 	mul	dx
  4247                              <1> 	;mov	edi, 0A0000h
  4248 00002711 6601C7              <1>         add     di, ax
  4249 00002714 58                  <1> 	pop	eax
  4250 00002715 01C7                <1> 	add	edi, eax ; addr
  4251 00002717 80E107              <1> 	and	cl, 7
  4252 0000271A B580                <1> 	mov	ch, 80h ; mask
  4253 0000271C D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  4254                              <1> 	
  4255                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  4256 0000271E 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4257 00002722 88EC                <1> 	mov	ah, ch
  4258 00002724 B008                <1> 	mov	al, 8
  4259 00002726 66EF                <1> 	out	dx, ax
  4260                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  4261 00002728 66B80502            <1> 	mov	ax, 0205h
  4262 0000272C 66EF                <1> 	out	dx, ax
  4263                              <1> 	; data = read_byte(0xa000,addr);
  4264 0000272E 8A07                <1> 	mov	al, [edi] ; (delay?)	
  4265                              <1> 	; if (AL & 0x80)
  4266                              <1> 	; {
  4267                              <1> 	;  outw(VGAREG_GRDC_ADDRESS, 0x1803);
  4268                              <1> 	; }
  4269 00002730 F6C380              <1> 	test	bl, 80h
  4270 00002733 7406                <1> 	jz	short vga_wp_2
  4271 00002735 66B80318            <1> 	mov	ax, 1803h
  4272 00002739 66EF                <1> 	out	dx, ax
  4273                              <1> vga_wp_2:	
  4274                              <1> 	; write_byte(0xa000,addr,AL);
  4275 0000273B 881F                <1> 	mov	[edi], bl
  4276                              <1> 	;
  4277                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4278 0000273D 66B808FF            <1>   	mov	ax, 0FF08h
  4279 00002741 66EF                <1> 	out	dx, ax
  4280 00002743 66B80500            <1> 	mov	ax, 0005h
  4281 00002747 66EF                <1> 	out	dx, ax
  4282 00002749 66B80300            <1> 	mov	ax, 0003h
  4283 0000274D 66EF                <1> 	out	dx, ax
  4284                              <1> 	;
  4285 0000274F C3                  <1> 	retn
  4286                              <1> 
  4287                              <1> vga_read_pixel: 
  4288                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4289                              <1> 	;
  4290                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4291                              <1> 	; vgabios-0.7a (2011)
  4292                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4293                              <1> 	; 'vgabios.c', 'biosfn_read_pixel'
  4294                              <1> 
  4295                              <1> 	; INPUT ->
  4296                              <1> 	; 	DX = row (0-239)
  4297                              <1> 	; 	CX = column (0-799)
  4298                              <1> 	;	(AH = [CRT_MODE])
  4299                              <1> 	; OUTPUT ->
  4300                              <1> 	; 	AL = pixel value
  4301                              <1> 	 
  4302                              <1> 	;mov 	ah, [CRT_MODE]
  4303 00002750 BE[22E90000]        <1> 	mov	esi, vga_modes
  4304 00002755 89F7                <1> 	mov	edi, esi
  4305 00002757 83C710              <1> 	add	edi, vga_mode_count
  4306                              <1> vga_rp_0:
  4307 0000275A AC                  <1> 	lodsb
  4308 0000275B 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4309 0000275D 7405                <1> 	je	short vga_rp_1
  4310 0000275F 39FE                <1> 	cmp	esi, edi
  4311 00002761 72F7                <1> 	jb	short vga_rp_0
  4312 00002763 C3                  <1> 	retn	; nothing to do
  4313                              <1> vga_rp_1:
  4314 00002764 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  4315                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4316 00002767 BF00000A00          <1> 	mov	edi, 0A0000h
  4317                              <1> 	;
  4318 0000276C 803E04              <1> 	cmp	byte [esi], PLANAR4
  4319 0000276F 741D                <1> 	je	short vga_rp_planar
  4320 00002771 803E03              <1> 	cmp	byte [esi], PLANAR1
  4321 00002774 7418                <1> 	je	short vga_rp_planar
  4322                              <1> vga_rp_linear8:
  4323                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  4324 00002776 0FB605[08E90000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4325 0000277D 66C1E003            <1>      	shl	ax, 3 ; * 8
  4326 00002781 66F7E2              <1> 	mul	dx
  4327 00002784 50                  <1> 	push	eax
  4328                              <1> 	;mov	edi, 0A0000h
  4329 00002785 6601CF              <1> 	add	di, cx
  4330 00002788 58                  <1> 	pop	eax
  4331 00002789 01C7                <1> 	add	edi, eax ; addr
  4332                              <1> 	; attr=read_byte(0xa000,addr);
  4333 0000278B 8A07                <1> 	mov	al, [edi] ; pixel value
  4334 0000278D C3                  <1> 	retn    
  4335                              <1> vga_rp_planar:
  4336                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  4337 0000278E 0FB7C1              <1> 	movzx	eax, cx
  4338 00002791 66C1E803            <1> 	shr	ax, 3 ; CX/8
  4339 00002795 50                  <1> 	push	eax
  4340 00002796 28E4                <1> 	sub	ah, ah ; 0
  4341 00002798 A0[08E90000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4342 0000279D 66F7E2              <1> 	mul	dx
  4343                              <1> 	;mov	edi, 0A0000h
  4344 000027A0 6601C7              <1>         add     di, ax
  4345 000027A3 58                  <1> 	pop	eax
  4346 000027A4 01C7                <1> 	add	edi, eax ; addr
  4347 000027A6 80E107              <1> 	and	cl, 7
  4348 000027A9 B580                <1> 	mov	ch, 80h ; mask
  4349 000027AB D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  4350                              <1> 	; attr = 0x00;
  4351 000027AD 30DB                <1> 	xor	bl, bl ; attr = bl = 0, 
  4352 000027AF 30C9                <1> 	xor	cl, cl ; i = cl = 0
  4353                              <1> 	; for(i=0;i<4;i++)
  4354                              <1>       	; {
  4355                              <1>        	;  outw(VGAREG_GRDC_ADDRESS, (i << 8) | 0x04);
  4356                              <1>        	;  data = read_byte(0xa000,addr) & mask;
  4357                              <1>        	;  if (data > 0) attr |= (0x01 << i);
  4358                              <1>       	; }
  4359                              <1> vga_rp_2:
  4360 000027B1 88CC                <1> 	mov	ah, cl ; i << 8
  4361 000027B3 B004                <1> 	mov	al, 4  ; | 0x04
  4362 000027B5 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4363 000027B9 66EF                <1> 	out	dx, ax
  4364                              <1> 	; data = read_byte(0xa000,addr) & mask;
  4365 000027BB 8A07                <1> 	mov	al, [edi]
  4366 000027BD 20E8                <1> 	and	al, ch ; & mask
  4367                              <1> 	; if (data > 0) attr |= (0x01 << i);
  4368 000027BF 08C0                <1> 	or	al, al
  4369 000027C1 7408                <1> 	jz	short vga_rp_3 ; al = 0 
  4370 000027C3 B701                <1> 	mov	bh, 1
  4371 000027C5 D2E7                <1> 	shl	bh, cl ; (0x01 << i)
  4372 000027C7 08FB                <1> 	or	bl, bh ; attr |= (0x01 << i)
  4373 000027C9 88D8                <1> 	mov	al, bl ; pixel value	
  4374                              <1> vga_rp_3:	
  4375 000027CB C3                  <1> 	retn
  4376                              <1> 
  4377                              <1> vga_beeper:
  4378                              <1> 	; 04/08/2016  (TRDOS 386 = TRDOS v2.0)
  4379 000027CC FB                  <1> 	sti
  4380                              <1> 	;mov	bh, [ACTIVE_PAGE]
  4381 000027CD E938F4FFFF          <1>         jmp     beeper_gfx
  4382                              <1> 
  4383                              <1> vga_write_teletype:
  4384                              <1> 	; 06/08/2016
  4385                              <1> 	; 04/08/2016
  4386                              <1> 	; 01/08/2016
  4387                              <1> 	; 31/07/2016
  4388                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4389                              <1> 	;
  4390                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4391                              <1> 	; vgabios-0.7a (2011)
  4392                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4393                              <1> 	; 'vgabios.c', 'biosfn_write_teletype'
  4394                              <1> 	; 'biosfn_write_char_only'
  4395                              <1> 
  4396                              <1> 	; INPUT ->
  4397                              <1> 	; [CRT_MODE] = current video mode (>7)
  4398                              <1> 	; AL = Character to write
  4399                              <1> 	; BL = Color of character
  4400                              <1> 	; OUTPUT ->
  4401                              <1> 	; Regen buffer updated
  4402                              <1> 
  4403                              <1> 	; biosfn_write_teletype (car, page, attr, flag) 
  4404                              <1> 	; car = character (AL)
  4405                              <1> 	; page = 0
  4406                              <1> 	; attr = color (BL)
  4407                              <1> 	; 'flag' not used
  4408                              <1> 
  4409 000027D2 8A25[06E90000]      <1> 	mov 	ah, [CRT_MODE]
  4410 000027D8 88C7                <1> 	mov	bh, al ; character
  4411 000027DA 668B15[E61F0100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  4412                              <1> 
  4413 000027E1 BE[2AE90000]        <1> 	mov	esi, vga_g_modes
  4414 000027E6 89F7                <1> 	mov	edi, esi
  4415 000027E8 83C708              <1> 	add	edi, vga_g_mode_count
  4416                              <1> vga_wtty_0:
  4417 000027EB AC                  <1> 	lodsb
  4418 000027EC 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4419 000027EE 7405                <1> 	je	short vga_wtty_2
  4420 000027F0 39FE                <1> 	cmp	esi, edi
  4421 000027F2 72F7                <1> 	jb	short vga_wtty_0
  4422                              <1> vga_wtty_1:
  4423 000027F4 C3                  <1> 	retn	; nothing to do
  4424                              <1> vga_wtty_2:
  4425 000027F5 80FF07              <1> 	cmp	bh, 07h ; bell (beep)
  4426 000027F8 74D2                <1> 	je	short vga_beeper  ; u11
  4427 000027FA 80FF08              <1> 	cmp	bh, 08h ; backspace
  4428 000027FD 7508                <1> 	jne	short vga_wtty_3
  4429                              <1> 	; if(xcurs>0)xcurs--;
  4430 000027FF 08D2                <1> 	or	dl, dl ; xcurs (column)
  4431 00002801 74F1                <1> 	jz	short vga_wtty_1
  4432 00002803 FECA                <1> 	dec	dl ; xcurs--;
  4433 00002805 EB59                <1>         jmp     short vga_wtty_12 
  4434                              <1> vga_wtty_3:			
  4435 00002807 80FF0D              <1> 	cmp	bh, 0Dh ; carriage return (\r)
  4436 0000280A 7504                <1> 	jne	short vga_wtty_4
  4437                              <1> 	; xcurs=0;
  4438 0000280C 28D2                <1> 	sub	dl, dl ; 0
  4439 0000280E EB50                <1>         jmp     short vga_wtty_12 
  4440                              <1> vga_wtty_4:	
  4441 00002810 80FF0A              <1> 	cmp	bh, 0Ah ; new line (\n)
  4442 00002813 7504                <1> 	jne	short vga_wtty_5
  4443                              <1> 	; ycurs++;
  4444 00002815 FEC6                <1> 	inc	dh ; next row
  4445 00002817 EB62                <1>         jmp     short vga_wtty_11
  4446                              <1> vga_wtty_5:
  4447 00002819 80FF09              <1> 	cmp 	bh, 09h ; tab stop
  4448 0000281C 7527                <1> 	jne	short vga_wtty_8
  4449 0000281E 88D0                <1> 	mov	al, dl
  4450 00002820 6698                <1> 	cbw
  4451 00002822 B108                <1> 	mov	cl, 8
  4452 00002824 F6F1                <1> 	div	cl
  4453 00002826 28E1                <1> 	sub	cl, ah
  4454                              <1> 	;
  4455 00002828 B720                <1> 	mov	bh, 20h ; space
  4456                              <1> vga_wtty_6: ; tab stop loop
  4457 0000282A 6651                <1> 	push	cx
  4458 0000282C 6653                <1> 	push	bx
  4459 0000282E E812000000          <1> 	call	vga_wtty_8
  4460 00002833 665B                <1> 	pop	bx  ; bh = character, bl = color
  4461 00002835 6659                <1> 	pop	cx
  4462 00002837 FEC9                <1> 	dec	cl
  4463 00002839 7409                <1> 	jz	short vga_wtty_7
  4464 0000283B 668B15[E61F0100]    <1> 	mov	dx, [CURSOR_POSN] ; new cursor position (pg 0)
  4465 00002842 EBE6                <1> 	jmp	short vga_wtty_6
  4466                              <1> vga_wtty_7:
  4467 00002844 C3                  <1> 	retn
  4468                              <1> 	;
  4469                              <1> vga_wtty_8:
  4470 00002845 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  4471                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4472 00002848 BF00000A00          <1> 	mov	edi, 0A0000h
  4473                              <1> 	;
  4474 0000284D 88F8                <1> 	mov	al, bh ; character
  4475                              <1> 	;
  4476 0000284F 803E04              <1> 	cmp	byte [esi], PLANAR4
  4477 00002852 7414                <1> 	je	short vga_wtty_planar
  4478 00002854 803E03              <1> 	cmp	byte [esi], PLANAR1
  4479 00002857 740F                <1> 	je	short vga_wtty_planar
  4480                              <1> vga_wtty_linear8:
  4481                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  4482                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  4483                              <1> 	; [CRT_COLS] = nbcols
  4484 00002859 E8F3FCFFFF          <1> 	call	write_gfx_char_lin
  4485 0000285E EB0D                <1> 	jmp	short vga_wtty_9
  4486                              <1> 
  4487                              <1> vga_wtty_12:
  4488                              <1> 	; 09/07/2016
  4489                              <1> 	; set cursor position
  4490                              <1> 	; NOTE: Hardware cursor position will not be set
  4491                              <1> 	;   in any VGA modes (>7)
  4492                              <1> 	;   But, cursor position will be saved into
  4493                              <1> 	;   [CURSOR_POSN].
  4494                              <1> 	;   TRDOS 386 (TRDOS v2.0) uses only one page
  4495                              <1> 	;   (page 0) for all graphics modes.
  4496                              <1> 
  4497 00002860 668915[E61F0100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  4498                              <1> 	; 04/08/2016
  4499                              <1> 	;mov	bh, [ACTIVE_PAGE] ; = 0
  4500                              <1> 	;call	_set_cpos
  4501 00002867 C3                  <1> 	retn
  4502                              <1> 
  4503                              <1> vga_wtty_planar:
  4504                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  4505                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  4506                              <1> 	; [CRT_COLS]= nbcols, [CHAR_HEIGHT] = cheight
  4507 00002868 E87BFDFFFF          <1> 	call	write_gfx_char_pl4
  4508                              <1> vga_wtty_9:
  4509 0000286D FEC2                <1> 	inc	dl ; xcurs++;
  4510                              <1> vga_wtty_10:
  4511                              <1> 	; Do we need to wrap ?
  4512                              <1> 	; if(xcurs==nbcols)
  4513 0000286F 3A15[08E90000]      <1> 	cmp	dl, [CRT_COLS] ; [VGA_COLS]
  4514 00002875 7204                <1> 	jb	short vga_wtty_11 ; no
  4515 00002877 28D2                <1> 	sub	dl, dl ; xcurs=0;
  4516 00002879 FEC6                <1> 	inc	dh ;  ycurs++;
  4517                              <1> vga_wtty_11:
  4518                              <1> 	; Do we need to scroll ?
  4519                              <1> 	; if(ycurs==nbrows)
  4520 0000287B 3A35[0EE90000]      <1> 	cmp	dh, [VGA_ROWS]
  4521 00002881 72DD                <1> 	jb	short vga_wtty_12 ; no
  4522                              <1> 	;
  4523                              <1> 	; biosfn_scroll (nblines,attr,rul,cul,rlr,clr,page,dir)
  4524                              <1> 	; al = nblines = 1, bl = attr (color) = 0
  4525                              <1> 	; ch = rul, cl = cul, dh = rlr, dl = clr, page = 0
  4526                              <1> 	; dir = SCROLL_UP
  4527                              <1> 	
  4528 00002883 B001                <1> 	mov	al, 1
  4529 00002885 28DB                <1> 	sub	bl, bl ; 0 ; blank/black line (attr=0) will be used
  4530 00002887 6629C9              <1> 	sub	cx, cx ; 0,0
  4531                              <1> 
  4532                              <1> 	; 06/08/2016
  4533 0000288A 8A35[0EE90000]      <1> 	mov	dh, [VGA_ROWS]
  4534 00002890 FECE                <1> 	dec	dh ; nbrows -1
  4535                              <1> 
  4536 00002892 6652                <1> 	push	dx 	; 04/08/2016
  4537 00002894 8A15[08E90000]      <1> 	mov	dl, [CRT_COLS]
  4538 0000289A FECA                <1> 	dec	dl ; nbcols -1
  4539                              <1> 	
  4540 0000289C 8A25[06E90000]      <1> 	mov	ah, [CRT_MODE]
  4541                              <1> 	
  4542                              <1> 	; biosfn_scroll(0x01,0x00,0,0,nbrows-1,nbcols-1,page,SCROLL_UP);
  4543 000028A2 E808F5FFFF          <1> 	call	vga_graphics_up
  4544                              <1> 	; 04/08/2016
  4545 000028A7 665A                <1> 	pop	dx
  4546                              <1> 	;dec	dh ; ycurs-=1
  4547 000028A9 EBB5                <1> 	jmp	short vga_wtty_12 
  4548                              <1> 
  4549                              <1> font_setup:
  4550                              <1> 	; 09/07/2016
  4551                              <1> 	; character generator (font loading) functions
  4552                              <1> 	;
  4553                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4554                              <1> 	; vgabios-0.7a (2011)
  4555                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4556                              <1> 	; 'vgabios.c', 'int10_func'
  4557                              <1> 
  4558                              <1> 	; AX = 1100H ; Load User-Defined Font (EGA/VGA)
  4559                              <1> 	;
  4560                              <1>         ; BH    height of each character (bytes per character definition)
  4561                              <1>         ; (BL   font block to load (EGA: 0-3; VGA: 0-7))
  4562                              <1> 	; CX    number of characters to redefine (<=256)
  4563                              <1>         ; DX    ASCII code of the first character defined at ES:BP
  4564                              <1>         ; EBP	address of font-definition information
  4565                              <1> 	;	(in user's memory space)
  4566                              <1> 
  4567                              <1> 	; case 0x11:
  4568                              <1>      	; switch(GET_AL())
  4569                              <1>       	; {
  4570                              <1> 	; case 0x00:
  4571                              <1>         ; case 0x10:
  4572                              <1>         ; biosfn_load_text_user_pat(GET_AL(),ES,BP,CX,DX,GET_BL(),GET_BH());
  4573                              <1>         ; break;
  4574                              <1> 
  4575                              <1> 	; AX = 1110H ; Load and Activate User-Defined Font (EGA/VGA)
  4576 000028AB 08C0                <1> 	or	al, al ; 0
  4577 000028AD 7404                <1> 	jz	short font_setup_0
  4578 000028AF 3C10                <1> 	cmp	al, 10h
  4579 000028B1 7511                <1> 	jne	short font_setup_1	
  4580                              <1> font_setup_0:
  4581 000028B3 E8B7000000          <1> 	call	transfer_user_fonts
  4582 000028B8 721C                <1> 	jc	short font_setup_error
  4583 000028BA E8C2000000          <1> 	call	load_text_user_pat
  4584 000028BF E93CEBFFFF          <1>         jmp     VIDEO_RETURN 
  4585                              <1> font_setup_1:
  4586                              <1> 	; AX = 1101H ; Load ROM 8x14 Character Set (EGA/VGA)
  4587                              <1> 	; case 0x01:
  4588                              <1>         ; case 0x11:
  4589                              <1>         ; biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
  4590                              <1>         ; break;
  4591 000028C4 3C01                <1> 	cmp	al, 1
  4592 000028C6 7404                <1> 	je	short font_setup_2
  4593 000028C8 3C11                <1> 	cmp	al, 11h
  4594 000028CA 7511                <1> 	jne	short font_setup_3	
  4595                              <1> font_setup_2:
  4596                              <1> 	; AX = 1111H ; Load and Activate ROM 8x14 Character Set (EGA/VGA)
  4597                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4598 000028CC E8EE010000          <1> 	call	load_text_8_14_pat
  4599 000028D1 E92AEBFFFF          <1>         jmp     VIDEO_RETURN
  4600                              <1> font_setup_error:
  4601 000028D6 29C0                <1> 	sub	eax, eax ; 0 -> fonts could not be loaded
  4602 000028D8 E928EBFFFF          <1> 	jmp	_video_return
  4603                              <1> font_setup_3:
  4604                              <1> 	; AX = 1102H ; Load ROM 8x8 Character Set (EGA/VGA)
  4605                              <1> 	; case 0x02:
  4606                              <1>         ; case 0x12:
  4607                              <1>         ; biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
  4608                              <1>         ; break;
  4609 000028DD 3C02                <1> 	cmp	al, 2
  4610 000028DF 7404                <1> 	je	short font_setup_4
  4611 000028E1 3C12                <1> 	cmp	al, 12h
  4612 000028E3 750A                <1> 	jne	short font_setup_5	
  4613                              <1> font_setup_4:
  4614                              <1> 	; AX = 1112H ; Load and Activate ROM 8x8 Character Set (EGA/VGA)
  4615                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4616 000028E5 E805020000          <1> 	call	load_text_8_8_pat
  4617 000028EA E911EBFFFF          <1>         jmp     VIDEO_RETURN
  4618                              <1> font_setup_5:
  4619                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set (EGA/VGA)
  4620                              <1> 	; case 0x04:
  4621                              <1>         ; case 0x14:
  4622                              <1>         ; biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
  4623                              <1>         ; break;
  4624 000028EF 3C04                <1> 	cmp	al, 4
  4625 000028F1 7404                <1> 	je	short font_setup_6
  4626 000028F3 3C14                <1> 	cmp	al, 14h
  4627 000028F5 750A                <1> 	jne	short font_setup_7	
  4628                              <1> font_setup_6:
  4629                              <1> 	; AX = 1114H ; Load and Activate ROM 8x16 Character Set (EGA/VGA)
  4630                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4631 000028F7 E823020000          <1> 	call	load_text_8_16_pat
  4632 000028FC E9FFEAFFFF          <1>         jmp     VIDEO_RETURN
  4633                              <1> font_setup_7:
  4634                              <1> 	; Note: AX=1120h (Setup INT 1Fh, EXT_PTR) is not needed
  4635                              <1> 	; for TRDOS 386 (TRDIOS v2.0) video functionality;
  4636                              <1> 	; because, originally EXT_PTR (font address) was used for
  4637                              <1> 	; chars 80h to 0FFh (after the first 128 ASCII char fonts), for
  4638                              <1> 	; CGA graphics mode; currenty, 'vgafont8' address has 256 chars!
  4639                              <1> 	; 
  4640                              <1> 	; case 0x20:
  4641                              <1>         ; biosfn_load_gfx_8_8_chars(ES,BP);
  4642                              <1>         ; break; 
  4643                              <1> 	; case 0x21:
  4644                              <1>         ; biosfn_load_gfx_user_chars(ES,BP,CX,GET_BL(),GET_DL());
  4645                              <1>         ; break;
  4646                              <1> 	; AX = 1121H ; Setup User-Defined Font for Graphics Mode (VGA)
  4647                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  4648                              <1>         ;                        01H = 14 rows
  4649                              <1>         ;                        02H = 25 rows
  4650                              <1>         ;                        03H = 43 rows
  4651                              <1>         ; CX   bytes per character definition
  4652                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  4653                              <1>         ; EBP  address of font-definition information (user's mem space)
  4654                              <1> 
  4655 00002901 3C21                <1> 	cmp	al, 21h
  4656 00002903 751A                <1> 	jne	short font_setup_9
  4657                              <1> 
  4658                              <1> 	; TRDOS 386 modification !
  4659                              <1> 	; dh = 0 -> 256 characters
  4660                              <1> 	; dh = 80h -> 128 characters
  4661                              <1> 	; (If DH <> 0 and DH <> 80h -> invalid)     
  4662 00002905 20F6                <1> 	and	dh, dh
  4663 00002907 7405                <1> 	jz	short font_setup_8 ; 256 characters
  4664 00002909 80FE80              <1> 	cmp	dh, 80h ; 128 characters
  4665 0000290C 75C8                <1> 	jne	short font_setup_error ; invalid !
  4666                              <1> font_setup_8:
  4667 0000290E E85C000000          <1> 	call	transfer_user_fonts
  4668 00002913 72C1                <1> 	jc	short font_setup_error
  4669                              <1> 	; ebp = user's font data address in system's memory space
  4670 00002915 E836020000          <1> 	call	load_gfx_user_chars
  4671 0000291A E9E1EAFFFF          <1>         jmp     VIDEO_RETURN 
  4672                              <1> font_setup_9:
  4673                              <1> 	; case 0x22:
  4674                              <1>         ; biosfn_load_gfx_8_14_chars(GET_BL());
  4675                              <1>         ; break;
  4676 0000291F 3C22                <1> 	cmp	al, 22h
  4677 00002921 750A                <1> 	jne	short font_setup_10
  4678 00002923 E866020000          <1> 	call	load_gfx_8_14_chars	
  4679 00002928 E9D3EAFFFF          <1>         jmp     VIDEO_RETURN 
  4680                              <1> font_setup_10:	
  4681                              <1> 	; case 0x23:
  4682                              <1>         ; biosfn_load_gfx_8_8_dd_chars(GET_BL());
  4683                              <1>         ; break;
  4684 0000292D 3C23                <1> 	cmp	al, 23h
  4685 0000292F 750A                <1> 	jne	short font_setup_11
  4686 00002931 E899020000          <1> 	call	load_gfx_8_8_chars	
  4687 00002936 E9C5EAFFFF          <1>         jmp     VIDEO_RETURN 
  4688                              <1> font_setup_11:	
  4689                              <1> 	; case 0x24:
  4690                              <1>         ; biosfn_load_gfx_8_16_chars(GET_BL());
  4691                              <1>         ; break;
  4692 0000293B 3C24                <1> 	cmp	al, 24h
  4693 0000293D 750A                <1> 	jne	short font_setup_12
  4694 0000293F E8CC020000          <1> 	call	load_gfx_8_16_chars	
  4695 00002944 E9B7EAFFFF          <1>         jmp     VIDEO_RETURN 
  4696                              <1> font_setup_12:
  4697                              <1>  	; case 0x30:
  4698                              <1>         ; biosfn_get_font_info(GET_BH(),&ES,&BP,&CX,&DX);
  4699                              <1>         ; break;
  4700 00002949 3C30                <1> 	cmp	al, 30h
  4701 0000294B 750A                <1> 	jne	short font_setup_13			
  4702 0000294D E8FF020000          <1> 	call	get_font_info
  4703                              <1> 	; eax = return value (info: 4 bytes for 4 parms)
  4704                              <1> 	; eax = 0 -> invalid function (input)
  4705 00002952 E9AEEAFFFF          <1>         jmp     _video_return
  4706                              <1> font_setup_13:
  4707 00002957 3C03                <1> 	cmp	al, 03h ; AX = 1103h	
  4708 00002959 750D                <1> 	jne	short font_setup_14
  4709                              <1> 	; biosfn_set_text_block_specifier:
  4710                              <1> 	; BL = font block selector code	
  4711                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
  4712                              <1> 	; (It is as BL = 0 for TRDOS 386)
  4713 0000295B 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4714                              <1> 	;mov	ah, bl
  4715 0000295F 28E4                <1> 	sub	ah, ah ; 0
  4716                              <1> 	;mov	al, 03h
  4717 00002961 66EF                <1> 	out	dx, ax
  4718 00002963 E998EAFFFF          <1> 	jmp     VIDEO_RETURN 
  4719                              <1> 	
  4720                              <1> font_setup_14:
  4721 00002968 29C0                <1> 	sub	eax, eax ; 0 = invalid function
  4722 0000296A E996EAFFFF          <1>         jmp     _video_return
  4723                              <1> 
  4724                              <1> transfer_user_fonts:
  4725                              <1> 	; 09/07/2016
  4726                              <1> 	;and	ecx, 0FFFFh
  4727                              <1> 	; ECX = byte count
  4728                              <1> 	;push	ecx
  4729 0000296F 89EE                <1> 	mov	esi, ebp ; user buffer
  4730 00002971 BF00000700          <1> 	mov	edi, Cluster_Buffer  ; system buffer
  4731 00002976 E843B00000          <1> 	call	transfer_from_user_buffer
  4732                              <1> 	;pop	ecx
  4733                              <1> 	; ecx = transfer (byte) count = character count
  4734 0000297B BD00000700          <1> 	mov	ebp, Cluster_Buffer
  4735                              <1> 	; jc	VIDEO_RETURN -> failed
  4736 00002980 C3                  <1> 	retn
  4737                              <1> 
  4738                              <1> load_text_user_pat:
  4739                              <1> 	; 26/07/2016
  4740                              <1> 	; 09/07/2016
  4741                              <1> 	; load user defined (EGA/VGA) text fonts
  4742                              <1> 	;
  4743                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4744                              <1> 	; vgabios-0.7a (2011)
  4745                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4746                              <1> 	; 'vgabios.c', 'biosfn_load_text_user_pat'
  4747                              <1> 
  4748                              <1> 	; biosfn_load_text_user_pat (AL,ES,BP,CX,DX,BL,BH)
  4749                              <1> 
  4750                              <1> 	; get_font_access();
  4751                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  4752                              <1> 	; for(i=0;i<CX;i++)
  4753                              <1> 	; {
  4754                              <1> 	;  src = BP + i * BH;
  4755                              <1> 	;  dest = blockaddr + (DX + i) * 32;
  4756                              <1> 	;  memcpyb(0xA000, dest, ES, src, BH);
  4757                              <1> 	; }
  4758                              <1> 	; release_font_access();
  4759                              <1> 	; if(AL>=0x10)
  4760                              <1> 	; {
  4761                              <1> 	; set_scan_lines(BH);
  4762                              <1> 	; }
  4763                              <1> 
  4764 00002981 50                  <1> 	push	eax
  4765 00002982 E83C000000          <1> 	call	get_font_access
  4766 00002987 28DB                <1> 	sub	bl, bl ; i = 0	
  4767                              <1> ltup_1:
  4768 00002989 88D8                <1> 	mov	al, bl
  4769 0000298B F6E7                <1> 	mul	bh
  4770 0000298D 0FB7F0              <1> 	movzx	esi, ax
  4771 00002990 01EE                <1> 	add	esi, ebp
  4772 00002992 88D8                <1> 	mov	al, bl
  4773 00002994 28E4                <1> 	sub	ah, ah
  4774 00002996 6601D0              <1> 	add	ax, dx ; (DX + i)
  4775 00002999 66C1E005            <1> 	shl	ax, 5  ; * 32
  4776 0000299D 0FB7F8              <1> 	movzx	edi, ax
  4777 000029A0 81C700000A00        <1> 	add	edi, 0A0000h
  4778 000029A6 51                  <1> 	push	ecx
  4779 000029A7 0FB6CF              <1> 	movzx	ecx, bh 		
  4780 000029AA F3A4                <1> 	rep	movsb
  4781 000029AC 59                  <1> 	pop	ecx	
  4782 000029AD FEC3                <1> 	inc	bl
  4783 000029AF 38CB                <1> 	cmp	bl, cl
  4784 000029B1 75D6                <1> 	jne	short ltup_1	
  4785                              <1> 	;
  4786 000029B3 E840000000          <1> 	call	release_font_access
  4787                              <1> 	;
  4788 000029B8 58                  <1> 	pop	eax
  4789                              <1> 	; if(AL>=0x10)
  4790 000029B9 3C10                <1> 	cmp	al, 10h
  4791 000029BB 7205                <1> 	jb	short ltup_2
  4792                              <1>    	; set_scan_lines(BH);
  4793 000029BD E875000000          <1> 	call	set_scan_lines
  4794                              <1> ltup_2:
  4795 000029C2 C3                  <1> 	retn
  4796                              <1> 
  4797                              <1> get_font_access:
  4798                              <1> 	; 09/07/2016
  4799                              <1> 	;
  4800                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4801                              <1> 	; vgabios-0.7a (2011)
  4802                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4803                              <1> 	; 'vgabios.c', 'get_font_access'
  4804                              <1> 
  4805                              <1> 	; get_font_access()
  4806 000029C3 52                  <1> 	push	edx
  4807 000029C4 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4808 000029C8 66B80001            <1> 	mov	ax, 0100h
  4809 000029CC 66EF                <1> 	out	dx, ax
  4810 000029CE 66B80204            <1> 	mov	ax, 0402h
  4811 000029D2 66EF                <1> 	out	dx, ax
  4812 000029D4 66B80407            <1> 	mov	ax, 0704h
  4813 000029D8 66EF                <1> 	out	dx, ax
  4814 000029DA 66B80003            <1> 	mov	ax, 0300h
  4815 000029DE 66EF                <1> 	out	dx, ax
  4816 000029E0 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4817 000029E4 66B80402            <1> 	mov	ax, 0204h
  4818 000029E8 66EF                <1> 	out	dx, ax
  4819 000029EA 66B80500            <1> 	mov	ax, 0005h
  4820 000029EE 66EF                <1> 	out	dx, ax
  4821 000029F0 66B80604            <1> 	mov	ax, 0406h
  4822 000029F4 66EF                <1> 	out	dx, ax
  4823 000029F6 5A                  <1> 	pop	edx
  4824 000029F7 C3                  <1> 	retn
  4825                              <1> 
  4826                              <1> release_font_access:
  4827                              <1> 	; 29/07/2016
  4828                              <1> 	; 09/07/2016
  4829                              <1> 	;
  4830                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4831                              <1> 	; vgabios-0.7a (2011)
  4832                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4833                              <1> 	; 'vgabios.c', 'release_font_access'
  4834                              <1> 
  4835 000029F8 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4836 000029FC 66B80001            <1> 	mov	ax, 0100h
  4837 00002A00 66EF                <1> 	out	dx, ax
  4838 00002A02 66B80203            <1> 	mov	ax, 0302h
  4839 00002A06 66EF                <1> 	out	dx, ax
  4840 00002A08 66B80403            <1> 	mov	ax, 0304h
  4841 00002A0C 66EF                <1> 	out	dx, ax
  4842 00002A0E 66B80003            <1> 	mov	ax, 0300h
  4843 00002A12 66EF                <1> 	out	dx, ax
  4844 00002A14 66BACC03            <1> 	mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
  4845 00002A18 EC                  <1>  	in	al, dx
  4846 00002A19 2401                <1> 	and	al, 01h
  4847 00002A1B C0E002              <1> 	shl	al, 2
  4848 00002A1E 0C0A                <1> 	or	al, 0Ah
  4849 00002A20 88C4                <1> 	mov	ah, al
  4850 00002A22 B006                <1> 	mov	al, 06h
  4851 00002A24 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4852 00002A28 66EF                <1> 	out	dx, ax
  4853 00002A2A 66B80400            <1> 	mov	ax, 0004h
  4854 00002A2E 66EF                <1> 	out	dx, ax
  4855 00002A30 66B80510            <1> 	mov	ax, 1005h
  4856 00002A34 66EF                <1> 	out	dx, ax
  4857 00002A36 C3                  <1> 	retn
  4858                              <1> 
  4859                              <1> set_scan_lines:
  4860                              <1> 	; 09/07/2016
  4861                              <1> 	;
  4862                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4863                              <1> 	; vgabios-0.7a (2011)
  4864                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4865                              <1> 	; 'vgabios.c', 'set_scan_lines'
  4866                              <1> 
  4867                              <1> 	; set_scan_lines(lines)
  4868                              <1> 	; BH = lines
  4869                              <1> 
  4870                              <1> 	; outb(crtc_addr, 0x09);
  4871 00002A37 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS = 3D4h (always)
  4872 00002A3B B009                <1> 	mov	al, 09h
  4873 00002A3D EE                  <1> 	out	dx, al
  4874                              <1> 	; crtc_r9 = inb(crtc_addr+1);
  4875 00002A3E 6642                <1> 	inc	dx ; 3D5h
  4876 00002A40 EC                  <1> 	in	al, dx
  4877                              <1> 	; crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1);
  4878 00002A41 24E0                <1> 	and	al, 0E0h
  4879 00002A43 FECF                <1> 	dec	bh ; lines - 1
  4880 00002A45 08F8                <1> 	or	al, bh
  4881                              <1> 	; outb(crtc_addr+1, crtc_r9);
  4882 00002A47 EE                  <1> 	out	dx, al
  4883                              <1> 	;inc	bh 
  4884                              <1> 	; if(lines==8)
  4885                              <1> 	;cmp	bh, 8
  4886 00002A48 80FF07              <1> 	cmp	bh, 7
  4887 00002A4B 7506                <1> 	jne	short ssl_1
  4888                              <1> 	; biosfn_set_cursor_shape(0x06,0x07);
  4889 00002A4D 66B90706            <1> 	mov	cx, 0607h
  4890 00002A51 EB06                <1> 	jmp	short ssl_2
  4891                              <1> ssl_1:
  4892                              <1> 	; biosfn_set_cursor_shape(lines-4,lines-3);
  4893 00002A53 88F9                <1> 	mov	cl, bh ; lines - 1
  4894 00002A55 88CD                <1> 	mov	ch, cl ; lines - 1 (16 -> 15)
  4895 00002A57 FECD                <1> 	dec	ch  ; lines - 2 (16 -> 14)
  4896                              <1> ssl_2:
  4897                              <1> 	; CH = start line, CL = stop line
  4898 00002A59 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  4899 00002A5B 66890D[1FE90000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  4900 00002A62 E87BF1FFFF          <1> 	call	m16	; output cx register
  4901                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, lines);
  4902 00002A67 FEC7                <1> 	inc	bh ; lines
  4903 00002A69 883D[0AE90000]      <1> 	mov	[CHAR_HEIGHT], bh
  4904                              <1> 	;  outb(crtc_addr, 0x12);
  4905 00002A6F 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS
  4906 00002A73 B012                <1> 	mov	al, 12h
  4907 00002A75 EE                  <1> 	out	dx, al
  4908                              <1> 	; vde = inb(crtc_addr+1);
  4909 00002A76 6642                <1> 	inc	dx
  4910 00002A78 EC                  <1> 	in	al, dx
  4911 00002A79 88C4                <1> 	mov	ah, al
  4912                              <1> 	; outb(crtc_addr, 0x07);
  4913 00002A7B 664A                <1> 	dec	dx
  4914 00002A7D B007                <1> 	mov	al, 07h
  4915 00002A7F EE                  <1> 	out	dx, al
  4916                              <1> 	; ovl = inb(crtc_addr+1);
  4917 00002A80 6642                <1> 	inc	dx
  4918 00002A82 EC                  <1> 	in	al, dx
  4919                              <1> 	; vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1);
  4920 00002A83 88E2                <1> 	mov	dl, ah ; vde
  4921 00002A85 88C6                <1> 	mov	dh, al ; ovl
  4922 00002A87 6683E002            <1> 	and	ax, 02h
  4923 00002A8B 66C1E007            <1> 	shl	ax, 7
  4924 00002A8F 6689C1              <1> 	mov	cx, ax ; (ovl & 0x02) << 7)	
  4925 00002A92 88F0                <1> 	mov	al, dh ; ovl
  4926 00002A94 6683E040            <1> 	and	ax, 40h			
  4927 00002A98 66C1E003            <1> 	shl	ax, 3  ; (ovl & 0x40) << 3)
  4928 00002A9C 6640                <1> 	inc	ax ; + 1 
  4929 00002A9E 6601C8              <1> 	add	ax, cx
  4930 00002AA1 30F6                <1> 	xor	dh, dh
  4931 00002AA3 6601D0              <1> 	add	ax, dx ; + vde
  4932                              <1> 	; rows = vde / lines;
  4933 00002AA6 F6F7                <1> 	div	bh
  4934                              <1> 	;dec	al ; rows -1
  4935                              <1> 	; write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, rows-1);
  4936 00002AA8 A2[0EE90000]        <1> 	mov	[VGA_ROWS], al ; rows (not 'rows-1' !)
  4937                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, rows * cols * 2);
  4938 00002AAD 8A25[08E90000]      <1> 	mov	ah, [CRT_COLS]
  4939 00002AB3 F6E4                <1> 	mul	ah
  4940 00002AB5 66D1E0              <1> 	shl	ax, 1
  4941 00002AB8 66A3[542D0100]      <1> 	mov 	[CRT_LEN], ax	
  4942 00002ABE C3                  <1> 	retn
  4943                              <1> 
  4944                              <1> load_text_8_14_pat:
  4945                              <1> 	; 26/07/2016
  4946                              <1> 	; 25/07/2016
  4947                              <1> 	; 23/07/2016
  4948                              <1> 	; 09/07/2016
  4949                              <1> 	; load user defined (EGA/VGA) text fonts
  4950                              <1> 	;
  4951                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4952                              <1> 	; vgabios-0.7a (2011)
  4953                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4954                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_14_pat'
  4955                              <1> 
  4956                              <1> 	; biosfn_load_text_8_14_pat (AL,BL)
  4957                              <1> 
  4958                              <1> 	; get_font_access();
  4959                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  4960                              <1> 	; for(i=0;i<0x100;i++)
  4961                              <1> 	; {
  4962                              <1> 	;  src = i * 14;
  4963                              <1> 	;  dest = blockaddr + i * 32;
  4964                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont14+src, 14);
  4965                              <1> 	; }
  4966                              <1> 	; release_font_access();
  4967                              <1> 	; if(AL>=0x10)
  4968                              <1> 	; {
  4969                              <1> 	; set_scan_lines(14);
  4970                              <1> 	; }
  4971                              <1> 
  4972 00002ABF 50                  <1> 	push	eax
  4973 00002AC0 E8FEFEFFFF          <1> 	call	get_font_access
  4974                              <1> 
  4975                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  4976                              <1> 	;mov	dl, bl
  4977                              <1> 	;and	dl, 3
  4978                              <1> 	;shl	dx, 14
  4979                              <1> 	;xchg	dx, bx
  4980                              <1> 	;and	dl, 4
  4981                              <1> 	;shl	dx, 11
  4982                              <1> 	;add	dx, bx 	
  4983                              <1>  
  4984                              <1> 	;xor	dx, dx  ; blockaddr = 0
  4985                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  4986                              <1> 
  4987 00002AC5 28DB                <1> 	sub	bl, bl ; i = 0
  4988 00002AC7 B70E                <1> 	mov	bh, 14
  4989 00002AC9 BE[60FC0000]        <1> 	mov	esi, vgafont14
  4990 00002ACE BF00000A00          <1> 	mov	edi, 0A0000h		
  4991                              <1> lt8_14_1:
  4992                              <1> 	;mov	al, bl
  4993                              <1> 	;mul	bh
  4994                              <1> 	;movzx	esi, ax
  4995                              <1> 	;add	esi, vgafont14
  4996                              <1> 	;mov	al, bl
  4997                              <1> 	;sub	ah, ah
  4998                              <1> 	;shl	ax, 5 ; * 32
  4999                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5000                              <1> 	;movzx	edi, ax ; dest
  5001                              <1> 	;add	edi, 0A0000h
  5002 00002AD3 0FB6CF              <1> 	movzx	ecx, bh 		
  5003 00002AD6 F3A4                <1> 	rep	movsb
  5004 00002AD8 83C712              <1> 	add	edi, 18 ; 32 - 14
  5005 00002ADB FEC3                <1> 	inc	bl
  5006 00002ADD 75F4                <1> 	jnz	short lt8_14_1	
  5007                              <1> 	;
  5008 00002ADF E814FFFFFF          <1> 	call	release_font_access
  5009                              <1> 	;
  5010 00002AE4 58                  <1> 	pop	eax
  5011                              <1> 	; if(AL>=0x10)
  5012 00002AE5 3C10                <1> 	cmp	al, 10h
  5013 00002AE7 7205                <1> 	jb	short lt8_14_4
  5014                              <1> 	; BH = 14
  5015                              <1>    	; set_scan_lines(14);
  5016 00002AE9 E849FFFFFF          <1> 	call	set_scan_lines
  5017                              <1> lt8_14_4:
  5018 00002AEE C3                  <1> 	retn
  5019                              <1> 
  5020                              <1> load_text_8_8_pat:
  5021                              <1> 	; 26/07/2016
  5022                              <1> 	; 25/07/2016
  5023                              <1> 	; 23/07/2016
  5024                              <1> 	; 09/07/2016
  5025                              <1> 	; load user defined (EGA/VGA) text fonts
  5026                              <1> 	;
  5027                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5028                              <1> 	; vgabios-0.7a (2011)
  5029                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5030                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_8_pat'
  5031                              <1> 
  5032                              <1> 	; biosfn_load_text_8_8_pat (AL,BL)
  5033                              <1> 
  5034                              <1> 	; get_font_access();
  5035                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5036                              <1> 	; for(i=0;i<0x100;i++)
  5037                              <1> 	; {
  5038                              <1> 	;  src = i * 8;
  5039                              <1> 	;  dest = blockaddr + i * 32;
  5040                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont8+src, 8);
  5041                              <1> 	; }
  5042                              <1> 	; release_font_access();
  5043                              <1> 	; if(AL>=0x10)
  5044                              <1> 	; {
  5045                              <1> 	; set_scan_lines(8);
  5046                              <1> 	; }
  5047                              <1> 
  5048 00002AEF 50                  <1> 	push	eax
  5049 00002AF0 E8CEFEFFFF          <1> 	call	get_font_access
  5050                              <1> 
  5051                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5052                              <1> 	;mov	dl, bl
  5053                              <1> 	;and	dl, 3
  5054                              <1> 	;shl	dx, 14
  5055                              <1> 	;xchg	dx, bx
  5056                              <1> 	;and	dl, 4
  5057                              <1> 	;shl	dx, 11
  5058                              <1> 	;add	dx, bx 	
  5059                              <1>  
  5060                              <1> 	;xor	dx, dx  ; blockaddr = 0
  5061                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  5062                              <1> 
  5063 00002AF5 28DB                <1> 	sub	bl, bl ; i = 0
  5064 00002AF7 B708                <1> 	mov	bh, 8
  5065 00002AF9 BE[60F40000]        <1> 	mov	esi, vgafont8
  5066 00002AFE BF00000A00          <1> 	mov	edi, 0A0000h		
  5067                              <1> lt8_8_1:
  5068                              <1> 	;mov	al, bl
  5069                              <1> 	;mul	bh
  5070                              <1> 	;movzx	esi, ax
  5071                              <1> 	;add	esi, vgafont8
  5072                              <1> 	;mov	al, bl
  5073                              <1> 	;sub	ah, ah
  5074                              <1> 	;shl	ax, 5 ; * 32
  5075                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5076                              <1> 	;movzx	edi, ax ; dest
  5077                              <1> 	;add	edi, 0A0000h
  5078 00002B03 0FB6CF              <1> 	movzx	ecx, bh 		
  5079 00002B06 F3A4                <1> 	rep	movsb
  5080 00002B08 83C718              <1> 	add	edi, 24 ; 32 - 8
  5081 00002B0B FEC3                <1> 	inc	bl
  5082 00002B0D 75F4                <1> 	jnz	short lt8_8_1	
  5083                              <1> 	;
  5084 00002B0F E8E4FEFFFF          <1> 	call	release_font_access
  5085                              <1> 	;
  5086 00002B14 58                  <1> 	pop	eax
  5087                              <1> 	; if(AL>=0x10)
  5088 00002B15 3C10                <1> 	cmp	al, 10h
  5089 00002B17 7205                <1> 	jb	short lt8_8_2
  5090                              <1> 	; BH = 8
  5091                              <1>    	; set_scan_lines(8);
  5092 00002B19 E819FFFFFF          <1> 	call	set_scan_lines
  5093                              <1> lt8_8_2:
  5094 00002B1E C3                  <1> 	retn
  5095                              <1> 
  5096                              <1> load_text_8_16_pat:
  5097                              <1> 	; 26/07/2016
  5098                              <1> 	; 25/07/2016
  5099                              <1> 	; 23/07/2016
  5100                              <1> 	; 09/07/2016
  5101                              <1> 	; load user defined (EGA/VGA) text fonts
  5102                              <1> 	;
  5103                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5104                              <1> 	; vgabios-0.7a (2011)
  5105                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5106                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_16_pat'
  5107                              <1> 
  5108                              <1> 	; biosfn_load_text_8_16_pat (AL,BL)
  5109                              <1> 
  5110                              <1> 	; get_font_access();
  5111                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5112                              <1> 	; for(i=0;i<0x100;i++)
  5113                              <1> 	; {
  5114                              <1> 	;  src = i * 16;
  5115                              <1> 	;  dest = blockaddr + i * 32;
  5116                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont16+src, 16);
  5117                              <1> 	; }
  5118                              <1> 	; release_font_access();
  5119                              <1> 	; if(AL>=0x10)
  5120                              <1> 	; {
  5121                              <1> 	; set_scan_lines(16);
  5122                              <1> 	; }
  5123                              <1> 
  5124 00002B1F 50                  <1> 	push	eax
  5125 00002B20 E89EFEFFFF          <1> 	call	get_font_access
  5126                              <1> 
  5127                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5128                              <1> 	;mov	dl, bl
  5129                              <1> 	;and	dl, 3
  5130                              <1> 	;shl	dx, 14
  5131                              <1> 	;xchg	dx, bx
  5132                              <1> 	;and	dl, 4
  5133                              <1> 	;shl	dx, 11
  5134                              <1> 	;add	dx, bx 	
  5135                              <1>  
  5136                              <1> 	;xor	dx, dx  ; blockaddr = 0
  5137                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  5138                              <1> 
  5139 00002B25 28DB                <1> 	sub	bl, bl ; i = 0
  5140 00002B27 B710                <1> 	mov	bh, 16
  5141 00002B29 BE[600A0100]        <1> 	mov	esi, vgafont16
  5142 00002B2E BF00000A00          <1> 	mov	edi, 0A0000h
  5143 00002B33 0FB6C7              <1> 	movzx	eax, bh	
  5144                              <1> lt8_16_1:
  5145                              <1> 	;mov	al, bl
  5146                              <1> 	;mul	bh
  5147                              <1> 	;movzx	esi, ax
  5148                              <1> 	;add	esi, vgafont16
  5149                              <1> 	;mov	al, bl ; i
  5150                              <1> 	;sub	ah, ah
  5151                              <1> 	;shl	ax, 5 ; * 32
  5152                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5153                              <1> 	;movzx	edi, ax ; dest
  5154                              <1> 	;add	edi, 0A0000h
  5155                              <1> 	;movzx	ecx, bh
  5156 00002B36 89C1                <1> 	mov	ecx, eax ; 16	
  5157 00002B38 F3A4                <1> 	rep	movsb
  5158 00002B3A 01C7                <1> 	add	edi, eax ; add edi, 16
  5159 00002B3C FEC3                <1> 	inc	bl
  5160 00002B3E 75F6                <1> 	jnz	short lt8_16_1
  5161                              <1> 	;
  5162 00002B40 E8B3FEFFFF          <1> 	call	release_font_access
  5163                              <1> 	;
  5164 00002B45 58                  <1> 	pop	eax
  5165                              <1> 	; if(AL>=0x10)
  5166 00002B46 3C10                <1> 	cmp	al, 10h
  5167 00002B48 7205                <1> 	jb	short lt8_16_2
  5168                              <1> 	; BH = 16
  5169                              <1>    	; set_scan_lines(16);
  5170 00002B4A E8E8FEFFFF          <1> 	call	set_scan_lines
  5171                              <1> lt8_16_2:
  5172 00002B4F C3                  <1> 	retn
  5173                              <1> 
  5174                              <1> load_gfx_user_chars:
  5175                              <1> 	; 08/08/2016
  5176                              <1> 	; 10/07/2016
  5177                              <1> 	; Setup User-Defined Font for Graphics Mode (VGA)
  5178                              <1> 	;
  5179                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5180                              <1> 	; vgabios-0.7a (2011)
  5181                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5182                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_user_chars'
  5183                              <1> 
  5184                              <1> 	; biosfn_load_gfx_user_chars (ES,BP,CX,BL,DL)
  5185                              <1> 	; /* set 0x43 INT pointer */
  5186                              <1>     	; write_word(0x0, 0x43*4, BP);
  5187                              <1>     	; write_word(0x0, 0x43*4+2, ES);
  5188 00002B50 31C0                <1> 	xor	eax, eax
  5189 00002B52 48                  <1> 	dec	eax ; 0FFFFFFFFh (user defined fonts)
  5190 00002B53 A3[662D0100]        <1> 	mov	[VGA_INT43H], eax
  5191                              <1> 		
  5192                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  5193                              <1>         ;                        01H = 14 rows
  5194                              <1>         ;                        02H = 25 rows
  5195                              <1>         ;                        03H = 43 rows
  5196                              <1>         ; CX   bytes per character definition
  5197                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  5198                              <1> 	; dh = 0 -> 256 characters
  5199                              <1> 	; dh = 80h -> 128 characters
  5200                              <1> 	; (If DH <> 0 and DH <> 80h -> invalid)     	 
  5201                              <1>         ; EBP  address of font-definition information (user's mem space)
  5202                              <1> 
  5203                              <1> 	; switch (BL) {
  5204                              <1> 	; case 0:
  5205                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5206                              <1> 	;    break;
  5207 00002B58 20DB                <1> 	and	bl, bl
  5208 00002B5A 7508                <1> 	jnz	short l_gfx_uc_1
  5209 00002B5C 8815[0EE90000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5210 00002B62 EB23                <1> 	jmp	short l_gfx_uc_4 	
  5211                              <1> l_gfx_uc_1:
  5212                              <1> 	; case 1:
  5213                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5214                              <1> 	;    break;
  5215 00002B64 FECB                <1> 	dec	bl
  5216 00002B66 7509                <1> 	jnz	short l_gfx_uc_2
  5217                              <1> 	; bl = 1
  5218 00002B68 C605[0EE90000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5219 00002B6F EB16                <1> 	jmp	short l_gfx_uc_4 	
  5220                              <1> l_gfx_uc_2:
  5221 00002B71 FECB                <1> 	dec	bl
  5222 00002B73 740B                <1> 	jz	short l_gfx_uc_3 ; bl = 2
  5223 00002B75 FECB                <1> 	dec	bl
  5224 00002B77 750E                <1> 	jnz	short l_gfx_uc_4 ; bl > 3
  5225                              <1> 	; bl = 3
  5226                              <1> 	; case 3:
  5227                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5228                              <1> 	;    break;
  5229 00002B79 C605[0EE90000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5230                              <1> l_gfx_uc_3:
  5231                              <1>     	; case 2:
  5232                              <1>     	; default:
  5233                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5234                              <1> 	;    break;
  5235                              <1> 	; bl = 2 or bl > 3
  5236 00002B80 C605[0EE90000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5237                              <1>     	; }
  5238                              <1> l_gfx_uc_4:
  5239                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, CX);
  5240 00002B87 880D[0AE90000]      <1> 	mov	[CHAR_HEIGHT], cl
  5241                              <1> 	; }
  5242 00002B8D C3                  <1> 	retn	
  5243                              <1> 
  5244                              <1> load_gfx_8_14_chars:
  5245                              <1> 	; 08/08/2016
  5246                              <1> 	; 10/07/2016
  5247                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5248                              <1> 	;
  5249                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5250                              <1> 	; vgabios-0.7a (2011)
  5251                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5252                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_14_chars'
  5253                              <1> 
  5254                              <1> 	; biosfn_load_gfx_8_14_chars (BL)
  5255                              <1> 	; /* set 0x43 INT pointer */
  5256                              <1>     	; write_word(0x0, 0x43*4, &vgafont14);
  5257                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5258 00002B8E C705[662D0100]-     <1> 	mov	dword [VGA_INT43H], vgafont14
  5258 00002B94 [60FC0000]          <1>
  5259                              <1> 		
  5260                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5261                              <1>         ;                         01H = 14 rows
  5262                              <1>         ;                         02H = 25 rows
  5263                              <1>         ;                         03H = 43 rows
  5264                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5265                              <1> 
  5266                              <1> 	; switch (BL) {
  5267                              <1> 	; case 0:
  5268                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5269                              <1> 	;    break;
  5270 00002B98 20DB                <1> 	and	bl, bl
  5271 00002B9A 7508                <1> 	jnz	short l_gfx_8_14c_1
  5272 00002B9C 8815[0EE90000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5273 00002BA2 EB23                <1> 	jmp	short l_gfx_8_14c_4 	
  5274                              <1> l_gfx_8_14c_1:
  5275                              <1> 	; case 1:
  5276                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5277                              <1> 	;    break;
  5278 00002BA4 FECB                <1> 	dec	bl
  5279 00002BA6 7509                <1> 	jnz	short l_gfx_8_14c_2
  5280                              <1> 	; bl = 1
  5281 00002BA8 C605[0EE90000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5282 00002BAF EB16                <1> 	jmp	short l_gfx_8_14c_4 	
  5283                              <1> l_gfx_8_14c_2:
  5284 00002BB1 FECB                <1> 	dec	bl
  5285 00002BB3 740B                <1> 	jz	short l_gfx_8_14c_3 ; bl = 2
  5286 00002BB5 FECB                <1> 	dec	bl
  5287 00002BB7 750E                <1> 	jnz	short l_gfx_8_14c_4 ; bl > 3
  5288                              <1> 	; bl = 3
  5289                              <1> 	; case 3:
  5290                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5291                              <1> 	;    break;
  5292 00002BB9 C605[0EE90000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5293                              <1> l_gfx_8_14c_3:
  5294                              <1>     	; case 2:
  5295                              <1>     	; default:
  5296                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5297                              <1> 	;    break;
  5298                              <1> 	; bl = 2 or bl > 3
  5299 00002BC0 C605[0EE90000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5300                              <1>     	; }
  5301                              <1> l_gfx_8_14c_4:
  5302                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 14);
  5303 00002BC7 C605[0AE90000]0E    <1>         mov     byte [CHAR_HEIGHT], 14
  5304                              <1> 	; }
  5305 00002BCE C3                  <1> 	retn	
  5306                              <1> 
  5307                              <1> load_gfx_8_8_chars:
  5308                              <1> 	; 08/08/2016
  5309                              <1> 	; 10/07/2016
  5310                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5311                              <1> 	;
  5312                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5313                              <1> 	; vgabios-0.7a (2011)
  5314                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5315                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_8_dd_chars'
  5316                              <1> 
  5317                              <1> 	; biosfn_load_gfx_8_8_dd_chars (BL)
  5318                              <1> 	; /* set 0x43 INT pointer */
  5319                              <1>     	; write_word(0x0, 0x43*4, &vgafont8);
  5320                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5321 00002BCF C705[662D0100]-     <1> 	mov	dword [VGA_INT43H], vgafont8
  5321 00002BD5 [60F40000]          <1>
  5322                              <1> 		
  5323                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5324                              <1>         ;                         01H = 14 rows
  5325                              <1>         ;                         02H = 25 rows
  5326                              <1>         ;                         03H = 43 rows
  5327                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5328                              <1> 
  5329                              <1> 	; switch (BL) {
  5330                              <1> 	; case 0:
  5331                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5332                              <1> 	;    break;
  5333 00002BD9 20DB                <1> 	and	bl, bl
  5334 00002BDB 7508                <1> 	jnz	short l_gfx_8_8c_1
  5335 00002BDD 8815[0EE90000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5336 00002BE3 EB23                <1> 	jmp	short l_gfx_8_8c_4 	
  5337                              <1> l_gfx_8_8c_1:
  5338                              <1> 	; case 1:
  5339                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5340                              <1> 	;    break;
  5341 00002BE5 FECB                <1> 	dec	bl
  5342 00002BE7 7509                <1> 	jnz	short l_gfx_8_8c_2
  5343                              <1> 	; bl = 1
  5344 00002BE9 C605[0EE90000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5345 00002BF0 EB16                <1> 	jmp	short l_gfx_8_8c_4 	
  5346                              <1> l_gfx_8_8c_2:
  5347 00002BF2 FECB                <1> 	dec	bl
  5348 00002BF4 740B                <1> 	jz	short l_gfx_8_8c_3 ; bl = 2
  5349 00002BF6 FECB                <1> 	dec	bl
  5350 00002BF8 750E                <1> 	jnz	short l_gfx_8_8c_4 ; bl > 3
  5351                              <1> 	; bl = 3
  5352                              <1> 	; case 3:
  5353                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5354                              <1> 	;    break;
  5355 00002BFA C605[0EE90000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5356                              <1> l_gfx_8_8c_3:
  5357                              <1>     	; case 2:
  5358                              <1>     	; default:
  5359                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5360                              <1> 	;    break;
  5361                              <1> 	; bl = 2 or bl > 3
  5362 00002C01 C605[0EE90000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5363                              <1>     	; }
  5364                              <1> l_gfx_8_8c_4:
  5365                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 8);
  5366 00002C08 C605[0AE90000]08    <1>         mov     byte [CHAR_HEIGHT], 8
  5367                              <1> 	; }
  5368 00002C0F C3                  <1> 	retn
  5369                              <1> 
  5370                              <1> load_gfx_8_16_chars:
  5371                              <1> 	; 08/08/2016
  5372                              <1> 	; 10/07/2016
  5373                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5374                              <1> 	;
  5375                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5376                              <1> 	; vgabios-0.7a (2011)
  5377                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5378                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_16_chars'
  5379                              <1> 
  5380                              <1> 	; biosfn_load_gfx_8_16_chars (BL)
  5381                              <1> 	; /* set 0x43 INT pointer */
  5382                              <1>     	; write_word(0x0, 0x43*4, &vgafont16);
  5383                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5384 00002C10 C705[662D0100]-     <1> 	mov	dword [VGA_INT43H], vgafont16
  5384 00002C16 [600A0100]          <1>
  5385                              <1> 		
  5386                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5387                              <1>         ;                         01H = 14 rows
  5388                              <1>         ;                         02H = 25 rows
  5389                              <1>         ;                         03H = 43 rows
  5390                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5391                              <1> 
  5392                              <1> 	; switch (BL) {
  5393                              <1> 	; case 0:
  5394                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5395                              <1> 	;    break;
  5396 00002C1A 20DB                <1> 	and	bl, bl
  5397 00002C1C 7508                <1> 	jnz	short l_gfx_8_16c_1
  5398 00002C1E 8815[0EE90000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5399 00002C24 EB23                <1> 	jmp	short l_gfx_8_16c_4 	
  5400                              <1> l_gfx_8_16c_1:
  5401                              <1> 	; case 1:
  5402                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5403                              <1> 	;    break;
  5404 00002C26 FECB                <1> 	dec	bl
  5405 00002C28 7509                <1> 	jnz	short l_gfx_8_16c_2
  5406                              <1> 	; bl = 1
  5407 00002C2A C605[0EE90000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5408 00002C31 EB16                <1> 	jmp	short l_gfx_8_16c_4 	
  5409                              <1> l_gfx_8_16c_2:
  5410 00002C33 FECB                <1> 	dec	bl
  5411 00002C35 740B                <1> 	jz	short l_gfx_8_16c_3 ; bl = 2
  5412 00002C37 FECB                <1> 	dec	bl
  5413 00002C39 750E                <1> 	jnz	short l_gfx_8_16c_4 ; bl > 3
  5414                              <1> 	; bl = 3
  5415                              <1> 	; case 3:
  5416                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5417                              <1> 	;    break;
  5418 00002C3B C605[0EE90000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5419                              <1> l_gfx_8_16c_3:
  5420                              <1>     	; case 2:
  5421                              <1>     	; default:
  5422                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5423                              <1> 	;    break;
  5424                              <1> 	; bl = 2 or bl > 3
  5425 00002C42 C605[0EE90000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5426                              <1>     	; }
  5427                              <1> l_gfx_8_16c_4:
  5428                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 16);
  5429 00002C49 C605[0AE90000]10    <1>         mov     byte [CHAR_HEIGHT], 16
  5430                              <1> 	; }
  5431 00002C50 C3                  <1> 	retn
  5432                              <1> 			
  5433                              <1> get_font_info:
  5434                              <1> 	; 08/08/2016
  5435                              <1> 	; 10/07/2016
  5436                              <1> 	; Get Current Character Generator Info (VGA)
  5437                              <1> 	;
  5438                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5439                              <1> 	; vgabios-0.7a (2011)
  5440                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5441                              <1> 	; 'vgabios.c', 'biosfn_get_font_info'
  5442                              <1> 
  5443                              <1> 	; Modified for TRDOS 386 !
  5444                              <1> 	;
  5445                              <1> 	; INPUT ->
  5446                              <1> 	;    AX = 1130h
  5447                              <1> 	;    BL = 0 -> Get info for current VGA font
  5448                              <1> 	;	       (BH = unused)
  5449                              <1> 	;    BL > 0 -> Invalid function (for now!)
  5450                              <1> 	; OUTPUT ->
  5451                              <1> 	;    AL = height (scanlines), bytes per character
  5452                              <1> 	;    AH = screen rows
  5453                              <1> 	;    Byte 16-23 of EAX = number of columns
  5454                              <1> 	;    Byte 24-31 of EAX = 
  5455                              <1> 	;	  0 -> default font (not configured yet)
  5456                              <1> 	;	  0FFh -> user defined font
  5457                              <1> 	;	  14 = vgafont14
  5458                              <1> 	;	   8 = vgafont8
  5459                              <1> 	;	  16 = vgafont16
  5460                              <1> 	;
  5461 00002C51 20DB                <1> 	and	bl, bl
  5462 00002C53 7403                <1> 	jz	short gfi_0
  5463                              <1> 	; invalid function (input)
  5464 00002C55 31C0                <1> 	xor	eax, eax ; 0
  5465 00002C57 C3                  <1> 	retn
  5466                              <1> gfi_0:
  5467 00002C58 A0[0AE90000]        <1> 	mov	al, [CHAR_HEIGHT]
  5468 00002C5D 8A25[0EE90000]      <1> 	mov	ah, [VGA_ROWS]
  5469 00002C63 C1E010              <1> 	shl	eax, 16
  5470 00002C66 A0[08E90000]        <1> 	mov	al, [CRT_COLS]
  5471 00002C6B 8B0D[662D0100]      <1> 	mov	ecx, [VGA_INT43H]
  5472 00002C71 21C9                <1> 	and	ecx, ecx
  5473 00002C73 741E                <1> 	jz	short gfi_2 ; 0 = default font
  5474 00002C75 41                  <1> 	inc	ecx ; 0FFFFFFFFh -> 0 (user defined font)
  5475 00002C76 7504                <1> 	jnz	short gfi_1
  5476 00002C78 FECC                <1> 	dec	ah ; 0FFh
  5477 00002C7A EB17                <1> 	jmp	short gfi_2
  5478                              <1> gfi_1:
  5479 00002C7C 49                  <1> 	dec	ecx ; 08/08/2016
  5480 00002C7D B40E                <1> 	mov	ah, 14
  5481 00002C7F 81F9[60FC0000]      <1> 	cmp	ecx, vgafont14
  5482 00002C85 740C                <1> 	je	short gfi_2
  5483 00002C87 B408                <1> 	mov	ah, 8
  5484 00002C89 81F9[60F40000]      <1> 	cmp	ecx, vgafont8
  5485 00002C8F 7402                <1> 	je	short gfi_2
  5486                              <1> 	; vgafont16
  5487 00002C91 D0E4                <1> 	shl	ah, 1 ; ah = 16
  5488                              <1> gfi_2:
  5489 00002C93 C1C010              <1> 	rol	eax, 16
  5490                              <1> gfi_3:
  5491 00002C96 C3                  <1> 	retn
  5492                              <1> 
  5493                              <1> ; % include 'vidata.s' ; VIDEO DATA
  5494                              <1> 
  5495                              <1> ; /// End Of VIDEO FUNCTIONS ///
  1697                                  
  1698                                  setup_rtc_int:
  1699                                  ; source: http://wiki.osdev.org/RTC
  1700 00002C97 FA                      	cli		; disable interrupts
  1701                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  1702                                  	; in order to change this ...
  1703                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  1704                                  	; (rate must be above 2 and not over 15)
  1705                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  1706 00002C98 B08A                    	mov	al, 8Ah 
  1707 00002C9A E670                    	out	70h, al ; set index to register A, disable NMI
  1708 00002C9C 90                      	nop
  1709 00002C9D E471                    	in	al, 71h ; get initial value of register A
  1710 00002C9F 88C4                    	mov 	ah, al
  1711 00002CA1 80E4F0                  	and	ah, 0F0h
  1712 00002CA4 B08A                    	mov	al, 8Ah 
  1713 00002CA6 E670                    	out	70h, al ; reset index to register A
  1714 00002CA8 88E0                    	mov	al, ah
  1715 00002CAA 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  1716 00002CAC E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  1717                                  	; enable RTC interrupt
  1718 00002CAE B08B                    	mov	al, 8Bh ;
  1719 00002CB0 E670                    	out	70h, al ; select register B and disable NMI
  1720 00002CB2 90                      	nop
  1721 00002CB3 E471                    	in	al, 71h ; read the current value of register B
  1722 00002CB5 88C4                    	mov	ah, al  ;
  1723 00002CB7 B08B                    	mov 	al, 8Bh ;
  1724 00002CB9 E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  1725 00002CBB 88E0                    	mov	al, ah  ;
  1726 00002CBD 0C40                    	or	al, 40h ;
  1727 00002CBF E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  1728 00002CC1 FB                      	sti
  1729 00002CC2 C3                      	retn
  1730                                  
  1731                                  ; Write memory information
  1732                                  ; 29/01/2016
  1733                                  ; 06/11/2014
  1734                                  ; 14/08/2015 
  1735                                  memory_info:	
  1736 00002CC3 A1[CC1F0100]            	mov	eax, [memory_size] ; in pages
  1737 00002CC8 50                      	push	eax
  1738 00002CC9 C1E00C                  	shl	eax, 12		   ; in bytes
  1739 00002CCC BB0A000000              	mov	ebx, 10
  1740 00002CD1 89D9                    	mov	ecx, ebx	   ; 10
  1741 00002CD3 BE[1CEE0000]            	mov	esi, mem_total_b_str	
  1742 00002CD8 E8BD000000              	call	bintdstr
  1743 00002CDD 58                      	pop	eax
  1744 00002CDE B107                    	mov	cl, 7
  1745 00002CE0 BE[40EE0000]            	mov	esi, mem_total_p_str
  1746 00002CE5 E8B0000000              	call	bintdstr	
  1747                                  	; 14/08/2015
  1748 00002CEA E8C8000000              	call	calc_free_mem
  1749                                  	; edx = calculated free pages
  1750                                  	; ecx = 0
  1751 00002CEF A1[D01F0100]            	mov 	eax, [free_pages]
  1752 00002CF4 39D0                    	cmp	eax, edx ; calculated free mem value 
  1753                                  		; and initial free mem value are same or not?
  1754 00002CF6 751D                    	jne 	short pmim ; print mem info with '?' if not
  1755 00002CF8 52                      	push 	edx ; free memory in pages	
  1756                                  	;mov 	eax, edx
  1757 00002CF9 C1E00C                  	shl	eax, 12 ; convert page count
  1758                                  			; to byte count
  1759 00002CFC B10A                    	mov	cl, 10
  1760 00002CFE BE[60EE0000]            	mov	esi, free_mem_b_str
  1761 00002D03 E892000000              	call	bintdstr
  1762 00002D08 58                      	pop	eax
  1763 00002D09 B107                    	mov	cl, 7
  1764 00002D0B BE[84EE0000]            	mov	esi, free_mem_p_str
  1765 00002D10 E885000000              	call	bintdstr
  1766                                  pmim:
  1767 00002D15 BE[0AEE0000]            	mov	esi, msg_memory_info
  1768                                  	;
  1769 00002D1A B407                    	mov	ah, 07h ; Black background, 
  1770                                  			; light gray forecolor
  1771                                  print_kmsg: ; 29/01/2016
  1772 00002D1C 8825[F71F0100]          	mov	[ccolor], ah
  1773                                  pkmsg_loop:
  1774 00002D22 AC                      	lodsb
  1775 00002D23 08C0                    	or	al, al
  1776 00002D25 7410                    	jz	short pkmsg_ok
  1777 00002D27 56                      	push	esi
  1778                                  	; 13/05/2016
  1779 00002D28 0FB61D[F71F0100]        	movzx	ebx, byte [ccolor]
  1780                                  			; Video page 0 (bh=0)
  1781 00002D2F E8EDEDFFFF              	call	_write_tty
  1782 00002D34 5E                      	pop	esi
  1783 00002D35 EBEB                    	jmp	short pkmsg_loop
  1784                                  pkmsg_ok:
  1785 00002D37 C3                      	retn
  1786                                  
  1787                                  ; Convert binary number to hexadecimal string
  1788                                  ; 10/05/2015  
  1789                                  ; dsectpm.s (28/02/2015)
  1790                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  1791                                  ; 01/12/2014
  1792                                  ; 25/11/2014
  1793                                  ;
  1794                                  bytetohex:
  1795                                  	; INPUT ->
  1796                                  	; 	AL = byte (binary number)
  1797                                  	; OUTPUT ->
  1798                                  	;	AX = hexadecimal string
  1799                                  	;
  1800 00002D38 53                      	push	ebx
  1801 00002D39 31DB                    	xor	ebx, ebx
  1802 00002D3B 88C3                    	mov	bl, al
  1803 00002D3D C0EB04                  	shr	bl, 4
  1804 00002D40 8A9B[8A2D0000]          	mov	bl, [ebx+hexchrs] 	 	
  1805 00002D46 86D8                    	xchg	bl, al
  1806 00002D48 80E30F                  	and	bl, 0Fh
  1807 00002D4B 8AA3[8A2D0000]          	mov	ah, [ebx+hexchrs] 
  1808 00002D51 5B                      	pop	ebx	
  1809 00002D52 C3                      	retn
  1810                                  
  1811                                  wordtohex:
  1812                                  	; INPUT ->
  1813                                  	; 	AX = word (binary number)
  1814                                  	; OUTPUT ->
  1815                                  	;	EAX = hexadecimal string
  1816                                  	;
  1817 00002D53 53                      	push	ebx
  1818 00002D54 31DB                    	xor	ebx, ebx
  1819 00002D56 86E0                    	xchg	ah, al
  1820 00002D58 6650                    	push	ax
  1821 00002D5A 88E3                    	mov	bl, ah
  1822 00002D5C C0EB04                  	shr	bl, 4
  1823 00002D5F 8A83[8A2D0000]          	mov	al, [ebx+hexchrs] 	 	
  1824 00002D65 88E3                    	mov	bl, ah
  1825 00002D67 80E30F                  	and	bl, 0Fh
  1826 00002D6A 8AA3[8A2D0000]          	mov	ah, [ebx+hexchrs]
  1827 00002D70 C1E010                  	shl	eax, 16
  1828 00002D73 6658                    	pop	ax
  1829 00002D75 5B                      	pop	ebx
  1830 00002D76 EBC0                    	jmp	short bytetohex
  1831                                  	;mov	bl, al
  1832                                  	;shr	bl, 4
  1833                                  	;mov	bl, [ebx+hexchrs] 	 	
  1834                                  	;xchg	bl, al	 	
  1835                                  	;and	bl, 0Fh
  1836                                  	;mov	ah, [ebx+hexchrs] 
  1837                                  	;pop	ebx	
  1838                                  	;retn
  1839                                  
  1840                                  dwordtohex:
  1841                                  	; INPUT ->
  1842                                  	; 	EAX = dword (binary number)
  1843                                  	; OUTPUT ->
  1844                                  	;	EDX:EAX = hexadecimal string
  1845                                  	;
  1846 00002D78 50                      	push	eax
  1847 00002D79 C1E810                  	shr	eax, 16
  1848 00002D7C E8D2FFFFFF              	call	wordtohex
  1849 00002D81 89C2                    	mov	edx, eax
  1850 00002D83 58                      	pop	eax
  1851 00002D84 E8CAFFFFFF              	call	wordtohex
  1852 00002D89 C3                      	retn
  1853                                  
  1854                                  ; 10/05/2015
  1855                                  hex_digits:
  1856                                  hexchrs:
  1857 00002D8A 303132333435363738-     	db '0123456789ABCDEF'
  1857 00002D93 39414243444546     
  1858                                  
  1859                                  ; Convert binary number to decimal/numeric string
  1860                                  ; 06/11/2014
  1861                                  ; Temporary Code
  1862                                  ;
  1863                                  
  1864                                  bintdstr:
  1865                                  	; EAX = binary number
  1866                                  	; ESI = decimal/numeric string address
  1867                                  	; EBX = divisor (10)
  1868                                  	; ECX = string length (<=10)
  1869 00002D9A 01CE                    	add	esi, ecx
  1870                                  btdstr0:
  1871 00002D9C 4E                      	dec	esi
  1872 00002D9D 31D2                    	xor	edx, edx
  1873 00002D9F F7F3                    	div	ebx
  1874 00002DA1 80C230                  	add	dl, 30h
  1875 00002DA4 8816                    	mov	[esi], dl
  1876 00002DA6 FEC9                    	dec	cl
  1877 00002DA8 740C                    	jz	btdstr2
  1878 00002DAA 09C0                    	or	eax, eax
  1879 00002DAC 75EE                    	jnz	short btdstr0
  1880                                  btdstr1:
  1881 00002DAE 4E                      	dec	esi
  1882 00002DAF C60620                          mov     byte [esi], 20h ; blank space
  1883 00002DB2 FEC9                    	dec	cl
  1884 00002DB4 75F8                    	jnz	short btdstr1
  1885                                  btdstr2:
  1886 00002DB6 C3                      	retn
  1887                                  
  1888                                  ; Calculate free memory pages on M.A.T.
  1889                                  ; 06/11/2014
  1890                                  ; Temporary Code
  1891                                  ;
  1892                                  
  1893                                  calc_free_mem:
  1894 00002DB7 31D2                    	xor	edx, edx
  1895                                  	;xor	ecx, ecx
  1896 00002DB9 668B0D[E01F0100]        	mov	cx, [mat_size] ; in pages
  1897 00002DC0 C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  1898 00002DC3 BE00001000              	mov	esi, MEM_ALLOC_TBL
  1899                                  cfm0:
  1900 00002DC8 AD                      	lodsd
  1901 00002DC9 51                      	push	ecx
  1902 00002DCA B920000000              	mov	ecx, 32
  1903                                  cfm1:
  1904 00002DCF D1E8                    	shr	eax, 1
  1905 00002DD1 7301                    	jnc	short cfm2
  1906 00002DD3 42                      	inc	edx
  1907                                  cfm2:
  1908 00002DD4 E2F9                    	loop	cfm1
  1909 00002DD6 59                      	pop	ecx
  1910 00002DD7 E2EF                    	loop	cfm0
  1911 00002DD9 C3                      	retn
  1912                                  
  1913                                  %include 'diskio.s'  ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskio.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 01/06/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; diskio.inc (22/08/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - DISKIO.INC
    20                              <1> ; Last Modification: 22/08/2015
    21                              <1> ; 	(Initialized Disk Parameters Data is in 'DISKDATA.INC') 
    22                              <1> ; 	(Uninitialized Disk Parameters Data is in 'DISKBSS.INC') 
    23                              <1> 
    24                              <1> ; DISK I/O SYSTEM - Erdogan Tan (Retro UNIX 386 v1 project)
    25                              <1> 
    26                              <1> ; ///////// DISK I/O SYSTEM ///////////////
    27                              <1> 
    28                              <1> ; 06/02/2015
    29                              <1> diskette_io:
    30 00002DDA 9C                  <1> 	pushfd
    31 00002DDB 0E                  <1> 	push 	cs
    32 00002DDC E809000000          <1> 	call 	DISKETTE_IO_1
    33 00002DE1 C3                  <1> 	retn
    34                              <1> 	
    35                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
    36                              <1> ;//////////////////////////////////////////////////////
    37                              <1> 
    38                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
    39                              <1> ; 20/02/2015
    40                              <1> ; 06/02/2015 (unix386.s)
    41                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
    42                              <1> ;
    43                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
    44                              <1> ;
    45                              <1> ; ADISK.EQU
    46                              <1> 
    47                              <1> ;----- Wait control constants 
    48                              <1> 
    49                              <1> ;amount of time to wait while RESET is active.
    50                              <1> 
    51                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
    52                              <1> 						;at 250 KBS xfer rate.
    53                              <1> 						;see INTEL MCS, 1985, pg. 5-456
    54                              <1> 
    55                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
    56                              <1> 						;status register to become valid
    57                              <1> 						;before re-reading.
    58                              <1> 
    59                              <1> ;After sending a byte to NEC, status register may remain
    60                              <1> ;incorrectly set for 24 us.
    61                              <1> 
    62                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
    63                              <1> 						;RQM low.
    64                              <1> 
    65                              <1> ; COMMON.MAC
    66                              <1> ;
    67                              <1> ;	Timing macros
    68                              <1> ;
    69                              <1> 
    70                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
    71                              <1> 		jmp short $+2
    72                              <1> %endmacro		
    73                              <1> 
    74                              <1> %macro		IODELAY  0			; NORMAL IODELAY
    75                              <1> 		jmp short $+2
    76                              <1> 		jmp short $+2
    77                              <1> %endmacro
    78                              <1> 
    79                              <1> %macro		NEWIODELAY 0
    80                              <1> 		out	0ebh,al
    81                              <1> %endmacro 
    82                              <1> 
    83                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
    84                              <1> ;;; WAIT_FOR_MEM
    85                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
    86                              <1> ;WAIT_FDU_INT_HI	equ	1
    87                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
    88                              <1> ;;; WAIT_FOR_PORT
    89                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
    90                              <1> ;WAIT_FDU_SEND_HI	equ	0
    91                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
    92                              <1> ;Time to wait while waiting for each byte of NEC results = .5
    93                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
    94                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
    95                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
    96                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
    97                              <1> ;;; WAIT_REFRESH
    98                              <1> ;amount of time to wait for head settle, per unit in parameter
    99                              <1> ;table = 1 ms.
   100                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
   101                              <1> 
   102                              <1> 
   103                              <1> ; //////////////// DISKETTE I/O ////////////////
   104                              <1> 
   105                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
   106                              <1> 
   107                              <1> ;----------------------------------------
   108                              <1> ;	EQUATES USED BY POST AND BIOS	:
   109                              <1> ;----------------------------------------
   110                              <1> 
   111                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   112                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   113                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
   114                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
   115                              <1> 
   116                              <1> ;----------------------------------------
   117                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
   118                              <1> ;-------------------------------------------------------------------------------
   119                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
   120                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
   121                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
   122                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
   123                              <1> 
   124                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
   125                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
   126                              <1> ;		EQU	011H		; - RESERVED			      ;C
   127                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
   128                              <1> ;		EQU	013H		; - RESERVED			      ;E
   129                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
   130                              <1> 
   131                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
   132                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
   133                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
   134                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
   135                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
   136                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
   137                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
   138                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
   139                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
   140                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
   141                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
   142                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
   143                              <1> 
   144                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
   145                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
   146                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
   147                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
   148                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
   149                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
   150                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
   151                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
   152                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
   153                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
   154                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
   155                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
   156                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
   157                              <1> 
   158                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
   159                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
   160                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
   161                              <1> 
   162                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
   163                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
   164                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
   165                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
   166                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
   167                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
   168                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
   169                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
   170                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
   171                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
   172                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
   173                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
   174                              <1> 
   175                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
   176                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
   177                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
   178                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
   179                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
   180                              <1> 
   181                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
   182                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
   183                              <1> ;INTA00		EQU	020H		; 8259 PORT
   184                              <1> INTA01		EQU	021H		; 8259 PORT
   185                              <1> INTB00		EQU	0A0H		; 2ND 8259
   186                              <1> INTB01		EQU	0A1H		;
   187                              <1> 
   188                              <1> ;-------------------------------------------------------------------------------
   189                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
   190                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
   191                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
   192                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
   193                              <1> ;-------------------------------------------------------------------------------
   194                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
   195                              <1> 
   196                              <1> ;-------------------------------------------------------------------------------
   197                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
   198                              <1> 
   199                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
   200                              <1> ; (unix386.s <-- dsectrm2.s)
   201                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
   202                              <1> 
   203                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
   204                              <1> ; 10/12/2014
   205                              <1> ;
   206                              <1> ;int40h:
   207                              <1> ;	pushf
   208                              <1> ;	push 	cs
   209                              <1> ;	;cli
   210                              <1> ;	call 	DISKETTE_IO_1
   211                              <1> ;	retn
   212                              <1> 
   213                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
   214                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
   215                              <1> ;
   216                              <1> 
   217                              <1> ;-- INT13H ---------------------------------------------------------------------
   218                              <1> ; DISKETTE I/O
   219                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
   220                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
   221                              <1> ; INPUT
   222                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
   223                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
   224                              <1> ;		ON ALL DRIVES
   225                              <1> ;------------------------------------------------------------------------------- 
   226                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
   227                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
   228                              <1> ;-------------------------------------------------------------------------------
   229                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
   230                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   231                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
   232                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
   233                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
   234                              <1> ;		320/360	320/360	    0-39
   235                              <1> ;		320/360	1.2M	    0-39
   236                              <1> ;		1.2M	1.2M	    0-79
   237                              <1> ;		720K	720K	    0-79
   238                              <1> ;		1.44M	1.44M	    0-79	
   239                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
   240                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
   241                              <1> ;		320/360	320/360	     1-8/9
   242                              <1> ;		320/360	1.2M	     1-8/9
   243                              <1> ;		1.2M	1.2M	     1-15
   244                              <1> ;		720K	720K	     1-9
   245                              <1> ;		1.44M	1.44M	     1-18		
   246                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
   247                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
   248                              <1> ;		320/360	320/360	        8/9
   249                              <1> ;		320/360	1.2M	        8/9
   250                              <1> ;		1.2M	1.2M		15
   251                              <1> ;		720K	720K		9
   252                              <1> ;		1.44M	1.44M		18
   253                              <1> ;
   254                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
   255                              <1> ;
   256                              <1> ;-------------------------------------------------------------------------------
   257                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
   258                              <1> ;-------------------------------------------------------------------------------
   259                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
   260                              <1> ;-------------------------------------------------------------------------------
   261                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
   262                              <1> ;-------------------------------------------------------------------------------
   263                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
   264                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
   265                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
   266                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
   267                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
   268                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
   269                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
   270                              <1> ;		READ/WRITE ACCESS.
   271                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
   272                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
   273                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
   274                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
   275                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
   276                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
   277                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
   278                              <1> ;
   279                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
   280                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
   281                              <1> ;		---------------------------------------------
   282                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
   283                              <1> ;		---------------------------------------------
   284                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
   285                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
   286                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
   287                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
   288                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
   289                              <1> ;		---------------------------------------------
   290                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
   291                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
   292                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
   293                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
   294                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
   295                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
   296                              <1> ;-------------------------------------------------------------------------------
   297                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
   298                              <1> ;	REGISTERS
   299                              <1> ;	  INPUT
   300                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   301                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
   302                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
   303                              <1> ;	  OUTPUT
   304                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
   305                              <1> ; 	    *** TRDOS 386 note: floppy disk parameter table (16 bytes)
   306                              <1> ;	    will be returned to user in EBX, buffer address *** 27/05/2016 ***		
   307                              <1> ;					
   308                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
   309                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   310                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   311                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
   312                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
   313                              <1> ;	    (BH) - 0
   314                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
   315                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
   316                              <1> ;	    (AX) - 0
   317                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
   318                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
   319                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
   320                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
   321                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
   322                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
   323                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
   324                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
   325                              <1> ;-------------------------------------------------------------------------------
   326                              <1> ;	(AH)= 15H  READ DASD TYPE
   327                              <1> ;	OUTPUT REGISTERS
   328                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
   329                              <1> ;		00 - DRIVE NOT PRESENT	
   330                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
   331                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
   332                              <1> ;		03 - RESERVED (FIXED DISK)
   333                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   334                              <1> ;-------------------------------------------------------------------------------
   335                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
   336                              <1> ;	OUTPUT REGISTERS
   337                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
   338                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
   339                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   340                              <1> ;-------------------------------------------------------------------------------
   341                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
   342                              <1> ;	INPUT REGISTERS
   343                              <1> ;	(AL) -	00 - NOT USED	
   344                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
   345                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
   346                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
   347                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
   348                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
   349                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
   350                              <1> ;-------------------------------------------------------------------------------
   351                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
   352                              <1> ;	INPUT REGISTERS
   353                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
   354                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   355                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   356                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
   357                              <1> ;	OUTPUT REGISTERS:
   358                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
   359                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
   360                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
   361                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
   362                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
   363                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
   364                              <1> ;-------------------------------------------------------------------------------
   365                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
   366                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
   367                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
   368                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
   369                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
   370                              <1> ;		CHANGE ERROR CODE
   371                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
   372                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
   373                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
   374                              <1> ;
   375                              <1> ; DATA VARIABLE -- @DISK_POINTER
   376                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
   377                              <1> ;-------------------------------------------------------------------------------
   378                              <1> ; OUTPUT FOR ALL FUNCTIONS
   379                              <1> ;	AH = STATUS OF OPERATION
   380                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
   381                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
   382                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
   383                              <1> ;		TYPE AH=(15)).
   384                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
   385                              <1> ;	FOR READ/WRITE/VERIFY
   386                              <1> ;		DS,BX,DX,CX PRESERVED
   387                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
   388                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
   389                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
   390                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
   391                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
   392                              <1> ;-------------------------------------------------------------------------------
   393                              <1> ;
   394                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
   395                              <1> ;
   396                              <1> ;   -----------------------------------------------------------------
   397                              <1> ;   |       |       |       |       |       |       |       |       |
   398                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
   399                              <1> ;   |       |       |       |       |       |       |       |       |
   400                              <1> ;   -----------------------------------------------------------------
   401                              <1> ;	|	|	|	|	|	|	|	|
   402                              <1> ;	|	|	|	|	|	-----------------
   403                              <1> ;	|	|	|	|	|		|
   404                              <1> ;	|	|	|	|    RESERVED		|
   405                              <1> ;	|	|	|	|		  PRESENT STATE
   406                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
   407                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
   408                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
   409                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
   410                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
   411                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
   412                              <1> ;	|	|	|	|	110: RESERVED
   413                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
   414                              <1> ;	|	|	|	|
   415                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
   416                              <1> ;	|	|	|
   417                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
   418                              <1> ;	|	|			DRIVE)
   419                              <1> ;	|	|
   420                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
   421                              <1> ;
   422                              <1> ;						00: 500 KBS
   423                              <1> ;						01: 300 KBS
   424                              <1> ;						10: 250 KBS
   425                              <1> ;						11: RESERVED
   426                              <1> ;
   427                              <1> ;
   428                              <1> ;-------------------------------------------------------------------------------
   429                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
   430                              <1> ;-------------------------------------------------------------------------------
   431                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
   432                              <1> ;-------------------------------------------------------------------------------
   433                              <1> 
   434                              <1> struc MD
   435 00000000 <res 00000001>      <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   436 00000001 <res 00000001>      <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   437 00000002 <res 00000001>      <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   438 00000003 <res 00000001>      <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
   439 00000004 <res 00000001>      <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
   440 00000005 <res 00000001>      <1> 	.GAP		resb	1	; GAP LENGTH
   441 00000006 <res 00000001>      <1> 	.DTL		resb	1	; DTL
   442 00000007 <res 00000001>      <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
   443 00000008 <res 00000001>      <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
   444 00000009 <res 00000001>      <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
   445 0000000A <res 00000001>      <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
   446 0000000B <res 00000001>      <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
   447 0000000C <res 00000001>      <1> 	.RATE		resb	1	; DATA TRANSFER RATE
   448                              <1> endstruc
   449                              <1> 
   450                              <1> BIT7OFF	EQU	7FH
   451                              <1> BIT7ON	EQU	80H
   452                              <1> 
   453                              <1> ;;int13h: ; 16/02/2015
   454                              <1> ;; 16/02/2015 - 21/02/2015
   455                              <1> int40h:
   456 00002DE2 9C                  <1> 	pushfd
   457 00002DE3 0E                  <1> 	push 	cs
   458 00002DE4 E801000000          <1> 	call 	DISKETTE_IO_1
   459 00002DE9 C3                  <1> 	retn	
   460                              <1> 
   461                              <1> DISKETTE_IO_1:
   462                              <1> 
   463 00002DEA FB                  <1> 	STI				; INTERRUPTS BACK ON
   464 00002DEB 55                  <1> 	PUSH	eBP			; USER REGISTER
   465 00002DEC 57                  <1> 	PUSH	eDI			; USER REGISTER
   466 00002DED 52                  <1> 	PUSH	eDX			; HEAD #, DRIVE # OR USER REGISTER
   467 00002DEE 53                  <1> 	PUSH	eBX			; BUFFER OFFSET PARAMETER OR REGISTER
   468 00002DEF 51                  <1> 	PUSH	eCX			; TRACK #-SECTOR # OR USER REGISTER
   469 00002DF0 89E5                <1> 	MOV	eBP,eSP			; BP     => PARAMETER LIST DEP. ON AH
   470                              <1> 					; [BP]   = SECTOR #
   471                              <1> 					; [BP+1] = TRACK #
   472                              <1> 					; [BP+2] = BUFFER OFFSET
   473                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
   474                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
   475                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
   476                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
   477                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
   478                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
   479                              <1> 					; BH/[BP+3] = 0
   480                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
   481                              <1> 					; DH/[BP+5] = MAX HEAD #
   482                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
   483 00002DF2 06                  <1> 	push	es ; 06/02/2015	
   484 00002DF3 1E                  <1> 	PUSH	DS			; BUFFER SEGMENT PARM OR USER REGISTER
   485 00002DF4 56                  <1> 	PUSH	eSI			; USER REGISTERS
   486                              <1> 	;CALL	DDS			; SEGMENT OF BIOS DATA AREA TO DS
   487                              <1> 	;mov	cx, cs
   488                              <1> 	;mov	ds, cx
   489 00002DF5 66B91000            <1> 	mov	cx, KDATA
   490 00002DF9 8ED9                <1>         mov     ds, cx
   491 00002DFB 8EC1                <1>         mov     es, cx
   492                              <1> 
   493                              <1> 	;CMP	AH,(FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
   494 00002DFD 80FC19              <1> 	cmp	ah,(FNC_TAE-FNC_TAB)/4  ; 18/02/2015
   495 00002E00 7202                <1> 	JB	short OK_FUNC		; FUNCTION OK
   496 00002E02 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
   497                              <1> OK_FUNC:
   498 00002E04 80FC01              <1> 	CMP	AH,1			; RESET OR STATUS ?
   499 00002E07 760C                <1> 	JBE	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
   500 00002E09 80FC08              <1> 	CMP	AH,8			; READ DRIVE PARMS ?
   501 00002E0C 7407                <1> 	JZ	short OK_DRV		; IF SO DRIVE CHECKED LATER
   502 00002E0E 80FA01              <1> 	CMP	DL,1			; DRIVES 0 AND 1 OK
   503 00002E11 7602                <1> 	JBE	short OK_DRV		; IF 0 OR 1 THEN JUMP
   504 00002E13 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
   505                              <1> OK_DRV:
   506 00002E15 31C9                <1> 	xor	ecx, ecx
   507                              <1> 	;mov	esi, ecx ; 08/02/2015
   508 00002E17 89CF                <1> 	mov	edi, ecx ; 08/02/2015
   509 00002E19 88E1                <1> 	MOV	CL,AH			; CL = FUNCTION
   510                              <1> 	;XOR	CH,CH			; CX = FUNCTION
   511                              <1> 	;SHL	CL, 1			; FUNCTION TIMES 2
   512 00002E1B C0E102              <1> 	SHL	CL, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
   513 00002E1E BB[562E0000]        <1> 	MOV	eBX,FNC_TAB		; LOAD START OF FUNCTION TABLE
   514 00002E23 01CB                <1> 	ADD	eBX,eCX			; ADD OFFSET INTO TABLE => ROUTINE
   515 00002E25 88F4                <1> 	MOV	AH,DH			; AX = HEAD #,# OF SECTORS OR DASD TYPE
   516 00002E27 30F6                <1> 	XOR	DH,DH			; DX = DRIVE #
   517 00002E29 6689C6              <1> 	MOV	SI,AX			; SI = HEAD #,# OF SECTORS OR DASD TYPE
   518 00002E2C 6689D7              <1> 	MOV     DI,DX                   ; DI = DRIVE #
   519                              <1> 	;
   520                              <1> 	; 11/12/2014
   521 00002E2F 8815[0BED0000]      <1>         mov     [cfd], dl               ; current floppy drive (for 'GET_PARM')        
   522                              <1> 	;
   523 00002E35 8A25[50200100]      <1> 	MOV	AH, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
   524 00002E3B C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; INITIALIZE FOR ALL OTHERS
   525                              <1> 
   526                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
   527                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
   528                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
   529                              <1> ;
   530                              <1> ;		DI	: DRIVE #
   531                              <1> ;		SI-HI	: HEAD #
   532                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
   533                              <1> ;		ES	: BUFFER SEGMENT
   534                              <1> ;		[BP]	: SECTOR #
   535                              <1> ;		[BP+1]	: TRACK #
   536                              <1> ;		[BP+2]	: BUFFER OFFSET
   537                              <1> ;
   538                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
   539                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
   540                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
   541                              <1> ;	SPECIFIC ERROR CODE.
   542                              <1> ;
   543                              <1> 					; (AH) = @DSKETTE_STATUS
   544 00002E42 FF13                <1> 	CALL	dWORD [eBX]		; CALL THE REQUESTED FUNCTION
   545 00002E44 5E                  <1> 	POP	eSI			; RESTORE ALL REGISTERS
   546 00002E45 1F                  <1> 	POP	DS
   547 00002E46 07                  <1> 	pop	es	; 06/02/2015
   548 00002E47 59                  <1> 	POP	eCX
   549 00002E48 5B                  <1> 	POP	eBX
   550 00002E49 5A                  <1> 	POP	eDX
   551 00002E4A 5F                  <1> 	POP	eDI
   552 00002E4B 89E5                <1> 	MOV	eBP, eSP
   553 00002E4D 50                  <1> 	PUSH	eAX
   554 00002E4E 9C                  <1> 	PUSHFd
   555 00002E4F 58                  <1> 	POP	eAX
   556                              <1> 	;MOV	[BP+6], AX
   557 00002E50 89450C              <1> 	mov	[ebp+12], eax  ; 18/02/2015, flags
   558 00002E53 58                  <1> 	POP	eAX
   559 00002E54 5D                  <1> 	POP	eBP
   560 00002E55 CF                  <1> 	IRETd
   561                              <1> 
   562                              <1> ;-------------------------------------------------------------------------------
   563                              <1> ; DW --> dd (06/02/2015)
   564 00002E56 [BA2E0000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
   565 00002E5A [332F0000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
   566 00002E5E [442F0000]          <1> 	dd	DSK_READ		; AH = 02H; READ
   567 00002E62 [552F0000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
   568 00002E66 [662F0000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
   569 00002E6A [772F0000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
   570 00002E6E [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
   571 00002E72 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
   572 00002E76 [09300000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
   573 00002E7A [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
   574 00002E7E [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
   575 00002E82 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
   576 00002E86 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
   577 00002E8A [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
   578 00002E8E [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
   579 00002E92 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
   580 00002E96 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
   581 00002E9A [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
   582 00002E9E [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
   583 00002EA2 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
   584 00002EA6 [FC2F0000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
   585 00002EAA [E1300000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
   586 00002EAE [0C310000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
   587 00002EB2 [46310000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
   588 00002EB6 [C9310000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
   589                              <1> FNC_TAE EQU     $                       ; END
   590                              <1> 
   591                              <1> ;-------------------------------------------------------------------------------
   592                              <1> ; DISK_RESET	(AH = 00H)	
   593                              <1> ;		RESET THE DISKETTE SYSTEM.
   594                              <1> ;
   595                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   596                              <1> ;-------------------------------------------------------------------------------
   597                              <1> DSK_RESET:
   598 00002EBA 66BAF203            <1> 	MOV	DX,03F2H		; ADAPTER CONTROL PORT
   599 00002EBE FA                  <1> 	CLI				; NO INTERRUPTS
   600 00002EBF A0[4E200100]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
   601 00002EC4 243F                <1> 	AND	AL,00111111B		; KEEP SELECTED AND MOTOR ON BITS
   602 00002EC6 C0C004              <1> 	ROL	AL,4			; MOTOR VALUE TO HIGH NIBBLE
   603                              <1> 					; DRIVE SELECT TO LOW NIBBLE
   604 00002EC9 0C08                <1> 	OR	AL,00001000B		; TURN ON INTERRUPT ENABLE
   605 00002ECB EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
   606 00002ECC C605[4D200100]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
   607                              <1> 	;JMP	$+2			; WAIT FOR I/O
   608                              <1> 	;JMP	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
   609                              <1> 					;      PULSE WIDTH)
   610                              <1> 	; 19/12/2014
   611                              <1> 	NEWIODELAY
   611 00002ED3 E6EB                <2>  out 0ebh,al
   612                              <1> 
   613                              <1> 	; 17/12/2014 
   614                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
   615 00002ED5 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
   616                              <1> wdw1:
   617                              <1> 	NEWIODELAY   ; 27/02/2015
   617 00002EDA E6EB                <2>  out 0ebh,al
   618 00002EDC E2FC                <1> 	loop	wdw1
   619                              <1> 	;
   620 00002EDE 0C04                <1> 	OR	AL,00000100B		; TURN OFF RESET BIT
   621 00002EE0 EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
   622                              <1> 	; 16/12/2014
   623                              <1> 	IODELAY
   623 00002EE1 EB00                <2>  jmp short $+2
   623 00002EE3 EB00                <2>  jmp short $+2
   624                              <1> 	;
   625                              <1> 	;STI				; ENABLE THE INTERRUPTS
   626 00002EE5 E83C0C0000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
   627 00002EEA 723E                <1> 	JC	short DR_ERR		; IF ERROR, RETURN IT
   628 00002EEC 66B9C000            <1> 	MOV	CX,11000000B		; CL = EXPECTED @NEC_STATUS
   629                              <1> NXT_DRV:
   630 00002EF0 6651                <1> 	PUSH	CX			; SAVE FOR CALL
   631 00002EF2 B8[282F0000]        <1> 	MOV	eAX, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
   632 00002EF7 50                  <1> 	PUSH	eAX			; "
   633 00002EF8 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
   634 00002EFA E81A0B0000          <1> 	CALL	NEC_OUTPUT
   635 00002EFF 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
   636 00002F00 E8510C0000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
   637 00002F05 6659                <1> 	POP	CX			; RESTORE AFTER CALL
   638 00002F07 7221                <1> 	JC	short DR_ERR		; ERROR RETURN
   639 00002F09 3A0D[51200100]      <1> 	CMP	CL, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
   640 00002F0F 7519                <1> 	JNZ	short DR_ERR		; EVERYTHING OK
   641 00002F11 FEC1                <1> 	INC	CL			; NEXT EXPECTED @NEC_STATUS
   642 00002F13 80F9C3              <1> 	CMP	CL,11000011B		; ALL POSSIBLE DRIVES CLEARED
   643 00002F16 76D8                <1> 	JBE	short NXT_DRV		; FALL THRU IF 11000100B OR >
   644                              <1> 	;
   645 00002F18 E869030000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
   646                              <1> RESBAC:
   647 00002F1D E81D090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   648 00002F22 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   649 00002F25 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   650 00002F27 C3                  <1> 	RETn		
   651                              <1> DR_POP_ERR:
   652 00002F28 6659                <1> 	POP	CX			; CLEAR STACK
   653                              <1> DR_ERR:
   654 00002F2A 800D[50200100]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; SET ERROR CODE
   655 00002F31 EBEA                <1> 	JMP	SHORT RESBAC		; RETURN FROM RESET
   656                              <1> 
   657                              <1> ;-------------------------------------------------------------------------------
   658                              <1> ; DISK_STATUS	(AH = 01H)
   659                              <1> ;	DISKETTE STATUS.
   660                              <1> ;
   661                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
   662                              <1> ;
   663                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
   664                              <1> ;-------------------------------------------------------------------------------
   665                              <1> DSK_STATUS:
   666 00002F33 8825[50200100]      <1> 	MOV	[DSKETTE_STATUS],AH	; PUT BACK FOR SETUP END
   667 00002F39 E801090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   668 00002F3E 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   669 00002F41 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   670 00002F43 C3                  <1> 	RETn		
   671                              <1> 
   672                              <1> ;-------------------------------------------------------------------------------
   673                              <1> ; DISK_READ	(AH = 02H)	
   674                              <1> ;	DISKETTE READ.
   675                              <1> ;
   676                              <1> ; ON ENTRY:	DI	: DRIVE #
   677                              <1> ;		SI-HI	: HEAD #
   678                              <1> ;		SI-LOW	: # OF SECTORS
   679                              <1> ;		ES	: BUFFER SEGMENT
   680                              <1> ;		[BP]	: SECTOR #
   681                              <1> ;		[BP+1]	: TRACK #
   682                              <1> ;		[BP+2]	: BUFFER OFFSET
   683                              <1> ;
   684                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   685                              <1> ;-------------------------------------------------------------------------------
   686                              <1> 
   687                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   688                              <1> 
   689                              <1> DSK_READ:
   690 00002F44 8025[4E200100]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
   691 00002F4B 66B846E6            <1> 	MOV	AX,0E646H		; AX = NEC COMMAND, DMA COMMAND
   692 00002F4F E83C040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   693 00002F54 C3                  <1> 	RETn
   694                              <1> 
   695                              <1> ;-------------------------------------------------------------------------------
   696                              <1> ; DISK_WRITE	(AH = 03H)
   697                              <1> ;	DISKETTE WRITE.
   698                              <1> ;
   699                              <1> ; ON ENTRY:	DI	: DRIVE #
   700                              <1> ;		SI-HI	: HEAD #
   701                              <1> ;		SI-LOW	: # OF SECTORS
   702                              <1> ;		ES	: BUFFER SEGMENT
   703                              <1> ;		[BP]	: SECTOR #
   704                              <1> ;		[BP+1]	: TRACK #
   705                              <1> ;		[BP+2]	: BUFFER OFFSET
   706                              <1> ;
   707                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   708                              <1> ;-------------------------------------------------------------------------------
   709                              <1> 
   710                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   711                              <1> 
   712                              <1> DSK_WRITE:
   713 00002F55 66B84AC5            <1> 	MOV	AX,0C54AH		; AX = NEC COMMAND, DMA COMMAND
   714 00002F59 800D[4E200100]80    <1>         OR      byte [MOTOR_STATUS],10000000B ; INDICATE WRITE OPERATION
   715 00002F60 E82B040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   716 00002F65 C3                  <1> 	RETn
   717                              <1> 
   718                              <1> ;-------------------------------------------------------------------------------
   719                              <1> ; DISK_VERF	(AH = 04H)
   720                              <1> ;	DISKETTE VERIFY.
   721                              <1> ;
   722                              <1> ; ON ENTRY:	DI	: DRIVE #
   723                              <1> ;		SI-HI	: HEAD #
   724                              <1> ;		SI-LOW	: # OF SECTORS
   725                              <1> ;		ES	: BUFFER SEGMENT
   726                              <1> ;		[BP]	: SECTOR #
   727                              <1> ;		[BP+1]	: TRACK #
   728                              <1> ;		[BP+2]	: BUFFER OFFSET
   729                              <1> ;
   730                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   731                              <1> ;-------------------------------------------------------------------------------
   732                              <1> DSK_VERF:
   733 00002F66 8025[4E200100]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
   734 00002F6D 66B842E6            <1> 	MOV	AX,0E642H		; AX = NEC COMMAND, DMA COMMAND
   735 00002F71 E81A040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   736 00002F76 C3                  <1> 	RETn
   737                              <1> 
   738                              <1> ;-------------------------------------------------------------------------------
   739                              <1> ; DISK_FORMAT	(AH = 05H)
   740                              <1> ;	DISKETTE FORMAT.
   741                              <1> ;
   742                              <1> ; ON ENTRY:	DI	: DRIVE #
   743                              <1> ;		SI-HI	: HEAD #
   744                              <1> ;		SI-LOW	: # OF SECTORS
   745                              <1> ;		ES	: BUFFER SEGMENT
   746                              <1> ;		[BP]	: SECTOR #
   747                              <1> ;		[BP+1]	: TRACK #
   748                              <1> ;		[BP+2]	: BUFFER OFFSET
   749                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
   750                              <1> ;
   751                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   752                              <1> ;-------------------------------------------------------------------------------
   753                              <1> DSK_FORMAT:
   754 00002F77 E853030000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
   755 00002F7C E84F050000          <1> 	CALL	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
   756 00002F81 800D[4E200100]80    <1>         OR      byte [MOTOR_STATUS], 10000000B ; INDICATE WRITE OPERATION
   757 00002F88 E897050000          <1> 	CALL	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
   758 00002F8D 725D                <1>         JC      short FM_DON            ; MEDIA CHANGED, SKIP
   759 00002F8F E8F2020000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
   760 00002F94 E8FD050000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
   761 00002F99 7405                <1>         JZ      short FM_WR             ; YES, SKIP SPECIFY COMMAND
   762 00002F9B E8D4050000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO CONTROLLER
   763                              <1> FM_WR:
   764 00002FA0 E88A060000          <1> 	CALL	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
   765 00002FA5 7245                <1>         JC      short FM_DON            ; RETURN WITH ERROR
   766 00002FA7 B44D                <1> 	MOV	AH,04DH			; ESTABLISH THE FORMAT COMMAND
   767 00002FA9 E8E7060000          <1> 	CALL	NEC_INIT		; INITIALIZE THE NEC
   768 00002FAE 723C                <1>         JC      short FM_DON            ; ERROR - EXIT
   769 00002FB0 B8[EC2F0000]        <1>         MOV     eAX, FM_DON             ; LOAD ERROR ADDRESS
   770 00002FB5 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
   771 00002FB6 B203                <1> 	MOV	DL,3			; BYTES/SECTOR VALUE TO NEC
   772 00002FB8 E856090000          <1> 	CALL	GET_PARM
   773 00002FBD E8570A0000          <1> 	CALL	NEC_OUTPUT
   774 00002FC2 B204                <1> 	MOV	DL,4			; SECTORS/TRACK VALUE TO NEC
   775 00002FC4 E84A090000          <1> 	CALL	GET_PARM
   776 00002FC9 E84B0A0000          <1> 	CALL	NEC_OUTPUT
   777 00002FCE B207                <1> 	MOV	DL,7			; GAP LENGTH VALUE TO NEC
   778 00002FD0 E83E090000          <1> 	CALL	GET_PARM
   779 00002FD5 E83F0A0000          <1> 	CALL	NEC_OUTPUT
   780 00002FDA B208                <1> 	MOV	DL,8			; FILLER BYTE TO NEC
   781 00002FDC E832090000          <1> 	CALL	GET_PARM
   782 00002FE1 E8330A0000          <1> 	CALL	NEC_OUTPUT
   783 00002FE6 58                  <1> 	POP	eAX			; THROW AWAY ERROR
   784 00002FE7 E827070000          <1> 	CALL	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
   785                              <1> FM_DON:
   786 00002FEC E80F030000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   787 00002FF1 E849080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   788 00002FF6 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   789 00002FF9 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   790 00002FFB C3                  <1> 	RETn
   791                              <1> 
   792                              <1> ;-------------------------------------------------------------------------------
   793                              <1> ; FNC_ERR
   794                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
   795                              <1> ;	SET BAD COMMAND IN STATUS.
   796                              <1> ;
   797                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   798                              <1> ;-------------------------------------------------------------------------------
   799                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
   800 00002FFC 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
   801 00002FFF B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
   802 00003001 8825[50200100]      <1> 	MOV	[DSKETTE_STATUS],AH	; STORE IN DATA AREA
   803 00003007 F9                  <1> 	STC				; SET CARRY INDICATING ERROR
   804 00003008 C3                  <1> 	RETn
   805                              <1> 
   806                              <1> ; 01/06/2016
   807                              <1> ; 28/05/2016
   808                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v.2.0)
   809                              <1> ;-------------------------------------------------------------------------------
   810                              <1> ; DISK_PARMS	(AH = 08H)	
   811                              <1> ;	READ DRIVE PARAMETERS.
   812                              <1> ;
   813                              <1> ; ON ENTRY:	DI : DRIVE #
   814                              <1> ;		; 27/05/2016
   815                              <1> ;		EBX = Buffer Address for floppy disk parameters table (16 bytes)
   816                              <1> ;
   817                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
   818                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
   819                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
   820                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
   821                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
   822                              <1> ;		BH/[BP+3] = 0
   823                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
   824                              <1> ;		DH/[BP+5] = MAX HEAD #
   825                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
   826                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
   827                              <1> ;		;DI/[BP+6] = OFFSET TO DISK_BASE
   828                              <1> ;		;ES        = SEGMENT OF DISK_BASE
   829                              <1> ;
   830                              <1> ;		AX        = 0
   831                              <1> ;
   832                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
   833                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
   834                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
   835                              <1> ;		       CALLER.
   836                              <1> ;-------------------------------------------------------------------------------
   837                              <1> DSK_PARMS:
   838 00003009 E8C1020000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
   839                              <1>      ;	MOV	WORD [BP+2],0		; DRIVE TYPE = 0
   840                              <1>      ;  MOV     AX, [EQUIP_FLAG]        ; LOAD EQUIPMENT FLAG FOR # DISKETTES
   841                              <1>      ;  AND     AL,11000001B            ; KEEP DISKETTE DRIVE BITS
   842                              <1>      ;  MOV     DL,2                    ; DISKETTE DRIVES = 2
   843                              <1>      ;  CMP     AL,01000001B            ; 2 DRIVES INSTALLED ?
   844                              <1>      ;  JZ      short STO_DL            ; IF YES JUMP
   845                              <1>      ;  DEC     DL                      ; DISKETTE DRIVES = 1
   846                              <1>      ;  CMP     AL,00000001B            ; 1 DRIVE INSTALLED ?
   847                              <1>      ;  JNZ     short NON_DRV           ; IF NO JUMP
   848 0000300E 29D2                <1> 	sub	edx, edx
   849 00003010 66A1[18ED0000]      <1> 	mov     ax, [fd0_type]
   850 00003016 6621C0              <1> 	and     ax, ax
   851 00003019 0F848A000000        <1>         jz      NON_DRV
   852 0000301F FEC2                <1> 	inc     dl
   853 00003021 20E4                <1> 	and     ah, ah
   854 00003023 7402                <1> 	jz      short STO_DL
   855 00003025 FEC2                <1> 	inc     dl
   856                              <1> STO_DL:
   857                              <1> 	;MOV	[BP+4],DL		; STORE NUMBER OF DRIVES
   858 00003027 895508              <1> 	mov	[ebp+8], edx ; 20/02/2015	 	
   859 0000302A 6683FF01            <1> 	CMP	DI,1			; CHECK FOR VALID DRIVE
   860 0000302E 777C                <1> 	JA	short NON_DRV1		; DRIVE INVALID
   861                              <1> 	;MOV	BYTE [BP+5],1		; MAXIMUM HEAD NUMBER =	1
   862 00003030 C6450901            <1> 	mov	byte [ebp+9], 1  ; 20/02/2015	
   863 00003034 E8D1080000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
   864                              <1> 	;;20/02/2015
   865                              <1> 	;;JC	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
   866                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE TYPE
   867 00003039 740F                <1> 	JZ	short CHK_EST		; JUMP IF SO
   868 0000303B E81B020000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   869 00003040 7208                <1> 	JC	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
   870                              <1> 	;MOV	[BP+2],AL		; STORE VALID CMOS DRIVE TYPE
   871                              <1>         ;mov	[ebp+4], al ; 06/02/2015
   872 00003042 8A4B04              <1> 	MOV     CL, [eBX+MD.SEC_TRK]     ; GET SECTOR/TRACK
   873 00003045 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]     ; GET MAX. TRACK NUMBER
   874 00003048 EB36                <1> 	JMP	SHORT STO_CX		; CMOS GOOD, USE CMOS
   875                              <1> CHK_EST:
   876 0000304A 8AA7[5D200100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; LOAD STATE FOR THIS DRIVE
   877 00003050 F6C410              <1> 	TEST	AH,MED_DET		; CHECK FOR ESTABLISHED STATE
   878 00003053 7457                <1> 	JZ	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
   879                              <1> USE_EST:
   880 00003055 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE STATE
   881 00003058 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
   882 0000305B 7570                <1> 	JNE	short USE_EST2		; NO, GO CHECK OTHER RATE
   883                              <1> 
   884                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
   885                              <1> 
   886 0000305D B001                <1> 	MOV	AL,01			; DRIVE TYPE 1 (360KB)
   887 0000305F E8F7010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   888 00003064 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   889 00003067 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   890 0000306A F687[5D200100]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; 80 TRACK ?
   891 00003071 740D                <1> 	JZ	short STO_CX		; MUST BE 360KB DRIVE 
   892                              <1> 
   893                              <1> ;-----	IT IS 1.44 MB DRIVE
   894                              <1> 
   895                              <1> PARM144:
   896 00003073 B004                <1> 	MOV	AL,04			; DRIVE TYPE 4 (1.44MB)
   897 00003075 E8E1010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   898 0000307A 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   899 0000307D 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   900                              <1> STO_CX:
   901 00003080 894D00              <1> 	MOV	[eBP],eCX		; SAVE POINTER IN STACK FOR RETURN
   902                              <1> ES_DI:
   903                              <1> 	;MOV	[BP+6],BX		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
   904                              <1> 	;mov	[ebp+12], ebx ; 06/02/2015
   905                              <1> 	;MOV	AX,CS			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
   906                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
   907                              <1> 	;
   908                              <1> 	; 28/05/2016
   909                              <1> 	; 27/05/2016
   910                              <1> 	; return floppy disk parameters table to user
   911                              <1> 	; in user's buffer, which is pointed by EBX
   912                              <1> 	;
   913 00003083 57                  <1> 	push	edi
   914 00003084 8B7D04              <1> 	mov	edi, [ebp+4]  		; ebx (input), user's buffer address
   915 00003087 0FB6C0              <1> 	movzx	eax, al
   916 0000308A 894504              <1>         mov	[ebp+4], eax   ; ebx	; drive type (for floppy drives)
   917                              <1> 	; 01/06/2016 (INT 33h, disk type return for floppy disks, in BL)
   918 0000308D A3[482D0100]        <1> 	mov	[user_buffer], eax	; 01/06/2016 (overwrite ebx return value)
   919                              <1> 	;(INT 33h, Function 08h will replace user's buffer addr with disk type!)
   920                              <1> 	;
   921 00003092 89DE                <1> 	mov	esi, ebx 		; floppy disk parameter table (16 bytes)
   922 00003094 B910000000          <1> 	mov	ecx, 16 ; 16 bytes
   923 00003099 E8D6A80000          <1>         call    transfer_to_user_buffer ; trdosk6.s (16/05/2016)
   924 0000309E 5F                  <1> 	pop	edi	
   925                              <1> DP_OUT:
   926 0000309F E85C020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   927 000030A4 6631C0              <1> 	XOR	AX,AX			; CLEAR
   928 000030A7 F8                  <1> 	CLC
   929 000030A8 C3                  <1> 	RETn
   930                              <1> 
   931                              <1> ;-----	NO DRIYE PRESENT HANDLER
   932                              <1> 
   933                              <1> NON_DRV:
   934                              <1> 	;MOV	BYTE [BP+4],0		; CLEAR NUMBER OF DRIVES
   935 000030A9 895508              <1> 	mov	[ebp+8], edx ; 0 ; 20/02/2015
   936                              <1> NON_DRV1:
   937 000030AC 6681FF8000          <1> 	CMP	DI,80H			; CHECK FOR FIXED MEDIA TYPE REQUEST
   938 000030B1 720C                <1> 	JB	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
   939                              <1> 
   940                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
   941                              <1> 	
   942 000030B3 E848020000          <1> 	CALL	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
   943 000030B8 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
   944 000030BB B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
   945 000030BD F9                  <1> 	STC
   946 000030BE C3                  <1> 	RETn
   947                              <1> 
   948                              <1> NON_DRV2:
   949                              <1> 	;XOR	AX,AX			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
   950 000030BF 31C0                <1> 	xor	eax, eax	
   951 000030C1 66894500            <1> 	MOV	[eBP],AX		; TRACKS, SECTORS/TRACK = 0
   952                              <1> 	;MOV	[BP+5],AH		; HEAD = 0
   953 000030C5 886509              <1> 	mov	[ebp+9], ah ; 06/02/2015
   954                              <1> 	;MOV	[BP+6],AX		; OFFSET TO DISK_BASE = 0
   955 000030C8 89450C              <1> 	mov	[ebp+12], eax
   956                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
   957 000030CB EBD2                <1> 	JMP	SHORT DP_OUT
   958                              <1> 
   959                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
   960                              <1> 
   961                              <1> USE_EST2:
   962 000030CD B002                <1> 	MOV	AL,02			; DRIVE TYPE 2 (1.2MB)
   963 000030CF E887010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   964 000030D4 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   965 000030D7 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   966 000030DA 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
   967 000030DD 74A1                <1> 	JZ	short STO_CX		; MUST BE 1.2MB DRIVE
   968 000030DF EB92                <1> 	JMP	SHORT PARM144		; ELSE, IT IS 1.44MB DRIVE 
   969                              <1> 
   970                              <1> ;-------------------------------------------------------------------------------
   971                              <1> ; DISK_TYPE (AH = 15H)	
   972                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
   973                              <1> ;
   974                              <1> ;  ON ENTRY:	DI = DRIVE #
   975                              <1> ;
   976                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
   977                              <1> ;-------------------------------------------------------------------------------
   978                              <1> DSK_TYPE:
   979 000030E1 E8E9010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
   980 000030E6 8A87[5D200100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET PRESENT STATE INFORMATION
   981 000030EC 08C0                <1> 	OR	AL,AL			; CHECK FOR NO DRIVE
   982 000030EE 7418                <1> 	JZ	short NO_DRV
   983 000030F0 B401                <1> 	MOV	AH,NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
   984 000030F2 A801                <1> 	TEST	AL,TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
   985 000030F4 7402                <1> 	JZ	short DT_BACK			; IF NO JUMP
   986 000030F6 B402                <1> 	MOV	AH,CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
   987                              <1> DT_BACK:
   988 000030F8 6650                <1> 	PUSH	AX			; SAVE RETURN VALUE
   989 000030FA E801020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   990 000030FF 6658                <1> 	POP	AX			; RESTORE RETURN VALUE
   991 00003101 F8                  <1> 	CLC				; NO ERROR
   992 00003102 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   993 00003105 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   994 00003107 C3                  <1> 	RETn
   995                              <1> NO_DRV:	
   996 00003108 30E4                <1> 	XOR	AH,AH			; NO DRIVE PRESENT OR UNKNOWN
   997 0000310A EBEC                <1> 	JMP	SHORT DT_BACK
   998                              <1> 
   999                              <1> ;-------------------------------------------------------------------------------
  1000                              <1> ; DISK_CHANGE	(AH = 16H)
  1001                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  1002                              <1> ;
  1003                              <1> ; ON ENTRY:	DI = DRIVE #
  1004                              <1> ;
  1005                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  1006                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  1007                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  1008                              <1> ;-------------------------------------------------------------------------------
  1009                              <1> DSK_CHANGE:
  1010 0000310C E8BE010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1011 00003111 8A87[5D200100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET MEDIA STATE INFORMATION
  1012 00003117 08C0                <1> 	OR	AL,AL			; DRIVE PRESENT ?
  1013 00003119 7422                <1> 	JZ	short DC_NON		; JUMP IF NO DRIVE
  1014 0000311B A801                <1> 	TEST	AL,TRK_CAPA		; 80 TRACK DRIVE ?
  1015 0000311D 7407                <1> 	JZ	short SETIT		; IF SO , CHECK CHANGE LINE
  1016                              <1> DC0:
  1017 0000311F E88D0A0000          <1>         CALL    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  1018 00003124 7407                <1> 	JZ	short FINIS		; CHANGE LINE NOT ACTIVE
  1019                              <1> 
  1020 00003126 C605[50200100]06    <1> SETIT:	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  1021                              <1> 
  1022 0000312D E8CE010000          <1> FINIS:	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1023 00003132 E808070000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1024 00003137 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  1025 0000313A 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  1026 0000313C C3                  <1> 	RETn
  1027                              <1> DC_NON:
  1028 0000313D 800D[50200100]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  1029 00003144 EBE7                <1> 	JMP	SHORT FINIS
  1030                              <1> 
  1031                              <1> ;-------------------------------------------------------------------------------
  1032                              <1> ; FORMAT_SET	(AH = 17H)
  1033                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  1034                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  1035                              <1> ;
  1036                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  1037                              <1> ;		DI     = DRIVE #
  1038                              <1> ;
  1039                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  1040                              <1> ;		AH = @DSKETTE_STATUS
  1041                              <1> ;		CY = 1 IF ERROR
  1042                              <1> ;-------------------------------------------------------------------------------
  1043                              <1> FORMAT_SET:
  1044 00003146 E884010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1045 0000314B 6656                <1> 	PUSH	SI			; SAVE DASD TYPE
  1046 0000314D 6689F0              <1> 	MOV	AX,SI			; AH = ? , AL , DASD TYPE
  1047 00003150 30E4                <1> 	XOR	AH,AH			; AH , 0 , AL , DASD TYPE
  1048 00003152 6689C6              <1> 	MOV	SI,AX			; SI = DASD TYPE
  1049 00003155 80A7[5D200100]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1050 0000315C 664E                <1> 	DEC	SI			; CHECK FOR 320/360K MEDIA & DRIVE
  1051 0000315E 7509                <1> 	JNZ	short NOT_320		; BYPASS IF NOT
  1052 00003160 808F[5D200100]90    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_250 ; SET TO 320/360
  1053 00003167 EB48                <1> 	JMP	SHORT S0
  1054                              <1> 
  1055                              <1> NOT_320:
  1056 00003169 E8B6030000          <1> 	CALL	MED_CHANGE		; CHECK FOR TIME_OUT
  1057 0000316E 803D[50200100]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT
  1058 00003175 743A                <1> 	JZ	short S0		; IF TIME OUT TELL CALLER
  1059                              <1> S3:
  1060 00003177 664E                <1> 	DEC	SI			; CHECK FOR 320/360K IN 1.2M DRIVE
  1061 00003179 7509                <1> 	JNZ	short NOT_320_12	; BYPASS IF NOT
  1062 0000317B 808F[5D200100]70    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  1063 00003182 EB2D                <1> 	JMP	SHORT S0
  1064                              <1> 
  1065                              <1> NOT_320_12:
  1066 00003184 664E                <1> 	DEC	SI			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  1067 00003186 7509                <1> 	JNZ	short NOT_12		; BYPASS IF NOT
  1068 00003188 808F[5D200100]10    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_500 ; SET STATE VARIABLE
  1069 0000318F EB20                <1> 	JMP	SHORT S0		; RETURN TO CALLER
  1070                              <1> 
  1071                              <1> NOT_12:	
  1072 00003191 664E                <1> 	DEC	SI			; CHECK FOR SET DASD TYPE 04
  1073 00003193 752B                <1> 	JNZ	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  1074                              <1> 
  1075 00003195 F687[5D200100]04    <1> 	TEST	byte [DSK_STATE+eDI], DRV_DET ; DRIVE DETERMINED ?
  1076 0000319C 740B                <1> 	JZ	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  1077 0000319E B050                <1> 	MOV	AL,MED_DET+RATE_300
  1078 000031A0 F687[5D200100]02    <1>         TEST    byte [DSK_STATE+eDI], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  1079 000031A7 7502                <1> 	JNZ	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  1080                              <1> 
  1081                              <1> ASSUME:
  1082 000031A9 B090                <1> 	MOV	AL,MED_DET+RATE_250	; SET UP
  1083                              <1> 
  1084                              <1> OR_IT_IN:
  1085 000031AB 0887[5D200100]      <1> 	OR	[DSK_STATE+eDI], AL	; OR IN THE CORRECT STATE
  1086                              <1> S0:
  1087 000031B1 E84A010000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1088 000031B6 E884060000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1089 000031BB 665B                <1> 	POP	BX			; GET SAVED AL TO BL
  1090 000031BD 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  1091 000031BF C3                  <1> 	RETn
  1092                              <1> 
  1093                              <1> FS_ERR:
  1094 000031C0 C605[50200100]01    <1> 	MOV	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  1095 000031C7 EBE8                <1> 	JMP	SHORT S0
  1096                              <1> 
  1097                              <1> ;-------------------------------------------------------------------------------
  1098                              <1> ; SET_MEDIA	(AH = 18H)
  1099                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  1100                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  1101                              <1> ;
  1102                              <1> ; ON ENTRY:
  1103                              <1> ;	[BP]	= SECTOR PER TRACK
  1104                              <1> ;	[BP+1]	= TRACK #
  1105                              <1> ;	DI	= DRIVE #
  1106                              <1> ;
  1107                              <1> ; ON EXIT:
  1108                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  1109                              <1> ;	IF NO ERROR:
  1110                              <1> ;		AH = 0
  1111                              <1> ;		CY = 0
  1112                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1113                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  1114                              <1> ;	IF ERROR:	
  1115                              <1> ;		AH = @DSKETTE_STATUS
  1116                              <1> ;		CY = 1
  1117                              <1> ;-------------------------------------------------------------------------------
  1118                              <1> SET_MEDIA:
  1119 000031C9 E801010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1120 000031CE F687[5D200100]01    <1>         TEST    byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  1121 000031D5 7415                <1> 	JZ	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  1122 000031D7 E848030000          <1> 	CALL	MED_CHANGE		; RESET CHANGE LINE
  1123 000031DC 803D[50200100]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  1124 000031E3 746B                <1> 	JE	short SM_RTN
  1125 000031E5 C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  1126                              <1> SM_CMOS:
  1127 000031EC E819070000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1128                              <1> 	;;20/02/2015
  1129                              <1> 	;;JC	short MD_NOT_FND	; ERROR IN CMOS
  1130                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE
  1131 000031F1 745D                <1> 	JZ	short SM_RTN		; RETURN IF SO
  1132 000031F3 E863000000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1133 000031F8 7231                <1> 	JC	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  1134 000031FA 57                  <1> 	PUSH	eDI			; SAVE REG.
  1135 000031FB 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR. TYPE TABLE
  1136 000031FD B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1137                              <1> DR_SEARCH:
  1138 00003202 8AA3[96EC0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  1139 00003208 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  1140 0000320B 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH ?
  1141 0000320D 7516                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  1142                              <1> DR_FND:
  1143 0000320F 8BBB[97EC0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  1144                              <1> MD_SEARCH:
  1145 00003215 8A6704              <1>         MOV     AH, [eDI+MD.SEC_TRK]    ; GET SECTOR/TRACK
  1146 00003218 386500              <1> 	CMP	[eBP],AH		; MATCH?
  1147 0000321B 7508                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT MEDIA
  1148 0000321D 8A670B              <1>         MOV     AH, [eDI+MD.MAX_TRK]    ; GET MAX. TRACK #
  1149 00003220 386501              <1> 	CMP 	[eBP+1],AH		; MATCH?
  1150 00003223 740F                <1> 	JE	short MD_FND		; YES, GO GET RATE
  1151                              <1> NXT_MD:
  1152                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1153 00003225 83C305              <1>         add	ebx, 5 ; 18/02/2015
  1154 00003228 E2D8                <1> 	LOOP    DR_SEARCH
  1155 0000322A 5F                  <1> 	POP	eDI			; RESTORE REG.
  1156                              <1> MD_NOT_FND:
  1157 0000322B C605[50200100]0C    <1> 	MOV	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  1158 00003232 EB1C                <1> 	JMP	SHORT SM_RTN		; RETURN
  1159                              <1> MD_FND:
  1160 00003234 8A470C              <1>         MOV     AL, [eDI+MD.RATE]       ; GET RATE
  1161 00003237 3C40                <1> 	CMP	AL,RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  1162 00003239 7502                <1> 	JNE	short MD_SET
  1163 0000323B 0C20                <1> 	OR	AL,DBL_STEP
  1164                              <1> MD_SET:
  1165                              <1> 	;MOV	[BP+6],DI		; SAVE TABLE POINTER IN STACK
  1166 0000323D 897D0C              <1> 	mov	[ebp+12], edi ; 18/02/2015
  1167 00003240 0C10                <1> 	OR	AL,MED_DET		; SET MEDIA ESTABLISHED
  1168 00003242 5F                  <1> 	POP	eDI
  1169 00003243 80A7[5D200100]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1170 0000324A 0887[5D200100]      <1> 	OR	[DSK_STATE+eDI], AL
  1171                              <1> 	;MOV	AX, CS			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1172                              <1> 	;MOV	ES, AX			; ES IS SEGMENT OF TABLE
  1173                              <1> SM_RTN:
  1174 00003250 E8AB000000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1175 00003255 E8E5050000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1176 0000325A C3                  <1> 	RETn
  1177                              <1> 
  1178                              <1> ;----------------------------------------------------------------
  1179                              <1> ; DR_TYPE_CHECK							:
  1180                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  1181                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  1182                              <1> ; ON ENTRY:							:
  1183                              <1> ;	AL = DRIVE TYPE						:
  1184                              <1> ; ON EXIT:							:
  1185                              <1> ;	CS = SEGMENT MEDIA/DRIVE PARAMETER TABLE (CODE)		:
  1186                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  1187                              <1> ;	     BX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE		:
  1188                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  1189                              <1> ; REGISTERS ALTERED: eBX						:
  1190                              <1> ;----------------------------------------------------------------		
  1191                              <1> DR_TYPE_CHECK:
  1192 0000325B 6650                <1> 	PUSH	AX			
  1193 0000325D 51                  <1> 	PUSH	eCX
  1194 0000325E 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  1195 00003260 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1196                              <1> TYPE_CHK:	
  1197 00003265 8AA3[96EC0000]      <1> 	MOV	AH,[DR_TYPE+eBX]	; GET DRIVE TYPE
  1198 0000326B 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  1199 0000326D 740D                <1> 	JE	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  1200                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1201 0000326F 83C305              <1>         add	ebx, 5	; 16/02/2015 (32 bit address modification)
  1202 00003272 E2F1                <1> 	LOOP    TYPE_CHK
  1203                              <1> 	;
  1204 00003274 BB[F5EC0000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  1205                              <1> 					; Default for GET_PARM (11/12/2014)
  1206                              <1> 	;
  1207 00003279 F9                  <1> 	STC				; DRIVE TYPE NOT FOUND IN TABLE
  1208 0000327A EB06                <1> 	JMP	SHORT TYPE_RTN
  1209                              <1> DR_TYPE_VALID:
  1210 0000327C 8B9B[97EC0000]      <1> 	MOV	eBX,[DR_TYPE+eBX+1] 	; BX = MEDIA TABLE
  1211                              <1> TYPE_RTN:
  1212 00003282 59                  <1> 	POP	eCX
  1213 00003283 6658                <1> 	POP	AX
  1214 00003285 C3                  <1> 	RETn	
  1215                              <1> 		
  1216                              <1> ;----------------------------------------------------------------
  1217                              <1> ; SEND_SPEC							:
  1218                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1219                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  1220                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  1221                              <1> ; ON EXIT:	NONE						:	
  1222                              <1> ; REGISTERS ALTERED: CX, DX					:
  1223                              <1> ;----------------------------------------------------------------		
  1224                              <1> SEND_SPEC:
  1225 00003286 50                  <1> 	PUSH	eAX			; SAVE AX
  1226 00003287 B8[AD320000]        <1> 	MOV	eAX, SPECBAC		; LOAD ERROR ADDRESS
  1227 0000328C 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1228 0000328D B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  1229 0000328F E885070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1230 00003294 28D2                <1> 	SUB	DL,DL			; FIRST SPECIFY BYTE
  1231 00003296 E878060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  1232 0000329B E879070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1233 000032A0 B201                <1> 	MOV	DL,1			; SECOND SPECIFY BYTE
  1234 000032A2 E86C060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  1235 000032A7 E86D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1236 000032AC 58                  <1> 	POP	eAX			; POP ERROR RETURN
  1237                              <1> SPECBAC:
  1238 000032AD 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  1239 000032AE C3                  <1> 	RETn
  1240                              <1> 
  1241                              <1> ;----------------------------------------------------------------
  1242                              <1> ; SEND_SPEC_MD							:
  1243                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1244                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  1245                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  1246                              <1> ; ON EXIT:	NONE						:	
  1247                              <1> ; REGISTERS ALTERED: AX						:
  1248                              <1> ;----------------------------------------------------------------		
  1249                              <1> SEND_SPEC_MD:
  1250 000032AF 50                  <1> 	PUSH	eAX			; SAVE RATE DATA
  1251 000032B0 B8[CD320000]        <1> 	MOV	eAX, SPEC_ESBAC		; LOAD ERROR ADDRESS
  1252 000032B5 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1253 000032B6 B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  1254 000032B8 E85C070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1255 000032BD 8A23                <1>         MOV     AH, [eBX+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  1256 000032BF E855070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1257 000032C4 8A6301              <1>         MOV     AH, [eBX+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  1258 000032C7 E84D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1259 000032CC 58                  <1> 	POP	eAX			; POP ERROR RETURN
  1260                              <1> SPEC_ESBAC:
  1261 000032CD 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  1262 000032CE C3                  <1> 	RETn
  1263                              <1> 
  1264                              <1> ;-------------------------------------------------------------------------------
  1265                              <1> ; XLAT_NEW  
  1266                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  1267                              <1> ;	MODE TO NEW ARCHITECTURE.
  1268                              <1> ;
  1269                              <1> ; ON ENTRY:	DI = DRIVE #
  1270                              <1> ;-------------------------------------------------------------------------------
  1271                              <1> XLAT_NEW:
  1272 000032CF 83FF01              <1> 	CMP	eDI,1				; VALID DRIVE
  1273 000032D2 7725                <1> 	JA	short XN_OUT			; IF INVALID BACK
  1274 000032D4 80BF[5D200100]00    <1> 	CMP	byte [DSK_STATE+eDI], 0		; NO DRIVE ?
  1275 000032DB 741D                <1> 	JZ	short DO_DET			; IF NO DRIVE ATTEMPT DETERMINE
  1276 000032DD 6689F9              <1> 	MOV	CX,DI				; CX = DRIVE NUMBER
  1277 000032E0 C0E102              <1> 	SHL	CL,2				; CL = SHIFT COUNT, A=0, B=4
  1278 000032E3 A0[5C200100]        <1> 	MOV	AL, [HF_CNTRL]			; DRIVE INFORMATION
  1279 000032E8 D2C8                <1> 	ROR	AL,CL				; TO LOW NIBBLE
  1280 000032EA 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA	; KEEP DRIVE BITS
  1281 000032EC 80A7[5D200100]F8    <1>         AND     byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  1282 000032F3 0887[5D200100]      <1> 	OR	[DSK_STATE+eDI], AL		; UPDATE DRIVE STATE
  1283                              <1> XN_OUT:
  1284 000032F9 C3                  <1> 	RETn
  1285                              <1> DO_DET:
  1286 000032FA E8BF080000          <1> 	CALL	DRIVE_DET			; TRY TO DETERMINE
  1287 000032FF C3                  <1> 	RETn
  1288                              <1> 
  1289                              <1> ;-------------------------------------------------------------------------------
  1290                              <1> ; XLAT_OLD 
  1291                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  1292                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  1293                              <1> ;
  1294                              <1> ; ON ENTRY:	DI = DRIVE
  1295                              <1> ;-------------------------------------------------------------------------------
  1296                              <1> XLAT_OLD:
  1297 00003300 83FF01              <1> 	CMP	eDI,1			; VALID DRIVE ?
  1298                              <1>         ;JA     short XO_OUT            ; IF INVALID BACK
  1299 00003303 0F8786000000        <1>         ja      XO_OUT
  1300 00003309 80BF[5D200100]00    <1>         CMP	byte [DSK_STATE+eDI],0	; NO DRIVE ?
  1301 00003310 747D                <1> 	JZ	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  1302                              <1> 
  1303                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  1304                              <1> 
  1305 00003312 6689F9              <1> 	MOV	CX,DI			; CX = DRIVE NUMBER
  1306 00003315 C0E102              <1> 	SHL	CL,2			; CL = SHIFT COUNT, A=0, B=4
  1307 00003318 B402                <1> 	MOV	AH,FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  1308 0000331A D2CC                <1> 	ROR	AH,CL			; ROTATE BY MASK
  1309 0000331C 8425[5C200100]      <1> 	TEST	[HF_CNTRL], AH		; MULTIPLE-DATA RATE DETERMINED ?
  1310 00003322 751C                <1> 	JNZ	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  1311                              <1> 
  1312                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  1313                              <1> 
  1314 00003324 B407                <1> 	MOV	AH,DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  1315 00003326 D2CC                <1> 	ROR	AH,CL			; FIX MASK TO KEEP
  1316 00003328 F6D4                <1> 	NOT	AH			; TRANSLATE MASK
  1317 0000332A 2025[5C200100]      <1> 	AND	[HF_CNTRL], AH		; KEEP BITS FROM OTHER DRIVE INTACT
  1318                              <1> 
  1319                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  1320                              <1> 
  1321 00003330 8A87[5D200100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; ACCESS STATE
  1322 00003336 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  1323 00003338 D2C8                <1> 	ROR	AL,CL			; FIX FOR THIS DRIVE
  1324 0000333A 0805[5C200100]      <1> 	OR	[HF_CNTRL], AL		; UPDATE SAVED DRIVE STATE
  1325                              <1> 
  1326                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  1327                              <1> 
  1328                              <1> SAVE_SET:
  1329 00003340 8AA7[5D200100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  1330 00003346 88E7                <1> 	MOV	BH,AH			; TO BH FOR LATER
  1331 00003348 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE
  1332 0000334B 80FC00              <1> 	CMP	AH,RATE_500		; RATE 500 ?
  1333 0000334E 7410                <1> 	JZ	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  1334 00003350 B001                <1> 	MOV	AL,M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  1335 00003352 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  1336 00003355 7518                <1> 	JNZ	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  1337 00003357 F6C720              <1> 	TEST	BH,DBL_STEP		; CHECK FOR DOUBLE STEP
  1338 0000335A 751F                <1> 	JNZ	short TST_DET		; MUST BE 360 IN 1.2
  1339                              <1> UNKNO:
  1340 0000335C B007                <1> 	MOV	AL,MED_UNK		; NONE OF THE ABOVE
  1341 0000335E EB22                <1> 	JMP	SHORT AL_SET		; PROCESS COMPLETE
  1342                              <1> CHK_144:
  1343 00003360 E8A5050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1344                              <1> 	;;20/02/2015
  1345                              <1> 	;;JC	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  1346 00003365 74F5                <1> 	jz	short UNKNO ;; 20/02/2015
  1347 00003367 3C02                <1> 	CMP	AL,2			; 1.2MB DRIVE ?
  1348 00003369 75F1                <1> 	JNE	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  1349 0000336B B002                <1> 	MOV	AL,M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  1350 0000336D EB0C                <1> 	JMP	SHORT TST_DET
  1351                              <1> CHK_250:
  1352 0000336F B000                <1> 	MOV	AL,M3D3U		; AL = 360 IN 360 UNESTABLISHED
  1353 00003371 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  1354 00003374 75E6                <1> 	JNZ	short UNKNO		; IF SO FALL IHRU
  1355 00003376 F6C701              <1> 	TEST	BH,TRK_CAPA		; 80 TRACK CAPABILITY ?
  1356 00003379 75E1                <1> 	JNZ	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  1357                              <1> TST_DET:
  1358 0000337B F6C710              <1> 	TEST	BH,MED_DET		; DETERMINED ?
  1359 0000337E 7402                <1> 	JZ	short AL_SET		; IF NOT THEN SET
  1360 00003380 0403                <1> 	ADD	AL,3			; MAKE DETERMINED/ESTABLISHED
  1361                              <1> AL_SET:
  1362 00003382 80A7[5D200100]F8    <1> 	AND	byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  1363 00003389 0887[5D200100]      <1> 	OR	[DSK_STATE+eDI], AL	; REPLACE WITH COMPATIBLE MODE
  1364                              <1> XO_OUT:
  1365 0000338F C3                  <1> 	RETn
  1366                              <1> 
  1367                              <1> ;-------------------------------------------------------------------------------
  1368                              <1> ; RD_WR_VF
  1369                              <1> ;	COMMON READ, WRITE AND VERIFY: 
  1370                              <1> ;	MAIN LOOP FOR STATE RETRIES.
  1371                              <1> ;
  1372                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
  1373                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
  1374                              <1> ;
  1375                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1376                              <1> ;-------------------------------------------------------------------------------
  1377                              <1> RD_WR_VF:
  1378 00003390 6650                <1> 	PUSH	AX			; SAVE DMA, NEC PARAMETERS
  1379 00003392 E838FFFFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1380 00003397 E8F3000000          <1> 	CALL	SETUP_STATE		; INITIALIZE START AND END RATE
  1381 0000339C 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  1382                              <1> DO_AGAIN:
  1383 0000339E 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  1384 000033A0 E87F010000          <1> 	CALL	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
  1385 000033A5 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  1386 000033A7 0F82C9000000        <1>         JC      RWV_END                 ; MEDIA CHANGE ERROR OR TIME-OUT
  1387                              <1> RWV:
  1388 000033AD 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  1389 000033AF 8AB7[5D200100]      <1> 	MOV	DH, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1390 000033B5 80E6C0              <1> 	AND	DH,RATE_MSK		; KEEP ONLY RATE
  1391 000033B8 E84D050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
  1392                              <1> 	;;20/02/2015
  1393                              <1> 	;;JC	short RWV_ASSUME	; ERROR IN CMOS
  1394 000033BD 7451                <1> 	jz	short RWV_ASSUME ; 20/02/2015
  1395 000033BF 3C01                <1> 	CMP	AL,1			; 40 TRACK DRIVE?
  1396 000033C1 750D                <1> 	JNE	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
  1397 000033C3 F687[5D200100]01    <1> 	TEST	byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
  1398 000033CA 7413                <1> 	JZ	short RWV_2		; YES, CMOS IS CORRECT
  1399 000033CC B002                <1> 	MOV	AL,2			; CHANGE TO 1.2M
  1400 000033CE EB0F                <1> 	JMP	SHORT RWV_2
  1401                              <1> RWV_1:
  1402 000033D0 720D                <1> 	JB	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
  1403 000033D2 F687[5D200100]01    <1> 	TEST    byte [DSK_STATE+eDI], TRK_CAPA ; IS IT REALLY 40 TRACK?
  1404 000033D9 7504                <1> 	JNZ	short RWV_2		; NO, 80 TRACK
  1405 000033DB B001                <1> 	MOV	AL,1			; IT IS 40 TRACK, FIX CMOS VALUE
  1406 000033DD EB04                <1> 	jmp	short rwv_3
  1407                              <1> RWV_2:
  1408 000033DF 08C0                <1> 	OR	AL,AL			; TEST FOR NO DRIVE
  1409 000033E1 742D                <1> 	JZ	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
  1410                              <1> rwv_3:
  1411 000033E3 E873FEFFFF          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
  1412 000033E8 7226                <1> 	JC	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
  1413                              <1> 
  1414                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
  1415                              <1> 
  1416 000033EA 57                  <1> 	PUSH	eDI			; SAVE DRIVE #
  1417 000033EB 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  1418 000033ED B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1419                              <1> RWV_DR_SEARCH:
  1420 000033F2 8AA3[96EC0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  1421 000033F8 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  1422 000033FB 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  1423 000033FD 750B                <1> 	JNE	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
  1424                              <1> RWV_DR_FND:
  1425 000033FF 8BBB[97EC0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAMETER TABLE
  1426                              <1> RWV_MD_SEARH:
  1427 00003405 3A770C              <1>         CMP     DH, [eDI+MD.RATE]       ; MATCH?
  1428 00003408 741B                <1> 	JE	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
  1429                              <1> RWV_NXT_MD:
  1430                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1431 0000340A 83C305              <1> 	add	eBX, 5
  1432 0000340D E2E3                <1> 	LOOP	RWV_DR_SEARCH
  1433 0000340F 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  1434                              <1> 
  1435                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
  1436                              <1> 
  1437                              <1> RWV_ASSUME:
  1438 00003410 BB[B4EC0000]        <1> 	MOV	eBX, MD_TBL1		; POINT TO 40 TRACK 250 KBS
  1439 00003415 F687[5D200100]01    <1> 	TEST 	byte [DSK_STATE+eDI], TRK_CAPA ; TEST FOR 80 TRACK
  1440 0000341C 740A                <1> 	JZ	short RWV_MD_FND1	; MUST BE 40 TRACK
  1441 0000341E BB[CEEC0000]        <1> 	MOV	eBX, MD_TBL3		; POINT TO 80 TRACK 500 KBS
  1442 00003423 EB03                <1> 	JMP	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
  1443                              <1> 
  1444                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
  1445                              <1> 	 			
  1446                              <1> RWV_MD_FND:
  1447 00003425 89FB                <1> 	MOV	eBX,eDI			; BX = MEDIA/DRIVE PARAMETER TABLE
  1448 00003427 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  1449                              <1> 	
  1450                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
  1451                              <1> 
  1452                              <1> RWV_MD_FND1:
  1453 00003428 E882FEFFFF          <1> 	CALL	SEND_SPEC_MD
  1454 0000342D E864010000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
  1455 00003432 7405                <1> 	JZ	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
  1456 00003434 E83B010000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO NEC
  1457                              <1> RWV_DBL:
  1458 00003439 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1459 0000343A E822040000          <1> 	CALL	SETUP_DBL		; CHECK FOR DOUBLE STEP
  1460 0000343F 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  1461 00003440 7226                <1> 	JC	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
  1462 00003442 6658                <1> 	POP	AX			; RESTORE NEC, DMA COMMAND
  1463 00003444 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1464 00003446 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1465 00003447 E861010000          <1> 	CALL	DMA_SETUP		; SET UP THE DMA
  1466 0000344C 5B                  <1> 	POP	eBX 
  1467 0000344D 6658                <1> 	POP	AX			; RESTORE NEC COMMAND
  1468 0000344F 722F                <1> 	JC	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
  1469 00003451 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1470 00003453 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1471 00003454 E83C020000          <1> 	CALL	NEC_INIT		; INITIALIZE NEC
  1472 00003459 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  1473 0000345A 720C                <1> 	JC	short CHK_RET		; ERROR - EXIT
  1474 0000345C E866020000          <1> 	CALL	RWV_COM			; OP CODE COMMON TO READ/WRITE/VERIFY
  1475 00003461 7205                <1> 	JC	short CHK_RET		; ERROR - EXIT
  1476 00003463 E8AB020000          <1> 	CALL	NEC_TERM		; TERMINATE, GET STATUS, ETC.
  1477                              <1> CHK_RET:
  1478 00003468 E84A030000          <1> 	CALL	RETRY			; CHECK FOR, SETUP RETRY
  1479 0000346D 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY PARAMETER
  1480 0000346F 7305                <1> 	JNC	short RWV_END		; CY = 0 NO RETRY
  1481 00003471 E928FFFFFF          <1>         JMP     DO_AGAIN                ; CY = 1 MEANS RETRY
  1482                              <1> RWV_END:
  1483 00003476 E8F4020000          <1> 	CALL	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
  1484 0000347B E887030000          <1> 	CALL	NUM_TRANS		; AL = NUMBER TRANSFERRED
  1485                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
  1486 00003480 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  1487 00003482 E879FEFFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1488 00003487 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  1489 00003489 E8B1030000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1490 0000348E C3                  <1> 	RETn
  1491                              <1> 
  1492                              <1> ;-------------------------------------------------------------------------------
  1493                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  1494                              <1> ;-------------------------------------------------------------------------------
  1495                              <1> SETUP_STATE:
  1496 0000348F F687[5D200100]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; MEDIA DETERMINED ?
  1497 00003496 7537                <1> 	JNZ	short J1C		; NO STATES IF DETERMINED
  1498 00003498 66B84000            <1>         MOV     AX,(RATE_500*256)+RATE_300  ; AH = START RATE, AL = END RATE
  1499 0000349C F687[5D200100]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE ?
  1500 000034A3 740D                <1> 	JZ	short AX_SET		; DO NOT KNOW DRIVE
  1501 000034A5 F687[5D200100]02    <1> 	TEST	byte [DSK_STATE+eDI], FMT_CAPA ; MULTI-RATE?
  1502 000034AC 7504                <1> 	JNZ	short AX_SET		; JUMP IF YES
  1503 000034AE 66B88080            <1>         MOV     AX,RATE_250*257         ; START A END RATE 250 FOR 360 DRIVE
  1504                              <1> AX_SET:	
  1505 000034B2 80A7[5D200100]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  1506 000034B9 08A7[5D200100]      <1> 	OR	[DSK_STATE+eDI], AH	; RATE FIRST TO TRY
  1507 000034BF 8025[58200100]F3    <1> 	AND	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  1508 000034C6 C0C804              <1> 	ROR	AL,4			; TO OPERATION LAST RATE LOCATION
  1509 000034C9 0805[58200100]      <1> 	OR	[LASTRATE], AL		; LAST RATE
  1510                              <1> J1C:	
  1511 000034CF C3                  <1> 	RETn
  1512                              <1> 
  1513                              <1> ;-------------------------------------------------------------------------------
  1514                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  1515                              <1> ;-------------------------------------------------------------------------------
  1516                              <1> FMT_INIT:
  1517 000034D0 F687[5D200100]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; IS MEDIA ESTABLISHED
  1518 000034D7 7546                <1> 	JNZ	short F1_OUT		; IF SO RETURN
  1519 000034D9 E82C040000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  1520                              <1> 	;; 20/02/2015
  1521                              <1> 	;;JC	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  1522 000034DE 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  1523 000034E0 FEC8                <1> 	DEC	AL			; MAKE ZERO ORIGIN
  1524                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  1525 000034E2 8AA7[5D200100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; AH = CURRENT STATE
  1526 000034E8 80E40F              <1> 	AND	AH, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  1527 000034EB 08C0                <1> 	OR	AL,AL			; CHECK FOR 360
  1528 000034ED 7505                <1> 	JNZ	short N_360		; IF 360 WILL BE 0
  1529 000034EF 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; ESTABLISH MEDIA
  1530 000034F2 EB25                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  1531                              <1> N_360:	
  1532 000034F4 FEC8                <1> 	DEC	AL			; 1.2 M DRIVE
  1533 000034F6 7505                <1> 	JNZ	short N_12		; JUMP IF NOT
  1534                              <1> F1_RATE:
  1535 000034F8 80CC10              <1> 	OR	AH,MED_DET+RATE_500	; SET FORMAT RATE
  1536 000034FB EB1C                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  1537                              <1> N_12:	
  1538 000034FD FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 3
  1539 000034FF 750F                <1> 	JNZ	short N_720		; JUMP IF NOT
  1540 00003501 F6C404              <1> 	TEST	AH,DRV_DET		; IS DRIVE DETERMINED
  1541 00003504 7410                <1> 	JZ	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  1542 00003506 F6C402              <1> 	TEST	AH,FMT_CAPA		; IS 1.2M
  1543 00003509 740B                <1> 	JZ	short ISNT_12		; JUMP IF NOT
  1544 0000350B 80CC50              <1> 	OR	AH,MED_DET+RATE_300	; RATE 300
  1545 0000350E EB09                <1> 	JMP	SHORT SKP_STATE		; CONTINUE
  1546                              <1> N_720:
  1547 00003510 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 4
  1548 00003512 750C                <1> 	JNZ	short CL_DRV		; NO DRIVE, CMOS BAD
  1549 00003514 EBE2                <1> 	JMP	SHORT F1_RATE
  1550                              <1> ISNT_12: 
  1551 00003516 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; MUST BE RATE 250
  1552                              <1> 
  1553                              <1> SKP_STATE:
  1554 00003519 88A7[5D200100]      <1> 	MOV	[DSK_STATE+eDI], AH	; STORE AWAY
  1555                              <1> F1_OUT:
  1556 0000351F C3                  <1> 	RETn
  1557                              <1> CL_DRV:	
  1558 00003520 30E4                <1> 	XOR	AH,AH			; CLEAR STATE
  1559 00003522 EBF5                <1> 	JMP	SHORT SKP_STATE		; SAVE IT
  1560                              <1> 
  1561                              <1> ;-------------------------------------------------------------------------------
  1562                              <1> ; MED_CHANGE	
  1563                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  1564                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  1565                              <1> ;
  1566                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  1567                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  1568                              <1> ;-------------------------------------------------------------------------------
  1569                              <1> MED_CHANGE:
  1570 00003524 E888060000          <1> 	CALL	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  1571 00003529 7447                <1> 	JZ	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  1572 0000352B 80A7[5D200100]EF    <1> 	AND	byte [DSK_STATE+eDI], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  1573                              <1> 
  1574                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  1575                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  1576                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  1577                              <1> 
  1578 00003532 6689F9              <1> 	MOV	CX,DI			; CL = DRIVE 0
  1579 00003535 B001                <1> 	MOV	AL,1			; MOTOR ON BIT MASK
  1580 00003537 D2E0                <1> 	SHL	AL,CL			; TO APPROPRIATE POSITION
  1581 00003539 F6D0                <1> 	NOT	AL			; KEEP ALL BUT MOTOR ON
  1582 0000353B FA                  <1> 	CLI				; NO INTERRUPTS
  1583 0000353C 2005[4E200100]      <1> 	AND	[MOTOR_STATUS], AL	; TURN MOTOR OFF INDICATOR
  1584 00003542 FB                  <1> 	STI				; INTERRUPTS ENABLED
  1585 00003543 E810040000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON
  1586                              <1> 
  1587                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  1588                              <1> 
  1589 00003548 E86DF9FFFF          <1> 	CALL	DSK_RESET		; RESET NEC
  1590 0000354D B501                <1> 	MOV	CH,01H			; MOVE TO CYLINDER 1
  1591 0000354F E8FF040000          <1> 	CALL	SEEK			; ISSUE SEEK
  1592 00003554 30ED                <1> 	XOR	CH,CH			; MOVE TO CYLINDER 0
  1593 00003556 E8F8040000          <1> 	CALL	SEEK			; ISSUE SEEK
  1594 0000355B C605[50200100]06    <1> 	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  1595                              <1> OK1:
  1596 00003562 E84A060000          <1> 	CALL	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  1597 00003567 7407                <1> 	JZ	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  1598                              <1> OK4:
  1599 00003569 C605[50200100]80    <1> 	MOV	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  1600                              <1> OK2:		
  1601 00003570 F9                  <1> 	STC				; MEDIA CHANGED, SET CY
  1602 00003571 C3                  <1> 	RETn
  1603                              <1> MC_OUT:
  1604 00003572 F8                  <1> 	CLC				; NO MEDIA CHANGED, CLEAR CY
  1605 00003573 C3                  <1> 	RETn
  1606                              <1> 
  1607                              <1> ;-------------------------------------------------------------------------------
  1608                              <1> ; SEND_RATE
  1609                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  1610                              <1> ; ON ENTRY:	DI = DRIVE #
  1611                              <1> ; ON EXIT:	NONE
  1612                              <1> ; REGISTERS ALTERED: DX
  1613                              <1> ;-------------------------------------------------------------------------------
  1614                              <1> SEND_RATE:
  1615 00003574 6650                <1> 	PUSH	AX			; SAVE REG.
  1616 00003576 8025[58200100]3F    <1> 	AND	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  1617 0000357D 8A87[5D200100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1618 00003583 24C0                <1> 	AND	AL,SEND_MSK		; KEEP ONLY RATE BITS
  1619 00003585 0805[58200100]      <1> 	OR	[LASTRATE], AL		; SAVE NEW RATE FOR NEXT CHECK
  1620 0000358B C0C002              <1> 	ROL	AL,2			; MOVE TO BIT OUTPUT POSITIONS
  1621 0000358E 66BAF703            <1> 	MOV	DX,03F7H		; OUTPUT NEW DATA RATE
  1622 00003592 EE                  <1> 	OUT	DX,AL
  1623 00003593 6658                <1> 	POP	AX			; RESTORE REG.
  1624 00003595 C3                  <1> 	RETn
  1625                              <1> 
  1626                              <1> ;-------------------------------------------------------------------------------
  1627                              <1> ; CHK_LASTRATE
  1628                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  1629                              <1> ; ON ENTRY:
  1630                              <1> ;	DI = DRIVE #
  1631                              <1> ; ON EXIT:
  1632                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  1633                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  1634                              <1> ; REGISTERS ALTERED: DX
  1635                              <1> ;-------------------------------------------------------------------------------
  1636                              <1> CHK_LASTRATE:
  1637 00003596 6650                <1> 	PUSH	AX			; SAVE REG
  1638 00003598 2225[58200100]      <1> 	AND	AH, [LASTRATE]		; GET LAST DATA RATE SELECTED
  1639 0000359E 8A87[5D200100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1640 000035A4 6625C0C0            <1>         AND     AX, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  1641 000035A8 38E0                <1> 	CMP	AL, AH			; COMPARE TO PREVIOUSLY TRIED
  1642                              <1> 					; ZF = 1 RATE IS THE SAME
  1643 000035AA 6658                <1> 	POP	AX			; RESTORE REG.
  1644 000035AC C3                  <1> 	RETn
  1645                              <1> 
  1646                              <1> ;-------------------------------------------------------------------------------
  1647                              <1> ; DMA_SETUP
  1648                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  1649                              <1> ;
  1650                              <1> ; ON ENTRY:	AL = DMA COMMAND
  1651                              <1> ;
  1652                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1653                              <1> ;-------------------------------------------------------------------------------
  1654                              <1> 
  1655                              <1> ; SI = Head #, # of Sectors or DASD Type
  1656                              <1> 
  1657                              <1> ; 22/08/2015
  1658                              <1> ; 08/02/2015 - Protected Mode Modification
  1659                              <1> ; 06/02/2015 - 07/02/2015
  1660                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  1661                              <1> ; (DMA Addres = Physical Address)
  1662                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  1663                              <1> ;
  1664                              <1> 
  1665                              <1> 
  1666                              <1> ; 04/02/2016 (clc)
  1667                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  1668                              <1> ; 16/12/2014 (IODELAY)
  1669                              <1> 
  1670                              <1> DMA_SETUP:
  1671                              <1> 
  1672                              <1> ;; 20/02/2015
  1673 000035AD 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  1674 000035B0 F7C2000000FF        <1> 	test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  1675 000035B6 756E                <1> 	jnz	short dma_bnd_err_stc
  1676                              <1> 	;
  1677 000035B8 6650                <1> 	push	ax			; DMA command
  1678 000035BA 52                  <1> 	push	edx			; *
  1679 000035BB B203                <1> 	mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  1680 000035BD E851030000          <1> 	call	GET_PARM		; 
  1681 000035C2 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  1682 000035C4 6689F0              <1> 	mov	ax, si			; Sector count
  1683 000035C7 88C4                <1> 	mov	ah, al			; AH =  # OF SECTORS
  1684 000035C9 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  1685 000035CB 66D1E8              <1> 	shr	ax, 1			; AX = # SECTORS * 128
  1686 000035CE 66D3E0              <1> 	shl	ax, cl			; SHIFT BY PARAMETER VALUE
  1687 000035D1 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  1688 000035D3 6689C1              <1> 	mov	cx, ax
  1689 000035D6 5A                  <1> 	pop	edx			; *
  1690 000035D7 6658                <1> 	pop	ax
  1691 000035D9 3C42                <1> 	cmp	al, 42h
  1692 000035DB 7507                <1>         jne     short NOT_VERF
  1693 000035DD BA0000FF00          <1> 	mov	edx, 0FF0000h
  1694 000035E2 EB08                <1> 	jmp	short J33
  1695                              <1> NOT_VERF:
  1696 000035E4 6601CA              <1> 	add	dx, cx			; check for overflow
  1697 000035E7 723E                <1> 	jc	short dma_bnd_err
  1698                              <1> 	;
  1699 000035E9 6629CA              <1> 	sub	dx, cx			; Restore start address
  1700                              <1> J33:
  1701 000035EC FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1702 000035ED E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1703                              <1> 	IODELAY				; WAIT FOR I/O
  1703 000035EF EB00                <2>  jmp short $+2
  1703 000035F1 EB00                <2>  jmp short $+2
  1704 000035F3 E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1705 000035F5 89D0                <1> 	mov	eax, edx		; Buffer address
  1706 000035F7 E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1707                              <1> 	IODELAY				; WAIT FOR I/O
  1707 000035F9 EB00                <2>  jmp short $+2
  1707 000035FB EB00                <2>  jmp short $+2
  1708 000035FD 88E0                <1> 	MOV	AL,AH
  1709 000035FF E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1710 00003601 C1E810              <1> 	shr	eax, 16
  1711                              <1> 	IODELAY				; I/O WAIT STATE
  1711 00003604 EB00                <2>  jmp short $+2
  1711 00003606 EB00                <2>  jmp short $+2
  1712 00003608 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  1713                              <1> 	IODELAY
  1713 0000360A EB00                <2>  jmp short $+2
  1713 0000360C EB00                <2>  jmp short $+2
  1714 0000360E 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  1715 00003611 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1716                              <1> 	IODELAY				; WAIT FOR I/O
  1716 00003613 EB00                <2>  jmp short $+2
  1716 00003615 EB00                <2>  jmp short $+2
  1717 00003617 88E0                <1> 	MOV	AL, AH
  1718 00003619 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1719                              <1> 	IODELAY
  1719 0000361B EB00                <2>  jmp short $+2
  1719 0000361D EB00                <2>  jmp short $+2
  1720 0000361F FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  1721 00003620 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  1722 00003622 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1723                              <1> 
  1724 00003624 F8                  <1> 	clc	; 04/02/2016
  1725 00003625 C3                  <1> 	retn
  1726                              <1> 
  1727                              <1> dma_bnd_err_stc:
  1728 00003626 F9                  <1> 	stc
  1729                              <1> dma_bnd_err:
  1730 00003627 C605[50200100]09    <1> 	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1731 0000362E C3                  <1> 	RETn				; CY SET BY ABOVE IF ERROR
  1732                              <1> 
  1733                              <1> ;; 16/12/2014
  1734                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1735                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1736                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1737                              <1> ;;	IODELAY
  1738                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1739                              <1> ;;	;SIODELAY
  1740                              <1> ;;      ;CMP	AL, 42H			; DMA VERIFY COMMAND
  1741                              <1> ;;      ;JNE	short NOT_VERF		; NO
  1742                              <1> ;;      ;XOR	AX, AX			; START ADDRESS
  1743                              <1> ;;      ;JMP	SHORT J33
  1744                              <1> ;;;NOT_VERF:	
  1745                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  1746                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  1747                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  1748                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  1749                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  1750                              <1> ;;	mov	eax, [ebp+4] ; 06/02/2015	
  1751                              <1> ;;	;JNC	short J33
  1752                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  1753                              <1> ;;;J33:
  1754                              <1> ;;	PUSH	eAX			; SAVE START ADDRESS
  1755                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1756                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1757                              <1> ;;	IODELAY
  1758                              <1> ;;	MOV	AL,AH
  1759                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1760                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  1761                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  1762                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  1763                              <1> ;;	IODELAY
  1764                              <1> ;;	;AND	AL,00001111B
  1765                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  1766                              <1> ;;	;SIODELAY
  1767                              <1> ;;
  1768                              <1> ;;;----- DETERMINE COUNT
  1769                              <1> ;;	sub	eax, eax ; 08/02/2015
  1770                              <1> ;;	MOV	AX, SI			; AL =  # OF SECTORS
  1771                              <1> ;;	XCHG	AL, AH			; AH =  # OF SECTORS
  1772                              <1> ;;	SUB	AL, AL			; AL = 0, AX = # SECTORS * 256
  1773                              <1> ;;	SHR	AX, 1			; AX = # SECTORS * 128
  1774                              <1> ;;	PUSH	AX			; SAVE # OF SECTORS * 128
  1775                              <1> ;;	MOV	DL, 3			; GET BYTES/SECTOR PARAMETER
  1776                              <1> ;;	CALL	GET_PARM		; "
  1777                              <1> ;;	MOV	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  1778                              <1> ;;	POP	AX			; AX = # SECTORS * 128
  1779                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  1780                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  1781                              <1> ;;	PUSH	eAX  ; 08/02/2015	; SAVE COUNT VALUE
  1782                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1783                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1784                              <1> ;;	IODELAY
  1785                              <1> ;;	MOV	AL, AH
  1786                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1787                              <1> ;;	;IODELAY
  1788                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  1789                              <1> ;;	POP	eCX  ; 08/02/2015 	; RECOVER COUNT VALUE
  1790                              <1> ;;	POP	eAX  ; 08/02/2015	; RECOVER ADDRESS VALUE
  1791                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  1792                              <1> ;;	add	ecx, eax ; 08/02/2015
  1793                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  1794                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1795                              <1> ;;	SIODELAY
  1796                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1797                              <1> ;;	;JNC	short NO_BAD		; CHECK FOR ERROR
  1798                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  1799                              <1> ;;	and	ecx, 0FFF00000h ; 16 MB limit
  1800                              <1> ;;	jz	short NO_BAD
  1801                              <1> ;;dma_bnd_err:
  1802                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1803                              <1> ;;NO_BAD:
  1804                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  1805                              <1> 
  1806                              <1> ;-------------------------------------------------------------------------------
  1807                              <1> ; FMTDMA_SET
  1808                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  1809                              <1> ;
  1810                              <1> ; ON ENTRY:	NOTHING REQUIRED
  1811                              <1> ;
  1812                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1813                              <1> ;-------------------------------------------------------------------------------
  1814                              <1> 
  1815                              <1> FMTDMA_SET:
  1816                              <1> ;; 20/02/2015 modification	
  1817 0000362F 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  1818 00003632 F7C20000F0FF        <1> 	test	edx, 0FFF00000h		; 16 MB limit
  1819 00003638 75EC                <1> 	jnz	short dma_bnd_err_stc
  1820                              <1> 	;
  1821 0000363A 6652                <1> 	push	dx			; *
  1822 0000363C B204                <1> 	mov	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  1823 0000363E E8D0020000          <1> 	call	GET_PARM		; "
  1824 00003643 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  1825 00003645 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  1826 00003647 66C1E002            <1> 	shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  1827 0000364B 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  1828 0000364D 6689C1              <1> 	mov	cx, ax
  1829 00003650 665A                <1> 	pop	dx			; *
  1830 00003652 6601CA              <1> 	add	dx, cx			; check for overflow
  1831 00003655 72D0                <1> 	jc	short dma_bnd_err
  1832                              <1> 	;
  1833 00003657 6629CA              <1> 	sub	dx, cx			; Restore start address
  1834                              <1> 	;
  1835 0000365A B04A                <1> 	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  1836 0000365C FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1837 0000365D E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1838                              <1> 	IODELAY				; WAIT FOR I/O
  1838 0000365F EB00                <2>  jmp short $+2
  1838 00003661 EB00                <2>  jmp short $+2
  1839 00003663 E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1840 00003665 89D0                <1> 	mov	eax, edx		; Buffer address
  1841 00003667 E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1842                              <1> 	IODELAY				; WAIT FOR I/O
  1842 00003669 EB00                <2>  jmp short $+2
  1842 0000366B EB00                <2>  jmp short $+2
  1843 0000366D 88E0                <1> 	MOV	AL,AH
  1844 0000366F E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1845 00003671 C1E810              <1> 	shr	eax, 16
  1846                              <1> 	IODELAY				; I/O WAIT STATE
  1846 00003674 EB00                <2>  jmp short $+2
  1846 00003676 EB00                <2>  jmp short $+2
  1847 00003678 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  1848                              <1> 	IODELAY
  1848 0000367A EB00                <2>  jmp short $+2
  1848 0000367C EB00                <2>  jmp short $+2
  1849 0000367E 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  1850 00003681 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1851                              <1> 	IODELAY				; WAIT FOR I/O
  1851 00003683 EB00                <2>  jmp short $+2
  1851 00003685 EB00                <2>  jmp short $+2
  1852 00003687 88E0                <1> 	MOV	AL, AH
  1853 00003689 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1854                              <1> 	IODELAY
  1854 0000368B EB00                <2>  jmp short $+2
  1854 0000368D EB00                <2>  jmp short $+2
  1855 0000368F FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  1856 00003690 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  1857 00003692 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1858 00003694 C3                  <1> 	retn
  1859                              <1> 
  1860                              <1> ;; 08/02/2015 - Protected Mode Modification
  1861                              <1> ;;	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  1862                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1863                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1864                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1865                              <1> ;;	IODELAY
  1866                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1867                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  1868                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  1869                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  1870                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  1871                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  1872                              <1> ;;	;JNC	short J33A
  1873                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  1874                              <1> ;;	mov	eax, [ebp+4] ; 08/02/2015
  1875                              <1> ;;;J33A:
  1876                              <1> ;;	PUSH	eAX ; 08/02/2015	; SAVE START ADDRESS
  1877                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1878                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1879                              <1> ;;	IODELAY
  1880                              <1> ;;	MOV	AL,AH
  1881                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1882                              <1> ;;	shr 	eax, 16 ; 08/02/2015
  1883                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  1884                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  1885                              <1> ;;	IODELAY
  1886                              <1> ;;	;AND	AL,00001111B
  1887                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  1888                              <1> ;;
  1889                              <1> ;;;----- DETERMINE COUNT
  1890                              <1> ;;	sub	eax, eax ; 08/02/2015
  1891                              <1> ;;	MOV	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  1892                              <1> ;;	CALL	GET_PARM		; "
  1893                              <1> ;;	XCHG	AL, AH			; AL = SECTORS/TRACK VALUE
  1894                              <1> ;;	SUB	AH, AH			; AX = SECTORS/TRACK VALUE
  1895                              <1> ;;	SHL	AX, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  1896                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  1897                              <1> ;;	PUSH	eAX 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  1898                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1899                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1900                              <1> ;;	IODELAY
  1901                              <1> ;;	MOV	AL, AH
  1902                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1903                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  1904                              <1> ;;	POP	eCX	; 08/02/2015	; RECOVER COUNT VALUE
  1905                              <1> ;;	POP	eAX	; 08/02/2015	; RECOVER ADDRESS VALUE
  1906                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  1907                              <1> ;;	add	ecx, eax ; 08/02/2015
  1908                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  1909                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1910                              <1> ;;	SIODELAY
  1911                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1912                              <1> ;;	;JNC	short FMTDMA_OK		; CHECK FOR ERROR
  1913                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  1914                              <1> ;;	and	ecx, 0FFF00000h  ; 16 MB limit
  1915                              <1> ;;	jz	short FMTDMA_OK
  1916                              <1> ;;	stc	; 20/02/2015
  1917                              <1> ;;fmtdma_bnd_err:
  1918                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1919                              <1> ;;FMTDMA_OK:
  1920                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  1921                              <1> 
  1922                              <1> ;-------------------------------------------------------------------------------
  1923                              <1> ; NEC_INIT	
  1924                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  1925                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  1926                              <1> ;
  1927                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  1928                              <1> ;
  1929                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1930                              <1> ;-------------------------------------------------------------------------------
  1931                              <1> NEC_INIT:
  1932 00003695 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1933 00003697 E8BC020000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  1934                              <1> 
  1935                              <1> ;-----	DO THE SEEK OPERATION
  1936                              <1> 
  1937 0000369C 8A6D01              <1> 	MOV	CH,[eBP+1]		; CH = TRACK #
  1938 0000369F E8AF030000          <1> 	CALL	SEEK			; MOVE TO CORRECT TRACK
  1939 000036A4 6658                <1> 	POP	AX			; RECOVER COMMAND
  1940 000036A6 721E                <1> 	JC	short ER_1		; ERROR ON SEEK
  1941 000036A8 BB[C6360000]        <1> 	MOV	eBX, ER_1		; LOAD ERROR ADDRESS
  1942 000036AD 53                  <1> 	PUSH	eBX			; PUSH NEC_OUT ERROR RETURN
  1943                              <1> 
  1944                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  1945                              <1> 
  1946 000036AE E866030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  1947 000036B3 6689F0              <1> 	MOV	AX,SI			; AH = HEAD #
  1948 000036B6 89FB                <1> 	MOV	eBX,eDI			; BL = DRIVE #
  1949 000036B8 C0E402              <1> 	SAL	AH,2			; MOVE IT TO BIT 2
  1950 000036BB 80E404              <1> 	AND	AH,00000100B		; ISOLATE THAT BIT
  1951 000036BE 08DC                <1> 	OR	AH,BL			; OR IN THE DRIVE NUMBER
  1952 000036C0 E854030000          <1> 	CALL	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  1953 000036C5 5B                  <1> 	POP	eBX			; THROW AWAY ERROR RETURN
  1954                              <1> ER_1:
  1955 000036C6 C3                  <1> 	RETn
  1956                              <1> 
  1957                              <1> ;-------------------------------------------------------------------------------
  1958                              <1> ; RWV_COM
  1959                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  1960                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  1961                              <1> ;
  1962                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  1963                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1964                              <1> ;-------------------------------------------------------------------------------
  1965                              <1> RWV_COM:
  1966 000036C7 B8[12370000]        <1> 	MOV	eAX, ER_2		; LOAD ERROR ADDRESS
  1967 000036CC 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1968 000036CD 8A6501              <1> 	MOV	AH,[eBP+1]		; OUTPUT TRACK #
  1969 000036D0 E844030000          <1> 	CALL	NEC_OUTPUT
  1970 000036D5 6689F0              <1> 	MOV	AX,SI			; OUTPUT HEAD #
  1971 000036D8 E83C030000          <1> 	CALL	NEC_OUTPUT
  1972 000036DD 8A6500              <1>         MOV     AH,[eBP]                ; OUTPUT SECTOR #
  1973 000036E0 E834030000          <1> 	CALL	NEC_OUTPUT
  1974 000036E5 B203                <1> 	MOV	DL,3			; BYTES/SECTOR PARAMETER FROM BLOCK
  1975 000036E7 E827020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  1976 000036EC E828030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1977 000036F1 B204                <1> 	MOV	DL,4			; EOT PARAMETER FROM BLOCK
  1978 000036F3 E81B020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  1979 000036F8 E81C030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1980 000036FD 8A6305              <1>         MOV     AH, [eBX+MD.GAP]        ; GET GAP LENGTH
  1981                              <1> _R15:
  1982 00003700 E814030000          <1> 	CALL	NEC_OUTPUT
  1983 00003705 B206                <1> 	MOV	DL,6			; DTL PARAMETER PROM BLOCK
  1984 00003707 E807020000          <1> 	CALL	GET_PARM		;  TO THE NEC
  1985 0000370C E808030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1986 00003711 58                  <1> 	POP	eAX			; THROW AWAY ERROR EXIT
  1987                              <1> ER_2:
  1988 00003712 C3                  <1> 	RETn
  1989                              <1> 
  1990                              <1> ;-------------------------------------------------------------------------------
  1991                              <1> ; NEC_TERM
  1992                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  1993                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  1994                              <1> ;
  1995                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1996                              <1> ;-------------------------------------------------------------------------------
  1997                              <1> NEC_TERM:
  1998                              <1> 
  1999                              <1> ;-----	LET THE OPERATION HAPPEN
  2000                              <1> 
  2001 00003713 56                  <1> 	PUSH	eSI			; SAVE HEAD #, # OF SECTORS
  2002 00003714 E80D040000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  2003 00003719 9C                  <1> 	PUSHF
  2004 0000371A E837040000          <1> 	CALL	RESULTS			; GET THE NEC STATUS
  2005 0000371F 724B                <1> 	JC	short SET_END_POP
  2006 00003721 9D                  <1> 	POPF
  2007 00003722 723E                <1> 	JC	short SET_END		; LOOK FOR ERROR
  2008                              <1> 
  2009                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  2010                              <1> 
  2011 00003724 FC                  <1> 	CLD				; SET THE CORRECT DIRECTION
  2012 00003725 BE[51200100]        <1> 	MOV	eSI, NEC_STATUS		; POINT TO STATUS FIELD
  2013 0000372A AC                  <1> 	lodsb				; GET ST0
  2014 0000372B 24C0                <1> 	AND	AL,11000000B		; TEST FOR NORMAL TERMINATION
  2015 0000372D 7433                <1> 	JZ	short SET_END
  2016 0000372F 3C40                <1> 	CMP	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  2017 00003731 7527                <1> 	JNZ	short J18		; NOT ABNORMAL, BAD NEC
  2018                              <1> 
  2019                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  2020                              <1> 
  2021 00003733 AC                  <1> 	lodsb				; GET ST1
  2022 00003734 D0E0                <1> 	SAL	AL,1			; TEST FOR EDT FOUND
  2023 00003736 B404                <1> 	MOV	AH,RECORD_NOT_FND
  2024 00003738 7222                <1> 	JC	short J19
  2025 0000373A C0E002              <1> 	SAL	AL,2
  2026 0000373D B410                <1> 	MOV	AH,BAD_CRC
  2027 0000373F 721B                <1> 	JC	short J19
  2028 00003741 D0E0                <1> 	SAL	AL,1			; TEST FOR DMA OVERRUN
  2029 00003743 B408                <1> 	MOV	AH,BAD_DMA
  2030 00003745 7215                <1> 	JC	short J19
  2031 00003747 C0E002              <1> 	SAL	AL,2			; TEST FOR RECORD NOT FOUND
  2032 0000374A B404                <1> 	MOV	AH,RECORD_NOT_FND
  2033 0000374C 720E                <1> 	JC	short J19
  2034 0000374E D0E0                <1> 	SAL	AL,1
  2035 00003750 B403                <1> 	MOV	AH,WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  2036 00003752 7208                <1> 	JC	short J19
  2037 00003754 D0E0                <1> 	SAL	AL,1			; TEST MISSING ADDRESS MARK
  2038 00003756 B402                <1> 	MOV	AH,BAD_ADDR_MARK
  2039 00003758 7202                <1> 	JC	short J19
  2040                              <1> 
  2041                              <1> ;----- 	NEC MUST HAVE FAILED
  2042                              <1> J18:
  2043 0000375A B420                <1> 	MOV	AH,BAD_NEC
  2044                              <1> J19:
  2045 0000375C 0825[50200100]      <1> 	OR	[DSKETTE_STATUS], AH
  2046                              <1> SET_END:
  2047 00003762 803D[50200100]01    <1> 	CMP	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  2048 00003769 F5                  <1> 	CMC
  2049 0000376A 5E                  <1> 	POP	eSI
  2050 0000376B C3                  <1> 	RETn				; RESTORE HEAD #, # OF SECTORS
  2051                              <1> 
  2052                              <1> SET_END_POP:
  2053 0000376C 9D                  <1> 	POPF
  2054 0000376D EBF3                <1> 	JMP	SHORT SET_END
  2055                              <1> 
  2056                              <1> ;-------------------------------------------------------------------------------
  2057                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  2058                              <1> ;-------------------------------------------------------------------------------
  2059                              <1> DSTATE:
  2060 0000376F 803D[50200100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  2061 00003776 753E                <1> 	JNZ	short SETBAC		    ; IF ERROR JUMP
  2062 00003778 808F[5D200100]10    <1> 	OR	byte [DSK_STATE+eDI],MED_DET ; NO ERROR, MARK MEDIA AS DETERMINED
  2063 0000377F F687[5D200100]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE DETERMINED ?
  2064 00003786 752E                <1> 	JNZ	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  2065 00003788 8A87[5D200100]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  2066 0000378E 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  2067 00003790 3C80                <1> 	CMP	AL,RATE_250		; RATE 250 ?
  2068 00003792 751B                <1> 	JNE	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  2069                              <1> 
  2070                              <1> ;----- 	CHECK IF IT IS 1.44M
  2071                              <1> 
  2072 00003794 E871010000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  2073                              <1> 	;;20/02/2015
  2074                              <1> 	;;JC	short M_12		; CMOS BAD
  2075 00003799 7414                <1> 	jz	short M_12 ;; 20/02/2015
  2076 0000379B 3C04                <1> 	CMP	AL, 4			; 1.44MB DRIVE ?
  2077 0000379D 7410                <1> 	JE	short M_12		; YES
  2078                              <1> M_720:
  2079 0000379F 80A7[5D200100]FD    <1> 	AND	byte [DSK_STATE+eDI], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  2080 000037A6 808F[5D200100]04    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET  ; MARK DRIVE DETERMINED
  2081 000037AD EB07                <1> 	JMP	SHORT SETBAC		; BACK
  2082                              <1> M_12:	
  2083 000037AF 808F[5D200100]06    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET+FMT_CAPA 
  2084                              <1> 					; TURN ON DETERMINED & FMT CAPA
  2085                              <1> SETBAC:
  2086 000037B6 C3                  <1> 	RETn
  2087                              <1> 
  2088                              <1> ;-------------------------------------------------------------------------------
  2089                              <1> ; RETRY	
  2090                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  2091                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  2092                              <1> ;
  2093                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  2094                              <1> ;-------------------------------------------------------------------------------
  2095                              <1> RETRY:
  2096 000037B7 803D[50200100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; GET STATUS OF OPERATION
  2097 000037BE 7445                <1> 	JZ	short NO_RETRY		; SUCCESSFUL OPERATION
  2098 000037C0 803D[50200100]80    <1> 	CMP	byte [DSKETTE_STATUS],TIME_OUT ; IF TIME OUT NO RETRY
  2099 000037C7 743C                <1> 	JZ	short NO_RETRY
  2100 000037C9 8AA7[5D200100]      <1> 	MOV	AH,[DSK_STATE+eDI]	; GET MEDIA STATE OF DRIVE
  2101 000037CF F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED/DETERMINED ?
  2102 000037D2 7531                <1> 	JNZ	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  2103 000037D4 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE RATE
  2104 000037D7 8A2D[58200100]      <1> 	MOV	CH,[LASTRATE]		; GET START OPERATION STATE
  2105 000037DD C0C504              <1> 	ROL	CH,4			; TO CORRESPONDING BITS
  2106 000037E0 80E5C0              <1> 	AND	CH,RATE_MSK		; ISOLATE RATE BITS
  2107 000037E3 38E5                <1> 	CMP	CH,AH			; ALL RATES TRIED
  2108 000037E5 741E                <1> 	JE	short NO_RETRY		; IF YES, THEN TRUE ERROR
  2109                              <1> 
  2110                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  2111                              <1> ;	 00000000B (500) -> 10000000B	(250)
  2112                              <1> ;	 10000000B (250) -> 01000000B	(300)
  2113                              <1> ;	 01000000B (300) -> 00000000B	(500)
  2114                              <1> 
  2115 000037E7 80FC01              <1> 	CMP	AH,RATE_500+1		; SET CY FOR RATE 500
  2116 000037EA D0DC                <1> 	RCR	AH,1			; TO NEXT STATE
  2117 000037EC 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE BITS
  2118 000037EF 80A7[5D200100]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP)
  2119                              <1> 					; RATE, DBL STEP OFF
  2120 000037F6 08A7[5D200100]      <1> 	OR	[DSK_STATE+eDI],AH	; TURN ON NEW RATE
  2121 000037FC C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; RESET STATUS FOR RETRY
  2122 00003803 F9                  <1> 	STC				; SET CARRY FOR RETRY
  2123 00003804 C3                  <1> 	RETn				; RETRY RETURN
  2124                              <1> 
  2125                              <1> NO_RETRY:
  2126 00003805 F8                  <1> 	CLC				; CLEAR CARRY NO RETRY
  2127 00003806 C3                  <1> 	RETn				; NO RETRY RETURN
  2128                              <1> 
  2129                              <1> ;-------------------------------------------------------------------------------
  2130                              <1> ; NUM_TRANS
  2131                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  2132                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  2133                              <1> ;
  2134                              <1> ; ON ENTRY:	[BP+1] = TRACK
  2135                              <1> ;		SI-HI  = HEAD
  2136                              <1> ;		[BP]   = START SECTOR
  2137                              <1> ;
  2138                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  2139                              <1> ;-------------------------------------------------------------------------------
  2140                              <1> NUM_TRANS:
  2141 00003807 30C0                <1> 	XOR	AL,AL			; CLEAR FOR ERROR
  2142 00003809 803D[50200100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  2143 00003810 752C                <1> 	JNZ	NT_OUT			; IF ERROR 0 TRANSFERRED
  2144 00003812 B204                <1> 	MOV	DL,4			; SECTORS/TRACK OFFSET TO DL
  2145 00003814 E8FA000000          <1> 	CALL	GET_PARM		; AH = SECTORS/TRACK
  2146 00003819 8A1D[56200100]      <1> 	MOV	BL, [NEC_STATUS+5]	; GET ENDING SECTOR
  2147 0000381F 6689F1              <1> 	MOV	CX,SI			; CH = HEAD # STARTED
  2148 00003822 3A2D[55200100]      <1> 	CMP	CH, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  2149 00003828 750D                <1> 	JNZ	DIF_HD			; IF ON SAME HEAD, THEN NO ADJUST
  2150 0000382A 8A2D[54200100]      <1> 	MOV	CH, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  2151 00003830 3A6D01              <1> 	CMP	CH,[eBP+1]		; IS IT ASKED FOR TRACK
  2152 00003833 7404                <1> 	JZ	short SAME_TRK		; IF SAME TRACK NO INCREASE
  2153 00003835 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  2154                              <1> DIF_HD:
  2155 00003837 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  2156                              <1> SAME_TRK:
  2157 00003839 2A5D00              <1> 	SUB	BL,[eBP]		; SUBTRACT START FROM END
  2158 0000383C 88D8                <1> 	MOV	AL,BL			; TO AL
  2159                              <1> NT_OUT:
  2160 0000383E C3                  <1> 	RETn
  2161                              <1> 
  2162                              <1> ;-------------------------------------------------------------------------------
  2163                              <1> ; SETUP_END
  2164                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
  2165                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
  2166                              <1> ;
  2167                              <1> ; ON EXIT:
  2168                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2169                              <1> ;-------------------------------------------------------------------------------
  2170                              <1> SETUP_END:
  2171 0000383F B202                <1> 	MOV	DL,2			; GET THE MOTOR WAIT PARAMETER
  2172 00003841 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  2173 00003843 E8CB000000          <1> 	CALL	GET_PARM
  2174 00003848 8825[4F200100]      <1> 	MOV	[MOTOR_COUNT],AH	; STORE UPON RETURN
  2175 0000384E 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  2176 00003850 8A25[50200100]      <1> 	MOV	AH, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  2177 00003856 08E4                <1> 	OR	AH,AH			; CHECK FOR ERROR
  2178 00003858 7402                <1> 	JZ	short NUN_ERR		; NO ERROR
  2179 0000385A 30C0                <1> 	XOR	AL,AL			; CLEAR NUMBER RETURNED
  2180                              <1> NUN_ERR: 
  2181 0000385C 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  2182 0000385F F5                  <1> 	CMC				; SUCCESS OR FAILURE
  2183 00003860 C3                  <1> 	RETn
  2184                              <1> 
  2185                              <1> ;-------------------------------------------------------------------------------
  2186                              <1> ; SETUP_DBL
  2187                              <1> ;	CHECK DOUBLE STEP.
  2188                              <1> ;
  2189                              <1> ; ON ENTRY :	DI = DRIVE
  2190                              <1> ;
  2191                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  2192                              <1> ;-------------------------------------------------------------------------------
  2193                              <1> SETUP_DBL:
  2194 00003861 8AA7[5D200100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  2195 00003867 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED STATE ?
  2196 0000386A 757E                <1> 	JNZ	short NO_DBL			; IF ESTABLISHED THEN DOUBLE DONE
  2197                              <1> 
  2198                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  2199                              <1> 
  2200 0000386C C605[4D200100]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  2201 00003873 E8E0000000          <1> 	CALL	MOTOR_ON		; ENSURE MOTOR STAY ON
  2202 00003878 B500                <1> 	MOV	CH,0			; LOAD TRACK 0
  2203 0000387A E8D4010000          <1> 	CALL	SEEK			; SEEK TO TRACK 0
  2204 0000387F E868000000          <1> 	CALL	READ_ID			; READ ID FUNCTION
  2205 00003884 7249                <1> 	JC	short SD_ERR		; IF ERROR NO TRACK 0
  2206                              <1> 
  2207                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  2208                              <1> 
  2209 00003886 66B95004            <1> 	MOV	CX,0450H 		; START, MAX TRACKS
  2210 0000388A F687[5D200100]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  2211 00003891 7402                <1> 	JZ	short CNT_OK		; IF NOT COUNT IS SETUP
  2212 00003893 B1A0                <1> 	MOV	CL,0A0H			; MAXIMUM TRACK 1.2 MB
  2213                              <1> 
  2214                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  2215                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  2216                              <1> ;	THEN SET DOUBLE STEP ON.
  2217                              <1> 
  2218                              <1> CNT_OK:
  2219 00003895 C605[4F200100]FF    <1>         MOV     byte [MOTOR_COUNT], 0FFH ; ENSURE MOTOR STAYS ON FOR OPERATION 
  2220 0000389C 6651                <1> 	PUSH	CX			; SAVE TRACK, COUNT
  2221 0000389E C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR STATUS, EXPECT ERRORS
  2222 000038A5 6631C0              <1> 	XOR	AX,AX			; CLEAR AX
  2223 000038A8 D0ED                <1> 	SHR	CH,1			; HALVE TRACK, CY = HEAD
  2224 000038AA C0D003              <1> 	RCL	AL,3			; AX = HEAD IN CORRECT BIT
  2225 000038AD 6650                <1> 	PUSH	AX			; SAVE HEAD
  2226 000038AF E89F010000          <1> 	CALL	SEEK			; SEEK TO TRACK
  2227 000038B4 6658                <1> 	POP	AX			; RESTORE HEAD
  2228 000038B6 6609C7              <1> 	OR	DI,AX			; DI = HEAD OR'ED DRIVE
  2229 000038B9 E82E000000          <1> 	CALL	READ_ID			; READ ID HEAD 0
  2230 000038BE 9C                  <1> 	PUSHF				; SAVE RETURN FROM READ_ID
  2231 000038BF 6681E7FB00          <1> 	AND	DI,11111011B		; TURN OFF HEAD 1 BIT
  2232 000038C4 9D                  <1> 	POPF				; RESTORE ERROR RETURN
  2233 000038C5 6659                <1> 	POP	CX			; RESTORE COUNT
  2234 000038C7 7308                <1> 	JNC	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  2235 000038C9 FEC5                <1> 	INC	CH			; INC FOR NEXT TRACK
  2236 000038CB 38CD                <1> 	CMP	CH,CL			; REACHED MAXIMUM YET
  2237 000038CD 75C6                <1> 	JNZ	short CNT_OK		; CONTINUE TILL ALL TRIED
  2238                              <1> 
  2239                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  2240                              <1> 
  2241                              <1> SD_ERR:	
  2242 000038CF F9                  <1> 	STC				; SET CARRY FOR ERROR
  2243 000038D0 C3                  <1> 	RETn				; SETUP_DBL ERROR EXIT
  2244                              <1> 
  2245                              <1> DO_CHK:
  2246 000038D1 8A0D[54200100]      <1> 	MOV	CL, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  2247 000038D7 888F[61200100]      <1> 	MOV	[DSK_TRK+eDI], CL	; STORE TRACK NUMBER
  2248 000038DD D0ED                <1> 	SHR	CH,1			; HALVE TRACK
  2249 000038DF 38CD                <1> 	CMP	CH,CL			; IS IT THE SAME AS ASKED FOR TRACK
  2250 000038E1 7407                <1> 	JZ	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  2251 000038E3 808F[5D200100]20    <1> 	OR	byte [DSK_STATE+eDI],DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  2252                              <1> NO_DBL:
  2253 000038EA F8                  <1> 	CLC				; CLEAR ERROR FLAG
  2254 000038EB C3                  <1> 	RETn
  2255                              <1> 
  2256                              <1> ;-------------------------------------------------------------------------------
  2257                              <1> ; READ_ID
  2258                              <1> ;	READ ID FUNCTION.
  2259                              <1> ;
  2260                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  2261                              <1> ;
  2262                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  2263                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2264                              <1> ;-------------------------------------------------------------------------------
  2265                              <1> READ_ID:
  2266 000038EC B8[09390000]        <1> 	MOV	eAX, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  2267 000038F1 50                  <1> 	PUSH	eAX
  2268 000038F2 B44A                <1> 	MOV	AH,4AH			; READ ID COMMAND
  2269 000038F4 E820010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  2270 000038F9 6689F8              <1> 	MOV	AX,DI			; DRIVE # TO AH, HEAD 0
  2271 000038FC 88C4                <1> 	MOV	AH,AL
  2272 000038FE E816010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  2273 00003903 E80BFEFFFF          <1> 	CALL	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  2274 00003908 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  2275                              <1> ER_3:
  2276 00003909 C3                  <1> 	RETn
  2277                              <1> 
  2278                              <1> ;-------------------------------------------------------------------------------
  2279                              <1> ; CMOS_TYPE
  2280                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  2281                              <1> ;
  2282                              <1> ; ON ENTRY:	DI = DRIVE #
  2283                              <1> ;
  2284                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  2285                              <1> ;-------------------------------------------------------------------------------
  2286                              <1> 
  2287                              <1> CMOS_TYPE: ; 11/12/2014
  2288 0000390A 8A87[18ED0000]      <1> mov	al, [eDI+fd0_type]
  2289 00003910 20C0                <1> and 	al, al ; 18/12/2014
  2290 00003912 C3                  <1> retn
  2291                              <1> 
  2292                              <1> ;CMOS_TYPE:
  2293                              <1> ;	MOV	AL, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  2294                              <1> ;	CALL	CMOS_READ		; GET CMOS STATUS
  2295                              <1> ;	TEST	AL,BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  2296                              <1> ;	STC				; SET CY = 1 INDICATING ERROR FOR RETURN
  2297                              <1> ;	JNZ	short BAD_CM		; ERROR IF EITHER BIT ON
  2298                              <1> ;	MOV	AL,CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  2299                              <1> ;	CALL	CMOS_READ		; GET DISKETTE BYTE
  2300                              <1> ;	OR	DI,DI			; SEE WHICH DRIVE IN QUESTION
  2301                              <1> ;	JNZ	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  2302                              <1> ;	ROR	AL,4			; EXCHANGE NIBBLES IF SECOND DRIVE
  2303                              <1> ;TB:
  2304                              <1> ;	AND	AL,0FH			; KEEP ONLY DRIVE DATA, RESET CY, 0
  2305                              <1> ;BAD_CM:
  2306                              <1> ;	RETn				; CY, STATUS OF READ
  2307                              <1> 
  2308                              <1> ;-------------------------------------------------------------------------------
  2309                              <1> ; GET_PARM
  2310                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  2311                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  2312                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  2313                              <1> ;	THE PARAMETER IN DL.
  2314                              <1> ;
  2315                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  2316                              <1> ;
  2317                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  2318                              <1> ;		AL,DH DESTROYED
  2319                              <1> ;-------------------------------------------------------------------------------
  2320                              <1> GET_PARM:
  2321                              <1> 	;PUSH	DS
  2322 00003913 56                  <1> 	PUSH	eSI
  2323                              <1>     	;SUB	AX,AX			; DS = 0, BIOS DATA AREA
  2324                              <1>     	;MOV	DS,AX
  2325                              <1> 	;;mov	ax, cs
  2326                              <1> 	;;mov	ds, ax
  2327                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  2328 00003914 87D3                <1> 	XCHG	eDX,eBX			; BL = INDEX
  2329                              <1> 	;SUB	BH,BH			; BX = INDEX
  2330 00003916 81E3FF000000        <1> 	and	ebx, 0FFh
  2331                              <1>     	;LDS	SI, [DISK_POINTER]	; POINT TO BLOCK
  2332                              <1> 	;
  2333                              <1> 	; 17/12/2014
  2334 0000391C 66A1[0BED0000]      <1> 	mov	ax, [cfd] ; current (AL) and previous fd (AH)
  2335 00003922 38E0                <1> 	cmp	al, ah
  2336 00003924 7425                <1> 	je	short gpndc
  2337 00003926 A2[0CED0000]        <1> 	mov	[pfd], al ; current drive -> previous drive
  2338 0000392B 53                  <1> 	push	ebx ; 08/02/2015
  2339 0000392C 88C3                <1> 	mov	bl, al 
  2340                              <1> 	; 11/12/2014
  2341 0000392E 8A83[18ED0000]      <1> 	mov	al, [eBX+fd0_type]	; Drive type (0,1,2,3,4)
  2342                              <1> 	; 18/12/2014
  2343 00003934 20C0                <1> 	and	al, al
  2344 00003936 7507                <1> 	jnz	short gpdtc
  2345 00003938 BB[F5EC0000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  2346 0000393D EB05                <1>         jmp     short gpdpu
  2347                              <1> gpdtc:	
  2348 0000393F E817F9FFFF          <1> 	call	DR_TYPE_CHECK
  2349                              <1> 	; cf = 1 -> eBX points to 1.44MB fd parameter table (default)
  2350                              <1> gpdpu:
  2351 00003944 891D[92EC0000]      <1> 	mov	[DISK_POINTER], ebx
  2352 0000394A 5B                  <1> 	pop	ebx
  2353                              <1> gpndc:
  2354 0000394B 8B35[92EC0000]      <1> 	mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  2355 00003951 8A241E              <1> 	MOV	AH, [eSI+eBX]		; GET THE WORD
  2356 00003954 87D3                <1> 	XCHG	eDX,eBX			; RESTORE BX
  2357 00003956 5E                  <1> 	POP	eSI
  2358                              <1> 	;POP	DS
  2359 00003957 C3                  <1> 	RETn
  2360                              <1> 
  2361                              <1> ;-------------------------------------------------------------------------------
  2362                              <1> ; MOTOR_ON
  2363                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  2364                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  2365                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  2366                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  2367                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  2368                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  2369                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  2370                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  2371                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  2372                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  2373                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  2374                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  2375                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  2376                              <1> ;
  2377                              <1> ; ON ENTRY:	DI = DRIVE #
  2378                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  2379                              <1> ;-------------------------------------------------------------------------------
  2380                              <1> MOTOR_ON:
  2381 00003958 53                  <1> 	PUSH	eBX			; SAVE REG.
  2382 00003959 E82A000000          <1> 	CALL	TURN_ON			; TURN ON MOTOR
  2383 0000395E 7226                <1> 	JC	short MOT_IS_ON		; IF CY=1 NO WAIT
  2384 00003960 E89BF9FFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  2385 00003965 E865F9FFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  2386                              <1> 	;CALL	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  2387                              <1> 	;JC	MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  2388                              <1> M_WAIT:
  2389 0000396A B20A                <1> 	MOV	DL,10			; GET THE MOTOR WAIT PARAMETER
  2390 0000396C E8A2FFFFFF          <1> 	CALL	GET_PARM
  2391                              <1> 	;MOV	AL,AH			; AL = MOTOR WAIT PARAMETER
  2392                              <1> 	;XOR	AH,AH			; AX = MOTOR WAIT PARAMETER
  2393                              <1> 	;CMP	AL,8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  2394 00003971 80FC08              <1> 	cmp	ah, 8
  2395                              <1> 	;JAE	short GP2		; IF YES, CONTINUE
  2396 00003974 7702                <1> 	ja	short J13
  2397                              <1> 	;MOV	AL,8			; ONE SECOND WAIT FOR MOTOR START UP
  2398 00003976 B408                <1> 	mov	ah, 8
  2399                              <1> 
  2400                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  2401                              <1> GP2:	
  2402                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  2403                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  2404 00003978 B95E200000          <1> 	MOV	eCX,8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  2405 0000397D E8DAE2FFFF          <1> 	CALL	WAITF			; GO TO FIXED WAIT ROUTINE
  2406                              <1> 	;DEC	AL			; DECREMENT TIME VALUE
  2407 00003982 FECC                <1> 	dec	ah
  2408 00003984 75F2                <1> 	JNZ	short J13		; ARE WE DONE YET
  2409                              <1> MOT_IS_ON:
  2410 00003986 5B                  <1> 	POP	eBX			; RESTORE REG.
  2411 00003987 C3                  <1> 	RETn
  2412                              <1> 
  2413                              <1> ;-------------------------------------------------------------------------------
  2414                              <1> ; TURN_ON
  2415                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  2416                              <1> ;
  2417                              <1> ; ON ENTRY:	DI = DRIVE #
  2418                              <1> ;
  2419                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  2420                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  2421                              <1> ;		AX,BX,CX,DX DESTROYED
  2422                              <1> ;-------------------------------------------------------------------------------
  2423                              <1> TURN_ON:
  2424 00003988 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2425 0000398A 88D9                <1> 	MOV	CL,BL			; CL = DRIVE #
  2426 0000398C C0C304              <1> 	ROL	BL,4			; BL = DRIVE SELECT
  2427 0000398F FA                  <1> 	CLI				; NO INTERRUPTS WHILE DETERMINING STATUS
  2428 00003990 C605[4F200100]FF    <1> 	MOV	byte [MOTOR_COUNT],0FFH	; ENSURE MOTOR STAYS ON FOR OPERATION
  2429 00003997 A0[4E200100]        <1> 	MOV	AL, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  2430 0000399C 2430                <1> 	AND	AL,00110000B		; KEEP ONLY DRIVE SELECT BITS
  2431 0000399E B401                <1> 	MOV	AH,1			; MASK FOR DETERMINING MOTOR BIT
  2432 000039A0 D2E4                <1> 	SHL	AH,CL			; AH = MOTOR ON, A=00000001, B=00000010
  2433                              <1> 
  2434                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  2435                              <1> ;  BL = DRIVE SELECT DESIRED
  2436                              <1> ;  AH = MOTOR ON MASK DESIRED
  2437                              <1> 
  2438 000039A2 38D8                <1> 	CMP	AL,BL			; REQUESTED DRIVE ALREADY SELECTED ?
  2439 000039A4 7508                <1> 	JNZ	short TURN_IT_ON	; IF NOT SELECTED JUMP
  2440 000039A6 8425[4E200100]      <1> 	TEST	AH, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  2441 000039AC 7535                <1> 	JNZ	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  2442                              <1> 
  2443                              <1> TURN_IT_ON:
  2444 000039AE 08DC                <1> 	OR	AH,BL			; AH = DRIVE SELECT AND MOTOR ON
  2445 000039B0 8A3D[4E200100]      <1> 	MOV	BH,[MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  2446 000039B6 80E70F              <1> 	AND	BH,00001111B		; KEEP ONLY MOTOR BITS
  2447 000039B9 8025[4E200100]CF    <1> 	AND	byte [MOTOR_STATUS],11001111B ; CLEAR OUT DRIVE SELECT
  2448 000039C0 0825[4E200100]      <1> 	OR	[MOTOR_STATUS],AH	; OR IN DRIVE SELECTED AND MOTOR ON
  2449 000039C6 A0[4E200100]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  2450 000039CB 88C3                <1> 	MOV	BL,AL			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  2451 000039CD 80E30F              <1> 	AND	BL,00001111B		; KEEP ONLY MOTOR BITS
  2452 000039D0 FB                  <1> 	STI				; ENABLE INTERRUPTS AGAIN
  2453 000039D1 243F                <1> 	AND	AL,00111111B		; STRIP AWAY UNWANTED BITS
  2454 000039D3 C0C004              <1> 	ROL	AL,4			; PUT BITS IN DESIRED POSITIONS
  2455 000039D6 0C0C                <1> 	OR	AL,00001100B		; NO RESET, ENABLE DMA/INTERRUPT
  2456 000039D8 66BAF203            <1> 	MOV	DX,03F2H		; SELECT DRIVE AND TURN ON MOTOR
  2457 000039DC EE                  <1> 	OUT	DX,AL
  2458 000039DD 38FB                <1> 	CMP	BL,BH			; NEW MOTOR TURNED ON ?
  2459                              <1> 	;JZ	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  2460 000039DF 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  2461 000039E1 F8                  <1> 	CLC				; (re)SET CARRY MEANING WAIT
  2462 000039E2 C3                  <1> 	RETn
  2463                              <1> 
  2464                              <1> NO_MOT_WAIT:
  2465 000039E3 FB                  <1> 	sti
  2466                              <1> no_mot_w1: ; 27/02/2015
  2467 000039E4 F9                  <1> 	STC				; SET NO WAIT REQUIRED
  2468                              <1> 	;STI				; INTERRUPTS BACK ON
  2469 000039E5 C3                  <1> 	RETn
  2470                              <1> 
  2471                              <1> ;-------------------------------------------------------------------------------
  2472                              <1> ; HD_WAIT
  2473                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  2474                              <1> ;
  2475                              <1> ; ON ENTRY:	DI = DRIVE #
  2476                              <1> ;
  2477                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  2478                              <1> ;-------------------------------------------------------------------------------
  2479                              <1> HD_WAIT:
  2480 000039E6 B209                <1> 	MOV	DL,9			; GET HEAD SETTLE PARAMETER
  2481 000039E8 E826FFFFFF          <1> 	CALL	GET_PARM
  2482 000039ED 08E4                <1> 	or	ah, ah	; 17/12/2014
  2483 000039EF 7519                <1> 	jnz	short DO_WAT
  2484 000039F1 F605[4E200100]80    <1>         TEST    byte [MOTOR_STATUS],10000000B ; SEE IF A WRITE OPERATION
  2485                              <1> 	;JZ	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  2486                              <1> 	;OR	AH,AH			; CHECK FOR ANY WAIT?
  2487                              <1> 	;JNZ	short DO_WAT		; IF THERE DO NOT ENFORCE
  2488 000039F8 741E                <1> 	jz	short HW_DONE
  2489 000039FA B40F                <1> 	MOV	AH,HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  2490 000039FC 8A87[5D200100]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  2491 00003A02 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  2492 00003A04 3C80                <1> 	CMP	AL,RATE_250		; 1.2 M DRIVE ?
  2493 00003A06 7502                <1> 	JNZ	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  2494                              <1> ;GP3:
  2495 00003A08 B414                <1> 	MOV	AH,HD320_SETTLE		; USE 320/360 HEAD SETTLE
  2496                              <1> ;	JMP	SHORT DO_WAT
  2497                              <1> 
  2498                              <1> ;ISNT_WRITE:
  2499                              <1> ;	OR	AH,AH			; CHECK FOR NO WAIT
  2500                              <1> ;	JZ	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  2501                              <1> 
  2502                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  2503                              <1> DO_WAT:
  2504                              <1> ;	MOV	AL,AH			; AL = # MILLISECONDS
  2505                              <1> ;	;XOR	AH,AH			; AX = # MILLISECONDS
  2506                              <1> J29:					; 	1 MILLISECOND LOOP
  2507                              <1> 	;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  2508 00003A0A B942000000          <1> 	MOV	eCX,66			; COUNT AT 15.085737 US PER COUNT
  2509 00003A0F E848E2FFFF          <1> 	CALL	WAITF			; DELAY FOR 1 MILLISECOND
  2510                              <1> 	;DEC	AL			; DECREMENT THE COUNT
  2511 00003A14 FECC                <1> 	dec	ah
  2512 00003A16 75F2                <1> 	JNZ	short J29		; DO AL MILLISECOND # OF TIMES
  2513                              <1> HW_DONE:
  2514 00003A18 C3                  <1> 	RETn
  2515                              <1> 
  2516                              <1> ;-------------------------------------------------------------------------------
  2517                              <1> ; NEC_OUTPUT
  2518                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  2519                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  2520                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  2521                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  2522                              <1> ; 
  2523                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  2524                              <1> ;
  2525                              <1> ; ON EXIT:	CY = 0  SUCCESS
  2526                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  2527                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  2528                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  2529                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  2530                              <1> ;		AX,CX,DX DESTROYED
  2531                              <1> ;-------------------------------------------------------------------------------
  2532                              <1> 
  2533                              <1> ; 09/12/2014 [Erdogan Tan] 
  2534                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  2535                              <1> ; Diskette Drive Controller Status Register (3F4h)
  2536                              <1> ;	This read only register facilitates the transfer of data between
  2537                              <1> ;	the system microprocessor and the controller.
  2538                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  2539                              <1> ;	  with the system micrprocessor.
  2540                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  2541                              <1> ;	  the transfer is to the controller.
  2542                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  2543                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  2544                              <1> ; Bit 3 - Reserved.
  2545                              <1> ; Bit 2 - Reserved.
  2546                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  2547                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  2548                              <1> 
  2549                              <1> ; Data Register (3F5h)
  2550                              <1> ; This read/write register passes data, commands and parameters, and provides
  2551                              <1> ; diskette status information.
  2552                              <1>   		
  2553                              <1> NEC_OUTPUT:
  2554                              <1> 	;PUSH	BX			; SAVE REG.
  2555 00003A19 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  2556                              <1> 	;MOV	BL,2			; HIGH ORDER COUNTER
  2557                              <1> 	;XOR	CX,CX			; COUNT FOR TIME OUT
  2558                              <1> 	; 16/12/2014
  2559                              <1> 	; waiting for (max.) 0.5 seconds
  2560                              <1>         ;;mov     byte [wait_count], 0 ;; 27/02/2015
  2561                              <1> 	;
  2562                              <1> 	; 17/12/2014
  2563                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  2564                              <1> 	;
  2565                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  2566                              <1> 	;		go on.
  2567                              <1> 	;INPUT:
  2568                              <1> 	;	AH=Mask for isolation bits.
  2569                              <1> 	;	AL=pattern to look for.
  2570                              <1> 	;	DX=Port to test for
  2571                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  2572                              <1> 	;	     (normally 30 microseconds per period.)
  2573                              <1> 	;
  2574                              <1> 	;WFP_SHORT:  
  2575                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  2576                              <1> 	;
  2577                              <1> 
  2578                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  2579                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  2580 00003A1D B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  2581                              <1> ;
  2582                              <1> ;WFPS_OUTER_LP:
  2583                              <1> ;	;
  2584                              <1> ;WFPS_CHECK_PORT:
  2585                              <1> J23:
  2586 00003A22 EC                  <1> 	IN	AL,DX			; GET STATUS
  2587 00003A23 24C0                <1> 	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  2588 00003A25 3C80                <1> 	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  2589 00003A27 7418                <1> 	JZ	short J27		; STATUS AND DIRECTION OK
  2590                              <1> WFPS_HI:
  2591 00003A29 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  2592 00003A2B A810                <1> 	TEST	AL,010H			; transition on memory
  2593 00003A2D 75FA                <1> 	JNZ	SHORT WFPS_HI		; refresh.
  2594                              <1> WFPS_LO:
  2595 00003A2F E461                <1> 	IN	AL, PORT_B		; SYS1
  2596 00003A31 A810                <1> 	TEST	AL,010H
  2597 00003A33 74FA                <1> 	JZ	SHORT WFPS_LO
  2598                              <1> 	;LOOP	SHORT WFPS_CHECK_PORT
  2599 00003A35 E2EB                <1> 	loop	J23	; 27/02/2015
  2600                              <1> ;	;
  2601                              <1> ;	dec	bl
  2602                              <1> ;	jnz	short WFPS_OUTER_LP
  2603                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  2604                              <1> ;J23:
  2605                              <1> ;	IN	AL,DX			; GET STATUS
  2606                              <1> ;	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  2607                              <1> ;	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  2608                              <1> ;	JZ	short J27		; STATUS AND DIRECTION OK
  2609                              <1> 	;LOOP	J23			; CONTINUE TILL CX EXHAUSTED
  2610                              <1> 	;DEC	BL			; DECREMENT COUNTER
  2611                              <1> 	;JNZ	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  2612                              <1>    
  2613                              <1> 	;;27/02/2015
  2614                              <1> 	;16/12/2014
  2615                              <1>         ;;cmp     byte [wait_count], 10   ; (10/18.2 seconds)
  2616                              <1> 	;;jb	short J23
  2617                              <1> 
  2618                              <1> ;WFPS_TIMEOUT:
  2619                              <1> 
  2620                              <1> ;-----	FALL THRU TO ERROR RETURN
  2621                              <1> 
  2622 00003A37 800D[50200100]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  2623                              <1> 	;POP	BX			; RESTORE REG.
  2624 00003A3E 58                  <1> 	POP	eAX ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  2625 00003A3F F9                  <1> 	STC				; INDICATE ERROR TO CALLER
  2626 00003A40 C3                  <1> 	RETn
  2627                              <1> 
  2628                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  2629                              <1> 
  2630                              <1> J27:	
  2631 00003A41 88E0                <1> 	MOV	AL,AH			; GET BYTE TO OUTPUT
  2632 00003A43 6642                <1> 	INC	DX			; DATA PORT = STATUS PORT + 1
  2633 00003A45 EE                  <1> 	OUT	DX,AL			; OUTPUT THE BYTE
  2634                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  2635                              <1> 	; 27/02/2015
  2636 00003A46 9C                  <1> 	PUSHF				; SAVE FLAGS
  2637 00003A47 B903000000          <1> 	MOV	eCX, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  2638 00003A4C E80BE2FFFF          <1> 	CALL 	WAITF			; NEC FLAGS UPDATE CYCLE
  2639 00003A51 9D                  <1> 	POPF				; RESTORE FLAGS FOR EXIT
  2640                              <1> 	;POP	BX			; RESTORE REG
  2641 00003A52 C3                  <1> 	RETn				; CY = 0 FROM TEST INSTRUCTION
  2642                              <1> 
  2643                              <1> ;-------------------------------------------------------------------------------
  2644                              <1> ; SEEK
  2645                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  2646                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  2647                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  2648                              <1> ;
  2649                              <1> ; ON ENTRY:	DI = DRIVE #
  2650                              <1> ;		CH = TRACK #
  2651                              <1> ;
  2652                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2653                              <1> ;		AX,BX,CX DX DESTROYED
  2654                              <1> ;-------------------------------------------------------------------------------
  2655                              <1> SEEK:
  2656 00003A53 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2657 00003A55 B001                <1> 	MOV	AL,1			; ESTABLISH MASK FOR RECALIBRATE TEST
  2658 00003A57 86CB                <1> 	XCHG	CL,BL			; SET DRIVE VALULE INTO CL
  2659 00003A59 D2C0                <1> 	ROL	AL,CL			; SHIFT MASK BY THE DRIVE VALUE
  2660 00003A5B 86CB                <1> 	XCHG	CL,BL			; RECOVER TRACK VALUE
  2661 00003A5D 8405[4D200100]      <1> 	TEST	AL,[SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  2662 00003A63 7526                <1> 	JNZ	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  2663                              <1> 
  2664 00003A65 0805[4D200100]      <1> 	OR	[SEEK_STATUS],AL	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  2665 00003A6B E862000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2666 00003A70 730E                <1> 	JNC	short AFT_RECAL		; RECALIBRATE DONE
  2667                              <1> 
  2668                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  2669                              <1> 
  2670 00003A72 C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR OUT INVALID STATUS
  2671 00003A79 E854000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2672 00003A7E 7251                <1> 	JC	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  2673                              <1> 
  2674                              <1> AFT_RECAL:
  2675 00003A80 C687[61200100]00    <1>         MOV     byte [DSK_TRK+eDI],0    ; SAVE NEW CYLINDER AS PRESENT POSITION
  2676 00003A87 08ED                <1> 	OR	CH,CH			; CHECK FOR SEEK TO TRACK 0
  2677 00003A89 743F                <1> 	JZ	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  2678                              <1> 
  2679                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  2680                              <1> 
  2681 00003A8B F687[5D200100]20    <1> J28A:	TEST	byte [DSK_STATE+eDI],DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  2682 00003A92 7402                <1> 	JZ	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  2683 00003A94 D0E5                <1> 	SHL	CH,1			; DOUBLE NUMBER OF STEP TO TAKE
  2684                              <1> 
  2685 00003A96 3AAF[61200100]      <1> _R7:	CMP	CH, [DSK_TRK+eDI]	; SEE IF ALREADY AT THE DESIRED TRACK
  2686 00003A9C 7433                <1> 	JE	short RB		; IF YES, DO NOT NEED TO SEEK
  2687                              <1> 
  2688 00003A9E BA[D13A0000]        <1> 	MOV	eDX, NEC_ERR		; LOAD RETURN ADDRESS
  2689 00003AA3 52                  <1> 	PUSH	eDX ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  2690 00003AA4 88AF[61200100]      <1> 	MOV	[DSK_TRK+eDI],CH	; SAVE NEW CYLINDER AS PRESENT POSITION
  2691 00003AAA B40F                <1> 	MOV	AH,0FH			; SEEK COMMAND TO NEC
  2692 00003AAC E868FFFFFF          <1> 	CALL	NEC_OUTPUT
  2693 00003AB1 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2694 00003AB3 88DC                <1> 	MOV	AH,BL			; OUTPUT DRIVE NUMBER
  2695 00003AB5 E85FFFFFFF          <1> 	CALL	NEC_OUTPUT
  2696 00003ABA 8AA7[61200100]      <1> 	MOV	AH, [DSK_TRK+eDI]	; GET CYLINDER NUMBER
  2697 00003AC0 E854FFFFFF          <1> 	CALL	NEC_OUTPUT
  2698 00003AC5 E829000000          <1> 	CALL	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  2699                              <1> 
  2700                              <1> ;-----	WAIT FOR HEAD SETTLE
  2701                              <1> 
  2702                              <1> DO_WAIT:
  2703 00003ACA 9C                  <1> 	PUSHF				; SAVE STATUS
  2704 00003ACB E816FFFFFF          <1> 	CALL	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  2705 00003AD0 9D                  <1> 	POPF				; RESTORE STATUS
  2706                              <1> RB:
  2707                              <1> NEC_ERR:
  2708                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  2709                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  2710 00003AD1 C3                  <1> 	RETn				; RETURN TO CALLER
  2711                              <1> 
  2712                              <1> ;-------------------------------------------------------------------------------
  2713                              <1> ; RECAL
  2714                              <1> ;	RECALIBRATE DRIVE
  2715                              <1> ;
  2716                              <1> ; ON ENTRY:	DI = DRIVE #
  2717                              <1> ;
  2718                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  2719                              <1> ;-------------------------------------------------------------------------------
  2720                              <1> RECAL:
  2721 00003AD2 6651                <1> 	PUSH	CX
  2722 00003AD4 B8[F03A0000]        <1> 	MOV	eAX, RC_BACK		; LOAD NEC_OUTPUT ERROR
  2723 00003AD9 50                  <1> 	PUSH	eAX
  2724 00003ADA B407                <1> 	MOV	AH,07H			; RECALIBRATE COMMAND
  2725 00003ADC E838FFFFFF          <1> 	CALL	NEC_OUTPUT
  2726 00003AE1 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2727 00003AE3 88DC                <1> 	MOV	AH,BL
  2728 00003AE5 E82FFFFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  2729 00003AEA E804000000          <1> 	CALL	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  2730 00003AEF 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  2731                              <1> RC_BACK:
  2732 00003AF0 6659                <1> 	POP	CX
  2733 00003AF2 C3                  <1> 	RETn
  2734                              <1> 
  2735                              <1> ;-------------------------------------------------------------------------------
  2736                              <1> ; CHK_STAT_2
  2737                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  2738                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  2739                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  2740                              <1> ;
  2741                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2742                              <1> ;-------------------------------------------------------------------------------
  2743                              <1> CHK_STAT_2:
  2744 00003AF3 B8[1B3B0000]        <1>         MOV     eAX, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  2745 00003AF8 50                  <1> 	PUSH	eAX
  2746 00003AF9 E828000000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  2747 00003AFE 721A                <1> 	JC	short J34		; IF ERROR, RETURN IT
  2748 00003B00 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  2749 00003B02 E812FFFFFF          <1> 	CALL	NEC_OUTPUT
  2750 00003B07 E84A000000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  2751 00003B0C 720C                <1> 	JC	short J34
  2752 00003B0E A0[51200100]        <1> 	MOV	AL,[NEC_STATUS]		; GET THE FIRST STATUS BYTE
  2753 00003B13 2460                <1> 	AND	AL,01100000B		; ISOLATE THE BITS
  2754 00003B15 3C60                <1> 	CMP	AL,01100000B		; TEST FOR CORRECT VALUE
  2755 00003B17 7403                <1> 	JZ	short J35		; IF ERROR, GO MARK IT
  2756 00003B19 F8                  <1> 	CLC				; GOOD RETURN
  2757                              <1> J34:
  2758 00003B1A 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  2759                              <1> CS_BACK:
  2760 00003B1B C3                  <1> 	RETn
  2761                              <1> J35:
  2762 00003B1C 800D[50200100]40    <1> 	OR	byte [DSKETTE_STATUS], BAD_SEEK
  2763 00003B23 F9                  <1> 	STC				; ERROR RETURN CODE
  2764 00003B24 EBF4                <1> 	JMP	SHORT J34
  2765                              <1> 
  2766                              <1> ;-------------------------------------------------------------------------------
  2767                              <1> ; WAIT_INT
  2768                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  2769                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  2770                              <1> ;	IF THE DRIVE IS NOT READY.
  2771                              <1> ;
  2772                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2773                              <1> ;-------------------------------------------------------------------------------
  2774                              <1> 
  2775                              <1> ; 17/12/2014
  2776                              <1> ; 2.5 seconds waiting !
  2777                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  2778                              <1> ; amount of time to wait for completion interrupt from NEC.
  2779                              <1> 
  2780                              <1> 
  2781                              <1> WAIT_INT:
  2782 00003B26 FB                  <1> 	STI				; TURN ON INTERRUPTS, JUST IN CASE
  2783 00003B27 F8                  <1> 	CLC				; CLEAR TIMEOUT INDICATOR
  2784                              <1>        ;MOV	BL,10			; CLEAR THE COUNTERS
  2785                              <1>        ;XOR	CX,CX			; FOR 2 SECOND WAIT
  2786                              <1> 
  2787                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  2788                              <1> 	;
  2789                              <1> 	;WAIT_FOR_MEM:	
  2790                              <1> 	;	Waits for a bit at a specified memory location pointed
  2791                              <1> 	;	to by ES:[DI] to become set.
  2792                              <1> 	;INPUT:
  2793                              <1> 	;	AH=Mask to test with.
  2794                              <1> 	;	ES:[DI] = memory location to watch.
  2795                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  2796                              <1> 	;	     (normally 30 microseconds per period.)
  2797                              <1> 
  2798                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  2799                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  2800                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  2801                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  2802                              <1> 	; 27/02/2015
  2803 00003B28 B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  2804                              <1> WFMS_CHECK_MEM:
  2805 00003B2D F605[4D200100]80    <1> 	test	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  2806 00003B34 7516                <1>         jnz     short J37
  2807                              <1> WFMS_HI:
  2808 00003B36 E461                <1> 	IN	AL,PORT_B  ; 061h	; SYS1, wait for lo to hi
  2809 00003B38 A810                <1> 	TEST	AL,010H			; transition on memory
  2810 00003B3A 75FA                <1> 	JNZ	SHORT WFMS_HI		; refresh.
  2811                              <1> WFMS_LO:
  2812 00003B3C E461                <1> 	IN	AL,PORT_B		;SYS1
  2813 00003B3E A810                <1> 	TEST	AL,010H
  2814 00003B40 74FA                <1> 	JZ	SHORT WFMS_LO
  2815 00003B42 E2E9                <1>         LOOP    WFMS_CHECK_MEM
  2816                              <1> ;WFMS_OUTER_LP:
  2817                              <1> ;;	or	bl, bl			; check outer counter
  2818                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  2819                              <1> ;	dec	bl
  2820                              <1> ;	jz	short J36A	
  2821                              <1> ;	jmp	short WFMS_CHECK_MEM
  2822                              <1> 
  2823                              <1> 	;17/12/2014
  2824                              <1> 	;16/12/2014
  2825                              <1> ;        mov     byte [wait_count], 0    ; Reset (INT 08H) counter
  2826                              <1> ;J36:
  2827                              <1> ;	TEST	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  2828                              <1> ;	JNZ	short J37
  2829                              <1> 	;16/12/2014
  2830                              <1> 	;LOOP	J36			; COUNT DOWN WHILE WAITING
  2831                              <1> 	;DEC	BL			; SECOND LEVEL COUNTER
  2832                              <1> 	;JNZ	short J36
  2833                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  2834                              <1> ;	jb	short J36
  2835                              <1> 
  2836                              <1> ;WFMS_TIMEOUT:
  2837                              <1> ;J36A:
  2838 00003B44 800D[50200100]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  2839 00003B4B F9                  <1> 	STC				; ERROR RETURN
  2840                              <1> J37:
  2841 00003B4C 9C                  <1> 	PUSHF				; SAVE CURRENT CARRY
  2842 00003B4D 8025[4D200100]7F    <1> 	AND	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  2843 00003B54 9D                  <1> 	POPF				; RECOVER CARRY
  2844 00003B55 C3                  <1> 	RETn				; GOOD RETURN CODE
  2845                              <1> 
  2846                              <1> ;-------------------------------------------------------------------------------
  2847                              <1> ; RESULTS
  2848                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  2849                              <1> ;	FOLLOWING AN INTERRUPT.
  2850                              <1> ;
  2851                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2852                              <1> ;		AX,BX,CX,DX DESTROYED
  2853                              <1> ;-------------------------------------------------------------------------------
  2854                              <1> RESULTS:
  2855 00003B56 57                  <1> 	PUSH	eDI
  2856 00003B57 BF[51200100]        <1> 	MOV	eDI, NEC_STATUS		; POINTER TO DATA AREA
  2857 00003B5C B307                <1> 	MOV	BL,7			; MAX STATUS BYTES
  2858 00003B5E 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  2859                              <1> 
  2860                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  2861                              <1> 
  2862                              <1> _R10: 
  2863                              <1> 	; 16/12/2014
  2864                              <1> 	; wait for (max) 0.5 seconds
  2865                              <1> 	;MOV	BH,2			; HIGH ORDER COUNTER
  2866                              <1> 	;XOR	CX,CX			; COUNTER
  2867                              <1> 
  2868                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  2869                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  2870                              <1> 	; 27/02/2015
  2871 00003B62 B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  2872                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  2873                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  2874                              <1> 
  2875                              <1> WFPSR_OUTER_LP:
  2876                              <1> 	;
  2877                              <1> WFPSR_CHECK_PORT:
  2878                              <1> J39:					; WAIT FOR MASTER
  2879 00003B67 EC                  <1> 	IN	AL,DX			; GET STATUS
  2880 00003B68 24C0                <1> 	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  2881 00003B6A 3CC0                <1> 	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  2882 00003B6C 7418                <1> 	JZ	short J42		; STATUS AND DIRECTION OK
  2883                              <1> WFPSR_HI:
  2884 00003B6E E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  2885 00003B70 A810                <1> 	TEST	AL,010H			; transition on memory
  2886 00003B72 75FA                <1> 	JNZ	SHORT WFPSR_HI		; refresh.
  2887                              <1> WFPSR_LO:
  2888 00003B74 E461                <1> 	IN	AL, PORT_B		; SYS1
  2889 00003B76 A810                <1> 	TEST	AL,010H
  2890 00003B78 74FA                <1> 	JZ	SHORT WFPSR_LO
  2891 00003B7A E2EB                <1>         LOOP    WFPSR_CHECK_PORT
  2892                              <1> 	;; 27/02/2015
  2893                              <1> 	;;dec	bh
  2894                              <1> 	;;jnz	short WFPSR_OUTER_LP
  2895                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  2896                              <1> 
  2897                              <1> 	;;mov	byte [wait_count], 0
  2898                              <1> ;J39:					; WAIT FOR MASTER
  2899                              <1> ;	IN	AL,DX			; GET STATUS
  2900                              <1> ;	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  2901                              <1> ;	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  2902                              <1> ;	JZ	short J42		; STATUS AND DIRECTION OK
  2903                              <1> 	;LOOP	J39			; LOOP TILL TIMEOUT
  2904                              <1> 	;DEC	BH			; DECREMENT HIGH ORDER COUNTER
  2905                              <1> 	;JNZ	short J39		; REPEAT TILL DELAY DONE
  2906                              <1> 	;
  2907                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  2908                              <1> 	;;jb	short J39	
  2909                              <1> 
  2910                              <1> ;WFPSR_TIMEOUT:
  2911 00003B7C 800D[50200100]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  2912 00003B83 F9                  <1> 	STC				; SET ERROR RETURN
  2913 00003B84 EB29                <1> 	JMP	SHORT POPRES		; POP REGISTERS AND RETURN
  2914                              <1> 
  2915                              <1> ;-----	READ IN THE STATUS
  2916                              <1> 
  2917                              <1> J42:
  2918 00003B86 EB00                <1> 	JMP	$+2			; I/O DELAY
  2919 00003B88 6642                <1> 	INC	DX			; POINT AT DATA PORT
  2920 00003B8A EC                  <1> 	IN	AL,DX			; GET THE DATA
  2921                              <1> 	; 16/12/2014
  2922                              <1> 	NEWIODELAY
  2922 00003B8B E6EB                <2>  out 0ebh,al
  2923 00003B8D 8807                <1>         MOV     [eDI],AL                ; STORE THE BYTE
  2924 00003B8F 47                  <1> 	INC	eDI			; INCREMENT THE POINTER
  2925                              <1> 	; 16/12/2014
  2926                              <1> ;	push	cx
  2927                              <1> ;	mov	cx, 30
  2928                              <1> ;wdw2:
  2929                              <1> ;	NEWIODELAY
  2930                              <1> ;	loop	wdw2
  2931                              <1> ;	pop	cx
  2932                              <1> 
  2933 00003B90 B903000000          <1> 	MOV	eCX,3			; MINIMUM 24 MICROSECONDS FOR NEC
  2934 00003B95 E8C2E0FFFF          <1> 	CALL	WAITF			; WAIT 30 TO 45 MICROSECONDS
  2935 00003B9A 664A                <1> 	DEC	DX			; POINT AT STATUS PORT
  2936 00003B9C EC                  <1> 	IN	AL,DX			; GET STATUS
  2937                              <1> 	; 16/12/2014
  2938                              <1> 	NEWIODELAY
  2938 00003B9D E6EB                <2>  out 0ebh,al
  2939                              <1> 	;
  2940 00003B9F A810                <1> 	TEST	AL,00010000B		; TEST FOR NEC STILL BUSY
  2941 00003BA1 740C                <1> 	JZ	short POPRES		; RESULTS DONE ?
  2942                              <1> 
  2943 00003BA3 FECB                <1> 	DEC	BL			; DECREMENT THE STATUS COUNTER
  2944 00003BA5 75BB                <1>         JNZ     short _R10              ; GO BACK FOR MORE
  2945 00003BA7 800D[50200100]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; TOO MANY STATUS BYTES
  2946 00003BAE F9                  <1> 	STC				; SET ERROR FLAG
  2947                              <1> 
  2948                              <1> ;-----	RESULT OPERATION IS DONE
  2949                              <1> POPRES:
  2950 00003BAF 5F                  <1> 	POP	eDI
  2951 00003BB0 C3                  <1> 	RETn				; RETURN WITH CARRY SET
  2952                              <1> 
  2953                              <1> ;-------------------------------------------------------------------------------
  2954                              <1> ; READ_DSKCHNG
  2955                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  2956                              <1> ;
  2957                              <1> ; ON ENTRY:	DI = DRIVE #
  2958                              <1> ;
  2959                              <1> ; ON EXIT:	DI = DRIVE #
  2960                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  2961                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  2962                              <1> ;		AX,CX,DX DESTROYED
  2963                              <1> ;-------------------------------------------------------------------------------
  2964                              <1> READ_DSKCHNG:
  2965 00003BB1 E8A2FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  2966 00003BB6 66BAF703            <1> 	MOV	DX,03F7H		; ADDRESS DIGITAL INPUT REGISTER
  2967 00003BBA EC                  <1> 	IN	AL,DX			; INPUT DIGITAL INPUT REGISTER
  2968 00003BBB A880                <1> 	TEST	AL,DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  2969 00003BBD C3                  <1> 	RETn				; RETURN TO CALLER WITH ZERO FLAG SET
  2970                              <1> 
  2971                              <1> ;-------------------------------------------------------------------------------
  2972                              <1> ; DRIVE_DET
  2973                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  2974                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  2975                              <1> ; ON ENTRY:	DI = DRIVE #
  2976                              <1> ;-------------------------------------------------------------------------------
  2977                              <1> DRIVE_DET:
  2978 00003BBE E895FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  2979 00003BC3 E80AFFFFFF          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2980 00003BC8 7251                <1> 	JC	short DD_BAC		; ASSUME NO DRIVE PRESENT
  2981 00003BCA B530                <1> 	MOV	CH,TRK_SLAP		; SEEK TO TRACK 48
  2982 00003BCC E882FEFFFF          <1> 	CALL	SEEK
  2983 00003BD1 7248                <1> 	JC	short DD_BAC		; ERROR NO DRIVE
  2984 00003BD3 B50B                <1> 	MOV	CH,QUIET_SEEK+1		; SEEK TO TRACK 10
  2985                              <1> SK_GIN:
  2986 00003BD5 FECD                <1> 	DEC	CH			; DECREMENT TO NEXT TRACK
  2987 00003BD7 6651                <1> 	PUSH	CX			; SAVE TRACK
  2988 00003BD9 E875FEFFFF          <1> 	CALL	SEEK
  2989 00003BDE 723C                <1> 	JC	short POP_BAC		; POP AND RETURN
  2990 00003BE0 B8[1C3C0000]        <1> 	MOV	eAX, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  2991 00003BE5 50                  <1> 	PUSH	eAX
  2992 00003BE6 B404                <1> 	MOV	AH,SENSE_DRV_ST		; SENSE DRIVE STATUS COMMAND BYTE
  2993 00003BE8 E82CFEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  2994 00003BED 6689F8              <1> 	MOV	AX,DI			; AL = DRIVE
  2995 00003BF0 88C4                <1> 	MOV	AH,AL			; AH = DRIVE
  2996 00003BF2 E822FEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  2997 00003BF7 E85AFFFFFF          <1> 	CALL	RESULTS			; GO GET STATUS
  2998 00003BFC 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  2999 00003BFD 6659                <1> 	POP	CX			; RESTORE TRACK
  3000 00003BFF F605[51200100]10    <1> 	TEST	byte [NEC_STATUS], HOME	; TRACK 0 ?
  3001 00003C06 74CD                <1> 	JZ	short SK_GIN		; GO TILL TRACK 0
  3002 00003C08 08ED                <1> 	OR	CH,CH			; IS HOME AT TRACK 0
  3003 00003C0A 7408                <1> 	JZ	short IS_80		; MUST BE 80 TRACK DRIVE
  3004                              <1> 
  3005                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  3006                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  3007                              <1> 
  3008 00003C0C 808F[5D200100]94    <1> 	OR	byte [DSK_STATE+eDI], DRV_DET+MED_DET+RATE_250
  3009 00003C13 C3                  <1> 	RETn				; ALL INFORMATION SET
  3010                              <1> IS_80:
  3011 00003C14 808F[5D200100]01    <1> 	OR	byte [DSK_STATE+eDI], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  3012                              <1> DD_BAC:
  3013 00003C1B C3                  <1> 	RETn
  3014                              <1> POP_BAC:
  3015 00003C1C 6659                <1> 	POP	CX			; THROW AWAY
  3016 00003C1E C3                  <1> 	RETn
  3017                              <1> 
  3018                              <1> fdc_int:  
  3019                              <1> 	  ; 30/07/2015	
  3020                              <1> 	  ; 16/02/2015
  3021                              <1> ;int_0Eh: ; 11/12/2014
  3022                              <1> 
  3023                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL  6 ) --------------------------------------
  3024                              <1> ; DISK_INT
  3025                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  3026                              <1> ;
  3027                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  3028                              <1> ;-------------------------------------------------------------------------------
  3029                              <1> DISK_INT_1:
  3030                              <1> 
  3031 00003C1F 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER
  3032 00003C21 1E                  <1> 	push	ds
  3033 00003C22 66B81000            <1> 	mov	ax, KDATA
  3034 00003C26 8ED8                <1> 	mov 	ds, ax
  3035 00003C28 800D[4D200100]80    <1>         OR      byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  3036 00003C2F B020                <1> 	MOV     AL,EOI                  ; END OF INTERRUPT MARKER
  3037 00003C31 E620                <1> 	OUT	INTA00,AL		; INTERRUPT CONTROL PORT
  3038 00003C33 1F                  <1> 	pop	ds
  3039 00003C34 6658                <1> 	POP	AX			; RECOVER REGISTER
  3040 00003C36 CF                  <1> 	IRET				; RETURN FROM INTERRUPT
  3041                              <1> 
  3042                              <1> ;-------------------------------------------------------------------------------
  3043                              <1> ; DSKETTE_SETUP
  3044                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  3045                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  3046                              <1> ;-------------------------------------------------------------------------------
  3047                              <1> 
  3048                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  3049                              <1> 
  3050                              <1> DSKETTE_SETUP:
  3051                              <1> 	;PUSH	AX			; SAVE REGISTERS
  3052                              <1> 	;PUSH	BX
  3053                              <1> 	;PUSH	CX
  3054 00003C37 52                  <1> 	PUSH	eDX
  3055                              <1> 	;PUSH	DI
  3056                              <1> 	;;PUSH	DS
  3057                              <1> 	; 14/12/2014
  3058                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  3059                              <1> 	;mov	[DISK_POINTER+2], cs
  3060                              <1> 	;
  3061                              <1> 	;OR	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  3062 00003C38 31FF                <1> 	XOR	eDI,eDI			; INITIALIZE DRIVE POINTER
  3063 00003C3A 66C705[5D200100]00- <1> 	MOV	WORD [DSK_STATE],0	; INITIALIZE STATES
  3063 00003C42 00                  <1>
  3064 00003C43 8025[58200100]33    <1> 	AND	byte [LASTRATE],~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  3065 00003C4A 800D[58200100]C0    <1> 	OR	byte [LASTRATE],SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  3066 00003C51 C605[4D200100]00    <1> 	MOV	byte [SEEK_STATUS],0	; INDICATE RECALIBRATE NEEDED
  3067 00003C58 C605[4F200100]00    <1> 	MOV	byte [MOTOR_COUNT],0	; INITIALIZE MOTOR COUNT
  3068 00003C5F C605[4E200100]00    <1> 	MOV	byte [MOTOR_STATUS],0	; INITIALIZE DRIVES TO OFF STATE
  3069 00003C66 C605[50200100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; NO ERRORS
  3070                              <1> 	;
  3071                              <1> 	; 28/02/2015
  3072                              <1> 	;mov	word [cfd], 100h 
  3073 00003C6D E848F2FFFF          <1> 	call	DSK_RESET
  3074 00003C72 5A                  <1> 	pop	edx
  3075 00003C73 F8                  <1> 	clc	; 29/05/2016
  3076 00003C74 C3                  <1> 	retn
  3077                              <1> 
  3078                              <1> ;SUP0:
  3079                              <1> ;	CALL	DRIVE_DET		; DETERMINE DRIVE
  3080                              <1> ;	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  3081                              <1> ;	; 02/01/2015
  3082                              <1> ;	;INC	DI			; POINT TO NEXT DRIVE
  3083                              <1> ;	;CMP	DI,MAX_DRV		; SEE IF DONE
  3084                              <1> ;	;JNZ	short SUP0		; REPEAT FOR EACH ORIVE
  3085                              <1> ;       cmp     byte [fd1_type], 0	
  3086                              <1> ;	jna	short sup1
  3087                              <1> ;	or	di, di
  3088                              <1> ;	jnz	short sup1
  3089                              <1> ;	inc	di
  3090                              <1> ;       jmp     short SUP0
  3091                              <1> ;sup1:
  3092                              <1> ;	MOV	byte [SEEK_STATUS],0	; FORCE RECALIBRATE
  3093                              <1> ;	;AND	byte [RTC_WAIT_FLAG],0FEH ; ALLOW FOR RTC WAIT
  3094                              <1> ;	CALL	SETUP_END		; VARIOUS CLEANUPS
  3095                              <1> ;	;;POP	DS			; RESTORE CALLERS REGISTERS
  3096                              <1> ;	;POP	DI
  3097                              <1> ;	POP	eDX
  3098                              <1> ;	;POP	CX
  3099                              <1> ;	;POP	BX
  3100                              <1> ;	;POP	AX
  3101                              <1> ;	RETn
  3102                              <1> 
  3103                              <1> ;//////////////////////////////////////////////////////
  3104                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3105                              <1> ;
  3106                              <1> 
  3107                              <1> int13h: ; 21/02/2015
  3108 00003C75 9C                  <1> 	pushfd
  3109 00003C76 0E                  <1> 	push 	cs
  3110 00003C77 E841010000          <1> 	call 	DISK_IO
  3111 00003C7C C3                  <1> 	retn
  3112                              <1> 
  3113                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  3114                              <1> ;/////////////////////////////////////////////////////////////////////
  3115                              <1> 
  3116                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  3117                              <1> ; 18/02/2016
  3118                              <1> ; 17/02/2016
  3119                              <1> ; 23/02/2015
  3120                              <1> ; 21/02/2015 (unix386.s)
  3121                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  3122                              <1> ;
  3123                              <1> ; Original Source Code:
  3124                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  3125                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  3126                              <1> ;
  3127                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  3128                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  3129                              <1> ;
  3130                              <1> 
  3131                              <1> 
  3132                              <1> ;The wait for controller to be not busy is 10 seconds.
  3133                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  3134                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ	1615h		
  3135                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ	  05h
  3136                              <1> WAIT_HDU_CTRL_BUSY_LH	equ	51615h	 ;21/02/2015		
  3137                              <1> 
  3138                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  3139                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  3140                              <1> ;;WAIT_HDU_INT_LO	equ	1615h
  3141                              <1> ;;WAIT_HDU_INT_HI	equ	  05h
  3142                              <1> WAIT_HDU_INT_LH		equ	51615h	; 21/02/2015
  3143                              <1> 
  3144                              <1> ;The wait for Data request on read and write longs is
  3145                              <1> ;2000 us. (?)
  3146                              <1> ;;WAIT_HDU_DRQ_LO	equ	1000	; 03E8h
  3147                              <1> ;;WAIT_HDU_DRQ_HI	equ	0
  3148                              <1> WAIT_HDU_DRQ_LH		equ	1000	; 21/02/2015
  3149                              <1> 
  3150                              <1> ; Port 61h (PORT_B)
  3151                              <1> SYS1		equ	61h	; PORT_B  (diskette.inc)
  3152                              <1> 
  3153                              <1> ; 23/12/2014
  3154                              <1> %define CMD_BLOCK       eBP-8  ; 21/02/2015
  3155                              <1> 
  3156                              <1> 
  3157                              <1> ;--- INT 13H -------------------------------------------------------------------
  3158                              <1> ;									       :
  3159                              <1> ; FIXED DISK I/O INTERFACE						       :
  3160                              <1> ;									       :
  3161                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  3162                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  3163                              <1> ;									       :
  3164                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  3165                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  3166                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  3167                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  3168                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  3169                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  3170                              <1> ;									       :
  3171                              <1> ;------------------------------------------------------------------------------:
  3172                              <1> ;									       :
  3173                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  3174                              <1> ;									       :
  3175                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  3176                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  3177                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  3178                              <1> ;			  DL > 80H - DISK				       :
  3179                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  3180                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  3181                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  3182                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  3183                              <1> ;	(AH)= 06H  UNUSED						       :
  3184                              <1> ;	(AH)= 07H  UNUSED						       :
  3185                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  3186                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  3187                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  3188                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  3189                              <1> ;	(AH)= 0AH  READ LONG						       :
  3190                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  3191                              <1> ;	(AH)= 0CH  SEEK 						       :
  3192                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  3193                              <1> ;	(AH)= 0EH  UNUSED						       :
  3194                              <1> ;	(AH)= 0FH  UNUSED						       :
  3195                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  3196                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  3197                              <1> ;	(AH)= 12H  UNUSED						       :
  3198                              <1> ;	(AH)= 13H  UNUSED						       :
  3199                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  3200                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  3201                              <1> ;									       :
  3202                              <1> ;-------------------------------------------------------------------------------
  3203                              <1> ;									       :
  3204                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  3205                              <1> ;									       :
  3206                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  3207                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  3208                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  3209                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  3210                              <1> ;									       :
  3211                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  3212                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  3213                              <1> ;				 (10 BITS TOTAL)			       :
  3214                              <1> ;									       :
  3215                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  3216                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  3217                              <1> ;									       :
  3218                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  3219                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  3220                              <1> ;									       :
  3221                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  3222                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  3223                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  3224                              <1> ;			       80H FOR A BAD SECTOR			       :
  3225                              <1> ;			   N = SECTOR NUMBER				       :
  3226                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  3227                              <1> ;			   THE TABLE SHOULD BE: 			       :
  3228                              <1> ;									       :
  3229                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  3230                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  3231                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  3232                              <1> ;									       :
  3233                              <1> ;-------------------------------------------------------------------------------
  3234                              <1> 
  3235                              <1> ;-------------------------------------------------------------------------------
  3236                              <1> ; OUTPUT								       :
  3237                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  3238                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  3239                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  3240                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  3241                              <1> ;									       :
  3242                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  3243                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  3244                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  3245                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  3246                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  3247                              <1> ;		REWRITTEN.						       :
  3248                              <1> ;									       :
  3249                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  3250                              <1> ;	   INPUT:							       :
  3251                              <1> ;	     (DL) = DRIVE NUMBER					       :	
  3252                              <1> ;	     ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)						       :	 	
  3253                              <1> ;	     EBX = Buffer address for fixed disk parameters table (32 bytes)   :
  3254                              <1> ;	   OUTPUT:							       :
  3255                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  3256                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  3257                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  3258                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  3259                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  3260                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  3261                              <1> ;									       :
  3262                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  3263                              <1> ;									       :
  3264                              <1> ;	AH = 0 - NOT PRESENT						       :
  3265                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  3266                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  3267                              <1> ;	     3 - FIXED DISK						       :
  3268                              <1> ;									       :
  3269                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  3270                              <1> ;									       :
  3271                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  3272                              <1> ;	INFORMATION.							       :
  3273                              <1> ;									       :
  3274                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  3275                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  3276                              <1> ;									       :
  3277                              <1> ;-------------------------------------------------------------------------------
  3278                              <1> 
  3279                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  3280                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  3281                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  3282                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  3283                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  3284                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  3285                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  3286                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  3287                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  3288                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  3289                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  3290                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  3291                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  3292                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  3293                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  3294                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  3295                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  3296                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  3297                              <1> 
  3298                              <1> ;--------------------------------------------------------
  3299                              <1> ;							:
  3300                              <1> ; FIXED DISK PARAMETER TABLE				:
  3301                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  3302                              <1> ;							:
  3303                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  3304                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  3305                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  3306                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  3307                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  3308                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  3309                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  3310                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  3311                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  3312                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  3313                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  3314                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  3315                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  3316                              <1> ;							:
  3317                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  3318                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  3319                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  3320                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  3321                              <1> ;							:
  3322                              <1> ;--------------------------------------------------------
  3323                              <1> 
  3324                              <1> ;--------------------------------------------------------
  3325                              <1> ;							:
  3326                              <1> ; HARDWARE SPECIFIC VALUES				:
  3327                              <1> ;							:
  3328                              <1> ;  -  CONTROLLER I/O PORT				:
  3329                              <1> ;							:
  3330                              <1> ;     > WHEN READ FROM: 				:
  3331                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  3332                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  3333                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  3334                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  3335                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  3336                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  3337                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  3338                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  3339                              <1> ;							:
  3340                              <1> ;     > WHEN WRITTEN TO:				:
  3341                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  3342                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  3343                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  3344                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  3345                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  3346                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  3347                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  3348                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  3349                              <1> ;							:
  3350                              <1> ;--------------------------------------------------------
  3351                              <1> 
  3352                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  3353                              <1> ;HF1_PORT	equ	0170h	
  3354                              <1> ;HF_REG_PORT	EQU	03F6H
  3355                              <1> ;HF1_REG_PORT	equ	0376h
  3356                              <1> 
  3357                              <1> HDC1_BASEPORT	equ	1F0h
  3358                              <1> HDC2_BASEPORT	equ	170h		
  3359                              <1> 
  3360 00003C7D 90                  <1> align 2
  3361                              <1> 
  3362                              <1> ;-----		STATUS REGISTER
  3363                              <1> 
  3364                              <1> ST_ERROR	EQU	00000001B	;
  3365                              <1> ST_INDEX	EQU	00000010B	;
  3366                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  3367                              <1> ST_DRQ		EQU	00001000B	;
  3368                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  3369                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  3370                              <1> ST_READY	EQU	01000000B	;
  3371                              <1> ST_BUSY 	EQU	10000000B	;
  3372                              <1> 
  3373                              <1> ;-----		ERROR REGISTER
  3374                              <1> 
  3375                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  3376                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  3377                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  3378                              <1> ;		EQU	00001000B	; NOT USED
  3379                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  3380                              <1> ;		EQU	00100000B	; NOT USED
  3381                              <1> ERR_DATA_ECC	EQU	01000000B
  3382                              <1> ERR_BAD_BLOCK	EQU	10000000B
  3383                              <1> 
  3384                              <1> 
  3385                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  3386                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  3387                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  3388                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  3389                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  3390                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  3391                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  3392                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  3393                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  3394                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  3395                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  3396                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  3397                              <1> 
  3398                              <1> ;MAX_FILE	EQU	2
  3399                              <1> ;S_MAX_FILE	EQU	2
  3400                              <1> MAX_FILE	equ	4		; 22/12/2014
  3401                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  3402                              <1> 
  3403                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  3404                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  3405                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  3406                              <1> 
  3407                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  3408                              <1> 
  3409                              <1> ;-----		COMMAND BLOCK REFERENCE
  3410                              <1> 
  3411                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  3412                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  3413                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  3414                              <1> ; 19/12/2014
  3415                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  3416                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  3417                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3418                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3419                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  3420                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  3421                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  3422                              <1> 
  3423                              <1> align 2
  3424                              <1> 
  3425                              <1> ;----------------------------------------------------------------
  3426                              <1> ; FIXED DISK I/O SETUP						:
  3427                              <1> ;								:
  3428                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  3429                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  3430                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  3431                              <1> ;								:
  3432                              <1> ;----------------------------------------------------------------
  3433                              <1> 
  3434                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  3435                              <1> 
  3436                              <1> DISK_SETUP:
  3437                              <1> 	;CLI
  3438                              <1> 	;;MOV	AX,ABS0 			; GET ABSOLUTE SEGMENT
  3439                              <1> 	;xor	ax,ax
  3440                              <1> 	;MOV	DS,AX				; SET SEGMENT REGISTER
  3441                              <1> 	;MOV	AX, [ORG_VECTOR] 		; GET DISKETTE VECTOR
  3442                              <1> 	;MOV	[DISK_VECTOR],AX		;  INTO INT 40H
  3443                              <1> 	;MOV	AX, [ORG_VECTOR+2]
  3444                              <1> 	;MOV	[DISK_VECTOR+2],AX
  3445                              <1> 	;MOV	word [ORG_VECTOR],DISK_IO	; FIXED DISK HANDLER
  3446                              <1> 	;MOV	[ORG_VECTOR+2],CS
  3447                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  3448                              <1> 	;;MOV	word [HDISK_INT],HD_INT		; FIXED DISK INTERRUPT
  3449                              <1> 	;mov	word [HDISK_INT1],HD_INT	;
  3450                              <1> 	;;MOV	[HDISK_INT+2],CS
  3451                              <1> 	;mov	[HDISK_INT1+2],CS
  3452                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  3453                              <1> 	;mov	word [HDISK_INT2],HD1_INT	;
  3454                              <1> 	;mov	[HDISK_INT2+2],CS
  3455                              <1> 	;
  3456                              <1> 	;;MOV	word [HF_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80
  3457                              <1> 	;;MOV	word [HF_TBL_VEC+2],DPT_SEGM
  3458                              <1> 	;;MOV	word [HF1_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81
  3459                              <1> 	;;MOV	word [HF1_TBL_VEC+2],DPT_SEGM
  3460                              <1> 	;push	cs
  3461                              <1> 	;pop	ds
  3462                              <1> 	;mov	word [HDPM_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80h
  3463                              <1> 	;mov	word [HDPM_TBL_VEC+2],DPT_SEGM
  3464 00003C7E C705[68200100]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  3464 00003C86 0900                <1>
  3465                              <1> 	;mov	word [HDPS_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81h
  3466                              <1> 	;mov	word [HDPS_TBL_VEC+2],DPT_SEGM
  3467 00003C88 C705[6C200100]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  3467 00003C90 0900                <1>
  3468                              <1> 	;mov	word [HDSM_TBL_VEC],HD2_DPT	; PARM TABLE DRIVE 82h
  3469                              <1> 	;mov	word [HDSM_TBL_VEC+2],DPT_SEGM
  3470 00003C92 C705[70200100]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  3470 00003C9A 0900                <1>
  3471                              <1> 	;mov	word [HDSS_TBL_VEC],HD3_DPT	; PARM TABLE DRIVE 83h
  3472                              <1> 	;mov	word [HDSS_TBL_VEC+2],DPT_SEGM
  3473 00003C9C C705[74200100]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  3473 00003CA4 0900                <1>
  3474                              <1> 	;
  3475                              <1> 	;;IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  3476                              <1> 	;;;AND	AL,0BFH
  3477                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  3478                              <1> 	;;;JMP	$+2
  3479                              <1> 	;;IODELAY
  3480                              <1> 	;;OUT	INTB01,AL
  3481                              <1> 	;;IODELAY
  3482                              <1> 	;;IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  3483                              <1> 	;;AND	AL,0FBH 		;  SECOND CHIP
  3484                              <1> 	;;;JMP	$+2
  3485                              <1> 	;;IODELAY
  3486                              <1> 	;;OUT	INTA01,AL
  3487                              <1> 	;
  3488                              <1> 	;STI
  3489                              <1> 	;;PUSH	DS			; MOVE ABS0 POINTER TO
  3490                              <1> 	;;POP	ES			; EXTRA SEGMENT POINTER
  3491                              <1> 	;;;CALL	DDS			; ESTABLISH DATA SEGMENT
  3492                              <1> 	;;MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  3493                              <1> 	;;MOV	byte [HF_NUM],0		; ZERO NUMBER OF FIXED DISKS
  3494                              <1> 	;;MOV	byte [CONTROL_BYTE],0
  3495                              <1> 	;;MOV	byte [PORT_OFF],0	; ZERO CARD OFFSET
  3496                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  3497                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  3498                              <1> 	;mov	si, hd0_type
  3499 00003CA6 BE[1AED0000]        <1> 	mov	esi, hd0_type
  3500                              <1> 	;mov	cx, 4
  3501 00003CAB B904000000          <1> 	mov	ecx, 4
  3502                              <1> hde_l:
  3503 00003CB0 AC                  <1> 	lodsb
  3504 00003CB1 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  3505 00003CB3 7206                <1> 	jb	short _L4
  3506 00003CB5 FE05[64200100]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  3507                              <1> _L4: ; 26/02/2015
  3508 00003CBB E2F3                <1> 	loop	hde_l	
  3509                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  3510                              <1> ;L4:
  3511                              <1> 	; 
  3512                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  3513                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  3514                              <1> 	;;mov 	cl, 3
  3515                              <1> 	;;
  3516                              <1> 	;;MOV	DL,80H			; CHECK THE CONTROLLER
  3517                              <1> ;;hdc_dl:
  3518                              <1> 	;;MOV	AH,14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  3519                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  3520                              <1> 	;;;JC	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  3521                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  3522                              <1> 	;;jnc	short hdc_reset0
  3523                              <1> 	;;loop	hdc_dl
  3524                              <1> 	;;; 27/12/2014
  3525                              <1> 	;;stc
  3526                              <1> 	;;retn
  3527                              <1> 	;
  3528                              <1> ;;hdc_reset0:
  3529                              <1> 	; 18/01/2015
  3530 00003CBD 8A0D[64200100]      <1> 	mov	cl, [HF_NUM]
  3531 00003CC3 20C9                <1> 	and	cl, cl
  3532 00003CC5 740E                <1> 	jz	short POD_DONE
  3533                              <1> 	;
  3534 00003CC7 B27F                <1> 	mov	dl, 7Fh
  3535                              <1> hdc_reset1:
  3536 00003CC9 FEC2                <1> 	inc	dl
  3537                              <1> 	;; 31/12/2015
  3538                              <1> 	;;push	dx
  3539                              <1> 	;;push	cx
  3540                              <1> 	;;push	ds
  3541                              <1> 	;;sub	ax, ax
  3542                              <1> 	;;mov	ds, ax
  3543                              <1> 	;;MOV	AX, [TIMER_LOW]		; GET START TIMER COUNTS
  3544                              <1> 	;;pop	ds
  3545                              <1> 	;;MOV	BX,AX
  3546                              <1> 	;;ADD	AX,6*182		; 60 SECONDS* 18.2
  3547                              <1> 	;;MOV	CX,AX
  3548                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  3549                              <1> 	;;
  3550                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  3551                              <1> 	;;CALL	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  3552                              <1> 	;;pop	cx
  3553                              <1> 	;;pop	dx
  3554                              <1> 	;;
  3555                              <1> 	; 18/01/2015
  3556 00003CCB B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  3557                              <1> 	;int	13h
  3558 00003CCD E8A3FFFFFF          <1> 	call	int13h
  3559 00003CD2 E2F5                <1> 	loop	hdc_reset1
  3560 00003CD4 F8                  <1> 	clc 	; 29/05/2016
  3561                              <1> POD_DONE:
  3562 00003CD5 C3                  <1> 	RETn
  3563                              <1> 
  3564                              <1> ;;-----	POD_ERROR
  3565                              <1> 
  3566                              <1> ;;CTL_ERRX:
  3567                              <1> ;	;MOV	SI,OFFSET F1782 	; CONTROLLER ERROR
  3568                              <1> ;	;CALL	SET_FAIL		; DO NOT IPL FROM DISK
  3569                              <1> ;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  3570                              <1> ;	;JMP	short POD_DONE
  3571                              <1> 
  3572                              <1> ;;HD_RESET_1:
  3573                              <1> ;;	;PUSH	BX			; SAVE TIMER LIMITS
  3574                              <1> ;;	;PUSH	CX
  3575                              <1> ;;RES_1: MOV	AH,09H			; SET DRIVE PARAMETERS
  3576                              <1> ;;	INT	13H
  3577                              <1> ;;	JC	short RES_2
  3578                              <1> ;;	MOV	AH,11H			; RECALIBRATE DRIVE
  3579                              <1> ;;	INT	13H
  3580                              <1> ;;	JNC	short RES_CK		; DRIVE OK
  3581                              <1> ;;RES_2: ;CALL	POD_TCHK		; CHECK TIME OUT
  3582                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  3583                              <1> ;;					; (30 seconds)		
  3584                              <1> ;;	;cmc
  3585                              <1> ;;	;JNC	short RES_1
  3586                              <1> ;;	jb	short RES_1
  3587                              <1> ;;;RES_FL: ;MOV	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  3588                              <1> ;;	;TEST	DL,1
  3589                              <1> ;;	;JNZ	RES_E1
  3590                              <1> ;;	;MOV	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  3591                              <1> ;;	;CALL	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  3592                              <1> ;;	;JMP	SHORT RES_E1
  3593                              <1> ;;RES_ER: ; 22/12/2014
  3594                              <1> ;;RES_OK:
  3595                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  3596                              <1> ;;	;POP	BX
  3597                              <1> ;;	RETn
  3598                              <1> ;;
  3599                              <1> ;;RES_RS: MOV	AH,00H			; RESET THE DRIVE
  3600                              <1> ;;	INT	13H
  3601                              <1> ;;RES_CK: MOV	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  3602                              <1> ;;	MOV	BL,DL			; SAVE DRIVE CODE
  3603                              <1> ;;	INT	13H
  3604                              <1> ;;	JC	short RES_ER
  3605                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  3606                              <1> ;;	MOV	DL,BL			; RESTORE DRIVE CODE
  3607                              <1> ;;RES_3: MOV	AX,0401H		; VERIFY THE LAST SECTOR
  3608                              <1> ;;	INT	13H
  3609                              <1> ;;	JNC	short RES_OK		; VERIFY OK
  3610                              <1> ;;	CMP	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  3611                              <1> ;;	JE	short RES_OK
  3612                              <1> ;;	CMP	AH,DATA_CORRECTED
  3613                              <1> ;;	JE	short RES_OK
  3614                              <1> ;;	CMP	AH,BAD_ECC
  3615                              <1> ;;	JE	short RES_OK
  3616                              <1> ;;	;CALL	POD_TCHK		; CHECK FOR TIME OUT
  3617                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  3618                              <1> ;;					; (60 seconds)		
  3619                              <1> ;;	cmc
  3620                              <1> ;;	JC	short RES_ER		; FAILED
  3621                              <1> ;;	MOV	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  3622                              <1> ;;	MOV	AL,CL			; SEPARATE OUT SECTOR NUMBER
  3623                              <1> ;;	AND	AL,3FH
  3624                              <1> ;;	DEC	AL			; TRY PREVIOUS ONE
  3625                              <1> ;;	JZ	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  3626                              <1> ;;	AND	CL,0C0H 		; KEEP CYLINDER BITS
  3627                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  3628                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  3629                              <1> ;;	JMP	short RES_3		; TRY AGAIN
  3630                              <1> ;;;RES_ER: MOV	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  3631                              <1> ;;	;TEST	DL,1
  3632                              <1> ;;	;JNZ	short RES_E1
  3633                              <1> ;;	;MOV	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  3634                              <1> ;;;RES_E1:
  3635                              <1> ;;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  3636                              <1> ;;;RES_OK:
  3637                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  3638                              <1> ;;	;POP	BX
  3639                              <1> ;;	;RETn
  3640                              <1> ;
  3641                              <1> ;;SET_FAIL:
  3642                              <1> ;	;MOV	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  3643                              <1> ;	;CALL	CMOS_READ
  3644                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  3645                              <1> ;	;XCHG	AH,AL			; SAVE IT
  3646                              <1> ;	;CALL	CMOS_WRITE		; PUT IT OUT
  3647                              <1> ;	;RETn
  3648                              <1> ;
  3649                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  3650                              <1> ;	;POP	AX			; SAVE RETURN
  3651                              <1> ;	;POP	CX			; GET TIME OUT LIMITS
  3652                              <1> ;	;POP	BX
  3653                              <1> ;	;PUSH	BX			; AND SAVE THEM AGAIN
  3654                              <1> ;	;PUSH	CX
  3655                              <1> ;	;PUSH	AX
  3656                              <1> ;	;push	ds
  3657                              <1> ;	;xor	ax, ax
  3658                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  3659                              <1> ;	;MOV	AX, [TIMER_LOW]		; AX = CURRENT TIME
  3660                              <1> ;	;				; BX = START TIME
  3661                              <1> ;	;				; CX = END TIME
  3662                              <1> ;	;pop	ds
  3663                              <1> ;	;CMP	BX,CX
  3664                              <1> ;	;JB	short TCHK1		; START < END
  3665                              <1> ;	;CMP	BX,AX
  3666                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  3667                              <1> ;	;JMP	SHORT TCHK2		; END, CURRENT < START
  3668                              <1> ;;TCHK1: CMP	AX,BX
  3669                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  3670                              <1> ;;TCHK2: CMP	AX,CX
  3671                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  3672                              <1> ;;					; OR CURRENT < END < START
  3673                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  3674                              <1> ;;	RETn
  3675                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  3676                              <1> ;;	RETn
  3677                              <1> ;;
  3678                              <1> ;;int_13h:
  3679                              <1> 
  3680                              <1> ;----------------------------------------
  3681                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  3682                              <1> ;----------------------------------------
  3683                              <1> 
  3684                              <1> ; 01/06/2016
  3685                              <1> ; 29/05/2016 
  3686                              <1> ; 28/05/2016
  3687                              <1> ; 27/05/2016
  3688                              <1> ; 16/05/2016
  3689                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  3690                              <1> int33h:  ; DISK I/O
  3691                              <1> 	; 29/05/2016
  3692 00003CD6 80642408FE          <1> 	and	byte [esp+8], 11111110b  ; clear carry bit of eflags register
  3693                              <1> 	; 16/05/2016
  3694 00003CDB 1E                  <1> 	push	ds
  3695 00003CDC 53                  <1> 	push	ebx ; user's buffer address (virtual)
  3696 00003CDD 66BB1000            <1> 	mov	bx, KDATA ; System (Kernel's) data segment
  3697 00003CE1 8EDB                <1> 	mov	ds, bx
  3698 00003CE3 8F05[482D0100]      <1> 	pop	dword [user_buffer] ; 01/06/2016
  3699 00003CE9 C605[8E260100]00    <1> 	mov	byte [scount], 0 ; sector count for transfer
  3700 00003CF0 80FC03              <1> 	cmp	ah, 03h ; chs write
  3701 00003CF3 7743                <1> 	ja	short int33h_2
  3702 00003CF5 7407                <1> 	je	short int33h_0
  3703 00003CF7 80FC02              <1> 	cmp	ah, 02h ; chs read
  3704 00003CFA 7269                <1> 	jb	short int33h_5
  3705 00003CFC EB62                <1> 	jmp	short int33h_4
  3706                              <1> int33h_0:
  3707                              <1> 	; transfer user's buffer content to sector buffer
  3708 00003CFE 51                  <1> 	push	ecx
  3709 00003CFF 0FB6C8              <1> 	movzx	ecx, al
  3710                              <1> int33h_1:
  3711 00003D02 56                  <1> 	push	esi
  3712 00003D03 8B35[482D0100]      <1> 	mov	esi, [user_buffer]
  3713                              <1> 	; esi = user's buffer address (virtual, ebx)
  3714 00003D09 57                  <1> 	push	edi
  3715 00003D0A 06                  <1> 	push	es
  3716 00003D0B 50                  <1> 	push	eax
  3717 00003D0C 66B81000            <1> 	mov	ax, KDATA
  3718 00003D10 8EC0                <1> 	mov	es, ax
  3719 00003D12 BF00000700          <1> 	mov	edi, Cluster_Buffer
  3720 00003D17 C1E109              <1> 	shl	ecx, 9 ; * 512
  3721 00003D1A E89F9C0000          <1> 	call	transfer_from_user_buffer
  3722 00003D1F 58                  <1> 	pop	eax
  3723 00003D20 07                  <1> 	pop	es
  3724 00003D21 5F                  <1> 	pop	edi
  3725 00003D22 5E                  <1> 	pop	esi
  3726 00003D23 59                  <1> 	pop	ecx
  3727 00003D24 733F                <1> 	jnc	short int33h_5
  3728 00003D26 8B1D[482D0100]      <1> 	mov	ebx, [user_buffer] ; 01/06/2016
  3729 00003D2C 1F                  <1> 	pop	ds
  3730                              <1> 
  3731                              <1> 	; (*) 29/05/2016
  3732                              <1> 	; (*) retf 4 ; skip eflags on stack
  3733                              <1> 
  3734                              <1> 	; 29/05/2016 -set carry flag on stack-
  3735                              <1> 	; [esp] = EIP
  3736                              <1> 	; [esp+4] = CS
  3737                              <1> 	; [esp+8] = E-FLAGS
  3738 00003D2D 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
  3739                              <1> 	; [esp+12] = ESP (user)
  3740                              <1> 	; [esp+16] = SS (User)
  3741 00003D32 B8FF000000          <1> 	mov	eax, 0FFh ; Unknown error !?
  3742 00003D37 CF                  <1> 	iretd
  3743                              <1> 	
  3744                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
  3745                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
  3746                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
  3747                              <1> 	; // RETF instruction:
  3748                              <1> 	;
  3749                              <1> 	; IF OperandMode=32 THEN
  3750                              <1>  	;    Load CS:EIP from stack;
  3751                              <1>  	;    Set CS RPL to CPL;
  3752                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
  3753                              <1>  	;    Load SS:eSP from stack;
  3754                              <1>  	; ELSE (* OperandMode=16 *)
  3755                              <1>  	;    Load CS:IP from stack;
  3756                              <1>  	;    Set CS RPL to CPL;
  3757                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
  3758                              <1> 	;    Load SS:eSP from stack;
  3759                              <1>  	; FI;
  3760                              <1> 	;
  3761                              <1> 	; //
  3762                              <1> 
  3763                              <1> int33h_2:
  3764 00003D38 80FC05              <1> 	cmp	ah, 05h ; format track
  3765 00003D3B 770A                <1> 	ja	short int33h_3
  3766 00003D3D 7226                <1> 	jb	short int33h_5
  3767 00003D3F 51                  <1> 	push	ecx
  3768 00003D40 B901000000          <1> 	mov	ecx, 1
  3769 00003D45 EBBB                <1> 	jmp	short int33h_1
  3770                              <1> int33h_3:
  3771 00003D47 80FC1C              <1> 	cmp	ah, 1Ch ; LBA write
  3772 00003D4A 7719                <1> 	ja	short int33h_5
  3773 00003D4C 74B0                <1> 	je	short int33h_0
  3774 00003D4E 80FC1B              <1> 	cmp	ah, 1Bh ; LBA read
  3775 00003D51 740D                <1> 	je	short int33h_4
  3776 00003D53 80FC08              <1> 	cmp	ah, 08h ; get disk parameters
  3777 00003D56 750D                <1> 	jne	short int33h_5
  3778                              <1> 	; 01/06/2016
  3779 00003D58 8B1D[482D0100]      <1> 	mov	ebx, [user_buffer] ; user's buffer address
  3780 00003D5E EB0A                <1> 	jmp	short int33h_6
  3781                              <1> int33h_4:
  3782 00003D60 A2[8E260100]        <1> 	mov	byte [scount], al ; <= 128 sectors
  3783                              <1> int33h_5:
  3784 00003D65 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; max. 65536 bytes
  3785                              <1> 				    ; buf. addr: 70000h	
  3786                              <1> 	;mov	byte [ClusterBuffer_Valid], 0
  3787                              <1> int33h_6:
  3788 00003D6A 1F                  <1> 	pop	ds
  3789 00003D6B 9C                  <1> 	pushfd
  3790 00003D6C 0E                  <1> 	push 	cs
  3791 00003D6D E84B000000          <1> 	call 	DISK_IO
  3792 00003D72 2E8B1D[482D0100]    <1> 	mov	ebx, [CS:user_buffer] ; 01/06/2016
  3793 00003D79 723C                <1> 	jc	short int33h_9
  3794                              <1> 	;
  3795 00003D7B 2E803D[8E260100]00  <1> 	cmp	byte [CS:scount], 0
  3796 00003D83 762C                <1> 	jna	short int33h_7
  3797                              <1> 	; transfer sector buffer content to user's buffer
  3798 00003D85 06                  <1> 	push	es
  3799 00003D86 1E                  <1> 	push	ds
  3800 00003D87 50                  <1> 	push	eax
  3801 00003D88 66B81000            <1> 	mov	ax, KDATA
  3802 00003D8C 8ED8                <1> 	mov	ds, ax
  3803 00003D8E 8EC0                <1> 	mov	es, ax
  3804 00003D90 51                  <1> 	push	ecx
  3805 00003D91 56                  <1> 	push	esi
  3806 00003D92 57                  <1> 	push	edi
  3807 00003D93 0FB60D[8E260100]    <1> 	movzx	ecx, byte [scount]
  3808 00003D9A C1E109              <1> 	shl	ecx, 9 ; * 512 bytes
  3809 00003D9D 89DF                <1> 	mov	edi, ebx ; user's buffer address
  3810 00003D9F BE00000700          <1> 	mov	esi, Cluster_Buffer
  3811 00003DA4 E8CB9B0000          <1> 	call	transfer_to_user_buffer
  3812 00003DA9 5F                  <1> 	pop	edi
  3813 00003DAA 5E                  <1> 	pop	esi
  3814 00003DAB 59                  <1> 	pop	ecx
  3815 00003DAC 58                  <1> 	pop	eax
  3816 00003DAD 1F                  <1> 	pop	ds
  3817 00003DAE 07                  <1> 	pop	es
  3818 00003DAF 7201                <1> 	jc	short int33h_8
  3819                              <1> int33h_7:
  3820                              <1> 	; cf = 0  ; use eflags which is in stack
  3821 00003DB1 CF                  <1> 	iretd	
  3822                              <1> int33h_8:
  3823 00003DB2 B8FF000000          <1> 	mov	eax, 0FFh ; Unknown error !?
  3824                              <1> int33h_9:
  3825                              <1> 	; cf = 1
  3826                              <1> 
  3827                              <1> 	; (*) 29/05/2016	
  3828                              <1> 	; (*) retf 4 ; skip eflags on stack
  3829                              <1> 	; Note: This 'retf 4' was wrong, -it was causing
  3830                              <1> 	;       to stack errors in ring 3-
  3831                              <1> 	;	POP sequence of 'retf 4' is as
  3832                              <1> 	;       "eip, cs, eflags, esp, ss, +4 bytes" 
  3833                              <1>         ;       it is not as "eip, cs, +4 bytes, esp, ss" ! 
  3834                              <1> 
  3835                              <1> 	; 29/05/2016 -set carry flag on stack-
  3836 00003DB7 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
  3837 00003DBC CF                  <1> 	iretd
  3838                              <1> 
  3839                              <1> ; 29/05/2016
  3840                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  3841                              <1> 
  3842                              <1> DISK_IO:
  3843 00003DBD 80FA80              <1> 	CMP	DL,80H			; TEST FOR FIXED DISK DRIVE
  3844                              <1> 	;JAE	short A1		; YES, HANDLE HERE
  3845                              <1> 	;;;INT	40H			; DISKETTE HANDLER
  3846                              <1> 	;;call	int40h
  3847 00003DC0 0F8224F0FFFF        <1> 	jb	DISKETTE_IO_1
  3848                              <1> ;RET_2:
  3849                              <1> 	;RETf	2			; BACK TO CALLER
  3850                              <1> ;	retf	4
  3851                              <1> A1:
  3852 00003DC6 FB                  <1> 	STI				; ENABLE INTERRUPTS
  3853                              <1> 	;; 04/01/2015
  3854                              <1> 	;;OR	AH,AH
  3855                              <1> 	;;JNZ	short A2
  3856                              <1> 	;;INT	40H			; RESET NEC WHEN AH=0
  3857                              <1> 	;;SUB	AH,AH
  3858 00003DC7 80FA83              <1> 	CMP	DL,(80H + S_MAX_FILE - 1)
  3859                              <1> 	;JA	short RET_2
  3860 00003DCA 7616                <1> 	jna	short _A0
  3861                              <1> 	; 29/05/2016
  3862 00003DCC 1E                  <1> 	push	ds
  3863 00003DCD 6650                <1> 	push	ax
  3864 00003DCF 66B81000            <1> 	mov	ax, KDATA
  3865 00003DD3 8ED8                <1> 	mov	ds, ax
  3866 00003DD5 6658                <1> 	pop	ax
  3867 00003DD7 B4AA                <1>         mov     ah, 0AAh        ; Hard disk drive not ready !
  3868                              <1> 				; (Programmer's guide to AMIBIOS, 1992)
  3869 00003DD9 8825[63200100]      <1> 	mov     byte [DISK_STATUS1], ah
  3870 00003DDF 1F                  <1> 	pop	ds
  3871 00003DE0 EB38                <1> 	jmp	short RET_2
  3872                              <1> _A0:
  3873                              <1> 	; 18/01/2015
  3874 00003DE2 08E4                <1> 	or	ah,ah
  3875 00003DE4 743A                <1> 	jz	short A4
  3876 00003DE6 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  3877 00003DE9 7504                <1> 	jne	short A2
  3878 00003DEB 28E4                <1> 	sub	ah,ah	; Reset
  3879 00003DED EB31                <1> 	jmp	short A4
  3880                              <1> A2:
  3881 00003DEF 80FC08              <1> 	CMP	AH,08H			; GET PARAMETERS IS A SPECIAL CASE
  3882                              <1> 	;JNZ	short A3
  3883                              <1>         ;JMP    GET_PARM_N
  3884 00003DF2 0F8431030000        <1> 	je	GET_PARM_N
  3885 00003DF8 80FC15              <1> A3:	CMP	AH,15H			; READ DASD TYPE IS ALSO
  3886                              <1> 	;JNZ	short A4
  3887                              <1>         ;JMP    READ_DASD_TYPE
  3888 00003DFB 0F84DA020000        <1>         je      READ_DASD_TYPE
  3889                              <1> 	; 02/02/2015
  3890 00003E01 80FC1D              <1> 	cmp	ah, 1Dh			;(Temporary for Retro UNIX 386 v1)
  3891                              <1> 	; 12/01/2015
  3892 00003E04 F5                  <1> 	cmc
  3893 00003E05 7319                <1> 	jnc	short A4
  3894                              <1> int33h_bad_cmd:
  3895                              <1> 	; 16/05/2016
  3896                              <1> 	; 30/01/2015
  3897                              <1> 	; 29/05/2016
  3898 00003E07 1E                  <1> 	push	ds
  3899 00003E08 6650                <1> 	push	ax
  3900 00003E0A 66B81000            <1> 	mov	ax, KDATA
  3901 00003E0E 8ED8                <1> 	mov	ds, ax
  3902 00003E10 6658                <1> 	pop	ax
  3903 00003E12 B401                <1> 	mov	ah, BAD_CMD
  3904 00003E14 8825[63200100]      <1> 	mov     [DISK_STATUS1], ah ; BAD_CMD  ; COMMAND ERROR
  3905                              <1>         ;jmp	short RET_2
  3906                              <1> RET_2:
  3907                              <1> 	; (*) 29/05/2016
  3908                              <1> 	; (*) retf 4
  3909 00003E1A 804C240801          <1> 	or	byte [esp+8], 1 ; set carry bit of eflags register
  3910 00003E1F CF                  <1> 	iretd
  3911                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  3912 00003E20 C8080000            <1> 	ENTER	8,0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  3913 00003E24 53                  <1> 	PUSH	eBX			;  IN THE STACK, THE COMMAND BLOCK IS:
  3914 00003E25 51                  <1> 	PUSH	eCX			;   @CMD_BLOCK == BYTE PTR [BP]-8
  3915 00003E26 52                  <1> 	PUSH	eDX
  3916 00003E27 1E                  <1> 	PUSH	DS
  3917 00003E28 06                  <1> 	PUSH	ES
  3918 00003E29 56                  <1> 	PUSH	eSI
  3919 00003E2A 57                  <1> 	PUSH	eDI
  3920                              <1> 	;;04/01/2015
  3921                              <1> 	;;OR	AH,AH			; CHECK FOR RESET
  3922                              <1> 	;;JNZ	short A5
  3923                              <1> 	;;MOV	DL,80H			; FORCE DRIVE 80 FOR RESET
  3924                              <1> ;;A5:	
  3925                              <1> 	;push	cs
  3926                              <1> 	;pop	ds
  3927                              <1> 	; 21/02/2015
  3928 00003E2B 6650                <1> 	push	ax
  3929 00003E2D 66B81000            <1> 	mov	ax, KDATA
  3930 00003E31 8ED8                <1> 	mov	ds, ax
  3931 00003E33 8EC0                <1> 	mov	es, ax	
  3932 00003E35 6658                <1> 	pop	ax
  3933 00003E37 E88D000000          <1> 	CALL	DISK_IO_CONT		; PERFORM THE OPERATION
  3934                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  3935 00003E3C 8A25[63200100]      <1> 	MOV	AH,[DISK_STATUS1]	; GET STATUS FROM OPERATION
  3936                              <1> 	;(*) CMP AH,1			; SET THE CARRY FLAG TO INDICATE
  3937                              <1> 	;(*) CMC			; SUCCESS OR FAILURE
  3938 00003E42 5F                  <1> 	POP	eDI			; RESTORE REGISTERS
  3939 00003E43 5E                  <1> 	POP	eSI
  3940 00003E44 07                  <1>         POP     ES
  3941 00003E45 1F                  <1>         POP     DS
  3942 00003E46 5A                  <1> 	POP	eDX
  3943 00003E47 59                  <1> 	POP	eCX
  3944 00003E48 5B                  <1> 	POP	eBX
  3945 00003E49 C9                  <1> 	LEAVE				; ADJUST (SP) AND RESTORE (BP)
  3946                              <1> 	;RETf	2			; THROW AWAY SAVED FLAGS
  3947                              <1> 	; (*) 29/05/2016
  3948                              <1> 	; (*) retf 4
  3949 00003E4A 80FC01              <1> 	cmp	ah, 1
  3950 00003E4D 7205                <1> 	jc	short _A5 
  3951 00003E4F 804C240801          <1> 	or	byte [esp+8], 1 ; set carry bit of eflags register
  3952                              <1> _A5:
  3953 00003E54 CF                  <1> 	iretd
  3954                              <1> 
  3955                              <1> ; 21/02/2015
  3956                              <1> ;       dw --> dd
  3957                              <1> D1:					; FUNCTION TRANSFER TABLE
  3958 00003E55 [17400000]          <1> 	dd	DISK_RESET		; 000H
  3959 00003E59 [8E400000]          <1> 	dd	RETURN_STATUS		; 001H
  3960 00003E5D [9B400000]          <1> 	dd	DISK_READ		; 002H
  3961 00003E61 [A4400000]          <1> 	dd	DISK_WRITE		; 003H
  3962 00003E65 [AD400000]          <1> 	dd	DISK_VERF		; 004H
  3963 00003E69 [C5400000]          <1> 	dd	FMT_TRK 		; 005H
  3964 00003E6D [0D400000]          <1> 	dd	BAD_COMMAND		; 006H	FORMAT BAD SECTORS
  3965 00003E71 [0D400000]          <1> 	dd	BAD_COMMAND		; 007H	FORMAT DRIVE
  3966 00003E75 [0D400000]          <1> 	dd	BAD_COMMAND		; 008H	RETURN PARAMETERS
  3967 00003E79 [B0410000]          <1> 	dd	INIT_DRV		; 009H
  3968 00003E7D [0F420000]          <1> 	dd	RD_LONG 		; 00AH
  3969 00003E81 [18420000]          <1> 	dd	WR_LONG 		; 00BH
  3970 00003E85 [21420000]          <1> 	dd	DISK_SEEK		; 00CH
  3971 00003E89 [17400000]          <1> 	dd	DISK_RESET		; 00DH
  3972 00003E8D [0D400000]          <1> 	dd	BAD_COMMAND		; 00EH	READ BUFFER
  3973 00003E91 [0D400000]          <1> 	dd	BAD_COMMAND		; 00FH	WRITE BUFFER
  3974 00003E95 [49420000]          <1> 	dd	TST_RDY 		; 010H
  3975 00003E99 [6D420000]          <1> 	dd	HDISK_RECAL		; 011H
  3976 00003E9D [0D400000]          <1> 	dd	BAD_COMMAND		; 012H	MEMORY DIAGNOSTIC
  3977 00003EA1 [0D400000]          <1> 	dd	BAD_COMMAND		; 013H	DRIVE DIAGNOSTIC
  3978 00003EA5 [A3420000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 014H	CONTROLLER DIAGNOSTIC
  3979                              <1> 	; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  3980 00003EA9 [0D400000]          <1> 	dd	BAD_COMMAND		; 015h
  3981 00003EAD [0D400000]          <1> 	dd	BAD_COMMAND		; 016h
  3982 00003EB1 [0D400000]          <1> 	dd	BAD_COMMAND		; 017h
  3983 00003EB5 [0D400000]          <1> 	dd	BAD_COMMAND		; 018h
  3984 00003EB9 [0D400000]          <1> 	dd	BAD_COMMAND		; 019h
  3985 00003EBD [0D400000]          <1> 	dd	BAD_COMMAND		; 01Ah
  3986 00003EC1 [9B400000]          <1> 	dd	DISK_READ		; 01Bh ; LBA read
  3987 00003EC5 [A4400000]          <1> 	dd	DISK_WRITE		; 01Ch ; LBA write
  3988                              <1> D1L     EQU    $ - D1
  3989                              <1> 
  3990                              <1> DISK_IO_CONT:
  3991                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  3992 00003EC9 80FC01              <1> 	CMP	AH,01H			; RETURN STATUS
  3993                              <1> 	;;JNZ	short SU0
  3994                              <1>         ;;JMP    RETURN_STATUS
  3995 00003ECC 0F84BC010000        <1> 	je	RETURN_STATUS
  3996                              <1> SU0:
  3997 00003ED2 C605[63200100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  3998                              <1> 	;;PUSH	BX			; SAVE DATA ADDRESS
  3999                              <1> 	;mov	si, bx ;; 14/02/2015
  4000 00003ED9 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  4001 00003EDB 8A1D[64200100]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  4002                              <1> 	;; 04/01/2015
  4003                              <1> 	;;PUSH	AX
  4004 00003EE1 80E27F              <1> 	AND	DL,7FH			; GET DRIVE AS 0 OR 1
  4005                              <1> 					; (get drive number as 0 to 3)
  4006 00003EE4 38D3                <1> 	CMP	BL,DL
  4007                              <1>         ;;JBE   BAD_COMMAND_POP         ; INVALID DRIVE
  4008 00003EE6 0F8621010000        <1>         jbe     BAD_COMMAND ;; 14/02/2015
  4009                              <1>         ;
  4010                              <1> 	;;03/01/2015
  4011 00003EEC 29DB                <1> 	sub	ebx, ebx
  4012 00003EEE 88D3                <1> 	mov	bl, dl
  4013                              <1> 	;sub	bh, bh
  4014 00003EF0 883D[78200100]      <1> 	mov	[LBAMode], bh 	; 0
  4015                              <1> 	;;test	byte [bx+hd0_type], 1	; LBA ready ?
  4016                              <1> 	;test	byte [ebx+hd0_type], 1
  4017                              <1> 	;jz	short su1		; no
  4018                              <1> 	;inc	byte [LBAMode]
  4019                              <1> ;su1:
  4020                              <1> 	; 21/02/2015 (32 bit modification)
  4021                              <1> 	;04/01/2015
  4022 00003EF6 6650                <1> 	push	ax ; ***
  4023                              <1> 	;PUSH	ES ; **
  4024 00003EF8 6652                <1> 	PUSH	DX ; *
  4025 00003EFA 6650                <1> 	push	ax
  4026 00003EFC E888060000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS
  4027                              <1> 	; 02/02/2015
  4028                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  4029 00003F01 668B4310            <1> 	mov	ax, [ebx+16]
  4030 00003F05 66A3[0EED0000]      <1> 	mov	[HF_PORT], ax
  4031                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  4032 00003F0B 668B5312            <1> 	mov	dx, [ebx+18]
  4033 00003F0F 668915[10ED0000]    <1> 	mov	[HF_REG_PORT], dx
  4034                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  4035 00003F16 8A4314              <1> 	mov	al, [ebx+20]
  4036                              <1> 	; 23/02/2015
  4037 00003F19 A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  4038 00003F1B 7406                <1> 	jz 	short su1
  4039 00003F1D FE05[78200100]      <1> 	inc	byte [LBAMode] ; 1 
  4040                              <1> su1: 	 
  4041 00003F23 C0E804              <1> 	shr 	al, 4
  4042 00003F26 2401                <1> 	and	al, 1			
  4043 00003F28 A2[12ED0000]        <1> 	mov	[hf_m_s], al 
  4044                              <1> 	;
  4045                              <1> 	; 03/01/2015
  4046                              <1> 	;MOV	AL,byte [ES:BX+8]	; GET CONTROL BYTE MODIFIER
  4047 00003F2D 8A4308              <1> 	mov	al, [ebx+8]
  4048                              <1> 	;MOV	DX,[HF_REG_PORT]	; Device Control register	
  4049 00003F30 EE                  <1> 	OUT	DX,AL			; SET EXTRA HEAD OPTION
  4050                              <1> 					; Control Byte:  (= 08h, here)
  4051                              <1> 					; bit 0 - 0
  4052                              <1> 					; bit 1 - nIEN (1 = disable irq)
  4053                              <1> 					; bit 2 - SRST (software RESET)
  4054                              <1> 					; bit 3 - use extra heads (8 to 15)
  4055                              <1> 					;         -always set to 1-	
  4056                              <1> 					; (bits 3 to 7 are reserved
  4057                              <1> 					;          for ATA devices)
  4058 00003F31 8A25[65200100]      <1> 	MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  4059 00003F37 80E4C0              <1> 	AND	AH,0C0H 		; CONTROL BYTE
  4060 00003F3A 08C4                <1> 	OR	AH,AL
  4061 00003F3C 8825[65200100]      <1> 	MOV	[CONTROL_BYTE],AH	
  4062                              <1> 	; 04/01/2015
  4063 00003F42 6658                <1> 	pop	ax
  4064 00003F44 665A                <1> 	pop	dx ; * ;; 14/02/2015
  4065 00003F46 20E4                <1> 	and	ah, ah	; Reset function ?
  4066 00003F48 7507                <1> 	jnz	short su2
  4067                              <1> 	;;pop	dx ; * ;; 14/02/2015
  4068                              <1> 	;pop	es ; **
  4069 00003F4A 6658                <1> 	pop	ax ; ***
  4070                              <1> 	;;pop	bx
  4071 00003F4C E9C6000000          <1>         jmp     DISK_RESET
  4072                              <1> su2:
  4073 00003F51 803D[78200100]00    <1> 	cmp	byte [LBAMode], 0
  4074 00003F58 7661                <1> 	jna	short su3
  4075                              <1> 	;
  4076                              <1> 	; 02/02/2015 (LBA read/write function calls)
  4077 00003F5A 80FC1B              <1> 	cmp	ah, 1Bh
  4078 00003F5D 720B                <1> 	jb	short lbarw1
  4079 00003F5F 80FC1C              <1> 	cmp	ah, 1Ch
  4080 00003F62 775C                <1> 	ja 	short invldfnc
  4081                              <1> 	;;pop	dx ; * ; 14/02/2015
  4082                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  4083 00003F64 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  4084                              <1> 	;; 14/02/2015
  4085 00003F66 88D1                <1> 	mov	cl, dl ; 14/02/2015
  4086                              <1> 	;;mov	dx, bx
  4087                              <1> 	;mov	dx, si ; higher word of LBA address (bits 16-23)
  4088                              <1> 	;;mov	bx, di
  4089                              <1> 	;mov	si, di ; Buffer offset
  4090 00003F68 EB31                <1> 	jmp	short lbarw2
  4091                              <1> lbarw1:
  4092                              <1> 	; convert CHS to LBA
  4093                              <1> 	;
  4094                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  4095                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  4096                              <1> 	;	+ Sector - 1
  4097 00003F6A 6652                <1> 	push	dx ; * ;; 14/02/2015
  4098                              <1> 	;xor	dh, dh
  4099 00003F6C 31D2                <1> 	xor	edx, edx
  4100                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  4101 00003F6E 8A530E              <1> 	mov	dl, [ebx+14]
  4102                              <1> 	;xor	ah, ah
  4103 00003F71 31C0                <1> 	xor	eax, eax
  4104                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  4105 00003F73 8A4302              <1> 	mov	al, [ebx+2]
  4106 00003F76 FEC8                <1> 	dec	al
  4107 00003F78 6640                <1> 	inc	ax		; 0 =  256
  4108 00003F7A 66F7E2              <1> 	mul 	dx
  4109                              <1> 		; AX = # of Heads" * Sectors/Track
  4110 00003F7D 6689CA              <1> 	mov	dx, cx
  4111                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  4112 00003F80 83E13F              <1> 	and	ecx, 3fh
  4113 00003F83 86D6                <1> 	xchg	dl, dh
  4114 00003F85 C0EE06              <1> 	shr	dh, 6
  4115                              <1> 		; DX = cylinder (0 to 1023)
  4116                              <1> 	;mul 	dx
  4117                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  4118 00003F88 F7E2                <1> 	mul	edx
  4119 00003F8A FEC9                <1> 	dec	cl  ; sector - 1
  4120                              <1> 	;add	ax, cx
  4121                              <1> 	;adc	dx, 0
  4122                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector -1
  4123 00003F8C 01C8                <1> 	add	eax, ecx
  4124 00003F8E 6659                <1> 	pop	cx ; * ; ch = head, cl = drive number (zero based)
  4125                              <1> 	;push	dx
  4126                              <1> 	;push	ax
  4127 00003F90 50                  <1> 	push	eax
  4128                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  4129 00003F91 8A430E              <1> 	mov	al, [ebx+14]
  4130 00003F94 F6E5                <1> 	mul	ch
  4131                              <1> 		;  AX = Head * Sectors/Track
  4132 00003F96 6699                <1>         cwd
  4133                              <1> 	;pop	dx
  4134 00003F98 5A                  <1> 	pop	edx
  4135                              <1> 	;add	ax, dx
  4136                              <1> 	;pop	dx
  4137                              <1> 	;adc	dx, 0 ; add carry bit
  4138 00003F99 01D0                <1> 	add	eax, edx
  4139                              <1> lbarw2:
  4140 00003F9B 29D2                <1> 	sub	edx, edx ; 21/02/2015
  4141 00003F9D 88CA                <1> 	mov	dl, cl ; 21/02/2015
  4142 00003F9F C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  4143                              <1> 				; NOTE: Features register (1F1h, 171h)
  4144                              <1> 				; is not used for ATA device R/W functions. 
  4145                              <1> 				; It is old/obsolete 'write precompensation'
  4146                              <1> 				; register and error register
  4147                              <1> 				; for old ATA/IDE devices.
  4148                              <1> 	; 18/01/2014
  4149                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  4150 00003FA3 8A0D[12ED0000]      <1> 	mov	cl, [hf_m_s]
  4151                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  4152                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  4153                              <1> 				; bit 6 = 1 = LBA mode
  4154                              <1> 				; bit 7 = 1
  4155 00003FA9 80C90E              <1> 	or	cl, 0Eh ; 1110b
  4156                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  4157 00003FAC 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  4158 00003FB1 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  4159                              <1> 	;or	dh, ch
  4160 00003FB4 09C8                <1> 	or	eax, ecx	
  4161                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  4162                              <1> 				  ; (Sector Number Register)
  4163                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  4164                              <1> 				  ; (Cylinder Low Register)
  4165                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  4166                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  4167                              <1> 				  ; (Cylinder High Register)
  4168                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  4169                              <1> 				  ; (Drive/Head Register)
  4170                              <1> 	
  4171                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  4172 00003FB6 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  4173                              <1> 	;14/02/2015
  4174                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  4175 00003FB9 EB38                <1> 	jmp	short su4
  4176                              <1> su3:
  4177                              <1> 	; 02/02/2015 
  4178                              <1> 	; (Temporary functions 1Bh & 1Ch are not valid for CHS mode) 
  4179 00003FBB 80FC14              <1> 	cmp 	ah, 14h
  4180 00003FBE 7604                <1> 	jna 	short chsfnc
  4181                              <1> invldfnc:
  4182                              <1>         ; 14/02/2015  
  4183                              <1> 	;pop	es ; **
  4184 00003FC0 6658                <1>         pop     ax ; ***
  4185                              <1>         ;jmp     short BAD_COMMAND_POP
  4186 00003FC2 EB49                <1>         jmp     short BAD_COMMAND
  4187                              <1> chsfnc:	
  4188                              <1> 	;MOV	AX,[ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  4189 00003FC4 668B4305            <1> 	mov	ax, [ebx+5]
  4190 00003FC8 66C1E802            <1> 	SHR	AX,2
  4191 00003FCC 8845F8              <1> 	MOV	[CMD_BLOCK],AL
  4192                              <1> 	;;MOV	AL,[ES:BX+8]		; GET CONTROL BYTE MODIFIER
  4193                              <1> 	;;PUSH	DX
  4194                              <1> 	;;MOV	DX,[HF_REG_PORT]
  4195                              <1> 	;;OUT	DX,AL			; SET EXTRA HEAD OPTION
  4196                              <1> 	;;POP	DX ; * 
  4197                              <1> 	;;POP	ES ; **
  4198                              <1> 	;;MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  4199                              <1> 	;;AND	AH,0C0H 		; CONTROL BYTE	
  4200                              <1> 	;;OR	AH,AL
  4201                              <1> 	;;MOV	[CONTROL_BYTE],AH
  4202                              <1> 	;
  4203 00003FCF 88C8                <1> 	MOV	AL,CL			; GET SECTOR NUMBER
  4204 00003FD1 243F                <1> 	AND	AL,3FH
  4205 00003FD3 8845FA              <1> 	MOV	[CMD_BLOCK+2],AL
  4206 00003FD6 886DFB              <1> 	MOV	[CMD_BLOCK+3],CH 	; GET CYLINDER NUMBER
  4207 00003FD9 88C8                <1> 	MOV	AL,CL
  4208 00003FDB C0E806              <1> 	SHR	AL,6
  4209 00003FDE 8845FC              <1> 	MOV	[CMD_BLOCK+4],AL 	; CYLINDER HIGH ORDER 2 BITS
  4210                              <1> 	;;05/01/2015
  4211                              <1> 	;;MOV	AL,DL			; DRIVE NUMBER
  4212 00003FE1 A0[12ED0000]        <1> 	mov	al, [hf_m_s]
  4213 00003FE6 C0E004              <1> 	SHL	AL,4
  4214 00003FE9 80E60F              <1> 	AND	DH,0FH			; HEAD NUMBER
  4215 00003FEC 08F0                <1> 	OR	AL,DH
  4216                              <1> 	;OR	AL,80H or 20H
  4217 00003FEE 0CA0                <1> 	OR	AL,80h+20h		; ECC AND 512 BYTE SECTORS
  4218 00003FF0 8845FD              <1> 	MOV	[CMD_BLOCK+5],AL 	; ECC/SIZE/DRIVE/HEAD
  4219                              <1> su4:
  4220                              <1> 	;POP	ES ; **
  4221                              <1>         ;; 14/02/2015
  4222                              <1>         ;;POP   AX
  4223                              <1>         ;;MOV   [CMD_BLOCK+1],AL        ; SECTOR COUNT
  4224                              <1>         ;;PUSH  AX
  4225                              <1>         ;;MOV   AL,AH                   ; GET INTO LOW BYTE
  4226                              <1>         ;;XOR   AH,AH                   ; ZERO HIGH BYTE
  4227                              <1>         ;;SAL   AX,1                    ; *2 FOR TABLE LOOKUP
  4228 00003FF3 6658                <1>         pop     ax ; ***
  4229 00003FF5 8845F9              <1>         mov     [CMD_BLOCK+1], al
  4230 00003FF8 29DB                <1>         sub	ebx, ebx
  4231 00003FFA 88E3                <1> 	mov     bl, ah
  4232                              <1>         ;xor     bh, bh
  4233                              <1>         ;sal     bx, 1
  4234 00003FFC 66C1E302            <1>         sal	bx, 2	; 32 bit offset (21/02/2015)
  4235                              <1> 	;;MOV   SI,AX                   ; PUT INTO SI FOR BRANCH
  4236                              <1>         ;;CMP   AX,D1L                  ; TEST WITHIN RANGE
  4237                              <1>         ;;JNB   short BAD_COMMAND_POP
  4238                              <1>         ;cmp     bx, D1L
  4239 00004000 83FB74              <1> 	cmp	ebx, D1L
  4240 00004003 7308                <1> 	jnb	short BAD_COMMAND
  4241                              <1>         ;xchg    bx, si
  4242 00004005 87DE                <1>         xchg	ebx, esi
  4243                              <1> 	;;;POP	AX			; RESTORE AX
  4244                              <1> 	;;;POP	BX			; AND DATA ADDRESS
  4245                              <1> 	
  4246                              <1> 	;;PUSH	CX
  4247                              <1> 	;;PUSH	AX			; ADJUST ES:BX
  4248                              <1> 	;MOV	CX,BX			; GET 3 HIGH ORDER NIBBLES OF BX
  4249                              <1> 	;SHR	CX,4
  4250                              <1> 	;MOV	AX,ES
  4251                              <1> 	;ADD	AX,CX
  4252                              <1> 	;MOV	ES,AX
  4253                              <1> 	;AND	BX,000FH		; ES:BX CHANGED TO ES:000X
  4254                              <1> 	;;POP	AX
  4255                              <1> 	;;POP	CX
  4256                              <1> 	;;JMP	word [CS:SI+D1]
  4257                              <1> 	;jmp	word [SI+D1]
  4258 00004007 FFA6[553E0000]      <1> 	jmp	dword [esi+D1]
  4259                              <1> ;;BAD_COMMAND_POP:
  4260                              <1> ;;	POP	AX
  4261                              <1> ;;	POP	BX
  4262                              <1> BAD_COMMAND:
  4263 0000400D C605[63200100]01    <1>         MOV     byte [DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  4264 00004014 B000                <1> 	MOV	AL,0
  4265 00004016 C3                  <1> 	RETn
  4266                              <1> 
  4267                              <1> ;----------------------------------------
  4268                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  4269                              <1> ;----------------------------------------
  4270                              <1> 
  4271                              <1> ; 18-1-2015 : one controller reset (not other one)
  4272                              <1> 
  4273                              <1> DISK_RESET:
  4274 00004017 FA                  <1> 	CLI
  4275 00004018 E4A1                <1> 	IN	AL,INTB01		; GET THE MASK REGISTER
  4276                              <1> 	;JMP	$+2
  4277                              <1> 	IODELAY
  4277 0000401A EB00                <2>  jmp short $+2
  4277 0000401C EB00                <2>  jmp short $+2
  4278                              <1> 	;AND	AL,0BFH 		; ENABLE FIXED DISK INTERRUPT
  4279 0000401E 243F                <1> 	and	al,3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  4280 00004020 E6A1                <1> 	OUT	INTB01,AL
  4281 00004022 FB                  <1> 	STI				; START INTERRUPTS
  4282                              <1> 	; 14/02/2015
  4283 00004023 6689D7              <1> 	mov	di, dx	
  4284                              <1> 	; 04/01/2015
  4285                              <1> 	;xor	di,di
  4286                              <1> drst0:
  4287 00004026 B004                <1> 	MOV	AL,04H  ; bit 2 - SRST 
  4288                              <1> 	;MOV	DX,HF_REG_PORT
  4289 00004028 668B15[10ED0000]    <1> 	MOV	DX,[HF_REG_PORT]
  4290 0000402F EE                  <1> 	OUT	DX,AL			; RESET
  4291                              <1> ;	MOV	CX,10			; DELAY COUNT
  4292                              <1> ;DRD:	DEC	CX
  4293                              <1> ;	JNZ	short DRD		; WAIT 4.8 MICRO-SEC
  4294                              <1> 	;mov	cx,2			; wait for 30 micro seconds	
  4295 00004030 B902000000          <1>         mov	ecx, 2 ; 21/02/2015
  4296 00004035 E822DCFFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  4297                              <1>                                         ; 40 micro seconds)
  4298 0000403A A0[65200100]        <1> 	mov	al,[CONTROL_BYTE]
  4299 0000403F 240F                <1> 	AND	AL,0FH			; SET HEAD OPTION
  4300 00004041 EE                  <1> 	OUT	DX,AL			; TURN RESET OFF
  4301 00004042 E838040000          <1> 	CALL	NOT_BUSY
  4302 00004047 7515                <1> 	JNZ	short DRERR		; TIME OUT ON RESET
  4303 00004049 668B15[0EED0000]    <1> 	MOV	DX,[HF_PORT]
  4304 00004050 FEC2                <1> 	inc	dl  ; HF_PORT+1
  4305                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  4306                              <1>         ;mov     cl, 10
  4307 00004052 B90A000000          <1>         mov     ecx, 10 ; 21/02/2015 
  4308                              <1> drst1:
  4309 00004057 EC                  <1> 	IN	AL,DX			; GET RESET STATUS
  4310 00004058 3C01                <1> 	CMP	AL,1
  4311                              <1> 	; 04/01/2015
  4312 0000405A 740A                <1> 	jz	short drst2
  4313                              <1> 	;JNZ	short DRERR		; BAD RESET STATUS
  4314                              <1>         	; Drive/Head Register - bit 4
  4315 0000405C E2F9                <1> 	loop	drst1
  4316                              <1> DRERR:	
  4317 0000405E C605[63200100]05    <1> 	MOV	byte [DISK_STATUS1],BAD_RESET ; CARD FAILED
  4318 00004065 C3                  <1> 	RETn
  4319                              <1> drst2:
  4320                              <1> 	; 14/02/2015
  4321 00004066 6689FA              <1> 	mov	dx,di
  4322                              <1> ;drst3:
  4323                              <1> ;	; 05/01/2015
  4324                              <1> ;	shl 	di,1
  4325                              <1> ;	; 04/01/2015
  4326                              <1> ;	mov	ax,[di+hd_cports]
  4327                              <1> ;	cmp	ax,[HF_REG_PORT]
  4328                              <1> ;	je	short drst4
  4329                              <1> ;	mov	[HF_REG_PORT], ax
  4330                              <1> ;	; 03/01/2015
  4331                              <1> ;	mov	ax,[di+hd_ports]
  4332                              <1> ;       mov     [HF_PORT], ax
  4333                              <1> ;	; 05/01/2014
  4334                              <1> ;	shr	di,1
  4335                              <1> ;	; 04/01/2015
  4336                              <1> ;	jmp	short drst0	; reset other controller
  4337                              <1> ;drst4:
  4338                              <1> ;	; 05/01/2015
  4339                              <1> ;	shr	di,1
  4340                              <1> ;	mov	al,[di+hd_dregs]
  4341                              <1> ;	and	al,10h ; bit 4 only
  4342                              <1> ;	shr	al,4 ; bit 4  -> bit 0
  4343                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  4344                              <1> 	;
  4345 00004069 A0[12ED0000]        <1> 	mov	al, [hf_m_s] ; 18/01/2015
  4346 0000406E A801                <1> 	test	al,1
  4347                              <1> ;	jnz	short drst6
  4348 00004070 7516                <1>         jnz     short drst4
  4349 00004072 8065FDEF            <1> 	AND     byte [CMD_BLOCK+5],0EFH ; SET TO DRIVE 0
  4350                              <1> ;drst5:
  4351                              <1> drst3:
  4352 00004076 E835010000          <1> 	CALL	INIT_DRV		; SET MAX HEADS
  4353                              <1> 	;mov	dx,di
  4354 0000407B E8ED010000          <1> 	CALL	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  4355                              <1> 	; 04/01/2014
  4356                              <1> ;	inc	di
  4357                              <1> ;	mov	dx,di
  4358                              <1> ;	cmp	dl,[HF_NUM]
  4359                              <1> ;	jb	short drst3
  4360                              <1> ;DRE:
  4361 00004080 C605[63200100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; IGNORE ANY SET UP ERRORS
  4362 00004087 C3                  <1> 	RETn
  4363                              <1> ;drst6:
  4364                              <1> drst4:		; Drive/Head Register - bit 4
  4365 00004088 804DFD10            <1> 	OR      byte [CMD_BLOCK+5],010H ; SET TO DRIVE 1     
  4366                              <1>         ;jmp    short drst5
  4367 0000408C EBE8                <1>         jmp     short drst3
  4368                              <1> 
  4369                              <1> ;----------------------------------------
  4370                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  4371                              <1> ;----------------------------------------
  4372                              <1> 
  4373                              <1> RETURN_STATUS:
  4374 0000408E A0[63200100]        <1> 	MOV	AL,[DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  4375 00004093 C605[63200100]00    <1>         MOV     byte [DISK_STATUS1],0   ; RESET STATUS
  4376 0000409A C3                  <1> 	RETn
  4377                              <1> 
  4378                              <1> ;----------------------------------------
  4379                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  4380                              <1> ;----------------------------------------
  4381                              <1> 
  4382                              <1> DISK_READ:
  4383 0000409B C645FE20            <1> 	MOV	byte [CMD_BLOCK+6],READ_CMD
  4384 0000409F E954020000          <1>         JMP     COMMANDI
  4385                              <1> 
  4386                              <1> ;----------------------------------------
  4387                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  4388                              <1> ;----------------------------------------
  4389                              <1> 
  4390                              <1> DISK_WRITE:
  4391 000040A4 C645FE30            <1> 	MOV	byte [CMD_BLOCK+6],WRITE_CMD
  4392 000040A8 E9A6020000          <1>         JMP     COMMANDO
  4393                              <1> 
  4394                              <1> ;----------------------------------------
  4395                              <1> ;	DISK VERIFY	     (AH = 04H) :
  4396                              <1> ;----------------------------------------
  4397                              <1> 
  4398                              <1> DISK_VERF:
  4399 000040AD C645FE40            <1> 	MOV	byte [CMD_BLOCK+6],VERIFY_CMD
  4400 000040B1 E814030000          <1> 	CALL	COMMAND
  4401 000040B6 750C                <1> 	JNZ	short VERF_EXIT		; CONTROLLER STILL BUSY
  4402 000040B8 E886030000          <1> 	CALL	_WAIT			; (Original: CALL WAIT)	
  4403 000040BD 7505                <1> 	JNZ	short VERF_EXIT		; TIME OUT
  4404 000040BF E813040000          <1> 	CALL	CHECK_STATUS
  4405                              <1> VERF_EXIT:
  4406 000040C4 C3                  <1> 	RETn
  4407                              <1> 
  4408                              <1> ;----------------------------------------
  4409                              <1> ;	FORMATTING	     (AH = 05H) :
  4410                              <1> ;----------------------------------------
  4411                              <1> 
  4412                              <1> FMT_TRK:				; FORMAT TRACK	(AH = 005H)
  4413 000040C5 C645FE50            <1> 	MOV	byte [CMD_BLOCK+6],FMTTRK_CMD
  4414                              <1> 	;PUSH	ES
  4415                              <1> 	;PUSH	BX
  4416 000040C9 53                  <1> 	push	ebx
  4417 000040CA E8BA040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  4418                              <1> 	;MOV	AL,[ES:BX+14]		; GET SECTORS/TRACK
  4419 000040CF 8A430E              <1> 	mov	al, [ebx+14]
  4420 000040D2 8845F9              <1> 	MOV	[CMD_BLOCK+1],AL 	; SET SECTOR COUNT IN COMMAND
  4421 000040D5 5B                  <1> 	pop	ebx
  4422                              <1> 	;POP	BX
  4423                              <1> 	;POP	ES
  4424 000040D6 E97F020000          <1>         JMP     CMD_OF                  ; GO EXECUTE THE COMMAND
  4425                              <1> 
  4426                              <1> ;----------------------------------------
  4427                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  4428                              <1> ;----------------------------------------
  4429                              <1> 
  4430                              <1> READ_DASD_TYPE:
  4431                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  4432 000040DB 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  4433                              <1> 	;PUSH	ES
  4434 000040DC 53                  <1> 	PUSH	eBX
  4435                              <1> 	;CALL	DDS			; ESTABLISH ADDRESSING
  4436                              <1> 	;push	cs
  4437                              <1> 	;pop	ds
  4438 000040DD 66BB1000            <1>         mov	bx, KDATA
  4439 000040E1 8EDB                <1> 	mov	ds, bx
  4440                              <1> 	;mov	es, bx
  4441 000040E3 C605[63200100]00    <1> 	MOV     byte [DISK_STATUS1],0
  4442 000040EA 8A1D[64200100]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  4443 000040F0 80E27F              <1> 	AND	DL,7FH			; GET DRIVE NUMBER
  4444 000040F3 38D3                <1> 	CMP	BL,DL
  4445 000040F5 7627                <1> 	JBE	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  4446 000040F7 E88D040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETER ADDRESS
  4447                              <1> 	;MOV	AL,[ES:BX+2]		; HEADS
  4448 000040FC 8A4302              <1> 	mov	al, [ebx+2]
  4449                              <1> 	;MOV	CL,[ES:BX+14]
  4450 000040FF 8A4B0E              <1> 	mov	cl, [ebx+14]
  4451 00004102 F6E9                <1> 	IMUL	CL			; * NUMBER OF SECTORS
  4452                              <1> 	;MOV	CX,[ES:BX]		; MAX NUMBER OF CYLINDERS
  4453 00004104 668B0B              <1> 	mov	cx ,[ebx]
  4454                              <1> 	;
  4455                              <1> 	; 02/01/2015 
  4456                              <1> 	; ** leave the last cylinder as reserved for diagnostics **
  4457                              <1> 	; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  4458 00004107 6649                <1> 	DEC	CX			; LEAVE ONE FOR DIAGNOSTICS
  4459                              <1> 	;
  4460 00004109 66F7E9              <1> 	IMUL	CX			; NUMBER OF SECTORS
  4461 0000410C 6689D1              <1> 	MOV	CX,DX			; HIGH ORDER HALF
  4462 0000410F 6689C2              <1> 	MOV	DX,AX			; LOW ORDER HALF
  4463                              <1> 	;SUB	AX,AX
  4464 00004112 28C0                <1> 	sub	al, al
  4465 00004114 B403                <1> 	MOV	AH,03H			; INDICATE FIXED DISK
  4466 00004116 5B                  <1> RDT2:	POP	eBX			; RESTORE REGISTERS
  4467                              <1> 	;POP	ES
  4468 00004117 1F                  <1> 	POP	DS
  4469                              <1> 	; (*) CLC			; CLEAR CARRY
  4470                              <1> 	;RETf	2
  4471                              <1> 	; (*) 29/05/2016
  4472                              <1> 	; (*) retf 4
  4473 00004118 80642408FE          <1> 	and	byte [esp+8], 0FEh ; clear carry bit of eflags register
  4474 0000411D CF                  <1> 	iretd
  4475                              <1> 
  4476                              <1> RDT_NOT_PRESENT:
  4477 0000411E 6629C0              <1> 	SUB	AX,AX			; DRIVE NOT PRESENT RETURN
  4478 00004121 6689C1              <1> 	MOV	CX,AX			; ZERO BLOCK COUNT
  4479 00004124 6689C2              <1> 	MOV	DX,AX
  4480 00004127 EBED                <1> 	JMP	short RDT2
  4481                              <1> 
  4482                              <1> ; 28/05/2016
  4483                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  4484                              <1> 
  4485                              <1> ;----------------------------------------
  4486                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  4487                              <1> ;----------------------------------------
  4488                              <1> 
  4489                              <1> GET_PARM_N:
  4490                              <1> 	; ebx = user's buffer address for parameters table
  4491                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  4492 00004129 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  4493 0000412A 06                  <1> 	PUSH	ES
  4494 0000412B 53                  <1> 	PUSH	eBX
  4495                              <1> 	;MOV	AX,ABS0 		; ESTABLISH ADDRESSING
  4496                              <1> 	;MOV	DS,AX
  4497                              <1> 	;TEST	DL,1			; CHECK FOR DRIVE 1
  4498                              <1> 	;JZ	short G0
  4499                              <1> 	;LES	BX,@HF1_TBL_VEC
  4500                              <1> 	;JMP	SHORT G1
  4501                              <1> ;G0:	LES	BX,@HF_TBL_VEC
  4502                              <1> ;G1:
  4503                              <1> 	;CALL	DDS			; ESTABLISH SEGMENT
  4504                              <1> 	; 22/12/2014
  4505                              <1> 	;push	cs
  4506                              <1> 	;pop	ds
  4507 0000412C 66BB1000            <1> 	mov	bx, KDATA
  4508 00004130 8EDB                <1> 	mov	ds, bx
  4509 00004132 8EC3                <1> 	mov	es, bx	; 27/05/2016
  4510                              <1> 	;
  4511 00004134 80EA80              <1> 	SUB	DL,80H
  4512 00004137 80FA04              <1> 	CMP	DL,MAX_FILE		; TEST WITHIN RANGE
  4513 0000413A 7361                <1> 	JAE	short G4
  4514                              <1> 	;
  4515 0000413C 31DB                <1> 	xor	ebx, ebx ; 21/02/2015
  4516                              <1> 	; 22/12/2014
  4517 0000413E 88D3                <1> 	mov	bl, dl
  4518                              <1> 	;xor	bh, bh  
  4519 00004140 C0E302              <1> 	shl	bl, 2			; convert index to offset
  4520                              <1> 	;add	bx, HF_TBL_VEC
  4521 00004143 81C3[68200100]      <1> 	add	ebx, HF_TBL_VEC
  4522                              <1> 	;mov	ax, [bx+2]
  4523                              <1> 	;mov	es, ax			; dpt segment
  4524                              <1> 	;mov	bx, [bx]		; dpt offset
  4525 00004149 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  4526                              <1> 
  4527 0000414B C605[63200100]00    <1> 	MOV	byte [DISK_STATUS1],0
  4528                              <1>         ;MOV     AX,[ES:BX]             ; MAX NUMBER OF CYLINDERS
  4529 00004152 668B03              <1> 	mov	ax, [ebx]
  4530                              <1> 	;;SUB	AX,2			; ADJUST FOR 0-N
  4531 00004155 6648                <1> 	dec	ax			; max. cylinder number
  4532 00004157 88C5                <1> 	MOV	CH,AL
  4533 00004159 66250003            <1> 	AND	AX,0300H		; HIGH TWO BITS OF CYLINDER
  4534 0000415D 66D1E8              <1> 	SHR	AX,1
  4535 00004160 66D1E8              <1> 	SHR	AX,1
  4536                              <1> 	;OR	AL,[ES:BX+14]		; SECTORS
  4537 00004163 0A430E              <1> 	or	al, [ebx+14]
  4538 00004166 88C1                <1> 	MOV	CL,AL
  4539                              <1> 	;MOV	DH,[ES:BX+2]		; HEADS
  4540 00004168 8A7302              <1> 	mov	dh, [ebx+2]
  4541 0000416B FECE                <1> 	DEC	DH			; 0-N RANGE
  4542 0000416D 8A15[64200100]      <1> 	MOV	DL,[HF_NUM]		; DRIVE COUNT
  4543 00004173 6629C0              <1> 	SUB	AX,AX
  4544                              <1>         ;27/12/2014 
  4545                              <1> 	;mov	di, bx			; HDPT offset
  4546                              <1> 	
  4547                              <1> 	; 27/05/2016
  4548                              <1> 	; return fixed disk parameters table to user
  4549                              <1> 	; in user's buffer, which is pointed by EBX
  4550                              <1> 	;
  4551 00004176 873C24              <1> 	xchg	edi, [esp]		; ebx (input)-> edi, edi -> [esp]
  4552 00004179 56                  <1> 	push	esi
  4553 0000417A 89DE                <1> 	mov	esi, ebx		; hard disk parameter table (32 bytes)	
  4554 0000417C 89FB                <1> 	mov	ebx, edi		; ebx = user's buffer address
  4555 0000417E 51                  <1> 	push	ecx
  4556 0000417F 50                  <1> 	push	eax
  4557 00004180 B920000000          <1> 	mov	ecx, 32 ; 32 bytes
  4558 00004185 E8EA970000          <1> 	call	transfer_to_user_buffer ; trdosk6.s (16/05/2016)
  4559 0000418A 58                  <1> 	pop	eax
  4560 0000418B 59                  <1> 	pop	ecx
  4561 0000418C 5E                  <1> 	pop	esi
  4562 0000418D 5F                  <1> 	pop	edi
  4563 0000418E 730A                <1> 	jnc	short G5
  4564                              <1> 	; 29/05/2016 (*)
  4565 00004190 B8FF000000          <1> 	mov	eax, 0FFh ; unknown error !
  4566                              <1> _G6:
  4567 00004195 804C241001          <1> 	or	byte [esp+16], 1 ; set carry bit of eflags register
  4568                              <1> G5:
  4569                              <1> 	; 27/05/2016
  4570                              <1> 	;POP	eBX			; RESTORE REGISTERS
  4571 0000419A 07                  <1> 	POP	ES
  4572 0000419B 1F                  <1> 	POP	DS
  4573                              <1> 	;RETf	2
  4574                              <1> 	; (*) 29/05/2016
  4575                              <1> 	; (*) retf 4
  4576                              <1> 	; (*) or byte [esp+8], 1 ; set carry bit of eflags register
  4577 0000419C CF                  <1> 	iretd
  4578                              <1> G4:
  4579 0000419D C605[63200100]07    <1> 	MOV     byte [DISK_STATUS1],INIT_FAIL ; OPERATION FAILED
  4580 000041A4 B407                <1> 	MOV	AH,INIT_FAIL
  4581 000041A6 28C0                <1> 	SUB	AL,AL
  4582 000041A8 6629D2              <1> 	SUB	DX,DX
  4583 000041AB 6629C9              <1> 	SUB	CX,CX
  4584                              <1> 	; 29/05/2016 (*)
  4585                              <1> 	;STC				; SET ERROR FLAG
  4586                              <1> 	;JMP	short G5
  4587 000041AE EBE5                <1> 	jmp	short _G6
  4588                              <1> 
  4589                              <1> ;----------------------------------------
  4590                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  4591                              <1> ;----------------------------------------
  4592                              <1> 	; 03/01/2015
  4593                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  4594                              <1> 	; logical sector per logical track
  4595                              <1> 	; and logical heads - 1 would be set but
  4596                              <1> 	; it is seen as it will be good
  4597                              <1> 	; if physical parameters will be set here
  4598                              <1> 	; because, number of heads <= 16.
  4599                              <1> 	; (logical heads usually more than 16)
  4600                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  4601                              <1> 	;	== INT 13h physical parameters
  4602                              <1> 
  4603                              <1> ;INIT_DRV:
  4604                              <1> ;	MOV	byte [CMD_BLOCK+6],SET_PARM_CMD
  4605                              <1> ;	CALL	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  4606                              <1> ;	MOV	AL,[ES:BX+2]		; GET NUMBER OF HEADS
  4607                              <1> ;	DEC	AL			; CONVERT TO 0-INDEX
  4608                              <1> ;	MOV	AH,[CMD_BLOCK+5] 	; GET SDH REGISTER
  4609                              <1> ;	AND	AH,0F0H 		; CHANGE HEAD NUMBER
  4610                              <1> ;	OR	AH,AL			; TO MAX HEAD
  4611                              <1> ;	MOV	[CMD_BLOCK+5],AH
  4612                              <1> ;	MOV	AL,[ES:BX+14]		; MAX SECTOR NUMBER
  4613                              <1> ;	MOV	[CMD_BLOCK+1],AL
  4614                              <1> ;	SUB	AX,AX
  4615                              <1> ;	MOV	[CMD_BLOCK+3],AL 	; ZERO FLAGS
  4616                              <1> ;	CALL	COMMAND 		; TELL CONTROLLER
  4617                              <1> ;	JNZ	short INIT_EXIT		; CONTROLLER BUSY ERROR
  4618                              <1> ;	CALL	NOT_BUSY		; WAIT FOR IT TO BE DONE
  4619                              <1> ;	JNZ	short INIT_EXIT		; TIME OUT
  4620                              <1> ;	CALL	CHECK_STATUS
  4621                              <1> ;INIT_EXIT:
  4622                              <1> ;	RETn
  4623                              <1> 
  4624                              <1> ; 04/01/2015
  4625                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  4626                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  4627                              <1> INIT_DRV:
  4628                              <1> 	;xor	ah,ah
  4629 000041B0 31C0                <1> 	xor	eax, eax ; 21/02/2015
  4630 000041B2 B00B                <1> 	mov	al,11 ; Physical heads from translated HDPT
  4631 000041B4 3825[78200100]      <1>         cmp     [LBAMode], ah   ; 0
  4632 000041BA 7702                <1> 	ja	short idrv0
  4633 000041BC B002                <1> 	mov	al,2  ; Physical heads from standard HDPT
  4634                              <1> idrv0:
  4635                              <1> 	; DL = drive number (0 based)
  4636 000041BE E8C6030000          <1> 	call	GET_VEC
  4637                              <1> 	;push	bx
  4638 000041C3 53                  <1> 	push	ebx ; 21/02/2015
  4639                              <1> 	;add	bx,ax
  4640 000041C4 01C3                <1> 	add	ebx, eax
  4641                              <1> 	;; 05/01/2015
  4642 000041C6 8A25[12ED0000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  4643                              <1> 	;;and 	ah,1 
  4644 000041CC C0E404              <1> 	shl	ah,4
  4645 000041CF 80CCA0              <1> 	or	ah,0A0h  ; Drive/Head register - 10100000b (A0h)	
  4646                              <1> 	;mov	al,[es:bx]
  4647 000041D2 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  4648 000041D4 FEC8                <1> 	dec	al	 ; last head number 
  4649                              <1> 	;and	al,0Fh
  4650 000041D6 08E0                <1> 	or	al,ah	 ; lower 4 bits for head number
  4651                              <1> 	;
  4652 000041D8 C645FE91            <1> 	mov	byte [CMD_BLOCK+6],SET_PARM_CMD
  4653 000041DC 8845FD              <1> 	mov	[CMD_BLOCK+5],al
  4654                              <1> 	;pop	bx
  4655 000041DF 5B                  <1> 	pop	ebx
  4656 000041E0 29C0                <1> 	sub	eax, eax ; 21/02/2015
  4657 000041E2 B004                <1> 	mov	al,4 ; Physical sec per track from translated HDPT
  4658 000041E4 803D[78200100]00    <1> 	cmp	byte [LBAMode], 0
  4659 000041EB 7702                <1> 	ja	short idrv1
  4660 000041ED B00E                <1> 	mov	al,14 ; Physical sec per track from standard HDPT
  4661                              <1> idrv1:
  4662                              <1> 	;xor	ah,ah
  4663                              <1> 	;add	bx,ax
  4664 000041EF 01C3                <1> 	add	ebx, eax ; 21/02/2015
  4665                              <1> 	;mov	al,[es:bx]
  4666                              <1> 			; sector number
  4667 000041F1 8A03                <1> 	mov	al, [ebx]
  4668 000041F3 8845F9              <1> 	mov	[CMD_BLOCK+1],al
  4669 000041F6 28C0                <1> 	sub	al,al
  4670 000041F8 8845FB              <1> 	mov	[CMD_BLOCK+3],al  ; ZERO FLAGS
  4671 000041FB E8CA010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  4672 00004200 750C                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  4673 00004202 E878020000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  4674 00004207 7505                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  4675 00004209 E8C9020000          <1> 	call	CHECK_STATUS
  4676                              <1> INIT_EXIT:
  4677 0000420E C3                  <1> 	RETn
  4678                              <1> 
  4679                              <1> ;----------------------------------------
  4680                              <1> ;	READ LONG	     (AH = 0AH) :
  4681                              <1> ;----------------------------------------
  4682                              <1> 
  4683                              <1> RD_LONG:
  4684                              <1> 	;MOV	@CMD_BLOCK+6,READ_CMD OR ECC_MODE
  4685 0000420F C645FE22            <1>         mov     byte [CMD_BLOCK+6],READ_CMD + ECC_MODE 
  4686 00004213 E9E0000000          <1>         JMP     COMMANDI
  4687                              <1> 
  4688                              <1> ;----------------------------------------
  4689                              <1> ;	WRITE LONG	     (AH = 0BH) :
  4690                              <1> ;----------------------------------------
  4691                              <1> 
  4692                              <1> WR_LONG:
  4693                              <1> 	;MOV	@CMD_BLOCK+6,WRITE_CMD OR ECC_MODE
  4694 00004218 C645FE32            <1>         MOV     byte [CMD_BLOCK+6],WRITE_CMD + ECC_MODE
  4695 0000421C E932010000          <1>         JMP     COMMANDO
  4696                              <1> 
  4697                              <1> ;----------------------------------------
  4698                              <1> ;	SEEK		     (AH = 0CH) :
  4699                              <1> ;----------------------------------------
  4700                              <1> 
  4701                              <1> DISK_SEEK:
  4702 00004221 C645FE70            <1>         MOV     byte [CMD_BLOCK+6],SEEK_CMD
  4703 00004225 E8A0010000          <1> 	CALL	COMMAND
  4704 0000422A 751C                <1> 	JNZ	short DS_EXIT 		; CONTROLLER BUSY ERROR
  4705 0000422C E812020000          <1> 	CALL	_WAIT
  4706 00004231 7515                <1>         JNZ     DS_EXIT                 ; TIME OUT ON SEEK
  4707 00004233 E89F020000          <1> 	CALL	CHECK_STATUS
  4708 00004238 803D[63200100]40    <1>         CMP     byte [DISK_STATUS1],BAD_SEEK
  4709 0000423F 7507                <1> 	JNE	short DS_EXIT
  4710 00004241 C605[63200100]00    <1>         MOV     byte [DISK_STATUS1],0
  4711                              <1> DS_EXIT:
  4712 00004248 C3                  <1> 	RETn
  4713                              <1> 
  4714                              <1> ;----------------------------------------
  4715                              <1> ;	TEST DISK READY      (AH = 10H) :
  4716                              <1> ;----------------------------------------
  4717                              <1> 
  4718                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  4719 00004249 E831020000          <1> 	CALL	NOT_BUSY
  4720 0000424E 751C                <1> 	JNZ	short TR_EX
  4721 00004250 8A45FD              <1> 	MOV	AL,[CMD_BLOCK+5] 	; SELECT DRIVE
  4722 00004253 668B15[0EED0000]    <1> 	MOV	DX,[HF_PORT]
  4723 0000425A 80C206              <1> 	add	dl,6
  4724 0000425D EE                  <1> 	OUT	DX,AL
  4725 0000425E E88C020000          <1> 	CALL	CHECK_ST		; CHECK STATUS ONLY
  4726 00004263 7507                <1> 	JNZ	short TR_EX
  4727 00004265 C605[63200100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; WIPE OUT DATA CORRECTED ERROR
  4728                              <1> TR_EX:	
  4729 0000426C C3                  <1> 	RETn
  4730                              <1> 
  4731                              <1> ;----------------------------------------
  4732                              <1> ;	RECALIBRATE	     (AH = 11H) :
  4733                              <1> ;----------------------------------------
  4734                              <1> 
  4735                              <1> HDISK_RECAL:
  4736 0000426D C645FE10            <1>         MOV     byte [CMD_BLOCK+6],RECAL_CMD ; 10h, 16
  4737 00004271 E854010000          <1> 	CALL	COMMAND 		; START THE OPERATION
  4738 00004276 7523                <1> 	JNZ	short RECAL_EXIT	; ERROR
  4739 00004278 E8C6010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION
  4740 0000427D 7407                <1> 	JZ	short RECAL_X 		; TIME OUT ONE OK ?
  4741 0000427F E8BF010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION LONGER
  4742 00004284 7515                <1> 	JNZ	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  4743                              <1> RECAL_X:
  4744 00004286 E84C020000          <1> 	CALL	CHECK_STATUS
  4745 0000428B 803D[63200100]40    <1> 	CMP	byte [DISK_STATUS1],BAD_SEEK ; SEEK NOT COMPLETE
  4746 00004292 7507                <1> 	JNE	short RECAL_EXIT	; IS OK
  4747 00004294 C605[63200100]00    <1> 	MOV	byte [DISK_STATUS1],0
  4748                              <1> RECAL_EXIT:
  4749 0000429B 803D[63200100]00    <1>         CMP     byte [DISK_STATUS1],0
  4750 000042A2 C3                  <1> 	RETn
  4751                              <1> 
  4752                              <1> ;----------------------------------------
  4753                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  4754                              <1> ;----------------------------------------
  4755                              <1> 
  4756                              <1> CTLR_DIAGNOSTIC:
  4757 000042A3 FA                  <1>         CLI                             ; DISABLE INTERRUPTS WHILE CHANGING MASK
  4758 000042A4 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  4759                              <1> 	;AND	AL,0BFH
  4760 000042A6 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  4761                              <1> 	;JMP	$+2
  4762                              <1> 	IODELAY
  4762 000042A8 EB00                <2>  jmp short $+2
  4762 000042AA EB00                <2>  jmp short $+2
  4763 000042AC E6A1                <1> 	OUT	INTB01,AL
  4764                              <1> 	IODELAY
  4764 000042AE EB00                <2>  jmp short $+2
  4764 000042B0 EB00                <2>  jmp short $+2
  4765 000042B2 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  4766 000042B4 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  4767                              <1> 	;JMP	$+2
  4768                              <1> 	IODELAY
  4768 000042B6 EB00                <2>  jmp short $+2
  4768 000042B8 EB00                <2>  jmp short $+2
  4769 000042BA E621                <1> 	OUT	INTA01,AL
  4770 000042BC FB                  <1> 	STI
  4771 000042BD E8BD010000          <1> 	CALL	NOT_BUSY		; WAIT FOR CARD
  4772 000042C2 752B                <1> 	JNZ	short CD_ERR		; BAD CARD
  4773                              <1> 	;MOV	DX, HF_PORT+7
  4774 000042C4 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4775 000042CB 80C207              <1> 	add	dl, 7
  4776 000042CE B090                <1> 	MOV	AL,DIAG_CMD		; START DIAGNOSE
  4777 000042D0 EE                  <1> 	OUT	DX,AL
  4778 000042D1 E8A9010000          <1> 	CALL	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  4779 000042D6 B480                <1> 	MOV	AH,TIME_OUT
  4780 000042D8 7517                <1> 	JNZ	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  4781                              <1> 	;MOV	DX,HF_PORT+1		; GET ERROR REGISTER
  4782 000042DA 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4783 000042E1 FEC2                <1> 	inc	dl
  4784 000042E3 EC                  <1> 	IN	AL,DX
  4785 000042E4 A2[5A200100]        <1> 	MOV	[HF_ERROR],AL		; SAVE IT
  4786 000042E9 B400                <1> 	MOV	AH,0
  4787 000042EB 3C01                <1> 	CMP	AL,1			; CHECK FOR ALL OK
  4788 000042ED 7402                <1> 	JE	SHORT CD_EXIT
  4789 000042EF B420                <1> CD_ERR: MOV	AH,BAD_CNTLR
  4790                              <1> CD_EXIT:
  4791 000042F1 8825[63200100]      <1> 	MOV	[DISK_STATUS1],AH
  4792 000042F7 C3                  <1> 	RETn
  4793                              <1> 
  4794                              <1> ;----------------------------------------
  4795                              <1> ; COMMANDI				:
  4796                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  4797                              <1> ;	NSECTOR RETURNS ZERO		:
  4798                              <1> ;----------------------------------------
  4799                              <1> COMMANDI:
  4800 000042F8 E862020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  4801 000042FD 7253                <1> 	JC	short CMD_ABORT
  4802                              <1> 	;MOV	DI,BX
  4803 000042FF 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  4804 00004301 E8C4000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  4805 00004306 754A                <1> 	JNZ	short CMD_ABORT
  4806                              <1> CMD_I1:
  4807 00004308 E836010000          <1> 	CALL	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  4808 0000430D 7543                <1> 	JNZ	short TM_OUT		; TIME OUT
  4809                              <1> cmd_i1x: ; 18/02/2016
  4810                              <1> 	;MOV	CX,256			; SECTOR SIZE IN WORDS
  4811 0000430F B900010000          <1> 	mov	ecx, 256 ; 21/02/2015	
  4812                              <1> 	;MOV	DX,HF_PORT
  4813 00004314 668B15[0EED0000]    <1> 	mov	dx,[HF_PORT]
  4814 0000431B FA                  <1> 	CLI
  4815 0000431C FC                  <1> 	CLD
  4816 0000431D F3666D              <1> 	REP	INSW			; GET THE SECTOR
  4817 00004320 FB                  <1> 	STI
  4818 00004321 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL INPUT
  4819 00004325 7419                <1> 	JZ	short CMD_I3
  4820 00004327 E880010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4821 0000432C 7224                <1> 	JC	short TM_OUT
  4822                              <1> 	;MOV	DX,HF_PORT
  4823 0000432E 668B15[0EED0000]    <1> 	mov	dx,[HF_PORT]
  4824                              <1> 	;MOV	CX,4			; GET ECC BYTES
  4825 00004335 B904000000          <1> 	mov 	ecx, 4 ; mov cx, 4 
  4826 0000433A EC                  <1> CMD_I2: IN	AL,DX
  4827                              <1> 	;MOV	[ES:DI],AL		; GO SLOW FOR BOARD
  4828 0000433B 8807                <1> 	mov 	[edi], al ; 21/02/2015
  4829 0000433D 47                  <1> 	INC	eDI
  4830 0000433E E2FA                <1> 	LOOP	CMD_I2
  4831                              <1> CMD_I3: 
  4832                              <1> 	; wait for 400 ns
  4833 00004340 80C207              <1> 	add 	dl, 7
  4834 00004343 EC                  <1> 	in	al, dx
  4835 00004344 EC                  <1> 	in	al, dx
  4836 00004345 EC                  <1> 	in	al, dx
  4837                              <1> 	;
  4838 00004346 E88C010000          <1> 	CALL	CHECK_STATUS
  4839 0000434B 7505                <1> 	JNZ	short CMD_ABORT		; ERROR RETURNED
  4840 0000434D FE4DF9              <1> 	DEC	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  4841                              <1> 	;JNZ	SHORT CMD_I1
  4842 00004350 75BD                <1> 	jnz	short cmd_i1x ; 18/02/2016
  4843                              <1> CMD_ABORT:
  4844 00004352 C3                  <1> TM_OUT: RETn
  4845                              <1> 
  4846                              <1> ;----------------------------------------
  4847                              <1> ; COMMANDO				:
  4848                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  4849                              <1> ;	NSECTOR RETURNS ZERO		:
  4850                              <1> ;----------------------------------------
  4851                              <1> COMMANDO:
  4852 00004353 E807020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  4853 00004358 72F8                <1> 	JC	short CMD_ABORT
  4854 0000435A 89DE                <1> CMD_OF: MOV	eSI,eBX ; 21/02/2015
  4855 0000435C E869000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  4856 00004361 75EF                <1> 	JNZ	short CMD_ABORT
  4857 00004363 E844010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4858 00004368 72E8                <1> 	JC	short TM_OUT			; TOO LONG
  4859                              <1> CMD_O1: ;PUSH	DS
  4860                              <1> 	;PUSH	ES			; MOVE ES TO DS
  4861                              <1> 	;POP	DS
  4862                              <1> 	;MOV	CX,256			; PUT THE DATA OUT TO THE CARD
  4863                              <1> 	;MOV	DX,HF_PORT
  4864                              <1> 	; 01/02/2015
  4865 0000436A 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4866                              <1> 	;push	es
  4867                              <1> 	;pop	ds
  4868                              <1> 	;mov	cx, 256
  4869 00004371 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015
  4870 00004376 FA                  <1> 	CLI
  4871 00004377 FC                  <1> 	CLD
  4872 00004378 F3666F              <1> 	REP	OUTSW
  4873 0000437B FB                  <1> 	STI
  4874                              <1> 	;POP	DS			; RESTORE DS
  4875 0000437C F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL OUTPUT
  4876 00004380 7419                <1> 	JZ	short CMD_O3
  4877 00004382 E825010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4878 00004387 72C9                <1> 	JC	short TM_OUT
  4879                              <1> 	;MOV	DX,HF_PORT
  4880 00004389 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4881                              <1> 	;MOV	CX,4			; OUTPUT THE ECC BYTES
  4882 00004390 B904000000          <1> 	mov	ecx, 4  ; mov cx, 4
  4883                              <1> CMD_O2: ;MOV	AL,[ES:SI]
  4884 00004395 8A06                <1> 	mov	al, [esi]
  4885 00004397 EE                  <1> 	OUT	DX,AL
  4886 00004398 46                  <1> 	INC	eSI
  4887 00004399 E2FA                <1> 	LOOP	CMD_O2
  4888                              <1> CMD_O3:
  4889 0000439B E8A3000000          <1> 	CALL	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  4890 000043A0 75B0                <1> 	JNZ	short TM_OUT		; ERROR RETURNED
  4891 000043A2 E830010000          <1> 	CALL	CHECK_STATUS
  4892 000043A7 75A9                <1> 	JNZ	short CMD_ABORT
  4893 000043A9 F605[59200100]08    <1> 	TEST	byte [HF_STATUS],ST_DRQ	; CHECK FOR MORE
  4894 000043B0 75B8                <1> 	JNZ	SHORT CMD_O1
  4895                              <1> 	;MOV	DX,HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  4896 000043B2 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4897                              <1> 	;add	dl, 2
  4898 000043B9 FEC2                <1> 	inc	dl
  4899 000043BB FEC2                <1> 	inc	dl
  4900 000043BD EC                  <1> 	IN	AL,DX			;
  4901 000043BE A8FF                <1> 	TEST	AL,0FFH 		;
  4902 000043C0 7407                <1> 	JZ	short CMD_O4			; COUNT = 0  OK
  4903 000043C2 C605[63200100]BB    <1> 	MOV	byte [DISK_STATUS1],UNDEF_ERR 
  4904                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  4905                              <1> CMD_O4:
  4906 000043C9 C3                  <1> 	RETn
  4907                              <1> 
  4908                              <1> ;--------------------------------------------------------
  4909                              <1> ; COMMAND						:
  4910                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  4911                              <1> ; OUTPUT						:
  4912                              <1> ;	BL = STATUS					:
  4913                              <1> ;	BH = ERROR REGISTER				:
  4914                              <1> ;--------------------------------------------------------
  4915                              <1> 
  4916                              <1> COMMAND:
  4917 000043CA 53                  <1> 	PUSH	eBX			; WAIT FOR SEEK COMPLETE AND READY
  4918                              <1> 	;;MOV	CX,DELAY_2		; SET INITIAL DELAY BEFORE TEST
  4919                              <1> COMMAND1:
  4920                              <1> 	;;PUSH	CX			; SAVE LOOP COUNT
  4921 000043CB E879FEFFFF          <1> 	CALL	TST_RDY 		; CHECK DRIVE READY
  4922                              <1> 	;;POP	CX
  4923 000043D0 7419                <1> 	JZ	short COMMAND2		; DRIVE IS READY
  4924 000043D2 803D[63200100]80    <1>         CMP     byte [DISK_STATUS1],TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
  4925                              <1> 	;JZ	short CMD_TIMEOUT
  4926                              <1> 	;;LOOP	COMMAND1		; KEEP TRYING FOR A WHILE
  4927                              <1> 	;JMP	SHORT COMMAND4		; ITS NOT GOING TO GET READY
  4928 000043D9 7507                <1> 	jne	short COMMAND4
  4929                              <1> CMD_TIMEOUT:
  4930 000043DB C605[63200100]20    <1> 	MOV	byte [DISK_STATUS1],BAD_CNTLR
  4931                              <1> COMMAND4:
  4932 000043E2 5B                  <1> 	POP	eBX
  4933 000043E3 803D[63200100]00    <1>         CMP     byte [DISK_STATUS1],0   ; SET CONDITION CODE FOR CALLER
  4934 000043EA C3                  <1> 	RETn
  4935                              <1> COMMAND2:
  4936 000043EB 5B                  <1> 	POP	eBX
  4937 000043EC 57                  <1> 	PUSH	eDI
  4938 000043ED C605[5B200100]00    <1> 	MOV	byte [HF_INT_FLAG],0	; RESET INTERRUPT FLAG
  4939 000043F4 FA                  <1> 	CLI				; INHIBIT INTERRUPTS WHILE CHANGING MASK
  4940 000043F5 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  4941                              <1> 	;AND	AL,0BFH
  4942 000043F7 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
  4943                              <1> 	;JMP	$+2
  4944                              <1> 	IODELAY
  4944 000043F9 EB00                <2>  jmp short $+2
  4944 000043FB EB00                <2>  jmp short $+2
  4945 000043FD E6A1                <1> 	OUT	INTB01,AL
  4946 000043FF E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  4947 00004401 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  4948                              <1> 	;JMP	$+2
  4949                              <1> 	IODELAY
  4949 00004403 EB00                <2>  jmp short $+2
  4949 00004405 EB00                <2>  jmp short $+2
  4950 00004407 E621                <1> 	OUT	INTA01,AL
  4951 00004409 FB                  <1> 	STI
  4952 0000440A 31FF                <1> 	XOR	eDI,eDI			; INDEX THE COMMAND TABLE
  4953                              <1> 	;MOV	DX,HF_PORT+1		; DISK ADDRESS
  4954 0000440C 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  4955 00004413 FEC2                <1> 	inc	dl
  4956 00004415 F605[65200100]C0    <1> 	TEST	byte [CONTROL_BYTE],0C0H ; CHECK FOR RETRY SUPPRESSION
  4957 0000441C 7411                <1> 	JZ	short COMMAND3
  4958 0000441E 8A45FE              <1> 	MOV	AL, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
  4959 00004421 24F0                <1> 	AND	AL,0F0H 		; GET RID OF MODIFIERS
  4960 00004423 3C20                <1> 	CMP	AL,20H			; 20H-40H IS READ, WRITE, VERIFY
  4961 00004425 7208                <1> 	JB	short COMMAND3
  4962 00004427 3C40                <1> 	CMP	AL,40H
  4963 00004429 7704                <1> 	JA	short COMMAND3
  4964 0000442B 804DFE01            <1> 	OR	byte [CMD_BLOCK+6],NO_RETRIES 
  4965                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
  4966                              <1> COMMAND3:
  4967 0000442F 8A443DF8            <1> 	MOV	AL,[CMD_BLOCK+eDI]	; GET THE COMMAND STRING BYTE
  4968 00004433 EE                  <1> 	OUT	DX,AL			; GIVE IT TO CONTROLLER
  4969                              <1> 	IODELAY
  4969 00004434 EB00                <2>  jmp short $+2
  4969 00004436 EB00                <2>  jmp short $+2
  4970 00004438 47                  <1> 	INC	eDI			; NEXT BYTE IN COMMAND BLOCK
  4971 00004439 6642                <1> 	INC	DX			; NEXT DISK ADAPTER REGISTER
  4972 0000443B 6683FF07            <1> 	cmp	di, 7	; 1/1/2015	; ALL DONE?
  4973 0000443F 75EE                <1> 	JNZ	short COMMAND3		; NO--GO DO NEXT ONE
  4974 00004441 5F                  <1> 	POP	eDI
  4975 00004442 C3                  <1> 	RETn				; ZERO FLAG IS SET
  4976                              <1> 
  4977                              <1> ;CMD_TIMEOUT:
  4978                              <1> ;	MOV	byte [DISK_STATUS1],BAD_CNTLR
  4979                              <1> ;COMMAND4:
  4980                              <1> ;	POP	BX
  4981                              <1> ;	CMP	[DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  4982                              <1> ;	RETn
  4983                              <1> 
  4984                              <1> ;----------------------------------------
  4985                              <1> ;	WAIT FOR INTERRUPT		:
  4986                              <1> ;----------------------------------------
  4987                              <1> ;WAIT:
  4988                              <1> _WAIT:
  4989 00004443 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
  4990                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
  4991                              <1> 	;CLC
  4992                              <1> 	;MOV	AX,9000H		; DEVICE WAIT INTERRUPT
  4993                              <1> 	;INT	15H
  4994                              <1> 	;JC	WT2			; DEVICE TIMED OUT
  4995                              <1> 	;MOV	BL,DELAY_1		; SET DELAY COUNT
  4996                              <1> 
  4997                              <1> 	;mov	bl, WAIT_HDU_INT_HI
  4998                              <1> 	;; 21/02/2015
  4999                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
  5000                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
  5001 00004444 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
  5002                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
  5003                              <1> ;-----	WAIT LOOP
  5004                              <1> 
  5005                              <1> WT1:	
  5006                              <1> 	;TEST	byte [HF_INT_FLAG],80H	; TEST FOR INTERRUPT
  5007 00004449 F605[5B200100]C0    <1> 	test 	byte [HF_INT_FLAG],0C0h
  5008                              <1> 	;LOOPZ	WT1
  5009 00004450 7517                <1> 	JNZ	short WT3		; INTERRUPT--LETS GO
  5010                              <1> 	;DEC	BL
  5011                              <1> 	;JNZ	short WT1		; KEEP TRYING FOR A WHILE
  5012                              <1> 
  5013                              <1> WT1_hi:
  5014 00004452 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
  5015 00004454 A810                <1> 	test	al, 10h			; transition on memory
  5016 00004456 75FA                <1> 	jnz	short WT1_hi		; refresh.
  5017                              <1> WT1_lo:
  5018 00004458 E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
  5019 0000445A A810                <1> 	test	al, 10h			
  5020 0000445C 74FA                <1> 	jz	short WT1_lo
  5021 0000445E E2E9                <1> 	loop	WT1
  5022                              <1> 	;;or	bl, bl
  5023                              <1> 	;;jz	short WT2	
  5024                              <1> 	;;dec	bl
  5025                              <1> 	;;jmp	short WT1
  5026                              <1> 	;dec	bl
  5027                              <1> 	;jnz	short WT1	
  5028                              <1> 
  5029 00004460 C605[63200100]80    <1> WT2:	MOV	byte [DISK_STATUS1],TIME_OUT ; REPORT TIME OUT ERROR
  5030 00004467 EB0E                <1> 	JMP	SHORT WT4
  5031 00004469 C605[63200100]00    <1> WT3:	MOV	byte [DISK_STATUS1],0
  5032 00004470 C605[5B200100]00    <1> 	MOV	byte [HF_INT_FLAG],0
  5033 00004477 803D[63200100]00    <1> WT4:	CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  5034 0000447E C3                  <1> 	RETn
  5035                              <1> 
  5036                              <1> ;----------------------------------------
  5037                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
  5038                              <1> ;----------------------------------------
  5039                              <1> NOT_BUSY:
  5040 0000447F FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
  5041                              <1> 	;PUSH	eBX
  5042                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
  5043 00004480 668B15[0EED0000]    <1> 	mov	DX, [HF_PORT]
  5044 00004487 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
  5045                              <1> 	;MOV	BL,DELAY_1
  5046                              <1> 					; wait for 10 seconds
  5047                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
  5048                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
  5049                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
  5050 0000448A B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
  5051                              <1> 	;
  5052                              <1> ;;      mov     byte [wait_count], 0    ; Reset wait counter
  5053                              <1> NB1:	
  5054 0000448F EC                  <1> 	IN	AL,DX			; CHECK STATUS
  5055                              <1> 	;TEST	AL,ST_BUSY
  5056 00004490 2480                <1> 	and	al, ST_BUSY
  5057                              <1> 	;LOOPNZ	NB1
  5058 00004492 7410                <1> 	JZ	short NB2		; NOT BUSY--LETS GO
  5059                              <1> 	;DEC	BL			
  5060                              <1> 	;JNZ	short NB1		; KEEP TRYING FOR A WHILE
  5061                              <1> 
  5062 00004494 E461                <1> NB1_hi: IN	AL,SYS1			; wait for hi to lo
  5063 00004496 A810                <1> 	TEST	AL,010H			; transition on memory
  5064 00004498 75FA                <1> 	JNZ	SHORT NB1_hi		; refresh.
  5065 0000449A E461                <1> NB1_lo: IN	AL,SYS1
  5066 0000449C A810                <1> 	TEST	AL,010H
  5067 0000449E 74FA                <1> 	JZ	short NB1_lo
  5068 000044A0 E2ED                <1> 	LOOP	NB1
  5069                              <1> 	;dec	bl
  5070                              <1> 	;jnz	short NB1
  5071                              <1> 	;
  5072                              <1> ;;      cmp     byte [wait_count], 182  ; 10 seconds (182 timer ticks)
  5073                              <1> ;;	jb	short NB1
  5074                              <1> 	;
  5075                              <1> 	;MOV	[DISK_STATUS1],TIME_OUT	; REPORT TIME OUT ERROR
  5076                              <1> 	;JMP	SHORT NB3
  5077 000044A2 B080                <1> 	mov	al, TIME_OUT
  5078                              <1> NB2:	
  5079                              <1> 	;MOV	byte [DISK_STATUS1],0
  5080                              <1> ;NB3:	
  5081                              <1> 	;POP	eBX
  5082 000044A4 A2[63200100]        <1> 	mov	[DISK_STATUS1], al	;;; will be set after return
  5083                              <1> 	;CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  5084 000044A9 08C0                <1> 	or	al, al			; (zf = 0 --> timeout)
  5085 000044AB C3                  <1> 	RETn
  5086                              <1> 
  5087                              <1> ;----------------------------------------
  5088                              <1> ;	WAIT FOR DATA REQUEST		:
  5089                              <1> ;----------------------------------------
  5090                              <1> WAIT_DRQ:
  5091                              <1> 	;MOV	CX,DELAY_3
  5092                              <1> 	;MOV	DX,HF_PORT+7
  5093 000044AC 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  5094 000044B3 80C207              <1> 	add	dl, 7
  5095                              <1> 	;;MOV	bl, WAIT_HDU_DRQ_HI	; 0
  5096                              <1> 	;MOV	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
  5097                              <1> 					; (but it is written as 2000
  5098                              <1> 					; micro seconds in ATORGS.ASM file
  5099                              <1> 					; of Award Bios - 1999, D1A0622)
  5100 000044B6 B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
  5101 000044BB EC                  <1> WQ_1:	IN	AL,DX			; GET STATUS
  5102 000044BC A808                <1> 	TEST	AL,ST_DRQ		; WAIT FOR DRQ
  5103 000044BE 7516                <1> 	JNZ	short WQ_OK
  5104                              <1> 	;LOOP	WQ_1			; KEEP TRYING FOR A SHORT WHILE
  5105                              <1> WQ_hi:	
  5106 000044C0 E461                <1> 	IN	AL,SYS1			; wait for hi to lo
  5107 000044C2 A810                <1> 	TEST	AL,010H			; transition on memory
  5108 000044C4 75FA                <1> 	JNZ	SHORT WQ_hi		; refresh.
  5109 000044C6 E461                <1> WQ_lo:  IN      AL,SYS1
  5110 000044C8 A810                <1> 	TEST	AL,010H
  5111 000044CA 74FA                <1> 	JZ	SHORT WQ_lo
  5112 000044CC E2ED                <1> 	LOOP	WQ_1
  5113                              <1> 
  5114 000044CE C605[63200100]80    <1>         MOV     byte [DISK_STATUS1],TIME_OUT ; ERROR
  5115 000044D5 F9                  <1> 	STC
  5116                              <1> WQ_OK:
  5117 000044D6 C3                  <1> 	RETn
  5118                              <1> ;WQ_OK:	;CLC
  5119                              <1> ;	RETn
  5120                              <1> 
  5121                              <1> ;----------------------------------------
  5122                              <1> ;	CHECK FIXED DISK STATUS 	:
  5123                              <1> ;----------------------------------------
  5124                              <1> CHECK_STATUS:
  5125 000044D7 E813000000          <1> 	CALL	CHECK_ST		; CHECK THE STATUS BYTE
  5126 000044DC 7509                <1> 	JNZ	short CHECK_S1		; AN ERROR WAS FOUND
  5127 000044DE A801                <1> 	TEST	AL,ST_ERROR		; WERE THERE ANY OTHER ERRORS
  5128 000044E0 7405                <1> 	JZ	short CHECK_S1		; NO ERROR REPORTED
  5129 000044E2 E849000000          <1> 	CALL	CHECK_ER		; ERROR REPORTED
  5130                              <1> CHECK_S1:
  5131 000044E7 803D[63200100]00    <1> 	CMP	byte [DISK_STATUS1],0 	; SET STATUS FOR CALLER
  5132 000044EE C3                  <1> 	RETn
  5133                              <1> 
  5134                              <1> ;----------------------------------------
  5135                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
  5136                              <1> ;----------------------------------------
  5137                              <1> CHECK_ST:
  5138                              <1> 	;MOV	DX,HF_PORT+7		; GET THE STATUS
  5139 000044EF 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]
  5140 000044F6 80C207              <1> 	add	dl, 7
  5141                              <1> 	
  5142                              <1> 	; 17/02/2016
  5143                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
  5144                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
  5145 000044F9 EC                  <1> 	IN	AL,DX
  5146                              <1> 	;in	al, dx ; 100ns
  5147                              <1> 	;in	al, dx ; 100ns
  5148                              <1>  	;in	al, dx ; 100ns
  5149                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
  5149 000044FA E6EB                <2>  out 0ebh,al
  5150                              <1> 	;
  5151 000044FC A2[59200100]        <1> 	MOV	[HF_STATUS],AL
  5152 00004501 B400                <1> 	MOV	AH,0
  5153 00004503 A880                <1> 	TEST	AL,ST_BUSY		; IF STILL BUSY
  5154 00004505 751A                <1> 	JNZ	short CKST_EXIT		;  REPORT OK
  5155 00004507 B4CC                <1> 	MOV	AH,WRITE_FAULT
  5156 00004509 A820                <1> 	TEST	AL,ST_WRT_FLT		; CHECK FOR WRITE FAULT
  5157 0000450B 7514                <1> 	JNZ	short CKST_EXIT
  5158 0000450D B4AA                <1> 	MOV	AH,NOT_RDY
  5159 0000450F A840                <1> 	TEST	AL,ST_READY		; CHECK FOR NOT READY
  5160 00004511 740E                <1> 	JZ	short CKST_EXIT
  5161 00004513 B440                <1> 	MOV	AH,BAD_SEEK
  5162 00004515 A810                <1> 	TEST	AL,ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
  5163 00004517 7408                <1> 	JZ	short CKST_EXIT
  5164 00004519 B411                <1> 	MOV	AH,DATA_CORRECTED
  5165 0000451B A804                <1> 	TEST	AL,ST_CORRCTD		; CHECK FOR CORRECTED ECC
  5166 0000451D 7502                <1> 	JNZ	short CKST_EXIT
  5167 0000451F B400                <1> 	MOV	AH,0
  5168                              <1> CKST_EXIT:
  5169 00004521 8825[63200100]      <1> 	MOV	[DISK_STATUS1],AH	; SET ERROR FLAG
  5170 00004527 80FC11              <1> 	CMP	AH,DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
  5171 0000452A 7403                <1> 	JZ	short CKST_EX1
  5172 0000452C 80FC00              <1> 	CMP	AH,0
  5173                              <1> CKST_EX1:
  5174 0000452F C3                  <1> 	RETn
  5175                              <1> 
  5176                              <1> ;----------------------------------------
  5177                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
  5178                              <1> ;----------------------------------------
  5179                              <1> CHECK_ER:
  5180                              <1> 	;MOV	DX, HF_PORT+1		; GET THE ERROR REGISTER
  5181 00004530 668B15[0EED0000]    <1> 	mov	dx, [HF_PORT]		;
  5182 00004537 FEC2                <1> 	inc	dl
  5183 00004539 EC                  <1> 	IN	AL,DX
  5184 0000453A A2[5A200100]        <1> 	MOV	[HF_ERROR],AL
  5185 0000453F 53                  <1> 	PUSH	eBX ; 21/02/2015
  5186 00004540 B908000000          <1> 	MOV	eCX,8			; TEST ALL 8 BITS
  5187 00004545 D0E0                <1> CK1:	SHL	AL,1			; MOVE NEXT ERROR BIT TO CARRY
  5188 00004547 7202                <1> 	JC	short CK2		; FOUND THE ERROR
  5189 00004549 E2FA                <1> 	LOOP	CK1			; KEEP TRYING
  5190 0000454B BB[02ED0000]        <1> CK2:	MOV	eBX, ERR_TBL		; COMPUTE ADDRESS OF
  5191 00004550 01CB                <1> 	ADD	eBX,eCX			; ERROR CODE
  5192                              <1> 	;;MOV	AH,BYTE [CS:BX]		; GET ERROR CODE
  5193                              <1> 	;mov	ah, [bx]
  5194 00004552 8A23                <1> 	mov	ah, [ebx] ; 21/02/2015	
  5195 00004554 8825[63200100]      <1> CKEX:	MOV	[DISK_STATUS1],AH	; SAVE ERROR CODE
  5196 0000455A 5B                  <1> 	POP	eBX
  5197 0000455B 80FC00              <1> 	CMP	AH,0
  5198 0000455E C3                  <1> 	RETn
  5199                              <1> 
  5200                              <1> ;--------------------------------------------------------
  5201                              <1> ; CHECK_DMA						:
  5202                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
  5203                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
  5204                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
  5205                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
  5206                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
  5207                              <1> ;  -ERROR OTHERWISE					:
  5208                              <1> ;--------------------------------------------------------
  5209                              <1> CHECK_DMA:
  5210 0000455F 6650                <1> 	PUSH	AX			; SAVE REGISTERS
  5211 00004561 66B80080            <1> 	MOV	AX,8000H		; AH = MAX # SECTORS AL = MAX OFFSET
  5212 00004565 F645FE02            <1>         TEST    byte [CMD_BLOCK+6],ECC_MODE
  5213 00004569 7404                <1> 	JZ	short CKD1
  5214 0000456B 66B8047F            <1> 	MOV	AX,7F04H		; ECC IS 4 MORE BYTES
  5215 0000456F 3A65F9              <1> CKD1:	CMP	AH, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
  5216 00004572 7706                <1> 	JA	short CKDOK		; IT WILL FIT
  5217 00004574 7208                <1> 	JB	short CKDERR		; TOO MANY
  5218 00004576 38D8                <1> 	CMP	AL,BL			; CHECK OFFSET ON MAX SECTORS
  5219 00004578 7204                <1> 	JB	short CKDERR		; ERROR
  5220 0000457A F8                  <1> CKDOK:	CLC				; CLEAR CARRY
  5221 0000457B 6658                <1> 	POP	AX
  5222 0000457D C3                  <1> 	RETn				; NORMAL RETURN
  5223 0000457E F9                  <1> CKDERR: STC				; INDICATE ERROR
  5224 0000457F C605[63200100]09    <1>         MOV     byte [DISK_STATUS1],DMA_BOUNDARY
  5225 00004586 6658                <1> 	POP	AX
  5226 00004588 C3                  <1> 	RETn
  5227                              <1> 
  5228                              <1> ;----------------------------------------
  5229                              <1> ;	SET UP ES:BX-> DISK PARMS	:
  5230                              <1> ;----------------------------------------
  5231                              <1> 					
  5232                              <1> ; INPUT -> DL = 0 based drive number
  5233                              <1> ; OUTPUT -> ES:BX = disk parameter table address
  5234                              <1> 
  5235                              <1> GET_VEC:
  5236                              <1> 	;SUB	AX,AX			; GET DISK PARAMETER ADDRESS
  5237                              <1> 	;MOV	ES,AX
  5238                              <1> 	;TEST	DL,1
  5239                              <1> 	;JZ	short GV_0
  5240                              <1> ;	LES	BX,[HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
  5241                              <1> ;	JMP	SHORT GV_EXIT
  5242                              <1> ;GV_0:
  5243                              <1> ;	LES	BX,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
  5244                              <1> ;
  5245                              <1> 	;xor	bh, bh
  5246 00004589 31DB                <1> 	xor	ebx, ebx
  5247 0000458B 88D3                <1> 	mov	bl, dl
  5248                              <1> 	;;02/01/2015
  5249                              <1> 	;;shl	bl, 1			; port address offset
  5250                              <1> 	;;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
  5251                              <1> 	;;shl	bl, 1			; dpt pointer offset
  5252 0000458D C0E302              <1> 	shl	bl, 2	;;
  5253                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
  5254 00004590 81C3[68200100]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
  5255                              <1> 	;push	word [bx+2]		; dpt segment
  5256                              <1> 	;pop	es
  5257                              <1> 	;mov	bx, [bx]		; dpt offset
  5258 00004596 8B1B                <1> 	mov	ebx, [ebx]		
  5259                              <1> ;GV_EXIT:
  5260 00004598 C3                  <1> 	RETn
  5261                              <1> 
  5262                              <1> hdc1_int: ; 21/02/2015
  5263                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL  14 ) ----------------------
  5264                              <1> ;								:
  5265                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  5266                              <1> ;								:
  5267                              <1> ;----------------------------------------------------------------
  5268                              <1> 
  5269                              <1> ; 22/12/2014
  5270                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
  5271                              <1> ;	 '11/15/85'
  5272                              <1> ; AWARD BIOS 1999 (D1A0622) 
  5273                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
  5274                              <1> 
  5275                              <1> ;int_76h:
  5276                              <1> HD_INT:
  5277 00004599 6650                <1> 	PUSH	AX
  5278 0000459B 1E                  <1> 	PUSH	DS
  5279                              <1> 	;CALL	DDS
  5280                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  5281 0000459C 66B81000            <1> 	mov	ax, KDATA
  5282 000045A0 8ED8                <1> 	mov 	ds, ax
  5283                              <1> 	;
  5284                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
  5285                              <1>         ;mov     byte [CS:HF_INT_FLAG], 0FFh
  5286 000045A2 C605[5B200100]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
  5287                              <1> 	;
  5288 000045A9 6652                <1> 	push	dx
  5289 000045AB 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
  5290                              <1> 					; Clear Controller
  5291                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
  5292 000045AF EC                  <1> 	in	al, dx			;
  5293 000045B0 665A                <1> 	pop	dx
  5294                              <1> 	NEWIODELAY
  5294 000045B2 E6EB                <2>  out 0ebh,al
  5295                              <1> 	;
  5296 000045B4 B020                <1> 	MOV	AL,EOI			; NON-SPECIFIC END OF INTERRUPT
  5297 000045B6 E6A0                <1> 	OUT	INTB00,AL		; FOR CONTROLLER #2
  5298                              <1> 	;JMP	$+2			; WAIT
  5299                              <1> 	NEWIODELAY
  5299 000045B8 E6EB                <2>  out 0ebh,al
  5300 000045BA E620                <1> 	OUT	INTA00,AL		; FOR CONTROLLER #1
  5301 000045BC 1F                  <1> 	POP	DS
  5302                              <1> 	;STI				; RE-ENABLE INTERRUPTS
  5303                              <1> 	;MOV	AX,9100H		; DEVICE POST
  5304                              <1> 	;INT	15H			;  INTERRUPT
  5305                              <1> irq15_iret: ; 25/02/2015
  5306 000045BD 6658                <1> 	POP	AX
  5307 000045BF CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
  5308                              <1> 
  5309                              <1> hdc2_int: ; 21/02/2015
  5310                              <1> ;++++ HARDWARE INT 77H ++ ( IRQ LEVEL  15 ) +++++++++++++++++++++
  5311                              <1> ;								:
  5312                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  5313                              <1> ;								:
  5314                              <1> ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5315                              <1> 
  5316                              <1> ;int_77h:
  5317                              <1> HD1_INT:
  5318 000045C0 6650                <1> 	PUSH	AX
  5319                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
  5320                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  5321 000045C2 B00B                <1> 	mov	al, 0Bh  ; In-Service Register
  5322 000045C4 E6A0                <1> 	out	0A0h, al
  5323 000045C6 EB00                <1>         jmp short $+2
  5324 000045C8 EB00                <1> 	jmp short $+2
  5325 000045CA E4A0                <1> 	in	al, 0A0h
  5326 000045CC 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
  5327 000045CE 74ED                <1> 	jz	short irq15_iret ; Fake (spurious)IRQ, do not send EOI)
  5328                              <1> 	;
  5329 000045D0 1E                  <1> 	PUSH	DS
  5330                              <1> 	;CALL	DDS
  5331                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  5332 000045D1 66B81000            <1> 	mov	ax, KDATA
  5333 000045D5 8ED8                <1> 	mov 	ds, ax
  5334                              <1> 	;
  5335                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
  5336                              <1>         ;or      byte [CS:HF_INT_FLAG],0C0h 
  5337 000045D7 800D[5B200100]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
  5338                              <1> 	;
  5339 000045DE 6652                <1> 	push	dx
  5340 000045E0 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
  5341                              <1> 					; Clear Controller (Award BIOS 1999)
  5342 000045E4 EBC9                <1> 	jmp	short Clear_IRQ1415
  5343                              <1> 
  5344                              <1> 
  5345                              <1> ;%include 'diskdata.inc' ; 11/03/2015
  5346                              <1> ;%include 'diskbss.inc' ; 11/03/2015
  5347                              <1> 
  5348                              <1> 
  5349                              <1> ;////////////////////////////////////////////////////////////////////
  5350                              <1> ;; END OF DISK I/O SYTEM ///
  1914                                  %include 'memory.s'  ; 09/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - memory.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 16/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; memory.inc (18/10/2015)
    15                              <1> ; ****************************************************************************
    16                              <1> 
    17                              <1> ; MEMORY.ASM - Retro UNIX 386 v1 MEMORY MANAGEMENT FUNCTIONS (PROCEDURES)
    18                              <1> ; Retro UNIX 386 v1 Kernel (unix386.s, v0.2.0.14) - MEMORY.INC
    19                              <1> ; Last Modification: 18/10/2015
    20                              <1> 
    21                              <1> ; ///////// MEMORY MANAGEMENT FUNCTIONS (PROCEDURES) ///////////////
    22                              <1> 
    23                              <1> ;;04/11/2014 (unix386.s)	
    24                              <1> ;PDE_A_PRESENT	equ	1		; Present flag for PDE
    25                              <1> ;PDE_A_WRITE	equ 	2		; Writable (write permission) flag
    26                              <1> ;PDE_A_USER	equ	4		; User (non-system/kernel) page flag
    27                              <1> ;;
    28                              <1> ;PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
    29                              <1> ;PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
    30                              <1> ;PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
    31                              <1> ;PTE_A_ACCESS   equ	32		; Accessed flag (bit 5) ; 09/03/2015
    32                              <1> 
    33                              <1> ; 27/04/2015
    34                              <1> ; 09/03/2015
    35                              <1> PAGE_SIZE 	equ 4096		; page size in bytes
    36                              <1> PAGE_SHIFT 	equ 12			; page table shift count
    37                              <1> PAGE_D_SHIFT 	equ 22	; 12 + 10	; page directory shift count
    38                              <1> PAGE_OFF	equ 0FFFh		; 12 bit byte offset in page frame
    39                              <1> PTE_MASK 	equ 03FFh		; page table entry mask
    40                              <1> PTE_DUPLICATED  equ 200h		; duplicated page sign (AVL bit 0)
    41                              <1> PDE_A_CLEAR	equ 0F000h		; to clear PDE attribute bits
    42                              <1> PTE_A_CLEAR	equ 0F000h		; to clear PTE attribute bits
    43                              <1> LOGIC_SECT_SIZE equ 512			; logical sector size
    44                              <1> ERR_MAJOR_PF	equ 0E0h		; major error: page fault
    45                              <1> ERR_MINOR_IM	equ 1			; insufficient (out of) memory
    46                              <1> ERR_MINOR_DSK	equ 2			; disk read/write error
    47                              <1> ERR_MINOR_PV	equ 3			; protection violation
    48                              <1> SWP_DISK_READ_ERR equ 4
    49                              <1> SWP_DISK_NOT_PRESENT_ERR equ 5
    50                              <1> SWP_SECTOR_NOT_PRESENT_ERR equ 6
    51                              <1> SWP_NO_FREE_SPACE_ERR equ 7
    52                              <1> SWP_DISK_WRITE_ERR equ 8
    53                              <1> SWP_NO_PAGE_TO_SWAP_ERR equ 9
    54                              <1> PTE_A_ACCESS_BIT equ 5  ; Bit 5 (accessed flag)        
    55                              <1> SECTOR_SHIFT    equ 3   ; sector shift (to convert page block number)
    56                              <1> ; 12/07/2016
    57                              <1> PTE_SHARED	equ 400h		; AVL bit 1, direct memory access bit	
    58                              <1> 					; (Indicates that the page is not allocated
    59                              <1> 					; for the process, it is a shared or system
    60                              <1>                                         ; page, it must not be deallocated!)
    61                              <1> ;
    62                              <1> ;; Retro Unix 386 v1 - paging method/principles
    63                              <1> ;;
    64                              <1> ;; 10/10/2014
    65                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
    66                              <1> ;;
    67                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
    68                              <1> ;;	(virtual address = physical address)
    69                              <1> ;; KERNEL PAGE TABLES:
    70                              <1> ;;	Kernel page directory and all page tables are
    71                              <1> ;;	on memory as initialized, as equal to physical memory
    72                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
    73                              <1> ;;
    74                              <1> ;;	what for: User pages may be swapped out, when accessing
    75                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
    76                              <1> ;;	kernel would have to swap it in! But it is also may be
    77                              <1> ;;	in use by a user process. (In system/kernel mode
    78                              <1> ;;	kernel can access all memory pages even if they are
    79                              <1> ;;	reserved/allocated for user processes. Swap out/in would
    80                              <1> ;;	cause conflicts.) 
    81                              <1> ;;	
    82                              <1> ;;	As result of these conditions,
    83                              <1> ;;	all kernel pages must be initialized as equal to 
    84                              <1> ;;	physical layout for preventing page faults. 
    85                              <1> ;;	Also, calling "allocate page" procedure after
    86                              <1> ;;	a page fault can cause another page fault (double fault)
    87                              <1> ;;	if all kernel page tables would not be initialized.
    88                              <1> ;;
    89                              <1> ;;	[first_page] = Beginning of users space, as offset to 
    90                              <1> ;;	memory allocation table. (double word aligned)
    91                              <1> ;;
    92                              <1> ;;	[next_page] = first/next free space to be searched
    93                              <1> ;;	as offset to memory allocation table. (dw aligned)
    94                              <1> ;;
    95                              <1> ;;	[last_page] = End of memory (users space), as offset
    96                              <1> ;;	to memory allocation table. (double word aligned)
    97                              <1> ;;
    98                              <1> ;; USER PAGE TABLES:
    99                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
   100                              <1> ;;		'ready only' marked copies of the 
   101                              <1> ;;		parent process's page table entries (for
   102                              <1> ;;		same physical memory).
   103                              <1> ;;		(A page will be copied to a new page after
   104                              <1> ;;		 if it causes R/W page fault.)
   105                              <1> ;;
   106                              <1> ;;	Every user process has own (different)
   107                              <1> ;;	page directory and page tables.	
   108                              <1> ;;
   109                              <1> ;;	Code starts at virtual address 0, always.
   110                              <1> ;;	(Initial value of EIP is 0 in user mode.)
   111                              <1> ;;	(Programs can be written/developed as simple
   112                              <1> ;;	 flat memory programs.)
   113                              <1> ;;
   114                              <1> ;; MEMORY ALLOCATION STRATEGY:
   115                              <1> ;;	Memory page will be allocated by kernel only 
   116                              <1> ;;		(in kernel/system mode only).
   117                              <1> ;;	* After a
   118                              <1> ;;	  - 'not present' page fault
   119                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
   120                              <1> ;;	* For loading (opening, reading) a file or disk/drive
   121                              <1> ;;	* As responce to 'allocate additional memory blocks' 
   122                              <1> ;;	  request by running process.
   123                              <1> ;;	* While creating a process, allocating a new buffer,
   124                              <1> ;;	  new page tables etc.
   125                              <1> ;;
   126                              <1> ;;	At first,
   127                              <1> ;;	- 'allocate page' procedure will be called;
   128                              <1> ;,	   if it will return with a valid (>0) physical address
   129                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
   130                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
   131                              <1> ;;	- 'allocate page' will be called for allocating page
   132                              <1> ;;	   directory, page table and running space (data/code).
   133                              <1> ;;	- every successful 'allocate page' call will decrease
   134                              <1> ;;	  'free_pages' count (pointer).
   135                              <1> ;;	- 'out of (insufficient) memory error' will be returned
   136                              <1> ;;	  if 'free_pages' points to a ZERO.
   137                              <1> ;;	- swapping out and swapping in (if it is not a new page)
   138                              <1> ;;	  procedures will be called as responce to 'out of memory'
   139                              <1> ;;	  error except errors caused by attribute conflicts.
   140                              <1> ;;	 (swapper functions)	 
   141                              <1> ;;					
   142                              <1> ;;	At second,
   143                              <1> ;;	- page directory entry will be updated then page table
   144                              <1> ;;	  entry will be updated.		
   145                              <1> ;;
   146                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
   147                              <1> ;;	- M.A.T. has a size according to available memory as
   148                              <1> ;;	  follows:
   149                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
   150                              <1> ;;		  - a bit with value of 0 means allocated page
   151                              <1> ;;		  - a bit with value of 1 means a free page
   152                              <1> ;,	- 'free_pages' pointer holds count of free pages
   153                              <1> ;;	  depending on M.A.T.
   154                              <1> ;;		(NOTE: Free page count will not be checked
   155                              <1> ;;		again -on M.A.T.- after initialization. 
   156                              <1> ;;		Kernel will trust on initial count.)
   157                              <1> ;,	- 'free_pages' count will be decreased by allocation
   158                              <1> ;;	  and it will be increased by deallocation procedures.
   159                              <1> ;;	
   160                              <1> ;;	- Available memory will be calculated during
   161                              <1> ;;	  the kernel's initialization stage (in real mode).
   162                              <1> ;;	  Memory allocation table and kernel page tables 
   163                              <1> ;;	  will be formatted/sized as result of available
   164                              <1> ;;	  memory calculation before paging is enabled.
   165                              <1> ;;
   166                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
   167                              <1> ;;	- Memory Allocation Table size will be 128 KB.
   168                              <1> ;;	- Memory allocation for kernel page directory size 
   169                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   170                              <1> ;;	  for page tables)
   171                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
   172                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
   173                              <1> ;;	- User (available) space will be started 
   174                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
   175                              <1> ;;	- The first 640 KB is for kernel's itself plus
   176                              <1> ;;	  memory allocation table and kernel's page directory
   177                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   178                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   179                              <1> ;; 	  for buffers.
   180                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   181                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   182                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
   183                              <1> ;;
   184                              <1> ;; For 1GB Available Memory:
   185                              <1> ;;	- Memory Allocation Table size will be 32 KB.
   186                              <1> ;;	- Memory allocation for kernel page directory size 
   187                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   188                              <1> ;;	  for page tables)
   189                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
   190                              <1> ;;	  is 1 MB (256*4*1024 bytes).
   191                              <1> ;;	- User (available) space will be started 
   192                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
   193                              <1> ;;	- The first 640 KB is for kernel's itself plus
   194                              <1> ;;	  memory allocation table and kernel's page directory
   195                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   196                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   197                              <1> ;; 	  for buffers.
   198                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   199                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   200                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
   201                              <1> ;;
   202                              <1> ;;
   203                              <1> 
   204                              <1> 
   205                              <1> ;;************************************************************************************
   206                              <1> ;; 
   207                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
   208                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
   209                              <1> 
   210                              <1> ;; Main factor: "sys fork" system call 
   211                              <1> ;;	
   212                              <1> ;; 		FORK
   213                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
   214                              <1> ;;  writable pages ---->|
   215                              <1> ;;                      |----> child - duplicated PTEs, read only pages
   216                              <1> ;; 
   217                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
   218                              <1> ;; 
   219                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
   220                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
   221                              <1> ;;       -while R/W bit is 0-. 
   222                              <1> ;; 
   223                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
   224                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
   225                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
   226                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
   227                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
   228                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
   229                              <1> ;; 
   230                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
   231                              <1> ;; # Parent's read only pages are copied to new child pages. 
   232                              <1> ;;   Parent's PTE attributes are not changed.
   233                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
   234                              <1> ;;    destroy/mix previous fork result).
   235                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
   236                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
   237                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
   238                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
   239                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
   240                              <1> ;;   as Child's Page Table Entries without copying actual page.
   241                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
   242                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
   243                              <1> ;; 
   244                              <1> ;; !? WHAT FOR (duplication after duplication):
   245                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
   246                              <1> ;; program/executable code continues from specified location as child process, 
   247                              <1> ;; returns back previous code location as parent process, every child after 
   248                              <1> ;; every sys fork uses last image of code and data just prior the fork.
   249                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
   250                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
   251                              <1> ;; was copied to child's process segment (all of code and data) according to
   252                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
   253                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
   254                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
   255                              <1> ;; (complete running image of parent process) to the child process; 
   256                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
   257                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
   258                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
   259                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
   260                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
   261                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
   262                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
   263                              <1> ;; new/fresh pages will be used to load and run new executable/program.
   264                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
   265                              <1> ;; for sharing same read only pages between parent and child processes.
   266                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
   267                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
   268                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
   269                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
   270                              <1> ;; -deallocation problem-.
   271                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
   272                              <1> ;; 
   273                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   274                              <1> ;; # Page fault handler will do those:
   275                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   276                              <1> ;;   - If it is reset/clear, there is a child uses same page.
   277                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
   278                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
   279                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
   280                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
   281                              <1> ;;     read only page will be converted to writable and unique page which belongs
   282                              <1> ;;     to child process.)	
   283                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   284                              <1> ;; # Page fault handler will do those:
   285                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   286                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
   287                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
   288                              <1> ;;     address or not. 
   289                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
   290                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
   291                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
   292                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
   293                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
   294                              <1> ;; 
   295                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
   296                              <1> ;;       will be set as writable (and unique) in case of child process was using 
   297                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
   298                              <1> ;;       duplication method details, it is not possible multiple child processes
   299                              <1> ;;       were using same page with duplicated PTEs.
   300                              <1> ;; 
   301                              <1> ;;************************************************************************************   
   302                              <1> 
   303                              <1> ;; 08/10/2014
   304                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
   305                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
   306                              <1> 
   307                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
   308                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
   309                              <1> ;; (25/08/2014, Revision: 5057) file 
   310                              <1> ;; by KolibriOS Team (2004-2012)
   311                              <1> 
   312                              <1> allocate_page:
   313                              <1> 	; 01/07/2015
   314                              <1> 	; 05/05/2015
   315                              <1> 	; 30/04/2015
   316                              <1> 	; 16/10/2014
   317                              <1> 	; 08/10/2014
   318                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
   319                              <1> 	;
   320                              <1> 	; INPUT -> none
   321                              <1> 	;
   322                              <1> 	; OUTPUT ->
   323                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   324                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
   325                              <1> 	;
   326                              <1> 	;	CF = 1 and EAX = 0 
   327                              <1> 	; 		   if there is not a free page to be allocated	
   328                              <1> 	;
   329                              <1> 	; Modified Registers -> none (except EAX)
   330                              <1> 	;
   331 000045E6 A1[D01F0100]        <1> 	mov	eax, [free_pages]
   332 000045EB 21C0                <1> 	and	eax, eax
   333 000045ED 7438                <1> 	jz	short out_of_memory
   334                              <1> 	;
   335 000045EF 53                  <1> 	push	ebx
   336 000045F0 51                  <1> 	push	ecx
   337                              <1> 	;
   338 000045F1 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
   339 000045F6 89D9                <1> 	mov	ecx, ebx
   340                              <1>  				     ; NOTE: 32 (first_page) is initial
   341                              <1> 				     ; value of [next_page].
   342                              <1> 				     ; It points to the first available
   343                              <1> 				     ; page block for users (ring 3) ...	
   344                              <1> 				     ; (MAT offset 32 = 1024/32)	
   345                              <1> 				     ; (at the of the first 4 MB)		
   346 000045F8 031D[D41F0100]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
   347                              <1> 				 ; next_free_page >> 5
   348 000045FE 030D[D81F0100]      <1> 	add	ecx, [last_page] ; Free page searching ends here
   349                              <1> 				 ; (total_pages - 1) >> 5
   350                              <1> al_p_scan:
   351 00004604 39CB                <1> 	cmp	ebx, ecx
   352 00004606 770A                <1> 	ja	short al_p_notfound
   353                              <1> 	;
   354                              <1> 	; 01/07/2015
   355                              <1> 	; AMD64 Architecture Programmers Manual
   356                              <1> 	; Volume 3:
   357                              <1> 	; General-Purpose and System Instructions
   358                              <1> 	;
   359                              <1> 	; BSF - Bit Scan Forward
   360                              <1> 	;
   361                              <1> 	;   Searches the value in a register or a memory location
   362                              <1> 	;   (second operand) for the least-significant set bit. 
   363                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
   364                              <1> 	;   and stores the index of the least-significant set bit in a destination
   365                              <1> 	;   register (first operand). If the second operand contains 0, 
   366                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
   367                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
   368                              <1> 	;   of the searched value
   369                              <1> 	;
   370 00004608 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
   371                              <1> 			   ; Clear ZF if a bit is found set (1) and 
   372                              <1> 			   ; loads the destination with an index to
   373                              <1> 			   ; first set bit. (0 -> 31) 
   374                              <1> 			   ; Sets ZF to 1 if no bits are found set.
   375 0000460B 7525                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
   376                              <1> 			 ;
   377                              <1> 			 ; NOTE:  a Memory Allocation Table bit 
   378                              <1> 			 ;	  with value of 1 means 
   379                              <1> 			 ;	  the corresponding page is free 
   380                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
   381 0000460D 83C304              <1> 	add	ebx, 4
   382                              <1> 			 ; We return back for searching next page block
   383                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
   384                              <1> 			 ;	 we always will find at least 1 free page here.
   385 00004610 EBF2                <1>         jmp     short al_p_scan
   386                              <1> 	;
   387                              <1> al_p_notfound:
   388 00004612 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   389 00004618 890D[D41F0100]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
   390                              <1> 				 ; (deallocate_page procedure will change it)
   391 0000461E 31C0                <1> 	xor	eax, eax
   392 00004620 A3[D01F0100]        <1> 	mov	[free_pages], eax ; 0
   393 00004625 59                  <1> 	pop	ecx
   394 00004626 5B                  <1> 	pop	ebx
   395                              <1> 	;
   396                              <1> out_of_memory:
   397 00004627 E85B040000          <1> 	call	swap_out
   398 0000462C 7325                <1> 	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
   399                              <1> 	;
   400 0000462E 29C0                <1> 	sub 	eax, eax ; 0
   401 00004630 F9                  <1> 	stc
   402 00004631 C3                  <1> 	retn
   403                              <1> 
   404                              <1> al_p_found:
   405 00004632 89D9                <1> 	mov	ecx, ebx
   406 00004634 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   407 0000463A 890D[D41F0100]      <1> 	mov	[next_page], ecx ; Set first free page searching start
   408                              <1> 				 ; address/offset (to the next)
   409 00004640 FF0D[D01F0100]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
   410                              <1> 	;
   411 00004646 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
   412                              <1> 				 ; is copied into the Carry Flag and then cleared
   413                              <1> 				 ; in the destination.
   414                              <1> 				 ;
   415                              <1> 				 ; Reset the bit which is corresponding to the 
   416                              <1> 				 ; (just) allocated page.
   417                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
   418 00004649 C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
   419 0000464C 01C8                <1> 	add	eax, ecx	 ; = page number
   420 0000464E C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
   421                              <1> 	; EAX = physical address of memory page
   422                              <1> 	;
   423                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
   424                              <1> 	;       according to this EAX value...
   425 00004651 59                  <1> 	pop	ecx
   426 00004652 5B                  <1> 	pop	ebx
   427                              <1> al_p_ok:
   428 00004653 C3                  <1> 	retn
   429                              <1> 
   430                              <1> 
   431                              <1> make_page_dir:
   432                              <1> 	; 18/04/2015
   433                              <1> 	; 12/04/2015
   434                              <1> 	; 23/10/2014
   435                              <1> 	; 16/10/2014
   436                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   437                              <1> 	;
   438                              <1> 	; INPUT ->
   439                              <1> 	;	none
   440                              <1> 	; OUTPUT ->
   441                              <1> 	;	(EAX = 0)
   442                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   443                              <1> 	;	cf = 0 ->
   444                              <1> 	;	u.pgdir = page directory (physical) address of the current
   445                              <1> 	;		  process/user.
   446                              <1> 	;
   447                              <1> 	; Modified Registers -> EAX
   448                              <1> 	;
   449 00004654 E88DFFFFFF          <1> 	call	allocate_page
   450 00004659 7216                <1> 	jc	short mkpd_error
   451                              <1> 	;
   452 0000465B A3[01310100]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
   453                              <1> 				  ; (Physical address)
   454                              <1> clear_page:
   455                              <1> 	; 18/04/2015
   456                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   457                              <1> 	;
   458                              <1> 	; INPUT ->
   459                              <1> 	;	EAX = physical address of the page
   460                              <1> 	; OUTPUT ->
   461                              <1> 	;	all bytes of the page will be cleared
   462                              <1> 	;
   463                              <1> 	; Modified Registers -> none
   464                              <1> 	;
   465 00004660 57                  <1> 	push	edi
   466 00004661 51                  <1> 	push	ecx
   467 00004662 50                  <1> 	push	eax
   468 00004663 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
   469 00004668 89C7                <1> 	mov	edi, eax
   470 0000466A 31C0                <1> 	xor	eax, eax
   471 0000466C F3AB                <1> 	rep	stosd
   472 0000466E 58                  <1> 	pop	eax
   473 0000466F 59                  <1> 	pop	ecx
   474 00004670 5F                  <1> 	pop	edi
   475                              <1> mkpd_error:
   476                              <1> mkpt_error:
   477 00004671 C3                  <1> 	retn
   478                              <1> 
   479                              <1> make_page_table:
   480                              <1> 	; 23/06/2015
   481                              <1> 	; 18/04/2015
   482                              <1> 	; 12/04/2015
   483                              <1> 	; 16/10/2014
   484                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   485                              <1> 	;
   486                              <1> 	; INPUT ->
   487                              <1> 	;	EBX = virtual (linear) address
   488                              <1> 	;	ECX = page table attributes (lower 12 bits)
   489                              <1> 	;	      (higher 20 bits must be ZERO)
   490                              <1> 	;	      (bit 0 must be 1)	 
   491                              <1> 	;	u.pgdir = page directory (physical) address
   492                              <1> 	; OUTPUT ->
   493                              <1> 	;	EDX = Page directory entry address
   494                              <1> 	;	EAX = Page table address
   495                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   496                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
   497                              <1> 	;
   498                              <1> 	; Modified Registers -> EAX, EDX
   499                              <1> 	;
   500 00004672 E86FFFFFFF          <1> 	call	allocate_page
   501 00004677 72F8                <1> 	jc	short mkpt_error
   502 00004679 E811000000          <1> 	call	set_pde	
   503 0000467E EBE0                <1> 	jmp	short clear_page
   504                              <1> 
   505                              <1> make_page:
   506                              <1> 	; 24/07/2015
   507                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
   508                              <1> 	;
   509                              <1> 	; INPUT ->
   510                              <1> 	;	EBX = virtual (linear) address
   511                              <1> 	;	ECX = page attributes (lower 12 bits)
   512                              <1> 	;	      (higher 20 bits must be ZERO)
   513                              <1> 	;	      (bit 0 must be 1)	 
   514                              <1> 	;	u.pgdir = page directory (physical) address
   515                              <1> 	; OUTPUT ->
   516                              <1> 	;	EBX = Virtual address
   517                              <1> 	;	(EDX = PTE value)
   518                              <1> 	;	EAX = Physical address
   519                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   520                              <1> 	;
   521                              <1> 	; Modified Registers -> EAX, EDX
   522                              <1> 	;
   523 00004680 E861FFFFFF          <1> 	call	allocate_page
   524 00004685 7207                <1> 	jc	short mkp_err
   525 00004687 E821000000          <1> 	call	set_pte	
   526 0000468C 73D2                <1> 	jnc	short clear_page ; 18/04/2015
   527                              <1> mkp_err:
   528 0000468E C3                  <1> 	retn
   529                              <1> 
   530                              <1> 
   531                              <1> set_pde:	; Set page directory entry (PDE)
   532                              <1> 	; 20/07/2015
   533                              <1> 	; 18/04/2015
   534                              <1> 	; 12/04/2015
   535                              <1> 	; 23/10/2014
   536                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   537                              <1> 	;
   538                              <1> 	; INPUT ->
   539                              <1> 	;	EAX = physical address
   540                              <1> 	;	      (use present value if EAX = 0)
   541                              <1> 	;	EBX = virtual (linear) address
   542                              <1> 	;	ECX = page table attributes (lower 12 bits)
   543                              <1> 	;	      (higher 20 bits must be ZERO)
   544                              <1> 	;	      (bit 0 must be 1)	 
   545                              <1> 	;	u.pgdir = page directory (physical) address
   546                              <1> 	; OUTPUT ->
   547                              <1> 	;	EDX = PDE address
   548                              <1> 	;	EAX = page table address (physical)
   549                              <1> 	;	;(CF=1 -> Invalid page address)
   550                              <1> 	;
   551                              <1> 	; Modified Registers -> EDX
   552                              <1> 	;
   553 0000468F 89DA                <1> 	mov	edx, ebx
   554 00004691 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
   555 00004694 C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
   556 00004697 0315[01310100]      <1> 	add	edx, [u.pgdir]
   557                              <1> 	;
   558 0000469D 21C0                <1> 	and	eax, eax
   559 0000469F 7506                <1> 	jnz	short spde_1
   560                              <1> 	;
   561 000046A1 8B02                <1> 	mov	eax, [edx]  ; old PDE value
   562                              <1> 	;test	al, 1
   563                              <1> 	;jz	short spde_2
   564 000046A3 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
   565                              <1> spde_1:
   566                              <1> 	;and	cx, 0FFFh
   567 000046A7 8902                <1> 	mov	[edx], eax
   568 000046A9 66090A              <1> 	or	[edx], cx
   569 000046AC C3                  <1> 	retn
   570                              <1> ;spde_2: ; error
   571                              <1> ;	stc
   572                              <1> ;	retn
   573                              <1> 
   574                              <1> set_pte:	; Set page table entry (PTE)
   575                              <1> 	; 24/07/2015
   576                              <1> 	; 20/07/2015
   577                              <1> 	; 23/06/2015
   578                              <1> 	; 18/04/2015
   579                              <1> 	; 12/04/2015
   580                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   581                              <1> 	;
   582                              <1> 	; INPUT ->
   583                              <1> 	;	EAX = physical page address
   584                              <1> 	;	      (use present value if EAX = 0)
   585                              <1> 	;	EBX = virtual (linear) address
   586                              <1> 	;	ECX = page attributes (lower 12 bits)
   587                              <1> 	;	      (higher 20 bits must be ZERO)
   588                              <1> 	;	      (bit 0 must be 1)	 
   589                              <1> 	;	u.pgdir = page directory (physical) address
   590                              <1> 	; OUTPUT ->
   591                              <1> 	;	EAX = physical page address
   592                              <1> 	;	(EDX = PTE value)
   593                              <1> 	;	EBX = virtual address
   594                              <1> 	;
   595                              <1> 	;	CF = 1 -> error
   596                              <1> 	;
   597                              <1> 	; Modified Registers -> EAX, EDX
   598                              <1> 	;
   599 000046AD 50                  <1> 	push	eax
   600 000046AE A1[01310100]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
   601 000046B3 E837000000          <1> 	call 	get_pde
   602                              <1> 		; EDX = PDE address
   603                              <1> 		; EAX = PDE value
   604 000046B8 5A                  <1> 	pop	edx ; physical page address
   605 000046B9 722A                <1> 	jc	short spte_err ; PDE not present
   606                              <1> 	;
   607 000046BB 53                  <1> 	push	ebx ; 24/07/2015
   608 000046BC 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   609                              <1> 			    ; EDX = PT address (physical)	
   610 000046C0 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
   611 000046C3 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
   612                              <1> 			 ; clear higher 10 bits (PD bits)
   613 000046C9 C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
   614 000046CC 01C3                <1> 	add	ebx, eax
   615                              <1> 	;
   616 000046CE 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
   617 000046D0 A801                <1> 	test	al, 1
   618 000046D2 740C                <1> 	jz	short spte_0
   619 000046D4 09D2                <1> 	or	edx, edx
   620 000046D6 750F                <1> 	jnz	short spte_1
   621 000046D8 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
   622 000046DC 89C2                <1> 	mov	edx, eax
   623 000046DE EB09                <1> 	jmp	short spte_2	
   624                              <1> spte_0:
   625                              <1> 	; If this PTE contains a swap (disk) address,
   626                              <1> 	; it can be updated by using 'swap_in' procedure
   627                              <1> 	; only!
   628 000046E0 21C0                <1> 	and	eax, eax
   629 000046E2 7403                <1> 	jz	short spte_1
   630                              <1> 	; 24/07/2015
   631                              <1> 	; swapped page ! (on disk)
   632 000046E4 5B                  <1> 	pop	ebx
   633                              <1> spte_err:
   634 000046E5 F9                  <1> 	stc
   635 000046E6 C3                  <1> 	retn
   636                              <1> spte_1: 
   637 000046E7 89D0                <1> 	mov	eax, edx
   638                              <1> spte_2:
   639 000046E9 09CA                <1> 	or	edx, ecx
   640                              <1> 	; 23/06/2015
   641 000046EB 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
   642                              <1> 	; 24/07/2015
   643 000046ED 5B                  <1> 	pop	ebx
   644 000046EE C3                  <1> 	retn
   645                              <1> 
   646                              <1> get_pde:	; Get present value of the relevant PDE
   647                              <1> 	; 20/07/2015
   648                              <1> 	; 18/04/2015
   649                              <1> 	; 12/04/2015
   650                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   651                              <1> 	;
   652                              <1> 	; INPUT ->
   653                              <1> 	;	EBX = virtual (linear) address
   654                              <1> 	;	EAX = page directory (physical) address
   655                              <1> 	; OUTPUT ->
   656                              <1> 	;	EDX = Page directory entry address
   657                              <1> 	;	EAX = Page directory entry value
   658                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   659                              <1> 	; Modified Registers -> EDX, EAX
   660                              <1> 	;
   661 000046EF 89DA                <1> 	mov	edx, ebx
   662 000046F1 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
   663 000046F4 C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
   664 000046F7 01C2                <1> 	add	edx, eax ; page directory address (physical)
   665 000046F9 8B02                <1> 	mov	eax, [edx]
   666 000046FB A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
   667 000046FD 751F                <1> 	jnz	short gpte_retn
   668 000046FF F9                  <1> 	stc
   669                              <1> gpde_retn:	
   670 00004700 C3                  <1> 	retn
   671                              <1> 
   672                              <1> get_pte:
   673                              <1> 		; Get present value of the relevant PTE
   674                              <1> 	; 29/07/2015
   675                              <1> 	; 20/07/2015
   676                              <1> 	; 18/04/2015
   677                              <1> 	; 12/04/2015
   678                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   679                              <1> 	;
   680                              <1> 	; INPUT ->
   681                              <1> 	;	EBX = virtual (linear) address
   682                              <1> 	;	EAX = page directory (physical) address
   683                              <1> 	; OUTPUT ->
   684                              <1> 	;	EDX = Page table entry address (if CF=0)
   685                              <1> 	;	      Page directory entry address (if CF=1)
   686                              <1> 	;            (Bit 0 value is 0 if PT is not present)
   687                              <1> 	;	EAX = Page table entry value (page address)
   688                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   689                              <1> 	; Modified Registers -> EAX, EDX
   690                              <1> 	;
   691 00004701 E8E9FFFFFF          <1> 	call 	get_pde
   692 00004706 72F8                <1> 	jc	short gpde_retn	; page table is not present
   693                              <1> 	;jnc	short gpte_1
   694                              <1> 	;retn
   695                              <1> ;gpte_1:
   696 00004708 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   697 0000470C 89DA                <1> 	mov	edx, ebx
   698 0000470E C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
   699 00004711 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
   700                              <1> 			 ; clear higher 10 bits (PD bits)
   701 00004717 C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
   702 0000471A 01C2                <1> 	add	edx, eax
   703 0000471C 8B02                <1> 	mov	eax, [edx]
   704                              <1> gpte_retn:
   705 0000471E C3                  <1> 	retn
   706                              <1> 
   707                              <1> deallocate_page_dir:
   708                              <1> 	; 15/09/2015
   709                              <1> 	; 05/08/2015
   710                              <1> 	; 30/04/2015
   711                              <1> 	; 28/04/2015
   712                              <1> 	; 17/10/2014
   713                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   714                              <1> 	;
   715                              <1> 	; INPUT ->
   716                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
   717                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   718                              <1> 	; OUTPUT ->
   719                              <1> 	;	All of page tables in the page directory
   720                              <1> 	;	and page dir's itself will be deallocated
   721                              <1> 	;	except 'read only' duplicated pages (will be converted
   722                              <1> 	;	to writable pages).
   723                              <1> 	;
   724                              <1> 	; Modified Registers -> EAX
   725                              <1> 	;
   726                              <1> 	;
   727 0000471F 56                  <1> 	push	esi
   728 00004720 51                  <1> 	push	ecx
   729 00004721 50                  <1> 	push	eax
   730 00004722 89C6                <1> 	mov	esi, eax 
   731 00004724 31C9                <1> 	xor	ecx, ecx
   732                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
   733                              <1> 	; it must not be deallocated
   734 00004726 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
   735                              <1> dapd_0:
   736 00004728 AD                  <1> 	lodsd
   737 00004729 A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
   738 0000472B 7409                <1> 	jz	short dapd_1	
   739 0000472D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   740 00004731 E812000000          <1> 	call	deallocate_page_table			
   741                              <1> dapd_1:
   742 00004736 41                  <1> 	inc	ecx ; page directory entry index
   743 00004737 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
   744 0000473D 72E9                <1> 	jb	short dapd_0
   745                              <1> dapd_2:
   746 0000473F 58                  <1> 	pop	eax
   747 00004740 E87F000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
   748 00004745 59                  <1> 	pop	ecx
   749 00004746 5E                  <1> 	pop	esi
   750 00004747 C3                  <1> 	retn
   751                              <1> 
   752                              <1> deallocate_page_table:
   753                              <1> 	; 12/07/2016
   754                              <1> 	; 19/09/2015
   755                              <1> 	; 15/09/2015
   756                              <1> 	; 05/08/2015
   757                              <1> 	; 30/04/2015
   758                              <1> 	; 28/04/2015
   759                              <1> 	; 24/10/2014
   760                              <1> 	; 23/10/2014
   761                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   762                              <1> 	;
   763                              <1> 	; INPUT ->
   764                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
   765                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   766                              <1> 	;	(ECX = page directory entry index)
   767                              <1> 	; OUTPUT ->
   768                              <1> 	;	All of pages in the page table and page table's itself
   769                              <1> 	;	will be deallocated except 'read only' duplicated pages
   770                              <1> 	;	(will be converted to writable pages).
   771                              <1> 	;
   772                              <1> 	; Modified Registers -> EAX
   773                              <1> 	;
   774 00004748 56                  <1> 	push	esi
   775 00004749 57                  <1> 	push	edi
   776 0000474A 52                  <1> 	push	edx
   777 0000474B 50                  <1> 	push	eax ; *
   778 0000474C 89C6                <1> 	mov	esi, eax 
   779 0000474E 31FF                <1> 	xor	edi, edi ; 0
   780                              <1> dapt_0:
   781 00004750 AD                  <1> 	lodsd
   782 00004751 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
   783 00004753 7441                <1> 	jz	short dapt_1
   784                              <1> 	;
   785 00004755 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
   786                              <1> 				  ; (must be 1)
   787 00004757 754C                <1> 	jnz	short dapt_3
   788                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
   789 00004759 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
   790                              <1> 				   ; as child's page ?
   791 0000475D 7451                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
   792                              <1> 	; check the parent's PTE value is read only & same page or not.. 
   793                              <1> 	; ECX = page directory entry index (0-1023)
   794 0000475F 53                  <1> 	push	ebx
   795 00004760 51                  <1> 	push	ecx
   796 00004761 66C1E102            <1> 	shl	cx, 2 ; *4 
   797 00004765 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
   798 00004767 8B0B                <1> 	mov	ecx, [ebx]
   799 00004769 F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
   800 0000476C 7435                <1> 	jz	short dapt_2	; parent process does not use this page
   801 0000476E 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
   802                              <1> 	; EDI = page table entry index (0-1023)
   803 00004773 89FA                <1> 	mov	edx, edi 
   804 00004775 66C1E202            <1> 	shl	dx, 2 ; *4 
   805 00004779 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
   806 0000477B 8B1A                <1> 	mov	ebx, [edx]
   807 0000477D F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
   808 00004780 7421                <1> 	jz	short dapt_2	; parent process does not use this page
   809 00004782 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
   810 00004786 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
   811 0000478B 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
   812 0000478D 7514                <1> 	jne	short dapt_2	; not same page
   813                              <1> 				; deallocate the child's page
   814 0000478F 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
   815 00004792 59                  <1> 	pop	ecx
   816 00004793 5B                  <1> 	pop	ebx
   817 00004794 EB1A                <1> 	jmp	short dapt_4
   818                              <1> dapt_1:
   819 00004796 09C0                <1> 	or	eax, eax	; swapped page ?
   820 00004798 741D                <1> 	jz	short dapt_5	; no
   821                              <1> 				; yes
   822 0000479A D1E8                <1> 	shr	eax, 1
   823 0000479C E8CD040000          <1> 	call	unlink_swap_block ; Deallocate swapped page block
   824                              <1> 				  ; on the swap disk (or in file)
   825 000047A1 EB14                <1> 	jmp	short dapt_5
   826                              <1> dapt_2:
   827 000047A3 59                  <1> 	pop	ecx
   828 000047A4 5B                  <1> 	pop	ebx
   829                              <1> dapt_3:	
   830                              <1> 	; 12/07/2016
   831 000047A5 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
   832 000047A9 7505                <1> 	jnz	short dapt_4   ; AVL bit 1 = 1, do not deallocate this page!
   833                              <1> 	;
   834                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   835 000047AB E814000000          <1> 	call	deallocate_page ; set the mem allocation bit of this page
   836                              <1> dapt_4:
   837 000047B0 C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
   838                              <1> dapt_5:
   839 000047B7 47                  <1> 	inc	edi ; page table entry index
   840 000047B8 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
   841 000047BE 7290                <1> 	jb	short dapt_0
   842                              <1> 	;
   843 000047C0 58                  <1> 	pop	eax ; *
   844 000047C1 5A                  <1> 	pop	edx
   845 000047C2 5F                  <1> 	pop	edi	
   846 000047C3 5E                  <1> 	pop	esi
   847                              <1> 	;
   848                              <1> 	;call	deallocate_page	; deallocate the page table's itself
   849                              <1> 	;retn
   850                              <1> 
   851                              <1> deallocate_page:
   852                              <1> 	; 15/09/2015
   853                              <1> 	; 28/04/2015
   854                              <1> 	; 10/03/2015
   855                              <1> 	; 17/10/2014
   856                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   857                              <1> 	;
   858                              <1> 	; INPUT -> 
   859                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   860                              <1> 	; OUTPUT ->
   861                              <1> 	;	[free_pages] is increased
   862                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
   863                              <1> 	;	CF = 1 if the page is already deallocated
   864                              <1> 	; 	       (or not allocated) before.  
   865                              <1> 	;
   866                              <1> 	; Modified Registers -> EAX
   867                              <1> 	;
   868 000047C4 53                  <1> 	push	ebx
   869 000047C5 52                  <1> 	push	edx
   870                              <1> 	;
   871 000047C6 C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
   872                              <1> 				     ; 12 bits right
   873                              <1> 				     ; to get page number
   874 000047C9 89C2                <1> 	mov	edx, eax
   875                              <1> 	; 15/09/2015
   876 000047CB C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
   877                              <1> 				     ; (1 allocation bit = 1 page)
   878                              <1> 				     ; (1 allocation bytes = 8 pages)
   879 000047CE 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
   880                              <1> 				     ; (to get 32 bit position)			
   881                              <1> 	;
   882 000047D1 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
   883 000047D6 01D3                <1> 	add	ebx, edx
   884 000047D8 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
   885                              <1> 				     ; (allocation bit position)	 
   886 000047DB 3B15[D41F0100]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
   887                              <1> 				     ; than the address in 'next_page' ?
   888                              <1> 				     ; (next/first free page value)		
   889 000047E1 7306                <1> 	jnb	short dap_1	     ; no	
   890 000047E3 8915[D41F0100]      <1> 	mov	[next_page], edx     ; yes
   891                              <1> dap_1:
   892 000047E9 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
   893                              <1> 				     ; set relevant bit to 1.
   894                              <1> 				     ; set CF to the previous bit value	
   895                              <1> 	;cmc			     ; complement carry flag	
   896                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
   897                              <1> 				     ; if the page is already deallocated
   898                              <1> 				     ; before.	
   899 000047EC FF05[D01F0100]      <1>         inc     dword [free_pages]
   900                              <1> dap_2:
   901 000047F2 5A                  <1> 	pop	edx
   902 000047F3 5B                  <1> 	pop	ebx
   903 000047F4 C3                  <1> 	retn
   904                              <1> 
   905                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   906                              <1> ;;                                                              ;;
   907                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
   908                              <1> ;; Distributed under terms of the GNU General Public License    ;;
   909                              <1> ;;                                                              ;;
   910                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   911                              <1> 
   912                              <1> ;;$Revision: 5057 $
   913                              <1> 
   914                              <1> 
   915                              <1> ;;align 4
   916                              <1> ;;proc alloc_page
   917                              <1> 
   918                              <1> ;;        pushfd
   919                              <1> ;;        cli
   920                              <1> ;;        push    ebx
   921                              <1> ;;;//-
   922                              <1> ;;        cmp     [pg_data.pages_free], 1
   923                              <1> ;;        jle     .out_of_memory
   924                              <1> ;;;//-
   925                              <1> ;;
   926                              <1> ;;        mov     ebx, [page_start]
   927                              <1> ;;        mov     ecx, [page_end]
   928                              <1> ;;.l1:
   929                              <1> ;;        bsf     eax, [ebx];
   930                              <1> ;;        jnz     .found
   931                              <1> ;;        add     ebx, 4
   932                              <1> ;;        cmp     ebx, ecx
   933                              <1> ;;        jb      .l1
   934                              <1> ;;        pop     ebx
   935                              <1> ;;        popfd
   936                              <1> ;;        xor     eax, eax
   937                              <1> ;;        ret
   938                              <1> ;;.found:
   939                              <1> ;;;//-
   940                              <1> ;;        dec     [pg_data.pages_free]
   941                              <1> ;;        jz      .out_of_memory
   942                              <1> ;;;//-
   943                              <1> ;;        btr     [ebx], eax
   944                              <1> ;;        mov     [page_start], ebx
   945                              <1> ;;        sub     ebx, sys_pgmap
   946                              <1> ;;        lea     eax, [eax+ebx*8]
   947                              <1> ;;        shl     eax, 12
   948                              <1> ;;;//-       dec [pg_data.pages_free]
   949                              <1> ;;        pop     ebx
   950                              <1> ;;        popfd
   951                              <1> ;;        ret
   952                              <1> ;;;//-
   953                              <1> ;;.out_of_memory:
   954                              <1> ;;        mov     [pg_data.pages_free], 1
   955                              <1> ;;        xor     eax, eax
   956                              <1> ;;        pop     ebx
   957                              <1> ;;        popfd
   958                              <1> ;;        ret
   959                              <1> ;;;//-
   960                              <1> ;;endp
   961                              <1> 
   962                              <1> duplicate_page_dir:
   963                              <1> 	; 21/09/2015
   964                              <1> 	; 31/08/2015
   965                              <1> 	; 20/07/2015
   966                              <1> 	; 28/04/2015
   967                              <1> 	; 27/04/2015
   968                              <1> 	; 18/04/2015
   969                              <1> 	; 12/04/2015
   970                              <1> 	; 18/10/2014
   971                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
   972                              <1> 	;
   973                              <1> 	; INPUT -> 
   974                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
   975                              <1> 	;		    page directory.
   976                              <1> 	; OUTPUT ->
   977                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
   978                              <1> 	;	       page directory.
   979                              <1> 	;	(New page directory with new page table entries.)
   980                              <1> 	;	(New page tables with read only copies of the parent's
   981                              <1> 	;	pages.)
   982                              <1> 	;	EAX = 0 -> Error (CF = 1)
   983                              <1> 	;
   984                              <1> 	; Modified Registers -> none (except EAX)
   985                              <1> 	;
   986 000047F5 E8ECFDFFFF          <1> 	call	allocate_page
   987 000047FA 723E                <1> 	jc	short dpd_err
   988                              <1> 	;
   989 000047FC 55                  <1> 	push	ebp ; 20/07/2015
   990 000047FD 56                  <1> 	push	esi
   991 000047FE 57                  <1> 	push	edi
   992 000047FF 53                  <1> 	push	ebx
   993 00004800 51                  <1> 	push	ecx
   994 00004801 8B35[01310100]      <1> 	mov	esi, [u.pgdir]
   995 00004807 89C7                <1> 	mov	edi, eax
   996 00004809 50                  <1> 	push	eax ; save child's page directory address
   997                              <1> 	; 31/08/2015
   998                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
   999                              <1> 	; (use same system space for all user page tables) 
  1000 0000480A A5                  <1> 	movsd
  1001 0000480B BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  1002 00004810 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  1003                              <1> dpd_0:	
  1004 00004815 AD                  <1> 	lodsd
  1005                              <1> 	;or	eax, eax
  1006                              <1>         ;jnz     short dpd_1
  1007 00004816 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  1008 00004818 7508                <1> 	jnz	short dpd_1
  1009                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
  1010 0000481A 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  1011 00004820 EB0F                <1> 	jmp	short dpd_2
  1012                              <1> dpd_1:	
  1013 00004822 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  1014 00004826 89C3                <1> 	mov	ebx, eax
  1015                              <1> 	; EBX = Parent's page table address
  1016 00004828 E81F000000          <1> 	call	duplicate_page_table
  1017 0000482D 720C                <1> 	jc	short dpd_p_err
  1018                              <1> 	; EAX = Child's page table address
  1019 0000482F 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  1020                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  1021                              <1> 			 ; (present, writable, user)
  1022                              <1> dpd_2:
  1023 00004831 AB                  <1> 	stosd
  1024 00004832 E2E1                <1> 	loop	dpd_0
  1025                              <1> 	;
  1026 00004834 58                  <1> 	pop	eax  ; restore child's page directory address
  1027                              <1> dpd_3:
  1028 00004835 59                  <1> 	pop	ecx
  1029 00004836 5B                  <1> 	pop	ebx
  1030 00004837 5F                  <1> 	pop	edi
  1031 00004838 5E                  <1> 	pop	esi
  1032 00004839 5D                  <1> 	pop	ebp ; 20/07/2015
  1033                              <1> dpd_err:
  1034 0000483A C3                  <1> 	retn
  1035                              <1> dpd_p_err:
  1036                              <1> 	; release the allocated pages missing (recover free space)
  1037 0000483B 58                  <1> 	pop	eax  ; the new page directory address (physical)
  1038 0000483C 8B1D[01310100]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  1039 00004842 E8D8FEFFFF          <1> 	call 	deallocate_page_dir
  1040 00004847 29C0                <1> 	sub	eax, eax ; 0
  1041 00004849 F9                  <1> 	stc
  1042 0000484A EBE9                <1> 	jmp	short dpd_3	
  1043                              <1> 
  1044                              <1> duplicate_page_table:
  1045                              <1> 	; 21/09/2015
  1046                              <1> 	; 20/07/2015
  1047                              <1> 	; 05/05/2015
  1048                              <1> 	; 28/04/2015
  1049                              <1> 	; 27/04/2015
  1050                              <1> 	; 18/04/2015
  1051                              <1> 	; 18/10/2014
  1052                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
  1053                              <1> 	;
  1054                              <1> 	; INPUT -> 
  1055                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
  1056                              <1> 	;	EBP = page table entry index (from 'duplicate_page_dir')
  1057                              <1> 	; OUTPUT ->
  1058                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  1059                              <1> 	;	      (with 'read only' attribute of page table entries)
  1060                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
  1061                              <1> 	;	CF = 1 -> error 
  1062                              <1> 	;
  1063                              <1> 	; Modified Registers -> EBP (except EAX)
  1064                              <1> 	;
  1065 0000484C E895FDFFFF          <1> 	call	allocate_page
  1066 00004851 726A                <1> 	jc	short dpt_err
  1067                              <1> 	;
  1068 00004853 50                  <1> 	push	eax ; *
  1069 00004854 56                  <1> 	push	esi
  1070 00004855 57                  <1> 	push	edi
  1071 00004856 52                  <1> 	push	edx
  1072 00004857 51                  <1> 	push	ecx
  1073                              <1> 	;
  1074 00004858 89DE                <1> 	mov	esi, ebx
  1075 0000485A 89C7                <1> 	mov	edi, eax
  1076 0000485C 89C2                <1> 	mov	edx, eax
  1077 0000485E 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  1078                              <1> dpt_0:
  1079 00004864 AD                  <1> 	lodsd
  1080 00004865 21C0                <1> 	and	eax, eax
  1081 00004867 7444                <1> 	jz	short dpt_3
  1082 00004869 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
  1083 0000486B 7507                <1> 	jnz	short dpt_1
  1084                              <1> 	; 20/07/2015
  1085                              <1> 	; ebp = virtual (linear) address of the memory page
  1086 0000486D E806050000          <1> 	call	reload_page ; 28/04/2015
  1087 00004872 7244                <1> 	jc	short dpt_p_err
  1088                              <1> dpt_1:
  1089                              <1> 	; 21/09/2015
  1090 00004874 89C1                <1> 	mov	ecx, eax
  1091 00004876 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1092 0000487A F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
  1093 0000487D 7525                <1> 	jnz	short dpt_2
  1094                              <1> 	; Read only (parent) page
  1095                              <1> 	; 	- there is a third process which uses this page -
  1096                              <1> 	; Allocate a new page for the child process
  1097 0000487F E862FDFFFF          <1> 	call	allocate_page
  1098 00004884 7232                <1> 	jc	short dpt_p_err
  1099 00004886 57                  <1> 	push	edi
  1100 00004887 56                  <1> 	push	esi
  1101 00004888 89CE                <1> 	mov	esi, ecx
  1102 0000488A 89C7                <1> 	mov	edi, eax
  1103 0000488C B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  1104 00004891 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  1105 00004893 5E                  <1> 	pop	esi
  1106 00004894 5F                  <1> 	pop	edi
  1107                              <1> 	; 
  1108 00004895 53                  <1> 	push	ebx
  1109 00004896 50                  <1> 	push	eax
  1110                              <1> 	; 20/07/2015
  1111 00004897 89EB                <1> 	mov	ebx, ebp
  1112                              <1> 	; ebx = virtual address of the memory page
  1113 00004899 E88A030000          <1> 	call	add_to_swap_queue
  1114 0000489E 58                  <1> 	pop	eax
  1115 0000489F 5B                  <1> 	pop	ebx
  1116                              <1> 	; 21/09/2015
  1117 000048A0 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  1118                              <1> 		; user + writable + present page
  1119 000048A2 EB09                <1> 	jmp	short dpt_3
  1120                              <1> dpt_2:
  1121                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  1122 000048A4 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
  1123                              <1> 		    ; (read only page!)
  1124 000048A6 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
  1125 000048A9 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
  1126                              <1> dpt_3:
  1127 000048AD AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  1128                              <1> 	;
  1129 000048AE 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  1130                              <1> 	;
  1131 000048B4 39D7                <1> 	cmp	edi, edx
  1132 000048B6 72AC                <1> 	jb	short dpt_0
  1133                              <1> dpt_p_err:
  1134 000048B8 59                  <1> 	pop	ecx
  1135 000048B9 5A                  <1> 	pop	edx
  1136 000048BA 5F                  <1> 	pop	edi
  1137 000048BB 5E                  <1> 	pop	esi
  1138 000048BC 58                  <1> 	pop	eax ; *
  1139                              <1> dpt_err:
  1140 000048BD C3                  <1> 	retn
  1141                              <1> 
  1142                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
  1143                              <1> 	; 21/09/2015
  1144                              <1> 	; 19/09/2015
  1145                              <1> 	; 17/09/2015
  1146                              <1> 	; 28/08/2015
  1147                              <1> 	; 20/07/2015
  1148                              <1> 	; 28/06/2015
  1149                              <1> 	; 03/05/2015
  1150                              <1> 	; 30/04/2015
  1151                              <1> 	; 18/04/2015
  1152                              <1> 	; 12/04/2015
  1153                              <1> 	; 30/10/2014
  1154                              <1> 	; 11/09/2014
  1155                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
  1156                              <1> 	;
  1157                              <1> 	; Note: This is not an interrupt/exception handler.
  1158                              <1> 	;	This is a 'page fault remedy' subroutine 
  1159                              <1> 	;	which will be called by standard/uniform
  1160                              <1> 	;	exception handler.
  1161                              <1> 	;
  1162                              <1> 	; INPUT -> 
  1163                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
  1164                              <1> 	;
  1165                              <1> 	;	cr2 = the virtual (linear) address 
  1166                              <1> 	;	      which has caused to page fault (19/09/2015)
  1167                              <1> 	;
  1168                              <1> 	; OUTPUT ->
  1169                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1170                              <1> 	;	EAX = 0 -> no error
  1171                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
  1172                              <1> 	;
  1173                              <1> 	; Modified Registers -> none (except EAX)
  1174                              <1> 	;	
  1175                              <1>         ;
  1176                              <1>         ; ERROR CODE:
  1177                              <1> 	;	 31  .....	4   3	2   1	0
  1178                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1179                              <1> 	;	|   Reserved  | I | R | U | W | P |
  1180                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1181                              <1> 	;
  1182                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
  1183                              <1>     	;		a page-protection violation. When not set,
  1184                              <1> 	;		it was caused by a non-present page.
  1185                              <1> 	; W : WRITE   -	When set, the page fault was caused by
  1186                              <1> 	;		a page write. When not set, it was caused
  1187                              <1> 	;		by a page read.
  1188                              <1> 	; U : USER    -	When set, the page fault was caused 
  1189                              <1> 	;		while CPL = 3. 
  1190                              <1> 	;		This does not necessarily mean that
  1191                              <1> 	;		the page fault was a privilege violation.
  1192                              <1> 	; R : RESERVD -	When set, the page fault was caused by
  1193                              <1> 	;     WRITE	reading a 1 in a reserved field.
  1194                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
  1195                              <1> 	;     FETCH	an instruction fetch
  1196                              <1> 	;
  1197                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
  1198                              <1> 	;  31               22                  12 11                    0
  1199                              <1> 	; +-------------------+-------------------+-----------------------+
  1200                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
  1201                              <1>        	; +-------------------+-------------------+-----------------------+
  1202                              <1> 	;
  1203                              <1> 
  1204                              <1> 	;; CR3 REGISTER (Control Register 3)
  1205                              <1> 	;  31                                   12             5 4 3 2   0
  1206                              <1> 	; +---------------------------------------+-------------+---+-----+
  1207                              <1>       	; |                                       |  		|P|P|     |
  1208                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
  1209                              <1>       	; |                                       | 		|D|T|     |
  1210                              <1>    	; +---------------------------------------+-------------+---+-----+
  1211                              <1> 	;
  1212                              <1> 	;	PWT    - WRITE THROUGH
  1213                              <1> 	;	PCD    - CACHE DISABLE		
  1214                              <1> 	;
  1215                              <1> 	;
  1216                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
  1217                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1218                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1219                              <1>       	; |                                       |     | | | | |P|P|U|R| |
  1220                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
  1221                              <1>       	; |                                       |     | | | | |D|T|S|W| |
  1222                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1223                              <1> 	;
  1224                              <1>         ;       P      - PRESENT
  1225                              <1>         ;       R/W    - READ/WRITE
  1226                              <1>         ;       U/S    - USER/SUPERVISOR
  1227                              <1> 	;	PWT    - WRITE THROUGH
  1228                              <1> 	;	PCD    - CACHE DISABLE	
  1229                              <1> 	;	A      - ACCESSED	
  1230                              <1>         ;       D      - DIRTY (IGNORED)
  1231                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1232                              <1> 	;	G      - GLOBAL	(IGNORED) 
  1233                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1234                              <1> 	;
  1235                              <1> 	;
  1236                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
  1237                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1238                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1239                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
  1240                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
  1241                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
  1242                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1243                              <1> 	;
  1244                              <1>         ;       P      - PRESENT
  1245                              <1>         ;       R/W    - READ/WRITE
  1246                              <1>         ;       U/S    - USER/SUPERVISOR
  1247                              <1> 	;	PWT    - WRITE THROUGH
  1248                              <1> 	;	PCD    - CACHE DISABLE	
  1249                              <1> 	;	A      - ACCESSED	
  1250                              <1>         ;       D      - DIRTY
  1251                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1252                              <1> 	;	G      - GLOBAL	 
  1253                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1254                              <1> 	;
  1255                              <1> 	;
  1256                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
  1257                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1258                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1259                              <1>       	; |                                       |     | | | | | | |U|R| |
  1260                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
  1261                              <1>       	; |                                       |     | | | | | | |S|W| |
  1262                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1263                              <1> 	;
  1264                              <1>         ;       P      - PRESENT
  1265                              <1>         ;       R/W    - READ/WRITE
  1266                              <1>         ;       U/S    - USER/SUPERVISOR
  1267                              <1>         ;       D      - DIRTY
  1268                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1269                              <1> 	;
  1270                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
  1271                              <1> 	;
  1272                              <1> 	;
  1273                              <1> 	;; Invalid Page Table Entry
  1274                              <1> 	; 31                                                           1 0
  1275                              <1>       	; +-------------------------------------------------------------+-+
  1276                              <1>       	; |                                                             | |
  1277                              <1>       	; |                          AVAILABLE                          |0|
  1278                              <1>       	; |                                                             | |
  1279                              <1>       	; +-------------------------------------------------------------+-+
  1280                              <1> 	;
  1281                              <1> 
  1282 000048BE 53                  <1> 	push	ebx
  1283 000048BF 52                  <1> 	push	edx
  1284 000048C0 51                  <1> 	push	ecx
  1285                              <1> 	;
  1286                              <1> 	; 21/09/2015 (debugging)
  1287 000048C1 FF05[11310100]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
  1288 000048C7 FF05[8C3E0100]      <1> 	inc	dword [PF_Count] ; total page fault count	
  1289                              <1> 	; 28/06/2015
  1290                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
  1291 000048CD 8A15[843E0100]      <1> 	mov	dl, [error_code]
  1292                              <1> 	;
  1293 000048D3 F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
  1294                              <1> 			; sign
  1295 000048D6 7422                <1> 	jz	short pfh_alloc_np
  1296                              <1> 	; 
  1297                              <1> 	; If it is not a 'write on read only page' type page fault
  1298                              <1> 	; major page fault error with minor reason must be returned without 
  1299                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
  1300                              <1> 	; after return here!
  1301                              <1> 	; Page fault will be remedied, by copying page contents
  1302                              <1> 	; to newly allocated page with write permission;
  1303                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
  1304                              <1> 	; used for working with minimum possible memory usage. 
  1305                              <1> 	; sys_fork will duplicate page directory and tables of parent  
  1306                              <1> 	; process with 'read only' flag. If the child process attempts to
  1307                              <1> 	; write on these read only pages, page fault will be directed here
  1308                              <1> 	; for allocating a new page with same data/content. 
  1309                              <1> 	;
  1310                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
  1311                              <1> 	; will not force to separate CODE and DATA space 
  1312                              <1> 	; in a process/program... 
  1313                              <1> 	; CODE segment/section may contain DATA!
  1314                              <1> 	; It is flat, smoth and simplest programming method already as in 
  1315                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
  1316                              <1> 	;	
  1317 000048D8 F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
  1318                              <1> 			; sign
  1319 000048DB 0F84AB000000        <1>         jz      pfh_p_err
  1320                              <1> 	; 31/08/2015
  1321 000048E1 F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
  1322                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
  1323 000048E4 0F84A2000000        <1>         jz	pfh_pv_err
  1324                              <1> 	;
  1325                              <1> 	; make a new page and copy the parent's page content
  1326                              <1> 	; as the child's new page content
  1327                              <1> 	;
  1328 000048EA 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
  1329                              <1> 			 ; which has caused to page fault
  1330 000048ED E8A2000000          <1> 	call 	copy_page
  1331 000048F2 0F828D000000        <1>         jc      pfh_im_err ; insufficient memory
  1332                              <1> 	;
  1333 000048F8 EB7D                <1>         jmp     pfh_cpp_ok
  1334                              <1> 	;
  1335                              <1> pfh_alloc_np:
  1336 000048FA E8E7FCFFFF          <1> 	call	allocate_page	; (allocate a new page)
  1337 000048FF 0F8280000000        <1>         jc      pfh_im_err	; 'insufficient memory' error
  1338                              <1> pfh_chk_cpl:
  1339                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1340                              <1> 		; (Lower 12 bits are ZERO, because 
  1341                              <1> 		;	the address is on a page boundary)
  1342 00004905 80E204              <1> 	and	dl, 4	; CPL = 3 ?
  1343 00004908 7505                <1> 	jnz	short pfh_um
  1344                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
  1345 0000490A 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
  1346                              <1> 			 ; of the current/active page directory
  1347                              <1> 			 ; (Always kernel/system mode page directory, here!)
  1348                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
  1349 0000490D EB06                <1> 	jmp	short pfh_get_pde
  1350                              <1> 	;
  1351                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
  1352 0000490F 8B1D[01310100]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
  1353                              <1> 			; Physical address of the USER's page directory
  1354                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
  1355                              <1> pfh_get_pde:
  1356 00004915 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
  1357 00004918 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
  1358                              <1> 			 ; which has been caused to page fault
  1359                              <1> 			 ;
  1360 0000491B C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
  1361 0000491E 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
  1362                              <1> 	;
  1363 00004921 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
  1364 00004923 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
  1365 00004925 F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
  1366 00004928 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
  1367                              <1> 			  	  ; set/validate page directory entry
  1368 0000492A 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  1369 0000492F 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
  1370 00004931 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
  1371 00004933 EB16                <1> 	jmp	short pfh_get_pte
  1372                              <1> pfh_set_pde:
  1373                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
  1374                              <1> 	;;	 (So, we know this PDE is empty or invalid)
  1375                              <1> 	;
  1376 00004935 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
  1377 00004937 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
  1378 00004939 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
  1379 0000493B 89C3                <1> 	mov	ebx, eax
  1380 0000493D E8A4FCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
  1381 00004942 7241                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
  1382                              <1> pfh_spde_1:
  1383                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1384 00004944 89C1                <1> 	mov	ecx, eax
  1385 00004946 E815FDFFFF          <1> 	call	clear_page ; Clear page content
  1386                              <1> pfh_get_pte:
  1387 0000494B 0F20D0              <1> 	mov	eax, cr2 ; virtual address
  1388                              <1> 			 ; which has been caused to page fault
  1389 0000494E 89C7                <1> 	mov	edi, eax ; 20/07/2015
  1390 00004950 C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
  1391                              <1> 			 ; higher 20 bits of the page fault address 
  1392 00004953 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
  1393 00004958 C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
  1394 0000495B 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
  1395 0000495D 8B03                <1> 	mov	eax, [ebx] ; get previous value of pte
  1396                              <1> 		; bit 0 of EAX is always 0 (otherwise we would not be here)
  1397 0000495F 21C0                <1> 	and	eax, eax
  1398 00004961 7410                <1> 	jz	short pfh_gpte_1
  1399                              <1> 	; 20/07/2015
  1400 00004963 87D9                <1> 	xchg	ebx, ecx ; new page address (physical)
  1401 00004965 55                  <1> 	push	ebp ; 20/07/2015
  1402 00004966 0F20D5              <1> 	mov	ebp, cr2
  1403                              <1> 		; ECX = physical address of the page table entry
  1404                              <1> 		; EBX = Memory page address (physical!)
  1405                              <1> 		; EAX = Swap disk (offset) address
  1406                              <1> 		; EBP = virtual address (page fault address)
  1407 00004969 E8B7000000          <1> 	call	swap_in
  1408 0000496E 5D                  <1> 	pop	ebp
  1409 0000496F 7210                <1> 	jc      short pfh_err_retn
  1410 00004971 87CB                <1> 	xchg	ecx, ebx
  1411                              <1> 		; EBX = physical address of the page table entry
  1412                              <1> 		; ECX = new page
  1413                              <1> pfh_gpte_1:
  1414 00004973 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
  1415 00004975 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
  1416                              <1> pfh_cpp_ok:
  1417                              <1> 	; 20/07/2015
  1418 00004977 0F20D3              <1> 	mov	ebx, cr2
  1419 0000497A E8A9020000          <1> 	call 	add_to_swap_queue
  1420                              <1> 	;
  1421                              <1> 	; The new PTE (which contains the new page) will be added to 
  1422                              <1> 	; the swap queue, here. 
  1423                              <1> 	; (Later, if memory will become insufficient, 
  1424                              <1> 	; one page will be swapped out which is at the head of 
  1425                              <1> 	; the swap queue by using FIFO and access check methods.)
  1426                              <1> 	;
  1427 0000497F 31C0                <1> 	xor	eax, eax  ; 0
  1428                              <1> 	;
  1429                              <1> pfh_err_retn:
  1430 00004981 59                  <1> 	pop	ecx
  1431 00004982 5A                  <1> 	pop	edx
  1432 00004983 5B                  <1> 	pop	ebx
  1433 00004984 C3                  <1> 	retn 
  1434                              <1> 	
  1435                              <1> pfh_im_err:
  1436 00004985 B8E1000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
  1437                              <1> 			; Major (Primary) Error: Page Fault
  1438                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
  1439 0000498A EBF5                <1> 	jmp	short pfh_err_retn
  1440                              <1> 
  1441                              <1> 
  1442                              <1> pfh_p_err: ; 09/03/2015
  1443                              <1> pfh_pv_err:
  1444                              <1> 	; Page fault was caused by a protection-violation
  1445 0000498C B8E3000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
  1446                              <1> 			; Major (Primary) Error: Page Fault
  1447                              <1> 			; Minor (Secondary) Error: Protection violation !
  1448 00004991 F9                  <1> 	stc
  1449 00004992 EBED                <1> 	jmp	short pfh_err_retn
  1450                              <1> 
  1451                              <1> copy_page:
  1452                              <1> 	; 22/09/2015
  1453                              <1> 	; 21/09/2015
  1454                              <1> 	; 19/09/2015
  1455                              <1> 	; 07/09/2015
  1456                              <1> 	; 31/08/2015
  1457                              <1> 	; 20/07/2015
  1458                              <1> 	; 05/05/2015
  1459                              <1> 	; 03/05/2015
  1460                              <1> 	; 18/04/2015
  1461                              <1> 	; 12/04/2015
  1462                              <1> 	; 30/10/2014
  1463                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
  1464                              <1> 	;
  1465                              <1> 	; INPUT -> 
  1466                              <1> 	;	EBX = Virtual (linear) address of source page
  1467                              <1> 	;	     (Page fault address)
  1468                              <1> 	; OUTPUT ->
  1469                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
  1470                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1471                              <1> 	;	EAX = 0 (CF = 1) 
  1472                              <1> 	;		if there is not a free page to be allocated
  1473                              <1> 	;	(page content of the source page will be copied
  1474                              <1> 	;	onto the target/new page) 	
  1475                              <1> 	;
  1476                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
  1477                              <1> 	;	
  1478 00004994 56                  <1> 	push	esi
  1479 00004995 57                  <1> 	push	edi
  1480                              <1> 	;push	ebx
  1481                              <1> 	;push	ecx
  1482 00004996 31F6                <1> 	xor 	esi, esi
  1483 00004998 C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
  1484 0000499B 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
  1485 0000499D C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
  1486 000049A0 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
  1487 000049A3 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
  1488 000049A5 031D[01310100]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
  1489 000049AB 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
  1490 000049AD 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
  1491 000049B1 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
  1492 000049B3 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1493 000049B9 66C1E302            <1> 	shl	bx, 2	   ; shift 2 bits left to get PTE offset
  1494 000049BD 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
  1495                              <1> 	; 07/09/2015
  1496 000049BF 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
  1497                              <1> 				     ; read only page as a child process?)	
  1498 000049C4 7509                <1> 	jnz	short cpp_0 ; yes
  1499 000049C6 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
  1500 000049C8 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
  1501 000049CD EB32                <1> 	jmp	short cpp_1
  1502                              <1> cpp_0:
  1503 000049CF 89FE                <1> 	mov	esi, edi
  1504 000049D1 0335[05310100]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
  1505 000049D7 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
  1506 000049D9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1507 000049DD 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
  1508 000049DF 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1509 000049E5 66C1E602            <1> 	shl	si, 2	   ; shift 2 bits left to get PTE offset
  1510 000049E9 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
  1511 000049EB 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
  1512                              <1> 	; 21/09/2015
  1513 000049ED 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
  1514 000049EF 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
  1515                              <1> 	;
  1516 000049F3 F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
  1517 000049F6 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
  1518                              <1> 	;
  1519 000049F8 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
  1520 000049FD 39C8                <1> 	cmp	eax, ecx   ; Same page?	
  1521 000049FF 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
  1522                              <1> 			    ; Convert child's page to writable page
  1523                              <1> cpp_1:
  1524 00004A01 E8E0FBFFFF          <1> 	call	allocate_page
  1525 00004A06 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
  1526 00004A08 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
  1527 00004A0A 7405                <1> 	jz	short cpp_2
  1528                              <1> 		; Convert read only page to writable page 
  1529                              <1> 		;(for the parent of the current process)
  1530                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
  1531                              <1> 	; 22/09/2015
  1532 00004A0C 890E                <1> 	mov	[esi], ecx
  1533 00004A0E 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
  1534                              <1> 				 ; 1+2+4 = 7
  1535                              <1> cpp_2:
  1536 00004A11 89C7                <1> 	mov	edi, eax ; new page address of the child process
  1537                              <1> 	; 07/09/2015
  1538 00004A13 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
  1539 00004A15 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
  1540 00004A1A F3A5                <1> 	rep	movsd ; 31/08/2015
  1541                              <1> cpp_3:		
  1542 00004A1C 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
  1543 00004A1E 8903                <1> 	mov	[ebx], eax ; Update PTE
  1544 00004A20 28C0                <1> 	sub	al, al ; clear attributes
  1545                              <1> cpp_4:
  1546                              <1> 	;pop	ecx
  1547                              <1> 	;pop	ebx
  1548 00004A22 5F                  <1> 	pop	edi
  1549 00004A23 5E                  <1> 	pop	esi
  1550 00004A24 C3                  <1> 	retn
  1551                              <1> 
  1552                              <1> ;; 28/04/2015
  1553                              <1> ;; 24/10/2014
  1554                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
  1555                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
  1556                              <1> ;;
  1557                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
  1558                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
  1559                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
  1560                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
  1561                              <1> ;;
  1562                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
  1563                              <1> ;;
  1564                              <1> ;; Method:
  1565                              <1> ;;	Swap page queue is a list of allocated pages with physical
  1566                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
  1567                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
  1568                              <1> ;;	When a new page is being allocated, swap queue is updated
  1569                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
  1570                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
  1571                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
  1572                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
  1573                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
  1574                              <1> ;;	offset value becomes it's previous offset value - 4.
  1575                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
  1576                              <1> ;;	the queue/list is not shifted.
  1577                              <1> ;;	After the queue/list shift, newly allocated page is added
  1578                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
  1579                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
  1580                              <1> ;;	will not be added to the tail of swap page queue.  		 
  1581                              <1> ;;	
  1582                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
  1583                              <1> ;;	the first non-accessed, writable page in the list, 
  1584                              <1> ;;	from the head to the tail. The list is shifted to left 
  1585                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
  1586                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
  1587                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
  1588                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
  1589                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
  1590                              <1> ;;	procedure will be failed)...
  1591                              <1> ;;
  1592                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
  1593                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
  1594                              <1> ;;	(PTE) will be added to the tail of the queue after
  1595                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
  1596                              <1> ;;	the queue will be rotated and the PTE in the head will be
  1597                              <1> ;;	added to the tail after resetting 'accessed' bit. 
  1598                              <1> ;;
  1599                              <1> ;;
  1600                              <1> ;;	
  1601                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
  1602                              <1> ;;
  1603                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
  1604                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
  1605                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
  1606                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
  1607                              <1> ;;
  1608                              <1> ;; [swpd_next] = the first free block address in swapped page records
  1609                              <1> ;;    		 for next free block search by 'swap_out' procedure.
  1610                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
  1611                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
  1612                              <1> ;; 		 (entire swap space must be accessed by using
  1613                              <1> ;;		 31 bit offset address) 
  1614                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
  1615                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
  1616                              <1> ;;		  0 for file, or beginning sector of the swap partition
  1617                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
  1618                              <1> ;;
  1619                              <1> ;; 					
  1620                              <1> ;; Method:
  1621                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
  1622                              <1> ;;	procedure swaps out a page from memory to the swap disk 
  1623                              <1> ;;	(partition) or swap file to get a new free page at the memory.
  1624                              <1> ;;	Swapping out is performed by using swap page queue.
  1625                              <1> ;;
  1626                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
  1627                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
  1628                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
  1629                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
  1630                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
  1631                              <1> ;;	Absolute physical (logical) address of the swapped page is 
  1632                              <1> ;;	calculated by adding offset value to the swap partition's 
  1633                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
  1634                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
  1635                              <1> ;;	and offset value is equal to absolute (physical or logical)
  1636                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
  1637                              <1> ;;	is in a partitioned virtual hard disk.) 
  1638                              <1> ;;
  1639                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
  1640                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
  1641                              <1> ;;
  1642                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
  1643                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
  1644                              <1> ;;
  1645                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
  1646                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
  1647                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
  1648                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
  1649                              <1> ;;	it means relevant (respective) block is in use, and, 
  1650                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
  1651                              <1> ;;      swap disk/file block is free.
  1652                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
  1653                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
  1654                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
  1655                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
  1656                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
  1657                              <1> ;;	------------------------------------------------------------
  1658                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
  1659                              <1> ;;	------------------------------------------------------------
  1660                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
  1661                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
  1662                              <1> ;;
  1663                              <1> ;;	..............................................................
  1664                              <1> ;;
  1665                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
  1666                              <1> ;;	then it searches Swap Allocation Table if free count is not
  1667                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
  1668                              <1> ;;	position with value of 1 on the table is converted to swap
  1669                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
  1670                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
  1671                              <1> ;;	number of physical swap disk or virtual swap disk)
  1672                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
  1673                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
  1674                              <1> ;;	(memory page). That will be a direct disk write procedure.
  1675                              <1> ;;	(for preventing late memory allocation, significant waiting). 
  1676                              <1> ;;	If disk write procedure returns with error or free count of 
  1677                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
  1678                              <1> ;;	'insufficient memory error' (cf=1). 
  1679                              <1> ;;
  1680                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
  1681                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
  1682                              <1> ;;	in other words, 'swap_out' will not check the table for other
  1683                              <1> ;;	free blocks after a disk write error. It will return to 
  1684                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
  1685                              <1> ;;
  1686                              <1> ;;	After writing the page on to swap disk/file address/sector,
  1687                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
  1688                              <1> ;;	address (cf=0). 
  1689                              <1> ;;
  1690                              <1> ;;	..............................................................
  1691                              <1> ;;
  1692                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
  1693                              <1> ;;	file sectors at specified memory page. Then page allocation
  1694                              <1> ;;	procedure updates relevant page table entry with 'present' 
  1695                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
  1696                              <1> ;;	to do, except to terminate the process which is the owner of
  1697                              <1> ;;	the swapped page.
  1698                              <1> ;;
  1699                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
  1700                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
  1701                              <1> ;;	updates [swpd_first] pointer if it is required.
  1702                              <1> ;;
  1703                              <1> ;;	..............................................................	 
  1704                              <1> ;;
  1705                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
  1706                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
  1707                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
  1708                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
  1709                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
  1710                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
  1711                              <1> ;;
  1712                              <1> 
  1713                              <1> swap_in:
  1714                              <1> 	; 31/08/2015
  1715                              <1> 	; 20/07/2015
  1716                              <1> 	; 28/04/2015
  1717                              <1> 	; 18/04/2015
  1718                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  1719                              <1> 	;
  1720                              <1> 	; INPUT -> 
  1721                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
  1722                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
  1723                              <1> 	;	EAX = Offset Address for the swapped page on the
  1724                              <1> 	;	      swap disk or in the swap file.
  1725                              <1> 	;
  1726                              <1> 	; OUTPUT ->
  1727                              <1> 	;	EAX = 0 if loading at memory has been successful
  1728                              <1> 	;
  1729                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
  1730                              <1> 	;		  or sector not present or drive not ready
  1731                              <1> 	;	     EAX = Error code
  1732                              <1> 	;	     [u.error] = EAX 
  1733                              <1> 	;		       = The last error code for the process
  1734                              <1> 	;		         (will be reset after returning to user)	  
  1735                              <1> 	;
  1736                              <1> 	; Modified Registers -> EAX
  1737                              <1> 	;
  1738                              <1> 
  1739 00004A25 833D[6E3E0100]00    <1>         cmp     dword [swp_drv], 0
  1740 00004A2C 7646                <1> 	jna	short swpin_dnp_err
  1741                              <1> 
  1742 00004A2E 3B05[723E0100]      <1> 	cmp	eax, [swpd_size]
  1743 00004A34 734A                <1> 	jnb	short swpin_snp_err
  1744                              <1> 
  1745 00004A36 56                  <1> 	push	esi
  1746 00004A37 53                  <1> 	push	ebx
  1747 00004A38 51                  <1> 	push	ecx
  1748 00004A39 8B35[6E3E0100]      <1> 	mov	esi, [swp_drv]	
  1749 00004A3F B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1750                              <1> 		; Note: Even if corresponding physical disk's sector 
  1751                              <1> 		; size different than 512 bytes, logical disk sector
  1752                              <1> 		; size is 512 bytes and disk reading procedure
  1753                              <1> 		; will be performed for reading 4096 bytes
  1754                              <1> 		; (2*2048, 8*512). 
  1755                              <1> 	; ESI = Logical disk description table address
  1756                              <1> 	; EBX = Memory page (buffer) address (physical!)
  1757                              <1> 	; EAX = Sector adress (offset address, logical sector number)
  1758                              <1> 	; ECX = Sector count ; 8 sectors
  1759 00004A44 50                  <1> 	push	eax
  1760 00004A45 E8B2020000          <1> 	call	logical_disk_read
  1761 00004A4A 58                  <1> 	pop	eax
  1762 00004A4B 730C                <1> 	jnc	short swpin_read_ok
  1763                              <1> 	;
  1764 00004A4D B804000000          <1> 	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
  1765 00004A52 A3[FD300100]        <1> 	mov	[u.error], eax
  1766 00004A57 EB17                <1> 	jmp	short swpin_retn
  1767                              <1> 	;
  1768                              <1> swpin_read_ok:
  1769                              <1> 	; EAX = Offset address (logical sector number)
  1770 00004A59 E810020000          <1> 	call	unlink_swap_block  ; Deallocate swap block	
  1771                              <1> 	;
  1772                              <1> 	; EBX = Memory page (buffer) address (physical!)
  1773                              <1> 	; 20/07/2015
  1774 00004A5E 89EB                <1> 	mov	ebx, ebp ; virtual address (page fault address)
  1775 00004A60 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  1776 00004A65 8A1D[F7300100]      <1> 	mov	bl, [u.uno] ; current process number
  1777                              <1> 	; EBX = Virtual address & process number combination
  1778 00004A6B E8DB000000          <1> 	call	swap_queue_shift
  1779                              <1> 	; eax = 0 ; 10/06/2016 (if ebx input > 0, eax output = 0)
  1780                              <1> 	;sub	eax, eax  ; 0 ; Error Code = 0  (no error)
  1781                              <1> 	; zf = 1
  1782                              <1> swpin_retn:
  1783 00004A70 59                  <1> 	pop	ecx
  1784 00004A71 5B                  <1> 	pop	ebx
  1785 00004A72 5E                  <1> 	pop	esi
  1786 00004A73 C3                  <1> 	retn
  1787                              <1> 
  1788                              <1> swpin_dnp_err:
  1789 00004A74 B805000000          <1> 	mov	eax, SWP_DISK_NOT_PRESENT_ERR
  1790                              <1> swpin_err_retn:
  1791 00004A79 A3[FD300100]        <1> 	mov	[u.error], eax
  1792 00004A7E F9                  <1> 	stc
  1793 00004A7F C3                  <1> 	retn
  1794                              <1> 
  1795                              <1> swpin_snp_err:
  1796 00004A80 B806000000          <1> 	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
  1797 00004A85 EBF2                <1> 	jmp	short swpin_err_retn
  1798                              <1> 
  1799                              <1> swap_out:
  1800                              <1> 	; 10/06/2016
  1801                              <1> 	; 07/06/2016
  1802                              <1>         ; 23/05/2016
  1803                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1804                              <1> 	; 24/10/2014 - 31/08/2015 (Retro UNIX 386 v1)
  1805                              <1> 	;
  1806                              <1> 	; INPUT -> 
  1807                              <1> 	;	none
  1808                              <1> 	;
  1809                              <1> 	; OUTPUT ->
  1810                              <1> 	;	EAX = Physical page address (which is swapped out
  1811                              <1> 	;	      for allocating a new page)
  1812                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
  1813                              <1> 	;		  or sector not present or drive not ready
  1814                              <1> 	;	     EAX = Error code
  1815                              <1> 	;	     [u.error] = EAX 
  1816                              <1> 	;		       = The last error code for the process
  1817                              <1> 	;		         (will be reset after returning to user)	  
  1818                              <1> 	;
  1819                              <1> 	; Modified Registers -> none (except EAX)
  1820                              <1> 	;
  1821 00004A87 66833D[6C3E0100]01  <1> 	cmp 	word [swpq_count], 1
  1822 00004A8F 0F82AF000000        <1>         jc      swpout_im_err ; 'insufficient memory'
  1823                              <1> 
  1824                              <1>         ;cmp    dword [swp_drv], 1
  1825                              <1> 	;jc	short swpout_dnp_err ; 'swap disk/file not present'
  1826                              <1> 
  1827 00004A95 833D[763E0100]01    <1>         cmp     dword [swpd_free], 1
  1828 00004A9C 0F828F000000        <1>         jc      swpout_nfspc_err ; 'no free space on swap disk'
  1829                              <1> 
  1830 00004AA2 53                  <1> 	push	ebx ; *
  1831                              <1> swpout_1:
  1832                              <1> 	; 10/06/2016
  1833 00004AA3 31DB                <1> 	xor	ebx, ebx ; shift the queue and return a PTE value
  1834 00004AA5 E8A1000000          <1> 	call	swap_queue_shift
  1835 00004AAA 21C0                <1> 	and	eax, eax	; 0 = empty queue (improper entries)
  1836 00004AAC 0F848A000000        <1>         jz      swpout_npts_err        ; There is not any proper PTE
  1837                              <1> 				       ; pointer in the swap queue
  1838                              <1> 	; EAX = PTE value of the page
  1839                              <1> 	; EBX = PTE address of the page
  1840 00004AB2 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1841                              <1> 	;
  1842                              <1> 	; 07/06/2016
  1843                              <1> 	; 19/05/2016
  1844                              <1> 	; check this page is in timer events or not
  1845                              <1> 	
  1846                              <1> swpout_timer_page_0:
  1847 00004AB6 52                  <1> 	push	edx ; **
  1848                              <1> 
  1849                              <1> 	; 07/06/2016
  1850 00004AB7 803D[4F2D0100]00    <1> 	cmp	byte [timer_events], 0 
  1851 00004ABE 762F                <1> 	jna	short swpout_2
  1852                              <1> 	;
  1853 00004AC0 8A15[4F2D0100]      <1> 	mov	dl, [timer_events]
  1854                              <1> 
  1855 00004AC6 51                  <1> 	push	ecx ; ***
  1856 00004AC7 53                  <1> 	push	ebx ; ****
  1857 00004AC8 BB[6C3D0100]        <1> 	mov	ebx, timer_set ; beginning address of timer event
  1858                              <1> 			       ; structures 
  1859                              <1> swpout_timer_page_1:
  1860 00004ACD 8A0B                <1> 	mov	cl, [ebx]
  1861 00004ACF 08C9                <1> 	or	cl, cl ; 0 = free, >0 = process number
  1862 00004AD1 7415                <1> 	jz	short swpout_timer_page_3
  1863 00004AD3 8B4B0C              <1> 	mov	ecx, [ebx+12] ; response (signal return) address
  1864 00004AD6 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; clear offset part (right 12 bits)
  1865                              <1> 				; of the response byte address, to
  1866                              <1> 				; get beginning of the page address)
  1867 00004ADB 39C8                <1> 	cmp	eax, ecx
  1868 00004ADD 7505                <1> 	jne	short swpout_timer_page_2 ; not same page
  1869                              <1> 	
  1870                              <1> 	; !same page!
  1871                              <1> 	;
  1872                              <1> 	; NOTE: // 19/05/2016 // - TRDOS 386 feature only ! -
  1873                              <1> 	; This page will be used by the kernel to put timer event
  1874                              <1> 	; response (signal return) byte at the requested address;
  1875                              <1> 	; in order to prevent a possible wrong write (while
  1876                              <1> 	; this page is swapped out) on physical memory,
  1877                              <1> 	; we must protect this page against to be swapped out!
  1878                              <1> 	;
  1879 00004ADF 5B                  <1> 	pop	ebx ; ****
  1880 00004AE0 59                  <1> 	pop	ecx ; ***
  1881 00004AE1 5A                  <1> 	pop	edx ; **
  1882 00004AE2 EBBF                <1> 	jmp	short swpout_1	; do not swap out this page !
  1883                              <1>  
  1884                              <1> swpout_timer_page_2:
  1885                              <1> 	; 07/06/2016
  1886 00004AE4 FECA                <1> 	dec	dl
  1887 00004AE6 7405                <1> 	jz	short swpout_timer_page_4
  1888                              <1> swpout_timer_page_3:
  1889                              <1> 	;cmp	ebx, timer_set + 240 ; last timer event (15*16) 
  1890                              <1> 	;jnb	short swpout_timer_page_4
  1891 00004AE8 83C310              <1> 	add	ebx, 16
  1892 00004AEB EBE0                <1> 	jmp	short swpout_timer_page_1	
  1893                              <1> 
  1894                              <1> swpout_timer_page_4:
  1895 00004AED 5B                  <1> 	pop	ebx ; ****
  1896 00004AEE 59                  <1> 	pop	ecx ; ***
  1897                              <1> swpout_2:
  1898 00004AEF 89DA                <1> 	mov	edx, ebx	       ; Page table entry address	
  1899 00004AF1 89C3                <1> 	mov	ebx, eax	       ; Buffer (Page) Address				
  1900                              <1> 	;
  1901 00004AF3 E8A9010000          <1> 	call	link_swap_block
  1902 00004AF8 7304                <1> 	jnc	short swpout_3	       ; It may not be needed here	
  1903                              <1> 				       ; because [swpd_free] value
  1904                              <1> 				       ; was checked at the beginging. 	
  1905 00004AFA 5A                  <1> 	pop	edx ; **
  1906 00004AFB 5B                  <1> 	pop	ebx ; *
  1907 00004AFC EB33                <1> 	jmp	short swpout_nfspc_err 
  1908                              <1> swpout_3:
  1909 00004AFE A900000080          <1> 	test	eax, 80000000h ; test bit 31 (this may not be needed!)
  1910 00004B03 752C                <1> 	jnz	short swpout_nfspc_err  ; 10/06/2016 (bit 31 = 1 !)
  1911                              <1> 	;	
  1912 00004B05 56                  <1> 	push	esi ; **
  1913 00004B06 51                  <1> 	push	ecx ; ***
  1914 00004B07 50                  <1> 	push	eax ; sector address ; (31 bit !, bit 31 = 0)
  1915 00004B08 8B35[6E3E0100]      <1> 	mov	esi, [swp_drv]	
  1916 00004B0E B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1917                              <1> 		; Note: Even if corresponding physical disk's sector 
  1918                              <1> 		; size different than 512 bytes, logical disk sector
  1919                              <1> 		; size is 512 bytes and disk writing procedure
  1920                              <1> 		; will be performed for writing 4096 bytes
  1921                              <1> 		; (2*2048, 8*512). 
  1922                              <1> 	; ESI = Logical disk description table address
  1923                              <1> 	; EBX = Buffer (Page) address
  1924                              <1> 	; EAX = Sector adress (offset address, logical sector number)
  1925                              <1> 	; ECX = Sector count ; 8 sectors
  1926                              <1> 	; edx = PTE address
  1927 00004B13 E8E5010000          <1> 	call	logical_disk_write
  1928                              <1> 	; edx = PTE address
  1929 00004B18 59                  <1> 	pop	ecx ; sector address	
  1930 00004B19 730C                <1> 	jnc	short swpout_write_ok
  1931                              <1> 	;
  1932                              <1> 	;; call	unlink_swap_block ; this block must be left as 'in use'
  1933                              <1> swpout_dw_err:
  1934 00004B1B B808000000          <1> 	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
  1935 00004B20 A3[FD300100]        <1> 	mov	[u.error], eax
  1936 00004B25 EB06                <1> 	jmp	short swpout_retn
  1937                              <1> 	;
  1938                              <1> swpout_write_ok:
  1939                              <1> 	; EBX = Buffer (page) address
  1940                              <1> 	; EDX = Page Table Entry address
  1941                              <1> 	; ECX = Swap disk sector (file block) address (31 bit)
  1942 00004B27 D1E1                <1> 	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
  1943 00004B29 890A                <1> 	mov 	[edx], ecx 
  1944                              <1> 		; bit 0 = 0 (swapped page)
  1945 00004B2B 89D8                <1> 	mov	eax, ebx
  1946                              <1> swpout_retn:
  1947 00004B2D 59                  <1> 	pop	ecx ; ***
  1948 00004B2E 5E                  <1> 	pop	esi ; **
  1949 00004B2F 5B                  <1> 	pop	ebx ; *
  1950 00004B30 C3                  <1> 	retn
  1951                              <1> 
  1952                              <1> ;swpout_dnp_err:
  1953                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
  1954                              <1> ;	jmp	short swpout_err_retn
  1955                              <1> swpout_nfspc_err:
  1956 00004B31 B807000000          <1> 	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
  1957                              <1> swpout_err_retn:
  1958 00004B36 A3[FD300100]        <1> 	mov	[u.error], eax
  1959                              <1> 	;stc
  1960 00004B3B C3                  <1> 	retn
  1961                              <1> swpout_npts_err:
  1962 00004B3C B809000000          <1> 	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
  1963 00004B41 5B                  <1> 	pop	ebx
  1964 00004B42 EBF2                <1> 	jmp	short swpout_err_retn
  1965                              <1> swpout_im_err:
  1966 00004B44 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
  1967 00004B49 EBEB                <1> 	jmp	short swpout_err_retn
  1968                              <1> 
  1969                              <1> swap_queue_shift:
  1970                              <1> 	; 10/06/2016
  1971                              <1> 	; 09/06/2016 - TRDOS 386 (TRDOS v2.0)
  1972                              <1> 	; 23/10/2014 - 20/07/2015 (Retro UNIX 386 v1)
  1973                              <1> 	;
  1974                              <1> 	; INPUT ->
  1975                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
  1976                              <1> 	;	      and process number combination (bit 0 to 11)
  1977                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
  1978                              <1> 	;	
  1979                              <1> 	; OUTPUT ->
  1980                              <1> 	;	If EBX input > 0 
  1981                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  1982                              <1> 	; 	   from the tail to the head, up to entry offset
  1983                              <1> 	; 	   which points to EBX input value or nothing
  1984                              <1> 	;	   to do if EBX value is not found in the queue.
  1985                              <1> 	;	   (The entry -with EBX value- will be removed
  1986                              <1> 	;	   from the queue if it is found.)
  1987                              <1> 	;
  1988                              <1> 	;	   EAX = 0		
  1989                              <1> 	;
  1990                              <1> 	;	If EBX input = 0
  1991                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  1992                              <1> 	; 	   from the tail to the head, if the PTE address
  1993                              <1> 	;	   which is pointed in head of the queue is marked
  1994                              <1> 	;	   as "accessed" or it is marked as "non present".
  1995                              <1> 	;	   (If "accessed" flag of the PTE -which is pointed
  1996                              <1> 	;	   in the head- is set -to 1-, it will be reset
  1997                              <1> 	;	   -to 0- and then, the queue will be rotated 
  1998                              <1> 	;	   -without dropping pointer of the PTE from 
  1999                              <1> 	;	   the queue- for 4 bytes on head to tail direction.
  2000                              <1> 	;	   Pointer in the head will be moved into the tail,
  2001                              <1> 	;	   other PTEs will be shifted on head direction.)
  2002                              <1> 	;
  2003                              <1> 	;	   Swap queue will be shifted up to the first
  2004                              <1> 	;	   'present' or 'non accessed' page will be found
  2005                              <1> 	;	   (as pointed) in the queue head (then it will be
  2006                              <1>         ;          removed/dropped from the queue).
  2007                              <1> 	;
  2008                              <1> 	;	   EAX (> 0) = PTE value of the page which is
  2009                              <1> 	;		 (it's pointer -virtual address-) dropped
  2010                              <1> 	;		 (removed) from swap queue.
  2011                              <1> 	;	   EBX = PTE address of the page (if EAX > 0)
  2012                              <1> 	;	         which is (it's pointer -virtual address-)
  2013                              <1> 	;		 dropped (removed) from swap queue.
  2014                              <1> 	;
  2015                              <1> 	;	   EAX = 0 -> empty swap queue ! 
  2016                              <1> 	;
  2017                              <1> 	; Modified Registers -> EAX, EBX (if EAX > 0)
  2018                              <1> 	;
  2019 00004B4B 0FB705[6C3E0100]    <1> 	movzx   eax, word [swpq_count]  ; Max. 1024
  2020 00004B52 6621C0              <1> 	and	ax, ax
  2021 00004B55 7433                <1> 	jz	short swpqs_retn
  2022 00004B57 57                  <1> 	push	edi
  2023 00004B58 56                  <1> 	push	esi
  2024 00004B59 51                  <1> 	push	ecx
  2025 00004B5A 53                  <1> 	push	ebx
  2026 00004B5B BE00E00800          <1> 	mov	esi, swap_queue
  2027 00004B60 89C1                <1> 	mov	ecx, eax
  2028 00004B62 09DB                <1> 	or	ebx, ebx
  2029 00004B64 7425                <1> 	jz	short swpqs_7
  2030                              <1> swpqs_1:
  2031 00004B66 AD                  <1> 	lodsd
  2032 00004B67 39D8                <1> 	cmp	eax, ebx
  2033 00004B69 7406                <1> 	je	short swpqs_2
  2034 00004B6B E2F9                <1> 	loop	swpqs_1
  2035                              <1> 	; 10/06/2016
  2036 00004B6D 29C0                <1> 	sub	eax, eax 
  2037 00004B6F EB15                <1> 	jmp	short swpqs_6
  2038                              <1> swpqs_2:
  2039 00004B71 89F7                <1> 	mov	edi, esi
  2040 00004B73 83EF04              <1> 	sub 	edi, 4
  2041                              <1> swpqs_3:
  2042 00004B76 66FF0D[6C3E0100]    <1> 	dec	word [swpq_count]
  2043 00004B7D 7403                <1> 	jz	short swpqs_5
  2044                              <1> swpqs_4:
  2045 00004B7F 49                  <1> 	dec 	ecx
  2046 00004B80 F3A5                <1> 	rep	movsd	; shift up (to the head)
  2047                              <1> swpqs_5:
  2048 00004B82 31C0                <1> 	xor	eax, eax
  2049 00004B84 8907                <1> 	mov	[edi], eax
  2050                              <1> swpqs_6:
  2051 00004B86 5B                  <1> 	pop	ebx
  2052                              <1> swpqs_14:
  2053 00004B87 59                  <1> 	pop	ecx
  2054 00004B88 5E                  <1> 	pop	esi
  2055 00004B89 5F                  <1> 	pop	edi
  2056                              <1> swpqs_retn:
  2057 00004B8A C3                  <1> 	retn		
  2058                              <1> swpqs_7:
  2059 00004B8B 89F7                <1> 	mov	edi, esi ; head
  2060 00004B8D AD                  <1> 	lodsd
  2061                              <1> 	; 20/07/2015
  2062 00004B8E 89C3                <1> 	mov	ebx, eax
  2063 00004B90 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF ; ~0FFFh 
  2064                              <1> 		      ; ebx = virtual address (at page boundary)	
  2065 00004B96 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 0FFFh
  2066                              <1> 		      ; ax = process number (1 to 4095)
  2067 00004B9B 3A05[F7300100]      <1> 	cmp	al, [u.uno]
  2068                              <1> 		; Max. 16 (nproc) processes for Retro UNIX 386 v1
  2069 00004BA1 7507                <1> 	jne	short swpqs_8
  2070 00004BA3 A1[01310100]        <1> 	mov	eax, [u.pgdir]
  2071 00004BA8 EB28                <1> 	jmp	short swpqs_9
  2072                              <1> swpqs_8:
  2073                              <1> 	; 09/06/2016
  2074 00004BAA 80B8[1B2E0100]00    <1> 	cmp	byte [eax+p.stat-1], 0
  2075 00004BB1 76C3                <1> 	jna	short swpqs_3     ; free (or terminated) process
  2076 00004BB3 80B8[1B2E0100]02    <1> 	cmp	byte [eax+p.stat-1], 2 ; waiting
  2077 00004BBA 77BA                <1> 	ja	short swpqs_3 	  ; zombie (3) or undefined ?	
  2078                              <1> 
  2079                              <1> 	;shl	ax, 2
  2080 00004BBC C0E002              <1> 	shl	al, 2
  2081 00004BBF 8B80[282E0100]      <1> 	mov 	eax, [eax+p.upage-4]
  2082 00004BC5 09C0                <1> 	or	eax, eax
  2083 00004BC7 74AD                <1> 	jz	short swpqs_3 ; invalid upage
  2084 00004BC9 83C061              <1> 	add	eax, u.pgdir - user
  2085                              <1> 			 ; u.pgdir value for the process
  2086                              <1> 			 ; is in [eax]
  2087 00004BCC 8B00                <1> 	mov	eax, [eax]
  2088 00004BCE 21C0                <1> 	and	eax, eax
  2089 00004BD0 74A4                <1> 	jz	short swpqs_3 ; invalid page directory
  2090                              <1> swpqs_9:
  2091 00004BD2 52                  <1> 	push	edx
  2092                              <1> 	; eax = page directory
  2093                              <1> 	; ebx = virtual address
  2094 00004BD3 E829FBFFFF          <1> 	call	get_pte
  2095 00004BD8 89D3                <1> 	mov	ebx, edx	; PTE address
  2096 00004BDA 5A                  <1> 	pop	edx
  2097                              <1> 	; 10/06/2016
  2098 00004BDB 723B                <1> 	jc	short swpqs_13 ; empty PDE
  2099                              <1> 	; EAX = PTE value
  2100 00004BDD A801                <1> 	test	al, PTE_A_PRESENT ; bit 0 = 1
  2101 00004BDF 7437                <1> 	jz	short swpqs_13  ; Drop non-present page
  2102                              <1> 			        ; from the queue (head)
  2103 00004BE1 A802                <1> 	test	al, PTE_A_WRITE	; bit 1 = 0 (read only)
  2104 00004BE3 7433                <1> 	jz	short swpqs_13  ; Drop read only page
  2105                              <1> 			        ; from the queue (head) 	
  2106                              <1> 	;test	al, PTE_A_ACCESS ; bit 5 = 1 (Accessed)
  2107                              <1> 	;jnz	short swpqs_11  ; present
  2108                              <1> 			        ; accessed page
  2109 00004BE5 0FBAF005            <1>         btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
  2110 00004BE9 7211                <1> 	jc	short swpqs_11  ; accessed page
  2111                              <1> 
  2112 00004BEB 49                  <1> 	dec	ecx
  2113 00004BEC 66890D[6C3E0100]    <1> 	mov	[swpq_count], cx
  2114 00004BF3 7402                <1>         jz      short swpqs_10
  2115                              <1> 		; esi = head + 4
  2116                              <1> 		; edi = head
  2117 00004BF5 F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2118                              <1> swpqs_10:
  2119 00004BF7 890F                <1> 	mov	[edi], ecx ; 0
  2120 00004BF9 59                  <1> 	pop	ecx       	;  EBX (input) in stack
  2121                              <1> 				;  EBX = PTE address	
  2122 00004BFA EB8B                <1> 	jmp	short swpqs_14 
  2123                              <1> 
  2124                              <1> swpqs_11:
  2125 00004BFC 8903                <1> 	mov	[ebx], eax     ; save changed attribute
  2126                              <1> 	; Rotation (head -> tail)
  2127 00004BFE 49                  <1> 	dec	ecx     ; entry count -> last entry number		
  2128 00004BFF 74F6                <1> 	jz	short swpqs_10
  2129                              <1> 		; esi = head + 4
  2130                              <1> 		; edi = head
  2131 00004C01 8B07                <1> 	mov	eax, [edi] ; 20/07/2015
  2132 00004C03 F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2133 00004C05 8907                <1> 	mov	[edi], eax ; head -> tail ; [k] = [1]
  2134                              <1> 
  2135 00004C07 668B0D[6C3E0100]    <1> 	mov	cx, [swpq_count]
  2136                              <1> 
  2137                              <1> swpqs_12:
  2138 00004C0E BE00E00800          <1> 	mov	esi, swap_queue ; head
  2139 00004C13 E973FFFFFF          <1>         jmp     swpqs_7
  2140                              <1> 
  2141                              <1> swpqs_13:
  2142 00004C18 49                  <1> 	dec	ecx
  2143 00004C19 66890D[6C3E0100]    <1> 	mov	[swpq_count], cx
  2144 00004C20 0F845CFFFFFF        <1>         jz      swpqs_5
  2145 00004C26 EBE6                <1> 	jmp	short swpqs_12
  2146                              <1> 
  2147                              <1> add_to_swap_queue:
  2148                              <1> ; temporary - 16/09/2015
  2149 00004C28 C3                  <1> retn
  2150                              <1> 	; 20/07/2015
  2151                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2152                              <1> 	;
  2153                              <1> 	; Adds new page to swap queue
  2154                              <1> 	; (page directories and page tables must not be added
  2155                              <1> 	; to swap queue)	
  2156                              <1> 	;
  2157                              <1> 	; INPUT ->
  2158                              <1> 	;	EBX = Virtual address (for current process, [u.uno])
  2159                              <1> 	;
  2160                              <1> 	; OUTPUT ->
  2161                              <1> 	;	EAX = [swpq_count]
  2162                              <1> 	;	      (after the PTE has been added)
  2163                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
  2164                              <1> 	;	      the PTE could not be added.
  2165                              <1> 	;
  2166                              <1> 	; Modified Registers -> EAX
  2167                              <1> 	;
  2168 00004C29 53                  <1> 	push	ebx
  2169 00004C2A 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  2170 00004C2F 8A1D[F7300100]      <1> 	mov	bl, [u.uno] ; current process number
  2171 00004C35 E811FFFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
  2172                              <1> 				 ; it is already in the queue
  2173                              <1> 		; then add it to the tail of the queue
  2174 00004C3A 0FB705[6C3E0100]    <1> 	movzx	eax, word [swpq_count]
  2175 00004C41 663D0004            <1> 	cmp	ax, 1024
  2176 00004C45 7205                <1> 	jb	short atsq_1
  2177 00004C47 6629C0              <1> 	sub	ax, ax
  2178 00004C4A 5B                  <1> 	pop	ebx
  2179 00004C4B C3                  <1> 	retn
  2180                              <1> atsq_1:
  2181 00004C4C 56                  <1> 	push	esi
  2182 00004C4D BE00E00800          <1> 	mov	esi, swap_queue
  2183 00004C52 6621C0              <1> 	and	ax, ax
  2184 00004C55 740A                <1> 	jz	short atsq_2
  2185 00004C57 66C1E002            <1> 	shl	ax, 2	; convert to offset
  2186 00004C5B 01C6                <1> 	add	esi, eax
  2187 00004C5D 66C1E802            <1> 	shr	ax, 2
  2188                              <1> atsq_2:
  2189 00004C61 6640                <1> 	inc	ax
  2190 00004C63 891E                <1> 	mov	[esi], ebx ; Virtual address + [u.uno] combination
  2191 00004C65 66A3[6C3E0100]      <1> 	mov	[swpq_count], ax
  2192 00004C6B 5E                  <1> 	pop	esi
  2193 00004C6C 5B                  <1> 	pop	ebx
  2194 00004C6D C3                  <1> 	retn
  2195                              <1> 
  2196                              <1> unlink_swap_block:
  2197                              <1> 	; 15/09/2015
  2198                              <1> 	; 30/04/2015
  2199                              <1> 	; 18/04/2015
  2200                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2201                              <1> 	;
  2202                              <1> 	; INPUT -> 
  2203                              <1> 	;	EAX = swap disk/file offset address
  2204                              <1> 	;	      (bit 1 to bit 31)
  2205                              <1> 	; OUTPUT ->
  2206                              <1> 	;	[swpd_free] is increased
  2207                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
  2208                              <1> 	;
  2209                              <1> 	; Modified Registers -> EAX
  2210                              <1> 	;
  2211 00004C6E 53                  <1> 	push	ebx
  2212 00004C6F 52                  <1> 	push	edx
  2213                              <1> 	;
  2214 00004C70 C1E804              <1> 	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
  2215                              <1> 				     ; 3 bits right
  2216                              <1> 				     ; to get swap block/page number
  2217 00004C73 89C2                <1> 	mov	edx, eax
  2218                              <1> 	; 15/09/2015
  2219 00004C75 C1EA03              <1> 	shr	edx, 3		     ; to get offset to S.A.T.
  2220                              <1> 				     ; (1 allocation bit = 1 page)
  2221                              <1> 				     ; (1 allocation bytes = 8 pages)
  2222 00004C78 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2223                              <1> 				     ; (to get 32 bit position)			
  2224                              <1> 	;
  2225 00004C7B BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table address
  2226 00004C80 01D3                <1> 	add	ebx, edx
  2227 00004C82 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
  2228                              <1> 				     ; (allocation bit position)	 
  2229 00004C85 3B05[7A3E0100]      <1> 	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
  2230                              <1> 				     ; than the address in 'swpd_next' ?
  2231                              <1> 				     ; (next/first free block value)		
  2232 00004C8B 7305                <1> 	jnb	short uswpbl_1	     ; no	
  2233 00004C8D A3[7A3E0100]        <1> 	mov	[swpd_next], eax     ; yes	
  2234                              <1> uswpbl_1:
  2235 00004C92 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate block
  2236                              <1> 				     ; set relevant bit to 1.
  2237                              <1> 				     ; set CF to the previous bit value	
  2238 00004C95 F5                  <1> 	cmc			     ; complement carry flag	
  2239 00004C96 7206                <1> 	jc	short uswpbl_2	     ; do not increase swfd_free count
  2240                              <1> 				     ; if the block is already deallocated
  2241                              <1> 				     ; before.	
  2242 00004C98 FF05[763E0100]      <1>         inc     dword [swpd_free]
  2243                              <1> uswpbl_2:
  2244 00004C9E 5A                  <1> 	pop	edx
  2245 00004C9F 5B                  <1> 	pop	ebx
  2246 00004CA0 C3                  <1> 	retn
  2247                              <1> 
  2248                              <1> link_swap_block:
  2249                              <1> 	; 01/07/2015
  2250                              <1> 	; 18/04/2015
  2251                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2252                              <1> 	;
  2253                              <1> 	; INPUT -> none
  2254                              <1> 	;
  2255                              <1> 	; OUTPUT ->
  2256                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
  2257                              <1> 	;	      in sectors (corresponding 
  2258                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
  2259                              <1> 	;
  2260                              <1> 	;	CF = 1 and EAX = 0 
  2261                              <1> 	; 		   if there is not a free block to be allocated	
  2262                              <1> 	;
  2263                              <1> 	; Modified Registers -> none (except EAX)
  2264                              <1> 	;
  2265                              <1> 
  2266                              <1> 	;mov	eax, [swpd_free]
  2267                              <1> 	;and	eax, eax
  2268                              <1> 	;jz	short out_of_swpspc
  2269                              <1> 	;
  2270 00004CA1 53                  <1> 	push	ebx
  2271 00004CA2 51                  <1> 	push	ecx
  2272                              <1> 	;
  2273 00004CA3 BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
  2274 00004CA8 89D9                <1> 	mov	ecx, ebx
  2275 00004CAA 031D[7A3E0100]      <1> 	add	ebx, [swpd_next] ; Free block searching starts from here
  2276                              <1> 				 ; next_free_swap_block >> 5
  2277 00004CB0 030D[7E3E0100]      <1> 	add	ecx, [swpd_last] ; Free block searching ends here
  2278                              <1> 				 ; (total_swap_blocks - 1) >> 5
  2279                              <1> lswbl_scan:
  2280 00004CB6 39CB                <1> 	cmp	ebx, ecx
  2281 00004CB8 770A                <1> 	ja	short lswbl_notfound
  2282                              <1> 	;
  2283 00004CBA 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
  2284                              <1> 			   ; Clears ZF if a bit is found set (1) and 
  2285                              <1> 			   ; loads the destination with an index to
  2286                              <1> 			   ; first set bit. (0 -> 31) 
  2287                              <1> 			   ; Sets ZF to 1 if no bits are found set.
  2288                              <1> 	; 01/07/2015
  2289 00004CBD 751C                <1> 	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
  2290                              <1> 			 ;
  2291                              <1> 			 ; NOTE:  a Swap Disk Allocation Table bit 
  2292                              <1> 			 ;	  with value of 1 means 
  2293                              <1> 			 ;	  the corresponding page is free 
  2294                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
  2295 00004CBF 83C304              <1> 	add	ebx, 4
  2296                              <1> 			 ; We return back for searching next page block
  2297                              <1> 			 ; NOTE: [swpd_free] is not ZERO; so, 
  2298                              <1> 			 ;	 we always will find at least 1 free block here.
  2299 00004CC2 EBF2                <1> 	jmp    	short lswbl_scan
  2300                              <1> 	;
  2301                              <1> lswbl_notfound:	
  2302 00004CC4 81E900000D00        <1> 	sub	ecx, swap_alloc_table
  2303 00004CCA 890D[7A3E0100]      <1> 	mov	[swpd_next], ecx ; next/first free page = last page 
  2304                              <1> 				 ; (unlink_swap_block procedure will change it)
  2305 00004CD0 31C0                <1> 	xor	eax, eax
  2306 00004CD2 A3[763E0100]        <1> 	mov	[swpd_free], eax
  2307 00004CD7 F9                  <1> 	stc
  2308                              <1> lswbl_ok:
  2309 00004CD8 59                  <1> 	pop	ecx
  2310 00004CD9 5B                  <1> 	pop	ebx
  2311 00004CDA C3                  <1> 	retn
  2312                              <1> 	;
  2313                              <1> ;out_of_swpspc:
  2314                              <1> ;	stc
  2315                              <1> ;	retn
  2316                              <1> 
  2317                              <1> lswbl_found:
  2318 00004CDB 89D9                <1> 	mov	ecx, ebx
  2319 00004CDD 81E900000D00        <1> 	sub	ecx, swap_alloc_table
  2320 00004CE3 890D[7A3E0100]      <1> 	mov	[swpd_next], ecx ; Set first free block searching start
  2321                              <1> 				 ; address/offset (to the next)
  2322 00004CE9 FF0D[763E0100]      <1>         dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
  2323                              <1> 	;
  2324 00004CEF 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
  2325                              <1> 				 ; is copied into the Carry Flag and then cleared
  2326                              <1> 				 ; in the destination.
  2327                              <1> 				 ;
  2328                              <1> 				 ; Reset the bit which is corresponding to the 
  2329                              <1> 				 ; (just) allocated block.
  2330 00004CF2 C1E105              <1> 	shl	ecx, 5		 ; (block offset * 32) + block index
  2331 00004CF5 01C8                <1> 	add	eax, ecx	 ; = block number
  2332 00004CF7 C1E003              <1> 	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
  2333                              <1> 				 ; 1 block =  8 sectors
  2334                              <1> 	;
  2335                              <1> 	; EAX = offset address of swap disk/file sector (beginning of the block)
  2336                              <1> 	;
  2337                              <1> 	; NOTE: The relevant page table entry will be updated
  2338                              <1> 	;       according to this EAX value...
  2339                              <1> 	;
  2340 00004CFA EBDC                <1> 	jmp	short lswbl_ok
  2341                              <1> 
  2342                              <1> logical_disk_read:
  2343                              <1> 	; 20/07/2015
  2344                              <1> 	; 09/03/2015 (temporary code here)
  2345                              <1> 	;
  2346                              <1> 	; INPUT ->
  2347                              <1> 	; 	ESI = Logical disk description table address
  2348                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2349                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2350                              <1> 	; 	ECX = Sector count
  2351                              <1> 	;
  2352                              <1> 	;
  2353 00004CFC C3                  <1> 	retn
  2354                              <1> 
  2355                              <1> logical_disk_write:
  2356                              <1> 	; 20/07/2015
  2357                              <1> 	; 09/03/2015 (temporary code here)
  2358                              <1> 	;
  2359                              <1> 	; INPUT ->
  2360                              <1> 	; 	ESI = Logical disk description table address
  2361                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2362                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2363                              <1> 	; 	ECX = Sector count
  2364                              <1> 	;
  2365 00004CFD C3                  <1> 	retn
  2366                              <1> 
  2367                              <1> get_physical_addr:
  2368                              <1> 	; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  2369                              <1> 	; 18/10/2015
  2370                              <1> 	; 29/07/2015
  2371                              <1> 	; 20/07/2015
  2372                              <1> 	; 04/06/2015
  2373                              <1> 	; 20/05/2015
  2374                              <1> 	; 28/04/2015
  2375                              <1> 	; 18/04/2015
  2376                              <1> 	; Get physical address
  2377                              <1> 	;     (allocates a new page for user if it is not present)
  2378                              <1> 	;	
  2379                              <1> 	; (This subroutine is needed for mapping user's virtual 
  2380                              <1> 	; (buffer) address to physical address (of the buffer).)
  2381                              <1> 	; ('sys write', 'sys read' system calls...)
  2382                              <1> 	;
  2383                              <1> 	; INPUT ->
  2384                              <1> 	;	EBX = virtual address
  2385                              <1> 	;	u.pgdir = page directory (physical) address
  2386                              <1> 	;
  2387                              <1> 	; OUTPUT ->
  2388                              <1> 	;	EAX = physical address 
  2389                              <1> 	;	EBX = linear address	
  2390                              <1> 	;	EDX = physical address of the page frame
  2391                              <1> 	;	      (with attribute bits)
  2392                              <1> 	;	ECX = byte count within the page frame
  2393                              <1> 	;
  2394                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
  2395                              <1> 	;
  2396 00004CFE 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
  2397                              <1> get_physical_addr_x: ; 27/05/2016
  2398 00004D04 A1[01310100]        <1> 	mov	eax, [u.pgdir]
  2399 00004D09 E8F3F9FFFF          <1> 	call	get_pte
  2400                              <1> 		; EDX = Page table entry address (if CF=0)
  2401                              <1> 	        ;       Page directory entry address (if CF=1)
  2402                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  2403                              <1> 		; EAX = Page table entry value (page address)
  2404                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
  2405 00004D0E 731C                <1> 	jnc	short gpa_1
  2406                              <1> 	;
  2407 00004D10 E8D1F8FFFF          <1> 	call	allocate_page
  2408 00004D15 725B                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
  2409                              <1> gpa_0:
  2410 00004D17 E844F9FFFF          <1> 	call 	clear_page
  2411                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  2412 00004D1C 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  2413                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  2414                              <1> 			   ; (user, writable, present page)	
  2415 00004D1E 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  2416 00004D20 A1[01310100]        <1> 	mov	eax, [u.pgdir]	
  2417 00004D25 E8D7F9FFFF          <1> 	call	get_pte
  2418 00004D2A 7246                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2419                              <1> gpa_1:
  2420                              <1> 	; EAX = PTE value, EDX = PTE address
  2421 00004D2C A801                <1> 	test 	al, PTE_A_PRESENT
  2422 00004D2E 751A                <1> 	jnz	short gpa_3
  2423 00004D30 09C0                <1> 	or	eax, eax
  2424 00004D32 7430                <1> 	jz	short gpa_4  ; Allocate a new page
  2425                              <1> 	; 20/07/2015
  2426 00004D34 55                  <1> 	push	ebp
  2427 00004D35 89DD                <1> 	mov	ebp, ebx ; virtual (linear) address
  2428                              <1> 	; reload swapped page
  2429 00004D37 E83C000000          <1> 	call	reload_page ; 28/04/2015
  2430 00004D3C 5D                  <1> 	pop	ebp
  2431 00004D3D 7224                <1> 	jc	short gpa_retn
  2432                              <1> gpa_2:
  2433                              <1> 	; 20/07/2015
  2434                              <1> 	; 20/05/2015
  2435                              <1> 	; add this page to swap queue
  2436 00004D3F 50                  <1> 	push	eax 
  2437                              <1> 	; EBX = virtual address
  2438 00004D40 E8E3FEFFFF          <1> 	call 	add_to_swap_queue
  2439 00004D45 58                  <1> 	pop	eax
  2440                              <1> 		; PTE address in EDX
  2441                              <1> 		; virtual address in EBX
  2442                              <1> 	; EAX = memory page address
  2443 00004D46 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
  2444                              <1> 				  ; present flag, bit 0 = 1
  2445                              <1> 				  ; user flag, bit 2 = 1	
  2446                              <1> 				  ; writable flag, bit 1 = 1
  2447 00004D48 8902                <1> 	mov	[edx], eax  ; Update PTE value
  2448                              <1> gpa_3:
  2449                              <1> 	; 18/10/2015
  2450 00004D4A 89D9                <1> 	mov	ecx, ebx
  2451 00004D4C 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
  2452 00004D52 89C2                <1> 	mov 	edx, eax
  2453 00004D54 662500F0            <1> 	and	ax, PTE_A_CLEAR
  2454 00004D58 01C8                <1> 	add	eax, ecx
  2455 00004D5A F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
  2456 00004D5C 81C100100000        <1> 	add	ecx, PAGE_SIZE
  2457 00004D62 F8                  <1> 	clc
  2458                              <1> gpa_retn:
  2459 00004D63 C3                  <1> 	retn	
  2460                              <1> gpa_4:	
  2461 00004D64 E87DF8FFFF          <1> 	call	allocate_page
  2462 00004D69 7207                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2463 00004D6B E8F0F8FFFF          <1> 	call	clear_page
  2464 00004D70 EBCD                <1> 	jmp	short gpa_2
  2465                              <1> 
  2466                              <1> gpa_im_err:	
  2467 00004D72 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2468                              <1> 				  ; Major error = 0 (No protection fault)	
  2469 00004D77 C3                  <1> 	retn
  2470                              <1> 
  2471                              <1> reload_page:
  2472                              <1> 	; 20/07/2015
  2473                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
  2474                              <1> 	;
  2475                              <1> 	; Reload (Restore) swapped page at memory
  2476                              <1> 	;
  2477                              <1> 	; INPUT -> 
  2478                              <1> 	;	EBP = Virtual (linear) memory address
  2479                              <1> 	;	EAX = PTE value (swap disk sector address)
  2480                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
  2481                              <1> 	; OUTPUT ->
  2482                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
  2483                              <1> 	;
  2484                              <1> 	;	CF = 1 and EAX = error code
  2485                              <1> 	;
  2486                              <1> 	; Modified Registers -> none (except EAX)
  2487                              <1> 	;
  2488 00004D78 D1E8                <1> 	shr	eax, 1   ; Convert PTE value to swap disk address 
  2489 00004D7A 53                  <1> 	push	ebx      ;
  2490 00004D7B 89C3                <1> 	mov	ebx, eax ; Swap disk (offset) address	
  2491 00004D7D E864F8FFFF          <1> 	call	allocate_page
  2492 00004D82 720C                <1> 	jc	short rlp_im_err
  2493 00004D84 93                  <1> 	xchg 	eax, ebx	
  2494                              <1> 	; EBX = Physical memory (page) address
  2495                              <1> 	; EAX = Swap disk (offset) address
  2496                              <1> 	; EBP = Virtual (linear) memory address
  2497 00004D85 E89BFCFFFF          <1> 	call	swap_in
  2498 00004D8A 720B                <1> 	jc	short rlp_swp_err  ; (swap disk/file read error)
  2499 00004D8C 89D8                <1> 	mov	eax, ebx	
  2500                              <1> rlp_retn:
  2501 00004D8E 5B                  <1> 	pop	ebx
  2502 00004D8F C3                  <1> 	retn
  2503                              <1> 	
  2504                              <1> rlp_im_err:	
  2505 00004D90 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2506                              <1> 				  ; Major error = 0 (No protection fault)	
  2507 00004D95 EBF7                <1> 	jmp	short rlp_retn
  2508                              <1> 
  2509                              <1> rlp_swp_err:
  2510 00004D97 B804000000          <1> 	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
  2511 00004D9C EBF0                <1> 	jmp	short rlp_retn
  2512                              <1> 
  2513                              <1> 
  2514                              <1> copy_page_dir:
  2515                              <1> 	; 19/09/2015
  2516                              <1> 	; temporary - 07/09/2015
  2517                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2518                              <1> 	;
  2519                              <1> 	; INPUT -> 
  2520                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
  2521                              <1> 	;		    page directory.
  2522                              <1> 	; OUTPUT ->
  2523                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
  2524                              <1> 	;	       page directory.
  2525                              <1> 	;	(New page directory with new page table entries.)
  2526                              <1> 	;	(New page tables with read only copies of the parent's
  2527                              <1> 	;	pages.)
  2528                              <1> 	;	EAX = 0 -> Error (CF = 1)
  2529                              <1> 	;
  2530                              <1> 	; Modified Registers -> none (except EAX)
  2531                              <1> 	;
  2532 00004D9E E843F8FFFF          <1> 	call	allocate_page
  2533 00004DA3 723E                <1> 	jc	short cpd_err
  2534                              <1> 	;
  2535 00004DA5 55                  <1> 	push	ebp ; 20/07/2015
  2536 00004DA6 56                  <1> 	push	esi
  2537 00004DA7 57                  <1> 	push	edi
  2538 00004DA8 53                  <1> 	push	ebx
  2539 00004DA9 51                  <1> 	push	ecx
  2540 00004DAA 8B35[01310100]      <1> 	mov	esi, [u.pgdir]
  2541 00004DB0 89C7                <1> 	mov	edi, eax
  2542 00004DB2 50                  <1> 	push	eax ; save child's page directory address
  2543                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
  2544                              <1> 	; (use same system space for all user page tables) 
  2545 00004DB3 A5                  <1> 	movsd
  2546 00004DB4 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  2547 00004DB9 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  2548                              <1> cpd_0:	
  2549 00004DBE AD                  <1> 	lodsd
  2550                              <1> 	;or	eax, eax
  2551                              <1>         ;jnz     short cpd_1
  2552 00004DBF A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  2553 00004DC1 7508                <1> 	jnz	short cpd_1
  2554                              <1>  	; (virtual address at the end of the page table)	
  2555 00004DC3 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  2556 00004DC9 EB0F                <1> 	jmp	short cpd_2
  2557                              <1> cpd_1:	
  2558 00004DCB 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  2559 00004DCF 89C3                <1> 	mov	ebx, eax
  2560                              <1> 	; EBX = Parent's page table address
  2561 00004DD1 E81F000000          <1> 	call	copy_page_table
  2562 00004DD6 720C                <1> 	jc	short cpd_p_err
  2563                              <1> 	; EAX = Child's page table address
  2564 00004DD8 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  2565                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  2566                              <1> 			 ; (present, writable, user)
  2567                              <1> cpd_2:
  2568 00004DDA AB                  <1> 	stosd
  2569 00004DDB E2E1                <1> 	loop	cpd_0
  2570                              <1> 	;
  2571 00004DDD 58                  <1> 	pop	eax  ; restore child's page directory address
  2572                              <1> cpd_3:
  2573 00004DDE 59                  <1> 	pop	ecx
  2574 00004DDF 5B                  <1> 	pop	ebx
  2575 00004DE0 5F                  <1> 	pop	edi
  2576 00004DE1 5E                  <1> 	pop	esi
  2577 00004DE2 5D                  <1> 	pop	ebp
  2578                              <1> cpd_err:
  2579 00004DE3 C3                  <1> 	retn
  2580                              <1> cpd_p_err:
  2581                              <1> 	; release the allocated pages missing (recover free space)
  2582 00004DE4 58                  <1> 	pop	eax  ; the new page directory address (physical)
  2583 00004DE5 8B1D[01310100]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  2584 00004DEB E82FF9FFFF          <1> 	call 	deallocate_page_dir
  2585 00004DF0 29C0                <1> 	sub	eax, eax ; 0
  2586 00004DF2 F9                  <1> 	stc
  2587 00004DF3 EBE9                <1> 	jmp	short cpd_3	
  2588                              <1> 
  2589                              <1> copy_page_table:
  2590                              <1> 	; 19/09/2015
  2591                              <1> 	; temporary - 07/09/2015
  2592                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2593                              <1> 	;
  2594                              <1> 	; INPUT -> 
  2595                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
  2596                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
  2597                              <1> 	; OUTPUT ->
  2598                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  2599                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
  2600                              <1> 	;	CF = 1 -> error 
  2601                              <1> 	;
  2602                              <1> 	; Modified Registers -> EBP (except EAX)
  2603                              <1> 	;
  2604 00004DF5 E8ECF7FFFF          <1> 	call	allocate_page
  2605 00004DFA 725A                <1> 	jc	short cpt_err
  2606                              <1> 	;
  2607 00004DFC 50                  <1> 	push	eax ; *
  2608                              <1> 	;push 	ebx
  2609 00004DFD 56                  <1> 	push	esi
  2610 00004DFE 57                  <1> 	push	edi
  2611 00004DFF 52                  <1> 	push	edx
  2612 00004E00 51                  <1> 	push	ecx
  2613                              <1> 	;
  2614 00004E01 89DE                <1> 	mov	esi, ebx
  2615 00004E03 89C7                <1> 	mov	edi, eax
  2616 00004E05 89C2                <1> 	mov	edx, eax
  2617 00004E07 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  2618                              <1> cpt_0:
  2619 00004E0D AD                  <1> 	lodsd
  2620 00004E0E A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
  2621 00004E10 750B                <1> 	jnz	short cpt_1
  2622 00004E12 21C0                <1> 	and	eax, eax
  2623 00004E14 7430                <1> 	jz	short cpt_2
  2624                              <1> 	; ebp = virtual (linear) address of the memory page
  2625 00004E16 E85DFFFFFF          <1> 	call	reload_page ; 28/04/2015
  2626 00004E1B 7234                <1> 	jc	short cpt_p_err
  2627                              <1> cpt_1:
  2628 00004E1D 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  2629 00004E21 89C1                <1> 	mov	ecx, eax
  2630                              <1> 	; Allocate a new page for the child process
  2631 00004E23 E8BEF7FFFF          <1> 	call	allocate_page
  2632 00004E28 7227                <1> 	jc	short cpt_p_err
  2633 00004E2A 57                  <1> 	push	edi
  2634 00004E2B 56                  <1> 	push	esi
  2635 00004E2C 89CE                <1> 	mov	esi, ecx
  2636 00004E2E 89C7                <1> 	mov	edi, eax
  2637 00004E30 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  2638 00004E35 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  2639 00004E37 5E                  <1> 	pop	esi
  2640 00004E38 5F                  <1> 	pop	edi
  2641                              <1> 	; 
  2642 00004E39 53                  <1> 	push	ebx
  2643 00004E3A 50                  <1> 	push	eax
  2644 00004E3B 89EB                <1> 	mov	ebx, ebp
  2645                              <1> 	; ebx = virtual address of the memory page
  2646 00004E3D E8E6FDFFFF          <1> 	call	add_to_swap_queue
  2647 00004E42 58                  <1> 	pop	eax
  2648 00004E43 5B                  <1> 	pop	ebx
  2649                              <1> 	;
  2650                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  2651 00004E44 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  2652                              <1> cpt_2:
  2653 00004E46 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  2654                              <1> 	;
  2655 00004E47 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  2656                              <1> 	;
  2657 00004E4D 39D7                <1> 	cmp	edi, edx
  2658 00004E4F 72BC                <1> 	jb	short cpt_0
  2659                              <1> cpt_p_err:
  2660 00004E51 59                  <1> 	pop	ecx
  2661 00004E52 5A                  <1> 	pop	edx
  2662 00004E53 5F                  <1> 	pop	edi
  2663 00004E54 5E                  <1> 	pop	esi
  2664                              <1> 	;pop	ebx
  2665 00004E55 58                  <1> 	pop	eax ; *
  2666                              <1> cpt_err:
  2667 00004E56 C3                  <1> 	retn
  2668                              <1> 
  2669                              <1> 
  2670                              <1> allocate_memory_block:
  2671                              <1> 	; 03/04/2016
  2672                              <1> 	; 02/04/2016
  2673                              <1> 	; 01/04/2016
  2674                              <1> 	; 14/03/2016
  2675                              <1> 	; 13/03/2016
  2676                              <1> 	; 12/03/2016 (TRDOS 386 = TRDOS v2.0)
  2677                              <1> 	; Allocating contiguous memory pages (in the kernel's memory space)
  2678                              <1> 	;
  2679                              <1> 	; INPUT -> 
  2680                              <1> 	;	EAX = Beginning address (physical)
  2681                              <1> 	;	EAX = 0 -> Allocate memory block from the first proper aperture	
  2682                              <1> 	;	ECX = Number of bytes to be allocated
  2683                              <1> 	;
  2684                              <1> 	; OUTPUT ->
  2685                              <1> 	; 	1) cf = 0 -> successful
  2686                              <1> 	;	EAX = Beginning (physical) address of the allocated memory block
  2687                              <1> 	;	ECX = Number of allocated bytes (rounded up to page borders) 
  2688                              <1> 	;	2) cf = 1 -> unsuccessful
  2689                              <1> 	;	 2.1) If EAX > 0 -> 
  2690                              <1> 	;	      (Number of requested pages is more than # of free pages
  2691                              <1> 	;	       but contiguous free pages -the aperture- is not enough!)	   	
  2692                              <1> 	;	      EAX = Beginning address of available aperture
  2693                              <1> 	;		    (one of all aperture with max. aperture size/length)		
  2694                              <1> 	;	      ECX = Size of available aperture (memory block) in bytes
  2695                              <1> 	;	 2.2) If EAX = 0 -> Out of memory error 
  2696                              <1> 	;	            (number of free pages is less than requested number)
  2697                              <1> 	;	      ECX = Total number of free bytes (free pages * 4096) 
  2698                              <1> 	;		    (It is not number of contiguous free bytes)	
  2699                              <1> 	;
  2700                              <1> 	; (Modified Registers -> EAX, ECX)
  2701                              <1> 	;
  2702                              <1> 	; PURPOSE: Loading a file at memory for copying or running etc.
  2703                              <1> 	; If this procedure returns with cf is set, ECX contains maximum
  2704                              <1> 	; available space and EAX contains the beginning address of it.
  2705                              <1> 	; If EAX has zero, ECX contains total number of free bytes.
  2706                              <1> 	; If requested block has been successfully allocated (by rounding up to
  2707                              <1> 	; the last page border), it must be deallocated later by using
  2708                              <1> 	; 'dealloacate_memory_block' procedure.    
  2709                              <1> 
  2710 00004E57 52                  <1> 	push	edx ; *
  2711 00004E58 BAFF0F0000          <1> 	mov	edx, PAGE_SIZE - 1   ; 4095
  2712 00004E5D 01D1                <1> 	add	ecx, edx
  2713 00004E5F 01D0                <1> 	add	eax, edx
  2714 00004E61 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  2715                              <1> 
  2716                              <1> 	; ECX = number of contiguous pages to be allocated
  2717 00004E64 8B15[D01F0100]      <1> 	mov	edx, [free_pages]
  2718 00004E6A 39D1                <1> 	cmp	ecx, edx
  2719 00004E6C 7775                <1> 	ja	short amb_6
  2720                              <1> 
  2721 00004E6E C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; 12
  2722                              <1> 
  2723 00004E71 89C2                <1> 	mov	edx, eax 	     ; page number
  2724 00004E73 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2725                              <1> 				     ; (1 allocation bit = 1 page)
  2726                              <1> 				     ; (1 allocation bytes = 8 pages)
  2727 00004E76 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2728                              <1> 				     ; (to get 32 bit position)	
  2729 00004E79 53                  <1> 	push	ebx ; **
  2730                              <1> amb_0:
  2731 00004E7A 890D[842C0100]      <1> 	mov	[mem_ipg_count], ecx ; initial (reset) value of page count
  2732 00004E80 890D[882C0100]      <1> 	mov	[mem_pg_count], ecx
  2733 00004E86 31C9                <1> 	xor	ecx, ecx ; 0
  2734 00004E88 890D[8C2C0100]      <1> 	mov	[mem_aperture], ecx ; 0
  2735 00004E8E 890D[902C0100]      <1> 	mov	[mem_max_aperture], ecx ; 0
  2736                              <1> 	
  2737 00004E94 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address.
  2738 00004E99 3B15[D41F0100]      <1> 	cmp	edx, [next_page]     ; Is the beginning page address lower
  2739                              <1> 				     ; than the address in 'next_page' ?
  2740                              <1> 				     ; (the first/next free page of user space)		
  2741 00004E9F 7208                <1> 	jb	short amb_1
  2742 00004EA1 3B15[D81F0100]      <1> 	cmp 	edx, [last_page]     ; is the beginning page address higher
  2743                              <1> 				     ; than the address in 'last_page' ?
  2744                              <1> 				     ; (end of the memory)		
  2745 00004EA7 7606                <1> 	jna	short amb_2	     ; no	
  2746                              <1> amb_1:
  2747 00004EA9 8B15[D41F0100]      <1> 	mov	edx, [next_page]     ; yes (reset to the first page of user space)
  2748                              <1> amb_2:
  2749 00004EAF 01D3                <1> 	add	ebx, edx
  2750                              <1> 
  2751 00004EB1 A3[942C0100]        <1> 	mov	[mem_pg_pos], eax    ; beginning page no (for curr. mem. aperture)
  2752 00004EB6 A3[982C0100]        <1>  	mov	[mem_max_pg_pos], eax ; beginning page no for max. mem. aperture
  2753                              <1> 
  2754 00004EBB 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only (0 to 31)
  2755                              <1> 				     ; (allocation bit position)	 
  2756 00004EBE 744B                <1> 	jz	short amb_10	     ; 0	
  2757                              <1> amb_3:
  2758 00004EC0 8B13                <1> 	mov	edx, [ebx]
  2759 00004EC2 88C1                <1> 	mov	cl, al ; 1 to 31
  2760 00004EC4 D3EA                <1> 	shr	edx, cl
  2761 00004EC6 89D0                <1> 	mov	eax, edx
  2762                              <1> amb_4:
  2763 00004EC8 D1E8                <1> 	shr	eax, 1 ; (***)
  2764 00004ECA 7321                <1> 	jnc	short amb_7
  2765 00004ECC FF05[8C2C0100]      <1> 	inc	dword [mem_aperture]
  2766 00004ED2 FF0D[882C0100]      <1> 	dec	dword [mem_pg_count]
  2767 00004ED8 747B                <1> 	jz	short amb_15
  2768                              <1> amb_5:
  2769 00004EDA 80F91F              <1> 	cmp	cl, 31
  2770 00004EDD 7317                <1> 	jnb	short amb_8
  2771 00004EDF FEC1                <1> 	inc	cl
  2772 00004EE1 EBE5                <1> 	jmp	short amb_4
  2773                              <1> 
  2774                              <1> amb_6:	; out_of_memory
  2775 00004EE3 31C0                <1> 	xor	eax, eax ; 0
  2776 00004EE5 89D1                <1> 	mov	ecx, edx ; free pages
  2777 00004EE7 C1E10C              <1> 	shl	ecx, PAGE_SHIFT
  2778 00004EEA 5A                  <1> 	pop	edx ; *
  2779 00004EEB F9                  <1> 	stc
  2780 00004EEC C3                  <1> 	retn
  2781                              <1> amb_7:
  2782 00004EED 50                  <1> 	push	eax ; (***) allocation bits (in shifted status)
  2783 00004EEE E819010000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2784 00004EF3 58                  <1> 	pop	eax ; (***)
  2785 00004EF4 EBE4                <1> 	jmp	short amb_5
  2786                              <1> amb_8:
  2787 00004EF6 28C9                <1> 	sub	cl, cl ; 0
  2788                              <1> amb_9:
  2789 00004EF8 89DA                <1> 	mov	edx, ebx
  2790 00004EFA 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
  2791 00004F00 3B15[D81F0100]      <1> 	cmp	edx, [last_page]
  2792 00004F06 7336                <1> 	jnb	short amb_14 ; contiguous pages not enough
  2793 00004F08 83C304              <1> 	add	ebx, 4
  2794                              <1> amb_10:
  2795 00004F0B 8B03                <1> 	mov	eax, [ebx]
  2796 00004F0D 21C0                <1> 	and 	eax, eax
  2797 00004F0F 7406                <1>         jz      short amb_11 ; there is not a free page bit in this alloc dword
  2798 00004F11 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
  2799 00004F12 740A                <1> 	jz	short amb_12 ; all of bits are set (32 free pages)
  2800 00004F14 48                  <1> 	dec	eax
  2801 00004F15 EBB1                <1> 	jmp	short amb_4
  2802                              <1> amb_11:
  2803 00004F17 E8F0000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2804 00004F1C EBDA                <1> 	jmp	short amb_9	
  2805                              <1> amb_12:
  2806 00004F1E B120                <1> 	mov	cl, 32
  2807 00004F20 390D[882C0100]      <1> 	cmp	[mem_pg_count], ecx ; 32
  2808 00004F26 7306                <1> 	jnb	short amb_13
  2809 00004F28 8B0D[882C0100]      <1> 	mov	ecx, [mem_pg_count]
  2810                              <1> amb_13:
  2811 00004F2E 010D[8C2C0100]      <1> 	add	[mem_aperture], ecx
  2812 00004F34 290D[882C0100]      <1> 	sub	[mem_pg_count], ecx
  2813 00004F3A 7619                <1> 	jna	short amb_15
  2814 00004F3C EBB8                <1> 	jmp	short amb_8
  2815                              <1> amb_14:
  2816 00004F3E A1[982C0100]        <1> 	mov	eax, [mem_max_pg_pos] ; begin address of max. mem aperture	
  2817 00004F43 8B0D[902C0100]      <1> 	mov	ecx, [mem_max_aperture] ; max. (largest) memory aperture
  2818 00004F49 C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
  2819 00004F4C C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
  2820 00004F4F F9                  <1> 	stc
  2821 00004F50 E9AC000000          <1>         jmp     amb_25
  2822                              <1> 
  2823                              <1> amb_15: ; OK !
  2824 00004F55 A1[942C0100]        <1> 	mov	eax, [mem_pg_pos]    ; Beginning address as page number
  2825 00004F5A 8B0D[8C2C0100]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count
  2826                              <1> amb_16:
  2827                              <1> 	; allocate contiguous memory pages (via memory allocation table bits)
  2828 00004F60 89C2                <1> 	mov	edx, eax
  2829 00004F62 C1EA05              <1> 	shr	edx, 5 ; 32 pages in one allocation dword (32 bits)
  2830 00004F65 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  2831 00004F6A 01D3                <1> 	add	ebx, edx
  2832 00004F6C 83E01F              <1> 	and	eax, 1Fh ; 31
  2833                              <1> 	; 03/04/2016
  2834 00004F6F BA20000000          <1> 	mov	edx, 32
  2835 00004F74 28C2                <1> 	sub	dl, al
  2836 00004F76 39CA                <1> 	cmp	edx, ecx
  2837 00004F78 7602                <1> 	jna	short amb_17
  2838 00004F7A 89CA                <1> 	mov	edx, ecx
  2839                              <1> amb_17:
  2840 00004F7C 29D1                <1> 	sub	ecx, edx
  2841 00004F7E 51                  <1> 	push	ecx ; ***
  2842 00004F7F 89D1                <1> 	mov	ecx, edx
  2843                              <1> amb_18:		
  2844 00004F81 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
  2845                              <1> 				 ; is copied into the Carry Flag and then cleared
  2846                              <1> 				 ; in the destination.
  2847 00004F84 FF0D[D01F0100]      <1> 	dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
  2848 00004F8A 49                  <1> 	dec	ecx
  2849 00004F8B 7404                <1> 	jz	short amb_19
  2850 00004F8D FEC0                <1> 	inc	al
  2851 00004F8F EBF0                <1> 	jmp	short amb_18
  2852                              <1> amb_19:	
  2853 00004F91 59                  <1> 	pop	ecx ; ***
  2854 00004F92 21C9                <1> 	and	ecx, ecx ; 0 ?
  2855 00004F94 741E                <1> 	jz	short amb_22	
  2856                              <1> 	; 01/04/2016
  2857 00004F96 B020                <1> 	mov	al, 32
  2858                              <1> amb_20:
  2859 00004F98 83C304              <1> 	add	ebx, 4
  2860 00004F9B 39C1                <1> 	cmp	ecx, eax ; 32
  2861 00004F9D 7305                <1> 	jnb	short amb_21
  2862                              <1> 	; ECX < 32
  2863 00004F9F 28C0                <1> 	sub	al, al ; 0
  2864 00004FA1 50                  <1> 	push	eax ; 0 ***
  2865 00004FA2 EBDD                <1> 	jmp	short amb_18
  2866                              <1> amb_21:
  2867 00004FA4 2905[D01F0100]      <1> 	sub	[free_pages], eax ; [free_pages] = [free_pages] - 32
  2868 00004FAA C70300000000        <1> 	mov	dword [ebx], 0 ; reset 32 bits
  2869 00004FB0 29C1                <1> 	sub	ecx, eax ; 32
  2870 00004FB2 75E4                <1> 	jnz	short amb_20
  2871                              <1> amb_22:
  2872 00004FB4 A1[942C0100]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
  2873 00004FB9 8B0D[8C2C0100]      <1> 	mov	ecx, [mem_aperture] ; Free contiguous page count
  2874                              <1> 	; [next_page] update
  2875 00004FBF 89C2                <1> 	mov	edx, eax
  2876                              <1> 	; 03/04/2016
  2877 00004FC1 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2878                              <1> 				     ; (1 allocation bit = 1 page)
  2879                              <1> 				     ; (1 allocation bytes = 8 pages)
  2880 00004FC4 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2881                              <1> 				     ; (to get 32 bit position)	
  2882 00004FC7 3B15[D41F0100]      <1> 	cmp	edx, [next_page] ; first free page pointer offset
  2883 00004FCD 7732                <1> 	ja	short amb_25
  2884 00004FCF BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  2885 00004FD4 833C1300            <1> 	cmp	dword [ebx+edx], 0
  2886 00004FD8 7721                <1> 	ja	short amb_24
  2887 00004FDA 89C2                <1> 	mov	edx, eax
  2888 00004FDC 01CA                <1> 	add	edx, ecx
  2889 00004FDE C1EA03              <1> 	shr	edx, 3
  2890 00004FE1 80E2FC              <1> 	and	dl, 0FCh
  2891                              <1> amb_23:
  2892 00004FE4 833C1300            <1> 	cmp	dword [ebx+edx], 0
  2893 00004FE8 7711                <1> 	ja	short amb_24
  2894 00004FEA 83C204              <1> 	add	edx, 4
  2895 00004FED 3B15[D81F0100]      <1> 	cmp	edx, [last_page]    ; last page pointer offset
  2896 00004FF3 76EF                <1> 	jna	short amb_23
  2897 00004FF5 8B15[DC1F0100]      <1> 	mov	edx, [first_page]   ; (for) beginning of user's space
  2898                              <1> amb_24:
  2899 00004FFB 8915[D41F0100]      <1> 	mov	[next_page], edx
  2900                              <1> amb_25:
  2901 00005001 9C                  <1> 	pushf
  2902 00005002 C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
  2903 00005005 C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
  2904 00005008 9D                  <1> 	popf
  2905 00005009 5B                  <1> 	pop	ebx ; **
  2906 0000500A 5A                  <1> 	pop	edx ; *
  2907 0000500B C3                  <1> 	retn
  2908                              <1> 
  2909                              <1> amb_26:	; set maximum free memory aperture (free memory block size) 
  2910 0000500C 89DA                <1> 	mov	edx, ebx ; current address
  2911 0000500E 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL ; MAT beginning address
  2912                              <1> 	; 02/04/2016 
  2913 00005014 C1E203              <1> 	shl	edx, 3 ; MAT byte offset * 8 = page number base
  2914 00005017 01CA                <1> 	add	edx, ecx ; current page number (ecx =  0 to 31)
  2915                              <1> 	;
  2916 00005019 A1[8C2C0100]        <1> 	mov	eax, [mem_aperture]
  2917 0000501E 21C0                <1> 	and	eax, eax
  2918 00005020 7424                <1>         jz      short amb_27
  2919 00005022 C705[8C2C0100]0000- <1>         mov     dword [mem_aperture], 0
  2919 0000502A 0000                <1>
  2920 0000502C 3B05[902C0100]      <1> 	cmp	eax, [mem_max_aperture]
  2921 00005032 7612                <1> 	jna	short amb_27
  2922 00005034 A3[902C0100]        <1> 	mov	[mem_max_aperture], eax
  2923                              <1> 	;
  2924 00005039 89D0                <1> 	mov	eax, edx
  2925 0000503B 2B05[902C0100]      <1> 	sub	eax, [mem_max_aperture] ; the last aperture size in pages
  2926                              <1> 	; EAX = Beginning page number of the max. aperture 
  2927 00005041 A3[982C0100]        <1> 	mov	[mem_max_pg_pos], eax
  2928                              <1> amb_27: 
  2929 00005046 42                  <1> 	inc	edx	
  2930 00005047 8915[942C0100]      <1> 	mov	[mem_pg_pos], edx ; next page
  2931                              <1> 
  2932 0000504D A1[842C0100]        <1> 	mov	eax, [mem_ipg_count] ; initial (reset) value of page count
  2933 00005052 A3[882C0100]        <1> 	mov	[mem_pg_count], eax
  2934                              <1> 
  2935 00005057 C3                  <1> 	retn
  2936                              <1> 
  2937                              <1> deallocate_memory_block:
  2938                              <1> 	; 03/04/2016
  2939                              <1> 	; 14/03/2016 (TRDOS 386 = TRDOS v2.0)
  2940                              <1> 	; Deallocating contiguous memory pages (in the kernel's memory space)
  2941                              <1> 	;
  2942                              <1> 	; INPUT -> 
  2943                              <1> 	;	EAX = Beginning address (physical)
  2944                              <1> 	;	ECX = Number of bytes to be deallocated
  2945                              <1> 	;
  2946                              <1> 	; OUTPUT ->
  2947                              <1> 	;	Mememory Allocation Table bits will be updated
  2948                              <1> 	;	[free_pages] will be changed (increased)
  2949                              <1> 	;
  2950                              <1> 	; (Modified Registers -> EAX, ECX)
  2951                              <1> 	;
  2952                              <1> 	; PURPOSE: Unloading/Freeing a file -or an allocated memory block- 
  2953                              <1> 	; at memory after copying, running, saving, reading, writing etc.
  2954                              <1> 	;
  2955                              <1> 
  2956 00005058 52                  <1> 	push	edx ; *
  2957 00005059 53                  <1> 	push	ebx ; **
  2958                              <1> 
  2959 0000505A C1E80C              <1> 	shr	eax, PAGE_SHIFT	     ; 12
  2960 0000505D C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  2961                              <1> 
  2962                              <1> 	; EAX = Beginning page number
  2963                              <1> 	; ECX = Number of contiguous pages to be deallocated
  2964                              <1> damb_0:
  2965                              <1> 	; deallocate contiguous memory pages (via memory allocation table bits)
  2966 00005060 89C2                <1> 	mov	edx, eax
  2967 00005062 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2968                              <1> 				     ; (1 allocation bit = 1 page)
  2969                              <1> 				     ; (1 allocation bytes = 8 pages)
  2970 00005065 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2971                              <1> 				     ; (to get 32 bit position)	
  2972 00005068 3B15[D41F0100]      <1> 	cmp	edx, [next_page] ; next free page
  2973 0000506E 7306                <1> 	jnb	short damb_1
  2974 00005070 8915[D41F0100]      <1> 	mov	[next_page], edx
  2975                              <1> damb_1:
  2976 00005076 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  2977 0000507B 01D3                <1> 	add	ebx, edx
  2978 0000507D 83E01F              <1> 	and	eax, 1Fh ; 31
  2979                              <1> 
  2980                              <1> 	; 03/04/2016
  2981 00005080 BA20000000          <1> 	mov	edx, 32
  2982 00005085 28C2                <1> 	sub	dl, al
  2983 00005087 39CA                <1> 	cmp	edx, ecx
  2984 00005089 7602                <1> 	jna	short damb_2
  2985 0000508B 89CA                <1> 	mov	edx, ecx
  2986                              <1> damb_2:
  2987 0000508D 29D1                <1> 	sub	ecx, edx
  2988 0000508F 51                  <1> 	push	ecx ; ***
  2989 00005090 89D1                <1> 	mov	ecx, edx
  2990                              <1> damb_3:		
  2991 00005092 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
  2992                              <1> 				     ; set relevant bit to 1.
  2993                              <1> 				     ; set CF to the previous bit value	
  2994 00005095 FF05[D01F0100]      <1> 	inc     dword [free_pages]   ; 1 page has been deallocated (X = X+1) 
  2995 0000509B 49                  <1> 	dec	ecx
  2996 0000509C 7404                <1> 	jz	short damb_4
  2997 0000509E FEC0                <1> 	inc	al
  2998 000050A0 EBF0                <1> 	jmp	short damb_3
  2999                              <1> damb_4:	
  3000 000050A2 59                  <1> 	pop	ecx ; ***
  3001 000050A3 21C9                <1> 	and	ecx, ecx ; 0 ?
  3002 000050A5 741E                <1> 	jz	short damb_7
  3003                              <1> 	; 03/04/2016
  3004 000050A7 B020                <1> 	mov	al, 32
  3005                              <1> damb_5:
  3006 000050A9 83C304              <1> 	add	ebx, 4
  3007 000050AC 39C1                <1> 	cmp	ecx, eax ; 32
  3008 000050AE 7305                <1> 	jnb	short damb_6
  3009                              <1> 	; ECX < 32
  3010 000050B0 28C0                <1> 	sub	al, al ; 0
  3011 000050B2 50                  <1> 	push	eax ; 0 ***
  3012 000050B3 EBDD                <1> 	jmp	short damb_3
  3013                              <1> damb_6:
  3014 000050B5 0105[D01F0100]      <1> 	add	[free_pages], eax ; [free_pages] = [free_pages] + 32
  3015 000050BB C703FFFFFFFF        <1> 	mov	dword [ebx], 0FFFFFFFFh ; set 32 bits
  3016 000050C1 29C1                <1> 	sub	ecx, eax ; 32
  3017 000050C3 75E4                <1> 	jnz	short damb_5
  3018                              <1> damb_7:
  3019 000050C5 5B                  <1> 	pop	ebx ; **
  3020 000050C6 5A                  <1> 	pop	edx ; *
  3021 000050C7 C3                  <1> 	retn
  3022                              <1> 
  3023                              <1> direct_memory_access:
  3024                              <1> 	; 16/07/2016
  3025                              <1> 	; 12/07/2016 (TRDOS 386 = TRDOS v2.0)
  3026                              <1> 	; This processure will be called to map
  3027                              <1> 	; user's (ring 3) page tables to access phsical
  3028                              <1> 	; (flat/linear) memory addresses, directy (without
  3029                              <1> 	;  kernel's data transfer functions).
  3030                              <1> 	; 
  3031                              <1> 	; Purpose: Video memory access and shared memory access.
  3032                              <1> 	;
  3033                              <1> 	; INPUT -> 
  3034                              <1> 	;	EAX = Beginning address (physical).
  3035                              <1> 	;	ECX = Number of contiguous pages to be mapped.
  3036                              <1> 	; OUTPUT ->
  3037                              <1> 	;	User's page directory and pages tables
  3038                              <1> 	;	will be updated.
  3039                              <1> 	;	
  3040                              <1> 	;	If an old page table entry has valid page address, 
  3041                              <1> 	;	that page will be deallocated just before PTE will
  3042                              <1> 	;	be changed for direct (1 to 1) memory page access.
  3043                              <1> 	;
  3044                              <1> 	;	If old PTE value points to a swapped page,
  3045                              <1>         ;       that page (block) will be unlinked on swap disk. 
  3046                              <1> 	;
  3047                              <1> 	;	Newly allocated pages (except page tables) will not
  3048                              <1> 	;	be applied to Memory Allocation Table.
  3049                              <1> 	;	AVL bit 1 (PTE bit 10) of page table entry will be
  3050                              <1> 	;	used to indicate shared (direct) memory page; then,
  3051                              <1> 	;	this page will not be deallocated later during
  3052                              <1> 	;	process termination. (Memory Allocation Table and
  3053                              <1> 	;	free memory count will not be affected.
  3054                              <1> 	;	(Except deallocating page table's itself.)
  3055                              <1> 	;	
  3056                              <1> 	;      CF = 1 -> error (EAX = error code)
  3057                              <1> 	;      CF = 0 -> success (EAX = beginning address)
  3058                              <1> 	;
  3059                              <1> 	;; (Modified Registers -> none)
  3060                              <1> 	; Modified registers: ebp, edx, ecx, ebx, esi, edi	
  3061                              <1> 	;
  3062                              <1> 
  3063                              <1> 	;push	ebp
  3064                              <1> 	;push	ebx
  3065                              <1> 	;push	ecx
  3066                              <1> 	;push	edx
  3067 000050C8 662500F0            <1> 	and	ax, PTE_A_CLEAR ; clear page offset
  3068 000050CC 50                  <1> 	push	eax
  3069 000050CD 89C5                <1> 	mov	ebp, eax
  3070                              <1> dmem_acc_0: 
  3071 000050CF 89C3                <1> 	mov	ebx, eax
  3072 000050D1 81C300004000        <1> 	add	ebx, CORE
  3073 000050D7 A1[01310100]        <1> 	mov	eax, [u.pgdir] ; page dir address (physical)
  3074 000050DC E820F6FFFF          <1> 	call	get_pte
  3075                              <1> 		; EDX = Page table entry address (if CF=0)
  3076                              <1> 	        ;       Page directory entry address (if CF=1)
  3077                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  3078                              <1> 		; EAX = Page table entry value (page address)
  3079                              <1> 		;	CF = 1 -> PDE not present or invalid ? 	
  3080 000050E1 7324                <1> 	jnc	short dmem_acc_1
  3081                              <1> 	;
  3082 000050E3 E8FEF4FFFF          <1> 	call	allocate_page
  3083 000050E8 0F82A1000000        <1>         jc      dmem_acc_7  ; 'insufficient memory' error
  3084                              <1> 	;
  3085 000050EE E86DF5FFFF          <1> 	call 	clear_page
  3086                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  3087 000050F3 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  3088                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  3089                              <1> 			   ; (user, writable, present page)	
  3090 000050F5 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  3091 000050F7 A1[01310100]        <1> 	mov	eax, [u.pgdir]	
  3092 000050FC E800F6FFFF          <1> 	call	get_pte
  3093 00005101 0F8288000000        <1>         jc      dmem_acc_7 ; 'insufficient memory' error
  3094                              <1> dmem_acc_1:
  3095                              <1> 	; EAX = PTE value, EDX = PTE address
  3096 00005107 A801                <1> 	test 	al, PTE_A_PRESENT
  3097 00005109 750D                <1> 	jnz	short dmem_acc_2
  3098 0000510B 09C0                <1> 	or	eax, eax
  3099 0000510D 7468                <1> 	jz	short dmem_acc_6   ; Change PTE
  3100 0000510F D1E8                <1> 	shr	eax, 1		; swap disk block (8 sectors) address
  3101                              <1> 	; unlink swap disk block
  3102 00005111 E858FBFFFF          <1> 	call	unlink_swap_block
  3103 00005116 EB5F                <1> 	jmp	short dmem_acc_6
  3104                              <1> 
  3105                              <1> dmem_acc_2:
  3106 00005118 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3107                              <1> 				  ; (must be 1)
  3108 0000511A 7550                <1> 	jnz	short dmem_acc_4
  3109                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3110 0000511C 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3111                              <1> 				   ; as child's page ?
  3112 00005120 7455                <1> 	jz	short dmem_acc_5 ; Change PTE but don't deallocate the page!
  3113                              <1> 
  3114                              <1> 	;push	edi
  3115                              <1> 	;push	esi
  3116                              <1> 
  3117 00005122 51                  <1> 	push	ecx
  3118                              <1> 	;push	ebx
  3119 00005123 8B1D[05310100]      <1> 	mov	ebx, [u.ppgdir] ; parent's page dir address (physical)
  3120                              <1> 	
  3121                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3122 00005129 89EF                <1> 	mov	edi, ebp
  3123 0000512B C1EF16              <1> 	shr	edi, PAGE_D_SHIFT ; 22
  3124                              <1> 	; EDI = page directory entry index (0-1023)
  3125 0000512E 89EE                <1> 	mov	esi, ebp
  3126 00005130 C1EE0C              <1> 	shr	esi, PAGE_SHIFT ; 12	
  3127 00005133 81E6FF030000        <1> 	and	esi, PTE_MASK
  3128                              <1> 	; ESI = page table entry index (0-1023)
  3129                              <1> 
  3130 00005139 66C1E702            <1> 	shl	di, 2 ; * 4
  3131 0000513D 01FB                <1> 	add	ebx, edi ; PDE offset (for the parent)
  3132 0000513F 8B0F                <1> 	mov	ecx, [edi]
  3133 00005141 F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
  3134 00005144 7425                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3135 00005146 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3136 0000514B 66C1E602            <1> 	shl	si, 2 ; *4 
  3137 0000514F 01CE                <1> 	add	esi, ecx ; PTE offset (for the parent)
  3138 00005151 8B1E                <1> 	mov	ebx, [esi]
  3139 00005153 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3140 00005156 7413                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3141 00005158 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3142 0000515C 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3143 00005161 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3144 00005163 7506                <1> 	jne	short dmem_acc_3	; not same page
  3145                              <1> 				; deallocate the child's page
  3146 00005165 800E02              <1>         or      byte [esi], PTE_A_WRITE ; convert to writable page (parent)
  3147                              <1> 	;pop	ebx
  3148 00005168 59                  <1> 	pop	ecx
  3149 00005169 EB0C                <1> 	jmp	short dmem_acc_5
  3150                              <1> dmem_acc_3:
  3151                              <1> 	;pop	ebx
  3152 0000516B 59                  <1> 	pop	ecx
  3153                              <1> dmem_acc_4:	
  3154 0000516C 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
  3155 00005170 7505                <1> 	jnz	short dmem_acc_5   ; AVL bit 1 = 1, do not deallocate this page!
  3156                              <1> 	;
  3157                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3158 00005172 E84DF6FFFF          <1> 	call	deallocate_page
  3159                              <1> dmem_acc_5:
  3160                              <1> 	;pop	esi
  3161                              <1> 	;pop	edi
  3162                              <1> dmem_acc_6:
  3163 00005177 89E8                <1> 	mov	eax, ebp ; physical page (offset=0) address
  3164                              <1> 	; EAX = memory page address
  3165                              <1> 	; EDX = PTE entry address (physical)
  3166 00005179 660D0704            <1> 	or	ax, PTE_A_PRESENT+PTE_A_USER+PTE_A_WRITE+PTE_SHARED
  3167                              <1> 			; present flag, bit 0 = 1
  3168                              <1> 			; user flag, bit 2 = 1	
  3169                              <1> 			; writable flag, bit 1 = 1
  3170                              <1> 			; direct memory access flag, bit 10 = 1
  3171                              <1> 			; (This page must not be deallocated!)
  3172 0000517D 8902                <1> 	mov	[edx], eax  ; Update PTE value
  3173 0000517F 49                  <1> 	dec	ecx ; remain count of contiguous pages
  3174 00005180 7414                <1> 	jz	short dmem_acc_8
  3175 00005182 81C500100000        <1> 	add	ebp, PAGE_SIZE ; next virtual (=pysical) page address
  3176 00005188 89E8                <1> 	mov	eax, ebp
  3177 0000518A E940FFFFFF          <1>         jmp     dmem_acc_0
  3178                              <1> dmem_acc_7:  ; ERROR ! 
  3179 0000518F C7042401000000      <1> 	mov	dword [esp], ERR_MINOR_IM 
  3180                              <1> 		; Insufficient memory (minor) error!
  3181                              <1> 		; Major error = 0 (No protection fault)	
  3182                              <1> 	; cf = 1
  3183                              <1> dmem_acc_8:
  3184 00005196 58                  <1> 	pop	eax
  3185                              <1> 	;pop	edx
  3186                              <1> 	;pop	ecx
  3187                              <1> 	;pop	ebx
  3188                              <1> 	;pop	ebp
  3189 00005197 C3                  <1> 	retn
  3190                              <1> 
  3191                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
  3192                              <1> 
  3193                              <1> ;; Data:
  3194                              <1> 
  3195                              <1> ; 09/03/2015
  3196                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
  3197                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
  3198                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  3199                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  3200                              <1> ;swpd_next:  dd 0 ; next free page block
  3201                              <1> ;swpd_last:  dd 0 ; last swap page block		 		
  1915                                  %include 'timer.s'   ; 17/01/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - timer.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ;
    15                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
    16                              <1> ; ****************************************************************************
    17                              <1> 
    18                              <1> ; TRDOS 386  (TRDOS v2.0) Kernel - TIMER & REAL TIME CLOCK (BIOS) FUNCTIONS
    19                              <1> 
    20                              <1> ; IBM PC-AT BIOS Source Code ('BIOS2.ASM')
    21                              <1> ; TITLE BIOS2 ---- 06/10/85 BIOS INTERRUPT ROUTINES
    22                              <1> 
    23                              <1> ;
    24                              <1> ; ///////// TIMER (& REAL TIME CLOCK) FUNCTIONS ///////////////
    25                              <1> 
    26                              <1> int1Ah:
    27                              <1> 	; 29/01/2016
    28                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
    29 00005198 9C                  <1> 	pushfd
    30 00005199 0E                  <1> 	push 	cs
    31 0000519A E801000000          <1> 	call 	TIME_OF_DAY_1
    32 0000519F C3                  <1> 	retn
    33                              <1> 
    34                              <1> ;--- INT  1A H -- (TIME OF DAY) -------------------------------------------------
    35                              <1> ;       THIS BIOS ROUTINE ALLOWS THE CLOCKS TO BE SET OR READ			:
    36                              <1> ;										:
    37                              <1> ; PARAMETERS:									:
    38                              <1> ;     (AH) = 00H  READ THE CURRENT SETTING AND RETURN WITH,			:
    39                              <1> ;                      (CX) = HIGH PORTION OF COUNT				:
    40                              <1> ;                      (DX) = LOW PORTION OF COUNT				:
    41                              <1> ;                      (AL) = 0 TIMER HAS NOT PASSED 24 HOURS SINCE LAST READ	:
    42                              <1> ;                             1 IF ON ANOTHER DAY. (RESET TO ZERO AFTER READ)	:
    43                              <1> ;										:
    44                              <1> ;     (AH) = 01H  SET THE CURRENT CLOCK USING,					:
    45                              <1> ;		     (CX) = HIGH PORTION OF COUNT				:
    46                              <1> ;		     (DX) = LOW PORTION OF COUNT.				:
    47                              <1> ;										:
    48                              <1> ;               NOTE: COUNTS OCCUR AT THE RATE OF 1193180/65536 COUNTS/SECOND	:
    49                              <1> ;                            (OR ABOUT 18.2 PER SECOND -- SEE EQUATES)		:
    50                              <1> ;										:
    51                              <1> ;     (AH) = 02H  READ THE REAL TIME CLOCK AND RETURN WITH,			:
    52                              <1> ;                      (CH) = HOURS IN BCD (00-23)				:
    53                              <1> ;                      (CL) = MINUTES IN BCD (00-59)				:
    54                              <1> ;                      (DH) = SECONDS IN BCD (00-59)				:
    55                              <1> ;                      (DL) = DAYLIGHT SAVINGS ENABLE (00-01)			:
    56                              <1> ;										:
    57                              <1> ;     (AH) = 03H  SET THE REAL TIME CLOCK USING,				:
    58                              <1> ;                     (CH) = HOURS IN BCD (00-23)				:
    59                              <1> ;                     (CL) = MINUTES IN BCD (00-59)				:
    60                              <1> ;                     (DH) = SECONDS IN BCD (00-59)				:
    61                              <1> ;                     (DL) = 01 IF DAYLIGHT SAVINGS ENABLE OPTION, ELSE 00.	:
    62                              <1> ;										:
    63                              <1> ;             NOTE: (DL) = 00 IF DAYLIGHT SAVINGS TIME ENABLE IS NOT ENABLED.	:
    64                              <1> ;                   (DL) = 01 ENABLES TWO SPECIAL UPDATES THE LAST SUNDAY IN	:
    65                              <1> ;	           APRIL   (1:59:59 --> 3:00:00 AM) AND THE LAST SUNDAY IN	:
    66                              <1> ;                   OCTOBER (1:59:59 --> 1:00:00 AM) THE FIRST TIME.		:
    67                              <1> ;										:
    68                              <1> ;     (AH) = 04H  READ THE DATE FROM THE REAL TIME CLOCK AND RETURN WITH,	:
    69                              <1> ;                      (CH) = CENTURY IN BCD (19 OR 20)				:
    70                              <1> ;                      (CL) = YEAR IN BCD (00-99)				:
    71                              <1> ;                      (DH) = MONTH IN BCD (01-12)				:
    72                              <1> ;                      (DL) = DAY IN BCD (01-31).				:
    73                              <1> ;										:
    74                              <1> ;     (AH) = 05H  SET THE DATE INTO THE REAL TIME CLOCK USING,			:
    75                              <1> ;                     (CH) = CENTURY IN BCD (19 OR 20)				:
    76                              <1> ;                     (CL) = YEAR IN BCD (00-99)				:
    77                              <1> ;                     (DH) = MONTH IN BCD (01-12)				:
    78                              <1> ;                     (DL) = DAY IN BCD (01-31).				:
    79                              <1> ;										:
    80                              <1> ;     (AH) = 06H  SET THE ALARM TO INTERRUPT AT SPECIFIED TIME,			:
    81                              <1> ;                     (CH) = HOURS IN BCD (00-23 (OR FFH))			:
    82                              <1> ;                     (CL) = MINUTES IN BCD (00-59 (OR FFH))			:
    83                              <1> ;                     (DH) = SECONDS IN BCD (00-59 (OR FFH))			:
    84                              <1> ;										:
    85                              <1> ;     (AH) = 07H  RESET THE ALARM INTERRUPT FUNCTION.				:
    86                              <1> ;										:
    87                              <1> ; NOTES: FOR ALL RETURNS CY= 0 FOR SUCCESSFUL OPERATION.			:
    88                              <1> ;        FOR (AH)= 2, 4, 6 - CARRY FLAG SET IF REAL TIME CLOCK NOT OPERATING.	:
    89                              <1> ;        FOR (AH)= 6 - CARRY FLAG SET IF ALARM ALREADY ENABLED. 		:
    90                              <1> ;        FOR THE ALARM FUNCTION (AH = 6) THE USER MUST SUPPLY A ROUTINE AND	:
    91                              <1> ;         INTERCEPT THE CORRECT ADDRESS IN THE VECTOR TABLE FOR INTERRUPT 4AH.	:
    92                              <1> ;         USE 0FFH FOR ANY "DO NOT CARE" POSITION FOR INTERVAL INTERRUPTS.	:
    93                              <1> ;        INTERRUPTS ARE DISABLED DURING DATA MODIFICATION. 			:
    94                              <1> ;        AH & AL ARE RETURNED MODIFIED AND NOT DEFINED EXCEPT WHERE INDICATED.	:
    95                              <1> ;--------------------------------------------------------------------------------
    96                              <1> 
    97                              <1> ; 29/05/2016
    98                              <1> ; 29/01/2016
    99                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   100                              <1> 
   101                              <1> ; 29/05/2016
   102                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   103                              <1> int35h:  ; Date/Time functions
   104                              <1> 
   105                              <1> TIME_OF_DAY_1:
   106 000051A0 FB                  <1> 	sti				; INTERRUPTS BACK ON
   107                              <1> 	; 29/05/2016
   108 000051A1 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   109                              <1> 	;
   110 000051A6 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
   111 000051A9 F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
   112                              <1> 	; (*) jc short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
   113 000051AA 721C                <1> 	jc	short _TIME_9 ; 29/05/2016
   114                              <1> 
   115 000051AC 1E                  <1> 	push	ds
   116 000051AD 56                  <1> 	push	esi
   117 000051AE 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
   118 000051B2 8EDE                <1> 	mov	ds, si
   119 000051B4 C0E402              <1> 	shl	ah, 2			; convert function to dword offset
   120 000051B7 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
   121 000051BA FA                  <1> 	cli				; NO INTERRUPTS DURING TIME FUNCTIONS
   122 000051BB FF96[CE510000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
   123                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
   124 000051C1 FB                  <1> 	sti				; INTERRUPTS BACK ON
   125 000051C2 B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
   126 000051C4 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
   127 000051C5 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
   128                              <1> ;TIME_9:
   129                              <1> 					; RETURN WITH CY= 0 IF NO ERROR
   130                              <1> 	; (*) 29/05/2016
   131                              <1> 	; (*) retf 4 ; skip eflags on stack
   132 000051C6 7305                <1> 	jnc	short _TIME_10
   133                              <1> _TIME_9:
   134                              <1> 	; 29/05/2016 -set carry flag on stack-
   135                              <1> 	; [esp] = EIP
   136                              <1> 	; [esp+4] = CS
   137                              <1> 	; [esp+8] = E-FLAGS
   138 000051C8 804C240801          <1> 	or	byte [esp+8], 1	 ; set carry bit of eflags register
   139                              <1> 	; [esp+12] = ESP (user)
   140                              <1> 	; [esp+16] = SS (User)
   141                              <1> _TIME_10:
   142 000051CD CF                  <1> 	iretd
   143                              <1> 	
   144                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
   145                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   146                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   147                              <1> 	; // RETF instruction:
   148                              <1> 	;
   149                              <1> 	; IF OperandMode=32 THEN
   150                              <1>  	;    Load CS:EIP from stack;
   151                              <1>  	;    Set CS RPL to CPL;
   152                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
   153                              <1>  	;    Load SS:eSP from stack;
   154                              <1>  	; ELSE (* OperandMode=16 *)
   155                              <1>  	;    Load CS:IP from stack;
   156                              <1>  	;    Set CS RPL to CPL;
   157                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
   158                              <1> 	;    Load SS:eSP from stack;
   159                              <1>  	; FI;
   160                              <1> 	;
   161                              <1> 	; //					
   162                              <1> 					; ROUTINE VECTOR TABLE (AH)=
   163                              <1> RTC_TB:
   164 000051CE [EE510000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
   165 000051D2 [01520000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
   166 000051D6 [0F520000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
   167 000051DA [3E520000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
   168 000051DE [80520000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
   169 000051E2 [AD520000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
   170 000051E6 [FA520000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
   171 000051EA [4D530000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
   172                              <1> 
   173                              <1> RTC_TBE	equ	$
   174                              <1> 
   175                              <1> RTC_00:				; READ TIME COUNT
   176 000051EE A0[4C200100]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
   177 000051F3 C605[4C200100]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
   178 000051FA 8B0D[48200100]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
   179 00005200 C3                  <1> 	retn
   180                              <1> 
   181                              <1> RTC_10:				; SET TIME COUNT
   182 00005201 890D[48200100]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
   183 00005207 C605[4C200100]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
   184 0000520E C3                  <1> 	retn				; RETURN WITH NO CARRY
   185                              <1> 
   186                              <1> RTC_20:				; GET RTC TIME
   187 0000520F E8EB010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   188 00005214 7227                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
   189                              <1> 
   190 00005216 B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
   191 00005218 E8FD010000          <1> 	call	CMOS_READ		; GET SECONDS
   192 0000521D 88C6                <1> 	mov	dh, al			; SAVE
   193 0000521F B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   194 00005221 E8F4010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
   195 00005226 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
   196 00005228 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
   197 0000522A B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
   198 0000522C E8E9010000          <1> 	call	CMOS_READ		; GET MINUTES
   199 00005231 88C1                <1> 	mov	cl, al			; SAVE
   200 00005233 B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
   201 00005235 E8E0010000          <1> 	call	CMOS_READ		; GET HOURS
   202 0000523A 88C5                <1> 	mov	ch, al			; SAVE
   203 0000523C F8                  <1> 	clc				; SET CY= 0
   204                              <1> RTC_29:
   205 0000523D C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
   206                              <1> 
   207                              <1> RTC_30:				; SET RTC TIME
   208 0000523E E8BC010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   209 00005243 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
   210 00005245 E817010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
   211                              <1> RTC_35:
   212 0000524A 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
   213 0000524C B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
   214 0000524E E8E0010000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
   215 00005253 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
   216 00005255 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
   217 00005257 E8D7010000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
   218 0000525C 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
   219 0000525E B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
   220 00005260 E8CE010000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
   221                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   222                              <1> 	;mov	ah, al
   223 00005265 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   224 00005269 E8AC010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
   225 0000526E 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
   226 00005270 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
   227 00005272 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
   228 00005275 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
   229 00005277 86E0                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
   230 00005279 E8B5010000          <1> 	call	CMOS_WRITE		; SET NEW ALARM SITS
   231 0000527E F8                  <1> 	clc				; SET CY= 0
   232 0000527F C3                  <1> 	retn				; RETURN WITH CY= 0
   233                              <1> 
   234                              <1> RTC_40:				; GET RTC DATE
   235 00005280 E87A010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   236 00005285 7225                <1> 	jc	short RTC_49		; EXIT IF ERROR (CY= 1)
   237                              <1> 
   238 00005287 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
   239 00005289 E88C010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
   240 0000528E 88C2                <1> 	mov	dl, al			; SAVE
   241 00005290 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
   242 00005292 E883010000          <1> 	call	CMOS_READ		; READ MONTH
   243 00005297 88C6                <1> 	mov	dh, al			; SAVE
   244 00005299 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
   245 0000529B E87A010000          <1> 	call	CMOS_READ		; READ YEAR
   246 000052A0 88C1                <1> 	mov	cl, al			; SAVE
   247 000052A2 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
   248 000052A4 E871010000          <1> 	call	CMOS_READ		; GET CENTURY BYTE
   249 000052A9 88C5                <1> 	mov	ch, al			; SAVE
   250 000052AB F8                  <1> 	clc				; SET CY=0
   251                              <1> RTC_49:
   252 000052AC C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAG
   253                              <1> 
   254                              <1> RTC_50:				; SET RTC DATE
   255 000052AD E84D010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   256 000052B2 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
   257 000052B4 E8A8000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   258                              <1> RTC_55:
   259 000052B9 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
   260 000052BD E871010000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
   261 000052C2 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
   262 000052C4 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
   263 000052C6 E868010000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
   264 000052CB 88F4                <1> 	mov	ah, dh			; GET MONTH
   265 000052CD B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
   266 000052CF E85F010000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
   267 000052D4 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
   268 000052D6 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
   269 000052D8 E856010000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
   270 000052DD 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
   271 000052DF B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
   272 000052E1 E84D010000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
   273                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   274                              <1> 	;mov	ah, al
   275 000052E6 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   276 000052EA E82B010000          <1> 	call	CMOS_READ		; READ WIRRENT SETTINGS
   277 000052EF 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
   278 000052F1 86E0                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
   279 000052F3 E83B010000          <1> 	call	CMOS_WRITE		; AND START CLOCK UPDATING
   280 000052F8 F8                  <1> 	clc				; SET CY= 0
   281 000052F9 C3                  <1> 	retn				; RETURN CY=0
   282                              <1> 
   283                              <1> RTC_60:				; SET RTC ALARM
   284 000052FA B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
   285 000052FC E819010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   286 00005301 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
   287 00005303 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
   288 00005304 7542                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
   289 00005306 E8F4000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   290 0000530B 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
   291 0000530D E84F000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   292                              <1> RTC_65:	
   293 00005312 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
   294 00005314 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
   295 00005316 E818010000          <1> 	call	CMOS_WRITE		; INSERT SECONDS
   296 0000531B 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
   297 0000531D B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
   298 0000531F E80F010000          <1> 	call	CMOS_WRITE		; INSERT MINUTES
   299 00005324 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
   300 00005326 B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
   301 00005328 E806010000          <1> 	call	CMOS_WRITE		; INSERT HOURS
   302 0000532D E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
   303 0000532F 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
   304 00005331 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
   305                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   306                              <1> 	;mov	ah, al
   307 00005333 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   308 00005337 E8DE000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
   309 0000533C 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
   310 0000533E 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
   311 00005340 86E0                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
   312 00005342 E8EC000000          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
   313 00005347 F8                  <1> 	clc				; SET CY= 0
   314                              <1> RTC_69:
   315 00005348 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
   316 0000534C C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
   317                              <1> 
   318                              <1> RTC_70:				; RESET ALARM
   319                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   320                              <1> 	;mov	ah, al
   321 0000534D 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
   322 00005351 E8C4000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   323 00005356 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
   324 00005358 86E0                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
   325 0000535A E8D4000000          <1> 	call	CMOS_WRITE		; RESTORE NEW VALUE
   326 0000535F F8                  <1> 	clc				; SET CY= 0
   327 00005360 C3                  <1> 	retn				; RETURN WITH NO CARRY
   328                              <1> 
   329                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
   330                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
   331                              <1> 	;mov	ah, 26h
   332 00005361 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
   333 00005365 E8C9000000          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
   334                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
   335                              <1> 	;mov	ah, 82h
   336 0000536A 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
   337 0000536E E8C0000000          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
   338 00005373 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
   339 00005375 E8A0000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
   340 0000537A B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
   341 0000537C E899000000          <1> 	call	CMOS_READ		; READ REGISTER D TO INITIALIZE
   342 00005381 C3                  <1> 	retn
   343                              <1> 
   344                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   345                              <1> 
   346                              <1> ;--- HARDWARE INT  70 H -- ( IRQ LEVEL  8) --------------------------------------
   347                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
   348                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
   349                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
   350                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
   351                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
   352                              <1> ;										:
   353                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
   354                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
   355                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
   356                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
   357                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
   358                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
   359                              <1> ;--------------------------------------------------------------------------------
   360                              <1> 
   361                              <1> RTC_INT:			; ALARM INTERRUPT
   362 00005382 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
   363 00005383 50                  <1> 	push	eax			; SAVE REGISTERS
   364 00005384 57                  <1> 	push	edi
   365                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
   366 00005385 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
   367 00005389 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
   368 0000538B 90                  <1> 	nop				; I/O DELAY
   369 0000538C EB00                <1> 	jmp	short $+2
   370 0000538E E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
   371 00005390 A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
   372 00005392 745D                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
   373                              <1> 
   374 00005394 86E0                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
   375 00005396 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
   376 00005398 90                  <1> 	nop				; I/O DELAY
   377 00005399 EB00                <1> 	jmp	short $+2	
   378 0000539B E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
   379 0000539D 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
   380 0000539F A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
   381 000053A1 743B                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
   382                              <1> 
   383                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
   384                              <1> 
   385 000053A3 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
   386 000053A7 8EDF                <1> 	mov	ds, di
   387                              <1> 	
   388 000053A9 812D[40200100]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
   388 000053B1 0000                <1>
   389 000053B3 7329                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
   390                              <1> 
   391                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
   392                              <1> 
   393 000053B5 6650                <1> 	push	ax			; SAVE INTERRUPT FLAG MASK
   394 000053B7 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
   395 000053BB E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
   396 000053BD 90                  <1> 	nop				; I/O DELAY
   397 000053BE EB00                <1> 	jmp	short $+2
   398 000053C0 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
   399 000053C2 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
   400 000053C4 86C4                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
   401 000053C6 E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
   402 000053C8 86C4                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
   403 000053CA E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
   404 000053CC C605[44200100]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
   405 000053D3 8B3D[45200100]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
   406 000053D9 C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
   407 000053DC 6658                <1> 	pop	ax			; GET INTERRUPT SOURCE BACK
   408                              <1> RTC_I_5:
   409 000053DE A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
   410 000053E0 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
   411                              <1> 
   412 000053E2 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   413 000053E4 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   414 000053E6 FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
   415 000053E7 52                  <1> 	push	edx
   416 000053E8 E8F4870000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
   417 000053ED 5A                  <1> 	pop	edx
   418 000053EE FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
   419                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
   420 000053EF EB94                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
   421                              <1> 
   422                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
   423 000053F1 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   424 000053F3 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   425 000053F5 B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
   426 000053F7 E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
   427 000053F9 E620                <1> 	out	INTA00,	al		; TO 8259 - 1
   428 000053FB 5F                  <1> 	pop	edi			; RESTORE REGISTERS
   429 000053FC 58                  <1> 	pop	eax
   430 000053FD 1F                  <1> 	pop	ds
   431 000053FE CF                  <1> 	iret				; END OF INTERRUPT
   432                              <1> 
   433                              <1> 	
   434                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
   435                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   436                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
   437                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
   438 000053FF 51                  <1> 	push	ecx
   439                              <1> 
   440                              <1> 	; 29/05/2016
   441 00005400 B968110000          <1> 	mov	ecx, ((1984+244)*4)/2	; AWARD BIOS 1999, ATIME.ASM		
   442                              <1> 					; 'WAITCPU_CK_UD_STAT'
   443                              <1> 					; (244Us + 1984Us)
   444                              <1> 					; (assume each read takes
   445                              <1> 					;  2 microseconds).
   446                              <1> 	;mov	ecx, 65535		
   447                              <1> 		;mov cx, 800		; SET TIMEOUT LOOP COUNT (= 800)	
   448                              <1> UPD_10:
   449 00005405 B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
   450 00005407 FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
   451 00005408 E80D000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
   452 0000540D A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
   453 0000540F 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
   454 00005411 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
   455 00005412 E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
   456 00005414 31C0                <1> 	xor	eax, eax		; CLEAR RESULTS IF ERROR
   457                              <1> 		; xor ax, ax
   458 00005416 F9                  <1> 	stc				; SET CARRY FOR ERROR
   459                              <1> UPD_90:
   460 00005417 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
   461 00005418 FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
   462 00005419 C3                  <1> 	retn				; RETURN WITH CY FLAG SET
   463                              <1> 
   464                              <1> 
   465                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0) 
   466                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   467                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
   468                              <1> 
   469                              <1> ;--- CMOS_READ -----------------------------------------------------------------
   470                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
   471                              <1> ;									       :
   472                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
   473                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   474                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
   475                              <1> ;									       :
   476                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
   477                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
   478                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   479                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   480                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   481                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
   482                              <1> ;-------------------------------------------------------------------------------
   483                              <1> 
   484                              <1> CMOS_READ:
   485 0000541A 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   486 0000541B D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   487 0000541D F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   488 0000541E D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   489 00005420 FA                  <1> 	cli				; DISABLE INTERRUPTS
   490 00005421 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   491                              <1> 	; 29/05/2016
   492                              <1> 	;nop				; I/O DELAY
   493 00005423 E6EB                <1> 	out	0ebh,al	; NEWIODELAY ; AWARD BIOS 1999, ATIME.ASM
   494                              <1> 	;
   495 00005425 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
   496 00005427 6650                <1> 	push	ax			; SAVE (AH) REGISTER VALUE AND CMOS BYTE
   497                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
   498                              <1> 		     ; ----- 10/06/85 (test4.asm)
   499 00005429 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 	; GET ADDRESS OF DEFAULT LOCATION
   500                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   501 0000542B D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   502 0000542D E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   503 0000542F 6658                <1> 	pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
   504 00005431 9D                  <1> 	popf	
   505 00005432 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
   506                              <1> 
   507                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   508                              <1> 
   509                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
   510                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
   511                              <1> ;									       :
   512                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
   513                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   514                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
   515                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
   516                              <1> ;									       :
   517                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
   518                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
   519                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   520                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   521                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   522                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
   523                              <1> ;-------------------------------------------------------------------------------
   524                              <1> 
   525                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
   526 00005433 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   527 00005434 6650                <1> 	push	ax			; SAVE WORK REGISTER VALUES
   528 00005436 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   529 00005438 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   530 00005439 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   531 0000543B FA                  <1> 	cli				; DISABLE INTERRUPTS
   532 0000543C E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   533 0000543E 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
   534 00005440 E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
   535 00005442 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
   536                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   537 00005444 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   538 00005446 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   539 00005448 90                  <1> 	nop				; I/O DELAY
   540 00005449 E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
   541 0000544B 6658                <1> 	pop	ax			; RESTORE WORK REGISTERS
   542 0000544D 9D                  <1> 	popf
   543 0000544E C3                  <1> 	retn
   544                              <1> 
   545                              <1> ; /// End Of TIMER FUNCTIONS ///
  1916                                  %include 'sysdefs.s' ; 24/01/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYSTEM DEFINITIONS : sysdefs.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    11                              <1> ; sysdefs.inc (14/11/2015)
    12                              <1> ; ****************************************************************************
    13                              <1> 
    14                              <1> ; Retro UNIX 386 v1 Kernel - SYSDEFS.INC
    15                              <1> ; Last Modification: 14/11/2015
    16                              <1> ;
    17                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
    18                              <1> ; (Modified from 
    19                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
    20                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
    21                              <1> ; 	UNIX.ASM (MASM 6.11) --> SYSDEFS.INC (NASM 2.11)
    22                              <1> ; ----------------------------------------------------------------------------
    23                              <1> ;
    24                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
    25                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
    26                              <1> ; <Bell Laboratories (17/3/1972)>
    27                              <1> ; <Preliminary Release of UNIX Implementation Document>
    28                              <1> ;
    29                              <1> ; ****************************************************************************
    30                              <1> 
    31                              <1> nproc 	equ	16  ; number of processes
    32                              <1> nfiles 	equ	50
    33                              <1> ntty	equ     8   ; 8+1 -> 8 (10/05/2013)
    34                              <1> nbuf	equ	4   ; 6 ;; 21/08/2015 - 'namei' buffer problem when nbuf > 4 	
    35                              <1> 		; NOTE: If fd0 super block buffer addres is beyond of the 1st
    36                              <1> 		; 32K, DMA r/w routine or someting else causes a jump to 
    37                              <1> 		; kernel panic routine (in 'alloc' routine, in u5.s)
    38                              <1> 		; because of invalid buffer content (r/w error). 
    39                              <1> 		; When all buffers are set before the end of the 1st 32k,
    40                              <1> 		; there is no problem!? (14/11/2015) 
    41                              <1> 
    42                              <1> ;csgmnt	equ	2000h	; 26/05/2013 (segment of process 1)
    43                              <1> ;core	equ 	0  	    ; 19/04/2013	
    44                              <1> ;ecore	equ	32768 - 64  ; 04/06/2013 (24/05/2013)
    45                              <1> 	; (if total size of argument list and arguments is 128 bytes)
    46                              <1> 	; maximum executable file size = 32768-(64+40+128-6) = 32530 bytes
    47                              <1> 	; maximum stack size = 40 bytes (+6 bytes for 'IRET' at 32570)	
    48                              <1> 	; initial value of user's stack pointer = 32768-64-128-2 = 32574
    49                              <1> 	; 	(sp=32768-args_space-2 at the beginning of execution)
    50                              <1> 	; argument list offset = 32768-64-128 = 32576 (if it is 128 bytes)
    51                              <1> 	; 'u' structure offset (for the '/core' dump file) = 32704
    52                              <1> 	; '/core' dump file size = 32768 bytes
    53                              <1>  
    54                              <1> ; 08/03/2014 
    55                              <1> ;sdsegmnt equ	6C0h  ; 256*16 bytes (swap data segment size for 16 processes)		 	 
    56                              <1> ; 19/04/2013 Retro UNIX 8086 v1 feaure only !
    57                              <1> ;;sdsegmnt equ 	740h  ; swap data segment (for user structures and registers)
    58                              <1> 
    59                              <1> ; 30/08/2013
    60                              <1> time_count equ 4 ; 10 --> 4 01/02/2014
    61                              <1> 
    62                              <1> ; 05/02/2014
    63                              <1> ; process status
    64                              <1> ;SFREE 	equ 0
    65                              <1> ;SRUN	equ 1
    66                              <1> ;SWAIT	equ 2
    67                              <1> ;SZOMB	equ 3
    68                              <1> ;SSLEEP	equ 4 ; Retro UNIX 8086 V1 extension (for sleep and wakeup)
    69                              <1> 
    70                              <1> ; 09/03/2015
    71                              <1> userdata equ 80000h ; user structure data address for current user ; temporary
    72                              <1> swap_queue equ 90000h - 2000h ; swap queue address ; temporary
    73                              <1> swap_alloc_table equ 0D0000h  ;  swap allocation table address ; temporary
    74                              <1> 
    75                              <1> ; 17/09/2015
    76                              <1> ESPACE equ 48 ; [u.usp] (at 'sysent') - [u.sp] value for error return
    77                              <1> 
    78                              <1> ; 20/05/2016
    79                              <1> ; 19/05/2016
    80                              <1> ; 18/05/2016
    81                              <1> ; 29/04/2016 
    82                              <1> ; TRDOS 386 (TRDOS v2.0) system calls - temporary List 
    83                              <1> ; 14/07/2013 - 21/09/2015 (Retro UNIX 8086 & 386 system calls) 
    84                              <1> ; UNIX v1 system calls
    85                              <1> ;_rele	equ 0
    86                              <1> _ver 	equ 0 ; Get TRDOS version (v2.0)
    87                              <1> _exit 	equ 1
    88                              <1> _fork 	equ 2
    89                              <1> _read 	equ 3
    90                              <1> _write	equ 4
    91                              <1> _open	equ 5
    92                              <1> _close 	equ 6
    93                              <1> _wait 	equ 7
    94                              <1> _creat 	equ 8
    95                              <1> _link 	equ 9
    96                              <1> _unlink	equ 10
    97                              <1> _exec	equ 11
    98                              <1> _chdir	equ 12
    99                              <1> _time 	equ 13
   100                              <1> _mkdir 	equ 14
   101                              <1> _chmod	equ 15
   102                              <1> _chown	equ 16
   103                              <1> _break	equ 17
   104                              <1> _stat	equ 18
   105                              <1> _seek	equ 19
   106                              <1> _tell 	equ 20
   107                              <1> _mount	equ 21
   108                              <1> _umount	equ 22
   109                              <1> _setuid	equ 23
   110                              <1> _getuid	equ 24
   111                              <1> _stime	equ 25
   112                              <1> _quit	equ 26	
   113                              <1> _intr	equ 27
   114                              <1> _fstat	equ 28
   115                              <1> _emt 	equ 29
   116                              <1> _mdate 	equ 30
   117                              <1> ;_stty 	equ 31
   118                              <1> _video  equ 31 ; TRDOS 386 Video Functions (16/05/2016)
   119                              <1> ;_gtty	equ 32
   120                              <1> _audio	equ 32 ; TRDOS 386 Video Functions (16/05/2016)
   121                              <1> ;_ilgins equ 33
   122                              <1> _timer	equ 33 ; TRDOS 386 Timer Functions (18/05/2016)
   123                              <1> _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
   124                              <1> _msg	equ 35 ; Retro UNIX 386 v1 feature only !
   125                              <1> _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
   126                              <1> _reserved1 equ 37 ;; TRDOS 386 (19/05/2016)
   127                              <1> _pri 	equ 38 ; change priority - TRDOS 386 (20/05/2016)
   128                              <1> _rele	equ 39 ; TRDOS 386 (19/05/2016)
   129                              <1> 
   130                              <1> %macro sys 1-4
   131                              <1>     ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
   132                              <1>     ; 03/09/2015	
   133                              <1>     ; 13/04/2015
   134                              <1>     ; Retro UNIX 386 v1 system call.		
   135                              <1>     %if %0 >= 2   
   136                              <1>         mov ebx, %2
   137                              <1>         %if %0 >= 3    
   138                              <1>             mov ecx, %3
   139                              <1>             %if %0 = 4
   140                              <1>                mov edx, %4   
   141                              <1>             %endif
   142                              <1>         %endif
   143                              <1>     %endif
   144                              <1>     mov eax, %1
   145                              <1>     ;int 30h
   146                              <1>     int 40h ; TRDOS 386 (TRDOS v2.0)		   
   147                              <1> %endmacro
   148                              <1> 
   149                              <1> ; 13/05/2015 - ERROR CODES
   150                              <1> ERR_FILE_NOT_OPEN  equ 10 ; 'file not open !' error
   151                              <1> ERR_FILE_ACCESS    equ 11 ; 'permission denied !' error
   152                              <1> ; 14/05/2015
   153                              <1> ERR_DIR_ACCESS     equ 11 ; 'permission denied !' error
   154                              <1> ERR_FILE_NOT_FOUND equ 12 ; 'file not found !' error
   155                              <1> ERR_TOO_MANY_FILES equ 13 ; 'too many open files !' error
   156                              <1> ERR_DIR_EXISTS     equ 14 ; 'directory already exists !' error 	
   157                              <1> ; 16/05/2015		
   158                              <1> ERR_DRV_NOT_RDY    equ 15 ; 'drive not ready !' error
   159                              <1> ; 18/05/2015
   160                              <1> ERR_DEV_NOT_RDY    equ 15 ; 'device not ready !' error
   161                              <1> ERR_DEV_ACCESS     equ 11 ; 'permission denied !' error 
   162                              <1> ERR_DEV_NOT_OPEN   equ 10 ; 'device not open !' error	
   163                              <1> ; 07/06/2015
   164                              <1> ERR_FILE_EOF	   equ 16 ; 'end of file !' error
   165                              <1> ERR_DEV_VOL_SIZE   equ 16 ; 'out of volume' error
   166                              <1> ; 09/06/2015
   167                              <1> ERR_DRV_READ	   equ 17 ; 'disk read error !'
   168                              <1> ERR_DRV_WRITE	   equ 18 ; 'disk write error !'
   169                              <1> ; 16/06/2015
   170                              <1> ERR_NOT_DIR	   equ 19 ; 'not a (valid) directory !' error
   171                              <1> ERR_FILE_SIZE	   equ 20 ; 'file size error !'	
   172                              <1> ; 22/06/2015
   173                              <1> ERR_NOT_SUPERUSER  equ 11 ; 'permission denied !' error
   174                              <1> ERR_NOT_OWNER      equ 11 ; 'permission denied !' error
   175                              <1> ERR_NOT_FILE       equ 11 ; 'permission denied !' error	
   176                              <1> ; 23/06/2015
   177                              <1> ERR_FILE_EXISTS    equ 14 ; 'file already exists !' error
   178                              <1> ERR_DRV_NOT_SAME   equ 21 ; 'not same drive !' error
   179                              <1> ERR_DIR_NOT_FOUND  equ 12 ; 'directory not found !' error
   180                              <1> ERR_NOT_EXECUTABLE equ 22 ; 'not executable file !' error
   181                              <1> ; 27/06/2015
   182                              <1> ERR_INV_PARAMETER  equ 23 ; 'invalid parameter !' error
   183                              <1> ERR_INV_DEV_NAME   equ 24 ; 'invalid device name !' error
   184                              <1> ; 29/06/2015
   185                              <1> ERR_TIME_OUT	   equ 25 ; 'time out !' error			
   186                              <1> ERR_DEV_NOT_RESP   equ 25 ; 'device not responding !' error
   187                              <1> ; 18/05/2016
   188                              <1> ERR_MISC	   equ 26 ; miscellaneous/other errors		
   189                              <1> 
   190                              <1> ; 26/08/2015
   191                              <1> ; 24/07/2015
   192                              <1> ; 24/06/2015
   193                              <1> MAX_ARG_LEN	   equ 256 ; max. length of sys exec arguments
   194                              <1> ; 01/07/2015
   195                              <1> MAX_MSG_LEN	   equ 255 ; max. msg length for 'sysmsg'
   196                              <1> ;	 					 		
  1917                                  %include 'trdosk0.s' ; 04/01/2016 
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DEFINITIONS : trdosk0.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/02/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; TRDOS2.ASM (09/11/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
    14                              <1> ;
    15                              <1> ; Masterboot / Partition Table at Beginning+1BEh
    16                              <1> ptBootable       equ 0
    17                              <1> ptBeginHead      equ 1
    18                              <1> ptBeginSector    equ 2
    19                              <1> ptBeginCylinder  equ 3
    20                              <1> ptFileSystemID   equ 4
    21                              <1> ptEndHead        equ 5
    22                              <1> ptEndSector      equ 6
    23                              <1> ptEndCylinder    equ 7
    24                              <1> ptStartSector    equ 8
    25                              <1> ptSectors        equ 12
    26                              <1> 
    27                              <1> ; Boot Sector Parameters at 7C00h
    28                              <1> DataArea1     equ -4
    29                              <1> DataArea2     equ -2
    30                              <1> BootStart     equ 0h
    31                              <1> OemName       equ 03h
    32                              <1> BytesPerSec   equ 0Bh
    33                              <1> SecPerClust   equ 0Dh
    34                              <1> ResSectors    equ 0Eh
    35                              <1> FATs          equ 10h
    36                              <1> RootDirEnts   equ 11h
    37                              <1> Sectors       equ 13h
    38                              <1> Media         equ 15h
    39                              <1> FATSecs       equ 16h
    40                              <1> SecPerTrack   equ 18h
    41                              <1> Heads         equ 1Ah 
    42                              <1> Hidden1       equ 1Ch
    43                              <1> Hidden2       equ 1Eh
    44                              <1> HugeSec1      equ 20h
    45                              <1> HugeSec2      equ 22h
    46                              <1> DriveNumber   equ 24h
    47                              <1> Reserved1     equ 25h
    48                              <1> bootsignature equ 26h                 
    49                              <1> VolumeID      equ 27h
    50                              <1> VolumeLabel   equ 2Bh
    51                              <1> FileSysType   equ 36h          
    52                              <1> Reserved2     equ 3Eh                           ; Starting cluster of P2000
    53                              <1> 
    54                              <1> ; FAT32 BPB Structure
    55                              <1> FAT32_FAT_Size equ 36
    56                              <1> FAT32_RootFClust equ 44
    57                              <1> FAT32_FSInfoSec equ 48
    58                              <1> FAT32_DrvNum equ 64
    59                              <1> FAT32_BootSig equ 66
    60                              <1> FAT32_VolID equ 67
    61                              <1> FAT32_VolLab equ 71
    62                              <1> FAT32_FilSysType equ 82
    63                              <1> 
    64                              <1> ; BIOS Disk Parameters
    65                              <1> DPDiskNumber  equ 0h
    66                              <1> DPDType       equ 1h
    67                              <1> DPReturn      equ 2h
    68                              <1> DPHeads       equ 3h
    69                              <1> DPCylinders   equ 4h
    70                              <1> DPSecPerTrack equ 6h
    71                              <1> DPDisks       equ 7h
    72                              <1> DPTableOff    equ 8h
    73                              <1> DPTableSeg    equ 0Ah
    74                              <1> DPNumOfSecs   equ 0Ch
    75                              <1> 
    76                              <1> ; BIOS INT 13h Extensions (LBA extensions)
    77                              <1> ; Just After DP Data (DPDiskNumber+)
    78                              <1> DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    79                              <1> DAP_Reserved1 equ 11h   ; Reserved Byte 
    80                              <1> DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    81                              <1> DAP_Reserved2 equ 13h   ; Reserved Byte
    82                              <1> DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    83                              <1> DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    84                              <1>                         ; C1= Selected Cylinder Number
    85                              <1>                         ; H0= Number Of Heads (Maximum Head Number + 1)
    86                              <1>                         ; H1= Selected Head Number
    87                              <1>                         ; S0= Maximum Sector Number
    88                              <1>                         ; S1= Selected Sector Number
    89                              <1>                         ; QUAD WORD
    90                              <1> ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    91                              <1>                              ; QUAD WORD (Also, value in 0h must be 18h) 
    92                              <1>                              ; TR-DOS will not use 64 bit Flat Address
    93                              <1> 
    94                              <1> ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    95                              <1> ; Just After DP Data (DPDiskNumber+)
    96                              <1> GetDParams_48h equ 20h ; Word. Data Length, must be 26 (1Ah) for short data.
    97                              <1> GDP_48h_InfoFlag equ 22h ; Word
    98                              <1> ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    99                              <1> GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
   100                              <1> GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
   101                              <1> GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
   102                              <1> GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
   103                              <1> GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
   104                              <1> 
   105                              <1> ; TR-DOS Standalone Program Extensions to the DiskParams Block
   106                              <1> ; Just After DP Data (DPDiskNumber+)
   107                              <1> TRDP_CurrentSector equ 3Ah  ; DX:AX (LBA)
   108                              <1> TRDP_SectorCount equ 3Eh    ; CX (or Counter)
   109                              <1> 
   110                              <1> 
   111                              <1> ; DOS Logical Disks
   112                              <1> LD_Name equ 0
   113                              <1> LD_DiskType equ 1
   114                              <1> LD_PhyDrvNo equ 2
   115                              <1> LD_FATType equ 3
   116                              <1> LD_FSType equ 4
   117                              <1> LD_LBAYes equ 5
   118                              <1> LD_BPB equ 6
   119                              <1> LD_FATBegin equ 96
   120                              <1> LD_ROOTBegin equ 100
   121                              <1> LD_DATABegin equ 104
   122                              <1> LD_StartSector equ 108
   123                              <1> LD_TotalSectors equ 112
   124                              <1> LD_FreeSectors equ 116
   125                              <1> LD_Clusters equ 120
   126                              <1> LD_PartitionEntry equ 124
   127                              <1> LD_DParamEntry equ 125
   128                              <1> LD_MediaChanged equ 126
   129                              <1> LD_CDirLevel equ 127
   130                              <1> LD_CurrentDirectory equ 128
   131                              <1> 
   132                              <1> ; Singlix FS Extensions to DOS Logical Disks
   133                              <1> ; 03/01/2010 (LD_BPB compatibility for CHS r/w)
   134                              <1> 
   135                              <1> LD_FS_Name equ 0
   136                              <1> LD_FS_DiskType equ 1
   137                              <1> LD_FS_PhyDrvNo equ 2
   138                              <1> LD_FS_FATType equ 3
   139                              <1> LD_FS_FSType equ 4
   140                              <1> LD_FS_LBAYes equ 5
   141                              <1> LD_FS_BPB equ 6
   142                              <1> LD_FS_MediaAttrib equ 6
   143                              <1> LD_FS_VersionMajor equ 7
   144                              <1> LD_FS_RootDirD equ 8
   145                              <1> LD_FS_MATLocation equ 12
   146                              <1> LD_FS_Reserved1 equ 16 ;1 reserved byte
   147                              <1> LD_FS_BytesPerSec equ 17 ; LD_BPB + 0Bh
   148                              <1> LD_FS_Reserved2 equ 19 ;2 reserved byte
   149                              <1> LD_FS_DATLocation equ 20
   150                              <1> LD_FS_DATSectors equ 24
   151                              <1> LD_FS_Reserved3 equ 28 ;3 reserved word
   152                              <1> LD_FS_SecPerTrack equ 30 ; LD_BPB + 18h
   153                              <1> LD_FS_NumHeads equ 32    ; LD_BPB + 1Ah
   154                              <1> LD_FS_UnDelDirD equ 34
   155                              <1> LD_FS_Reserved4 equ 38 ;4 reserved word
   156                              <1> LD_FS_VolumeSerial equ 40
   157                              <1> LD_FS_VolumeName equ 44
   158                              <1> LD_FS_BeginSector equ 108
   159                              <1> LD_FS_VolumeSize equ 112
   160                              <1> LD_FS_FreeSectors equ 116
   161                              <1> LD_FS_FirstFreeSector equ 120
   162                              <1> LD_FS_PartitionEntry equ 124
   163                              <1> LD_FS_DParamEntry equ 125
   164                              <1> LD_FS_MediaChanged equ 126
   165                              <1> LD_FS_CDirLevel equ 127
   166                              <1> LD_FS_CDIR_Converted equ 128
   167                              <1> 
   168                              <1> ; Valid FAT Types
   169                              <1> FS_FAT12 equ 1
   170                              <1> FS_FAT16_CHS equ 2
   171                              <1> FS_FAT32_CHS equ 3
   172                              <1> FS_FAT16_LBA equ 4
   173                              <1> FS_FAT32_LBA equ 5
   174                              <1> 
   175                              <1> ; Cursor Location
   176                              <1> CCCpointer equ  0450h   ; BIOS data, current cursor column
   177                              <1> ; FAT Clusters EOC sign
   178                              <1> FAT12EOC equ 0FFFh
   179                              <1> FAT16EOC equ 0FFFFh
   180                              <1> ;FAT32EOC equ 0FFFFFFFh ; It is not direct usable for 8086 code
   181                              <1> ; BAD Cluster
   182                              <1> FAT12BADC equ 0FF7h
   183                              <1> FAT16BADC equ 0FFF7h
   184                              <1> ;FAT32BADC equ 0FFFFFF7h ; It is not direct usable for 8086 code
   185                              <1> ; MS-DOS FAT16 FS (Maximum Possible) Last Cluster Number= 0FFF6h 
   186                              <1> 
   187                              <1> ; TRFS
   188                              <1> 
   189                              <1> bs_FS_JmpBoot equ 0 ; jmp short bsBootCode
   190                              <1>                 ; db 0EBh, db 3Fh, db 90h
   191                              <1> bs_FS_Identifier equ 3  ; db 'FS', db 0
   192                              <1> bs_FS_BytesPerSec equ 6 ; dw 512
   193                              <1> bs_FS_MediaAttrib equ 8 ; db 3
   194                              <1> bs_FS_PartitionID equ 9 ; db 0A1h
   195                              <1> bs_FS_VersionMaj equ 10 ; db 01h
   196                              <1> bs_FS_VersionMin equ 11 ; db 0
   197                              <1> bs_FS_BeginSector equ 12   ; dd 0 
   198                              <1> bs_FS_VolumeSize equ 16 ; dd 2880
   199                              <1> bs_FS_StartupFD equ 20 ; dd 0
   200                              <1> bs_FS_MATLocation equ 24 ; dd 1
   201                              <1> bs_FS_RootDirD equ 28 ; dd 8
   202                              <1> bs_FS_SystemConfFD equ 32 ; dd 0
   203                              <1> bs_FS_SwapFD equ 36 ; dd 0
   204                              <1> bs_FS_UnDelDirD equ 40 ; dd 0
   205                              <1> bs_FS_DriveNumber equ 44 ; db 0
   206                              <1> bs_FS_LBA_Ready equ 45 ; db 0
   207                              <1> bs_FS_MagicWord equ 46 
   208                              <1> bs_FS_SecPerTrack equ 46 ; db 0A1h
   209                              <1> bs_FS_Heads equ 47 ; db 01h 
   210                              <1> bs_FS_OperationSys equ 48 ; db "TR-SINGLIX v1.0b"
   211                              <1> bs_FS_Terminator equ 64 ; db 0
   212                              <1> bs_FS_BootCode equ 65 
   213                              <1> 
   214                              <1> FS_MAT_DATLocation equ 12
   215                              <1> FS_MAT_DATScount equ 16
   216                              <1> FS_MAT_FreeSectors equ 20
   217                              <1> FS_MAT_FirstFreeSector equ 24
   218                              <1> FS_RDT_VolumeSerialNo equ 28
   219                              <1> FS_RDT_VolumeName equ 64
   220                              <1> 
   221                              <1> ; FAT12 + FAT16 + FAT32
   222                              <1> BS_JmpBoot equ 0
   223                              <1> BS_OEMName equ 3
   224                              <1> BPB_BytsPerSec equ 11
   225                              <1> BPB_SecPerClust equ 13
   226                              <1> BPB_RsvdSecCnt equ 14
   227                              <1> BPB_NumFATs equ 16
   228                              <1> BPB_RootEntCnt equ 17
   229                              <1> BPB_TotalSec16 equ 19
   230                              <1> BPB_Media equ 21
   231                              <1> BPB_FATSz16 equ 22
   232                              <1> BPB_SecPerTrk equ 24
   233                              <1> BPB_NumHeads equ 26
   234                              <1> BPB_HiddSec equ 28
   235                              <1> BPB_TotalSec32 equ 32
   236                              <1> 
   237                              <1> ; FAT12 and FAT16 only
   238                              <1> BS_DrvNum equ 36
   239                              <1> BS_Reserved1 equ 37
   240                              <1> BS_BootSig equ 38
   241                              <1> BS_VolID equ 39
   242                              <1> BS_VolLab equ 43
   243                              <1> BS_FilSysType equ 54 ; 8 bytes
   244                              <1> BS_BootCode equ 62
   245                              <1> 
   246                              <1> ; FAT32 only
   247                              <1> BPB_FATSz32 equ 36 ; FAT32, 4 bytes
   248                              <1> BPB_ExtFlags equ 40 ; FAT32, 2 bytes
   249                              <1> BPB_FSVer equ 42 ; FAT32, 2 bytes
   250                              <1> BPB_RootClus equ 44 ; FAT32, 4 bytes
   251                              <1> BPB_FSInfo equ 48 ; FAT 32, 2 bytes 
   252                              <1> BPB_BkBootSec equ 50 ; FAT32, 2 bytes
   253                              <1> BPB_Reserved equ 52 ; FAT32, 12 bytes
   254                              <1> BS_FAT32_DrvNum equ 64 ; FAT32, 1 byte
   255                              <1> BS_FAT32_Reserved1 equ 65 ; FAT32, 1 byte
   256                              <1> BS_FAT32_BootSig equ 66 ; FAT32, 1 byte
   257                              <1> BS_FAT32_VolID equ 67 ; FAT32, 4 bytes
   258                              <1> BS_FAT32_VolLab equ 71 ; FAT32, 11 bytes
   259                              <1> BS_FAT32_FilSysType equ 82 ; FAT32, 8 bytes
   260                              <1> BS_FAT32_BootCode equ 90
   261                              <1> 
   262                              <1> ; 29/02/2016
   263                              <1> ;(FAT32 Free Cluster Count & First Free Cluster values)
   264                              <1> ;[BPB_Reserved] = Free Cluster Count (offset 52)
   265                              <1> ;[BPB_Reserved+4] = First Free Cluster (offset 56)
   266                              <1> 
   267                              <1> BS_Validation equ 510
   268                              <1> 
   269                              <1> ; 15/02/2016
   270                              <1> ; FILE.ASM - 09/10/2011
   271                              <1> ; Directory Entry Structure
   272                              <1> ; 29/10/2009 (According to Microsoft FAT32 File System Specification)
   273                              <1> DirEntry_Name equ 0
   274                              <1> DirEntry_Attr equ 11
   275                              <1> DirEntry_NTRes equ 12
   276                              <1> DirEntry_CrtTimeTenth equ 13
   277                              <1> DirEntry_CrtTime equ 14
   278                              <1> DirEntry_CrtDate equ 16
   279                              <1> DirEntry_LastAccDate equ 18
   280                              <1> DirEntry_FstClusHI equ 20
   281                              <1> DirEntry_WrtTime equ 22
   282                              <1> DirEntry_WrtDate equ 24
   283                              <1> DirEntry_FstClusLO equ 26
   284                              <1> DirEntry_FileSize equ 28
  1918                                  %include 'trdosk1.s' ; 04/01/2016 
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYS INIT : trdosk1.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 13/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; TRDOS2.ASM (09/11/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
    14                              <1> ;
    15                              <1> 
    16                              <1> sys_init:
    17                              <1> 	; 07/05/2016
    18                              <1> 	; 02/05/2016
    19                              <1> 	; 24/04/2016
    20                              <1> 	; 14/04/2016
    21                              <1> 	; 13/04/2016
    22                              <1> 	; 30/03/2016
    23                              <1> 	; 24/01/2016
    24                              <1> 	; 06/01/2016
    25                              <1> 	; 04/01/2016
    26                              <1> 
    27                              <1> 	; 30/03/2016
    28                              <1> 	; Clear Logical DOS Disk Description Tables Area
    29 0000544F 31C0                <1> 	xor	eax, eax
    30 00005451 BF00010900          <1> 	mov	edi, Logical_DOSDisks
    31 00005456 B980060000          <1> 	mov	ecx, 6656/4 ; 26*256 = 6656 bytes
    32 0000545B F3AB                <1> 	rep	stosd ; 1664 times 4 bytes
    33                              <1> 
    34 0000545D B83F3A2F00          <1> 	mov	eax, '?:/'
    35 00005462 A3[8F200100]        <1> 	mov	[Current_Dir_Drv], eax
    36                              <1> 
    37                              <1> 	; Logical DRV INIT (only for hard disks)
    38 00005467 E8B3010000          <1> 	call 	ldrv_init  ; trdosk2.s
    39                              <1> 	
    40                              <1> 	; When floppy_drv_init call is disabled
    41                              <1> 	; media changed sign is needed
    42                              <1> 	; for proper drive initialization
    43                              <1>         
    44 0000546C BE00010900          <1> 	mov 	esi, Logical_DOSDisks
    45 00005471 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
    46 00005473 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
    47 00005476 8806                <1> 	mov 	[esi], al ; A:
    48 00005478 81C600010000        <1> 	add 	esi, 100h 
    49 0000547E 8806                <1> 	mov 	[esi], al ; B: 
    50                              <1>            
    51                              <1> _current_drive_bootdisk:
    52 00005480 8A15[14ED0000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
    53 00005486 80FAFF              <1> 	cmp 	dl, 0FFh
    54 00005489 740A                <1> 	je 	short _last_dos_diskno_check
    55                              <1> _boot_drive_check:
    56 0000548B 80FA80              <1> 	cmp 	dl, 80h
    57 0000548E 7218                <1> 	jb 	short _current_drive_a
    58 00005490 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
    59 00005493 EB13                <1> 	jmp 	short _current_drive_a 
    60                              <1> 
    61                              <1> _last_dos_diskno_check:
    62 00005495 8A15[07DE0000]      <1> 	mov 	dl, [Last_DOS_DiskNo]
    63 0000549B 80FA02              <1> 	cmp 	dl, 2
    64 0000549E 7706                <1> 	ja 	short _current_drive_c
    65 000054A0 7406                <1> 	je 	short _current_drive_a
    66 000054A2 30D2                <1> 	xor 	dl, dl ; A:
    67 000054A4 EB02                <1> 	jmp 	short _current_drive_a
    68                              <1> 
    69                              <1> _current_drive_c:
    70 000054A6 B202                <1> 	mov 	dl, 2 ; C:
    71                              <1> 
    72                              <1> _current_drive_a:
    73 000054A8 8815[15ED0000]      <1> 	mov	[drv], dl
    74 000054AE BE[09DE0000]        <1>         mov     esi, msg_CRLF_temp
    75 000054B3 E89E000000          <1> 	call 	print_msg
    76                              <1> 
    77 000054B8 8A15[15ED0000]      <1> 	mov	dl, [drv]
    78 000054BE E893090000          <1> 	call 	change_current_drive
    79 000054C3 730C                <1> 	jnc 	short _start_mainprog
    80                              <1> 
    81                              <1> _drv_not_ready_error: 
    82 000054C5 BE[CDE00000]        <1> 	mov 	esi, msgl_drv_not_ready
    83 000054CA E887000000          <1> 	call 	print_msg
    84 000054CF EB63                <1>         jmp     _end_of_mainprog
    85                              <1> 
    86                              <1> _start_mainprog:
    87                              <1> 	; 07/05/2016
    88                              <1> 	; 02/05/2016
    89                              <1> 	; 24/04/2016
    90                              <1> 	; Retro UNIX 386 v1, 'sys_init' (u0.s)
    91                              <1> 	; 23/06/2015
    92                              <1> 
    93                              <1> 	; 02/05/2016
    94                              <1> 	; 24/04/2016
    95 000054D1 66B80100            <1> 	mov	ax, 1
    96 000054D5 A2[F7300100]        <1> 	mov	[u.uno], al
    97 000054DA 66A3[92300100]      <1> 	mov	[mpid], ax
    98 000054E0 66A3[8C2D0100]      <1> 	mov	[p.pid], ax
    99 000054E6 A2[1C2E0100]        <1> 	mov	[p.stat], al
   100 000054EB B004                <1> 	mov	al, time_count
   101 000054ED A2[EA300100]        <1> 	mov	[u.quant], al
   102                              <1> 	;
   103 000054F2 A1[C81F0100]        <1> 	mov	eax, [k_page_dir]
   104 000054F7 A3[01310100]        <1> 	mov	[u.pgdir], eax ; reset
   105                              <1> 	;
   106 000054FC E8E5F0FFFF          <1> 	call	allocate_page
   107 00005501 0F82A3000000        <1> 	jc	panic
   108 00005507 A3[F8300100]        <1> 	mov	[u.upage], eax ; user structure page	
   109 0000550C A3[2C2E0100]        <1> 	mov	[p.upage], eax
   110 00005511 E84AF1FFFF          <1> 	call	clear_page
   111                              <1> 	;
   112                              <1> 	; 24/08/2015
   113 00005516 FE0D[9F300100]      <1> 	dec 	byte [sysflg] ; FFh = ready for system call
   114                              <1> 			      ; 0 = executing a system call
   115                              <1> 	; 13/04/2016
   116                              <1> 	; Clear Environment Variables Page/Area
   117 0000551C BF00300900          <1> 	mov	edi, Env_Page ; 93000h
   118 00005521 B980000000          <1> 	mov	ecx, Env_Page_Size / 4 	; 512/4  (4096/4)				 	  		 	  
   119 00005526 31C0                <1> 	xor	eax, eax
   120 00005528 F3AB                <1> 	rep	stosd
   121                              <1> 
   122                              <1> 	; 14/04/2016
   123 0000552A E8BA320000          <1>  	call	mainprog_startup_configuration
   124                              <1> 
   125 0000552F E85E0A0000          <1>         call    dos_prompt
   126                              <1>               
   127                              <1> _end_of_mainprog:
   128 00005534 BE[09DE0000]        <1>         mov     esi, msg_CRLF_temp
   129 00005539 E818000000          <1> 	call 	print_msg
   130 0000553E BE[0FDE0000]        <1> 	mov 	esi, mainprog_Version
   131 00005543 E80E000000          <1> 	call 	print_msg
   132                              <1> 	; 24/01/2016
   133 00005548 28E4                <1> 	sub	ah, ah
   134 0000554A E87DB5FFFF          <1> 	call	int16h ; call getch
   135 0000554F E954BAFFFF          <1> 	jmp	cpu_reset
   136                              <1> 
   137 00005554 EBFE                <1> infinitiveloop: jmp short infinitiveloop
   138                              <1> 
   139                              <1> print_msg:
   140                              <1> 	; 13/05/2016
   141                              <1> 	; 04/01/2016
   142                              <1> 	; 01/07/2015
   143                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   144                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   145                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
   146                              <1> 	;
   147 00005556 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   148                              <1> 	;mov	bl, 07h ; Black background, light gray forecolor
   149                              <1> 
   150 0000555C AC                  <1> 	lodsb
   151                              <1> pmsg1:
   152 0000555D 56                  <1> 	push 	esi
   153                              <1> 	;mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   154 0000555E B307                <1> 	mov	bl, 07h ; Black background, light gray forecolor
   155 00005560 E8BCC5FFFF          <1> 	call 	_write_tty
   156 00005565 5E                  <1> 	pop	esi
   157 00005566 AC                  <1> 	lodsb
   158 00005567 20C0                <1> 	and 	al, al
   159 00005569 75F2                <1> 	jnz 	short pmsg1
   160 0000556B C3                  <1> 	retn
   161                              <1> 
   162                              <1> clear_screen:
   163                              <1> 	; 13/05/2016
   164                              <1> 	; 30/01/2016
   165                              <1> 	; 24/01/2016
   166                              <1> 	; 04/01/2016
   167 0000556C 0FB61D[F61F0100]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
   168 00005573 8AA3[17E90000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
   169 00005579 80FC04              <1> 	cmp	ah, 4
   170 0000557C 7205                <1> 	jb	short cls1
   171 0000557E 80FC07              <1> 	cmp	ah, 7
   172 00005581 7526                <1> 	jne	short vga_clear
   173                              <1> cls1:
   174                              <1> 	;mov	bh, bl
   175                              <1> 	;mov	bl, 7
   176 00005583 3A25[06E90000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
   177                              <1> 	;je	short cls2 ; yes (current video mode = 3)
   178                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
   179                              <1> 	;;retn
   180                              <1> 	;jmp	set_mode_3
   181 00005589 0F859CC5FFFF        <1> 	jne	set_mode_3
   182                              <1> cls2:
   183 0000558F 88DF                <1> 	mov	bh, bl ; video page (0 to 7)
   184 00005591 B307                <1> 	mov	bl, 07h ; attribute to be used on blanked line
   185 00005593 28C0                <1> 	sub 	al, al ; 0 =  entire window
   186 00005595 6631C9              <1> 	xor 	cx, cx
   187 00005598 66BA4F18            <1> 	mov 	dx, 184Fh
   188 0000559C E8D8C2FFFF          <1> 	call	_scroll_up ; 24/01/2016
   189                              <1> 	;
   190                              <1> 	;mov	bh, [ACTIVE_PAGE] ; video page number (0 to 7)
   191 000055A1 6631D2              <1> 	xor 	dx, dx
   192 000055A4 E80EC6FFFF          <1> 	call	_set_cpos ; 24/01/2016 
   193                              <1> 	;retn
   194                              <1> vga_clear:
   195 000055A9 C3                  <1> 	retn	
   196                              <1> 
   197                              <1> panic:
   198                              <1> 	; 13/05/2016 (TRDOS 386 = TRDOS v2)
   199                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   200                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   201 000055AA BE[AEEE0000]        <1> 	mov 	esi, panic_msg
   202 000055AF E8A2FFFFFF          <1> 	call 	print_msg
   203                              <1> key_to_reboot:
   204                              <1>         ; 24/01/2016
   205 000055B4 28E4                <1>         sub     ah, ah
   206 000055B6 E811B5FFFF          <1>         call    int16h ; call   getch
   207                              <1>         ; wait for a character from the current tty
   208                              <1> 	;
   209 000055BB B00A                <1> 	mov	al, 0Ah
   210 000055BD 8A3D[F61F0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
   211 000055C3 B307                <1> 	mov	bl, 07h ; Black background, 
   212                              <1> 			; light gray forecolor
   213 000055C5 E857C5FFFF          <1> 	call 	_write_tty
   214 000055CA E9D9B9FFFF          <1> 	jmp	cpu_reset 
   215                              <1> 
   216                              <1> ctrlbrk:
   217                              <1> 	; 12/11/2015
   218                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   219                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
   220                              <1> 	;
   221                              <1> 	; INT 1Bh (control+break) handler		
   222                              <1> 	;
   223                              <1>       	; Retro Unix 8086 v1 feature only!
   224                              <1>       	;
   225 000055CF 66833D[EC300100]00  <1> 	cmp 	word [u.intr], 0
   226 000055D7 7645                <1> 	jna 	short cbrk4
   227                              <1> cbrk0:
   228                              <1> 	; 12/11/2015
   229                              <1> 	; 06/12/2013
   230 000055D9 66833D[EE300100]00  <1> 	cmp 	word [u.quit], 0
   231 000055E1 743B                <1> 	jz	short cbrk4
   232                              <1> 	;
   233                              <1> 	; 20/09/2013	
   234 000055E3 6650                <1> 	push 	ax
   235 000055E5 A0[F61F0100]        <1> 	mov	al, [ptty]
   236                              <1> 	;
   237                              <1> 	; 12/11/2015
   238                              <1> 	;
   239                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
   240                              <1> 	; or ctrl+break from console (pseudo) tty
   241                              <1> 	; (!redirection!)
   242                              <1> 	;
   243 000055EA 3C08                <1> 	cmp	al, 8 ; serial port tty nums > 7
   244 000055EC 7211                <1>         jb      short cbrk1 ; console (pseudo) tty
   245                              <1> 	;	
   246                              <1> 	; Serial port interrupt handler sets [ptty]
   247                              <1> 	; to the port's tty number (as temporary).
   248                              <1> 	;
   249                              <1> 	; If active process is using a stdin or 
   250                              <1> 	; stdout redirection (by the shell),
   251                              <1>         ; console tty keyboard must be available
   252                              <1> 	; to terminate running process,
   253                              <1> 	; in order to prevent a deadlock. 
   254                              <1> 	;
   255 000055EE 52                  <1> 	push	edx
   256 000055EF 0FB615[F7300100]    <1> 	movzx	edx, byte [u.uno]
   257 000055F6 3A82[EB2D0100]      <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
   258 000055FC 5A                  <1> 	pop	edx
   259 000055FD 7412                <1> 	je	short cbrk2
   260                              <1> cbrk1:
   261 000055FF FEC0                <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
   262                              <1> 	; 06/12/2013
   263 00005601 3A05[D8300100]      <1> 	cmp	al, [u.ttyp] ; recent open tty (r)
   264 00005607 7408                <1> 	je	short cbrk2	
   265 00005609 3A05[D9300100]      <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
   266 0000560F 750B                <1> 	jne	short cbrk3	
   267                              <1> cbrk2:
   268                              <1> 	;; 06/12/2013
   269                              <1> 	;mov	ax, [u.quit]
   270                              <1> 	;and	ax, ax
   271                              <1> 	;jz	short cbrk3
   272                              <1> 	;
   273 00005611 6631C0              <1> 	xor	ax, ax ; 0
   274 00005614 6648                <1> 	dec	ax
   275                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
   276 00005616 66A3[EE300100]      <1> 	mov	[u.quit], ax
   277                              <1> cbrk3:
   278 0000561C 6658                <1> 	pop	ax
   279                              <1> cbrk4:
   280 0000561E C3                  <1> 	retn
  1919                                  %include 'trdosk2.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DRV INIT : trdosk2.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 06/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; TRDOS2.ASM (09/11/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; DRV_INIT.ASM (c) 2009-2011 Erdogan TAN  [26/09/2009] Last Update: 07/08/2011
    14                              <1> ;
    15                              <1> 
    16                              <1> ldrv_init: ; Logical Drive Initialization
    17                              <1> 	; 12/02/2016
    18                              <1> 	; 06/01/2016
    19                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
    20                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
    21                              <1> 	; 07/08/2011
    22                              <1> 	; 20/09/2009
    23                              <1> 	; 2005
    24 0000561F 0FB60D[64200100]    <1> 	movzx	ecx, byte [HF_NUM] ; number of fixed disks
    25 00005626 80F901              <1> 	cmp	cl, 1
    26 00005629 7301                <1> 	jnb	short load_hd_partition_tables
    27                              <1> 	; No hard disks
    28 0000562B C3                  <1> 	retn
    29                              <1> load_hd_partition_tables:
    30 0000562C 8B35[68200100]      <1> 	mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
    31 00005632 BF[8E240100]        <1> 	mov 	edi, PTable_hd0
    32 00005637 B280                <1> 	mov 	dl, 80h
    33                              <1> load_next_hd_partition_table:
    34 00005639 51                  <1> 	push	ecx
    35 0000563A 57                  <1> 	push	edi
    36 0000563B 56                  <1> 	push	esi ; FDPT (+ DPTE) address
    37 0000563C 8A4614              <1> 	mov	al, [esi+20] ; DPTE offset 4
    38 0000563F 2440                <1> 	and	al, 40h ;  LBA bit (bit 6)
    39                              <1> 	;shr	al, 6
    40 00005641 A2[8F260100]        <1> 	mov 	[HD_LBA_yes], al
    41 00005646 E81C040000          <1> 	call	load_masterboot
    42 0000564B 7275                <1> 	jc	short pass_pt_this_hard_disk
    43                              <1> 
    44 0000564D BE[4C240100]        <1> 	mov	esi, PartitionTable
    45 00005652 89F3                <1> 	mov	ebx, esi
    46                              <1> 	;mov	ecx, 16
    47 00005654 B110                <1> 	mov	cl, 16
    48 00005656 F3A5                <1> 	rep 	movsd
    49 00005658 89DE                <1> 	mov 	esi, ebx 
    50 0000565A C605[17ED0000]04    <1> 	mov 	byte [hdc], 4 ; 4 - partition index
    51                              <1> loc_validate_hdp_partition:
    52 00005661 807E0400            <1> 	cmp 	byte [esi+ptFileSystemID], 0
    53 00005665 7641                <1> 	jna	short loc_validate_next_hdp_partition2
    54 00005667 56                  <1> 	push	esi ; Masterboot partition table offset
    55 00005668 52                  <1> 	push	edx ; dl = Physical drive number 
    56 00005669 FE05[90260100]      <1> 	inc	byte [PP_Counter]
    57 0000566F 31FF                <1>         xor	edi, edi ; 0  
    58                              <1> 	; Input -> ESI = PartitionTable offset
    59                              <1> 	; DL = Hard disk drive number 
    60                              <1> 	; EDI = 0 -> Primary Partition
    61                              <1> 	; EDI > 0 -> Extended Partition's Start Sector   
    62 00005671 E879010000          <1> 	call 	validate_hd_fat_partition
    63 00005676 730A                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
    64                              <1> 	;pop	edx
    65                              <1> 	;push	edx
    66 00005678 8B1424              <1> 	mov	edx, [esp] 
    67 0000567B E8C5020000          <1> 	call	validate_hd_fs_partition
    68 00005680 7224                <1> 	jc	short loc_validate_next_hdp_partition1
    69                              <1> loc_set_valid_hdp_partition_entry:
    70 00005682 8A0D[07DE0000]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
    71 00005688 80C141              <1> 	add 	cl, 'A'
    72                              <1> 	; ESI = Logical dos drive description table address
    73 0000568B 880E                <1> 	mov	[esi+LD_Name], cl
    74 0000568D 8A6602              <1> 	mov	ah, [esi+LD_PhyDrvNo]
    75 00005690 88E0                <1> 	mov	al, ah ; Physical drive number
    76 00005692 2C80                <1> 	sub	al, 80h
    77 00005694 C0E002              <1> 	shl	al, 2
    78 00005697 0404                <1> 	add	al, 4 ; 0 Based
    79 00005699 2A05[17ED0000]      <1> 	sub	al, [hdc] ; 4 - partition index
    80                              <1> 	; AL = Partition entry/index, 0 based
    81                              <1> 	;  0 -> hd 0, Partition Table offset = 0
    82                              <1> 	; 15 -> hd 3, Partition Table offset = 3
    83                              <1> 	;mov	[esi+LD_PartitionEntry], al 
    84 0000569F 80EC7E              <1> 	sub 	ah, 7Eh
    85                              <1> 	; AH = Physical drive index, zero based
    86                              <1> 	;  0 for drive A:, 2 for drive C:
    87                              <1> 	;mov 	[esi+LD_DParamEntry], ah 
    88 000056A2 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
    89                              <1> loc_validate_next_hdp_partition1:
    90 000056A6 5A                  <1> 	pop 	edx ; dl = Physical drive number 
    91 000056A7 5E                  <1> 	pop	esi ; Masterboot partition table offset
    92                              <1> loc_validate_next_hdp_partition2:
    93                              <1> 	; ESI = PartitionTable offset
    94                              <1> 	; DL = Hard/Fixed disk drive number
    95 000056A8 FE0D[17ED0000]      <1> 	dec	byte [hdc] ; 4 - partition index
    96 000056AE 7412                <1> 	jz	short pass_pt_this_hard_disk
    97 000056B0 83C610              <1> 	add	esi, 16 ; 10h
    98 000056B3 EBAC                <1> 	jmp	short loc_validate_hdp_partition
    99                              <1> loc_next_hd_partition_table:
   100 000056B5 FEC2                <1> 	inc	dl
   101 000056B7 83C620              <1> 	add	esi, 32 ; next FDPT address
   102 000056BA 83C740              <1> 	add	edi, 64 ; next partition table destination
   103 000056BD E977FFFFFF          <1>         jmp     load_next_hd_partition_table
   104                              <1> pass_pt_this_hard_disk:
   105 000056C2 5E                  <1> 	pop	esi ; FDPT (+ DPTE) address
   106 000056C3 5F                  <1> 	pop	edi ; Ptable_hd?
   107 000056C4 59                  <1> 	pop	ecx
   108 000056C5 E2EE                <1> 	loop	loc_next_hd_partition_table
   109 000056C7 803D[90260100]01    <1> 	cmp	byte [PP_Counter], 1
   110 000056CE 7301                <1> 	jnb	short load_extended_dos_partitions
   111                              <1> 	; Empty partition table
   112 000056D0 C3                  <1> 	retn 
   113                              <1> load_extended_dos_partitions:
   114 000056D1 BE[8E240100]        <1> 	mov	esi, PTable_hd0
   115 000056D6 BF[8E250100]        <1> 	mov	edi, PTable_ep0
   116 000056DB C605[17ED0000]80    <1> 	mov	byte [hdc], 80h
   117                              <1> next_hd_extd_partition:
   118 000056E2 56                  <1> 	push	esi ; PTable_hd? offset
   119 000056E3 57                  <1> 	push	edi ; PTable_ep?
   120                              <1> 	;mov	ecx, 4
   121 000056E4 B104                <1> 	mov	cl, 4
   122 000056E6 8A15[17ED0000]      <1> 	mov	dl, byte [hdc]
   123                              <1> hd_check_fs_id_05h:
   124 000056EC 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   125 000056EF 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
   126 000056F1 7404                <1> 	je	short loc_set_ep_start_sector
   127 000056F3 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
   128 000056F5 7546                <1> 	jne	short continue_to_check_ep
   129                              <1> loc_set_ep_start_sector:
   130 000056F7 FE05[91260100]      <1> 	inc	byte [EP_Counter]
   131 000056FD 88D4                <1> 	mov	ah, dl ; byte [hdc]
   132 000056FF 86E0                <1> 	xchg	ah, al ; al = Drv Number, ah = Partition Identifier
   133 00005701 50                  <1> 	push	eax 
   134 00005702 30E4                <1> 	xor	ah, ah  
   135 00005704 2C80                <1> 	sub	al, 80h
   136 00005706 50                  <1> 	push	eax
   137 00005707 C0E002              <1> 	shl	al, 2 ; al = al * 4
   138 0000570A 0FB6D8              <1> 	movzx	ebx, al
   139 0000570D 81C3[92260100]      <1> 	add	ebx, EP_StartSector
   140 00005713 8B4608              <1> 	mov	eax, [esi+ptStartSector]
   141                              <1>         ; EAX = Extended partition's start sector
   142 00005716 8903                <1>         mov	[ebx], eax
   143 00005718 58                  <1> 	pop	eax ; AL = Drv number - 80h, AH = 0 
   144 00005719 5A                  <1> 	pop	edx ; DL = Drv number, DH = Partition ID
   145 0000571A BB[8E220100]        <1> 	mov	ebx, MasterBootBuff
   146 0000571F 803D[8F260100]01    <1> 	cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
   147 00005726 7240                <1> 	jb	short loc_hd_load_ep_05h
   148 00005728 80FE05              <1> 	cmp	dh, 05h
   149 0000572B 743B                <1> 	je	short loc_hd_load_ep_05h
   150                              <1> loc_hd_load_ep_0Fh:
   151                              <1> 	; 04/01/2016
   152 0000572D 51                  <1> 	push	ecx
   153 0000572E 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; sector number
   154                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
   155                              <1> 	; LBA read/write (with private LBA function) 
   156                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   157                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   158 00005731 B41B                <1> 	mov	ah, 1Bh ; LBA read
   159 00005733 B001                <1> 	mov	al, 1 ; sector count
   160 00005735 E83BE5FFFF          <1> 	call	int13h
   161 0000573A 59                  <1> 	pop	ecx
   162 0000573B 733F                <1> 	jnc	short loc_hd_move_ep_table
   163                              <1> continue_to_check_ep:
   164 0000573D 83C610              <1> 	add	esi, 16
   165 00005740 E2AA                <1> 	loop	hd_check_fs_id_05h
   166                              <1> continue_check_ep_next_disk:
   167 00005742 5F                  <1> 	pop	edi ; PTable_ep?
   168 00005743 5E                  <1> 	pop	esi ; PTable_hd?
   169 00005744 A0[64200100]        <1> 	mov	al, [HF_NUM] ; number of hard disks
   170 00005749 047F                <1> 	add	al, 7Fh
   171 0000574B 3805[17ED0000]      <1> 	cmp	[hdc], al
   172 00005751 0F8392000000        <1> 	jnb	loc_validating_hd_partitions_ok
   173 00005757 83C640              <1> 	add	esi, 64
   174 0000575A 83C740              <1> 	add	edi, 64
   175 0000575D FE05[17ED0000]      <1> 	inc	byte [hdc]
   176 00005763 E97AFFFFFF          <1> 	jmp	next_hd_extd_partition
   177                              <1> loc_hd_load_ep_05h:
   178 00005768 51                  <1> 	push	ecx 
   179 00005769 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   180 0000576C 668B4E02            <1>         mov     cx, word [esi+ptBeginSector]
   181 00005770 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   182                              <1> 	;mov	ebx, MasterBootBuff
   183 00005774 E8FCE4FFFF          <1> 	call	int13h
   184 00005779 59                  <1> 	pop	ecx  
   185 0000577A 72C1                <1> 	jc	short continue_to_check_ep
   186                              <1> loc_hd_move_ep_table:
   187                              <1>         ;pop	edi
   188                              <1> 	;push	edi  ; PTable_ep?
   189 0000577C 8B3C24              <1> 	mov	edi, [esp]        
   190 0000577F BE[4C240100]        <1>         mov	esi, PartitionTable ; Extended
   191 00005784 89F3                <1> 	mov	ebx, esi
   192                              <1> 	;mov	ecx, 16
   193 00005786 B110                <1> 	mov	cl, 16
   194 00005788 F3A5                <1>        	rep	movsd
   195 0000578A 89DE                <1> 	mov	esi, ebx 
   196                              <1> loc_set_hde_sub_partition_count:
   197 0000578C C605[90260100]04    <1> 	mov	byte [PP_Counter], 4
   198                              <1> loc_validate_hde_partition:
   199 00005793 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
   200 00005797 763F                <1> 	jna	short loc_validate_next_hde_partition2
   201 00005799 56                  <1> 	push	esi ; Extended partition table offset
   202 0000579A 8A15[17ED0000]      <1> 	mov	dl, byte [hdc]
   203 000057A0 0FB6C2              <1> 	movzx	eax, dl
   204 000057A3 2C80                <1> 	sub	al, 80h
   205 000057A5 C0E002              <1> 	shl	al, 2
   206                              <1> 	; 06/01/2016 
   207                              <1> 	; (TRDOS v1.0 had a bug here, in 'DRV_INIT.ASM')
   208                              <1> 	; BUGFIX *
   209                              <1> 	;mov	ecx, eax
   210 000057A8 88C1                <1> 	mov	cl, al
   211 000057AA 80C104              <1> 	add	cl, 4
   212 000057AD 2A0D[90260100]      <1> 	sub	cl, [PP_Counter] ; 4 to 1
   213                              <1> 	; CL = Partition entry/index, 0 based
   214                              <1>         ;  0 -> hd 0, Partition Table offset = 0
   215                              <1>         ; 15 -> hd 3, Partition Table offset = 3
   216 000057B3 88D5                <1>       	mov	ch, dl   
   217 000057B5 80ED7E              <1> 	sub	ch, 7Eh ;
   218                              <1> 	; CH = Physical drive index, zero based
   219                              <1> 	;  0 for drive A:, 2 for drive C:	
   220                              <1> 	; BUGFIX *
   221 000057B8 51                  <1> 	push	ecx ; *
   222 000057B9 BF[92260100]        <1> 	mov	edi, EP_StartSector
   223 000057BE 01C7                <1> 	add	edi, eax
   224                              <1> 	; Input -> ESI = PartitionTable offset
   225                              <1> 	; DL = Hard disk drive number   
   226                              <1> 	; EDI = Extended partition start sector pointer
   227 000057C0 E82A000000          <1> 	call	validate_hd_fat_partition
   228 000057C5 59                  <1> 	pop	ecx ; *
   229 000057C6 720F                <1> 	jc	short loc_validate_next_hde_partition1
   230                              <1> loc_set_valid_hde_partition_entry:
   231                              <1> 	; 06/01/2016 (TRDOS v2.0)
   232                              <1> 	; BUGFIX *
   233                              <1> 	;mov	[esi+LD_PartitionEntry], cl 
   234                              <1> 	;mov	[esi+LD_DParamEntry], ch 
   235 000057C8 66894E7C            <1> 	mov	[esi+LD_PartitionEntry], cx 
   236                              <1> 	;
   237 000057CC 8A0D[07DE0000]      <1> 	mov	cl, [Last_DOS_DiskNo] 
   238 000057D2 80C141              <1> 	add	cl, 'A'
   239 000057D5 880E                <1> 	mov	[esi+LD_Name], cl
   240                              <1> loc_validate_next_hde_partition1:
   241 000057D7 5E                  <1> 	pop	esi ; Extended partition table offset
   242                              <1> loc_validate_next_hde_partition2:
   243                              <1> 	; ESI = Extended partition table offset
   244                              <1> 	; DL = Hard disk drive number
   245 000057D8 FE0D[90260100]      <1> 	dec	byte [PP_Counter]
   246 000057DE 0F845EFFFFFF        <1> 	jz	continue_check_ep_next_disk
   247 000057E4 83C610              <1> 	add 	esi, 16 ; 10h
   248 000057E7 EBAA                <1> 	jmp	short loc_validate_hde_partition
   249                              <1> loc_validating_hd_partitions_ok:
   250 000057E9 A0[07DE0000]        <1> 	mov	al, [Last_DOS_DiskNo]
   251                              <1> loc_drv_init_retn:
   252 000057EE C3                  <1> 	retn
   253                              <1> 
   254                              <1> validate_hd_fat_partition:
   255                              <1> 	; 12/02/2016
   256                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
   257                              <1> 	; 07/08/2011
   258                              <1> 	; 23/07/2011
   259                              <1> 	; Input
   260                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   261                              <1> 	;   ESI = PartitionTable offset
   262                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
   263                              <1> 	;   EDI = 0 -> Primary Partition 
   264                              <1> 	;   byte [Last_DOS_DiskNo]
   265                              <1>  	; Output
   266                              <1> 	;  cf=0 -> Validated
   267                              <1> 	;   ESI = Logical dos drv desc. table
   268                              <1> 	;   EBX = FAT boot sector buffer
   269                              <1> 	;   byte [Last_DOS_DiskNo]
   270                              <1> 	;  cf=1 -> Not a valid FAT partition
   271                              <1> 	; EAX, EDX, ECX, EDI -> changed 
   272                              <1> 	
   273                              <1> 	;mov 	esi, PartitionTable
   274 000057EF 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
   275 000057F2 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition
   276                              <1> 	; 12/02/2016
   277                              <1> 	;jb	short loc_not_a_valid_fat_partition2
   278 000057F5 7305                <1>  	jnb	short vhdp_FAT16_32
   279                              <1> 	;
   280 000057F7 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)		
   281 000057FA 7519                <1> 	jne	short loc_not_a_valid_fat_partition1
   282                              <1> vhdp_FAT16_32:
   283 000057FC B002                <1> 	mov	al, 2
   284 000057FE 7417                <1> 	je	short loc_set_valid_hd_partition_params
   285 00005800 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
   286 00005803 7710                <1> 	ja	short loc_not_a_valid_fat_partition1
   287 00005805 7410                <1> 	je	short loc_set_valid_hd_partition_params
   288                              <1> 
   289 00005807 FEC0                <1> 	inc	al ; 3
   290 00005809 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
   291 0000580C 7409                <1> 	je	short loc_set_valid_hd_partition_params
   292 0000580E 7206                <1> 	jb	short loc_not_a_valid_fat_partition2
   293 00005810 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
   294 00005813 7402                <1> 	je	short loc_set_valid_hd_partition_params
   295                              <1> loc_not_a_valid_fat_partition1:
   296 00005815 F9                  <1> 	stc
   297                              <1> loc_not_a_valid_fat_partition2:
   298 00005816 C3                  <1> 	retn
   299                              <1> 
   300                              <1> loc_set_valid_hd_partition_params:
   301 00005817 FE05[07DE0000]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
   302                              <1> 	;
   303 0000581D 31DB                <1> 	xor	ebx, ebx
   304 0000581F 8A3D[07DE0000]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256	
   305 00005825 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   306                              <1> 	;
   307 0000582B C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   308 0000582F 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
   309                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
   310                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
   311 00005832 66894303            <1> 	mov	word [ebx+LD_FATType], ax
   312                              <1> 	;
   313 00005836 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
   314 00005839 09FF                <1> 	or	edi, edi 
   315 0000583B 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
   316                              <1> loc_add_hd_FAT_ep_start_sector:
   317 0000583D 030F                <1> 	add	ecx, [edi]
   318                              <1> pass_hd_FAT_ep_start_sector_adding:
   319 0000583F 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
   320                              <1> loc_hd_FAT_logical_drv_init:
   321 00005842 89DD                <1> 	mov	ebp, ebx
   322                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   323 00005844 A0[8F260100]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
   324 00005849 884305              <1> 	mov	[ebx+LD_LBAYes], al
   325 0000584C BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   326 00005851 08C0                <1> 	or	al, al
   327 00005853 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
   328                              <1> loc_hd_FAT_drv_init_load_bs_lba:
   329                              <1> 	; DL = Physical drive number
   330                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
   331                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   332                              <1> 	; LBA read/write (with private LBA function) 
   333                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   334                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   335 00005855 B41B                <1> 	mov	ah, 1Bh ; LBA read
   336 00005857 B001                <1> 	mov	al, 1 ; sector count
   337 00005859 E817E4FFFF          <1> 	call	int13h
   338 0000585E 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
   339                              <1> loc_not_a_valid_fat_partition3:
   340 00005860 C3                  <1> 	retn
   341                              <1> loc_hd_FAT_drv_init_load_bs_chs:
   342 00005861 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   343 00005864 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   344 00005868 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   345                              <1> 	;mov	ebx, DOSBootSectorBuff
   346 0000586C E804E4FFFF          <1> 	call	int13h
   347 00005871 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
   348                              <1> loc_hd_drv_FAT_boot_validation:
   349                              <1> 	;mov	esi, DOSBootSectorBuff
   350 00005873 89DE                <1> 	mov	esi, ebx
   351 00005875 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   352 0000587E 751A                <1> 	jne	short loc_not_a_valid_fat_partition4
   353 00005880 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
   354 00005884 7514                <1> 	jne	short loc_not_a_valid_fat_partition4
   355 00005886 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
   356 0000588B 770F                <1> 	ja	short loc_hd_FAT16_BPB
   357 0000588D 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
   358 00005891 7507                <1> 	jne	short loc_not_a_valid_fat_partition4
   359                              <1> loc_hd_FAT32_BPB:
   360 00005893 B92D000000          <1> 	mov	ecx, 45
   361 00005898 EB0D                <1> 	jmp	short loc_hd_move_FAT_BPB
   362                              <1> 	;
   363                              <1> loc_not_a_valid_fat_partition4:
   364 0000589A F9                  <1> 	stc
   365 0000589B C3                  <1> 	retn
   366                              <1> 	;
   367                              <1> loc_hd_FAT16_BPB:
   368 0000589C 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
   369 000058A0 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
   370 000058A2 B920000000          <1> 	mov	ecx, 32
   371                              <1> loc_hd_move_FAT_BPB:
   372 000058A7 89EF                <1> 	mov 	edi, ebp
   373                              <1> 	;mov	esi, ebx ; Boot sector
   374 000058A9 57                  <1> 	push	edi
   375 000058AA 83C706              <1> 	add	edi, LD_BPB
   376 000058AD F366A5              <1> 	rep	movsw 
   377 000058B0 5E                  <1> 	pop	esi
   378 000058B1 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
   379 000058B5 03466C              <1> 	add	eax, [esi+LD_StartSector]
   380 000058B8 894660              <1> 	mov	[esi+LD_FATBegin], eax
   381 000058BB 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
   382 000058BF 7224                <1> 	jb	short loc_set_FAT16_RootDirLoc
   383                              <1> loc_set_FAT32_RootDirLoc:
   384 000058C1 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
   385 000058C4 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
   386 000058C8 F7E3                <1> 	mul	ebx
   387 000058CA 034660              <1> 	add	eax, [esi+LD_FATBegin]
   388                              <1> loc_set_FAT32_data_begin:
   389 000058CD 894668              <1> 	mov	[esi+LD_DATABegin], eax
   390 000058D0 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   391                              <1> 	; If Root Directory Cluster <> 2 then
   392                              <1> 	; change the beginning sector value 
   393                              <1> 	; of the root dir by adding sector offset.
   394 000058D3 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
   395 000058D6 83E802              <1> 	sub	eax, 2
   396 000058D9 7442                <1> 	jz	short short loc_set_32bit_FAT_total_sectors  
   397                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
   398 000058DB 8A5E13              <1> 	mov	bl, byte [esi+LD_BPB+BPB_SecPerClust] 
   399 000058DE F7E3                <1> 	mul	ebx
   400 000058E0 014664              <1> 	add	[esi+LD_ROOTBegin], eax
   401 000058E3 EB38                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
   402                              <1> 	;
   403                              <1> loc_set_FAT16_RootDirLoc:
   404 000058E5 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
   405 000058E9 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
   406 000058ED F7E2                <1> 	mul	edx
   407 000058EF 034660              <1> 	add	eax, [esi+LD_FATBegin]  
   408 000058F2 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   409                              <1> loc_set_FAT16_data_begin:
   410 000058F5 894668              <1> 	mov	[esi+LD_DATABegin], eax 
   411 000058F8 B820000000          <1> 	mov	eax, 20h  ; Size of a directory entry
   412                              <1> 	;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
   413 000058FD 668B5617            <1>         mov     dx, [esi+LD_BPB+BPB_RootEntCnt]
   414 00005901 F7E2                <1>         mul	edx
   415                              <1> 	;mov	ecx, 511
   416 00005903 66B9FF01            <1> 	mov	cx, 511
   417 00005907 01C8                <1> 	add	eax, ecx
   418 00005909 41                  <1> 	inc	ecx ; 512
   419 0000590A F7F1                <1> 	div	ecx
   420 0000590C 014668              <1> 	add	[esi+LD_DATABegin], eax
   421 0000590F 0FB74619            <1> 	movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
   422 00005913 6685C0              <1> 	test	ax, ax
   423 00005916 7405                <1> 	jz	short loc_set_32bit_FAT_total_sectors
   424                              <1> loc_set_16bit_FAT_total_sectors:
   425 00005918 894670              <1> 	mov	[esi+LD_TotalSectors], eax
   426 0000591B EB06                <1> 	jmp	short loc_set_hd_FAT_cluster_count
   427                              <1> loc_set_32bit_FAT_total_sectors:
   428 0000591D 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
   429 00005920 894670              <1> 	mov	[esi+LD_TotalSectors], eax
   430                              <1> loc_set_hd_FAT_cluster_count:
   431 00005923 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
   432 00005926 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
   433 00005929 29D0                <1> 	sub	eax, edx
   434 0000592B 31D2                <1> 	xor	edx, edx ; 0
   435 0000592D 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
   436 00005931 F7F1                <1>         div	ecx 
   437 00005933 894678              <1> 	mov	[esi+LD_Clusters], eax
   438                              <1> 	; Maximum Valid Cluster Number= EAX +1
   439                              <1> 	; with 2 reserved clusters= EAX +2
   440                              <1> loc_set_hd_FAT_fs_free_sectors:
   441                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
   442 00005936 E859010000          <1> 	call	get_free_FAT_sectors
   443 0000593B 7207                <1> 	jc	short loc_validate_hd_FAT_partition_retn
   444 0000593D 894674              <1> 	mov	[esi+LD_FreeSectors], eax
   445 00005940 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
   446                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
   447                              <1> 	;add	cl, 'A'
   448                              <1> 	;mov	[esi+LD_FS_Name], cl
   449                              <1> 
   450                              <1> loc_validate_hd_FAT_partition_retn:         
   451 00005944 C3                  <1> 	retn
   452                              <1> 
   453                              <1> validate_hd_fs_partition:
   454                              <1> 	; 13/02/2016
   455                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   456                              <1> 	; 29/01/2011
   457                              <1> 	; 23/07/2011
   458                              <1> 	; Input
   459                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   460                              <1> 	;   ESI = PartitionTable offset
   461                              <1> 	;   byte [Last_DOS_DiskNo]
   462                              <1> 	; Output
   463                              <1> 	;  cf=0 -> Validated
   464                              <1> 	;   ESI = Logical dos drv desc. table
   465                              <1> 	;   EBX = Singlix FS boot sector buffer
   466                              <1> 	;   byte [Last_DOS_DiskNo]
   467                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
   468                              <1> 	; EAX, EDX, ECX, EDI -> changed 
   469                              <1> 
   470                              <1> 	;mov	esi, PartitionTable
   471 00005945 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
   472 00005948 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
   473 0000594B 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   474                              <1> loc_set_valid_hd_fs_partition_params:
   475 0000594D FE05[07DE0000]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
   476 00005953 30C0                <1> 	xor	al, al ; mov al, 0
   477                              <1> 	;mov	[drv], dl
   478 00005955 29DB                <1> 	sub	ebx, ebx ; 0
   479 00005957 8A3D[07DE0000]      <1> 	mov	bh, [Last_DOS_DiskNo] 
   480 0000595D 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   481 00005963 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   482 00005967 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
   483                              <1> 	;mov	[ebx+LD_FATType], al ; 0
   484                              <1> 	;mov	[ebx+LD_FSType], ah
   485 0000596A 66894303            <1> 	mov	[ebx+LD_FATType], ax
   486                              <1> 	;mov	eax, [esi+ptStartSector]
   487                              <1> 	;mov	[ebx+LD_StartSector], eax
   488                              <1> loc_hd_fs_logical_drv_init:
   489 0000596E 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
   490                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   491 00005970 A0[8F260100]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
   492 00005975 884305              <1> 	mov	[ebx+LD_LBAYes], al
   493 00005978 89DE                <1> 	mov	esi, ebx
   494 0000597A BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   495 0000597F 08C0                <1> 	or	al, al
   496 00005981 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
   497                              <1> loc_hd_fs_drv_init_load_bs_chs:
   498 00005983 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   499 00005986 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   500 0000598A 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   501                              <1> 	;mov	ebx, DOSBootSectorBuff
   502 0000598E E8E2E2FFFF          <1> 	call	int13h
   503 00005993 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
   504                              <1> loc_validate_hd_fs_partition_err_retn:
   505 00005995 C3                  <1> 	retn
   506                              <1> loc_validate_hd_fs_partition_stc_retn:
   507 00005996 F9                  <1> 	stc
   508 00005997 C3                  <1> 	retn
   509                              <1> loc_hd_fs_drv_init_load_bs_lba:
   510                              <1> 	; DL = Physical drive number
   511                              <1> 	;mov	esi, ebx
   512 00005998 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
   513                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   514                              <1> 	; LBA read/write (with private LBA function) 
   515                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   516                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   517 0000599B B41B                <1> 	mov	ah, 1Bh ; LBA read
   518 0000599D B001                <1> 	mov	al, 1 ; sector count
   519 0000599F E8D1E2FFFF          <1> 	call	int13h
   520 000059A4 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
   521                              <1> loc_hd_drv_fs_boot_validation:
   522                              <1> 	;mov	esi, DOSBootSectorBuff
   523 000059A6 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
   524 000059A8 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   525 000059B1 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   526                              <1>         ;
   527                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
   528 000059B3 66817E035346        <1> 	cmp	word [esi+bs_FS_Identifier], 'SF'
   529 000059B9 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   530                              <1>         ;'A1h' check is not necessary
   531                              <1> 	;  if 'FS' check is passed as OK/Yes.
   532 000059BB 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
   533 000059BF 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   534                              <1> 	;
   535 000059C1 89EF                <1> 	mov	edi, ebp ; 10/01/2016
   536                              <1> 	;
   537 000059C3 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
   538 000059C6 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
   539                              <1> 	;
   540                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
   541 000059C9 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
   542 000059CC 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
   543                              <1> 	;
   544 000059CF 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
   545 000059D2 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
   546                              <1> 	;
   547 000059D5 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
   548 000059D9 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
   549 000059DD 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
   550 000059E0 6698                <1> 	cbw
   551 000059E2 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
   552 000059E6 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
   553                              <1> 	;cbw
   554 000059E9 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
   555                              <1> 	;
   556 000059ED 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
   557 000059F0 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
   558 000059F3 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
   559 000059F6 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
   560 000059F9 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
   561 000059FC 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
   562 000059FF 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
   563 00005A02 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
   564 00005A05 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
   565 00005A08 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
   566                              <1> 	;
   567 00005A0B 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
   568 00005A0D 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   569 00005A10 89FE                <1> 	mov	esi, edi
   570                              <1> mread_hd_fs_MAT_sector:
   571                              <1>        ;mov	ebx, DOSBootSectorBuff
   572 00005A12 B901000000          <1> 	mov	ecx, 1
   573 00005A17 E800800000          <1> 	call	disk_read
   574 00005A1C 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
   575                              <1> 	; EDI will not be changed
   576 00005A1E 89DE                <1> 	mov	esi, ebx
   577                              <1> use_hdfs_mat_sector_params:
   578 00005A20 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
   579 00005A23 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
   580 00005A26 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
   581 00005A29 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
   582 00005A2C 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
   583 00005A2F 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
   584 00005A32 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
   585 00005A35 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
   586 00005A38 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
   587 00005A3B 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   588 00005A3E 89FE                <1> 	mov	esi, edi   
   589                              <1> read_hd_fs_RDT_sector:
   590 00005A40 BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff
   591                              <1> 	;mov	ecx, 1
   592 00005A45 B101                <1> 	mov	cl, 1
   593 00005A47 E8D07F0000          <1> 	call	disk_read
   594 00005A4C 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
   595                              <1> 	; EDI will not be changed
   596 00005A4E 89DE                <1> 	mov	esi, ebx
   597                              <1> use_hdfs_RDT_sector_params:
   598 00005A50 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
   599 00005A53 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
   600 00005A56 57                  <1> 	push	edi
   601                              <1> 	;mov	ecx, 16
   602 00005A57 B110                <1> 	mov	cl, 16
   603 00005A59 83C640              <1> 	add	esi, FS_RDT_VolumeName
   604 00005A5C 83C72C              <1> 	add	edi, LD_FS_VolumeName
   605 00005A5F F3A5                <1> 	rep	movsd ; 64 bytes
   606 00005A61 5E                  <1> 	pop	esi
   607                              <1> 		; Volume Name Reset
   608 00005A62 C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
   609                              <1> 	;
   610                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
   611                              <1> 	;add	cl, 'A'
   612                              <1> 	;mov	[esi+LD_FS_Name], cl
   613                              <1> 
   614                              <1> loc_validate_hd_fs_partition_retn:
   615 00005A66 C3                  <1> 	retn
   616                              <1> 
   617                              <1> load_masterboot:
   618                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   619                              <1> 	; 2005 - 2011
   620                              <1> 	; input -> DL = drive number
   621 00005A67 B40D                <1> 	mov	ah, 0Dh ; Alternate disk reset
   622 00005A69 E807E2FFFF          <1> 	call	int13h
   623 00005A6E 7301                <1> 	jnc	short pass_reset_error
   624                              <1> harddisk_error:
   625 00005A70 C3                  <1>   	retn
   626                              <1> pass_reset_error:
   627 00005A71 BB[8E220100]        <1> 	mov	ebx, MasterBootBuff
   628 00005A76 66B80102            <1> 	mov	ax, 0201h
   629 00005A7A 66B90100            <1> 	mov	cx, 1
   630 00005A7E 30F6                <1> 	xor	dh, dh
   631 00005A80 E8F0E1FFFF          <1>  	call	int13h
   632 00005A85 72E9                <1> 	jc	short harddisk_error
   633                              <1> 	;
   634 00005A87 66813D[8C240100]55- <1> 	cmp	word [MBIDCode], 0AA55h
   634 00005A8F AA                  <1>
   635 00005A90 7401                <1> 	je	short load_masterboot_ok
   636 00005A92 F9                  <1> 	stc
   637                              <1> load_masterboot_ok:
   638 00005A93 C3                  <1> 	retn
   639                              <1> 
   640                              <1> get_free_FAT_sectors:
   641                              <1> 	; 29/02/2016
   642                              <1> 	; 13/02/2016
   643                              <1> 	; 04/02/2016
   644                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
   645                              <1> 	; 11/07/2010
   646                              <1> 	; 21/06/2009
   647                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
   648                              <1> 	; OUTPUT: STC => Error
   649                              <1>         ;	cf = 0 and EAX = Free FAT sectors
   650                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
   651                              <1> 
   652 00005A94 31C0                <1> 	xor	eax, eax
   653                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
   654                              <1> 	
   655 00005A96 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
   656 00005A9A 7650                <1> 	jna	short loc_gfc_get_fat_free_clusters
   657                              <1> 
   658                              <1> 	; 29/02/2016
   659 00005A9C 48                  <1> 	dec	eax ; 0FFFFFFFFh
   660 00005A9D 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
   661 00005AA0 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
   662 00005AA3 40                  <1> 	inc	eax ; 0
   663                              <1> 	;
   664 00005AA4 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
   665 00005AA8 03466C              <1> 	add	eax, [esi+LD_StartSector]
   666                              <1> 
   667 00005AAB BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff
   668 00005AB0 B901000000          <1> 	mov	ecx, 1
   669 00005AB5 E8627F0000          <1>  	call	disk_read
   670 00005ABA 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
   671                              <1> retn_gfc_get_fsinfo_sec:
   672 00005ABC C3                  <1> 	retn
   673                              <1> 
   674                              <1> loc_gfc_check_fsinfo_signs:
   675 00005ABD BB[A2260100]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
   676 00005AC2 813B52526141        <1>         cmp     dword [ebx], 41615252h
   677 00005AC8 7520                <1> 	jne	short retn_gfc_get_fsinfo_stc
   678                              <1> 	;add	ebx, 484
   679                              <1> 	;cmp	dword [ebx], 61417272h
   680 00005ACA 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
   680 00005AD3 61                  <1>
   681 00005AD4 7514                <1> 	jne	short retn_gfc_get_fsinfo_stc
   682                              <1> 	;add	ebx, 4
   683                              <1> 	;mov	eax, [ebx]
   684 00005AD6 8B83E8010000        <1> 	mov	eax, [ebx+488]
   685                              <1> 	; 29/02/2016
   686 00005ADC 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
   687 00005ADF 8B93EC010000        <1> 	mov	edx,  [ebx+492] 
   688 00005AE5 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster
   689                              <1> 	;
   690 00005AE8 EB12                <1> 	jmp	short retn_from_get_free_fat32_clusters
   691                              <1> 
   692                              <1> retn_gfc_get_fsinfo_stc:
   693 00005AEA F9                  <1> 	stc
   694 00005AEB C3                  <1> 	retn
   695                              <1> 
   696                              <1> loc_gfc_get_fat_free_clusters:
   697                              <1> 	;mov	eax, 2
   698 00005AEC B002                <1> 	mov	al, 2
   699                              <1> 	;mov	[FAT_CurrentCluster], eax
   700                              <1> loc_gfc_loop_get_next_cluster:
   701 00005AEE E800500000          <1> 	call	get_next_cluster
   702 00005AF3 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
   703 00005AF5 21C0                <1> 	and	eax, eax
   704 00005AF7 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
   705                              <1>  
   706                              <1> retn_from_get_free_fat_clusters:
   707 00005AF9 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
   708                              <1> retn_from_get_free_fat32_clusters:
   709 00005AFC 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
   710 00005B00 F7E3                <1>       	mul	ebx
   711                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
   712                              <1> retn_get_free_sectors_calc:
   713 00005B02 C3                  <1> 	retn
   714                              <1> 
   715                              <1> loc_gfc_free_fat_clusters_cont:
   716 00005B03 09C0                <1> 	or	eax, eax
   717 00005B05 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
   718 00005B07 FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
   719                              <1>    
   720                              <1> loc_gfc_pass_inc_free_cluster_count:
   721                              <1> 	;mov	eax, [FAT_CurrentCluster]
   722 00005B0A 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
   723 00005B0C 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
   724 00005B0F 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
   725 00005B11 40                  <1> 	inc	eax
   726                              <1> 	;mov	[FAT_CurrentCluster], eax
   727 00005B12 EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
   728                              <1> 
   729                              <1> floppy_drv_init:
   730                              <1> 	; 06/07/2016
   731                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   732                              <1> 	; 24/07/2011
   733                              <1> 	; 04/07/2009
   734                              <1> 	; INPUT ->
   735                              <1> 	;	DL = Drive number (0,1)
   736                              <1> 	; OUTPUT ->
   737                              <1> 	;	BL = drive name
   738                              <1> 	;	BH = drive number
   739                              <1> 	;	ESI = Logical DOS drv description table
   740                              <1> 	;	EAX = Volume serial number
   741                              <1>  
   742 00005B14 BE[18ED0000]        <1> 	mov	esi, fd0_type ; 10/01/2016
   743 00005B19 BF00010900          <1> 	mov	edi, Logical_DOSDisks
   744 00005B1E 08D2                <1> 	or	dl, dl
   745 00005B20 7407                <1> 	jz	short loc_drv_init_fd0_fd1
   746 00005B22 81C700010000        <1> 	add	edi, 100h
   747 00005B28 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
   748                              <1> loc_drv_init_fd0_fd1:
   749 00005B29 C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
   750 00005B2D 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
   751                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
   752 00005B30 7221                <1> 	jb	short read_fd_boot_sector_retn
   753 00005B32 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
   754                              <1> read_fd_boot_sector:
   755 00005B35 30F6                <1> 	xor	dh, dh
   756 00005B37 B904000000          <1> 	mov	ecx, 4 ; Retry Count
   757                              <1> read_fd_boot_sector_again:
   758 00005B3C 51                  <1> 	push 	ecx
   759                              <1> 	;mov	cx, 1
   760 00005B3D B101                <1> 	mov	cl, 1
   761 00005B3F 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   762 00005B43 BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff
   763 00005B48 E828E1FFFF          <1> 	call	int13h
   764 00005B4D 59                  <1> 	pop	ecx
   765 00005B4E 7304                <1> 	jnc	short use_fd_boot_sector_params
   766 00005B50 E2EA                <1> 	loop	read_fd_boot_sector_again
   767                              <1> 
   768                              <1> read_fd_boot_sector_stc_retn:
   769 00005B52 F9                  <1> 	stc
   770                              <1> read_fd_boot_sector_retn:
   771 00005B53 C3                  <1> 	retn
   772                              <1> 
   773                              <1> use_fd_boot_sector_params:
   774                              <1> 	;mov	esi, DOSBootSectorBuff
   775 00005B54 89DE                <1> 	mov	esi, ebx
   776 00005B56 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   777 00005B5F 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
   778 00005B61 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
   779 00005B67 0F85A2000000        <1>         jne     use_fd_fatfs_boot_sector_params
   780                              <1> 	;
   781 00005B6D 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
   782 00005B70 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
   783                              <1> 	;
   784                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
   785 00005B73 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
   786 00005B76 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
   787                              <1> 	;
   788 00005B79 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
   789 00005B7C 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
   790 00005B7F 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
   791 00005B83 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
   792 00005B87 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
   793 00005B8A 6698                <1> 	cbw
   794 00005B8C 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
   795 00005B90 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
   796                              <1> 	;cbw
   797 00005B93 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
   798                              <1> 	;
   799 00005B97 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
   800 00005B9A 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
   801 00005B9D 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
   802 00005BA0 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
   803 00005BA3 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
   804 00005BA6 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
   805 00005BA9 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
   806 00005BAC 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
   807 00005BAF 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
   808 00005BB2 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
   809                              <1> 	;		
   810 00005BB5 89FE                <1> 	mov	esi, edi
   811 00005BB7 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
   812                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
   813                              <1> read_fd_MAT_sector_again:
   814                              <1> 	;mov	ebx, DOSBootSectorBuff
   815                              <1> 	;mov	ecx, 1
   816 00005BBA B101                <1> 	mov	cl, 1
   817 00005BBC E8617E0000          <1> 	call	chs_read
   818 00005BC1 89DE                <1> 	mov	esi, ebx
   819 00005BC3 7301                <1> 	jnc	short use_fdfs_mat_sector_params
   820                              <1> 	;jmp	short read_fd_boot_sector_retn
   821 00005BC5 C3                  <1> 	retn
   822                              <1> use_fdfs_mat_sector_params:
   823 00005BC6 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
   824 00005BC9 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
   825 00005BCC 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
   826 00005BCF 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
   827 00005BD2 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
   828 00005BD5 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
   829 00005BD8 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
   830 00005BDB 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
   831                              <1> 	;
   832 00005BDE 89FE                <1> 	mov	esi, edi
   833 00005BE0 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
   834                              <1> read_fd_RDT_sector_again:
   835                              <1> 	;mov	ebx, DOSBootSectorBuff
   836                              <1> 	;mov	cx, 1
   837 00005BE3 B101                <1> 	mov	cl, 1
   838 00005BE5 E8387E0000          <1> 	call	chs_read
   839 00005BEA 89DE                <1> 	mov	esi, ebx
   840 00005BEC 7220                <1> 	jc	short read_fd_RDT_sector_retn
   841                              <1> use_fdfs_RDT_sector_params:
   842 00005BEE 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
   843 00005BF1 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
   844 00005BF4 57                  <1> 	push	edi
   845                              <1> 	;mov	ecx, 16
   846 00005BF5 B110                <1> 	mov	cl, 16	
   847 00005BF7 83C640              <1> 	add	esi, FS_RDT_VolumeName
   848 00005BFA 83C72C              <1> 	add	edi, LD_FS_VolumeName
   849 00005BFD F3A5                <1> 	rep	movsd ; 64 bytes
   850 00005BFF 5E                  <1> 	pop	esi
   851 00005C00 C6460300            <1> 	mov	byte [esi+LD_FATType], 0
   852 00005C04 C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h  
   853 00005C08 E9A5000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
   854                              <1> 
   855                              <1> read_fd_RDT_sector_stc_retn:
   856 00005C0D F9                  <1> 	stc
   857                              <1> read_fd_RDT_sector_retn:
   858 00005C0E C3                  <1> 	retn
   859                              <1> 
   860                              <1> use_fd_fatfs_boot_sector_params:
   861 00005C0F 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
   862 00005C13 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
   863 00005C15 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
   864 00005C19 72F3                <1> 	jb	short read_fd_RDT_sector_retn
   865 00005C1B 57                  <1> 	push	edi
   866 00005C1C 83C706              <1> 	add	edi, LD_BPB
   867                              <1> 	;mov	ecx, 16
   868 00005C1F B110                <1> 	mov	cl, 16
   869 00005C21 F3A5                <1> 	rep	movsd ; 64 bytes 
   870 00005C23 5E                  <1> 	pop	esi
   871 00005C24 31C0                <1> 	xor	eax, eax
   872 00005C26 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
   873 00005C29 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
   874 00005C2D 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs] 
   875 00005C30 F7E1                <1>   	mul	ecx
   876                              <1> 	; edx = 0 !
   877 00005C32 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
   878 00005C36 66895660            <1> 	mov	[esi+LD_FATBegin], dx
   879                              <1> 	;add	eax, edx
   880 00005C3A 6601D0              <1> 	add	ax, dx
   881 00005C3D 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   882 00005C40 894668              <1> 	mov	[esi+LD_DATABegin], eax 
   883 00005C43 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
   884                              <1> 	;;shl	edx, 5 ; * 32 (Size of a directory entry)
   885                              <1> 	;shl	dx, 5
   886                              <1> 	;;add	edx, 511
   887                              <1> 	;add	dx, 511
   888                              <1> 	;;shr	edx, 9 ; edx = ((edx*32)+511) / 512
   889                              <1> 	;shr	dx, 9
   890 00005C47 6683C20F            <1> 	add	dx, 15 ; 06/07/2016 (+(512/32)-1)
   891 00005C4B 66C1EA04            <1> 	shr	dx, 4 ; / 16 (==16 entries per sector)
   892 00005C4F 015668              <1> 	add 	[esi+LD_DATABegin], edx ; + rd sectors
   893                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
   894 00005C52 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
   895 00005C56 894670              <1> 	mov	[esi+LD_TotalSectors], eax
   896 00005C59 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
   897                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
   898 00005C5C 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]  
   899 00005C5F 80F901              <1> 	cmp	cl, 1
   900 00005C62 7605                <1> 	jna	short save_fd_fatfs_cluster_count
   901                              <1> 	;sub	edx, edx
   902 00005C64 6629D2              <1> 	sub	dx, dx ; 0
   903                              <1> 	;sub	dl, dl ; 06/07/2016
   904 00005C67 F7F1                <1> 	div	ecx
   905                              <1> save_fd_fatfs_cluster_count:
   906 00005C69 894678              <1> 	mov	[esi+LD_Clusters], eax
   907                              <1> 
   908                              <1>       ; Maximum Valid Cluster Number = EAX +1
   909                              <1>       ; with 2 reserved clusters= EAX +2
   910                              <1>  
   911                              <1> reset_FAT_buffer_decriptors:
   912 00005C6C 29C0                <1> 	sub	eax, eax ; 0  
   913 00005C6E A2[A6280100]        <1> 	mov	[FAT_BuffValidData], al ; 0
   914 00005C73 A2[A7280100]        <1> 	mov	[FAT_BuffDrvName], al ; 0
   915 00005C78 A3[AA280100]        <1> 	mov	[FAT_BuffSector], eax ; 0
   916                              <1> 
   917                              <1> read_fd_FAT_sectors:
   918 00005C7D BB001C0900          <1>   	mov	ebx, FAT_Buffer
   919 00005C82 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
   920                              <1> 	;mov	ecx, 3
   921 00005C86 B103                <1> 	mov	cl, 3 ; 3 sectors
   922 00005C88 E8957D0000          <1> 	call	chs_read
   923 00005C8D 7240                <1> 	jc	short read_fd_FAT_sectors_retn
   924                              <1> use_fd_FAT_sectors:
   925 00005C8F 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
   926 00005C92 0441                <1> 	add	al, 'A' 
   927 00005C94 A2[A7280100]        <1> 	mov	[FAT_BuffDrvName], al 
   928 00005C99 C605[A6280100]01    <1>  	mov	byte [FAT_BuffValidData], 1
   929 00005CA0 E82B000000          <1> 	call	fd_init_calculate_free_clusters
   930 00005CA5 7228                <1> 	jc	short read_fd_FAT_sectors_retn
   931                              <1>   
   932                              <1> loc_use_fd_boot_sector_params_FAT:
   933 00005CA7 C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
   934 00005CAB C6460401            <1> 	mov	byte [esi+LD_FSType], 1
   935 00005CAF 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
   936                              <1> loc_cont_use_fd_boot_sector_params:
   937 00005CB2 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
   938 00005CB5 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
   939 00005CB8 88FB                <1> 	mov	bl, bh
   940 00005CBA 80C341              <1> 	add	bl, 'A'
   941 00005CBD 881E                <1> 	mov	byte [esi+LD_Name], bl
   942 00005CBF C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
   943 00005CC3 C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
   944 00005CC7 C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
   945 00005CCB C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
   946                              <1> 
   947                              <1> read_fd_FAT_sectors_retn:
   948 00005CCF C3                  <1> 	retn   
   949                              <1> 
   950                              <1> fd_init_calculate_free_clusters:
   951                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   952                              <1> 	; 04/07/2009
   953                              <1> 	; INPUT ->
   954                              <1> 	;     ESI = Logical DOS drive description table address
   955                              <1> 	; OUTPUT ->
   956                              <1> 	;    [ESI+LD_FreeSectors] will be set
   957                              <1> 	
   958 00005CD0 29C0                <1> 	sub	eax, eax
   959 00005CD2 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
   960 00005CD5 B002                <1> 	mov	al, 2 ; eax = 2
   961                              <1> 
   962                              <1> fd_init_loop_get_next_cluster:
   963 00005CD7 E830000000          <1> 	call	fd_init_get_next_cluster
   964 00005CDC 722D                <1> 	jc	short fd_init_calculate_free_clusters_retn
   965                              <1> 
   966                              <1> fd_init_free_fat_clusters:
   967                              <1> 	;cmp 	eax, 0
   968                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
   969                              <1> 	;and	eax, eax
   970                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
   971 00005CDE 6621C0              <1> 	and	ax, ax
   972 00005CE1 7504                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
   973                              <1> 	;inc	dword [esi+LD_FreeSectors]
   974 00005CE3 66FF4674            <1>         inc	word [esi+LD_FreeSectors]
   975                              <1>     
   976                              <1> fd_init_pass_inc_free_cluster_count:
   977                              <1>   	;mov	eax, [FAT_CurrentCluster]
   978 00005CE7 66A1[A2280100]      <1> 	mov	ax, [FAT_CurrentCluster]
   979                              <1> 	;cmp	eax, [esi+LD_Clusters]
   980 00005CED 663B4678            <1> 	cmp	ax, [esi+LD_Clusters]
   981 00005CF1 7704                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
   982                              <1> 	;inc	eax
   983 00005CF3 6640                <1> 	inc	ax
   984 00005CF5 EBE0                <1> 	jmp	short fd_init_loop_get_next_cluster
   985                              <1> 
   986                              <1> retn_from_fd_init_calculate_free_clusters:
   987 00005CF7 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
   988 00005CFA 3C01                <1>   	cmp	al, 1
   989 00005CFC 760D                <1> 	jna	short fd_init_calculate_free_clusters_retn
   990                              <1> 	;movzx	eax, al
   991 00005CFE 6698                <1> 	cbw
   992                              <1> 	;mov	ecx, [esi+LD_FreeSectors]
   993 00005D00 668B4E74            <1> 	mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
   994                              <1>   	;mul	ecx
   995 00005D04 66F7E1              <1> 	mul	cx
   996                              <1> 	;mov	[esi+LD_FreeSectors], eax
   997 00005D07 66894674            <1> 	mov	[esi+LD_FreeSectors], ax
   998                              <1> fd_init_calculate_free_clusters_retn:
   999 00005D0B C3                  <1> 	retn
  1000                              <1> 
  1001                              <1> fd_init_get_next_cluster:
  1002                              <1> 	; 04/02/2016
  1003                              <1> 	; 02/02/2016
  1004                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1005                              <1> 	; 04/07/2009
  1006                              <1> 	; INPUT ->
  1007                              <1> 	;    EAX = Current cluster
  1008                              <1> 	;    ESI = Logical DOS drive description table address
  1009                              <1> 	;    EDX = 0
  1010                              <1> 	; OUTPUT ->
  1011                              <1> 	;    EAX = Next cluster
  1012                              <1> 
  1013 00005D0C A3[A2280100]        <1> 	mov	[FAT_CurrentCluster], eax
  1014                              <1> fd_init_get_next_cluster_readnext:
  1015 00005D11 29D2                <1> 	sub	edx, edx ; 0
  1016 00005D13 BB00040000          <1>   	mov	ebx, 1024 ; 400h
  1017 00005D18 F7F3                <1>   	div	ebx
  1018                              <1>   	; EAX = Count of 3 FAT sectors
  1019                              <1>   	; EDX = Buffer entry index
  1020 00005D1A 89C1                <1> 	mov	ecx, eax
  1021                              <1> 	;mov	eax, 3
  1022 00005D1C B003                <1> 	mov	al, 3
  1023 00005D1E F7E2                <1> 	mul	edx ; Multiply by 3
  1024 00005D20 66D1E8              <1> 	shr	ax, 1 ; Divide by 2
  1025 00005D23 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
  1026 00005D25 81C3001C0900        <1> 	add	ebx, FAT_Buffer
  1027 00005D2B 89C8                <1> 	mov	eax, ecx
  1028                              <1> 	;mov	edx, 3
  1029 00005D2D 66BA0300            <1> 	mov	dx, 3
  1030 00005D31 F7E2                <1> 	mul	edx 
  1031                              <1>   	; EAX = FAT Beginning Sector
  1032                              <1> 	; EDX = 0
  1033 00005D33 8A0E                <1> 	mov	cl, [esi+LD_Name]
  1034                              <1> 	;cmp	byte [FAT_BuffValidData], 0
  1035                              <1> 	;jna	short fd_init_load_FAT_sectors0
  1036 00005D35 3A0D[A7280100]      <1> 	cmp	cl, [FAT_BuffDrvName]
  1037 00005D3B 751E                <1> 	jne	short fd_init_load_FAT_sectors0
  1038 00005D3D 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
  1039 00005D43 751C                <1> 	jne	short fd_init_load_FAT_sectors1
  1040                              <1> 	;mov	eax, [FAT_CurrentCluster]
  1041 00005D45 A0[A2280100]        <1> 	mov	al, [FAT_CurrentCluster]
  1042                              <1> 	;shr	eax, 1
  1043 00005D4A D0E8                <1> 	shr	al, 1
  1044 00005D4C 668B03              <1> 	mov	ax, [ebx]
  1045 00005D4F 7306                <1>   	jnc	short fd_init_gnc_even
  1046 00005D51 66C1E804            <1> 	shr	ax, 4
  1047                              <1> fd_init_gnc_clc_retn:
  1048 00005D55 F8                  <1> 	clc
  1049 00005D56 C3                  <1> 	retn
  1050                              <1> 
  1051                              <1> fd_init_gnc_even:
  1052 00005D57 80E40F              <1> 	and	ah, 0Fh
  1053 00005D5A C3                  <1> 	retn
  1054                              <1> 
  1055                              <1> fd_init_load_FAT_sectors0:
  1056 00005D5B 880D[A7280100]      <1> 	mov 	[FAT_BuffDrvName], cl
  1057                              <1> fd_init_load_FAT_sectors1:
  1058 00005D61 C605[A6280100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1059 00005D68 A3[AA280100]        <1> 	mov	[FAT_BuffSector], eax
  1060 00005D6D 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1061 00005D70 BB001C0900          <1>  	mov	ebx, FAT_Buffer
  1062                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
  1063 00005D75 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
  1064 00005D79 662B0D[AA280100]    <1> 	sub	cx, [FAT_BuffSector]
  1065                              <1>         ;cmp	ecx, 3
  1066 00005D80 6683F903            <1> 	cmp	cx, 3
  1067 00005D84 7605                <1> 	jna	short fdinit_pass_fix_sector_count_3
  1068                              <1> 	;mov	ecx, 3
  1069 00005D86 B903000000          <1> 	mov	ecx, 3
  1070                              <1> fdinit_pass_fix_sector_count_3:  
  1071 00005D8B E8927C0000          <1> 	call	chs_read
  1072 00005D90 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
  1073 00005D92 C605[A6280100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1074                              <1> 		; Drv not ready or read Error !
  1075 00005D99 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
  1076                              <1> 	;xor	edx, edx
  1077 00005D9E C3                  <1> 	retn
  1078                              <1> 
  1079                              <1> fd_init_FAT_sectors_no_load_error:
  1080 00005D9F C605[A6280100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1081 00005DA6 A1[A2280100]        <1> 	mov	eax, [FAT_CurrentCluster]
  1082 00005DAB E961FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
  1083                              <1> 
  1084                              <1> get_FAT_volume_name:
  1085                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1086                              <1> 	; 12/09/2009
  1087                              <1> 	; INPUT ->
  1088                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
  1089                              <1> 	;       BL = 0
  1090                              <1> 	; OUTPUT ->
  1091                              <1> 	;	CF = 0 -> ESI = Volume name address
  1092                              <1> 	; 	CF = 1 -> Root volume name not found
  1093                              <1> 
  1094                              <1> 	;mov 	ah, 0FFh
  1095                              <1> 	;mov 	al, [Last_Dos_DiskNo]
  1096                              <1> 	;cmp 	al, bh
  1097                              <1> 	;jb     short loc_gfvn_dir_load_err
  1098                              <1> 
  1099 00005DB0 89DE                <1> 	mov	esi, ebx
  1100 00005DB2 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
  1101 00005DB8 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1102 00005DBE 8A06                <1> 	mov     al, [esi+LD_Name]
  1103 00005DC0 8A6603              <1> 	mov     ah, [esi+LD_FATType]
  1104 00005DC3 80FC01              <1> 	cmp     ah, 1
  1105 00005DC6 7210                <1> 	jb    	short loc_gfvn_dir_load_err
  1106 00005DC8 3C41                <1> 	cmp 	al, 'A'
  1107 00005DCA 720C                <1> 	jb      short loc_gfvn_dir_load_err
  1108 00005DCC 80FC02              <1> 	cmp 	ah, 2 
  1109 00005DCF 7708                <1> 	ja      short get_FAT32_root_cluster
  1110                              <1> 	
  1111 00005DD1 E8784E0000          <1> 	call    load_FAT_root_directory
  1112 00005DD6 730B                <1> 	jnc     short loc_get_volume_name
  1113                              <1> 
  1114                              <1> loc_gfvn_dir_load_err:
  1115 00005DD8 C3                  <1> 	retn
  1116                              <1> 
  1117                              <1> get_FAT32_root_cluster:
  1118 00005DD9 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
  1119 00005DDC E8F84E0000          <1> 	call    load_FAT_sub_directory
  1120 00005DE1 7224                <1> 	jc	short loc_get_volume_name_retn
  1121                              <1> 
  1122                              <1> loc_get_volume_name:
  1123 00005DE3 BE00000800          <1>         mov     esi, Directory_Buffer
  1124 00005DE8 6631C9              <1> 	xor	cx, cx ; 0
  1125                              <1> check_root_volume_name:
  1126 00005DEB 8A06                <1> 	mov	al, [esi]
  1127 00005DED 08C0                <1> 	or      al, al
  1128 00005DEF 7416                <1> 	jz      short loc_get_volume_name_retn
  1129 00005DF1 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
  1130 00005DF5 7410                <1> 	je      short loc_get_volume_name_retn
  1131 00005DF7 663B0D[BB280100]    <1> 	cmp     cx, [DirBuff_LastEntry]
  1132 00005DFE 7308                <1> 	jnb     short pass_check_root_volume_name
  1133 00005E00 6641                <1> 	inc     cx
  1134 00005E02 83C620              <1> 	add     esi, 32
  1135 00005E05 EBE4                <1> 	jmp     short check_root_volume_name
  1136                              <1> 
  1137                              <1> loc_get_volume_name_retn:
  1138 00005E07 C3                  <1> 	retn
  1139                              <1>     
  1140                              <1> pass_check_root_volume_name:
  1141 00005E08 803D[B7280100]03    <1> 	cmp	byte [DirBuff_FATType], 3
  1142 00005E0F 7230                <1> 	jb	short loc_get_volume_name_retn_xor
  1143                              <1> 
  1144 00005E11 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1145 00005E16 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1146 00005E1B 31C0                <1> 	xor	eax, eax
  1147 00005E1D 8A25[B6280100]      <1> 	mov	ah, [DirBuff_DRV]
  1148 00005E23 80EC41              <1> 	sub	ah, 'A' 
  1149 00005E26 01C6                <1> 	add	esi, eax
  1150 00005E28 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
  1151 00005E2D E8C14C0000          <1> 	call	get_next_cluster
  1152 00005E32 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
  1153                              <1>   	
  1154 00005E34 83F801              <1> 	cmp     eax, 1
  1155 00005E37 F5                  <1> 	cmc
  1156 00005E38 C3                  <1> 	retn
  1157                              <1>   
  1158                              <1> loc_gfvn_load_FAT32_dir_cluster:
  1159 00005E39 E89B4E0000          <1> 	call	load_FAT_sub_directory
  1160 00005E3E 73A3                <1> 	jnc	short loc_get_volume_name
  1161 00005E40 C3                  <1> 	retn
  1162                              <1> 
  1163                              <1> loc_get_volume_name_retn_xor:
  1164 00005E41 31C0                <1> 	xor 	eax, eax
  1165 00005E43 C3                  <1> 	retn
  1166                              <1> 
  1167                              <1> get_media_change_status:
  1168                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1169                              <1> 	; 09/09/2009
  1170                              <1> 	; INPUT:
  1171                              <1> 	;     DL = Drive number (physical)
  1172                              <1> 	; OUTPUT: clc & AH = 6 media changed
  1173                              <1> 	;     clc & AH = 0 media not changed         
  1174                              <1> 	;     stc -> Drive not ready or an error 
  1175                              <1>   
  1176 00005E44 B416                <1> 	mov	ah, 16h
  1177 00005E46 E82ADEFFFF          <1>   	call	int13h
  1178 00005E4B 80FC06              <1> 	cmp	ah, 06h
  1179 00005E4E 7405                <1> 	je	short loc_gmc_status_retn
  1180 00005E50 08E4                <1> 	or	ah, ah
  1181 00005E52 7401                <1> 	jz	short loc_gmc_status_retn
  1182                              <1> loc_gmc_status_stc_retn:    
  1183 00005E54 F9                  <1> 	stc
  1184                              <1> loc_gmc_status_retn:
  1185 00005E55 C3                  <1> 	retn
  1920                                  %include 'trdosk3.s' ; 06/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk3.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 13/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 06/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; MAINPROG.ASM (09/11/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; MAINPROG.ASM [ TRDOS KERNEL - COMMAND EXECUTER SECTION - MAIN PROGRAM ]
    14                              <1> ; (c) 2004-2011  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/11/2011
    15                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ] Last Update: 09/11/2011
    16                              <1> ; DIR.ASM [ DIRECTORY FUNCTIONS ] Last Update: 09/10/2011
    17                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
    18                              <1> 
    19                              <1> change_current_drive:
    20                              <1> 	; 02/02/2016
    21                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
    22                              <1> 	; 18/08/2011
    23                              <1> 	; 09/09/2009
    24                              <1> 	; INPUT:
    25                              <1> 	;   DL = Logical DOS Drive Number
    26                              <1> 	; OUTPUT:
    27                              <1> 	;  cf=1 -> Not successful
    28                              <1> 	;   EAX = Error code
    29                              <1> 	;  cf=0 ->
    30                              <1> 	;   EAX = 0 (successful)
    31                              <1> 
    32 00005E56 31DB                <1> 	xor	ebx, ebx
    33 00005E58 88D7                <1> 	mov	bh, dl
    34                              <1> 
    35                              <1> 	;cmp	dl, 1
    36                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
    37                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
    38                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
    39                              <1> 
    40                              <1> loc_ccdrv_initial_media_change_check:
    41 00005E5A BE00010900          <1> 	mov	esi, Logical_DOSDisks
    42 00005E5F 01DE                <1> 	add	esi, ebx
    43                              <1> loc_ccdrv_dos_drive_name_check:
    44 00005E61 80FA02              <1> 	cmp	dl, 2
    45 00005E64 720F                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
    46                              <1> 
    47 00005E66 8A06                <1> 	mov	al, [esi+LD_Name]
    48 00005E68 2C41                <1> 	sub	al, 'A'
    49 00005E6A 38D0                <1> 	cmp	al, dl
    50 00005E6C 7407                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
    51                              <1> 
    52                              <1> loc_ccdrv_drive_not_ready_err:
    53 00005E6E B815000000          <1> 	mov	eax, 15h ; Drive not ready
    54                              <1> loc_change_current_drive_stc_retn:
    55 00005E73 F9                  <1> 	stc
    56 00005E74 C3                  <1> 	retn  
    57                              <1> 
    58                              <1> loc_ccdrv_dos_drive_name_check_ok:
    59 00005E75 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
    60 00005E78 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
    61 00005E7B 7450                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
    62                              <1> 
    63 00005E7D 80FA01              <1> 	cmp	dl, 1
    64 00005E80 7778                <1> 	ja	short loc_gmcs_init_drv_hd
    65                              <1> 
    66                              <1> loc_gmcs_init_drv_fd:
    67 00005E82 08E4                <1> 	or	ah, ah 
    68                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
    69 00005E84 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
    70                              <1> 
    71 00005E86 E8B9FFFFFF          <1> 	call	get_media_change_status
    72 00005E8B 72E1                <1> 	jc	short loc_ccdrv_drive_not_ready_err
    73                              <1> 
    74 00005E8D 20E4                <1> 	and	ah, ah
    75 00005E8F 7471                <1> 	jz	short loc_change_current_drv3
    76                              <1> 
    77 00005E91 80F406              <1> 	xor	ah, 6
    78 00005E94 75D8                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
    79                              <1> 
    80                              <1> loc_ccdrv_call_fd_init_check_vol_id:
    81 00005E96 E8440A0000          <1> 	call	get_volume_serial_number
    82 00005E9B 7308                <1> 	jnc	short loc_ccdrv_check_vol_serial
    83                              <1> 
    84                              <1> loc_ccdrv_call_fd_init:
    85 00005E9D E872FCFFFF          <1> 	call	floppy_drv_init
    86 00005EA2 7315                <1> 	jnc	short loc_reset_drv_fd_current_dir
    87                              <1> 
    88                              <1> loc_ccdrv_fdinit_fail_retn:
    89 00005EA4 C3                  <1> 	retn
    90                              <1> 
    91                              <1> loc_ccdrv_check_vol_serial:
    92 00005EA5 A3[84200100]        <1> 	mov	[Current_VolSerial], eax
    93                              <1> 	;mov	dl, bh
    94 00005EAA E865FCFFFF          <1> 	call	floppy_drv_init
    95 00005EAF 72F3                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
    96                              <1> 
    97 00005EB1 3B05[84200100]      <1> 	cmp	eax, [Current_VolSerial]
    98 00005EB7 7445                <1> 	je	short loc_change_current_drv2
    99                              <1> 
   100                              <1> loc_reset_drv_fd_current_dir:
   101 00005EB9 31C0                <1> 	xor	eax, eax              
   102 00005EBB 88467F              <1>         mov	[esi+LD_CDirLevel], al
   103 00005EBE 89F7                <1> 	mov	edi, esi
   104 00005EC0 81C780000000        <1> 	add	edi, LD_CurrentDirectory
   105 00005EC6 B920000000          <1> 	mov	ecx, 32
   106 00005ECB F3AB                <1> 	rep	stosd   
   107                              <1>  
   108                              <1> loc_ccdrv_get_FAT_volume_name_0:
   109 00005ECD 8A4603              <1> 	mov	al, [esi+LD_FATType]
   110 00005ED0 08C0                <1> 	or	al, al
   111 00005ED2 742A                <1> 	jz	short loc_change_current_drv2
   112                              <1> 
   113 00005ED4 56                  <1> 	push	esi 
   114 00005ED5 3C02                <1> 	cmp	al, 2
   115 00005ED7 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
   116                              <1>              
   117                              <1> loc_ccdrv_get_FAT2_16_vol_name:
   118 00005ED9 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
   119 00005EDC EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
   120                              <1> 
   121                              <1> loc_ccdrv_get_FAT32_vol_name:
   122 00005EDE 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
   123                              <1> loc_ccdrv_get_FAT_volume_name_1:
   124 00005EE1 53                  <1> 	push	ebx
   125 00005EE2 56                  <1> 	push	esi
   126 00005EE3 E8C8FEFFFF          <1> 	call	get_FAT_volume_name
   127 00005EE8 5F                  <1> 	pop	edi
   128 00005EE9 5B                  <1> 	pop	ebx
   129                              <1> 	; BL = 0
   130 00005EEA 720B                <1> 	jc	short loc_change_current_drv1
   131 00005EEC 20C0                <1> 	and	al, al
   132 00005EEE 7407                <1> 	jz	short loc_change_current_drv1
   133                              <1> 
   134                              <1> loc_ccdrv_move_FAT_volume_name:
   135 00005EF0 B90B000000          <1> 	mov	ecx, 11
   136 00005EF5 F3A4                <1> 	rep	movsb
   137                              <1> 
   138                              <1> loc_change_current_drv1:
   139 00005EF7 5E                  <1> 	pop	esi
   140 00005EF8 EB04                <1> 	jmp	short loc_change_current_drv2
   141                              <1> 
   142                              <1> loc_gmcs_init_drv_hd:
   143 00005EFA 08E4                <1> 	or	ah, ah
   144 00005EFC 7404                <1> 	jz	short loc_change_current_drv3
   145                              <1> 	; BL = 0, BH = Logical DOS drive number
   146                              <1> loc_change_current_drv2:
   147 00005EFE C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
   148                              <1> loc_change_current_drv3:
   149 00005F02 883D[8E200100]      <1> 	mov	[Current_Drv], bh
   150                              <1> 
   151                              <1> 	;call	restore_current_directory
   152                              <1> 	;retn
   153                              <1> 
   154                              <1> restore_current_directory:
   155                              <1> 	; 11/02/2016
   156                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
   157                              <1> 	; 25/01/2010
   158                              <1> 	; 12/10/2009
   159                              <1> 	;
   160                              <1> 	; INPUT:
   161                              <1> 	;   ESI = Logical DOS Drive Description Table
   162                              <1> 	;
   163                              <1> 	; OUTPUT:
   164                              <1> 	;   ESI = Logical DOS Drive Description Table
   165                              <1> 	;   EDI = offset Current_Dir_Drv 
   166                              <1> 
   167 00005F08 8A4603              <1> 	mov	al, [esi+LD_FATType]
   168 00005F0B A2[8D200100]        <1> 	mov	[Current_FATType], al
   169                              <1> 
   170 00005F10 8A26                <1> 	mov	ah, [esi+LD_Name] 
   171 00005F12 8825[8F200100]      <1> 	mov	[Current_Dir_Drv], ah
   172                              <1> 
   173 00005F18 20C0                <1> 	and	al, al
   174 00005F1A 741D                <1> 	jz	short loc_restore_FS_current_directory
   175                              <1> 
   176                              <1> loc_restore_FAT_current_directory:
   177 00005F1C 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   178 00005F1F 8825[8C200100]      <1> 	mov	[Current_Dir_Level], ah
   179 00005F25 08E4                <1> 	or	ah, ah
   180 00005F27 7416                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
   181                              <1> 
   182 00005F29 0FB6D4              <1> 	movzx	edx, ah
   183 00005F2C C0E204              <1> 	shl	dl, 4 ; * 16
   184 00005F2F 01F2                <1>         add	edx, esi
   185 00005F31 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
   186 00005F37 EB2C                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
   187                              <1> 
   188                              <1> loc_restore_FS_current_directory:
   189 00005F39 E8D64D0000          <1> 	call	load_current_FS_directory 
   190 00005F3E C3                  <1> 	retn 
   191                              <1> 
   192                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
   193 00005F3F 3C03                <1> 	cmp	al, 3
   194 00005F41 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
   195                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
   196 00005F43 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   197 00005F46 EB04                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
   198                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
   199 00005F48 30C0                <1> 	xor	al, al  ; xor eax, eax
   200 00005F4A 31D2                <1> 	xor	edx, edx
   201                              <1> loc_ccdrv_check_rootdir_sign:
   202 00005F4C 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
   203 00005F53 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
   204                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
   205 00005F55 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
   206 00005F5B C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
   206 00005F64 54                  <1>
   207                              <1> 
   208                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
   209 00005F65 A3[88200100]        <1> 	mov	[Current_Dir_FCluster], eax
   210                              <1> 
   211 00005F6A BF[EF280100]        <1> 	mov	edi, PATH_Array
   212 00005F6F 89F2                <1> 	mov	edx, esi
   213 00005F71 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   214 00005F77 B920000000          <1> 	mov	ecx, 32
   215 00005F7C F3A5                <1> 	rep	movsd
   216                              <1> 
   217 00005F7E E8852D0000          <1> 	call	change_prompt_dir_string
   218                              <1> 	
   219 00005F83 89D6                <1> 	mov	esi, edx
   220                              <1> 	
   221 00005F85 29C0                <1>         sub	eax, eax
   222                              <1>        ;sub	edx, edx
   223 00005F87 BF[8F200100]        <1> 	mov	edi, Current_Dir_Drv
   224                              <1> 
   225 00005F8C A2[08DE0000]        <1> 	mov	[Restore_CDIR], al ; 0
   226 00005F91 C3                  <1> 	retn
   227                              <1> 
   228                              <1> dos_prompt:
   229                              <1> 	; 06/05/2016
   230                              <1> 	; 30/01/2016
   231                              <1> 	; 29/01/2016
   232                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   233                              <1> 	; 15/09/2011
   234                              <1> 	; 13/09/2009
   235                              <1> 	; 2004-2005
   236                              <1> 
   237                              <1> 	; 06/05/2016
   238 00005F92 C705[3C2D0100]-     <1> 	mov	dword [mainprog_return_addr], return_from_command_intepreter
   238 00005F98 [46600000]          <1>
   239                              <1> 
   240                              <1> loc_TRDOS_prompt:
   241 00005F9C BF[8E210100]        <1> 	mov	edi, TextBuffer
   242 00005FA1 C6075B              <1> 	mov	byte [edi], "["
   243 00005FA4 47                  <1> 	inc	edi
   244 00005FA5 BE[5BDE0000]        <1> 	mov	esi, TRDOSPromptLabel
   245                              <1> get_next_prompt_label_char:
   246 00005FAA 803E20              <1> 	cmp	byte [esi], 20h
   247 00005FAD 7203                <1> 	jb	short pass_prompt_label
   248 00005FAF A4                  <1> 	movsb
   249 00005FB0 EBF8                <1> 	jmp	short get_next_prompt_label_char
   250                              <1> pass_prompt_label:
   251 00005FB2 C6075D              <1> 	mov	byte [edi], "]"
   252 00005FB5 47                  <1> 	inc	edi
   253 00005FB6 C60720              <1> 	mov	byte [edi], 20h
   254 00005FB9 47                  <1> 	inc	edi
   255 00005FBA BE[8F200100]        <1> 	mov	esi, Current_Dir_Drv
   256 00005FBF 66A5                <1> 	movsw
   257 00005FC1 A4                  <1> 	movsb 
   258                              <1> loc_prompt_current_directory:
   259 00005FC2 803E20              <1> 	cmp	byte [esi], 20h
   260 00005FC5 7203                <1> 	jb	short pass_prompt_current_directory
   261 00005FC7 A4                  <1> 	movsb
   262 00005FC8 EBF8                <1> 	jmp	short loc_prompt_current_directory  
   263                              <1> pass_prompt_current_directory:
   264 00005FCA C6073E              <1> 	mov	byte [edi], '>'
   265 00005FCD 47                  <1> 	inc	edi
   266 00005FCE C60700              <1> 	mov	byte [edi], 0  
   267 00005FD1 BE[8E210100]        <1> 	mov	esi, TextBuffer
   268 00005FD6 E87BF5FFFF          <1> 	call	print_msg
   269                              <1>         
   270                              <1> 	;sub	bh, bh ; video page = 0
   271                              <1> 	;call	get_cpos ; get cursor position
   272 00005FDB 668B15[E61F0100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   273 00005FE2 8815[EE200100]      <1> 	mov	[CursorColumn], dl
   274                              <1> 
   275                              <1> 	; 30/01/2016 (to show cursor on the row, again)
   276                              <1> 	; (Initial color attributes of video page 0 is 0)
   277                              <1> 	; (see: 'StartPMP' in trdos386.s)
   278                              <1> 	; 
   279                              <1> 	;mov	edi, 0B8000h ; start of video page 0
   280                              <1> 	;movzx	ecx, dl ; column	 
   281                              <1> 	;mov	al, 80
   282                              <1> 	;mul	dh
   283                              <1> 	;add	ax, cx
   284                              <1> 	;shl	ax, 1 ; character + attribute
   285                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
   286                              <1> 	;neg	cl
   287                              <1> 	;add	cl, 80
   288                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
   289                              <1> 	;rep	stosw	
   290                              <1> 
   291                              <1> loc_rw_char:
   292 00005FE8 E899000000          <1> 	call	rw_char
   293                              <1> loc_move_command:
   294 00005FED BE[3E210100]        <1> 	mov	esi, CommandBuffer
   295 00005FF2 89F7                <1> 	mov	edi, esi
   296 00005FF4 31C9                <1> 	xor	ecx, ecx
   297                              <1> first_command_char:
   298 00005FF6 AC                  <1> 	lodsb
   299 00005FF7 3C20                <1> 	cmp	al, 20h
   300 00005FF9 772E                <1> 	ja	short pass_space_control
   301 00005FFB 7241                <1> 	jb	short loc_move_cmd_arguments_ok
   302 00005FFD 81FE[8D210100]      <1> 	cmp	esi, CommandBuffer + 79
   303 00006003 72F1                <1> 	jb	short first_command_char
   304 00006005 EB37                <1> 	jmp	short loc_move_cmd_arguments_ok
   305                              <1> 
   306                              <1> next_command_char:
   307 00006007 AC                  <1> 	lodsb
   308 00006008 3C20                <1> 	cmp	al, 20h
   309 0000600A 771D                <1> 	ja	short pass_space_control
   310 0000600C 7230                <1> 	jb	short loc_move_cmd_arguments_ok
   311                              <1> 
   312                              <1> loc_1st_cmd_arg: ; 30/01/2016
   313 0000600E AC                  <1> 	lodsb
   314 0000600F 3C20                <1> 	cmp	al, 20h
   315 00006011 74FB                <1> 	je	short loc_1st_cmd_arg
   316 00006013 7229                <1> 	jb	short loc_move_cmd_arguments_ok
   317                              <1> 	
   318 00006015 C60700              <1>         mov     byte [edi], 0
   319 00006018 47                  <1> 	inc	edi
   320                              <1> 
   321                              <1> loc_move_cmd_arguments:
   322 00006019 AA                  <1> 	stosb
   323 0000601A 81FE[8D210100]      <1> 	cmp	esi, CommandBuffer + 79
   324 00006020 731C                <1> 	jnb	short loc_move_cmd_arguments_ok
   325 00006022 AC                  <1>         lodsb
   326 00006023 3C20                <1> 	cmp	al, 20h
   327 00006025 73F2                <1> 	jnb	short loc_move_cmd_arguments
   328 00006027 EB15                <1> 	jmp	short loc_move_cmd_arguments_ok
   329                              <1> 
   330                              <1> pass_space_control:
   331 00006029 3C61                <1> 	cmp	al, 61h
   332 0000602B 7206                <1> 	jb	short pass_capitalize
   333 0000602D 3C7A                <1> 	cmp	al, 7Ah
   334 0000602F 7702                <1> 	ja	short pass_capitalize
   335 00006031 24DF                <1> 	and	al, 0DFh
   336                              <1> pass_capitalize:
   337 00006033 AA                  <1> 	stosb   
   338 00006034 FEC1                <1> 	inc     cl
   339 00006036 81FE[8D210100]      <1>         cmp     esi, CommandBuffer + 79
   340 0000603C 72C9                <1> 	jb      short next_command_char 
   341                              <1> 
   342                              <1> loc_move_cmd_arguments_ok:
   343 0000603E C60700              <1>         mov     byte [edi], 0
   344                              <1>        
   345                              <1> call_command_intepreter:
   346 00006041 E8D4080000          <1> 	call    command_interpreter
   347                              <1> 
   348                              <1> return_from_command_intepreter:
   349 00006046 B950000000          <1>         mov	ecx, 80
   350                              <1> 	;mov	cx, 80
   351 0000604B BF[3E210100]        <1> 	mov	edi, CommandBuffer
   352 00006050 30C0                <1> 	xor	al, al
   353 00006052 F3AA                <1> 	rep	stosb
   354                              <1> 	;cmp	byte [Program_Exit], 0
   355                              <1> 	;ja	short loc_terminate_trdos
   356                              <1>         
   357                              <1> 	; 16/01/2016
   358 00006054 803D[06E90000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
   359 0000605B 741D                <1> 	je	short pass_set_txt_mode
   360                              <1> 
   361 0000605D E8ACB3FFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
   362                              <1> 
   363                              <1> loc_check_active_page:
   364 00006062 30C0                <1> 	xor	al, al
   365 00006064 3805[F61F0100]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
   366 0000606A 0F842CFFFFFF        <1>         je      loc_TRDOS_prompt 
   367                              <1> 	; AL = 0 = video page 0
   368 00006070 E876B7FFFF          <1> 	call	set_active_page
   369 00006075 E922FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
   370                              <1> 
   371                              <1> pass_set_txt_mode: 
   372 0000607A BE[ABEE0000]        <1> 	mov	esi, nextline
   373 0000607F E8D2F4FFFF          <1> 	call	print_msg
   374 00006084 EBDC                <1> 	jmp     short loc_check_active_page
   375                              <1> 
   376                              <1> rw_char:
   377                              <1> 	; 13/05/2016
   378                              <1> 	; 30/01/2016
   379                              <1> 	; 29/01/2016
   380                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   381                              <1> 	; 2004-2005
   382                              <1> 	
   383                              <1> 	; DH = cursor row, DL = cursor column
   384                              <1> 	; BH = 0 = video page number (active page)
   385                              <1> 
   386                              <1> 	;xor	bh, bh ; 0 = video page 0
   387                              <1> 
   388                              <1> readnextchar:
   389 00006086 30E4                <1> 	xor     ah, ah
   390 00006088 E83FAAFFFF          <1> 	call	int16h
   391 0000608D 20C0                <1> 	and	al, al
   392 0000608F 7434                <1> 	jz	short loc_arrow    
   393 00006091 3CE0                <1> 	cmp	al, 0E0h          
   394 00006093 7430                <1> 	je	short loc_arrow
   395 00006095 3C08                <1> 	cmp	al, 08h             
   396 00006097 7544                <1> 	jne	short char_return
   397                              <1> loc_back:
   398 00006099 3A15[EE200100]      <1> 	cmp	dl, [CursorColumn]
   399 0000609F 76E5                <1> 	jna     short readnextchar
   400                              <1> prev_column:
   401 000060A1 FECA                <1> 	dec	dl
   402                              <1> set_cursor_pos:
   403 000060A3 6652                <1> 	push	dx
   404                              <1> 	;xor	bh, bh ; 0 = video page 0
   405                              <1> 	; DH = Row, DL = Column
   406 000060A5 E80DBBFFFF          <1> 	call	_set_cpos ; 17/01/2016
   407 000060AA 665A                <1>         pop	dx
   408                              <1> 	;movzx	ebx, dl
   409 000060AC 88D3                <1> 	mov	bl, dl
   410 000060AE 2A1D[EE200100]      <1> 	sub	bl, [CursorColumn] 
   411 000060B4 B020                <1> 	mov	al, 20h
   412 000060B6 8883[3E210100]      <1> 	mov	[CommandBuffer+ebx], al
   413                              <1> 	;sub	bh, bh ; video page 0
   414                              <1> 	;mov	cx, 1
   415 000060BC B307                <1> 	mov	bl, 7 ; color attribute
   416 000060BE E8E5B9FFFF          <1> 	call	_write_c_current ; 17/01/2016
   417                              <1> 	;mov	dx, [CURSOR_POSN]
   418 000060C3 EBC1                <1> 	jmp	short readnextchar
   419                              <1> loc_arrow:    
   420 000060C5 80FC4B              <1> 	cmp	ah, 4Bh
   421 000060C8 74CF                <1> 	je	short loc_back
   422 000060CA 80FC53              <1> 	cmp	ah, 53h
   423 000060CD 74CA                <1> 	je      short loc_back
   424 000060CF 80FC4D              <1> 	cmp	ah, 4Dh
   425 000060D2 75B2                <1> 	jne	short readnextchar
   426 000060D4 80FA4F              <1> 	cmp	dl, 79
   427 000060D7 73AD                <1> 	jnb	short readnextchar
   428 000060D9 FEC2                <1> 	inc	dl
   429 000060DB EBC6                <1> 	jmp	short set_cursor_pos
   430                              <1> char_return:
   431 000060DD 0FB6DA              <1> 	movzx	ebx, dl
   432 000060E0 2A1D[EE200100]      <1> 	sub	bl, [CursorColumn] 
   433 000060E6 3C20                <1> 	cmp	al, 20h
   434 000060E8 7220                <1> 	jb	short loc_escape
   435 000060EA 8883[3E210100]      <1> 	mov	[CommandBuffer+ebx], al
   436 000060F0 80FA4F              <1> 	cmp	dl, 79
   437 000060F3 7391                <1> 	jnb	short readnextchar
   438 000060F5 66BB0700            <1> 	mov	bx, 7 ; color attribute
   439 000060F9 E823BAFFFF          <1> 	call	_write_tty
   440 000060FE 668B15[E61F0100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   441 00006105 E97CFFFFFF          <1>         jmp     readnextchar
   442                              <1> loc_escape:
   443 0000610A 3C1B                <1> 	cmp	al, 1Bh
   444 0000610C 7418                <1> 	je	short rw_char_retn
   445                              <1> 	;
   446 0000610E 3C0D                <1> 	cmp	al, 0Dh ; CR
   447 00006110 0F8570FFFFFF        <1>         jne     readnextchar
   448                              <1> 	; 13/05/2016
   449 00006116 66BB0700            <1> 	mov	bx, 7 ; attribute/color (bl)
   450                              <1> 		      ; video page 0 (bh=0)	
   451 0000611A E802BAFFFF          <1> 	call	_write_tty
   452                              <1> 	;mov	bx, 7  ; attribute/color
   453                              <1> 		      ; video page 0 (bh=0)
   454 0000611F B00A                <1> 	mov	al, 0Ah ; LF
   455 00006121 E8FBB9FFFF          <1> 	call	_write_tty
   456                              <1> rw_char_retn:
   457 00006126 C3                  <1> 	retn
   458                              <1> 
   459                              <1> show_date:
   460                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   461                              <1>         ; 2004-2005
   462                              <1> 
   463                              <1> 	;mov	ah, 04h
   464                              <1> 	;call	int1Ah
   465 00006127 E854F1FFFF          <1> 	call	RTC_40	; GET RTC DATE
   466                              <1> 
   467 0000612C 88D0                <1> 	mov	al, dl
   468 0000612E E890A9FFFF          <1>   	call	bcd_to_ascii
   469 00006133 66A3[50DF0000]      <1> 	mov	[Day], ax
   470                              <1> 
   471 00006139 88F0                <1> 	mov	al, dh
   472 0000613B E883A9FFFF          <1>   	call	bcd_to_ascii
   473 00006140 66A3[53DF0000]      <1> 	mov	[Month], ax
   474                              <1> 
   475 00006146 88E8                <1> 	mov	al, ch
   476 00006148 E876A9FFFF          <1>   	call	bcd_to_ascii
   477 0000614D 66A3[56DF0000]      <1> 	mov	[Century], ax
   478                              <1> 
   479 00006153 88C8                <1> 	mov	al, cl
   480 00006155 E869A9FFFF          <1>   	call	bcd_to_ascii
   481 0000615A 66A3[58DF0000]      <1> 	mov	word [Year], ax
   482                              <1> 
   483 00006160 BE[40DF0000]        <1> 	mov	esi, Msg_Show_Date
   484 00006165 E8ECF3FFFF          <1> 	call	print_msg
   485                              <1> 
   486 0000616A C3                  <1> 	retn
   487                              <1> 
   488                              <1> set_date:
   489                              <1> 	; 13/05/2016
   490                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   491                              <1>         ; 2004-2005
   492                              <1> 
   493 0000616B BE[24DF0000]        <1> 	mov	esi, Msg_Enter_Date
   494 00006170 E8E1F3FFFF          <1> 	call	print_msg
   495                              <1> 
   496                              <1> loc_enter_day_1:
   497 00006175 30E4                <1> 	xor     ah, ah
   498 00006177 E850A9FFFF          <1> 	call	int16h
   499                              <1> 	; AL = ASCII Code of the Character
   500 0000617C 3C0D                <1> 	cmp	al, 13
   501 0000617E 0F84B7010000        <1> 	je	loc_set_date_retn
   502 00006184 3C1B                <1> 	cmp	al, 27
   503 00006186 0F84AF010000        <1> 	je	loc_set_date_retn
   504 0000618C A2[50DF0000]        <1> 	mov	[Day], al
   505 00006191 3C30                <1> 	cmp	al, '0'
   506 00006193 0F82AD010000        <1> 	jb	loc_set_date_stc_0
   507 00006199 3C33                <1> 	cmp	al, '3'
   508 0000619B 0F87A5010000        <1> 	ja	loc_set_date_stc_0
   509                              <1> 	; 13/05/2016
   510                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   511                              <1> 		      ; video page 0 (bh)	
   512 000061A1 B307                <1> 	mov	bl, 7
   513 000061A3 E879B9FFFF          <1> 	call	_write_tty
   514                              <1> loc_enter_day_2:
   515 000061A8 30E4                <1> 	xor     ah, ah
   516 000061AA E81DA9FFFF          <1> 	call	int16h
   517                              <1> 	; AL = ASCII Code of the Character
   518 000061AF 3C1B                <1> 	cmp	al, 27
   519 000061B1 0F8484010000        <1>         je      loc_set_date_retn
   520 000061B7 A2[51DF0000]        <1> 	mov	[Day+1], al
   521 000061BC 3C30                <1> 	cmp	al, '0'
   522 000061BE 0F828C010000        <1>         jb      loc_set_date_stc_1
   523 000061C4 3C39                <1> 	cmp	al, '9'
   524 000061C6 0F8784010000        <1>         ja      loc_set_date_stc_1
   525 000061CC 803D[50DF0000]33    <1> 	cmp	byte [Day], '3'
   526 000061D3 7208                <1> 	jb	short pass_set_day_31
   527 000061D5 3C31                <1> 	cmp	al, '1'
   528 000061D7 0F8773010000        <1>         ja      loc_set_date_stc_1
   529                              <1> pass_set_day_31:
   530                              <1> 	; 13/05/2016
   531                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   532                              <1> 		      ; video page 0 (bh)	
   533 000061DD B307                <1> 	mov	bl, 7
   534 000061DF E83DB9FFFF          <1> 	call	_write_tty
   535                              <1> loc_enter_separator_1:
   536 000061E4 28E4                <1> 	sub     ah, ah ; 0
   537 000061E6 E8E1A8FFFF          <1> 	call	int16h
   538                              <1> 	; AL = ASCII Code of the Character
   539 000061EB 3C1B                <1> 	cmp	al, 27
   540 000061ED 0F8448010000        <1>         je      loc_set_date_retn
   541 000061F3 3C2D                <1> 	cmp	al, '-'
   542 000061F5 7408                <1> 	je	short pass_set_date_separator_1
   543 000061F7 3C2F                <1> 	cmp	al, '/'
   544 000061F9 0F856C010000        <1>         jne     loc_set_date_stc_2
   545                              <1> pass_set_date_separator_1:
   546                              <1> 	; 13/05/2016
   547                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   548                              <1> 		      ; video page 0 (bh)
   549 000061FF B307                <1> 	mov	bl, 7	
   550 00006201 E81BB9FFFF          <1> 	call	_write_tty
   551                              <1> loc_enter_month_1:
   552 00006206 30E4                <1> 	xor     ah, ah ; 0
   553 00006208 E8BFA8FFFF          <1> 	call	int16h
   554                              <1> 	; AL = ASCII Code of the Character
   555 0000620D 3C1B                <1> 	cmp	al, 27
   556 0000620F 0F8426010000        <1>         je      loc_set_date_retn
   557 00006215 A2[53DF0000]        <1> 	mov	[Month], al
   558 0000621A 3C30                <1> 	cmp	al, '0'
   559 0000621C 0F8264010000        <1>         jb      loc_set_date_stc_3
   560 00006222 3C31                <1> 	cmp	al, '1'
   561 00006224 0F875C010000        <1>         ja      loc_set_date_stc_3
   562                              <1> 	; 13/05/2016
   563                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   564                              <1> 		      ; video page 0 (bh)	
   565 0000622A B307                <1> 	mov	bl, 7
   566 0000622C E8F0B8FFFF          <1> 	call	_write_tty
   567                              <1> loc_enter_month_2:
   568 00006231 30E4                <1> 	xor     ah, ah
   569 00006233 E894A8FFFF          <1> 	call	int16h
   570                              <1> 	; AL = ASCII Code of the Character
   571 00006238 3C1B                <1> 	cmp	al, 27
   572 0000623A 0F84FB000000        <1>         je      loc_set_date_retn
   573 00006240 A2[54DF0000]        <1> 	mov	[Month+1], al
   574 00006245 3C30                <1> 	cmp	al, '0'
   575 00006247 0F8254010000        <1>         jb      loc_set_date_stc_4
   576 0000624D 3C39                <1> 	cmp	al, '9'
   577 0000624F 0F874C010000        <1>         ja      loc_set_date_stc_4
   578 00006255 803D[53DF0000]31    <1> 	cmp	byte [Month], '1'
   579 0000625C 7208                <1> 	jb	short pass_set_month_12
   580 0000625E 3C32                <1> 	cmp	al, '2'
   581 00006260 0F873B010000        <1>         ja      loc_set_date_stc_4
   582                              <1> pass_set_month_12:
   583                              <1> 	; 13/05/2016
   584                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   585                              <1> 		      ; video page 0 (bh)
   586 00006266 B307                <1> 	mov	bl, 7	
   587 00006268 E8B4B8FFFF          <1> 	call	_write_tty
   588                              <1> loc_enter_separator_2:
   589 0000626D 28E4                <1> 	sub     ah, ah
   590 0000626F E858A8FFFF          <1> 	call	int16h
   591                              <1> 	; AL = ASCII Code of the Character
   592 00006274 3C1B                <1> 	cmp	al, 27
   593 00006276 0F84BF000000        <1>         je      loc_set_date_retn
   594 0000627C 3C2D                <1> 	cmp	al, '-'
   595 0000627E 7408                <1> 	je	short pass_set_date_separator_2
   596 00006280 3C2F                <1> 	cmp	al, '/'
   597 00006282 0F8534010000        <1>         jne     loc_set_date_stc_5
   598                              <1> pass_set_date_separator_2:
   599                              <1> 	; 13/05/2016
   600                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   601                              <1> 		      ; video page 0 (bh)	
   602 00006288 B307                <1> 	mov	bl, 7
   603 0000628A E892B8FFFF          <1> 	call	_write_tty
   604                              <1> loc_enter_year_1:
   605 0000628F 30E4                <1> 	xor    ah, ah
   606 00006291 E836A8FFFF          <1> 	call	int16h
   607                              <1> 	; AL = ASCII Code of the Character
   608 00006296 3C1B                <1> 	cmp	al, 27
   609 00006298 0F849D000000        <1>         je      loc_set_date_retn
   610 0000629E A2[58DF0000]        <1> 	mov	[Year], al
   611 000062A3 3C30                <1> 	cmp	al, '0'
   612 000062A5 0F822C010000        <1>         jb      loc_set_date_stc_6
   613 000062AB 3C39                <1> 	cmp	al, '9'
   614 000062AD 0F8724010000        <1>         ja      loc_set_date_stc_6
   615                              <1> 	; 13/05/2016
   616                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   617                              <1> 		      ; video page 0 (bh)
   618 000062B3 B307                <1> 	mov	bl, 7	
   619 000062B5 E867B8FFFF          <1> 	call	_write_tty
   620                              <1> loc_enter_year_2:
   621 000062BA 30E4                <1> 	xor	ah, ah
   622 000062BC E80BA8FFFF          <1> 	call	int16h
   623                              <1> 	; AL = ASCII Code of the Character
   624 000062C1 3C1B                <1> 	cmp	al, 27
   625 000062C3 7476                <1> 	je	short loc_set_date_retn
   626 000062C5 A2[59DF0000]        <1> 	mov	byte [Year+1], al
   627 000062CA 3C30                <1> 	cmp	al, '0'
   628 000062CC 0F8220010000        <1>         jb      loc_set_date_stc_7
   629 000062D2 3C39                <1> 	cmp	al, '9'
   630 000062D4 0F8718010000        <1>         ja      loc_set_date_stc_7
   631                              <1> 	; 13/05/2016
   632                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   633                              <1> 		      ; video page 0 (bh)
   634 000062DA B307                <1> 	mov	bl, 7	
   635 000062DC E840B8FFFF          <1> 	call	_write_tty
   636                              <1> loc_set_date_get_lchar_again:
   637 000062E1 28E4                <1> 	sub	ah, ah ; 0
   638 000062E3 E8E4A7FFFF          <1> 	call	int16h
   639                              <1> 	; AL = ASCII Code of the Character
   640 000062E8 3C0D                <1> 	cmp	al, 13 ; ENTER key
   641 000062EA 7412                <1> 	je	short loc_set_date_progress
   642 000062EC 3C1B                <1> 	cmp	al, 27 ; ESC key
   643 000062EE 744B                <1> 	je	short loc_set_date_retn
   644                              <1> 	;
   645 000062F0 E82A010000          <1> 	call	check_for_backspace
   646 000062F5 75EA                <1> 	jne	short loc_set_date_get_lchar_again
   647                              <1> 
   648                              <1> loc_set_date_bs_8:
   649 000062F7 E811010000          <1> 	call	write_backspace
   650 000062FC EBBC                <1> 	jmp	short loc_enter_year_2
   651                              <1> 
   652                              <1> loc_set_date_progress:
   653                              <1> 	; Get Current Date
   654                              <1> 	;mov	ah, 04h
   655                              <1> 	;call	int1Ah
   656 000062FE E87DEFFFFF          <1> 	call	RTC_40	; GET RTC DATE
   657                              <1> 	; CH = century (in BCD)
   658                              <1> 
   659 00006303 66A1[58DF0000]      <1> 	mov	ax, [Year]
   660 00006309 662D3030            <1> 	sub	ax, '00'
   661 0000630D C0E004              <1> 	shl	al, 4 ; * 16
   662 00006310 88C1                <1> 	mov	cl, al
   663 00006312 00E1                <1> 	add	cl, ah
   664 00006314 66A1[53DF0000]      <1> 	mov	ax, [Month]
   665 0000631A 662D3030            <1> 	sub	ax, '00'
   666 0000631E C0E004              <1> 	shl	al, 4 ; * 16
   667 00006321 88C6                <1> 	mov	dh, al
   668 00006323 00E6                <1> 	add	dh, ah
   669 00006325 66A1[50DF0000]      <1> 	mov	ax, [Day]
   670 0000632B 662D3030            <1> 	sub	ax, '00'
   671 0000632F C0E004              <1> 	shl	al, 4 ; * 16
   672 00006332 88C2                <1> 	mov	dl, al
   673 00006334 00E2                <1> 	add	dl, ah
   674                              <1> 
   675                              <1> 	;mov	ah, 05h
   676                              <1> 	;call	int1Ah
   677 00006336 E872EFFFFF          <1> 	call	RTC_50	; SET RTC DATE
   678                              <1> 
   679                              <1> loc_set_date_retn:
   680 0000633B BE[ABEE0000]        <1> 	mov	esi, nextline
   681 00006340 E811F2FFFF          <1> 	call	print_msg
   682 00006345 C3                  <1> 	retn
   683                              <1> 
   684                              <1> loc_set_date_stc_0:
   685                              <1> 	;xor	bh, bh ; video page 0
   686 00006346 E8B6B8FFFF          <1> 	call	beeper ; BEEP !
   687 0000634B E925FEFFFF          <1>         jmp     loc_enter_day_1
   688                              <1> loc_set_date_stc_1:
   689 00006350 E8CA000000          <1> 	call	check_for_backspace
   690 00006355 740A                <1> 	je	short loc_set_date_bs_1
   691                              <1> 	;xor	bh, bh ; video page 0
   692 00006357 E8A5B8FFFF          <1> 	call	beeper ; BEEP !
   693 0000635C E947FEFFFF          <1>         jmp     loc_enter_day_2
   694                              <1> loc_set_date_bs_1:
   695 00006361 E8A7000000          <1> 	call	write_backspace
   696 00006366 E90AFEFFFF          <1>         jmp     loc_enter_day_1
   697                              <1> loc_set_date_stc_2:
   698 0000636B E8AF000000          <1> 	call	check_for_backspace
   699 00006370 740A                <1> 	je	short loc_set_date_bs_2
   700                              <1> 	;xor	bh, bh ; video page 0
   701 00006372 E88AB8FFFF          <1> 	call	beeper ; BEEP !
   702 00006377 E968FEFFFF          <1>         jmp     loc_enter_separator_1
   703                              <1> loc_set_date_bs_2:
   704 0000637C E88C000000          <1> 	call	write_backspace
   705 00006381 E922FEFFFF          <1>         jmp     loc_enter_day_2
   706                              <1> loc_set_date_stc_3:
   707 00006386 E894000000          <1> 	call	check_for_backspace	
   708 0000638B 740A                <1> 	je short loc_set_date_bs_3
   709                              <1> 	;xor	bh, bh ; video page 0
   710 0000638D E86FB8FFFF          <1> 	call	beeper ; BEEP !
   711 00006392 E96FFEFFFF          <1>         jmp     loc_enter_month_1
   712                              <1> loc_set_date_bs_3:
   713 00006397 E871000000          <1> 	call	write_backspace
   714 0000639C E943FEFFFF          <1>         jmp     loc_enter_separator_1
   715                              <1> loc_set_date_stc_4:
   716 000063A1 E879000000          <1> 	call	check_for_backspace	
   717 000063A6 740A                <1> 	je	short loc_set_date_bs_4
   718                              <1> 	;xor	bh, bh ; video page 0
   719 000063A8 E854B8FFFF          <1> 	call	beeper ; BEEP !
   720 000063AD E97FFEFFFF          <1>         jmp     loc_enter_month_2
   721                              <1> loc_set_date_bs_4:
   722 000063B2 E856000000          <1> 	call	write_backspace
   723 000063B7 E94AFEFFFF          <1>         jmp     loc_enter_month_1
   724                              <1> loc_set_date_stc_5:
   725 000063BC E85E000000          <1> 	call	check_for_backspace
   726 000063C1 740A                <1> 	je	short loc_set_date_bs_5
   727                              <1> 	;xor	bh, bh ; video page 0
   728 000063C3 E839B8FFFF          <1> 	call	beeper ; BEEP !
   729 000063C8 E9A0FEFFFF          <1>         jmp     loc_enter_separator_2
   730                              <1> loc_set_date_bs_5:
   731 000063CD E83B000000          <1> 	call	write_backspace
   732 000063D2 E95AFEFFFF          <1>         jmp     loc_enter_month_2
   733                              <1> loc_set_date_stc_6:
   734 000063D7 E843000000          <1> 	call	check_for_backspace
   735 000063DC 740A                <1>         je      short  loc_set_date_bs_6
   736                              <1> 	;xor	bh, bh ; video page 0
   737 000063DE E81EB8FFFF          <1> 	call	beeper ; BEEP !
   738 000063E3 E9A7FEFFFF          <1>         jmp     loc_enter_year_1
   739                              <1> loc_set_date_bs_6:
   740 000063E8 E820000000          <1> 	call	write_backspace
   741 000063ED E97BFEFFFF          <1>         jmp     loc_enter_separator_2
   742                              <1> loc_set_date_stc_7:
   743 000063F2 E828000000          <1> 	call	check_for_backspace
   744 000063F7 740A                <1> 	je	short loc_set_date_bs_7
   745                              <1> 	;xor	bh, bh ; video page 0
   746 000063F9 E803B8FFFF          <1> 	call	beeper ; BEEP !
   747 000063FE E9B7FEFFFF          <1>         jmp     loc_enter_year_2
   748                              <1> loc_set_date_bs_7:
   749 00006403 E805000000          <1> 	call	write_backspace
   750 00006408 E982FEFFFF          <1>         jmp     loc_enter_year_1
   751                              <1> 
   752                              <1> write_backspace:
   753                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   754 0000640D B008                <1> 	mov	al, 08h ; BACKSPACE
   755                              <1> 	; 13/05/2016
   756 0000640F 66BB0700            <1> 	mov	bx, 7 ; bl = attribute/color
   757                              <1> 		      ; bh = video page = 0	
   758 00006413 E809B7FFFF          <1> 	call	_write_tty
   759 00006418 B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
   760                              <1> 	;mov	bx, 7 ; attribute/color
   761                              <1> 	;call	_write_c_current
   762                              <1> 	;retn
   763 0000641A E989B6FFFF          <1> 	jmp	_write_c_current
   764                              <1> 
   765                              <1> check_for_backspace:
   766                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   767 0000641F 663D080E            <1> 	cmp	ax, 0E08h
   768 00006423 7410                <1> 	je	short cfbs_retn
   769 00006425 663DE04B            <1> 	cmp	ax, 4BE0h
   770 00006429 740A                <1> 	je	short cfbs_retn
   771 0000642B 663D004B            <1> 	cmp	ax, 4B00h
   772 0000642F 7404                <1> 	je	short cfbs_retn
   773 00006431 663DE053            <1> 	cmp	ax, 53E0h
   774                              <1> cfbs_retn:
   775 00006435 C3                  <1> 	retn
   776                              <1> 
   777                              <1> show_time:
   778                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   779                              <1>         ; 2004-2005
   780                              <1> 
   781                              <1> 	;mov	ah, 02h
   782                              <1> 	;call	int1Ah
   783 00006436 E8D4EDFFFF          <1> 	call	RTC_20	; GET RTC TIME
   784                              <1> 	
   785 0000643B 88E8                <1> 	mov	al, ch
   786 0000643D E881A6FFFF          <1> 	call	bcd_to_ascii
   787 00006442 66A3[7EDF0000]      <1> 	mov	[Hour], ax
   788                              <1> 
   789 00006448 88C8                <1> 	mov	al, cl
   790 0000644A E874A6FFFF          <1> 	call	bcd_to_ascii
   791 0000644F 66A3[81DF0000]      <1> 	mov	[Minute], ax
   792                              <1> 
   793 00006455 88F0                <1> 	mov	al, dh
   794 00006457 E867A6FFFF          <1> 	call	bcd_to_ascii
   795 0000645C 66A3[84DF0000]      <1> 	mov	[Second], ax
   796                              <1> 
   797 00006462 BE[6EDF0000]        <1> 	mov	esi, Msg_Show_Time
   798 00006467 E8EAF0FFFF          <1> 	call	print_msg
   799 0000646C C3                  <1> 	retn
   800                              <1> 
   801                              <1> set_time:
   802                              <1> 	; 13/05/2016
   803                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   804                              <1>         ; 2004-2005
   805                              <1> 
   806 0000646D BE[5DDF0000]        <1> 	mov 	esi, Msg_Enter_Time
   807 00006472 E8DFF0FFFF          <1> 	call	print_msg
   808                              <1> 
   809                              <1> loc_enter_hour_1:
   810 00006477 30E4                <1> 	xor     ah, ah
   811 00006479 E84EA6FFFF          <1> 	call	int16h
   812                              <1> 	; AL = ASCII Code of the Character
   813 0000647E 3C0D                <1> 	cmp	al, 13 ; ENTER key
   814 00006480 0F84AE010000        <1>         je      loc_set_time_retn
   815 00006486 3C1B                <1> 	cmp	al, 27 ; ESC key
   816 00006488 0F84A6010000        <1>         je      loc_set_time_retn
   817 0000648E A2[7EDF0000]        <1> 	mov	[Hour], al
   818 00006493 3C30                <1> 	cmp	al, '0'
   819 00006495 0F82A4010000        <1>         jb      loc_set_time_stc_0
   820 0000649B 3C32                <1> 	cmp	al, '2'
   821 0000649D 0F879C010000        <1>         ja      loc_set_time_stc_0
   822                              <1> 	; 13/05/2016
   823                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   824                              <1> 		      ; video page 0 (bh)
   825 000064A3 B307                <1> 	mov	bl, 7	
   826 000064A5 E877B6FFFF          <1> 	call	_write_tty
   827                              <1> loc_enter_hour_2:
   828 000064AA 30E4                <1> 	xor     ah, ah
   829 000064AC E81BA6FFFF          <1> 	call	int16h
   830                              <1> 	; AL = ASCII Code of the Character
   831 000064B1 3C1B                <1> 	cmp	al, 27
   832 000064B3 0F847B010000        <1>         je      loc_set_time_retn
   833 000064B9 A2[7FDF0000]        <1> 	mov	[Hour+1], al
   834 000064BE 3C30                <1> 	cmp	al, '0'
   835 000064C0 0F8283010000        <1>         jb      loc_set_time_stc_1
   836 000064C6 3C39                <1> 	cmp	al, '9'
   837 000064C8 0F877B010000        <1> 	ja	loc_set_time_stc_1
   838 000064CE 803D[7EDF0000]32    <1>         cmp     byte [Hour], '2'
   839 000064D5 7208                <1> 	jb	short pass_set_time_24
   840 000064D7 3C34                <1> 	cmp	al, '4'
   841 000064D9 0F876A010000        <1>         ja      loc_set_time_stc_1
   842                              <1> pass_set_time_24:
   843                              <1> 	; 13/05/2016
   844                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   845                              <1> 		      ; video page 0 (bh)
   846 000064DF B307                <1> 	mov	bl, 7	
   847 000064E1 E83BB6FFFF          <1> 	call	_write_tty
   848                              <1> loc_enter_time_separator_1:
   849 000064E6 28E4                <1> 	sub    ah, ah ; 0
   850 000064E8 E8DFA5FFFF          <1> 	call	int16h
   851                              <1> 	; AL = ASCII Code of the Character
   852 000064ED 3C1B                <1> 	cmp	al, 27
   853 000064EF 0F843F010000        <1>         je      loc_set_time_retn
   854 000064F5 3C3A                <1> 	cmp	al, ':'
   855 000064F7 0F8567010000        <1>         jne     loc_set_time_stc_2
   856                              <1> 	; 13/05/2016
   857                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   858                              <1> 		      ; video page 0 (bh)
   859 000064FD B307                <1> 	mov	bl, 7	
   860 000064FF E81DB6FFFF          <1> 	call	_write_tty
   861                              <1> loc_enter_minute_1:
   862 00006504 30E4                <1> 	xor     ah, ah
   863 00006506 E8C1A5FFFF          <1> 	call	int16h
   864                              <1> 	; AL = ASCII Code of the Character
   865 0000650B 3C1B                <1> 	cmp	al, 27
   866 0000650D 0F8421010000        <1>         je      loc_set_time_retn
   867 00006513 A2[81DF0000]        <1> 	mov	[Minute], al
   868 00006518 3C30                <1> 	cmp	al, '0'
   869 0000651A 0F825F010000        <1>         jb      loc_set_time_stc_3
   870 00006520 3C35                <1> 	cmp	al, '5'
   871 00006522 0F8757010000        <1>         ja      loc_set_time_stc_3
   872                              <1> 	; 13/05/2016
   873                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   874                              <1> 		      ; video page 0 (bh)
   875 00006528 B307                <1> 	mov	bl, 7	
   876 0000652A E8F2B5FFFF          <1> 	call	_write_tty
   877                              <1> loc_enter_minute_2:
   878 0000652F 30E4                <1> 	xor     ah, ah
   879 00006531 E896A5FFFF          <1> 	call	int16h
   880                              <1> 	; AL = ASCII Code of the Character
   881 00006536 3C1B                <1> 	cmp	al, 27
   882 00006538 0F84F6000000        <1>         je      loc_set_time_retn
   883 0000653E A2[82DF0000]        <1> 	mov	[Minute+1], al
   884 00006543 3C30                <1> 	cmp	al, '0'
   885 00006545 0F824F010000        <1>         jb      loc_set_time_stc_4
   886 0000654B 3C39                <1> 	cmp	al, '9'
   887 0000654D 0F8747010000        <1>         ja      loc_set_time_stc_4
   888                              <1> 	; 13/05/2016
   889                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   890                              <1> 		      ; video page 0 (bh)
   891 00006553 B307                <1> 	mov	bl, 7	
   892 00006555 E8C7B5FFFF          <1> 	call	_write_tty
   893                              <1> loc_enter_time_separator_2:
   894 0000655A 66C705[84DF0000]30- <1> 	mov	word [Second], 3030h
   894 00006562 30                  <1>
   895 00006563 28E4                <1> 	sub     ah, ah
   896 00006565 E862A5FFFF          <1> 	call	int16h
   897                              <1> 	; AL = ASCII Code of the Character
   898 0000656A 3C0D                <1> 	cmp	al, 13
   899 0000656C 0F8485000000        <1>         je      loc_set_time_progress
   900 00006572 3C1B                <1> 	cmp	al, 27
   901 00006574 0F84BA000000        <1>         je      loc_set_time_retn
   902 0000657A 3C3A                <1> 	cmp	al, ':'
   903 0000657C 0F8533010000        <1>         jne     loc_set_time_stc_5
   904                              <1> 	; 13/05/2016
   905                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   906                              <1> 		      ; video page 0 (bh)
   907 00006582 B307                <1> 	mov	bl, 7	
   908 00006584 E898B5FFFF          <1> 	call	_write_tty
   909                              <1> loc_enter_second_1:
   910 00006589 30E4                <1> 	xor     ah, ah
   911 0000658B E83CA5FFFF          <1> 	call	int16h
   912                              <1> 	; AL = ASCII Code of the Character
   913 00006590 3C0D                <1> 	cmp	al, 13
   914 00006592 7463                <1> 	je	short loc_set_time_progress
   915 00006594 3C1B                <1> 	cmp	al, 27
   916 00006596 0F8498000000        <1>         je      loc_set_time_retn
   917 0000659C A2[84DF0000]        <1> 	mov	[Second], al
   918 000065A1 3C30                <1> 	cmp	al, '0'
   919 000065A3 0F8227010000        <1>         jb      loc_set_time_stc_6
   920 000065A9 3C35                <1> 	cmp	al, '5'
   921 000065AB 0F871F010000        <1>         ja      loc_set_time_stc_6
   922                              <1> 	; 13/05/2016
   923                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   924                              <1> 		      ; video page 0 (bh)
   925 000065B1 B307                <1> 	mov	bl, 7	
   926 000065B3 E869B5FFFF          <1> 	call	_write_tty
   927                              <1> loc_enter_second_2:
   928 000065B8 30E4                <1> 	xor     ah, ah
   929 000065BA E80DA5FFFF          <1> 	call	int16h
   930                              <1> 	; AL = ASCII Code of the Character
   931 000065BF 3C1B                <1> 	cmp	al, 27
   932 000065C1 7471                <1> 	je	short loc_set_time_retn
   933 000065C3 3C30                <1> 	cmp	al, '0'
   934 000065C5 0F8229010000        <1>         jb      loc_set_time_stc_7
   935 000065CB 3C39                <1> 	cmp	al, '9'
   936 000065CD 0F8721010000        <1>         ja      loc_set_time_stc_7
   937                              <1> 	; 13/05/2016
   938                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   939                              <1> 		      ; video page 0 (bh)
   940 000065D3 B307                <1> 	mov	bl, 7	
   941 000065D5 E847B5FFFF          <1> 	call	_write_tty
   942                              <1> loc_set_time_get_lchar_again:
   943 000065DA 28E4                <1> 	sub	ah, ah ; 0
   944 000065DC E8EBA4FFFF          <1> 	call	int16h
   945                              <1> 	; AL = ASCII Code of the Character
   946 000065E1 3C0D                <1> 	cmp	al, 13
   947 000065E3 7412                <1> 	je	short loc_set_time_progress
   948 000065E5 3C1B                <1> 	cmp	al, 27
   949 000065E7 744B                <1> 	je	short loc_set_time_retn
   950                              <1> 	;
   951 000065E9 E831FEFFFF          <1> 	call	check_for_backspace
   952 000065EE 75EA                <1> 	jne	short loc_set_time_get_lchar_again
   953                              <1> 
   954                              <1> loc_set_time_bs_8:
   955 000065F0 E818FEFFFF          <1> 	call	write_backspace
   956 000065F5 EBC1                <1> 	jmp	short loc_enter_second_2
   957                              <1> 
   958                              <1> loc_set_time_progress:
   959                              <1> 	; Get Current Time
   960                              <1> 	;mov 	ah, 02h
   961                              <1> 	;call	int1Ah
   962 000065F7 E813ECFFFF          <1> 	call	RTC_20	; GET RTC TIME
   963                              <1> 	;DL = Daylight Savings Enable option (0-1)	
   964                              <1> 
   965 000065FC 66A1[7EDF0000]      <1> 	mov	ax, [Hour]
   966 00006602 662D3030            <1> 	sub	ax, '00'
   967 00006606 C0E004              <1> 	shl	al, 4 ; * 16
   968 00006609 88C5                <1> 	mov	ch, al
   969 0000660B 00E5                <1> 	add	ch, ah
   970 0000660D 66A1[81DF0000]      <1> 	mov	ax, [Minute]
   971 00006613 662D3030            <1> 	sub	ax, '00'
   972 00006617 C0E004              <1> 	shl	al, 4 ; * 16
   973 0000661A 88C1                <1> 	mov	cl, al
   974 0000661C 00E1                <1> 	add	cl, ah
   975 0000661E 66A1[84DF0000]      <1> 	mov	ax, [Second]
   976 00006624 662D3030            <1> 	sub	ax, '00'
   977 00006628 C0E004              <1> 	shl	al, 4 ; * 16
   978 0000662B 88C6                <1> 	mov	dh, al
   979 0000662D 00E6                <1> 	add	dh, ah
   980                              <1> 	
   981                              <1> 	;mov	ah, 03h
   982                              <1> 	;call	int1Ah
   983 0000662F E80AECFFFF          <1> 	call	RTC_30	; SET RTC TIME
   984                              <1> 
   985                              <1> loc_set_time_retn:
   986 00006634 BE[ABEE0000]        <1> 	mov 	esi, nextline
   987 00006639 E818EFFFFF          <1> 	call	print_msg
   988 0000663E C3                  <1> 	retn
   989                              <1> 
   990                              <1> loc_set_time_stc_0:
   991                              <1> 	;xor	bh, bh ; video page 0
   992 0000663F E8BDB5FFFF          <1> 	call	beeper ; BEEP !
   993 00006644 E92EFEFFFF          <1>         jmp     loc_enter_hour_1
   994                              <1> loc_set_time_stc_1:
   995 00006649 E8D1FDFFFF          <1> 	call	check_for_backspace
   996 0000664E 740A                <1> 	je	short loc_set_time_bs_1
   997                              <1> 	;xor	bh, bh ; video page 0
   998 00006650 E8ACB5FFFF          <1> 	call	beeper ; BEEP !
   999 00006655 E950FEFFFF          <1>         jmp     loc_enter_hour_2
  1000                              <1> loc_set_time_bs_1:
  1001 0000665A E8AEFDFFFF          <1> 	call	write_backspace
  1002 0000665F E913FEFFFF          <1>         jmp     loc_enter_hour_1
  1003                              <1> loc_set_time_stc_2:
  1004 00006664 E8B6FDFFFF          <1> 	call	check_for_backspace
  1005 00006669 740A                <1> 	je	short loc_set_time_bs_2
  1006                              <1> 	;xor	bh, bh ; video page 0
  1007 0000666B E891B5FFFF          <1> 	call	beeper ; BEEP !
  1008 00006670 E971FEFFFF          <1>         jmp     loc_enter_time_separator_1
  1009                              <1> loc_set_time_bs_2:
  1010 00006675 E893FDFFFF          <1> 	call	write_backspace
  1011 0000667A E92BFEFFFF          <1>         jmp     loc_enter_hour_2
  1012                              <1> loc_set_time_stc_3:
  1013 0000667F E89BFDFFFF          <1> 	call	check_for_backspace
  1014 00006684 740A                <1> 	je	short loc_set_time_bs_3
  1015                              <1> 	;xor	bh, bh ; video page 0
  1016 00006686 E876B5FFFF          <1> 	call	beeper ; BEEP !6
  1017 0000668B E974FEFFFF          <1>         jmp     loc_enter_minute_1
  1018                              <1> loc_set_time_bs_3:
  1019 00006690 E878FDFFFF          <1> 	call	write_backspace
  1020 00006695 E94CFEFFFF          <1>         jmp     loc_enter_time_separator_1
  1021                              <1> loc_set_time_stc_4:
  1022 0000669A E880FDFFFF          <1> 	call	check_for_backspace
  1023 0000669F 740A                <1> 	je	short loc_set_time_bs_4
  1024                              <1> 	;xor	bh, bh ; video page 0
  1025 000066A1 E85BB5FFFF          <1> 	call	beeper ; BEEP !
  1026 000066A6 E984FEFFFF          <1>         jmp     loc_enter_minute_2
  1027                              <1> loc_set_time_bs_4:
  1028 000066AB E85DFDFFFF          <1> 	call	write_backspace
  1029 000066B0 E94FFEFFFF          <1>         jmp     loc_enter_minute_1
  1030                              <1> loc_set_time_stc_5:
  1031 000066B5 E865FDFFFF          <1> 	call	check_for_backspace
  1032 000066BA 740A                <1> 	je	short loc_set_time_bs_5
  1033                              <1> 	;xor	bh, bh ; video page 0
  1034 000066BC E840B5FFFF          <1> 	call	beeper ; BEEP !
  1035 000066C1 E994FEFFFF          <1>         jmp     loc_enter_time_separator_2
  1036                              <1> loc_set_time_bs_5:
  1037 000066C6 E842FDFFFF          <1> 	call	write_backspace
  1038 000066CB E95FFEFFFF          <1>         jmp     loc_enter_minute_2
  1039                              <1> loc_set_time_stc_6:
  1040 000066D0 E84AFDFFFF          <1> 	call	check_for_backspace
  1041 000066D5 7413                <1> 	je	short loc_set_time_bs_6
  1042                              <1> 	;xor	bh, bh ; video page 0
  1043 000066D7 E825B5FFFF          <1> 	call	beeper ; BEEP !
  1044 000066DC 66C705[84DF0000]30- <1> 	mov	word [Second], 3030h
  1044 000066E4 30                  <1>
  1045 000066E5 E99FFEFFFF          <1>         jmp     loc_enter_second_1
  1046                              <1> loc_set_time_bs_6:
  1047 000066EA E81EFDFFFF          <1> 	call	write_backspace
  1048 000066EF E966FEFFFF          <1>         jmp     loc_enter_time_separator_2
  1049                              <1> loc_set_time_stc_7:
  1050 000066F4 E826FDFFFF          <1> 	call	check_for_backspace
  1051 000066F9 740A                <1> 	je	short loc_set_time_bs_7
  1052                              <1> 	;xor	bh, bh ; video page 0
  1053 000066FB E801B5FFFF          <1> 	call	beeper ; BEEP !
  1054 00006700 E9B3FEFFFF          <1>         jmp     loc_enter_second_2
  1055                              <1> loc_set_time_bs_7:
  1056 00006705 E803FDFFFF          <1> 	call	write_backspace
  1057 0000670A E97AFEFFFF          <1>         jmp     loc_enter_second_1
  1058                              <1> 
  1059                              <1> print_volume_info:
  1060                              <1> 	; 01/03/2016
  1061                              <1> 	; 08/02/2016
  1062                              <1> 	; 06/02/2016
  1063                              <1> 	; 04/02/2016
  1064                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
  1065                              <1> 	; 25/10/2009
  1066                              <1> 	;
  1067                              <1> 	; "Volume Serial No: "
  1068                              <1>  	;
  1069                              <1> 	; INPUT  : AL = DOS Drive Number
  1070                              <1> 	; OUTPUT : AH = FS Type
  1071                              <1> 	;          AL = DOS Drive Name
  1072                              <1> 	; CF = 0 -> OK
  1073                              <1> 	; CF = 1 -> Drive not ready 
  1074                              <1> 
  1075 0000670F 88C4                <1> 	mov	ah, al
  1076 00006711 28C0                <1> 	sub	al, al
  1077 00006713 0FB7F0              <1> 	movzx	esi, ax	
  1078 00006716 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1079 0000671C 8A06                <1> 	mov	al, [esi]
  1080 0000671E 3C41                <1> 	cmp	al, 'A'  
  1081 00006720 7304                <1> 	jnb	short loc_pvi_set_vol_name
  1082 00006722 8A6604              <1> 	mov	ah, [esi+LD_FSType]
  1083 00006725 C3                  <1> 	retn
  1084                              <1> 
  1085                              <1> loc_pvi_set_vol_name:
  1086 00006726 A2[B8DF0000]        <1> 	mov	[Vol_Drv_Name], al
  1087 0000672B 56                  <1> 	push	esi
  1088 0000672C E858010000          <1> 	call	move_volume_name_and_serial_no ;;;
  1089 00006731 7302                <1> 	jnc	short loc_pvi_mvn_ok
  1090 00006733 5E                  <1> 	pop	esi
  1091 00006734 C3                  <1> 	retn
  1092                              <1> 
  1093                              <1> loc_pvi_mvn_ok:
  1094 00006735 8B3424              <1> 	mov	esi, [esp]
  1095 00006738 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1096 0000673C 7509                <1> 	jne	short loc_pvi_fat_vol_size
  1097 0000673E 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
  1098 00006741 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1099 00006745 EB07                <1> 	jmp	short loc_vol_size_mul32
  1100                              <1> loc_pvi_fat_vol_size:
  1101 00006747 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
  1102 0000674A 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1103                              <1> loc_vol_size_mul32:
  1104 0000674E F7E3                <1> 	mul	ebx
  1105 00006750 09D2                <1> 	or	edx, edx
  1106 00006752 7507                <1> 	jnz	short loc_vol_size_in_kbytes
  1107                              <1> loc_vol_size_in_bytes:
  1108 00006754 B9[96DF0000]        <1> 	mov	ecx, VolSize_Bytes
  1109 00006759 EB0D                <1> 	jmp	short loc_write_vol_size_str
  1110                              <1> loc_vol_size_in_kbytes:
  1111 0000675B 66BB0004            <1> 	mov	bx, 1024
  1112 0000675F F7F3                <1> 	div	ebx
  1113 00006761 B9[89DF0000]        <1> 	mov 	ecx, VolSize_KiloBytes
  1114 00006766 31D2                <1> 	xor	edx, edx ; 0
  1115                              <1> loc_write_vol_size_str:
  1116 00006768 890D[C7280100]      <1> 	mov	[VolSize_Unit1], ecx
  1117                              <1> 	; 
  1118 0000676E BF[DD280100]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
  1119                              <1>         ;mov	byte [edi], 0
  1120 00006773 B90A000000          <1> 	mov	ecx, 10
  1121                              <1> loc_write_vol_size_chr:
  1122 00006778 F7F1                <1> 	div	ecx
  1123 0000677A 80C230              <1> 	add	dl, '0'
  1124 0000677D 4F                  <1> 	dec	edi	
  1125 0000677E 8817                <1> 	mov	[edi], dl
  1126 00006780 85C0                <1> 	test	eax, eax
  1127 00006782 7404                <1> 	jz	short loc_write_vol_size_str_ok
  1128 00006784 28D2                <1> 	sub	dl, dl ; 0
  1129 00006786 EBF0                <1> 	jmp	short loc_write_vol_size_chr
  1130                              <1> 
  1131                              <1> loc_write_vol_size_str_ok:
  1132 00006788 893D[CF280100]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
  1133                              <1> 	;
  1134 0000678E BF[A1DF0000]        <1> 	mov	edi, Vol_FS_Name
  1135 00006793 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
  1136 00006796 20C9                <1> 	and	cl, cl ; 0 ?
  1137 00006798 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
  1138 0000679A 66C7075452          <1> 	mov	word [edi], 'TR'
  1139 0000679F C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
  1140                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1141 000067A6 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
  1142 000067AA 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
  1143 000067AD EB36                <1> 	jmp	short loc_vol_freespace_mul32
  1144                              <1> 
  1145                              <1> loc_write_vol_FAT_str_1:
  1146 000067AF 66B83332            <1> 	mov	ax, '32' ; FAT32
  1147 000067B3 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
  1148 000067B6 7708                <1> 	ja	short loc_write_vol_FAT_str_2
  1149 000067B8 66B83132            <1> 	mov	ax, '12' ; FAT12
  1150 000067BC 7202                <1> 	jb	short loc_write_vol_FAT_str_2
  1151 000067BE B436                <1> 	mov	ah, '6'  ; FAT16
  1152                              <1> loc_write_vol_FAT_str_2:
  1153 000067C0 C70746415420        <1> 	mov	dword [edi], 'FAT '
  1154 000067C6 66894704            <1> 	mov	word [edi+4], ax
  1155                              <1> 	;
  1156                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1157 000067CA 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
  1158 000067CE 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1159                              <1> 
  1160                              <1> loc_vol_freespace_recalc0:
  1161                              <1> 	; 01/03/2016
  1162 000067D1 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  1163 000067D4 720F                <1> 	jb	short loc_vol_freespace_mul32
  1164                              <1> 	;inc	eax ; 0
  1165 000067D6 20C9                <1> 	and	cl, cl ; byte [esi+LD_FATType]
  1166 000067D8 740B                <1> 	jz	short loc_vol_freespace_mul32 	
  1167 000067DA 53                  <1> 	push	ebx
  1168 000067DB 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free sectors
  1169 000067DF E88B490000          <1> 	call	calculate_fat_freespace
  1170 000067E4 5B                  <1> 	pop	ebx
  1171                              <1> 
  1172                              <1> loc_vol_freespace_mul32:
  1173 000067E5 F7E3                <1> 	mul	ebx
  1174 000067E7 09D2                <1> 	or	edx, edx
  1175 000067E9 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
  1176                              <1> loc_vol_fspace_in_bytes:
  1177 000067EB B9[96DF0000]        <1> 	mov	ecx, VolSize_Bytes
  1178 000067F0 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
  1179                              <1> loc_vol_fspace_in_kbytes:
  1180 000067F2 66BB0004            <1> 	mov	bx, 1024
  1181 000067F6 F7F3                <1> 	div	ebx
  1182 000067F8 B9[89DF0000]        <1> 	mov 	ecx, VolSize_KiloBytes
  1183 000067FD 31D2                <1> 	xor	edx, edx ; 0
  1184                              <1> loc_write_vol_fspace_str:
  1185 000067FF 890D[CB280100]      <1> 	mov	[VolSize_Unit2], ecx
  1186                              <1> 	;	
  1187 00006805 BF[ED280100]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
  1188                              <1>         ;mov	byte [edi], 0
  1189 0000680A B90A000000          <1> 	mov	ecx, 10
  1190                              <1> loc_write_vol_fspace_chr:
  1191 0000680F F7F1                <1> 	div	ecx
  1192 00006811 80C230              <1> 	add	dl, '0'
  1193 00006814 4F                  <1> 	dec	edi	
  1194 00006815 8817                <1> 	mov	[edi], dl
  1195 00006817 85C0                <1> 	test	eax, eax
  1196 00006819 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
  1197 0000681B 28D2                <1> 	sub	dl, dl ; 0
  1198 0000681D EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
  1199                              <1> 
  1200                              <1> loc_write_vol_fspace_str_ok:
  1201 0000681F 893D[DF280100]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
  1202                              <1> 	;
  1203 00006825 BE[9FDF0000]        <1> 	mov	esi, Volume_in_drive
  1204 0000682A E827EDFFFF          <1> 	call	print_msg
  1205 0000682F BE[DFDF0000]        <1> 	mov	esi, Vol_Name
  1206 00006834 E81DEDFFFF          <1> 	call	print_msg
  1207 00006839 BE[ABEE0000]        <1> 	mov	esi, nextline
  1208 0000683E E813EDFFFF          <1> 	call	print_msg
  1209                              <1> 	;
  1210 00006843 BE[40E00000]        <1> 	mov	esi, Vol_Total_Sector_Header
  1211 00006848 E809EDFFFF          <1> 	call	print_msg
  1212 0000684D 8B35[CF280100]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
  1213 00006853 E8FEECFFFF          <1> 	call	print_msg
  1214 00006858 8B35[C7280100]      <1> 	mov	esi, [VolSize_Unit1]
  1215 0000685E E8F3ECFFFF          <1> 	call	print_msg
  1216                              <1> 	;
  1217 00006863 BE[51E00000]        <1> 	mov	esi, Vol_Free_Sectors_Header
  1218 00006868 E8E9ECFFFF          <1> 	call	print_msg
  1219 0000686D 8B35[DF280100]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
  1220 00006873 E8DEECFFFF          <1> 	call	print_msg
  1221 00006878 8B35[CB280100]      <1> 	mov	esi, [VolSize_Unit2]
  1222 0000687E E8D3ECFFFF          <1> 	call	print_msg
  1223                              <1> 	;
  1224 00006883 5E                  <1> 	pop	esi
  1225                              <1> 	
  1226                              <1> 	;mov	ah, [esi+LD_FSType]
  1227                              <1> 	;mov	al, [esi+LD_FATType]
  1228 00006884 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1229                              <1> 
  1230 00006888 C3                  <1> 	retn
  1231                              <1> 
  1232                              <1> move_volume_name_and_serial_no:
  1233                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
  1234                              <1> 	; this routine will be called by
  1235                              <1> 	; "print_volume_info" and "print_directory"
  1236                              <1> 	; INPUT ->
  1237                              <1> 	;	ESI = Logical DOS drv descripton table address
  1238                              <1> 	; OUTPUT ->
  1239                              <1> 	;	*Volume name will be moved to text area
  1240                              <1> 	;	*Volume serial number will be converted to
  1241                              <1> 	;	 text and will be moved to text area
  1242                              <1> 	;   cf = 1 -> invalid/unknown dos drive
  1243                              <1> 	;   cf = 0 -> ecx = 0
  1244                              <1> 	;
  1245                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
  1246                              <1> 
  1247 00006889 BF[DFDF0000]        <1> 	mov 	edi, Vol_Name
  1248                              <1> 
  1249                              <1> 	;mov	ah, [esi+LD_FSType]
  1250                              <1> 	;mov	al, [esi+LD_FATType]
  1251 0000688E 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1252 00006892 80FCA1              <1> 	cmp	ah, 0A1h
  1253 00006895 7418                <1> 	je	short mvn_2
  1254 00006897 08E4                <1> 	or	ah, ah
  1255 00006899 7404                <1> 	jz	short mvn_0
  1256 0000689B 08C0                <1> 	or	al, al
  1257 0000689D 7504                <1> 	jnz	short mvn_1
  1258                              <1> mvn_0:
  1259 0000689F 8A06                <1> 	mov	al, [esi]
  1260 000068A1 F9                  <1> 	stc
  1261 000068A2 C3                  <1> 	retn
  1262                              <1> mvn_1:
  1263 000068A3 3C02                <1> 	cmp	al, 2
  1264 000068A5 7717                <1> 	ja	short mvn_3 
  1265                              <1> 	;or	al, al
  1266                              <1> 	;jz	short mvn_2
  1267 000068A7 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
  1268 000068AA 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
  1269 000068AD EB15                <1> 	jmp	short mvn_4
  1270                              <1> mvn_2:
  1271 000068AF 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
  1272 000068B2 83C62C              <1> 	add	esi, LD_FS_VolumeName
  1273 000068B5 B910000000          <1> 	mov	ecx, 16
  1274 000068BA F3A5                <1> 	rep	movsd
  1275 000068BC EB10                <1> 	jmp	short mvn_5
  1276                              <1> mvn_3:
  1277 000068BE 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
  1278 000068C1 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
  1279                              <1> mvn_4:
  1280 000068C4 B90B000000          <1> 	mov	ecx, 11
  1281 000068C9 F3A4                <1> 	rep	movsb
  1282 000068CB C60700              <1> 	mov	byte [edi], 0
  1283                              <1> mvn_5:
  1284                              <1> 	;mov	[Current_VolSerial], eax  
  1285 000068CE E8A5C4FFFF          <1> 	call	dwordtohex
  1286 000068D3 8915[34E00000]      <1> 	mov	[Vol_Serial1], edx
  1287 000068D9 A3[39E00000]        <1> 	mov	[Vol_Serial2], eax
  1288                              <1> 	; ecx = 0
  1289 000068DE C3                  <1> 	retn
  1290                              <1> 
  1291                              <1> get_volume_serial_number:
  1292                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
  1293                              <1> 	; 08/08/2010
  1294                              <1> 	;
  1295                              <1> 	; INPUT -> DL = Logical DOS Drive number
  1296                              <1> 	; OUTPUT -> EAX = Volume serial number
  1297                              <1> 	;          BL= FAT Type	    
  1298                              <1> 	;          BH = Logical DOS drv Number (DL input)
  1299                              <1> 	; cf = 1 -> Drive not ready
  1300                              <1> 
  1301 000068DF 31DB                <1> 	xor	ebx, ebx
  1302 000068E1 88D7                <1> 	mov	bh, dl
  1303 000068E3 3815[07DE0000]      <1> 	cmp	[Last_DOS_DiskNo], dl
  1304 000068E9 7304                <1> 	jnb	short loc_gvsn_start
  1305                              <1> loc_gvsn_stc_retn:
  1306 000068EB 31C0                <1> 	xor	eax, eax
  1307 000068ED F9                  <1> 	stc 
  1308 000068EE C3                  <1>         retn 
  1309                              <1> loc_gvsn_start:
  1310 000068EF 56                  <1> 	push	esi
  1311 000068F0 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1312 000068F5 01DE                <1> 	add	esi, ebx
  1313 000068F7 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
  1314 000068FA 20DB                <1> 	and	bl, bl
  1315 000068FC 740F                <1> 	jz	short loc_gvsn_fs
  1316 000068FE 80FB02              <1> 	cmp	bl, 2
  1317 00006901 7705                <1> 	ja	short loc_gvsn_fat32
  1318                              <1> loc_gvsn_fat:
  1319 00006903 83C62D              <1> 	add	esi, LD_BPB + VolumeID
  1320 00006906 EB0E                <1> 	jmp	short loc_gvsn_return
  1321                              <1> loc_gvsn_fat32: 
  1322 00006908 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
  1323 0000690B EB09                <1> 	jmp	short loc_gvsn_return 
  1324                              <1> loc_gvsn_fs:
  1325 0000690D 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1326 00006911 75D8                <1> 	jne	short loc_gvsn_stc_retn 
  1327 00006913 83C628              <1> 	add	esi, LD_FS_VolumeSerial
  1328                              <1> loc_gvsn_return:
  1329 00006916 8B06                <1> 	mov	eax, [esi]
  1330 00006918 5E                  <1> 	pop	esi
  1331 00006919 C3                  <1> 	retn
  1332                              <1> 
  1333                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
  1334                              <1> ; 09/11/2011
  1335                              <1> ; 29/01/2005
  1336                              <1> 
  1337                              <1> command_interpreter:
  1338                              <1> 	; 13/05/2016
  1339                              <1> 	; 07/05/2016
  1340                              <1> 	; 04/03/2016
  1341                              <1> 	; 04/02/2016
  1342                              <1> 	; 03/02/2016
  1343                              <1> 	; 30/01/2016
  1344                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
  1345                              <1> 	; 15/09/2011         
  1346                              <1> 	; 29/01/2005
  1347                              <1>         
  1348                              <1> 	; Input: ecx = command word length (CL)
  1349                              <1> 	;	 CommandBuffer = Command string offset
  1350                              <1>  
  1351 0000691A C605[80290100]00    <1> 	mov	byte [Program_Exit],0
  1352 00006921 80F904              <1> 	cmp	cl, 4
  1353 00006924 0F87AE020000        <1>         ja      c_6
  1354 0000692A 0F822E010000        <1>         jb      c_2
  1355                              <1> c_4:
  1356                              <1> 
  1357                              <1> cmp_cmd_exit:
  1358 00006930 BF[75DE0000]        <1> 	mov	edi, Cmd_Exit
  1359 00006935 E8C9030000          <1> 	call	cmp_cmd	
  1360 0000693A 7208                <1> 	jc	short cmp_cmd_date
  1361                              <1> 
  1362 0000693C C605[80290100]01    <1>         mov     byte [Program_Exit], 1
  1363 00006943 C3                  <1>         retn
  1364                              <1> 
  1365                              <1> cmp_cmd_date:
  1366 00006944 B104                <1> 	mov	cl, 4
  1367 00006946 BF[91DE0000]        <1> 	mov	edi, Cmd_Date
  1368 0000694B E8B3030000          <1> 	call	cmp_cmd	
  1369 00006950 720B                <1>         jc	short cmp_cmd_time
  1370                              <1> 	
  1371 00006952 E8D0F7FFFF          <1> 	call	show_date
  1372 00006957 E80FF8FFFF          <1> 	call	set_date
  1373 0000695C C3                  <1> 	retn
  1374                              <1> 
  1375                              <1> cmp_cmd_time:
  1376 0000695D B104                <1> 	mov	cl, 4
  1377 0000695F BF[96DE0000]        <1> 	mov	edi, Cmd_Time
  1378 00006964 E89A030000          <1>    	call	cmp_cmd	
  1379 00006969 720B                <1> 	jc	short cmp_cmd_show
  1380                              <1> 
  1381 0000696B E8C6FAFFFF          <1> 	call	show_time
  1382 00006970 E8F8FAFFFF          <1> 	call	set_time
  1383 00006975 C3                  <1> 	retn
  1384                              <1> 
  1385                              <1> cmp_cmd_show:
  1386 00006976 B104                <1> 	mov	cl, 4
  1387 00006978 BF[A7DE0000]        <1> 	mov	edi, Cmd_Show
  1388 0000697D E881030000          <1>    	call	cmp_cmd	
  1389 00006982 0F83F6090000        <1>         jnc     show_file
  1390                              <1> 
  1391                              <1> cmp_cmd_echo:
  1392 00006988 B104                <1> 	mov	cl, 4
  1393 0000698A BF[ECDE0000]        <1> 	mov	edi, Cmd_Echo
  1394 0000698F E86F030000          <1>    	call	cmp_cmd	
  1395 00006994 721B                <1> 	jc	short cmp_cmd_copy
  1396                              <1> 
  1397                              <1> 	; 14/04/2016
  1398 00006996 56                  <1> 	push	esi
  1399                              <1> cmd_echo_asciiz:
  1400 00006997 46                  <1>         inc	esi
  1401 00006998 8A06                <1> 	mov	al, [esi]
  1402 0000699A 3C20                <1> 	cmp	al, 20h
  1403 0000699C 73F9                <1> 	jnb	short cmd_echo_asciiz
  1404 0000699E C60600              <1> 	mov	byte [esi], 0                 
  1405 000069A1 5E                  <1> 	pop	esi  
  1406 000069A2 E8AFEBFFFF          <1> 	call	print_msg
  1407 000069A7 BE[1DEF0000]        <1> 	mov	esi, NextLine
  1408                              <1> 	;call	print_msg   
  1409                              <1> 	;retn
  1410 000069AC E9A5EBFFFF          <1> 	jmp	print_msg
  1411                              <1> 
  1412                              <1> cmp_cmd_copy:
  1413 000069B1 B104                <1> 	mov	cl, 4
  1414 000069B3 BF[CADE0000]        <1> 	mov	edi, Cmd_Copy
  1415 000069B8 E846030000          <1>    	call	cmp_cmd	
  1416 000069BD 0F8301180000        <1> 	jnc	copy_file
  1417                              <1> 
  1418                              <1> cmp_cmd_move:
  1419 000069C3 B104                <1> 	mov	cl, 4
  1420 000069C5 BF[CFDE0000]        <1> 	mov	edi, Cmd_Move
  1421 000069CA E834030000          <1>    	call	cmp_cmd	
  1422 000069CF 0F8395160000        <1> 	jnc	move_file
  1423                              <1> 
  1424                              <1> cmp_cmd_path:
  1425 000069D5 B104                <1> 	mov	cl, 4
  1426 000069D7 BF[D4DE0000]        <1> 	mov	edi, Cmd_Path
  1427 000069DC E822030000          <1>    	call	cmp_cmd	
  1428 000069E1 0F83351A0000        <1> 	jnc	set_get_path
  1429                              <1> 
  1430                              <1> cmp_cmd_beep:
  1431 000069E7 B104                <1> 	mov	cl, 4
  1432 000069E9 BF[0ADF0000]        <1> 	mov	edi, Cmd_Beep
  1433 000069EE E810030000          <1>    	call	cmp_cmd	
  1434 000069F3 720B                <1> 	jc	short cmp_cmd_find
  1435                              <1> 	; 13/05/2016
  1436 000069F5 8A3D[F61F0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  1437 000069FB E901B2FFFF          <1> 	jmp	beeper
  1438                              <1> 
  1439                              <1> cmp_cmd_find:
  1440 00006A00 B104                <1> 	mov	cl, 4
  1441 00006A02 BF[DEDE0000]        <1> 	mov	edi, Cmd_Find
  1442 00006A07 E8F7020000          <1>    	call	cmp_cmd	
  1443 00006A0C 0F82D4020000        <1>         jc      cmp_cmd_external
  1444                              <1> 
  1445                              <1> 	;call	find_and_list_files
  1446 00006A12 E9EC220000          <1> 	jmp	find_and_list_files
  1447                              <1> 	;retn
  1448                              <1> 
  1449                              <1> c_1:
  1450 00006A17 AD                  <1> 	lodsd
  1451                              <1> cmp_cmd_help:
  1452 00006A18 3C3F                <1> 	cmp	al, '?'
  1453 00006A1A 751D                <1>         jne     short cmp_cmd_remark
  1454                              <1> 
  1455 00006A1C BE[67DE0000]        <1> 	mov	esi, Command_List
  1456                              <1> cmd_help_next_w:
  1457 00006A21 E830EBFFFF          <1> 	call	print_msg
  1458                              <1> 
  1459 00006A26 803E20              <1> 	cmp	byte [esi], 20h ; 0
  1460 00006A29 7232                <1> 	jb	short cmd_help_retn
  1461                              <1> 	
  1462 00006A2B 56                  <1> 	push	esi
  1463 00006A2C BE[ABEE0000]        <1> 	mov	esi, nextline
  1464 00006A31 E820EBFFFF          <1> 	call	print_msg
  1465 00006A36 5E                  <1> 	pop	esi
  1466 00006A37 EBE8                <1> 	jmp	short cmd_help_next_w	
  1467                              <1> 
  1468                              <1> cmp_cmd_remark:
  1469 00006A39 3C2A                <1> 	cmp	al, '*'
  1470 00006A3B 0F85A5020000        <1>         jne     cmp_cmd_external
  1471 00006A41 46                  <1> 	inc	esi
  1472 00006A42 BF[F0200100]        <1> 	mov	edi, Remark
  1473 00006A47 8A06                <1> 	mov	al, [esi]
  1474 00006A49 3C20                <1> 	cmp	al, 20h
  1475 00006A4B 7707                <1> 	ja	short cmd_remark_write
  1476 00006A4D 89FE                <1> 	mov	esi, edi ; Remark
  1477 00006A4F E902EBFFFF          <1> 	jmp	print_msg
  1478                              <1> 
  1479                              <1> cmd_remark_write:
  1480 00006A54 AA                  <1> 	stosb
  1481 00006A55 AC                  <1> 	lodsb
  1482 00006A56 3C20                <1> 	cmp	al, 20h
  1483 00006A58 73FA                <1> 	jnb	short cmd_remark_write
  1484 00006A5A C60700              <1> 	mov	byte [edi], 0
  1485                              <1> 
  1486                              <1> cmd_help_retn:
  1487                              <1> cmd_remark_retn:
  1488                              <1> cd_retn:
  1489 00006A5D C3                  <1> 	retn
  1490                              <1> 
  1491                              <1> c_2:
  1492 00006A5E 80F902              <1> 	cmp	cl, 2
  1493 00006A61 0F87B1000000        <1>         ja      c_3
  1494 00006A67 BE[3E210100]        <1> 	mov	esi, CommandBuffer
  1495 00006A6C 72A9                <1> 	jb	short c_1
  1496                              <1> 
  1497                              <1> cmp_cmd_cd:
  1498 00006A6E 66AD                <1> 	lodsw
  1499 00006A70 663D4344            <1> 	cmp	ax, 'CD'
  1500 00006A74 7553                <1> 	jne	short cmp_cmd_drive
  1501 00006A76 46                  <1>         inc	esi
  1502                              <1> cd_0:
  1503 00006A77 668B06              <1> 	mov	ax, [esi]	
  1504 00006A7A 3C20                <1> 	cmp	al, 20h
  1505 00006A7C 76DF                <1> 	jna	short cd_retn
  1506                              <1> 	; 10/02/2016
  1507 00006A7E 80FC3A              <1> 	cmp	ah, ':'
  1508 00006A81 7504                <1> 	jne	short cd_1
  1509 00006A83 46                  <1> 	inc	esi
  1510 00006A84 46                  <1> 	inc	esi
  1511 00006A85 EB4B                <1> 	jmp	short cd_2
  1512                              <1> 
  1513                              <1> cd_1:	; change current directory
  1514                              <1> 	; 29/11/2009
  1515                              <1> 	; AH = CDh	; to separate 'CD' command from others
  1516                              <1> 			; for restoring current directory
  1517                              <1> 			; 0CDh sign is for saving cdir into 
  1518                              <1> 			; DOS drv description table cdir area
  1519                              <1> 	
  1520 00006A87 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
  1521                              <1> 
  1522 00006A89 E85A230000          <1> 	call	change_current_directory
  1523 00006A8E 0F8374220000        <1>         jnc     change_prompt_dir_string
  1524                              <1> 
  1525                              <1> cd_error_messages:
  1526 00006A94 3C03                <1> 	cmp	al, 3
  1527 00006A96 740C                <1> 	je	short cd_path_not_found
  1528 00006A98 3C15                <1> 	cmp	al, 15h 
  1529 00006A9A 745B                <1> 	je	short cd_drive_not_ready
  1530 00006A9C 3C18                <1> 	cmp	al, 18h ; Bad request structure length 
  1531 00006A9E 746C                <1> 	je	short cd_command_failed
  1532 00006AA0 3C1A                <1> 	cmp	al, 1Ah ; Unknown media type, non-DOS disk
  1533 00006AA2 7468                <1>         je      short cd_command_failed
  1534                              <1> 
  1535                              <1> cd_path_not_found:
  1536 00006AA4 6650                <1> 	push	ax	
  1537 00006AA6 BE[13E10000]        <1> 	mov	esi, Msg_Dir_Not_Found
  1538 00006AAB E8A6EAFFFF          <1> 	call	print_msg
  1539 00006AB0 6658                <1> 	pop	ax
  1540 00006AB2 3A25[8C200100]      <1> 	cmp	ah, [Current_Dir_Level]
  1541 00006AB8 0F834A220000        <1>         jnb     change_prompt_dir_string
  1542 00006ABE 8825[8C200100]      <1> 	mov	[Current_Dir_Level], ah
  1543 00006AC4 E93F220000          <1>         jmp     change_prompt_dir_string   
  1544                              <1> 
  1545                              <1> cmp_cmd_drive: ; change current drive
  1546                              <1> 	; C:, D:, E: etc.
  1547 00006AC9 80FC3A              <1> 	cmp	ah, ':'
  1548 00006ACC 0F8514020000        <1>         jne     cmp_cmd_external
  1549                              <1> 
  1550                              <1> cd_2:	; 'CD C:', 'CD D:' ...
  1551 00006AD2 803E20              <1> 	cmp	byte [esi], 20h
  1552 00006AD5 0F8715020000        <1>         ja      loc_cmd_failed
  1553                              <1> 
  1554 00006ADB 24DF                <1> 	and	al, 0DFh
  1555 00006ADD 2C41                <1> 	sub	al, 'A'
  1556 00006ADF 0F820B020000        <1>         jc      loc_cmd_failed
  1557                              <1> 
  1558 00006AE5 3A05[07DE0000]      <1>         cmp     al, [Last_DOS_DiskNo]
  1559 00006AEB 770A                <1>         ja	short cd_drive_not_ready
  1560                              <1> 	
  1561 00006AED 88C2                <1> 	mov	dl, al
  1562 00006AEF E862F3FFFF          <1> 	call 	change_current_drive
  1563 00006AF4 7201                <1> 	jc	short cd_drive_not_ready	
  1564 00006AF6 C3                  <1> 	retn
  1565                              <1> 
  1566                              <1> cd_drive_not_ready:
  1567 00006AF7 BE[D0E00000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1568 00006AFC E855EAFFFF          <1> 	call	print_msg
  1569                              <1> 
  1570                              <1> cd_fail_drive_restart:
  1571 00006B01 8A15[8E200100]      <1> 	mov	dl, [Current_Drv]
  1572                              <1> 	;call 	change_current_drive
  1573 00006B07 E94AF3FFFF          <1>         jmp     change_current_drive
  1574                              <1> 	;retn
  1575                              <1> 
  1576                              <1> cd_command_failed:
  1577 00006B0C BE[B1E00000]        <1> 	mov	esi, Msg_Bad_Command
  1578 00006B11 E840EAFFFF          <1> 	call	print_msg
  1579 00006B16 EBE9                <1> 	jmp	short cd_fail_drive_restart
  1580                              <1> 
  1581                              <1> c_3:
  1582                              <1> cmp_cmd_dir:
  1583 00006B18 BF[67DE0000]        <1> 	mov	edi, Cmd_Dir
  1584 00006B1D E8E1010000          <1> 	call	cmp_cmd	
  1585 00006B22 0F8380020000        <1> 	jnc	print_directory_list
  1586                              <1> 
  1587                              <1> cmp_cmd_cls:
  1588 00006B28 B103                <1> 	mov	cl, 3
  1589 00006B2A BF[A3DE0000]        <1> 	mov	edi, Cmd_Cls
  1590 00006B2F E8CF010000          <1> 	call	cmp_cmd	
  1591 00006B34 0F8332EAFFFF        <1>         jnc	clear_screen
  1592                              <1> 
  1593                              <1> cmp_cmd_ver:
  1594 00006B3A B103                <1> 	mov	cl, 3
  1595 00006B3C BF[71DE0000]        <1> 	mov	edi, Cmd_Ver
  1596 00006B41 E8BD010000          <1> 	call	cmp_cmd	
  1597 00006B46 720A                <1> 	jc	short cmp_cmd_mem
  1598                              <1> 
  1599 00006B48 BE[0FDE0000]        <1> 	mov	esi, mainprog_Version
  1600                              <1> 	;call	print_msg
  1601 00006B4D E904EAFFFF          <1> 	jmp	print_msg
  1602                              <1> 	;retn
  1603                              <1> 
  1604                              <1> cmp_cmd_mem:
  1605 00006B52 B103                <1> 	mov	cl, 3
  1606 00006B54 BF[D9DE0000]        <1> 	mov	edi, Cmd_Mem
  1607 00006B59 E8A5010000          <1> 	call	cmp_cmd	
  1608 00006B5E 0F835FC1FFFF        <1> 	jnc	memory_info
  1609                              <1> 
  1610                              <1> cmp_cmd_del:
  1611 00006B64 B103                <1> 	mov	cl, 3
  1612 00006B66 BF[ACDE0000]        <1> 	mov	edi, Cmd_Del
  1613 00006B6B E893010000          <1> 	call	cmp_cmd	
  1614 00006B70 0F83340F0000        <1>         jnc     delete_file
  1615                              <1> 
  1616                              <1> cmp_cmd_set:
  1617 00006B76 B103                <1> 	mov	cl, 3
  1618 00006B78 BF[9FDE0000]        <1> 	mov	edi, Cmd_Set
  1619 00006B7D E881010000          <1> 	call	cmp_cmd	
  1620 00006B82 0F830C180000        <1>         jnc     set_get_env
  1621                              <1> 
  1622                              <1> cmp_cmd_run:
  1623 00006B88 B103                <1> 	mov	cl, 3
  1624 00006B8A BF[9BDE0000]        <1> 	mov	edi, Cmd_Run
  1625 00006B8F E86F010000          <1> 	call	cmp_cmd	
  1626                              <1> 	; 07/05/2016
  1627 00006B94 0F824C010000        <1>         jc      cmp_cmd_external
  1628 00006B9A E9431E0000          <1> 	jmp	load_and_execute_file
  1629                              <1> c_5:
  1630                              <1> cmp_cmd_mkdir:
  1631 00006B9F BF[C4DE0000]        <1> 	mov	edi, Cmd_Mkdir
  1632 00006BA4 E85A010000          <1> 	call	cmp_cmd	
  1633 00006BA9 0F83930A0000        <1>         jnc     make_directory
  1634                              <1> 
  1635                              <1> cmp_cmd_rmdir:
  1636 00006BAF B105                <1> 	mov	cl, 5
  1637 00006BB1 BF[BEDE0000]        <1> 	mov	edi, Cmd_Rmdir
  1638 00006BB6 E848010000          <1> 	call	cmp_cmd	
  1639 00006BBB 0F83A00B0000        <1>         jnc     delete_directory
  1640                              <1> 
  1641                              <1> cmp_cmd_chdir:
  1642 00006BC1 B105                <1> 	mov	cl, 5
  1643 00006BC3 BF[04DF0000]        <1> 	mov	edi, Cmd_Chdir
  1644 00006BC8 E836010000          <1> 	call	cmp_cmd	
  1645 00006BCD 0F8213010000        <1>         jc      cmp_cmd_external
  1646                              <1> 
  1647 00006BD3 E99FFEFFFF          <1> 	jmp	cd_0
  1648                              <1> 
  1649                              <1> c_6:
  1650 00006BD8 80F906              <1> 	cmp	cl, 6
  1651 00006BDB 0F87DF000000        <1>         ja      c_8
  1652 00006BE1 72BC                <1> 	jb	short c_5
  1653                              <1> cmp_cmd_prompt:
  1654 00006BE3 BF[7ADE0000]        <1> 	mov	edi, Cmd_Prompt
  1655 00006BE8 E816010000          <1> 	call	cmp_cmd	
  1656 00006BED 722E                <1>         jc	short cmp_cmd_volume
  1657                              <1> get_prompt_name_fchar:
  1658 00006BEF AC                  <1> 	lodsb
  1659 00006BF0 3C20                <1> 	cmp	al, 20h
  1660 00006BF2 74FB                <1> 	je	short get_prompt_name_fchar
  1661 00006BF4 7712                <1> 	ja	short loc_change_prompt_label
  1662 00006BF6 BE[5BDE0000]        <1> 	mov	esi, TRDOSPromptLabel
  1663 00006BFB C7065452444F        <1> 	mov	dword [esi], "TRDO"
  1664 00006C01 66C746045300        <1>        	mov	word [esi+4], "S" 
  1665                              <1> loc_cmd_prompt_return:
  1666 00006C07 C3                  <1> 	retn
  1667                              <1> loc_change_prompt_label:
  1668 00006C08 66B90B00            <1> 	mov	cx, 11
  1669 00006C0C BF[5BDE0000]        <1> 	mov	edi, TRDOSPromptLabel
  1670                              <1> put_char_new_prompt_label:
  1671 00006C11 AA                  <1> 	stosb
  1672 00006C12 AC                  <1> 	lodsb
  1673 00006C13 3C20                <1> 	cmp	al, 20h
  1674 00006C15 7202                <1> 	jb	short pass_put_new_prompt_label
  1675 00006C17 E2F8                <1> 	loop	put_char_new_prompt_label
  1676                              <1> pass_put_new_prompt_label:
  1677 00006C19 C60700              <1> 	mov	byte [edi], 0
  1678 00006C1C C3                  <1> 	retn
  1679                              <1> 
  1680                              <1> cmp_cmd_volume:
  1681 00006C1D B106                <1> 	mov	cl, 6
  1682 00006C1F BF[81DE0000]        <1> 	mov	edi, Cmd_Volume
  1683 00006C24 E8DA000000          <1> 	call	cmp_cmd	
  1684 00006C29 7255                <1>         jc	short cmp_cmd_attrib
  1685                              <1> 
  1686                              <1> cmd_vol1:
  1687 00006C2B AC                  <1> 	lodsb
  1688 00006C2C 3C20                <1> 	cmp	al, 20h
  1689 00006C2E 7707                <1> 	ja	short cmd_vol2
  1690 00006C30 A0[8E200100]        <1> 	mov	al, [Current_Drv]
  1691 00006C35 EB3D                <1> 	jmp	short cmd_vol4
  1692                              <1> cmd_vol2:
  1693 00006C37 3C41                <1> 	cmp	al, 'A'
  1694 00006C39 0F82B1000000        <1>         jb      loc_cmd_failed
  1695 00006C3F 3C7A                <1> 	cmp	al, 'z'
  1696 00006C41 0F87A9000000        <1>         ja      loc_cmd_failed
  1697 00006C47 3C5A                <1> 	cmp	al, 'Z'
  1698 00006C49 760A                <1> 	jna	short cmd_vol3
  1699 00006C4B 3C61                <1> 	cmp	al, 'a'
  1700 00006C4D 0F829D000000        <1>         jb      loc_cmd_failed
  1701 00006C53 24DF                <1> 	and	al, 0DFh
  1702                              <1> cmd_vol3:
  1703 00006C55 8A26                <1> 	mov	ah, [esi]
  1704 00006C57 80FC3A              <1> 	cmp	ah, ':'
  1705 00006C5A 0F8590000000        <1>         jne     loc_cmd_failed
  1706 00006C60 2C41                <1> 	sub	al, 'A'
  1707 00006C62 3A05[07DE0000]      <1>         cmp     al, [Last_DOS_DiskNo]
  1708 00006C68 760A                <1> 	jna	short cmd_vol4
  1709                              <1> 
  1710 00006C6A BE[D0E00000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1711 00006C6F E9E2E8FFFF          <1> 	jmp	print_msg
  1712                              <1> 	
  1713                              <1> cmd_vol4:
  1714 00006C74 E896FAFFFF          <1> 	call	print_volume_info
  1715 00006C79 0F8278FEFFFF        <1>         jc      cd_drive_not_ready
  1716 00006C7F C3                  <1> 	retn
  1717                              <1> 
  1718                              <1> cmp_cmd_attrib:
  1719 00006C80 B106                <1> 	mov	cl, 6
  1720 00006C82 BF[B0DE0000]        <1> 	mov	edi, Cmd_Attrib
  1721 00006C87 E877000000          <1> 	call	cmp_cmd	
  1722 00006C8C 0F83380F0000        <1>         jnc     set_file_attributes
  1723                              <1> 
  1724                              <1> cmp_cmd_rename:
  1725 00006C92 B106                <1> 	mov	cl, 6
  1726 00006C94 BF[B7DE0000]        <1> 	mov	edi, Cmd_Rename
  1727 00006C99 E865000000          <1> 	call	cmp_cmd	
  1728 00006C9E 0F836E110000        <1>         jnc     rename_file
  1729                              <1> 
  1730                              <1> cmp_cmd_device:
  1731 00006CA4 B106                <1> 	mov	cl, 6
  1732 00006CA6 BF[F5DE0000]        <1> 	mov	edi, Cmd_Device
  1733 00006CAB E853000000          <1> 	call	cmp_cmd	
  1734 00006CB0 7234                <1>         jc	short cmp_cmd_external
  1735                              <1> 
  1736 00006CB2 C3                  <1> 	retn
  1737                              <1> 
  1738                              <1> c_7:
  1739                              <1> cmp_cmd_devlist:
  1740 00006CB3 BF[FCDE0000]        <1> 	mov	edi, Cmd_DevList
  1741 00006CB8 E846000000          <1> 	call	cmp_cmd	
  1742 00006CBD 7227                <1>         jc	short cmp_cmd_external
  1743                              <1> 
  1744 00006CBF C3                  <1> 	retn
  1745                              <1> 
  1746                              <1> c_8:
  1747 00006CC0 80F908              <1>         cmp	cl, 8
  1748 00006CC3 7721                <1> 	ja	short cmp_cmd_external
  1749 00006CC5 72EC                <1> 	jb	short c_7
  1750                              <1> 
  1751                              <1> cmp_cmd_longname:
  1752 00006CC7 BF[88DE0000]        <1> 	mov	edi, Cmd_LongName
  1753 00006CCC E832000000          <1> 	call	cmp_cmd	
  1754 00006CD1 0F8351060000        <1>         jnc     get_and_print_longname
  1755                              <1> 
  1756                              <1> cmp_cmd_readfile:
  1757 00006CD7 B108                <1> 	mov	cl, 8
  1758 00006CD9 BF[E3DE0000]        <1> 	mov	edi, Cmd_ReadFile
  1759 00006CDE E820000000          <1> 	call	cmp_cmd	
  1760 00006CE3 7201                <1>         jc	short cmp_cmd_external
  1761                              <1> 
  1762                              <1> loc_cmd_return:
  1763 00006CE5 C3                  <1> 	retn
  1764                              <1> 
  1765                              <1> cmp_cmd_external:
  1766                              <1> 	; 07/05/2016
  1767                              <1> 	; 22/04/2016
  1768 00006CE6 BE[3E210100]        <1> 	mov	esi, CommandBuffer
  1769 00006CEB E9F21C0000          <1> 	jmp	loc_run_check_filename 
  1770                              <1> 
  1771                              <1> loc_cmd_failed:
  1772 00006CF0 803D[3E210100]20    <1> 	cmp	byte [CommandBuffer], 20h
  1773 00006CF7 76EC                <1> 	jna	short loc_cmd_return
  1774 00006CF9 BE[B1E00000]        <1> 	mov	esi, Msg_Bad_Command
  1775                              <1> ;	call	print_msg
  1776                              <1> ;loc_cmd_return:
  1777                              <1> ;	retn
  1778 00006CFE E953E8FFFF          <1> 	jmp	print_msg
  1779                              <1> 
  1780                              <1> cmp_cmd:
  1781                              <1> 	 ; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
  1782 00006D03 BE[3E210100]        <1>          mov	esi, CommandBuffer
  1783                              <1>          ; edi = internal command word (ASCIIZ)
  1784                              <1> 	 ; ecx = command length (<=8)
  1785                              <1> cmp_cmd_1:
  1786 00006D08 AC                  <1> 	lodsb
  1787 00006D09 AE                  <1> 	scasb
  1788 00006D0A 750D                <1> 	jne	short cmp_cmd_3
  1789 00006D0C E2FA                <1> 	loop	cmp_cmd_1
  1790 00006D0E AC                  <1>  	lodsb
  1791 00006D0F 3C20                <1> 	cmp	al, 20h
  1792 00006D11 7703                <1> 	ja	short cmp_cmd_2
  1793 00006D13 30C0                <1> 	xor	al, al
  1794                              <1> 	; ZF = 1 -> internal command word matches
  1795 00006D15 C3                  <1> 	retn
  1796                              <1> cmp_cmd_2:
  1797                              <1> 	; ZF = 0 (CF = 0) -> external command word 	
  1798 00006D16 58                  <1> 	pop	eax ; no return to the caller from here 
  1799 00006D17 EBCD                <1> 	jmp	cmp_cmd_external	
  1800                              <1> cmp_cmd_3:
  1801 00006D19 F9                  <1> 	stc
  1802                              <1> 	; CF = 1 -> internal command word does not match
  1803 00006D1A C3                  <1> 	retn
  1804                              <1> 
  1805                              <1> loc_run_cmd_failed:
  1806                              <1> 	; 15/03/2016
  1807                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1808                              <1> 	; 07/12/2009 (CMD_INTR.ASM)	
  1809                              <1> 	; 29/11/2009
  1810                              <1> 
  1811 00006D1B E855000000          <1> 	call	restore_cdir_after_cmd_fail
  1812                              <1> 
  1813                              <1> loc_run_cmd_failed_cmp_al:
  1814                              <1> 	; End of Restore_CDIR code (29/11/2009)
  1815                              <1> 
  1816 00006D20 3C01                <1> 	cmp	al, 1
  1817 00006D22 74CC                <1> 	je	loc_cmd_failed
  1818                              <1> loc_run_dir_not_found:
  1819 00006D24 3C03                <1> 	cmp	al, 3
  1820 00006D26 750A                <1> 	jne	short loc_run_file_notfound_msg
  1821                              <1> 	; Path not found (MS-DOS Error Code = 3)
  1822 00006D28 BE[13E10000]        <1> 	mov	esi, Msg_Dir_Not_Found
  1823 00006D2D E924E8FFFF          <1> 	jmp	print_msg
  1824                              <1> 
  1825                              <1> loc_run_file_notfound_msg:
  1826 00006D32 3C02                <1> 	cmp	al, 2 ; File not found
  1827 00006D34 750A                <1> 	jne	short loc_run_file_drv_read_err
  1828                              <1> 
  1829                              <1> loc_print_file_notfound_msg: 
  1830 00006D36 BE[2AE10000]        <1>         mov     esi, Msg_File_Not_Found
  1831                              <1> 	;call	proc_printmsg
  1832                              <1> 	;retn
  1833 00006D3B E916E8FFFF          <1> 	jmp	print_msg
  1834                              <1> 
  1835                              <1> loc_run_file_drv_read_err:
  1836                              <1> 	; Err: 1Eh (Read fault)
  1837 00006D40 3C1E                <1> 	cmp	al, 1Eh ; Drive not ready or read error
  1838 00006D42 7404                <1> 	je	short loc_run_file_print_drv_read_err
  1839                              <1> 	;
  1840 00006D44 3C15                <1> 	cmp	al, 15h ; Drive not ready (or read error)
  1841 00006D46 750A                <1> 	jne	short loc_run_file_toobig
  1842                              <1> 
  1843                              <1> loc_run_file_print_drv_read_err:
  1844 00006D48 BE[D0E00000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1845 00006D4D E904E8FFFF          <1> 	jmp	print_msg
  1846                              <1> 
  1847                              <1> loc_run_file_toobig:
  1848 00006D52 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
  1849 00006D54 750A                <1> 	jne	short loc_run_misc_error
  1850 00006D56 BE[72E10000]        <1> 	mov	esi, Msg_Insufficient_Memory
  1851 00006D5B E9F6E7FFFF          <1> 	jmp	print_msg
  1852                              <1> 
  1853                              <1> 	; 15/03/2016
  1854                              <1> print_misc_error_msg:
  1855                              <1> loc_run_misc_error:
  1856                              <1> 	; AL = Error code
  1857 00006D60 E8D3BFFFFF          <1> 	call	bytetohex
  1858 00006D65 66A3[A6E10000]      <1>         mov     [error_code_hex], ax
  1859                              <1> 	
  1860 00006D6B BE[89E10000]        <1> 	mov	esi, Msg_Error_Code 
  1861                              <1> 	;call	print_msg 
  1862                              <1> 	;retn
  1863                              <1> 
  1864 00006D70 E9E1E7FFFF          <1> 	jmp	print_msg
  1865                              <1> 
  1866                              <1> restore_cdir_after_cmd_fail:
  1867                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1868 00006D75 50                  <1> 	push	eax
  1869 00006D76 8A3D[EE280100]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
  1870                              <1> 				; of the 'run' command.
  1871 00006D7C 3A3D[8E200100]      <1> 	cmp	bh, [Current_Drv]
  1872 00006D82 7409                <1> 	je	short loc_run_restore_cdir
  1873 00006D84 88FA                <1> 	mov	dl, bh
  1874 00006D86 E8CBF0FFFF          <1> 	call	change_current_drive 
  1875 00006D8B EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
  1876                              <1> 
  1877                              <1> loc_run_restore_cdir:
  1878 00006D8D 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  1879 00006D94 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
  1880 00006D96 30DB                <1> 	xor	bl, bl
  1881 00006D98 0FB7F3              <1> 	movzx	esi, bx
  1882 00006D9B 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1883 00006DA1 E862F1FFFF          <1> 	call	restore_current_directory
  1884                              <1> 
  1885                              <1> loc_run_err_pass_restore_cdir:
  1886 00006DA6 58                  <1> 	pop	eax
  1887 00006DA7 C3                  <1> 	retn
  1888                              <1> 
  1889                              <1> print_directory_list:
  1890                              <1> 	; 10/02/2016
  1891                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1892                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
  1893                              <1> 	;
  1894 00006DA8 66C705[302A0100]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
  1894 00006DB0 08                  <1>
  1895 00006DB1 A0[8E200100]        <1> 	mov	al, [Current_Drv]
  1896 00006DB6 A2[EE280100]        <1> 	mov	[RUN_CDRV], al
  1897                              <1> get_dfname_fchar:
  1898 00006DBB AC                  <1> 	lodsb
  1899 00006DBC 3C20                <1> 	cmp	al, 20h
  1900 00006DBE 74FB                <1> 	je	short get_dfname_fchar
  1901 00006DC0 0F82A4000000        <1>         jb      loc_print_dir_call_all
  1902 00006DC6 3C2D                <1> 	cmp	al, '-'
  1903 00006DC8 7542                <1> 	jne	short loc_print_dir_call_flt
  1904                              <1> get_next_attr_char:
  1905 00006DCA AC                  <1> 	lodsb
  1906 00006DCB 3C20                <1> 	cmp	al, 20h
  1907 00006DCD 74FB                <1> 	je	short get_next_attr_char
  1908 00006DCF 0F821BFFFFFF        <1>         jb      loc_cmd_failed
  1909 00006DD5 24DF                <1> 	and	al, 0DFh
  1910 00006DD7 3C44                <1> 	cmp	al, 'D' ; directories only ?
  1911 00006DD9 7512                <1> 	jne	short pass_only_directories
  1912 00006DDB AC                  <1> 	lodsb
  1913 00006DDC 3C20                <1> 	cmp	al, 20h
  1914 00006DDE 0F870CFFFFFF        <1>         ja      loc_cmd_failed
  1915 00006DE4 800D[302A0100]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
  1916 00006DEB EB18                <1> 	jmp	short get_dfname_fchar_attr
  1917                              <1> pass_only_directories:
  1918 00006DED 3C46                <1> 	cmp	al, 'F'	; files only ?
  1919 00006DEF 0F85B0000000        <1>         jne     check_attr_s
  1920 00006DF5 AC                  <1> 	lodsb
  1921 00006DF6 3C20                <1> 	cmp	al, 20h
  1922 00006DF8 0F87F2FEFFFF        <1>         ja      loc_cmd_failed
  1923 00006DFE 800D[312A0100]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
  1924                              <1> get_dfname_fchar_attr:
  1925 00006E05 AC                  <1> 	lodsb
  1926 00006E06 3C20                <1> 	cmp	al, 20h
  1927 00006E08 74FB                <1> 	je	short get_dfname_fchar_attr
  1928 00006E0A 725E                <1> 	jb	short loc_print_dir_call_all
  1929                              <1> 
  1930                              <1> loc_print_dir_call_flt:
  1931 00006E0C 4E                  <1> 	dec	esi
  1932 00006E0D BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  1933 00006E12 E8E5250000          <1> 	call	parse_path_name
  1934 00006E17 7308                <1>  	jnc	short loc_print_dir_change_drv_1
  1935 00006E19 3C01                <1> 	cmp	al, 1
  1936 00006E1B 0F87FAFEFFFF        <1>         ja      loc_run_cmd_failed
  1937                              <1> 
  1938                              <1> loc_print_dir_change_drv_1:
  1939 00006E21 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  1940                              <1> loc_print_dir_change_drv_2:
  1941 00006E27 3A15[EE280100]      <1> 	cmp	dl, [RUN_CDRV]
  1942 00006E2D 740B                <1> 	je	short loc_print_dir_change_directory 
  1943 00006E2F E822F0FFFF          <1> 	call	change_current_drive
  1944 00006E34 0F82E1FEFFFF        <1>         jc      loc_run_cmd_failed
  1945                              <1> loc_print_dir_change_directory:
  1946 00006E3A 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
  1947 00006E41 761D                <1> 	jna	short pass_print_dir_change_directory
  1948                              <1> 
  1949 00006E43 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  1950 00006E49 BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  1951 00006E4E 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  1952 00006E50 E8931F0000          <1> 	call	change_current_directory
  1953 00006E55 0F82C0FEFFFF        <1>         jc      loc_run_cmd_failed
  1954                              <1> 
  1955                              <1> loc_print_dir_change_prompt_dir_string:
  1956 00006E5B E8A81E0000          <1> 	call	change_prompt_dir_string
  1957                              <1> 
  1958                              <1> pass_print_dir_change_directory:
  1959 00006E60 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  1960 00006E65 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
  1961 00006E68 7706                <1> 	ja	short loc_print_dir_call
  1962                              <1> 
  1963                              <1> loc_print_dir_call_all:
  1964 00006E6A C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
  1965                              <1> loc_print_dir_call:
  1966 00006E70 E87E000000          <1> 	call	print_directory
  1967                              <1> 
  1968 00006E75 8A15[EE280100]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
  1969 00006E7B 3A15[8E200100]      <1> 	cmp	dl, [Current_Drv]
  1970 00006E81 7406                <1> 	je	short loc_print_dir_call_restore_cdir_retn
  1971 00006E83 E8CEEFFFFF          <1> 	call	change_current_drive 
  1972 00006E88 C3                  <1> 	retn
  1973                              <1> 
  1974                              <1> loc_print_dir_call_restore_cdir_retn:
  1975 00006E89 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  1976 00006E90 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
  1977                              <1> 
  1978 00006E92 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1979 00006E97 31C0                <1> 	xor	eax, eax
  1980 00006E99 88D4                <1> 	mov	ah, dl
  1981 00006E9B 01C6                <1> 	add	esi, eax
  1982                              <1> 
  1983 00006E9D E866F0FFFF          <1> 	call	restore_current_directory
  1984                              <1> 
  1985                              <1> pass_print_dir_call_restore_cdir_retn:
  1986 00006EA2 C3                  <1> 	retn
  1987                              <1> 
  1988                              <1> check_attr_s_cap:
  1989 00006EA3 24DF                <1> 	and	al, 0DFh
  1990                              <1> check_attr_s:
  1991 00006EA5 3C53                <1> 	cmp	al, 'S'
  1992 00006EA7 7514                <1> 	jne	short pass_attr_s
  1993 00006EA9 800D[302A0100]04    <1> 	or	byte [AttributesMask], 4 ; system
  1994 00006EB0 AC                  <1> 	lodsb
  1995 00006EB1 3C20                <1> 	cmp	al, 20h
  1996 00006EB3 0F844CFFFFFF        <1>         je      get_dfname_fchar_attr
  1997 00006EB9 72AF                <1> 	jb	short loc_print_dir_call_all
  1998 00006EBB 24DF                <1> 	and	al, 0DFh
  1999                              <1> pass_attr_s:
  2000 00006EBD 3C48                <1> 	cmp	al, 'H'
  2001 00006EBF 7514                <1> 	jne	short pass_attr_h
  2002 00006EC1 800D[302A0100]02    <1> 	or	byte [AttributesMask], 2 ; hidden
  2003                              <1> pass_attr_shr:
  2004 00006EC8 AC                  <1> 	lodsb
  2005 00006EC9 3C20                <1> 	cmp	al, 20h
  2006 00006ECB 0F8434FFFFFF        <1>         je      get_dfname_fchar_attr
  2007 00006ED1 7297                <1> 	jb	short loc_print_dir_call_all
  2008 00006ED3 EBCE                <1> 	jmp	short check_attr_s_cap
  2009                              <1> 
  2010                              <1> pass_attr_h:
  2011 00006ED5 3C52                <1> 	cmp	al, 'R'
  2012 00006ED7 7509                <1> 	jne	short pass_attr_r
  2013 00006ED9 800D[302A0100]01    <1> 	or	byte [AttributesMask], 1 ; read only
  2014 00006EE0 EBE6                <1> 	jmp	short pass_attr_shr
  2015                              <1> 
  2016                              <1> pass_attr_r:
  2017 00006EE2 3C41                <1> 	cmp	al, 'A'
  2018 00006EE4 0F8506FEFFFF        <1>         jne     loc_cmd_failed
  2019 00006EEA 800D[302A0100]20    <1> 	or	byte [AttributesMask], 20h ; archive
  2020 00006EF1 EBD5                <1> 	jmp	short pass_attr_shr
  2021                              <1> 
  2022                              <1> print_directory:
  2023                              <1> 	; 13/05/2016
  2024                              <1> 	; 11/02/2016
  2025                              <1> 	; 10/02/2016
  2026                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2027                              <1> 	; 30/10/2010 ('proc_print_directory')	
  2028                              <1> 	; 19/09/2009
  2029                              <1> 	; 2005 
  2030                              <1> 	; INPUT ->
  2031                              <1> 	;	ESI = Asciiz File/Dir Name Address
  2032                              <1> 
  2033 00006EF3 56                  <1> 	push	esi
  2034                              <1> 
  2035 00006EF4 29C0                <1> 	sub	eax, eax
  2036                              <1> 
  2037 00006EF6 66A3[BC2A0100]      <1> 	mov	word [Dir_Count], ax ; 0
  2038 00006EFC 66A3[BA2A0100]      <1> 	mov 	word [File_Count], ax ; 0
  2039 00006F02 A3[BE2A0100]        <1> 	mov 	dword [Total_FSize], eax ; 0
  2040                              <1> 
  2041 00006F07 E860E6FFFF          <1> 	call    clear_screen
  2042                              <1> 	
  2043 00006F0C 31C9                <1> 	xor	ecx, ecx	
  2044 00006F0E 8A2D[8E200100]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
  2045 00006F14 A0[8F200100]        <1> 	mov     al, [Current_Dir_Drv] 
  2046 00006F19 A2[CEDF0000]        <1> 	mov     [Dir_Drive_Name], al
  2047 00006F1E BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2048 00006F23 01CE                <1> 	add	esi, ecx
  2049                              <1> 
  2050 00006F25 E85FF9FFFF          <1> 	call	move_volume_name_and_serial_no
  2051 00006F2A 730C                <1> 	jnc	short print_dir_strlen_check
  2052                              <1> 
  2053 00006F2C 5E                  <1> 	pop	esi
  2054 00006F2D 8A3D[F61F0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  2055                              <1> 	;call	beeper
  2056                              <1> 	;retn
  2057 00006F33 E9C9ACFFFF          <1> 	jmp	beeper  ; beep ! and return
  2058                              <1> 
  2059                              <1> print_dir_strlen_check:
  2060 00006F38 BE[91200100]        <1> 	mov	esi, Current_Dir_Root
  2061 00006F3D BF[6BE00000]        <1> 	mov	edi, Dir_Str_Root
  2062                              <1> 	
  2063                              <1> 	;xor	ecx, ecx
  2064 00006F42 8A0D[ED200100]      <1>         mov     cl, [Current_Dir_StrLen]
  2065 00006F48 FEC1                <1> 	inc	cl
  2066 00006F4A 80F940              <1> 	cmp	cl, 64
  2067 00006F4D 760D                <1> 	jna	short pass_print_dir_strlen_shorting
  2068 00006F4F 46                  <1> 	inc	esi
  2069 00006F50 01CE                <1> 	add	esi, ecx
  2070 00006F52 83EE40              <1> 	sub	esi, 64 
  2071 00006F55 47                  <1> 	inc	edi
  2072 00006F56 B82E2E2E20          <1> 	mov	eax, '... ' 
  2073 00006F5B AB                  <1> 	stosd
  2074                              <1>  
  2075                              <1> pass_print_dir_strlen_shorting:
  2076 00006F5C F3A4                <1> 	rep	movsb
  2077                              <1> 
  2078 00006F5E BE[C1DF0000]        <1> 	mov	esi, Dir_Drive_Str
  2079 00006F63 E8EEE5FFFF          <1> 	call	print_msg
  2080                              <1> 
  2081 00006F68 BE[20E00000]        <1> 	mov	esi, Vol_Serial_Header
  2082 00006F6D E8E4E5FFFF          <1> 	call	print_msg
  2083                              <1> 
  2084 00006F72 BE[60E00000]        <1> 	mov	esi, Dir_Str_Header
  2085 00006F77 E8DAE5FFFF          <1> 	call	print_msg
  2086                              <1> 	
  2087 00006F7C BE[A9EE0000]        <1> 	mov	esi, next2line
  2088 00006F81 E8D0E5FFFF          <1> 	call	print_msg
  2089                              <1> 
  2090                              <1> loc_print_dir_first_file:
  2091 00006F86 C605[D12A0100]10    <1> 	mov	byte [PrintDir_RowCounter], 16
  2092 00006F8D 66A1[302A0100]      <1> 	mov	ax, [AttributesMask]
  2093 00006F93 5E                  <1> 	pop	esi
  2094                              <1> 
  2095 00006F94 E859020000          <1> 	call	find_first_file
  2096 00006F99 0F826F010000        <1>         jc      loc_dir_ok
  2097                              <1> 	 
  2098                              <1> loc_dfname_use_this:
  2099                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
  2100 00006F9F F6C310              <1> 	test	bl, 10h  ; Is it a directory?
  2101 00006FA2 741B                <1> 	jz	short loc_not_dir
  2102                              <1> 
  2103 00006FA4 66FF05[BC2A0100]    <1> 	inc	word [Dir_Count]
  2104 00006FAB 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
  2105 00006FAD BE[ACE10000]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
  2106 00006FB2 BF[C3E10000]        <1> 	mov	edi, Dir_Or_FileSize
  2107                              <1> 	; move 10 bytes
  2108 00006FB7 A5                  <1> 	movsd
  2109 00006FB8 A5                  <1> 	movsd
  2110 00006FB9 66A5                <1> 	movsw	    	
  2111 00006FBB 89D6                <1> 	mov	esi, edx
  2112 00006FBD EB36                <1> 	jmp     short loc_dir_attribute
  2113                              <1> 
  2114                              <1> loc_not_dir:
  2115 00006FBF 66FF05[BA2A0100]    <1> 	inc	word [File_Count]
  2116 00006FC6 0105[BE2A0100]      <1> 	add	[Total_FSize], eax
  2117                              <1> 
  2118 00006FCC B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
  2119 00006FD1 89CF                <1> 	mov	edi, ecx
  2120 00006FD3 81C7[C3E10000]      <1> 	add	edi, Dir_Or_FileSize
  2121                              <1> loc_dir_rdivide:
  2122 00006FD9 29D2                <1> 	sub	edx, edx
  2123 00006FDB F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
  2124 00006FDD 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
  2125 00006FE0 4F                  <1> 	dec	edi
  2126 00006FE1 8817                <1> 	mov     [edi], dl
  2127 00006FE3 21C0                <1> 	and	eax, eax
  2128 00006FE5 75F2                <1> 	jnz	short loc_dir_rdivide
  2129                              <1> 
  2130                              <1> loc_dir_fill_space:
  2131 00006FE7 81FF[C3E10000]      <1> 	cmp     edi, Dir_Or_FileSize
  2132 00006FED 7606                <1> 	jna     short loc_dir_attribute
  2133 00006FEF 4F                  <1> 	dec     edi
  2134 00006FF0 C60720              <1> 	mov     byte [edi], 20h
  2135 00006FF3 EBF2                <1> 	jmp     short loc_dir_fill_space
  2136                              <1> 
  2137                              <1> loc_dir_attribute:
  2138 00006FF5 C705[CEE10000]2020- <1> 	mov	dword [File_Attribute], 20202020h
  2138 00006FFD 2020                <1>
  2139                              <1> 
  2140 00006FFF 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
  2141 00007002 7207                <1> 	jb	short loc_dir_pass_arch
  2142 00007004 C605[D1E10000]41    <1> 	mov	byte [File_Attribute+3], 'A'
  2143                              <1> 
  2144                              <1> loc_dir_pass_arch:
  2145 0000700B 80E307              <1> 	and	bl, 7
  2146 0000700E 7428                <1> 	jz	short loc_dir_file_name
  2147 00007010 88DF                <1> 	mov	bh, bl
  2148 00007012 80E303              <1> 	and	bl, 3
  2149 00007015 38DF                <1> 	cmp	bh, bl
  2150 00007017 7607                <1> 	jna	short loc_dir_pass_s
  2151 00007019 C605[CEE10000]53    <1> 	mov	byte [File_Attribute], 'S'
  2152                              <1> 
  2153                              <1> loc_dir_pass_s:
  2154 00007020 80E302              <1> 	and     bl,2
  2155 00007023 7407                <1> 	jz      short loc_dir_pass_h
  2156 00007025 C605[CFE10000]48    <1> 	mov     byte [File_Attribute+1], 'H'
  2157                              <1> loc_dir_pass_h:
  2158 0000702C 80E701              <1> 	and     bh,1
  2159 0000702F 7407                <1> 	jz      short loc_dir_file_name
  2160 00007031 C605[D0E10000]52    <1> 	mov     byte [File_Attribute+2], 'R'
  2161                              <1> loc_dir_file_name:
  2162                              <1> 	;mov     bx, [esi+18h] ; Date
  2163                              <1> 	;mov     dx, [esi+16h] ; Time
  2164 00007038 8B5E16              <1> 	mov	ebx, [esi+16h]
  2165 0000703B 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
  2166 0000703D BF[B6E10000]        <1> 	mov     edi, File_Name
  2167                              <1> 	; move 8 bytes
  2168 00007042 A5                  <1> 	movsd
  2169 00007043 A5                  <1> 	movsd
  2170 00007044 C60720              <1> 	mov	byte [edi], 20h
  2171 00007047 47                  <1> 	inc	edi
  2172                              <1> 	; move 3 bytes
  2173 00007048 66A5                <1> 	movsw
  2174 0000704A A4                  <1> 	movsb
  2175 0000704B 89CE                <1> 	mov	esi, ecx
  2176                              <1> 
  2177                              <1> Dir_Time_start:
  2178                              <1> 	;mov	ax, dx		; Time
  2179 0000704D 6689D8              <1> 	mov	ax, bx
  2180 00007050 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
  2181 00007054 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
  2182 00007058 D40A                <1> 	aam			; Q([AL]/10)->AH
  2183                              <1> 				; R([AL]/10)->AL
  2184                              <1> 				; [AL]+[AH]= Minute as BCD
  2185 0000705A 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2186 0000705E 86E0                <1> 	xchg	ah, al
  2187 00007060 66A3[E1E10000]      <1> 	mov	[File_Minute], ax
  2188                              <1> 
  2189                              <1> 	;mov	al, dh
  2190 00007066 88F8                <1> 	mov	al, bh
  2191 00007068 C0E803              <1> 	shr	al, 3		; shift right 3 times
  2192 0000706B D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
  2193 0000706D 660D3030            <1> 	or	ax, '00'
  2194 00007071 86E0                <1> 	xchg	ah, al
  2195 00007073 66A3[DEE10000]      <1> 	mov     [File_Hour], ax
  2196                              <1> 
  2197 00007079 C1EB10              <1> 	shr	ebx, 16		; BX = Date
  2198                              <1> 	
  2199                              <1> Dir_Date_start:
  2200 0000707C 6689D8              <1> 	mov	ax, bx		; Date
  2201 0000707F 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
  2202 00007083 D40A                <1> 	aam			; Q([AL]/10)->AH
  2203                              <1> 				; R([AL]/10)->AL
  2204                              <1> 				; [AL]+[AH]= Day as BCD
  2205 00007085 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2206 00007089 86C4                <1> 	xchg	al, ah
  2207                              <1> 
  2208 0000708B 66A3[D3E10000]      <1> 	mov	[File_Day], ax
  2209                              <1> 
  2210 00007091 6689D8              <1> 	mov	ax, bx
  2211 00007094 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
  2212 00007098 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
  2213 0000709C D40A                <1> 	aam
  2214 0000709E 660D3030            <1> 	or	ax, '00'
  2215 000070A2 86E0                <1> 	xchg	ah, al
  2216 000070A4 66A3[D6E10000]      <1> 	mov	[File_Month], ax
  2217                              <1> 
  2218 000070AA 6689D8              <1> 	mov	ax, bx
  2219 000070AD 66C1E809            <1> 	shr     ax, 9
  2220 000070B1 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
  2221 000070B5 6605BC07            <1> 	add	ax, 1980
  2222                              <1> 
  2223 000070B9 B10A                <1> 	mov	cl, 10
  2224 000070BB F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
  2225 000070BD 80CC30              <1> 	or	ah, '0'
  2226 000070C0 8825[DCE10000]      <1> 	mov	[File_Year+3], ah
  2227 000070C6 D40A                <1> 	aam
  2228 000070C8 86E0                <1> 	xchg	ah, al
  2229 000070CA 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
  2230 000070CD 8825[DBE10000]      <1> 	mov	[File_Year+2], ah
  2231 000070D3 D40A                <1> 	aam
  2232 000070D5 86C4                <1> 	xchg	al, ah
  2233 000070D7 660D3030            <1> 	or	ax, '00'
  2234 000070DB 66A3[D9E10000]      <1> 	mov	[File_Year], ax
  2235                              <1> 
  2236                              <1> loc_show_line:
  2237 000070E1 56                  <1> 	push	esi
  2238 000070E2 BE[B6E10000]        <1> 	mov     esi, File_Name
  2239 000070E7 E86AE4FFFF          <1> 	call	print_msg
  2240 000070EC BE[ABEE0000]        <1> 	mov	esi, nextline
  2241 000070F1 E860E4FFFF          <1> 	call	print_msg
  2242 000070F6 5E                  <1> 	pop	esi
  2243                              <1> 
  2244 000070F7 FE0D[D12A0100]      <1> 	dec	byte [PrintDir_RowCounter]
  2245 000070FD 0F84D4000000        <1>         jz      pause_dir_scroll
  2246                              <1> 
  2247                              <1> loc_next_entry:
  2248 00007103 E899010000          <1> 	call	find_next_file
  2249 00007108 0F8391FEFFFF        <1>         jnc     loc_dfname_use_this
  2250                              <1> 
  2251                              <1> loc_dir_ok:
  2252 0000710E B90A000000          <1> 	mov     ecx, 10
  2253 00007113 66A1[BC2A0100]      <1> 	mov	ax, [Dir_Count]
  2254 00007119 BF[F7E10000]        <1> 	mov	edi, Decimal_Dir_Count
  2255 0000711E 6639C8              <1> 	cmp	ax, cx ; 10
  2256 00007121 7216                <1> 	jb	short pass_ddc
  2257 00007123 47                  <1> 	inc	edi
  2258 00007124 6683F864            <1> 	cmp	ax, 100
  2259 00007128 720F                <1> 	jb	short pass_ddc
  2260 0000712A 47                  <1> 	inc	edi
  2261 0000712B 663DE803            <1> 	cmp	ax, 1000
  2262 0000712F 7208                <1> 	jb	short pass_ddc
  2263 00007131 47                  <1> 	inc	edi
  2264 00007132 663D1027            <1> 	cmp	ax, 10000
  2265 00007136 7201                <1> 	jb	short pass_ddc
  2266 00007138 47                  <1> 	inc	edi
  2267                              <1> pass_ddc:
  2268 00007139 886F01              <1> 	mov     [edi+1], ch ; 0
  2269                              <1> loc_ddc_rediv:
  2270 0000713C 31D2                <1> 	xor     edx, edx
  2271 0000713E 66F7F1              <1> 	div     cx	; 10
  2272 00007141 80C230              <1> 	add     dl, '0'
  2273 00007144 8817                <1> 	mov     [edi], dl
  2274 00007146 4F                  <1> 	dec     edi
  2275 00007147 6609C0              <1> 	or	ax, ax
  2276 0000714A 75F0                <1> 	jnz	short loc_ddc_rediv
  2277                              <1> 
  2278 0000714C 66A1[BA2A0100]      <1> 	mov     ax, [File_Count]
  2279 00007152 BF[E6E10000]        <1> 	mov     edi, Decimal_File_Count
  2280 00007157 6639C8              <1> 	cmp     ax, cx ; 10
  2281 0000715A 7216                <1> 	jb      short pass_dfc
  2282 0000715C 47                  <1> 	inc     edi
  2283 0000715D 6683F864            <1> 	cmp     ax, 100
  2284 00007161 720F                <1> 	jb      short pass_dfc
  2285 00007163 47                  <1> 	inc     edi
  2286 00007164 663DE803            <1> 	cmp     ax, 1000
  2287 00007168 7208                <1> 	jb      short pass_dfc
  2288 0000716A 47                  <1> 	inc     edi
  2289 0000716B 663D1027            <1> 	cmp     ax, 10000
  2290 0000716F 7201                <1> 	jb      short pass_dfc
  2291 00007171 47                  <1> 	inc     edi
  2292                              <1> pass_dfc:
  2293                              <1> 	;mov    cx, 10
  2294 00007172 886F01              <1> 	mov     [edi+1], ch ; 00
  2295                              <1> loc_dfc_rediv:
  2296                              <1> 	;xor	dx, dx
  2297 00007175 30D2                <1> 	xor	dl, dl
  2298 00007177 66F7F1              <1> 	div	cx
  2299 0000717A 80C230              <1> 	add	dl, '0'
  2300 0000717D 8817                <1> 	mov	[edi], dl
  2301 0000717F 4F                  <1> 	dec	edi
  2302 00007180 6609C0              <1> 	or	ax, ax
  2303 00007183 75F0                <1> 	jnz	short loc_dfc_rediv
  2304                              <1> 
  2305 00007185 BF[D02A0100]        <1> 	mov     edi, TFS_Dec_End
  2306                              <1>         ;mov    byte [edi], 0
  2307 0000718A A1[BE2A0100]        <1> 	mov     eax, [Total_FSize]
  2308                              <1> 	;mov    ecx, 10
  2309                              <1> rediv_tfs_hex:
  2310                              <1> 	;sub	edx, edx
  2311 0000718F 28D2                <1> 	sub	dl, dl
  2312 00007191 F7F1                <1> 	div	ecx
  2313 00007193 80C230              <1> 	add	dl, '0'
  2314 00007196 4F                  <1> 	dec     edi
  2315 00007197 8817                <1> 	mov     [edi], dl
  2316 00007199 21C0                <1> 	and	eax, eax
  2317 0000719B 75F2                <1> 	jnz	short rediv_tfs_hex
  2318                              <1> 	
  2319 0000719D 893D[C22A0100]      <1> 	mov	[TFS_Dec_Begin], edi
  2320 000071A3 BE[E4E10000]        <1> 	mov	esi, Decimal_File_Count_Header
  2321 000071A8 E8A9E3FFFF          <1> 	call	print_msg
  2322 000071AD BE[ECE10000]        <1> 	mov	esi, str_files
  2323 000071B2 E89FE3FFFF          <1> 	call	print_msg
  2324 000071B7 BE[FDE10000]        <1> 	mov	esi, str_dirs
  2325 000071BC E895E3FFFF          <1> 	call	print_msg
  2326 000071C1 8B35[C22A0100]      <1> 	mov	esi, [TFS_Dec_Begin]
  2327 000071C7 E88AE3FFFF          <1> 	call	print_msg
  2328 000071CC BE[0EE20000]        <1> 	mov	esi, str_bytes
  2329 000071D1 E880E3FFFF          <1> 	call	print_msg
  2330                              <1> 
  2331 000071D6 C3                  <1> 	retn
  2332                              <1> 
  2333                              <1> pause_dir_scroll:
  2334 000071D7 28E4                <1> 	sub	ah, ah           
  2335 000071D9 E8EE98FFFF          <1> 	call	int16h
  2336 000071DE 3C1B                <1> 	cmp	al, 1Bh
  2337 000071E0 0F8428FFFFFF        <1>         je      loc_dir_ok
  2338 000071E6 C605[D12A0100]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
  2339 000071ED E911FFFFFF          <1>         jmp     loc_next_entry
  2340                              <1> 
  2341                              <1> find_first_file:
  2342                              <1> 	; 11/02/2015
  2343                              <1> 	; 10/02/2016
  2344                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2345                              <1> 	; 09/10/2011
  2346                              <1> 	; 17/09/2009
  2347                              <1> 	; 2005
  2348                              <1> 	; INPUT ->
  2349                              <1> 	;	ESI = ASCIIZ File/Dir Name Address (in Current Directory)
  2350                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
  2351                              <1> 	;	      bit 0 = Read Only
  2352                              <1> 	;	      bir 1 = Hidden
  2353                              <1> 	;	      bit 2 = System
  2354                              <1> 	;	      bit 3 = Volume Label
  2355                              <1> 	;	      bit 4 = Directory
  2356                              <1> 	;	      bit 5 = Archive
  2357                              <1> 	;	      bit 6 = Reserved, must be 0
  2358                              <1> 	;	      bit 7 = Reserved, must be 0
  2359                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
  2360                              <1> 	;
  2361                              <1> 	; OUTPUT ->
  2362                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  2363                              <1> 	;	CF = 0 ->
  2364                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
  2365                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
  2366                              <1> 	;	     EAX = File Size
  2367                              <1> 	;	      BL = Attributes of The File/Directory
  2368                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  2369                              <1> 	;             DX > 0 : Ambiguous filename chars are used
  2370                              <1> 	;
  2371                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2372                              <1> 
  2373 000071F2 66A3[822A0100]      <1> 	mov	[FindFile_AttributesMask], ax
  2374 000071F8 BF[842A0100]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
  2375 000071FD 31C0                <1> 	xor	eax, eax
  2376 000071FF B90B000000          <1> 	mov	ecx, 11
  2377 00007204 F3AB                <1> 	rep	stosd	; 44 bytes
  2378                              <1> 	;stosw		; +2 bytes 
  2379                              <1> 	    
  2380 00007206 BF[742A0100]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
  2381 0000720B 39FE                <1> 	cmp	esi, edi
  2382 0000720D 7408                <1> 	je	short loc_fff_mfn_ok
  2383 0000720F 89FA                <1> 	mov	edx, edi 
  2384                              <1> 	 ; move 13 bytes
  2385 00007211 A5                  <1> 	movsd
  2386 00007212 A5                  <1> 	movsd
  2387 00007213 A5                  <1> 	movsd
  2388 00007214 AA                  <1> 	stosb
  2389 00007215 89D6                <1> 	mov	esi, edx
  2390                              <1> loc_fff_mfn_ok:
  2391 00007217 BF[232A0100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  2392 0000721C E810210000          <1> 	call	convert_file_name
  2393 00007221 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  2394                              <1> 
  2395 00007223 66A1[822A0100]      <1> 	mov	ax, [FindFile_AttributesMask]
  2396                              <1> 	;xor	ecx, ecx
  2397 00007229 30C9                <1> 	xor	cl, cl  
  2398 0000722B E80C1E0000          <1> 	call	locate_current_dir_file
  2399 00007230 726E                <1> 	jc	short loc_fff_retn
  2400                              <1> 	; EDI = Directory Entry
  2401                              <1> 	; EBX = Directory Buffer Entry Index/Number
  2402                              <1> 
  2403                              <1> loc_fff_fnf_ln_check:
  2404 00007232 30ED                <1> 	xor	ch, ch 
  2405 00007234 80F60F              <1> 	xor	dh, 0Fh
  2406 00007237 7408                <1> 	jz	short loc_fff_longname_yes
  2407 00007239 882D[812A0100]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
  2408 0000723F EB0C                <1> 	jmp	short loc_fff_longname_no
  2409                              <1> 
  2410                              <1> loc_fff_longname_yes:
  2411                              <1> 	;inc	byte [FindFile_LongNameYes]
  2412 00007241 8A0D[8E290100]      <1> 	mov	cl, [LFN_EntryLength]  
  2413 00007247 880D[812A0100]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
  2414                              <1> 
  2415                              <1> loc_fff_longname_no:
  2416                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
  2417 0000724D 66891D[AC2A0100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  2418 00007254 6689C2              <1> 	mov	dx, ax ; Ambigouos Filename chars used sign > 0
  2419                              <1> 
  2420 00007257 A0[8E200100]        <1> 	mov	al, [Current_Drv]
  2421 0000725C A2[322A0100]        <1> 	mov	[FindFile_Drv], al 
  2422                              <1> 
  2423 00007261 A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2424 00007266 A3[A42A0100]        <1> 	mov	[FindFile_DirFirstCluster], eax
  2425                              <1> 
  2426 0000726B A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
  2427 00007270 A3[A82A0100]        <1> 	mov	[FindFile_DirCluster], eax
  2428                              <1> 
  2429 00007275 66FF05[AE2A0100]    <1> 	inc	word [FindFile_MatchCounter]
  2430                              <1> 
  2431 0000727C 89FB                <1> 	mov	ebx, edi
  2432 0000727E 89FE                <1> 	mov	esi, edi
  2433 00007280 BF[842A0100]        <1> 	mov	edi, FindFile_DirEntry
  2434 00007285 89F8                <1> 	mov	eax, edi
  2435 00007287 B108                <1> 	mov	cl, 8
  2436 00007289 F3A5                <1> 	rep	movsd
  2437 0000728B 89C6                <1> 	mov	esi, eax
  2438 0000728D 89DF                <1> 	mov	edi, ebx
  2439                              <1> 
  2440 0000728F A1[A02A0100]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
  2441                              <1> 
  2442 00007294 8A1D[8F2A0100]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes 
  2443 0000729A 8A3D[812A0100]      <1> 	mov	bh, [FindFile_LongNameYes]
  2444                              <1> 
  2445                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  2446                              <1> 	;mov	[FindFile_DirEntryNumber], cx
  2447                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
  2448                              <1> 	; ecx = 0
  2449                              <1> 
  2450                              <1> loc_fff_retn:
  2451 000072A0 C3                  <1> 	retn
  2452                              <1> 
  2453                              <1> find_next_file:
  2454                              <1> 	; 10/02/2016
  2455                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2456                              <1> 	; 06/02/2011
  2457                              <1> 	; 17/09/2009
  2458                              <1> 	; 2005
  2459                              <1> 	; INPUT ->
  2460                              <1> 	;	NONE, Find First File Parameters
  2461                              <1> 	; OUTPUT ->
  2462                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  2463                              <1> 	;	CF = 0 -> 
  2464                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
  2465                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
  2466                              <1> 	;	    EAX = File Size
  2467                              <1> 	;	      BL = Attributes of The File/Directory
  2468                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  2469                              <1> 	;             DX > 0 : Ambiguous filename chars are used 
  2470                              <1> 	;
  2471                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2472                              <1> 
  2473 000072A1 66833D[AE2A0100]00  <1> 	cmp	word [FindFile_MatchCounter], 0
  2474 000072A9 7707                <1> 	ja	short loc_start_search_next_file
  2475                              <1> 
  2476                              <1> loc_fnf_stc_retn:
  2477 000072AB F9                  <1> 	stc
  2478                              <1> loc_fnf_ax12h_retn:
  2479 000072AC B812000000          <1> 	mov	eax, 12h ; 18, No More files
  2480                              <1> ;loc_fnf_retn:
  2481 000072B1 C3                  <1> 	retn
  2482                              <1> 
  2483                              <1> loc_start_search_next_file:
  2484 000072B2 668B1D[AC2A0100]    <1> 	mov	bx, [FindFile_DirEntryNumber]
  2485 000072B9 6643                <1> 	inc	bx
  2486 000072BB 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  2487 000072C2 7719                <1> 	ja	short loc_cont_search_next_file
  2488                              <1> 
  2489                              <1> loc_fnf_search:
  2490 000072C4 BE[232A0100]        <1> 	mov	esi, Dir_Entry_Name
  2491 000072C9 66A1[822A0100]      <1> 	mov	ax, [FindFile_AttributesMask]
  2492 000072CF 6631C9              <1> 	xor	cx, cx
  2493 000072D2 E8671E0000          <1> 	call	find_directory_entry
  2494 000072D7 0F8355FFFFFF        <1>         jnc     loc_fff_fnf_ln_check
  2495                              <1> 
  2496                              <1> loc_cont_search_next_file:
  2497 000072DD 31DB                <1> 	xor	ebx, ebx
  2498 000072DF 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  2499 000072E5 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2500 000072EA 01DE                <1> 	add	esi, ebx
  2501                              <1> 
  2502 000072EC 803D[8C200100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2503 000072F3 7608                <1> 	jna	short loc_fnf_check_FAT_type
  2504 000072F5 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2505 000072F9 72B1                <1> 	jb	short loc_fnf_ax12h_retn
  2506 000072FB EB06                <1> 	jmp	short loc_fnf_check_next_cluster
  2507                              <1>  
  2508                              <1> loc_fnf_check_FAT_type:
  2509 000072FD 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
  2510 00007301 72A9                <1> 	jb	short loc_fnf_ax12h_retn
  2511                              <1> 
  2512                              <1> loc_fnf_check_next_cluster:
  2513 00007303 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
  2514 00007308 E8E6370000          <1> 	call	get_next_cluster
  2515 0000730D 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
  2516 0000730F 09C0                <1> 	or	eax, eax
  2517 00007311 7498                <1> 	jz	short loc_fnf_stc_retn
  2518                              <1> 	;mov	eax, 15h ;Drive not ready or read error
  2519 00007313 F5                  <1>  	cmc	;stc
  2520                              <1> loc_fnf_retn:
  2521 00007314 C3                  <1> 	retn
  2522                              <1> 
  2523                              <1> loc_fnf_load_next_dir_cluster:
  2524 00007315 E8BF390000          <1> 	call	load_FAT_sub_directory
  2525 0000731A 72F8                <1> 	jc	short loc_fnf_retn
  2526 0000731C 6631DB              <1> 	xor	bx, bx
  2527 0000731F 66891D[AC2A0100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  2528 00007326 EB9C                <1> 	jmp	short loc_fnf_search
  2529                              <1> 
  2530                              <1> get_and_print_longname:
  2531                              <1> 	; 13/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2532                              <1> 	; 24/01/2010
  2533                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
  2534                              <1> get_longname_fchar:
  2535 00007328 803E20              <1> 	cmp	byte [esi], 20h
  2536 0000732B 7701                <1> 	ja	short loc_find_longname
  2537                              <1> 	;jb	short loc_longname_retn
  2538                              <1> 	;inc	esi
  2539                              <1> 	;je	short get_longname_fchar
  2540                              <1> ;loc_longname_retn:
  2541 0000732D C3                  <1> 	retn
  2542                              <1> loc_find_longname:
  2543 0000732E E872210000          <1> 	call	find_longname
  2544 00007333 7320                <1> 	jnc	short loc_print_longname
  2545                              <1> 	
  2546 00007335 08C0                <1> 	or	al, al
  2547 00007337 7412                <1> 	jz	short loc_longname_not_found
  2548                              <1> 	  
  2549 00007339 3C15                <1> 	cmp	al, 15h
  2550 0000733B 0F84B6F7FFFF        <1> 	je	cd_drive_not_ready
  2551                              <1> 
  2552                              <1> loc_ln_file_dir_not_found:
  2553 00007341 BE[3CE10000]        <1> 	mov	esi, Msg_File_Directory_Not_Found
  2554                              <1> 	;call	print_msg	
  2555                              <1>         ;retn
  2556 00007346 E90BE2FFFF          <1> 	jmp	print_msg
  2557                              <1> 
  2558                              <1> loc_longname_not_found:
  2559 0000734B BE[5BE10000]        <1>         mov     esi, Msg_LongName_Not_Found
  2560                              <1> 	;call	print_msg	
  2561                              <1>         ;retn
  2562 00007350 E901E2FFFF          <1> 	jmp	print_msg
  2563                              <1> 
  2564                              <1> loc_print_longname:
  2565                              <1> 	;mov	esi, LongFileName
  2566 00007355 BF[8E210100]        <1> 	mov	edi, TextBuffer
  2567 0000735A 57                  <1> 	push	edi 
  2568 0000735B 3C00                <1> 	cmp	al, 0
  2569 0000735D 7708                <1> 	ja	short loc_print_longname_1
  2570                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
  2571 0000735F AC                  <1> 	lodsb
  2572 00007360 AA                  <1> 	stosb  
  2573 00007361 08C0                <1> 	or	al, al
  2574 00007363 75FA                <1> 	jnz	short loc_print_FS_longname
  2575 00007365 EB07                <1> 	jmp	short loc_print_longname_2
  2576                              <1> 	;
  2577                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
  2578 00007367 66AD                <1> 	lodsw
  2579 00007369 AA                  <1> 	stosb  
  2580 0000736A 08C0                <1> 	or	al, al
  2581 0000736C 75F9                <1> 	jnz	short loc_print_longname_1
  2582                              <1> 	;
  2583                              <1> loc_print_longname_2:	
  2584 0000736E 5E                  <1> 	pop	esi
  2585 0000736F E8E2E1FFFF          <1> 	call	print_msg
  2586 00007374 BE[ABEE0000]        <1>   	mov	esi, nextline
  2587                              <1> 	;call	print_msg
  2588                              <1> 	;retn
  2589 00007379 E9D8E1FFFF          <1> 	jmp	print_msg	
  2590                              <1> 
  2591                              <1> show_file:
  2592                              <1> 	; 18/02/2016
  2593                              <1> 	; 17/02/2016
  2594                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2595                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
  2596                              <1> 	; 08/11/2009
  2597                              <1> 
  2598                              <1> loc_show_parse_path_name:
  2599 0000737E BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  2600 00007383 E874200000          <1> 	call	parse_path_name
  2601 00007388 0F8262F9FFFF        <1> 	jc	loc_cmd_failed
  2602                              <1> 
  2603                              <1> loc_show_check_filename_exists:
  2604 0000738E BE[742A0100]        <1> 	mov	esi, FindFile_Name
  2605 00007393 803E20              <1> 	cmp	byte [esi], 20h
  2606 00007396 0F8654F9FFFF        <1> 	jna	loc_cmd_failed
  2607                              <1> 
  2608                              <1> 	; 15/02/2016 (invalid file name check)
  2609 0000739C E809020000          <1> 	call	check_filename 	
  2610 000073A1 730A                <1> 	jnc	short loc_show_change_drv
  2611                              <1> 
  2612 000073A3 BE[24E20000]        <1> 	mov	esi, Msg_invalid_name_chars
  2613 000073A8 E9A9E1FFFF          <1> 	jmp	print_msg
  2614                              <1>    
  2615                              <1> loc_show_change_drv:
  2616 000073AD 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  2617 000073B3 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  2618 000073B9 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  2619 000073BF 38F2                <1> 	cmp	dl, dh
  2620 000073C1 740B                <1> 	je	short loc_show_change_directory
  2621 000073C3 E88EEAFFFF          <1> 	call	change_current_drive
  2622                              <1> 	;jc	loc_file_rw_cmd_failed
  2623 000073C8 0F824DF9FFFF        <1> 	jc	loc_run_cmd_failed
  2624                              <1> 
  2625                              <1> loc_show_change_directory:
  2626 000073CE 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  2627 000073D5 7618                <1> 	jna	short loc_findload_showfile
  2628                              <1> 
  2629 000073D7 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2630 000073DD BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  2631 000073E2 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2632 000073E4 E8FF190000          <1> 	call	change_current_directory
  2633                              <1> 	;jc	loc_file_rw_cmd_failed
  2634 000073E9 0F822CF9FFFF        <1> 	jc	loc_run_cmd_failed
  2635                              <1> 
  2636                              <1> ;loc_show_change_prompt_dir_string:
  2637                              <1> 	;call	change_prompt_dir_string
  2638                              <1> 
  2639                              <1> loc_findload_showfile:
  2640                              <1> 	; 15/02/2016
  2641 000073EF BE[742A0100]        <1> 	mov	esi, FindFile_Name
  2642 000073F4 BF[232A0100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  2643 000073F9 E8331F0000          <1> 	call	convert_file_name
  2644 000073FE 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  2645                              <1> 
  2646 00007400 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
  2647                              <1> 	; Directory attribute : 10h
  2648                              <1> 	; Volume name attribute: 8h
  2649 00007402 B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
  2650                              <1> 	;
  2651 00007404 6631C9              <1> 	xor	cx, cx  
  2652 00007407 E8301C0000          <1> 	call	locate_current_dir_file
  2653                              <1> 	;jc	loc_file_rw_cmd_failed
  2654 0000740C 0F8209F9FFFF        <1> 	jc	loc_run_cmd_failed
  2655                              <1> 
  2656                              <1> loc_show_load_file:
  2657                              <1> 	; EDI = Directory Entry
  2658 00007412 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
  2659 00007416 C1E010              <1> 	shl	eax, 16
  2660 00007419 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
  2661 0000741D A3[DC2A0100]        <1> 	mov	[Show_Cluster], eax
  2662 00007422 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
  2663 00007425 21C0                <1> 	and	eax, eax ; Empty file !
  2664 00007427 0F8491000000        <1>         jz      end_of_show_file 
  2665 0000742D A3[E02A0100]        <1> 	mov	[Show_FileSize], eax
  2666 00007432 31C0                <1> 	xor	eax, eax
  2667 00007434 A3[E42A0100]        <1> 	mov	[Show_FilePointer], eax ; 0
  2668 00007439 66A3[E82A0100]      <1> 	mov	[Show_ClusterPointer], ax ; 0
  2669 0000743F 29DB                <1> 	sub	ebx, ebx
  2670 00007441 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  2671 00007447 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2672 0000744C 01DE                <1> 	add	esi, ebx
  2673 0000744E 8935[D82A0100]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
  2674                              <1> 
  2675 00007454 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0	
  2676 00007458 7713                <1> 	ja	short loc_show_calculate_cluster_size
  2677                              <1> 	; Singlix FS
  2678                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
  2679 0000745A 8B15[DC2A0100]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)	
  2680 00007460 8915[D42A0100]      <1> 	mov	[Show_FDT], edx
  2681 00007466 31C0                <1> 	xor	eax, eax
  2682 00007468 A3[DC2A0100]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
  2683                              <1> 				    ; (next time it will be 1)			
  2684                              <1> loc_show_calculate_cluster_size:
  2685 0000746D 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
  2686                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS	
  2687 00007471 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
  2688                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  2689 00007474 F7E3                <1> 	mul	ebx	
  2690                              <1> 
  2691                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
  2692                              <1> 	;ja	short end_of_show_file	
  2693 00007476 66A3[EA2A0100]      <1> 	mov	[Show_ClusterSize], ax
  2694                              <1> 
  2695                              <1> loc_start_show_file:
  2696 0000747C BE[ABEE0000]        <1> 	mov	esi, nextline
  2697 00007481 E8D0E0FFFF          <1> 	call	print_msg
  2698                              <1> 
  2699 00007486 A1[DC2A0100]        <1> 	mov	eax, [Show_Cluster]
  2700 0000748B C605[EC2A0100]17    <1> 	mov	byte [Show_RowCount], 23
  2701                              <1> 
  2702                              <1> 	; 17/02/2016
  2703 00007492 8B35[D82A0100]      <1> 	mov	esi, [Show_LDDDT]
  2704                              <1> 
  2705                              <1> loc_show_next_cluster:
  2706                              <1> 	; 15/02/2016
  2707 00007498 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  2708                              <1> 	; ESI = Logical DOS drv description table address
  2709 0000749D E875380000          <1> 	call	read_cluster
  2710                              <1> 	;jc	loc_file_rw_cmd_failed
  2711 000074A2 0F8273F8FFFF        <1> 	jc	loc_run_cmd_failed
  2712                              <1> 
  2713 000074A8 31DB                <1> 	xor 	ebx, ebx
  2714                              <1> loc_show_next_byte:
  2715 000074AA 803D[EC2A0100]00    <1> 	cmp	byte [Show_RowCount], 0
  2716 000074B1 7521                <1> 	jne	short pass_show_wait_for_key
  2717 000074B3 30E4                <1> 	xor	ah, ah
  2718 000074B5 E81296FFFF          <1> 	call	int16h
  2719 000074BA 3C1B                <1> 	cmp	al, 1Bh
  2720 000074BC 750F                <1> 	jne	short pass_exit_show
  2721                              <1> end_of_show_file:
  2722                              <1> pass_show_file:
  2723 000074BE BE[ABEE0000]        <1> 	mov	esi, nextline
  2724 000074C3 E88EE0FFFF          <1> 	call	print_msg
  2725 000074C8 E94D010000          <1> 	jmp	loc_file_rw_restore_retn
  2726                              <1> 
  2727                              <1> pass_exit_show:
  2728 000074CD C605[EC2A0100]14    <1> 	mov	byte [Show_RowCount], 20
  2729                              <1> pass_show_wait_for_key:
  2730 000074D4 81C300000700        <1> 	add	ebx, Cluster_Buffer
  2731 000074DA 8A03                <1> 	mov	al, [ebx]
  2732 000074DC 3C0D                <1> 	cmp	al, 0Dh
  2733 000074DE 0F8590000000        <1>         jne     loc_show_check_tab_space
  2734 000074E4 FE0D[EC2A0100]      <1> 	dec	byte [Show_RowCount]
  2735                              <1> pass_show_dec_rowcount:
  2736 000074EA B307                <1> 	mov	bl, 7 ; (light gray character color, black background)
  2737 000074EC 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  2738 000074F2 E82AA6FFFF          <1> 	call	_write_tty
  2739                              <1> loc_show_check_eof:
  2740 000074F7 FF05[E42A0100]      <1> 	inc	dword [Show_FilePointer]
  2741 000074FD A1[E42A0100]        <1> 	mov	eax, [Show_FilePointer]
  2742 00007502 3B05[E02A0100]      <1> 	cmp	eax, [Show_FileSize]
  2743 00007508 73B4                <1> 	jnb	short end_of_show_file
  2744 0000750A 66FF05[E82A0100]    <1> 	inc	word [Show_ClusterPointer]
  2745 00007511 0FB71D[E82A0100]    <1> 	movzx	ebx, word [Show_ClusterPointer]
  2746                              <1> 
  2747                              <1> 	; 17/02/2016
  2748                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
  2749 00007518 66F7C3FF01          <1>         test    bx, 1FFh ;  1 to 511
  2750 0000751D 758B                <1> 	jnz	short loc_show_next_byte
  2751                              <1> 
  2752                              <1> 	; 16/02/2016
  2753 0000751F 8B35[D82A0100]      <1> 	mov	esi, [Show_LDDDT]
  2754                              <1> 	;
  2755 00007525 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2756 00007529 7719                <1> 	ja	short loc_show_check_fat_cluster_size
  2757                              <1> 
  2758                              <1> 	; Singlix FS
  2759                              <1> 	; 1 sector, more... (cluster size = 1 sector)
  2760 0000752B A1[DC2A0100]        <1> 	mov	eax, [Show_Cluster]
  2761 00007530 40                  <1> 	inc	eax
  2762 00007531 A3[DC2A0100]        <1> 	mov	[Show_Cluster], eax
  2763                              <1> 
  2764 00007536 6621DB              <1> 	and	bx, bx ; 65536 -> 0
  2765 00007539 0F856BFFFFFF        <1>         jnz	loc_show_next_byte
  2766 0000753F E954FFFFFF          <1> 	jmp     loc_show_next_cluster
  2767                              <1> 	 
  2768                              <1> loc_show_check_fat_cluster_size:
  2769                              <1> 	; 17/02/2016
  2770 00007544 663B1D[EA2A0100]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
  2771 0000754B 0F8259FFFFFF        <1>         jb	loc_show_next_byte
  2772 00007551 66C705[E82A0100]00- <1> 	mov	word [Show_ClusterPointer], 0
  2772 00007559 00                  <1>
  2773                              <1> 
  2774 0000755A A1[DC2A0100]        <1> 	mov	eax, [Show_Cluster]
  2775                              <1> 	;mov	esi, [Show_LDDDT]
  2776                              <1> loc_show_get_next_cluster:
  2777 0000755F E88F350000          <1> 	call	get_next_cluster
  2778                              <1> 	;jc	loc_file_rw_cmd_failed
  2779 00007564 0F82B1F7FFFF        <1> 	jc	loc_run_cmd_failed
  2780                              <1> loc_show_update_ccluster:
  2781 0000756A A3[DC2A0100]        <1> 	mov	[Show_Cluster], eax			
  2782 0000756F E924FFFFFF          <1>         jmp     loc_show_next_cluster
  2783                              <1> 
  2784                              <1> loc_show_check_tab_space:
  2785 00007574 3C09                <1> 	cmp	al, 09h
  2786 00007576 0F856EFFFFFF        <1>         jne     pass_show_dec_rowcount
  2787                              <1> loc_show_put_tab_space:
  2788 0000757C 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  2789 00007582 E834A2FFFF          <1> 	call	get_cpos
  2790                              <1> 	; dl = cursor column
  2791 00007587 80E207              <1> 	and	dl, 7 ; 18/02/2016
  2792                              <1> 	;shr	bh, 1 ; [ACTIVE_PAGE]
  2793 0000758A 8A3D[F61F0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  2794 00007590 B307                <1> 	mov	bl, 7 ; color attribute
  2795                              <1> loc_show_put_space_chars:
  2796 00007592 B020                <1> 	mov	al, 20h ; space
  2797                              <1> 	;mov	bh, [ACTIVE_PAGE] ; [ptty]
  2798                              <1> 	;mov	bl, 7 ; color attribute
  2799 00007594 6652                <1> 	push	dx
  2800 00007596 E886A5FFFF          <1> 	call	_write_tty
  2801 0000759B 665A                <1> 	pop	dx
  2802                              <1> 	; 18/02/2016
  2803 0000759D 80FA07              <1> 	cmp	dl, 7
  2804 000075A0 0F8351FFFFFF        <1> 	jnb	loc_show_check_eof
  2805 000075A6 FEC2                <1> 	inc	dl
  2806 000075A8 EBE8                <1> 	jmp	short loc_show_put_space_chars
  2807                              <1> 
  2808                              <1> check_filename:
  2809                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2810                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
  2811                              <1> 	; 10/07/2010
  2812                              <1> 	; Derived from 'proc_check_filename'
  2813                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  2814                              <1> 	;
  2815                              <1> 	; INPUT -> 
  2816                              <1> 	;	ESI = Dot File Name Location
  2817                              <1> 	; OUTPUT ->
  2818                              <1> 	;	cf = 1 -> error code in AL
  2819                              <1> 	;	     AL = 0Bh -> Invalid file name   
  2820                              <1> 	;	cf = 0 -> valid file name
  2821                              <1> 	; 
  2822                              <1> 	;(EAX, ECX, EDI will be changed)
  2823                              <1> 
  2824                              <1> check_invalid_filename_chars:
  2825                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2826                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
  2827                              <1> 	; 10/02/2010
  2828                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
  2829                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  2830                              <1> 	;
  2831                              <1> 	; INPUT -> 
  2832                              <1> 	;	ESI = ASCIIZ FileName
  2833                              <1> 	; OUTPUT ->
  2834                              <1> 	;	cf = 1 -> invalid
  2835                              <1> 	;	cf = 0 -> valid
  2836                              <1> 	; 
  2837                              <1> 	;(EAX, ECX, ESI, EDI will be changed)
  2838                              <1>   
  2839 000075AA 56                  <1> 	push	esi
  2840                              <1> 
  2841 000075AB BF[10DF0000]        <1>         mov     edi, invalid_fname_chars
  2842 000075B0 AC                  <1> 	lodsb
  2843                              <1> check_filename_next_char:
  2844 000075B1 B914000000          <1> 	mov	ecx, sizeInvFnChars
  2845 000075B6 BF[10DF0000]        <1> 	mov	edi, invalid_fname_chars
  2846                              <1> loc_scan_invalid_filename_char:
  2847 000075BB AE                  <1> 	scasb 
  2848 000075BC 741F                <1> 	je	short loc_invalid_filename_stc 
  2849 000075BE E2FB                <1> 	loop	loc_scan_invalid_filename_char
  2850 000075C0 AC                  <1> 	lodsb
  2851 000075C1 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
  2852 000075C3 77EC                <1> 	ja	short check_filename_next_char
  2853                              <1> 
  2854                              <1> check_filename_dot:
  2855 000075C5 8B3424              <1> 	mov	esi, [esp]
  2856                              <1> 
  2857 000075C8 B421                <1> 	mov	ah, 21h
  2858 000075CA B908000000          <1> 	mov	ecx, 8
  2859                              <1> loc_check_filename_next_char:
  2860 000075CF AC                  <1> 	lodsb
  2861 000075D0 3C2E                <1> 	cmp	al, 2Eh
  2862 000075D2 7511                <1> 	jne	short pass_check_fn_dot_check
  2863                              <1> loc_check_filename_ext_0:
  2864 000075D4 AC                  <1> 	lodsb
  2865 000075D5 38E0                <1> 	cmp	al, ah ; 21h
  2866 000075D7 7205                <1> 	jb	short loc_invalid_filename
  2867 000075D9 3C2E                <1> 	cmp	al, 2Eh
  2868 000075DB 7519                <1> 	jne	short loc_check_filename_ext_1
  2869                              <1> 
  2870                              <1> loc_invalid_filename_stc:
  2871                              <1> loc_check_fn_stc_rtn:
  2872 000075DD F9                  <1> 	stc
  2873                              <1> loc_invalid_filename:
  2874 000075DE B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
  2875                              <1> 	; Invalid file name chars
  2876                              <1> loc_check_fn_rtn:
  2877 000075E3 5E                  <1> 	pop	esi
  2878 000075E4 C3                  <1> 	retn
  2879                              <1> 
  2880                              <1> pass_check_fn_dot_check:
  2881 000075E5 38E0                <1> 	cmp	al, ah ; 21h
  2882 000075E7 7224                <1> 	jb	short loc_check_fn_clc_rtn
  2883 000075E9 E2E4                <1> 	loop	loc_check_filename_next_char
  2884 000075EB AC                  <1> 	lodsb
  2885 000075EC 38E0                <1> 	cmp	al, ah ; 21h
  2886 000075EE 721D                <1> 	jb	short loc_check_fn_clc_rtn
  2887 000075F0 3C2E                <1> 	cmp	al, 2Eh
  2888 000075F2 75E9                <1> 	jne	short loc_check_fn_stc_rtn
  2889 000075F4 EBDE                <1> 	jmp	short loc_check_filename_ext_0
  2890                              <1> 
  2891                              <1> loc_check_filename_ext_1:
  2892 000075F6 AC                  <1> 	lodsb
  2893 000075F7 38E0                <1> 	cmp	al, ah ; 21h
  2894 000075F9 7212                <1> 	jb	short loc_check_fn_clc_rtn
  2895 000075FB 3C2E                <1> 	cmp	al, 2Eh
  2896 000075FD 74DE                <1> 	je	short loc_check_fn_stc_rtn
  2897 000075FF AC                  <1> 	lodsb
  2898 00007600 38E0                <1> 	cmp	al, ah ; 21h
  2899 00007602 7209                <1> 	jb	short loc_check_fn_clc_rtn
  2900 00007604 3C2E                <1> 	cmp	al, 2Eh
  2901 00007606 74D5                <1> 	je	short loc_check_fn_stc_rtn
  2902 00007608 AC                  <1> 	lodsb
  2903 00007609 38E0                <1> 	cmp	al, ah ; 21h
  2904 0000760B 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
  2905                              <1> 
  2906                              <1> loc_check_fn_clc_rtn:
  2907 0000760D 5E                  <1> 	pop	esi
  2908 0000760E F8                  <1> 	clc
  2909 0000760F C3                  <1> 	retn
  2910                              <1> 
  2911                              <1> loc_print_deleted_message:
  2912 00007610 BE[F9E20000]        <1> 	mov	esi, Msg_Deleted
  2913 00007615 E83CDFFFFF          <1> 	call	print_msg
  2914                              <1> 
  2915                              <1> 	;clc
  2916                              <1> 
  2917                              <1> loc_file_rw_restore_retn:
  2918                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2919                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
  2920                              <1> loc_file_rw_cmd_failed:
  2921 0000761A 9C                  <1> 	pushf 
  2922 0000761B E855F7FFFF          <1> 	call	restore_cdir_after_cmd_fail	
  2923 00007620 9D                  <1> 	popf
  2924 00007621 720D                <1> 	jc	short loc_file_rw_check_write_fault
  2925 00007623 C3                  <1> 	retn
  2926                              <1> 
  2927                              <1> loc_permission_denied:
  2928                              <1> 	; 27/02/2016
  2929 00007624 BE[06E30000]        <1> 	mov	esi, Msg_Permission_Denied
  2930 00007629 E828DFFFFF          <1> 	call	print_msg
  2931 0000762E EBEA                <1> 	jmp	short loc_file_rw_restore_retn
  2932                              <1> 
  2933                              <1> loc_file_rw_check_write_fault:
  2934 00007630 3C1D                <1> 	cmp	al, 1Dh ; Write Fault
  2935 00007632 0F85E8F6FFFF        <1>         jne     loc_run_cmd_failed_cmp_al
  2936 00007638 BE[F1E00000]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
  2937                              <1> 	;call	print_msg
  2938                              <1> 	;retn
  2939 0000763D E914DFFFFF          <1> 	jmp	print_msg
  2940                              <1> 
  2941                              <1> make_directory:
  2942                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
  2943                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
  2944                              <1> 	; 14/08/2010
  2945                              <1> 	; 10/07/2010
  2946                              <1> 	; 29/11/2009
  2947                              <1> 	;
  2948                              <1> get_mkdir_fchar:
  2949                              <1> 	; esi = directory name
  2950 00007642 803E20              <1> 	cmp	byte [esi], 20h
  2951 00007645 7701                <1>         ja	short loc_mkdir_parse_path_name
  2952                              <1> 
  2953                              <1> loc_mkdir_nodirname_retn:
  2954 00007647 C3                  <1> 	retn
  2955                              <1> 
  2956                              <1> loc_mkdir_parse_path_name:
  2957 00007648 BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  2958 0000764D E8AA1D0000          <1>         call    parse_path_name
  2959 00007652 0F8298F6FFFF        <1> 	jc	loc_cmd_failed
  2960                              <1> 
  2961                              <1> loc_mkdir_check_dirname_exists:
  2962 00007658 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  2963 0000765D 803E20              <1> 	cmp	byte [esi], 20h
  2964 00007660 0F868AF6FFFF        <1> 	jna	loc_cmd_failed
  2965 00007666 8935[F02A0100]      <1> 	mov	[DelFile_FNPointer], esi
  2966 0000766C E839FFFFFF          <1> 	call	check_filename
  2967 00007671 7259                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
  2968                              <1> 
  2969                              <1> loc_mkdir_drv:
  2970 00007673 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  2971 00007679 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  2972                              <1> 	
  2973 0000767F 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  2974 00007685 38F2                <1> 	cmp	dl, dh
  2975 00007687 7407                <1> 	je	short loc_mkdir_change_directory
  2976                              <1> 
  2977 00007689 E8C8E7FFFF          <1> 	call	change_current_drive
  2978 0000768E 728A                <1> 	jc	loc_file_rw_cmd_failed
  2979                              <1> 
  2980                              <1> loc_mkdir_change_directory:
  2981 00007690 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  2982 00007697 7614                <1> 	jna	short loc_mkdir_find_directory
  2983                              <1> 
  2984 00007699 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2985 0000769F BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  2986 000076A4 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2987 000076A6 E83D170000          <1> 	call	change_current_directory
  2988 000076AB 722E                <1> 	jc	short loc_mkdir_check_error_code
  2989                              <1> 
  2990                              <1> ;loc_mkdir_change_prompt_dir_string:
  2991                              <1> 	;call	change_prompt_dir_string
  2992                              <1> 
  2993                              <1> loc_mkdir_find_directory:
  2994                              <1> 	;mov	esi, FindFile_Name
  2995 000076AD 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  2996                              <1> 	;xor	eax, eax
  2997 000076B3 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
  2998 000076B6 E837FBFFFF          <1> 	call	find_first_file
  2999 000076BB 721E                <1> 	jc	short loc_mkdir_check_error_code
  3000                              <1> 
  3001                              <1> loc_mkdir_directory_found:
  3002 000076BD BE[51E20000]        <1> 	mov	esi, Msg_Name_Exists
  3003 000076C2 E88FDEFFFF          <1> 	call	print_msg
  3004                              <1> 
  3005 000076C7 E94EFFFFFF          <1>         jmp     loc_file_rw_restore_retn
  3006                              <1> 
  3007                              <1> loc_mkdir_invalid_dir_name_chars:
  3008 000076CC BE[24E20000]        <1> 	mov	esi, Msg_invalid_name_chars
  3009 000076D1 E880DEFFFF          <1> 	call	print_msg
  3010                              <1> 
  3011 000076D6 E93FFFFFFF          <1>         jmp     loc_file_rw_restore_retn
  3012                              <1> 
  3013                              <1> loc_mkdir_check_error_code:
  3014 000076DB 3C02                <1> 	cmp	al, 2
  3015                              <1> 	;je	short loc_mkdir_directory_not_found
  3016 000076DD 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
  3017 000076DF F9                  <1> 	stc
  3018 000076E0 E935FFFFFF          <1>         jmp     loc_file_rw_cmd_failed
  3019                              <1> 
  3020                              <1> loc_mkdir_directory_not_found:
  3021                              <1> loc_mkdir_ask_for_yes_no:
  3022 000076E5 BE[72E20000]        <1> 	mov	esi, Msg_DoYouWantMkdir
  3023 000076EA E867DEFFFF          <1> 	call	print_msg
  3024 000076EF 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3025 000076F5 E85CDEFFFF          <1> 	call	print_msg
  3026 000076FA BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  3027 000076FF E852DEFFFF          <1> 	call	print_msg
  3028                              <1> 
  3029 00007704 C605[9BE20000]20    <1> 	mov	byte [Y_N_nextline], 20h
  3030                              <1> 
  3031                              <1> loc_mkdir_ask_again:
  3032 0000770B 30E4                <1> 	xor	ah, ah
  3033 0000770D E8BA93FFFF          <1> 	call	int16h
  3034 00007712 3C1B                <1> 	cmp	al, 1Bh
  3035                              <1> 	;je	short loc_do_not_make_directory
  3036 00007714 7447                <1> 	je	short loc_mkdir_y_n_escape
  3037 00007716 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
  3038 00007718 3C59                <1> 	cmp	al, 'Y' ; 'yes'
  3039 0000771A 7404                <1> 	je	short loc_mkdir_yes_make_directory
  3040 0000771C 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3041 0000771E 75EB                <1> 	jne	short loc_mkdir_ask_again
  3042                              <1> 
  3043                              <1> loc_do_not_make_directory:
  3044                              <1> loc_mkdir_yes_make_directory:
  3045 00007720 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  3046 00007725 6650                <1> 	push	ax
  3047 00007727 BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  3048 0000772C E825DEFFFF          <1> 	call	print_msg
  3049 00007731 6658                <1> 	pop	ax
  3050                              <1> 	;cmp	al, 'Y' ; 'yes'
  3051                              <1> 	;cmc
  3052                              <1>         ;jnc	loc_file_rw_restore_retn
  3053 00007733 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3054 00007735 0F84DFFEFFFF        <1>         je	loc_file_rw_restore_retn  
  3055                              <1> 
  3056                              <1> loc_mkdir_call_make_sub_directory:
  3057 0000773B 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3058 00007741 B110                <1> 	mov	cl, 10h ; Directory attributes 
  3059 00007743 E8B31D0000          <1> 	call	make_sub_directory
  3060                              <1> loc_rename_file_ok: ; 06/03/2016
  3061 00007748 0F82CCFEFFFF        <1>         jc	loc_file_rw_cmd_failed
  3062                              <1> move_source_file_to_destination_OK:
  3063 0000774E BE[9FE20000]        <1> 	mov	esi, Msg_OK
  3064 00007753 E8FEDDFFFF          <1> 	call	print_msg
  3065 00007758 E9BDFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3066                              <1> 
  3067                              <1> loc_mkdir_y_n_escape:
  3068 0000775D B04E                <1> 	mov	al, 'N' ; 'no'
  3069 0000775F EBBF                <1> 	jmp	short loc_do_not_make_directory
  3070                              <1> 
  3071                              <1> delete_directory:
  3072                              <1> 	; 06/03/2016
  3073                              <1> 	; 01/03/2016
  3074                              <1> 	; 29/02/2016
  3075                              <1> 	; 28/02/2016
  3076                              <1> 	; 27/02/2016
  3077                              <1> 	; 26/02/2016 (TRDOS 386 =  TRDOS v2.0)
  3078                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
  3079                              <1> 	; 05/06/2010
  3080                              <1> 	;
  3081                              <1> get_rmdir_fchar:
  3082                              <1> 	; esi = directory name
  3083 00007761 803E20              <1> 	cmp	byte [esi], 20h
  3084 00007764 7701                <1>         ja	short loc_rmdir_parse_path_name
  3085                              <1> 
  3086                              <1> loc_rmdir_nodirname_retn:
  3087 00007766 C3                  <1> 	retn
  3088                              <1> 
  3089                              <1> loc_rmdir_parse_path_name:
  3090 00007767 BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  3091 0000776C E88B1C0000          <1> 	call	parse_path_name
  3092 00007771 0F8279F5FFFF        <1> 	jc	loc_cmd_failed
  3093                              <1> 
  3094                              <1> loc_rmdir_check_dirname_exists:
  3095 00007777 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3096 0000777C 803E20              <1> 	cmp	byte [esi], 20h
  3097 0000777F 0F866BF5FFFF        <1> 	jna	loc_cmd_failed
  3098 00007785 8935[F02A0100]      <1> 	mov	[DelFile_FNPointer], esi 
  3099                              <1> 
  3100                              <1> loc_rmdir_drv:
  3101 0000778B 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  3102 00007791 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  3103                              <1> 
  3104 00007797 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  3105 0000779D 38F2                <1> 	cmp	dl, dh
  3106 0000779F 740B                <1> 	je	short loc_rmdir_change_directory
  3107                              <1> 
  3108 000077A1 E8B0E6FFFF          <1> 	call	change_current_drive
  3109 000077A6 0F826EFEFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3110                              <1> 
  3111                              <1> loc_rmdir_change_directory:
  3112 000077AC 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3113 000077B3 7614                <1> 	jna	short loc_rmdir_find_directory
  3114                              <1> 
  3115 000077B5 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3116 000077BB BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  3117 000077C0 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3118 000077C2 E821160000          <1> 	call	change_current_directory
  3119 000077C7 7211                <1> 	jc	short loc_rmdir_check_error_code
  3120                              <1> 
  3121                              <1> ;loc_rmdir_change_prompt_dir_string:
  3122                              <1> 	;call	change_prompt_dir_string
  3123                              <1> 
  3124                              <1> loc_rmdir_find_directory:
  3125                              <1> 	;mov	esi, FindFile_Name
  3126 000077C9 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3127 000077CF 66B81008            <1> 	mov	ax, 0810h ; Only directories
  3128 000077D3 E81AFAFFFF          <1> 	call	find_first_file
  3129 000077D8 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
  3130                              <1> 
  3131                              <1> loc_rmdir_check_error_code:
  3132 000077DA 3C02                <1> 	cmp	al, 2
  3133 000077DC 740B                <1> 	je	short loc_rmdir_directory_not_found
  3134 000077DE F9                  <1> 	stc
  3135 000077DF E936FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3136                              <1> 
  3137                              <1> loc_rmdir_ambgfn_check:
  3138 000077E4 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3139 000077E7 740F                <1> 	jz	short loc_rmdir_directory_found
  3140                              <1> 
  3141                              <1> loc_rmdir_directory_not_found:
  3142 000077E9 BE[13E10000]        <1> 	mov	esi, Msg_Dir_Not_Found
  3143 000077EE E863DDFFFF          <1> 	call	print_msg
  3144                              <1> 
  3145 000077F3 E922FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3146                              <1> 
  3147                              <1> loc_rmdir_directory_found:
  3148 000077F8 80E307              <1> 	and	bl, 07h ; Attributes
  3149 000077FB 0F8523FEFFFF        <1> 	jnz	loc_permission_denied
  3150                              <1> 
  3151                              <1> loc_rmdir_save_lnel: ; 28/02/2016
  3152                              <1>        ;mov	bh, [LongName_EntryLength]
  3153 00007801 883D[FA2A0100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  3154                              <1> 	; edi = Directory Entry Offset (DirBuff)
  3155                              <1> 	; esi = Directory Entry (FFF Structure)
  3156                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
  3157                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
  3158                              <1>         ;shl	eax, 16
  3159                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
  3160                              <1> 	; ROOT Dir First Cluster = 0
  3161                              <1>         ;cmp	eax, 2
  3162                              <1> 	;jb	loc_update_direntry_1
  3163                              <1> 
  3164                              <1> pass_rmdir_fc_check:
  3165 00007807 57                  <1> 	push	edi ; * (29/02/2016)
  3166                              <1> 
  3167 00007808 BE[A5E20000]        <1> 	mov	esi, Msg_DoYouWantRmDir
  3168 0000780D E844DDFFFF          <1> 	call	print_msg
  3169 00007812 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3170 00007818 E839DDFFFF          <1> 	call	print_msg
  3171 0000781D BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  3172 00007822 E82FDDFFFF          <1> 	call	print_msg
  3173                              <1> 
  3174                              <1> loc_rmdir_ask_again:
  3175 00007827 30E4                <1> 	xor	ah, ah
  3176 00007829 E89E92FFFF          <1> 	call	int16h
  3177 0000782E 3C1B                <1> 	cmp	al, 1Bh
  3178                              <1> 	;je	short loc_do_not_delete_directory
  3179 00007830 0F8498000000        <1>         je      loc_rmdir_y_n_escape ; 06/03/2016
  3180 00007836 24DF                <1> 	and	al, 0DFh
  3181 00007838 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  3182 0000783D 3C59                <1> 	cmp	al, 'Y'
  3183 0000783F 7404                <1> 	je	short loc_rmdir_yes_delete_directory
  3184 00007841 3C4E                <1> 	cmp	al, 'N'
  3185 00007843 75E2                <1> 	jne	short loc_rmdir_ask_again
  3186                              <1> 
  3187                              <1> loc_do_not_delete_directory:
  3188                              <1> loc_rmdir_yes_delete_directory:
  3189 00007845 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  3190 0000784A 6650                <1> 	push	ax
  3191 0000784C BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  3192 00007851 E800DDFFFF          <1> 	call	print_msg
  3193 00007856 6658                <1> 	pop	ax
  3194 00007858 5F                  <1> 	pop	edi ; * (29/02/2016)
  3195                              <1> 	;cmp	al, 'Y' ; 'yes'
  3196                              <1> 	;cmc
  3197                              <1>         ;jnc	loc_file_rw_restore_retn
  3198 00007859 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3199 0000785B 0F84B9FDFFFF        <1>         je	loc_file_rw_restore_retn  
  3200                              <1> 
  3201                              <1> loc_rmdir_delete_short_name_check_dir_empty:
  3202                              <1> 	; EDI = Directory buffer entry offset/address 
  3203 00007861 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  3204 00007865 C1E010              <1>         shl	eax, 16
  3205 00007868 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  3206                              <1> 
  3207 0000786C A3[F42A0100]        <1> 	mov 	[DelFile_FCluster], eax
  3208                              <1> 
  3209                              <1> 	;mov	bx, [DirBuff_EntryCounter]
  3210 00007871 668B1D[AC2A0100]    <1> 	mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
  3211 00007878 66891D[F82A0100]    <1> 	mov	[DelFile_EntryCounter], bx
  3212                              <1> 
  3213 0000787F 29DB                <1>     	sub	ebx, ebx
  3214 00007881 8A3D[322A0100]      <1> 	mov	bh, [FindFile_Drv]
  3215 00007887 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3216 0000788C 01DE                <1> 	add	esi, ebx
  3217                              <1> 
  3218 0000788E 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
  3219 00007894 743F                <1> 	je	short loc_rmdir_delete_fs_directory
  3220                              <1> 
  3221                              <1> 	;cmp	byte [esi+LD_FATType], 1
  3222                              <1> 	;jnb	short loc_rmdir_get__last_cluster_0
  3223                              <1> 	;mov	eax, 0Bh ; Invalid Format
  3224                              <1> 	;jmp	loc_file_rw_cmd_failed
  3225                              <1>   
  3226                              <1> ;loc_rmdir_get_last_cluster_0:
  3227 00007896 8B15[BD280100]      <1> 	mov	edx, [DirBuff_Cluster]
  3228 0000789C 8915[242B0100]      <1> 	mov	[RmDir_ParentDirCluster], edx
  3229                              <1> 
  3230 000078A2 893D[202B0100]      <1> 	mov	[RmDir_DirEntryOffset], edi
  3231                              <1> 
  3232                              <1> 	; 01/03/2016
  3233 000078A8 C705[AE280100]0000- <1> 	mov	dword [FAT_ClusterCounter], 0 ; Reset
  3233 000078B0 0000                <1>
  3234                              <1> 
  3235                              <1> loc_rmdir_get_last_cluster:
  3236 000078B2 E8373A0000          <1> 	call	get_last_cluster
  3237 000078B7 0F82B8000000        <1>         jc      loc_rmdir_cmd_failed
  3238                              <1> 	
  3239 000078BD 3B05[F42A0100]      <1> 	cmp	eax, [DelFile_FCluster]
  3240 000078C3 752F                <1> 	jne	short loc_rmdir_multi_dir_clusters
  3241                              <1> 
  3242 000078C5 C605[1F2B0100]00    <1> 	mov	byte [RmDir_MultiClusters], 0
  3243 000078CC EB2D                <1> 	jmp	short pass_rmdir_multi_dir_clusters
  3244                              <1> 
  3245                              <1> loc_rmdir_y_n_escape:
  3246 000078CE B04E                <1> 	mov	al, 'N' ; 'no'
  3247 000078D0 E970FFFFFF          <1>         jmp     loc_do_not_delete_directory
  3248                              <1> 
  3249                              <1> loc_rmdir_delete_fs_directory:
  3250 000078D5 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  3251 000078D9 0F8545FDFFFF        <1> 	jne	loc_permission_denied
  3252                              <1> 
  3253 000078DF E821140000          <1> 	call	delete_fs_directory
  3254 000078E4 0F8326FDFFFF        <1> 	jnc	loc_print_deleted_message
  3255                              <1> 
  3256 000078EA 09C0                <1> 	or	eax, eax
  3257 000078EC 745D                <1> 	jz	loc_rmdir_directory_not_empty_2         
  3258 000078EE F9                  <1> 	stc
  3259 000078EF E926FDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3260                              <1>  
  3261                              <1> loc_rmdir_multi_dir_clusters:
  3262 000078F4 C605[1F2B0100]01    <1> 	mov	byte [RmDir_MultiClusters], 1
  3263                              <1> 
  3264                              <1> pass_rmdir_multi_dir_clusters:
  3265 000078FB A3[282B0100]        <1> 	mov 	[RmDir_DirLastCluster], eax
  3266 00007900 890D[2C2B0100]      <1> 	mov	[RmDir_PreviousCluster], ecx
  3267                              <1> 
  3268                              <1> loc_rmdir_load_fat_sub_directory:
  3269 00007906 E8CE330000          <1> 	call	load_FAT_sub_directory
  3270 0000790B 7268                <1> 	jc	loc_rmdir_cmd_failed
  3271                              <1> 
  3272                              <1> loc_rmdir_find_last_dir_entry:
  3273 0000790D 56                  <1> 	push	esi
  3274 0000790E BE[162A0100]        <1> 	mov	esi, Dir_File_Name
  3275 00007913 C6062A              <1> 	mov	byte [esi], '*'
  3276 00007916 C646082A            <1> 	mov	byte [esi+8], '*'
  3277 0000791A 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
  3278                              <1> loc_rmdir_find_last_dir_entry_next:
  3279 0000791C 66B80008            <1> 	mov	ax, 0800h ; Except volume/long names
  3280 00007920 6631C9              <1> 	xor	cx, cx ; 0 = Find a valid file or dir name
  3281 00007923 E816180000          <1> 	call	find_directory_entry
  3282 00007928 7271                <1> 	jc	short loc_rmdir_empty_dir_cluster
  3283 0000792A 83FB01              <1> 	cmp	ebx, 1
  3284 0000792D 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
  3285                              <1> loc_rmdir_dot_entry_check:
  3286 0000792F 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
  3287 00007932 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
  3288 00007934 08DB                <1> 	or	bl, bl
  3289 00007936 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
  3290 00007938 807F0120            <1> 	cmp	byte [edi+1], 20h
  3291 0000793C EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
  3292                              <1> 
  3293                              <1> loc_rmdir_dotdot_entry_check:
  3294 0000793E 66817F012E20        <1> 	cmp	word [edi+1], '. '
  3295                              <1> pass_rmdir_dot_entry_check:	
  3296 00007944 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
  3297 00007946 FEC3                <1> 	inc	bl
  3298 00007948 EBD2                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next 
  3299                              <1> 
  3300                              <1> 
  3301                              <1> loc_rmdir_directory_not_empty_1:
  3302 0000794A 58                  <1> 	pop	eax ; pushed esi 
  3303                              <1> 
  3304                              <1> loc_rmdir_directory_not_empty_2:
  3305 0000794B BE[C6E20000]        <1> 	mov	esi, Msg_Dir_Not_Empty
  3306 00007950 E801DCFFFF          <1> 	call	print_msg
  3307                              <1> 	; 01/03/2016
  3308 00007955 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  3309 0000795A 09C0                <1> 	or	eax, eax ; 0 ?
  3310 0000795C 0F84B8FCFFFF        <1> 	jz	loc_file_rw_restore_retn
  3311                              <1> 	; ESI = Logical DOS Drive Description Table address	
  3312                              <1> 
  3313 00007962 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
  3314                              <1> 	           ; BL = 1 -> add free clusters
  3315 00007966 E804380000          <1> 	call	calculate_fat_freespace
  3316 0000796B 09C9                <1> 	or	ecx, ecx
  3317 0000796D 0F84A7FCFFFF        <1>         jz      loc_file_rw_restore_retn ; ecx = 0 -> OK
  3318                              <1> 	; ecx > 0 -> Error (Recalculation is neeeded)
  3319 00007973 EB0E                <1> 	jmp	short loc_rmdir_cmd_return
  3320                              <1> 
  3321                              <1> 
  3322                              <1> loc_rmdir_cmd_failed:
  3323 00007975 833D[AE280100]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
  3324 0000797C 0F8298FCFFFF        <1> 	jb	loc_file_rw_cmd_failed	
  3325 00007982 F9                  <1> 	stc
  3326                              <1> loc_rmdir_cmd_return:
  3327                              <1> 	; 01/03/2016
  3328 00007983 9C                  <1> 	pushf
  3329                              <1> 	; ESI = Logical DOS Drive Description Table address	
  3330 00007984 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
  3331                              <1> 	           ; BL = 0 -> Recalculate free cluster count
  3332 00007988 50                  <1> 	push	eax
  3333 00007989 E8E1370000          <1> 	call	calculate_fat_freespace	
  3334 0000798E 58                  <1> 	pop	eax
  3335 0000798F 9D                  <1> 	popf
  3336 00007990 0F8284FCFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3337 00007996 E97FFCFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3338                              <1> 
  3339                              <1> 
  3340                              <1> loc_rmdir_empty_dir_cluster:
  3341 0000799B 5E                  <1> 	pop	esi
  3342                              <1> 
  3343                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
  3344 0000799C 803D[1F2B0100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  3345 000079A3 761D                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
  3346                              <1> 
  3347 000079A5 A1[2C2B0100]        <1> 	mov	eax, [RmDir_PreviousCluster]
  3348                              <1> 	;xor	ecx, ecx
  3349 000079AA 49                  <1> 	dec	ecx ; FFFFFFFFh
  3350 000079AB E86D340000          <1> 	call	update_cluster
  3351 000079B0 7310                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
  3352                              <1> 
  3353                              <1> loc_rmdir_unlink_stc_retn:
  3354                              <1> 	; 01/03/2016
  3355 000079B2 83F801              <1> 	cmp	eax, 1  ; eax = 0 -> end of cluster chain
  3356 000079B5 F5                  <1> 	cmc 
  3357 000079B6 72BD                <1> 	jc	short loc_rmdir_cmd_failed
  3358 000079B8 EB1D                <1> 	jmp	short loc_rmdir_save_fat_buffer 
  3359                              <1> 	
  3360                              <1> loc_rmdir_unlink_stc_retn_0Bh:
  3361 000079BA B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
  3362 000079BF F9                  <1> 	stc
  3363 000079C0 EBB3                <1> 	jmp	short loc_rmdir_cmd_failed
  3364                              <1>  
  3365                              <1> loc_rmdir_unlink_dir_last_cluster:
  3366 000079C2 A1[282B0100]        <1> 	mov	eax, [RmDir_DirLastCluster]
  3367 000079C7 31C9                <1> 	xor	ecx, ecx ; 0
  3368 000079C9 E84F340000          <1> 	call	update_cluster
  3369 000079CE 73EA                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh
  3370                              <1> 	; Because of it is the last cluster
  3371                              <1> 	; 'update_cluster' must return with eocc error 
  3372 000079D0 09C0                <1> 	or	eax, eax
  3373 000079D2 7403                <1> 	jz	short loc_rmdir_save_fat_buffer ; eocc	
  3374 000079D4 F9                  <1> 	stc
  3375 000079D5 EB9E                <1>         jmp     short loc_rmdir_cmd_failed
  3376                              <1> 	 
  3377                              <1> loc_rmdir_save_fat_buffer:
  3378 000079D7 803D[A6280100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  3379 000079DE 7525                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
  3380 000079E0 E8F5360000          <1> 	call	save_fat_buffer
  3381 000079E5 728E                <1> 	jc	short loc_rmdir_cmd_failed
  3382                              <1> 
  3383                              <1> 	; 01/03/2016
  3384 000079E7 803D[1F2B0100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  3385 000079EE 7615                <1> 	jna	short loc_rmdir_calculate_FAT_freespace
  3386                              <1> 
  3387 000079F0 A1[F42A0100]        <1> 	mov	eax, [DelFile_FCluster]
  3388 000079F5 E9B8FEFFFF          <1>         jmp     loc_rmdir_get_last_cluster
  3389                              <1> 
  3390                              <1> loc_rmdir_delete_short_name_invalid_data:
  3391 000079FA B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
  3392 000079FF F9                  <1> 	stc
  3393 00007A00 E970FFFFFF          <1>         jmp     loc_rmdir_cmd_failed
  3394                              <1> 
  3395                              <1> loc_rmdir_calculate_FAT_freespace:
  3396 00007A05 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  3397 00007A0A 66BB01FF            <1> 	mov	bx, 0FF01h
  3398                              <1> 	; BL = 1 -> Add EAX to free space count
  3399                              <1> 	; BH = FFh ->
  3400                              <1> 	; ESI = Logical DOS Drive Description Table address
  3401 00007A0E E85C370000          <1> 	call	calculate_fat_freespace
  3402                              <1> 
  3403 00007A13 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
  3404 00007A15 7409                <1> 	jz 	short loc_rmdir_delete_short_name_continue
  3405                              <1> 
  3406                              <1> loc_rmdir_recalculate_FAT_freespace:
  3407 00007A17 66BB00FF            <1>         mov     bx, 0FF00h ; BL = 0 -> Recalculate free space
  3408 00007A1B E84F370000          <1> 	call	calculate_fat_freespace
  3409                              <1> 	          
  3410                              <1> loc_rmdir_delete_short_name_continue:
  3411 00007A20 A1[242B0100]        <1> 	mov	eax, [RmDir_ParentDirCluster]
  3412 00007A25 83F802              <1> 	cmp	eax, 2
  3413 00007A28 730D                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
  3414 00007A2A E81F320000          <1> 	call	load_FAT_root_directory
  3415 00007A2F 0F82E5FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3416 00007A35 EB0B                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
  3417                              <1> 
  3418                              <1> loc_rmdir_del_short_name_load_sub_dir:	
  3419 00007A37 E89D320000          <1> 	call	load_FAT_sub_directory
  3420 00007A3C 0F82D8FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3421                              <1> 
  3422                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
  3423 00007A42 0FB73D[202B0100]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
  3424 00007A49 81C700000800        <1> 	add	edi, Directory_Buffer
  3425                              <1> 
  3426 00007A4F 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  3427 00007A53 C1E010              <1> 	shl	eax, 16
  3428 00007A56 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  3429                              <1>         ; Not necessary... 
  3430 00007A5A 3B05[F42A0100]      <1> 	cmp	eax, [DelFile_FCluster]
  3431 00007A60 7598                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
  3432                              <1> 	;
  3433 00007A62 C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
  3434                              <1> 	; 27/02/2016
  3435                              <1> 	; TRDOS v1 has a bug here! it does not set
  3436                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  3437                              <1> 	; 'save_directory_buffer' would not save the change ! 
  3438 00007A65 C605[B8280100]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
  3439                              <1> 	;
  3440 00007A6C E8EF1D0000          <1> 	call	save_directory_buffer
  3441 00007A71 0F82A3FBFFFF        <1> 	jc	loc_file_rw_cmd_failed 
  3442                              <1> 
  3443                              <1> loc_rmdir_del_long_name:
  3444 00007A77 0FB615[FA2A0100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  3445 00007A7E 08D2                <1> 	or	dl, dl
  3446 00007A80 7414                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
  3447                              <1>              
  3448 00007A82 0FB705[F82A0100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  3449 00007A89 29D0                <1> 	sub	eax, edx
  3450 00007A8B 0F8289FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3451                              <1>  
  3452                              <1>  	; EAX = Directory Entry Number of the long name last entry
  3453 00007A91 E82A1F0000          <1> 	call	delete_longname
  3454                              <1> 	;jc	short loc_file_rw_cmd_failed
  3455                              <1> 
  3456                              <1> loc_rmdir_update_parent_dir_lmdt:
  3457 00007A96 E8601E0000          <1> 	call	update_parent_dir_lmdt
  3458                              <1> 	;jc	short loc_file_rw_cmd_failed
  3459                              <1> 
  3460                              <1> loc_rmdir_ok:
  3461 00007A9B BE[9FE20000]        <1> 	mov	esi, Msg_OK
  3462 00007AA0 E8B1DAFFFF          <1> 	call	print_msg
  3463 00007AA5 E970FBFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3464                              <1> 
  3465                              <1> 
  3466                              <1> delete_file:
  3467                              <1> 	; 29/02/2016
  3468                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
  3469                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
  3470                              <1> 	; 28/02/2010
  3471                              <1> 
  3472                              <1> get_delfile_fchar:
  3473                              <1> 	; esi = file name
  3474 00007AAA 803E20              <1> 	cmp	byte [esi], 20h
  3475 00007AAD 7701                <1>         ja	short loc_delfile_parse_path_name
  3476                              <1> 
  3477                              <1> loc_delfile_nofilename_retn:
  3478 00007AAF C3                  <1> 	retn
  3479                              <1> 
  3480                              <1> loc_delfile_parse_path_name:
  3481 00007AB0 BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  3482 00007AB5 E842190000          <1> 	call	parse_path_name
  3483 00007ABA 0F8230F2FFFF        <1> 	jc	loc_cmd_failed
  3484                              <1> 
  3485                              <1> loc_delfile_check_filename_exists:
  3486 00007AC0 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3487 00007AC5 803E20              <1> 	cmp	byte [esi], 20h
  3488 00007AC8 0F8622F2FFFF        <1> 	jna	loc_cmd_failed
  3489 00007ACE 8935[F02A0100]      <1> 	mov	[DelFile_FNPointer], esi 
  3490                              <1> 
  3491                              <1> loc_delfile_drv:
  3492 00007AD4 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  3493 00007ADA 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  3494 00007AE0 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  3495 00007AE6 38F2                <1> 	cmp	dl, dh
  3496 00007AE8 740B                <1> 	je	short loc_delfile_change_directory
  3497                              <1> 
  3498 00007AEA E867E3FFFF          <1> 	call	change_current_drive
  3499 00007AEF 0F8225FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3500                              <1> 
  3501                              <1> loc_delfile_change_directory:
  3502 00007AF5 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3503 00007AFC 7618                <1> 	jna	short loc_delfile_find
  3504                              <1> 
  3505 00007AFE FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3506 00007B04 BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  3507 00007B09 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3508 00007B0B E8D8120000          <1> 	call	change_current_directory
  3509 00007B10 0F8204FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3510                              <1> 
  3511                              <1> ;loc_delfile_change_prompt_dir_string:
  3512                              <1> 	;call	change_prompt_dir_string
  3513                              <1> 
  3514                              <1> loc_delfile_find:
  3515                              <1> 	;mov	esi, FindFile_Name
  3516 00007B16 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3517 00007B1C 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  3518 00007B20 E8CDF6FFFF          <1> 	call	find_first_file
  3519 00007B25 0F82EFFAFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3520                              <1> 
  3521                              <1> loc_delfile_ambgfn_check:
  3522 00007B2B 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3523 00007B2E 740B                <1> 	jz	short loc_delfile_found
  3524                              <1> 
  3525                              <1> loc_file_not_found:
  3526 00007B30 B802000000          <1> 	mov	eax, 2 ; File not found sign
  3527 00007B35 F9                  <1> 	stc
  3528 00007B36 E9DFFAFFFF          <1> 	jmp	loc_file_rw_cmd_failed   
  3529                              <1> 
  3530                              <1> loc_delfile_found:
  3531 00007B3B 80E307              <1> 	and	bl, 07h ; Attributes
  3532 00007B3E 0F85E0FAFFFF        <1>         jnz     loc_permission_denied
  3533                              <1> 
  3534                              <1> ;loc_delfile_found_save_lnel:
  3535                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  3536                              <1> 
  3537                              <1> loc_delfile_ask_for_delete:
  3538 00007B44 57                  <1> 	push	edi ; * (29/02/2016)
  3539                              <1> 
  3540 00007B45 BE[DDE20000]        <1> 	mov	esi, Msg_DoYouWantDelete
  3541 00007B4A E807DAFFFF          <1> 	call	print_msg
  3542 00007B4F 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3543 00007B55 E8FCD9FFFF          <1> 	call	print_msg
  3544 00007B5A BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  3545 00007B5F E8F2D9FFFF          <1> 	call	print_msg
  3546                              <1> 
  3547                              <1> loc_delfile_ask_again:
  3548 00007B64 30E4                <1> 	xor	ah, ah
  3549 00007B66 E8618FFFFF          <1> 	call	int16h
  3550 00007B6B 3C1B                <1> 	cmp	al, 1Bh
  3551                              <1> 	;je	short loc_do_not_delete_file
  3552 00007B6D 7457                <1> 	je	short loc_delfile_y_n_escape ; 06/03/2016
  3553 00007B6F 24DF                <1> 	and	al, 0DFh
  3554 00007B71 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  3555 00007B76 3C59                <1> 	cmp	al, 'Y'
  3556 00007B78 7404                <1> 	je	short loc_yes_delete_file
  3557 00007B7A 3C4E                <1> 	cmp	al, 'N'
  3558 00007B7C 75E6                <1> 	jne	short loc_delfile_ask_again
  3559                              <1> 
  3560                              <1> loc_do_not_delete_file:
  3561                              <1> loc_yes_delete_file:
  3562 00007B7E A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  3563 00007B83 6650                <1> 	push	ax
  3564 00007B85 BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  3565 00007B8A E8C7D9FFFF          <1> 	call	print_msg
  3566 00007B8F 6658                <1> 	pop	ax
  3567 00007B91 5F                  <1> 	pop	edi ; * (29/02/2016)
  3568                              <1> 	;cmp	al, 'Y' ; 'yes'
  3569                              <1> 	;cmc
  3570                              <1>         ;jnc	loc_file_rw_restore_retn
  3571 00007B92 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3572 00007B94 0F8480FAFFFF        <1>         je	loc_file_rw_restore_retn  
  3573                              <1> 
  3574                              <1> loc_delete_file:
  3575 00007B9A 8A3D[322A0100]      <1> 	mov	bh, [FindFile_Drv]
  3576                              <1> 	;mov	bl, [DelFile_LNEL]
  3577 00007BA0 8A1D[812A0100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  3578                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  3579 00007BA6 668B0D[AC2A0100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  3580                              <1> 	; (*) EDI = Directory buffer entry offset/address 
  3581 00007BAD E8F81F0000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
  3582 00007BB2 0F8358FAFFFF        <1> 	jnc	loc_print_deleted_message
  3583                              <1> 
  3584 00007BB8 3C05                <1> 	cmp	al, 05h
  3585 00007BBA 0F8464FAFFFF        <1> 	je	loc_permission_denied
  3586 00007BC0 F9                  <1> 	stc
  3587 00007BC1 E954FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3588                              <1> 
  3589                              <1> loc_delfile_y_n_escape:
  3590 00007BC6 B04E                <1> 	mov	al, 'N' ; 'no'
  3591 00007BC8 EBB4                <1> 	jmp	short loc_do_not_delete_file
  3592                              <1> 
  3593                              <1> set_file_attributes:
  3594                              <1> 	; 06/03/2016
  3595                              <1> 	; 04/03/2016 (TRDOS 386 =  TRDOS v2.0)
  3596                              <1> 	; 10/07/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_attrib')
  3597                              <1> 	; 23/05/2010 
  3598                              <1> 	; 17/12/2000 (P2000.ASM)
  3599                              <1> 
  3600                              <1> 	; esi = file or directory name
  3601 00007BCA 6631C0              <1> 	xor	ax, ax
  3602 00007BCD 66A3[2EE30000]      <1> 	mov	[Attr_Chars], ax
  3603 00007BD3 A2[482B0100]        <1> 	mov	[Attributes], al
  3604                              <1> 
  3605                              <1> get_attrib_fchar:
  3606                              <1> 	; esi = file name
  3607 00007BD8 8A06                <1> 	mov	al, [esi]
  3608 00007BDA 3C20                <1> 	cmp	al, 20h
  3609 00007BDC 7623                <1> 	jna	short loc_attr_file_nofilename_retn
  3610                              <1> 
  3611                              <1> loc_scan_attrib_params:
  3612 00007BDE 3C2D                <1> 	cmp	al, '-'
  3613 00007BE0 0F871C010000        <1> 	ja	loc_attr_file_parse_path_name
  3614 00007BE6 7408                <1> 	je	short loc_attr_space
  3615                              <1> 
  3616 00007BE8 3C2B                <1> 	cmp	al, '+'
  3617 00007BEA 0F8500F1FFFF        <1> 	jne	loc_cmd_failed
  3618                              <1> 
  3619                              <1> loc_attr_space:
  3620 00007BF0 8A6601              <1> 	mov	ah, [esi+1]
  3621 00007BF3 80FC20              <1>  	cmp	ah, 20h
  3622 00007BF6 770A                <1> 	ja	short pass_attr_space
  3623 00007BF8 0F82F2F0FFFF        <1> 	jb	loc_cmd_failed
  3624 00007BFE 46                  <1> 	inc	esi
  3625 00007BFF EBEF                <1> 	jmp	short loc_attr_space
  3626                              <1> 
  3627                              <1> loc_attr_file_nofilename_retn:
  3628 00007C01 C3                  <1> 	retn
  3629                              <1> 
  3630                              <1> pass_attr_space:
  3631 00007C02 80E4DF              <1> 	and	ah, 0DFh
  3632 00007C05 80FC53              <1> 	cmp	ah, 'S'
  3633 00007C08 0F87E2F0FFFF        <1> 	ja	loc_cmd_failed
  3634 00007C0E 7204                <1> 	jb	short pass_attr_system
  3635 00007C10 B404                <1> 	mov	ah, 04h   ; System
  3636 00007C12 EB21                <1> 	jmp	short pass_attr_archive
  3637                              <1> 
  3638                              <1> pass_attr_system:
  3639 00007C14 80FC48              <1> 	cmp	ah, 'H'
  3640 00007C17 7706                <1> 	ja	short pass_attr_hidden
  3641 00007C19 7213                <1> 	jb	short pass_attr_read_only
  3642 00007C1B B402                <1> 	mov	ah, 02h    ; Hidden
  3643 00007C1D EB16                <1> 	jmp	short pass_attr_archive
  3644                              <1> 
  3645                              <1> pass_attr_hidden:
  3646 00007C1F 80FC52              <1> 	cmp	ah, 'R'
  3647 00007C22 0F87C8F0FFFF        <1> 	ja	loc_cmd_failed
  3648 00007C28 7204                <1> 	jb	short pass_attr_read_only ; Read only
  3649 00007C2A B401                <1> 	mov	ah, 01h
  3650 00007C2C EB07                <1> 	jmp	short pass_attr_archive
  3651                              <1> 
  3652                              <1> pass_attr_read_only:
  3653 00007C2E 80FC41              <1> 	cmp	ah, 'A'
  3654 00007C31 753B                <1> 	jne	short loc_chk_attr_enter
  3655 00007C33 B420                <1> 	mov	ah, 20h    ; Archive
  3656                              <1> 
  3657                              <1> pass_attr_archive:
  3658 00007C35 3C2D                <1> 	cmp	al, '-'
  3659 00007C37 7508                <1> 	jne	short pass_reducing_attributes
  3660 00007C39 0825[2EE30000]      <1> 	or	[Attr_Chars], ah
  3661 00007C3F EB06                <1> 	jmp	short loc_change_attributes_inc
  3662                              <1> 
  3663                              <1> pass_reducing_attributes:
  3664 00007C41 0825[2FE30000]      <1> 	or	[Attr_Chars+1], ah
  3665                              <1> 
  3666                              <1> loc_change_attributes_inc:
  3667 00007C47 46                  <1> 	inc	esi
  3668 00007C48 8A6601              <1> 	mov	ah, [esi+1]
  3669 00007C4B 80FC20              <1> 	cmp	ah, 20h
  3670 00007C4E 7227                <1> 	jb	short pass_change_attr
  3671 00007C50 74F5                <1> 	je	short loc_change_attributes_inc
  3672 00007C52 80FC2D              <1> 	cmp	ah, '-'
  3673 00007C55 770D                <1> 	ja	short loc_chk_next_attr_char1
  3674 00007C57 7405                <1> 	je	short loc_chk_next_attr_char0
  3675 00007C59 80FC2B              <1> 	cmp	ah, '+'
  3676 00007C5C 7506                <1> 	jne	short loc_chk_next_attr_char1
  3677                              <1> 
  3678                              <1> loc_chk_next_attr_char0:
  3679 00007C5E 46                  <1> 	inc	esi
  3680 00007C5F 668B06              <1> 	mov	ax, [esi]
  3681 00007C62 EB9E                <1> 	jmp	short pass_attr_space
  3682                              <1> 
  3683                              <1> loc_chk_next_attr_char1:
  3684 00007C64 803E2D              <1> 	cmp	byte [esi], '-'
  3685 00007C67 7799                <1> 	ja	short pass_attr_space
  3686 00007C69 E988000000          <1>         jmp     loc_attr_file_check_fname_fchar
  3687                              <1> 
  3688                              <1> loc_chk_attr_enter:
  3689 00007C6E 80FC0D              <1> 	cmp	ah, 0Dh
  3690 00007C71 0F8579F0FFFF        <1> 	jne	loc_cmd_failed
  3691                              <1> 
  3692                              <1> pass_change_attr:
  3693 00007C77 A0[2EE30000]        <1> 	mov	al, [Attr_Chars]
  3694 00007C7C F6D0                <1> 	not	al
  3695 00007C7E 2005[482B0100]      <1> 	and	[Attributes], al
  3696 00007C84 A0[2FE30000]        <1> 	mov	al, [Attr_Chars+1]
  3697 00007C89 0805[482B0100]      <1> 	or	[Attributes], al
  3698                              <1> 
  3699                              <1> loc_show_attributes:
  3700 00007C8F BE[ABEE0000]        <1> 	mov	esi, nextline
  3701 00007C94 E8BDD8FFFF          <1> 	call	print_msg
  3702                              <1> 
  3703                              <1> loc_show_attributes_no_nextline:
  3704 00007C99 C705[2EE30000]4E4F- <1> 	mov	dword [Attr_Chars], 'NORM'
  3704 00007CA1 524D                <1>
  3705 00007CA3 66C705[32E30000]41- <1> 	mov	word [Attr_Chars+4], 'AL'
  3705 00007CAB 4C                  <1>
  3706 00007CAC BE[2EE30000]        <1> 	mov	esi, Attr_Chars
  3707 00007CB1 A0[482B0100]        <1> 	mov	al, [Attributes]
  3708 00007CB6 A804                <1> 	test	al, 04h
  3709 00007CB8 7406                <1> 	jz	short pass_put_attr_s
  3710 00007CBA 66C7065300          <1> 	mov	word [esi], 0053h     ; S
  3711 00007CBF 46                  <1> 	inc	esi
  3712                              <1> 
  3713                              <1> pass_put_attr_s:
  3714 00007CC0 A802                <1> 	test	al, 02h
  3715 00007CC2 7406                <1> 	jz	short pass_put_attr_h
  3716 00007CC4 66C7064800          <1> 	mov	word [esi], 0048h     ; H
  3717 00007CC9 46                  <1> 	inc	esi
  3718                              <1> 
  3719                              <1> pass_put_attr_h:
  3720 00007CCA A801                <1> 	test	al, 01h
  3721 00007CCC 7406                <1> 	jz	short pass_put_attr_r
  3722 00007CCE 66C7065200          <1> 	mov	word [esi], 0052h     ; R
  3723 00007CD3 46                  <1> 	inc	esi
  3724                              <1> 
  3725                              <1> pass_put_attr_r:
  3726 00007CD4 3C20                <1> 	cmp	al, 20h
  3727 00007CD6 7205                <1> 	jb	short pass_put_attr_a
  3728 00007CD8 66C7064100          <1> 	mov	word [esi], 0041h     ; A
  3729                              <1> 
  3730                              <1> pass_put_attr_a:
  3731 00007CDD BE[21E30000]        <1> 	mov	esi, Str_Attributes
  3732 00007CE2 E86FD8FFFF          <1> 	call	print_msg
  3733 00007CE7 BE[ABEE0000]        <1> 	mov	esi, nextline
  3734 00007CEC E865D8FFFF          <1> 	call	print_msg
  3735 00007CF1 E924F9FFFF          <1> 	jmp	loc_file_rw_restore_retn 
  3736                              <1> 
  3737                              <1> loc_attr_file_check_fname_fchar:
  3738 00007CF6 46                  <1> 	inc	esi
  3739 00007CF7 803E20              <1> 	cmp	byte [esi], 20h
  3740 00007CFA 74FA                <1> 	je	short loc_attr_file_check_fname_fchar
  3741 00007CFC 0F8275FFFFFF        <1>         jb      pass_change_attr
  3742                              <1> 		   
  3743                              <1> loc_attr_file_parse_path_name:
  3744 00007D02 BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  3745 00007D07 E8F0160000          <1> 	call	parse_path_name
  3746 00007D0C 0F82DEEFFFFF        <1> 	jc	loc_cmd_failed
  3747                              <1> 
  3748                              <1> loc_attr_file_check_filename_exists:
  3749 00007D12 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3750 00007D17 803E20              <1> 	cmp	byte [esi], 20h
  3751 00007D1A 0F86D0EFFFFF        <1> 	jna	loc_cmd_failed
  3752 00007D20 8935[F02A0100]      <1> 	mov	[DelFile_FNPointer], esi 
  3753                              <1> 
  3754                              <1> loc_attr_file_drv:
  3755 00007D26 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  3756 00007D2C 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  3757                              <1> 
  3758 00007D32 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  3759 00007D38 38F2                <1> 	cmp	dl, dh
  3760 00007D3A 740B                <1> 	je	short loc_attr_file_change_directory
  3761                              <1> 
  3762 00007D3C E815E1FFFF          <1> 	call	change_current_drive
  3763 00007D41 0F82D3F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3764                              <1> 
  3765                              <1> loc_attr_file_change_directory:
  3766 00007D47 803D[332A0100]20    <1>         cmp     byte [FindFile_Directory], 20h
  3767 00007D4E 7618                <1> 	jna	short loc_attr_file_find
  3768                              <1> 
  3769 00007D50 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3770                              <1> 	
  3771 00007D56 BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  3772 00007D5B 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3773 00007D5D E886100000          <1> 	call	change_current_directory
  3774 00007D62 0F82B2F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3775                              <1> 
  3776                              <1> ;loc_attr_file_change_prompt_dir_string:
  3777                              <1> 	;call	change_prompt_dir_string
  3778                              <1> 
  3779                              <1> loc_attr_file_find:
  3780                              <1> 	;mov	esi, FindFile_Name
  3781 00007D68 8B35[F02A0100]      <1> 	mov	esi, [DelFile_FNPointer]
  3782 00007D6E 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  3783 00007D72 E87BF4FFFF          <1> 	call	find_first_file
  3784 00007D77 0F829DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3785                              <1> 
  3786                              <1> loc_attr_file_ambgfn_check:
  3787 00007D7D 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3788                              <1> 	;	(Note: It was BX in TRDOS v1)
  3789                              <1> 	;jz	short loc_attr_file_found
  3790 00007D80 0F85AAFDFFFF        <1>         jnz     loc_file_not_found ; 06/03/2016 
  3791                              <1> 
  3792                              <1> 	;mov	eax, 2 ; File not found sign
  3793                              <1> 	;stc
  3794                              <1> 	;jmp	loc_file_rw_cmd_failed   
  3795                              <1> 
  3796                              <1> loc_attr_file_found:
  3797                              <1> 	; EDI = Directory buffer entry offset/address
  3798                              <1> 	; BL = File (or Directory) Attributes 
  3799                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  3800                              <1> 	; mov	bl, [EDI+0Bh]
  3801                              <1> 	
  3802 00007D86 66833D[2EE30000]00  <1> 	cmp	word [Attr_Chars], 0
  3803 00007D8E 770B                <1> 	ja	short loc_attr_file_change_attributes
  3804 00007D90 881D[482B0100]      <1> 	mov	[Attributes], bl
  3805 00007D96 E9F4FEFFFF          <1> 	jmp	loc_show_attributes
  3806                              <1> 
  3807                              <1> loc_attr_file_change_attributes:
  3808 00007D9B A0[2EE30000]        <1> 	mov	al, [Attr_Chars]
  3809 00007DA0 F6D0                <1> 	not	al
  3810 00007DA2 20C3                <1> 	and	bl, al
  3811 00007DA4 A0[2FE30000]        <1> 	mov	al, [Attr_Chars+1]
  3812 00007DA9 08C3                <1> 	or	bl, al
  3813                              <1> 
  3814 00007DAB 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
  3815 00007DB1 741D                <1> 	je	short loc_attr_file_fs_check
  3816                              <1> 
  3817 00007DB3 881D[482B0100]      <1> 	mov	[Attributes], bl
  3818 00007DB9 885F0B              <1> 	mov	[edi+0Bh], bl    ; Attributes (New!)
  3819                              <1> 
  3820                              <1> 	; 04/03/2016
  3821                              <1> 	; TRDOS v1 has a bug here! it does not set
  3822                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  3823                              <1> 	; 'save_directory_buffer' would not save the new attributes ! 
  3824                              <1> 	
  3825 00007DBC C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  3826                              <1> 
  3827 00007DC3 E8981A0000          <1> 	call 	save_directory_buffer
  3828 00007DC8 0F824CF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3829                              <1> 
  3830 00007DCE EB33                <1> 	jmp	short loc_print_attr_changed_message
  3831                              <1> 
  3832                              <1> loc_attr_file_fs_check:
  3833 00007DD0 29C0                <1> 	sub	eax, eax
  3834 00007DD2 8A25[B6280100]      <1>         mov     ah, [DirBuff_DRV]
  3835 00007DD8 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3836 00007DDD 01C6                <1>         add     esi, eax
  3837 00007DDF 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
  3838 00007DE3 7309                <1> 	jnc	short loc_attr_file_change_fs_file_attributes
  3839 00007DE5 66B80D00            <1> 	mov	ax, 0Dh ; Invalid Data
  3840 00007DE9 E92CF8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3841                              <1> 
  3842                              <1> loc_attr_file_change_fs_file_attributes:
  3843                              <1> 	; BL = New MS-DOS File Attributes
  3844 00007DEE 88D8                <1> 	mov	al, bl ; File/Directory Attributes
  3845 00007DF0 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign	  
  3846 00007DF2 E89C050000          <1> 	call	change_fs_file_attributes
  3847 00007DF7 0F821DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3848                              <1> 
  3849 00007DFD 881D[482B0100]      <1> 	mov	[Attributes], bl 
  3850                              <1> 
  3851                              <1> loc_print_attr_changed_message:
  3852 00007E03 BE[1CE30000]        <1> 	mov	esi, Msg_New
  3853 00007E08 E849D7FFFF          <1> 	call	print_msg
  3854 00007E0D E987FEFFFF          <1> 	jmp	loc_show_attributes_no_nextline
  3855                              <1> 
  3856                              <1> rename_file:
  3857                              <1> 	; 08/03/2016
  3858                              <1> 	; 06/03/2016 (TRDOS 386 =  TRDOS v2.0)
  3859                              <1> 	; 20/11/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_rename')
  3860                              <1> 	; 16/11/2010 
  3861                              <1> 
  3862                              <1> get_rename_source_fchar:
  3863                              <1> 	; esi = file name
  3864 00007E12 803E20              <1> 	cmp	byte [esi], 20h
  3865 00007E15 7614                <1>         jna	short loc_rename_nofilename_retn
  3866                              <1> 
  3867 00007E17 8935[6C2B0100]      <1> 	mov	[SourceFilePath], esi
  3868                              <1> 
  3869                              <1> rename_scan_source_file:
  3870 00007E1D 46                  <1> 	inc	esi
  3871 00007E1E 803E20              <1> 	cmp	byte [esi], 20h
  3872 00007E21 7409                <1> 	je	short rename_scan_destination_file_1
  3873                              <1> 	;jb	short loc_rename_nofilename_retn
  3874 00007E23 0F82C7EEFFFF        <1> 	jb	loc_cmd_failed
  3875 00007E29 EBF2                <1> 	jmp	short rename_scan_source_file
  3876                              <1> 
  3877                              <1> loc_rename_nofilename_retn: ; 08/03/2016
  3878 00007E2B C3                  <1> 	retn
  3879                              <1> 
  3880                              <1> rename_scan_destination_file_1:
  3881 00007E2C C60600              <1> 	mov	byte [esi], 0
  3882                              <1> 
  3883                              <1> rename_scan_destination_file_2:
  3884 00007E2F 46                  <1> 	inc	esi  
  3885 00007E30 803E20              <1> 	cmp	byte [esi], 20h
  3886 00007E33 74FA                <1> 	je	short rename_scan_destination_file_2
  3887                              <1> 	;jb	short loc_rename_nofilename_retn
  3888 00007E35 0F82B5EEFFFF        <1> 	jb	loc_cmd_failed
  3889                              <1> 
  3890 00007E3B 8935[702B0100]      <1> 	mov	[DestinationFilePath], esi
  3891                              <1> 
  3892                              <1> rename_scan_destination_file_3:
  3893 00007E41 46                  <1> 	inc	esi  
  3894 00007E42 803E20              <1> 	cmp	byte [esi], 20h
  3895 00007E45 77FA                <1> 	ja	short rename_scan_destination_file_3
  3896                              <1> 
  3897 00007E47 C60600              <1> 	mov	byte [esi], 0
  3898                              <1> 
  3899                              <1> loc_rename_save_current_drive:
  3900 00007E4A 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  3901 00007E50 8835[EE280100]      <1> 	mov	byte [RUN_CDRV], dh
  3902                              <1> 
  3903                              <1> loc_rename_sf_parse_path_name:
  3904 00007E56 8B35[6C2B0100]      <1> 	mov	esi, [SourceFilePath] 
  3905 00007E5C BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  3906 00007E61 E896150000          <1> 	call	parse_path_name
  3907 00007E66 0F8284EEFFFF        <1> 	jc	loc_cmd_failed
  3908                              <1> 
  3909                              <1> loc_rename_sf_check_filename_exists:
  3910 00007E6C BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3911 00007E71 803E20              <1> 	cmp	byte [esi], 20h
  3912 00007E74 0F8676EEFFFF        <1> 	jna	loc_cmd_failed
  3913                              <1> 
  3914                              <1> 	;mov	[DelFile_FNPointer], esi 
  3915                              <1> 
  3916                              <1> loc_rename_sf_drv:
  3917                              <1> 	;mov	dh, [Current_Drv]
  3918                              <1> 	;mov	[RUN_CDRV], dh
  3919                              <1> 
  3920 00007E7A 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  3921 00007E80 38F2                <1> 	cmp	dl, dh ; dh = [Current_Drv]
  3922 00007E82 740B                <1> 	je	short rename_sf_change_directory
  3923                              <1> 
  3924 00007E84 E8CDDFFFFF          <1> 	call	change_current_drive
  3925 00007E89 0F828BF7FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3926                              <1> 
  3927                              <1> rename_sf_change_directory:
  3928 00007E8F 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3929 00007E96 7618                <1> 	jna	short rename_sf_find
  3930                              <1> 
  3931 00007E98 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3932 00007E9E BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  3933 00007EA3 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3934 00007EA5 E83E0F0000          <1> 	call	change_current_directory
  3935 00007EAA 0F826AF7FFFF        <1>  	jc	loc_file_rw_cmd_failed
  3936                              <1> 
  3937                              <1> ;rename_sf_change_prompt_dir_string:
  3938                              <1> 	;call	change_prompt_dir_string
  3939                              <1> 
  3940                              <1> rename_sf_find:
  3941                              <1> 	;mov	esi, [DelFile_FNPointer]
  3942 00007EB0 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3943                              <1> 
  3944 00007EB5 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  3945 00007EB9 E834F3FFFF          <1> 	call	find_first_file
  3946 00007EBE 0F8256F7FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3947                              <1> 
  3948                              <1> loc_rename_sf_ambgfn_check:
  3949 00007EC4 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3950                              <1> 	;	(Note: It was BX in TRDOS v1)
  3951                              <1> 	;jz	short loc_rename_sf_found
  3952 00007EC7 0F8563FCFFFF        <1> 	jnz	loc_file_not_found
  3953                              <1> 
  3954                              <1> 	;mov	eax, 2 ; File not found sign
  3955                              <1> 	;stc
  3956                              <1> 	;jmp	loc_file_rw_cmd_failed   
  3957                              <1> 
  3958                              <1> loc_rename_sf_found:
  3959                              <1> 	; EDI = Directory buffer entry offset/address
  3960                              <1> 	; BL = File (or Directory) Attributes 
  3961                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  3962                              <1> 	; mov	bl, [EDI+0Bh]
  3963                              <1> 
  3964 00007ECD F6C307              <1> 	test	bl, 07h ; Attributes, S-H-R
  3965 00007ED0 0F854EF7FFFF        <1> 	jnz	loc_permission_denied
  3966                              <1> 	
  3967 00007ED6 BE[322A0100]        <1>         mov     esi, FindFile_Drv
  3968 00007EDB BF[742B0100]        <1>         mov     edi, SourceFile_Drv
  3969 00007EE0 B920000000          <1> 	mov	ecx, 32
  3970 00007EE5 F3A5                <1> 	rep	movsd
  3971                              <1> 
  3972                              <1> loc_rename_df_parse_path_name:
  3973 00007EE7 8B35[702B0100]      <1> 	mov	esi, [DestinationFilePath]
  3974 00007EED BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  3975 00007EF2 E805150000          <1> 	call	parse_path_name
  3976 00007EF7 7219                <1> 	jc	short loc_rename_df_cmd_failed
  3977                              <1> 
  3978                              <1> 	;mov	dh, [RUN_CDRV]
  3979 00007EF9 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  3980                              <1> 
  3981                              <1> 	; 'rename' command is valid only for same dos drive and same dir!
  3982                              <1> 	; ('move' command must be used if source file and destination file
  3983                              <1> 	; directories are not same!) 
  3984 00007EFF 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  3985 00007F05 38F2                <1> 	cmp	dl, dh ; are source and destination drives different ?!
  3986 00007F07 7509                <1> 	jne	short loc_rename_df_cmd_failed ; yes! 
  3987                              <1> 
  3988                              <1> rename_df_check_dirname_exists:
  3989 00007F09 803D[332A0100]00    <1> 	cmp	byte [FindFile_Directory], 0
  3990 00007F10 760B                <1> 	jna	short rename_df_check_filename_exists
  3991                              <1> 
  3992                              <1> 	; different source file and destination file directories !
  3993                              <1> loc_rename_df_cmd_failed:
  3994                              <1> loc_rename_df_found:
  3995 00007F12 B801000000          <1> 	mov	eax, 1 ; TRDOS 'Bad command or file name' error
  3996 00007F17 F9                  <1> 	stc
  3997 00007F18 E9FDF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3998                              <1> 	  
  3999                              <1> rename_df_check_filename_exists:
  4000 00007F1D BE[742A0100]        <1> 	mov	esi, FindFile_Name
  4001 00007F22 E883F6FFFF          <1> 	call	check_filename
  4002 00007F27 0F829FF7FFFF        <1> 	jc	loc_mkdir_invalid_dir_name_chars
  4003                              <1> 
  4004                              <1> 	;mov	[DelFile_FNPointer], esi 
  4005                              <1> 	;cmp	byte [esi], 20h
  4006                              <1> 	;ja	short loc_rename_df_find
  4007                              <1> 
  4008                              <1> 	;mov	dh, [Current_Drv] ; dh has not been changed
  4009                              <1> 
  4010                              <1> rename_df_drv_check_writable:
  4011 00007F2D 0FB6F6              <1> 	movzx	esi, dh
  4012                              <1> 	;movzx	esi, byte [Current_Drv]
  4013 00007F30 81C600010900        <1> 	add	esi, Logical_DOSDisks
  4014                              <1> 
  4015 00007F36 88F2                <1> 	mov	dl, dh ; dl = [Current_Drv]
  4016 00007F38 8A7601              <1> 	mov	dh, [esi+LD_DiskType]
  4017                              <1> 
  4018 00007F3B 80FE01              <1> 	cmp	dh, 1 ; 0 = Invalid
  4019 00007F3E 7310                <1> 	jnb	short rename_df_compare_sf_df_name
  4020                              <1> 
  4021 00007F40 B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected
  4022 00007F45 8B1D[702B0100]      <1> 	mov	ebx, [DestinationFilePath] 
  4023 00007F4B E9CAF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4024                              <1> 
  4025                              <1> rename_df_compare_sf_df_name:
  4026 00007F50 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  4027 00007F55 BF[B62B0100]        <1> 	mov	edi, SourceFile_Name
  4028 00007F5A B90C000000          <1> 	mov	ecx, 12
  4029                              <1> rename_df_compare_sf_df_name_next: 
  4030 00007F5F AC                  <1> 	lodsb
  4031 00007F60 AE                  <1> 	scasb
  4032 00007F61 7506                <1> 	jne	short loc_rename_df_find
  4033 00007F63 08C0                <1> 	or	al, al
  4034 00007F65 74AB                <1> 	jz	short loc_rename_df_cmd_failed
  4035 00007F67 E2F6                <1> 	loop	rename_df_compare_sf_df_name_next 
  4036                              <1> 
  4037                              <1> loc_rename_df_find:
  4038                              <1> 	;mov	esi, [DelFile_FNPointer]
  4039 00007F69 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  4040                              <1> 
  4041 00007F6E 6631C0              <1> 	xor	ax, ax ; Any
  4042 00007F71 E87CF2FFFF          <1> 	call	find_first_file
  4043 00007F76 739A                <1> 	jnc	short loc_rename_df_found
  4044                              <1> 
  4045                              <1> loc_rename_df_check_error_code:
  4046                              <1> 	;cmp	eax, 2
  4047 00007F78 3C02                <1> 	cmp	al, 2 ; Not found error
  4048 00007F7A 7406                <1> 	je	short rename_df_move_find_struct_to_dest
  4049 00007F7C F9                  <1> 	stc
  4050 00007F7D E998F6FFFF          <1> 	jmp loc_file_rw_cmd_failed
  4051                              <1> 
  4052                              <1> ;loc_rename_df_found:
  4053                              <1> ;	mov	eax, 1 ;Bad command or file name error
  4054                              <1> ;	stc
  4055                              <1> ;	jmp	loc_file_rw_cmd_failed
  4056                              <1> 
  4057                              <1> rename_df_move_find_struct_to_dest:
  4058 00007F82 BE[322A0100]        <1>         mov     esi, FindFile_Drv
  4059 00007F87 BF[F42B0100]        <1>         mov     edi, DestinationFile_Drv
  4060 00007F8C B920000000          <1> 	mov	ecx, 32
  4061 00007F91 F3A5                <1> 	rep	movsd
  4062                              <1> 
  4063                              <1> loc_rename_df_process_q_sf:
  4064                              <1> 	;mov	ecx, 12
  4065 00007F93 B10C                <1> 	mov	cl, 12
  4066 00007F95 BE[B62B0100]        <1>  	mov	esi, SourceFile_Name
  4067 00007F9A BF[5DE30000]        <1> 	mov	edi, Rename_OldName
  4068                              <1> rename_df_process_q_nml_1_sf:
  4069 00007F9F AC                  <1> 	lodsb
  4070 00007FA0 3C20                <1>         cmp	al, 20h
  4071 00007FA2 7603                <1>         jna	short rename_df_process_q_nml_2_sf
  4072 00007FA4 AA                  <1> 	stosb
  4073 00007FA5 E2F8                <1> 	loop	rename_df_process_q_nml_1_sf
  4074                              <1> 
  4075                              <1> rename_df_process_q_nml_2_sf:
  4076 00007FA7 C60700              <1> 	mov	byte [edi], 0
  4077                              <1> 
  4078                              <1> loc_rename_df_process_q_df:
  4079                              <1> 	;mov	ecx, 12
  4080 00007FAA B10C                <1> 	mov	cl, 12
  4081 00007FAC BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  4082 00007FB1 BF[6EE30000]        <1> 	mov	edi, Rename_NewName
  4083                              <1> rename_df_process_q_nml_1_df:
  4084 00007FB6 AC                  <1> 	lodsb
  4085 00007FB7 3C20                <1> 	cmp	al, 20h
  4086 00007FB9 7603                <1> 	jna	short loc_rename_df_process_q_nml_2_df
  4087 00007FBB AA                  <1> 	stosb
  4088 00007FBC E2F8                <1> 	loop	rename_df_process_q_nml_1_df
  4089                              <1> 
  4090                              <1> loc_rename_df_process_q_nml_2_df:
  4091 00007FBE C60700              <1> 	mov	byte [edi], 0
  4092                              <1> 
  4093                              <1> loc_rename_confirmation_question:
  4094 00007FC1 BE[35E30000]        <1> 	mov	esi, Msg_DoYouWantRename
  4095 00007FC6 E88BD5FFFF          <1> 	call	print_msg
  4096                              <1> 
  4097 00007FCB A0[D12B0100]        <1> 	mov	al, [SourceFile_DirEntry+11] ; Attributes
  4098 00007FD0 2410                <1> 	and	al, 10h
  4099 00007FD2 750C                <1> 	jnz	short rename_confirmation_question_dir
  4100                              <1> 
  4101                              <1> rename_confirmation_question_file:
  4102 00007FD4 BE[4CE30000]        <1> 	mov	esi, Rename_File
  4103 00007FD9 E878D5FFFF          <1> 	call	print_msg 
  4104 00007FDE EB0A                <1> 	jmp	short rename_confirmation_question_as 
  4105                              <1> 
  4106                              <1> rename_confirmation_question_dir:
  4107 00007FE0 BE[52E30000]        <1> 	mov	esi, Rename_Directory
  4108 00007FE5 E86CD5FFFF          <1> 	call	print_msg
  4109                              <1> 
  4110                              <1> rename_confirmation_question_as:
  4111 00007FEA BE[5DE30000]        <1> 	mov	esi, Rename_OldName
  4112 00007FEF E862D5FFFF          <1> 	call	print_msg
  4113 00007FF4 BE[6AE30000]        <1> 	mov	esi, Msg_File_rename_as
  4114 00007FF9 E858D5FFFF          <1> 	call	print_msg
  4115 00007FFE BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  4116 00008003 E84ED5FFFF          <1> 	call	print_msg
  4117                              <1> 
  4118                              <1> loc_rename_ask_again:
  4119 00008008 30E4                <1> 	xor	ah, ah
  4120 0000800A E8BD8AFFFF          <1> 	call	int16h
  4121 0000800F 3C1B                <1> 	cmp	al, 1Bh
  4122 00008011 740F                <1> 	je	short loc_do_not_rename_file
  4123 00008013 24DF                <1> 	and	al, 0DFh
  4124 00008015 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  4125 0000801A 3C59                <1> 	cmp	al, 'Y'
  4126 0000801C 7404                <1> 	je	short loc_yes_rename_file
  4127 0000801E 3C4E                <1> 	cmp	al, 'N'
  4128 00008020 75E6                <1> 	jne	short loc_rename_ask_again
  4129                              <1> 
  4130                              <1> loc_do_not_rename_file:
  4131                              <1> loc_yes_rename_file:
  4132 00008022 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  4133 00008027 6650                <1> 	push	ax
  4134 00008029 BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  4135 0000802E E823D5FFFF          <1> 	call	print_msg
  4136 00008033 6658                <1> 	pop	ax
  4137                              <1> 	;cmp	al, 'Y' ; 'yes'
  4138                              <1> 	;cmc
  4139                              <1>         ;jnc	loc_file_rw_restore_retn
  4140 00008035 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4141 00008037 0F84DDF5FFFF        <1>         je	loc_file_rw_restore_retn  
  4142                              <1> 
  4143 0000803D BE[6EE30000]        <1> 	mov	esi, Rename_NewName
  4144 00008042 668B0D[EE2B0100]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
  4145 00008049 66A1[DA2B0100]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
  4146 0000804F 66C1E010            <1> 	shl	ax, 16
  4147 00008053 66A1[E02B0100]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
  4148                              <1> 
  4149 00008059 0FB61D[C32B0100]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]  
  4150 00008060 E8E11B0000          <1>    	call	rename_directory_entry
  4151 00008065 E9DEF6FFFF          <1> 	jmp	loc_rename_file_ok	
  4152                              <1> ;loc_rename_file_ok:
  4153                              <1> ;	jc	loc_run_cmd_failed
  4154                              <1> ;	mov	esi, Msg_OK
  4155                              <1> ;	call	proc_printmsg
  4156                              <1> ;	jmp	loc_file_rw_restore_retn
  4157                              <1> 
  4158                              <1> move_file:
  4159                              <1> 	; 11/03/2016
  4160                              <1> 	; 09/03/2016
  4161                              <1> 	; 08/03/2016 (TRDOS 386 =  TRDOS v2.0)
  4162                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_move')
  4163                              <1> 	; 23/04/2011
  4164                              <1> 
  4165                              <1> get_move_source_fchar:
  4166                              <1> 	; esi = file name
  4167 0000806A 803E20              <1> 	cmp	byte [esi], 20h
  4168 0000806D 7614                <1>         jna	short loc_move_nofilename_retn
  4169                              <1> 
  4170 0000806F 8935[6C2B0100]      <1> 	mov	[SourceFilePath], esi
  4171                              <1> 
  4172                              <1> move_scan_source_file:
  4173 00008075 46                  <1> 	inc	esi
  4174 00008076 803E20              <1> 	cmp	byte [esi], 20h
  4175 00008079 7409                <1>         je      short move_scan_destination_1
  4176                              <1> 	;jb	short loc_move_nofilename_retn
  4177 0000807B 0F826FECFFFF        <1> 	jb	loc_cmd_failed
  4178 00008081 EBF2                <1> 	jmp	short move_scan_source_file
  4179                              <1> 
  4180                              <1> loc_move_nofilename_retn:
  4181 00008083 C3                  <1> 	retn
  4182                              <1> 
  4183                              <1> move_scan_destination_1:
  4184 00008084 C60600              <1> 	mov	byte [esi], 0
  4185                              <1> 
  4186                              <1> move_scan_destination_2:
  4187 00008087 46                  <1> 	inc	esi  
  4188 00008088 803E20              <1> 	cmp	byte [esi], 20h
  4189 0000808B 74FA                <1> 	je	short move_scan_destination_2
  4190                              <1> 	;jb	short loc_move_nofilename_retn
  4191 0000808D 0F825DECFFFF        <1> 	jb	loc_cmd_failed
  4192                              <1> 
  4193 00008093 8935[702B0100]      <1> 	mov	[DestinationFilePath], esi
  4194                              <1> 
  4195                              <1> move_scan_destination_3:
  4196 00008099 46                  <1> 	inc	esi  
  4197 0000809A 803E20              <1> 	cmp	byte [esi], 20h
  4198 0000809D 77FA                <1> 	ja	short move_scan_destination_3
  4199 0000809F C60600              <1> 	mov	byte [esi], 0
  4200                              <1> 
  4201                              <1> loc_move_scan_destination_OK:
  4202 000080A2 8B35[6C2B0100]      <1> 	mov	esi, [SourceFilePath]
  4203 000080A8 8B3D[702B0100]      <1> 	mov	edi, [DestinationFilePath]
  4204                              <1> 
  4205 000080AE B001                <1> 	mov	al, 1  ; move procedure Phase 1
  4206 000080B0 E80E1C0000          <1> 	call	move_source_file_to_destination_file
  4207 000080B5 7328                <1> 	jnc	short move_source_file_to_destination_question
  4208                              <1> 
  4209                              <1> loc_move_cmd_failed_1:
  4210 000080B7 08C0                <1> 	or	al, al
  4211 000080B9 0F8431ECFFFF        <1> 	jz	loc_cmd_failed 
  4212 000080BF 3C11                <1> 	cmp	al, 11h
  4213 000080C1 740D                <1> 	je	short loc_msg_not_same_device   
  4214 000080C3 3C05                <1> 	cmp	al, 05h
  4215 000080C5 0F8550ECFFFF        <1> 	jne	loc_run_cmd_failed
  4216                              <1> 
  4217 000080CB E954F5FFFF          <1> 	jmp	loc_permission_denied
  4218                              <1> 
  4219                              <1> 	;mov	esi, Msg_Permission_denied
  4220                              <1> 	;call	print_msg
  4221                              <1> 	;jmp	loc_file_rw_restore_retn
  4222                              <1> 
  4223                              <1> loc_msg_not_same_device:
  4224 000080D0 BE[7BE30000]        <1> 	mov	esi, msg_not_same_drv 
  4225 000080D5 E87CD4FFFF          <1> 	call	print_msg
  4226 000080DA E93BF5FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4227                              <1> 
  4228                              <1> move_source_file_to_destination_question:
  4229 000080DF A0[742B0100]        <1>         mov     al, [SourceFile_Drv]
  4230 000080E4 0441                <1> 	add	al, 'A'
  4231 000080E6 A2[DDE30000]        <1> 	mov	[msg_source_file_drv], al
  4232 000080EB A0[F42B0100]        <1>         mov     al, [DestinationFile_Drv]
  4233 000080F0 0441                <1> 	add	al, 'A'
  4234 000080F2 A2[FCE30000]        <1> 	mov	[msg_destination_file_drv], al
  4235                              <1> 
  4236 000080F7 57                  <1> 	push	edi ; *
  4237                              <1> 
  4238 000080F8 BE[C1E30000]        <1> 	mov	esi, msg_source_file
  4239 000080FD E854D4FFFF          <1> 	call	print_msg
  4240 00008102 BE[752B0100]        <1> 	mov	esi, SourceFile_Directory
  4241 00008107 803E20              <1> 	cmp	byte [esi], 20h
  4242 0000810A 7605                <1> 	jna	short msftdfq_sfn
  4243 0000810C E845D4FFFF          <1> 	call	print_msg
  4244                              <1> msftdfq_sfn:
  4245 00008111 BE[B62B0100]        <1> 	mov	esi, SourceFile_Name
  4246 00008116 E83BD4FFFF          <1> 	call	print_msg
  4247 0000811B BE[E0E30000]        <1> 	mov	esi, msg_destination_file
  4248 00008120 E831D4FFFF          <1> 	call	print_msg
  4249 00008125 BE[F52B0100]        <1> 	mov	esi, DestinationFile_Directory
  4250 0000812A 803E20              <1> 	cmp	byte [esi], 20h
  4251 0000812D 7605                <1> 	jna	short msftdfq_dfn
  4252 0000812F E822D4FFFF          <1> 	call	print_msg
  4253                              <1> msftdfq_dfn:
  4254 00008134 BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  4255 00008139 E818D4FFFF          <1> 	call	print_msg
  4256 0000813E BE[FFE30000]        <1> 	mov	esi, msg_copy_nextline
  4257 00008143 E80ED4FFFF          <1> 	call	print_msg
  4258 00008148 BE[FFE30000]        <1> 	mov	esi, msg_copy_nextline
  4259 0000814D E804D4FFFF          <1> 	call	print_msg
  4260                              <1> 
  4261                              <1> loc_move_ask_for_new_file_yes_no:
  4262 00008152 BE[8DE30000]        <1> 	mov	esi, Msg_DoYouWantMoveFile
  4263 00008157 E8FAD3FFFF          <1> 	call	print_msg
  4264 0000815C BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  4265 00008161 E8F0D3FFFF          <1> 	call	print_msg
  4266                              <1> loc_move_ask_for_new_file_again:
  4267 00008166 30E4                <1> 	xor	ah, ah
  4268 00008168 E85F89FFFF          <1> 	call	int16h
  4269 0000816D 3C1B                <1> 	cmp	al, 1Bh
  4270                              <1> 	;je	short loc_do_not_move_file
  4271 0000816F 744F                <1> 	je	short loc_move_y_n_escape
  4272 00008171 24DF                <1> 	and	al, 0DFh
  4273 00008173 A2[9BE20000]        <1>         mov     [Y_N_nextline], al
  4274 00008178 3C59                <1> 	cmp	al, 'Y'
  4275 0000817A 7404                <1> 	je	short loc_yes_move_file
  4276 0000817C 3C4E                <1> 	cmp	al, 'N'
  4277 0000817E 75E6                <1> 	jne	short loc_move_ask_for_new_file_again
  4278                              <1> 
  4279                              <1> loc_do_not_move_file:
  4280                              <1> loc_yes_move_file:
  4281 00008180 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  4282 00008185 6650                <1> 	push	ax
  4283 00008187 BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  4284 0000818C E8C5D3FFFF          <1> 	call	print_msg
  4285 00008191 6658                <1> 	pop	ax
  4286 00008193 5F                  <1> 	pop	edi ; *
  4287                              <1> 	;cmp	al, 'Y' ; 'yes'
  4288                              <1> 	;cmc
  4289                              <1>         ;jnc	loc_file_rw_restore_retn
  4290 00008194 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4291 00008196 0F847EF4FFFF        <1>         je	loc_file_rw_restore_retn
  4292                              <1> 
  4293                              <1> loc_move_yes_move_file:
  4294 0000819C B002                <1> 	mov	al, 2 ; move procedure Phase 2
  4295 0000819E E8201B0000          <1> 	call	move_source_file_to_destination_file
  4296                              <1> 	;jc	short loc_move_cmd_failed_2
  4297 000081A3 0F83A5F5FFFF        <1>         jnc     move_source_file_to_destination_OK
  4298                              <1> 
  4299                              <1> ;move_source_file_to_destination_OK:
  4300                              <1> ;	mov	esi, Msg_OK
  4301                              <1> ;	call	print_msg
  4302                              <1> ;	jmp	loc_file_rw_restore_retn
  4303                              <1> 
  4304                              <1> loc_move_cmd_failed_2:
  4305 000081A9 3C27                <1> 	cmp	al, 27h
  4306 000081AB 0F856AEBFFFF        <1> 	jne	loc_run_cmd_failed
  4307                              <1> 
  4308 000081B1 BE[A6E30000]        <1> 	mov	esi, msg_insufficient_disk_space
  4309 000081B6 E89BD3FFFF          <1> 	call	print_msg
  4310                              <1> 
  4311 000081BB E95AF4FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4312                              <1> 
  4313                              <1> loc_move_y_n_escape:
  4314 000081C0 B04E                <1> 	mov	al, 'N' ; 'no'
  4315 000081C2 EBBC                <1> 	jmp	short loc_do_not_move_file
  4316                              <1> 
  4317                              <1> copy_file:
  4318                              <1> 	; 24/03/2016
  4319                              <1> 	; 21/03/2016
  4320                              <1> 	; 15/03/2016 (TRDOS 386 =  TRDOS v2.0)
  4321                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_copy')
  4322                              <1> 	; 01/08/2010
  4323                              <1> 
  4324                              <1> get_copy_source_fchar:
  4325                              <1> 	; esi = file name
  4326 000081C4 803E20              <1> 	cmp	byte [esi], 20h
  4327 000081C7 7614                <1>         jna     short loc_copy_nofilename_retn
  4328                              <1> 
  4329 000081C9 8935[6C2B0100]      <1> 	mov	[SourceFilePath], esi
  4330                              <1> 
  4331                              <1> copy_scan_source_file:
  4332 000081CF 46                  <1> 	inc	esi  
  4333 000081D0 803E20              <1> 	cmp	byte [esi], 20h
  4334 000081D3 7409                <1> 	je	short copy_scan_destination_1
  4335                              <1> 	;jb	short loc_copy_nofilename_retn
  4336 000081D5 0F8215EBFFFF        <1> 	jb	loc_cmd_failed
  4337 000081DB EBF2                <1> 	jmp	short copy_scan_source_file
  4338                              <1> 
  4339                              <1> loc_copy_nofilename_retn:
  4340 000081DD C3                  <1> 	retn
  4341                              <1> 
  4342                              <1> copy_scan_destination_1:
  4343 000081DE C60600              <1> 	mov	byte [esi], 0
  4344                              <1> 
  4345                              <1> copy_scan_destination_2:
  4346 000081E1 46                  <1> 	inc	esi  
  4347 000081E2 803E20              <1> 	cmp	byte [esi], 20h
  4348 000081E5 74FA                <1> 	je	short copy_scan_destination_2
  4349                              <1> 	;jb	short loc_copy_nofilename_retn
  4350 000081E7 0F8203EBFFFF        <1> 	jb	loc_cmd_failed
  4351                              <1> 
  4352 000081ED 8935[702B0100]      <1> 	mov	[DestinationFilePath], esi
  4353                              <1> 
  4354                              <1> copy_scan_destination_3:
  4355 000081F3 46                  <1> 	inc	esi  
  4356 000081F4 803E20              <1> 	cmp	byte [esi], 20h
  4357 000081F7 77FA                <1> 	ja	short copy_scan_destination_3
  4358 000081F9 C60600              <1> 	mov	byte [esi], 0
  4359                              <1> 
  4360                              <1> loc_copy_save_current_drive:
  4361 000081FC 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  4362 00008202 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  4363                              <1> 
  4364                              <1> copy_source_file_to_destination_phase_1:
  4365 00008208 8B35[6C2B0100]      <1> 	mov	esi, [SourceFilePath]
  4366 0000820E 8B3D[702B0100]      <1> 	mov	edi, [DestinationFilePath]
  4367                              <1> 
  4368 00008214 B001                <1> 	mov	al, 1  ; copy procedure Phase 1
  4369 00008216 E8331D0000          <1> 	call	copy_source_file_to_destination_file
  4370 0000821B 732B                <1> 	jnc	short copy_source_file_to_destination_question
  4371                              <1> 
  4372                              <1> loc_copy_cmd_failed_1:
  4373                              <1> 	; 18/03/2016 (restore current drive and directory)
  4374 0000821D 08C0                <1> 	or	al, al
  4375 0000821F 7507                <1> 	jnz	short loc_copy_cmd_failed_2
  4376                              <1> 
  4377 00008221 FEC0                <1>         inc     al ; mov al, 1 ; Bad command or file name !
  4378 00008223 E9F3EAFFFF          <1> 	jmp	loc_run_cmd_failed
  4379                              <1> 
  4380                              <1> loc_copy_cmd_failed_2:
  4381 00008228 3C27                <1> 	cmp	al, 27h ; Insufficient disk space 
  4382 0000822A 740D                <1> 	je	short loc_file_write_insuff_disk_space_msg
  4383                              <1>  
  4384 0000822C 3C05                <1> 	cmp	al, 05h
  4385 0000822E 0F85E7EAFFFF        <1> 	jne	loc_run_cmd_failed
  4386                              <1> 	
  4387 00008234 E9EBF3FFFF          <1> 	jmp	loc_permission_denied
  4388                              <1> 
  4389                              <1> loc_file_write_insuff_disk_space_msg:
  4390 00008239 BE[A6E30000]        <1> 	mov	esi, msg_insufficient_disk_space
  4391 0000823E E813D3FFFF          <1> 	call	print_msg
  4392 00008243 E9D2F3FFFF          <1>         jmp     loc_file_rw_restore_retn 
  4393                              <1> 
  4394                              <1> copy_source_file_to_destination_question:
  4395 00008248 57                  <1> 	push	edi ; *
  4396                              <1> 
  4397                              <1> 	; dh = source file attributes
  4398                              <1> 	; dl > 0 -> destination file found
  4399 00008249 20D2                <1> 	and	dl, dl            
  4400 0000824B 7449                <1> 	jz	short copy_source_file_to_destination_pass_owrq
  4401                              <1> 
  4402                              <1> loc_copy_ask_for_owr_yes_no:
  4403 0000824D BE[02E40000]        <1> 	mov	esi, Msg_DoYouWantOverWriteFile
  4404 00008252 E8FFD2FFFF          <1> 	call	print_msg
  4405 00008257 BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  4406 0000825C E8F5D2FFFF          <1> 	call	print_msg
  4407 00008261 BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  4408 00008266 E8EBD2FFFF          <1> 	call	print_msg
  4409                              <1> 
  4410                              <1> loc_copy_ask_for_owr_again:
  4411 0000826B 30E4                <1> 	xor	ah, ah
  4412 0000826D E85A88FFFF          <1> 	call	int16h
  4413 00008272 3C1B                <1> 	cmp	al, 1Bh
  4414                              <1>         ;je     loc_do_not_copy_file
  4415 00008274 7419                <1>         je      short loc_copy_y_n_escape
  4416 00008276 24DF                <1> 	and	al, 0DFh
  4417 00008278 A2[9BE20000]        <1>         mov     [Y_N_nextline], al
  4418 0000827D 3C59                <1> 	cmp	al, 'Y'
  4419 0000827F 0F84B1000000        <1>         je      loc_yes_copy_file
  4420 00008285 3C4E                <1> 	cmp	al, 'N'
  4421 00008287 0F84A9000000        <1>         je      loc_do_not_copy_file
  4422 0000828D EBDC                <1> 	jmp	short loc_copy_ask_for_owr_again
  4423                              <1> 
  4424                              <1> loc_copy_y_n_escape:
  4425 0000828F B04E                <1> 	mov	al, 'N' ; 'no'
  4426 00008291 E9A0000000          <1>         jmp     loc_do_not_copy_file
  4427                              <1> 
  4428                              <1> copy_source_file_to_destination_pass_owrq:
  4429 00008296 A0[742B0100]        <1> 	mov     al, [SourceFile_Drv]
  4430 0000829B 0441                <1> 	add	al, 'A'
  4431 0000829D A2[DDE30000]        <1> 	mov	[msg_source_file_drv], al
  4432 000082A2 A0[F42B0100]        <1>         mov     al, [DestinationFile_Drv]
  4433 000082A7 0441                <1> 	add	al, 'A'
  4434 000082A9 A2[FCE30000]        <1> 	mov	[msg_destination_file_drv], al
  4435                              <1> 
  4436 000082AE BE[C1E30000]        <1> 	mov	esi, msg_source_file
  4437 000082B3 E89ED2FFFF          <1> 	call	print_msg
  4438 000082B8 BE[752B0100]        <1> 	mov	esi, SourceFile_Directory
  4439 000082BD 803E20              <1> 	cmp	byte [esi], 20h
  4440 000082C0 7605                <1> 	jna	short csftdfq_sfn
  4441 000082C2 E88FD2FFFF          <1> 	call	print_msg
  4442                              <1> csftdfq_sfn:
  4443 000082C7 BE[B62B0100]        <1> 	mov	esi, SourceFile_Name
  4444 000082CC E885D2FFFF          <1> 	call	print_msg
  4445 000082D1 BE[E0E30000]        <1> 	mov	esi, msg_destination_file
  4446 000082D6 E87BD2FFFF          <1> 	call	print_msg
  4447 000082DB BE[F52B0100]        <1> 	mov	esi, DestinationFile_Directory
  4448 000082E0 803E20              <1> 	cmp	byte [esi], 20h
  4449 000082E3 7605                <1> 	jna	short csftdfq_dfn
  4450 000082E5 E86CD2FFFF          <1> 	call	print_msg
  4451                              <1> csftdfq_dfn:
  4452 000082EA BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  4453 000082EF E862D2FFFF          <1> 	call	print_msg
  4454 000082F4 BE[FFE30000]        <1> 	mov	esi, msg_copy_nextline
  4455 000082F9 E858D2FFFF          <1> 	call	print_msg
  4456 000082FE BE[FFE30000]        <1> 	mov	esi, msg_copy_nextline
  4457 00008303 E84ED2FFFF          <1> 	call	print_msg
  4458                              <1> 
  4459                              <1> loc_copy_ask_for_new_file_yes_no:
  4460 00008308 BE[21E40000]        <1> 	mov	esi, Msg_DoYouWantCopyFile
  4461 0000830D E844D2FFFF          <1> 	call	print_msg
  4462 00008312 BE[91E20000]        <1> 	mov	esi, Msg_YesNo
  4463 00008317 E83AD2FFFF          <1> 	call	print_msg
  4464                              <1> 
  4465                              <1> loc_copy_ask_for_new_file_again:
  4466 0000831C 30E4                <1> 	xor	ah, ah
  4467 0000831E E8A987FFFF          <1> 	call	int16h
  4468 00008323 3C1B                <1> 	cmp	al, 1Bh
  4469 00008325 740F                <1> 	je	short loc_do_not_copy_file
  4470 00008327 24DF                <1> 	and	al, 0DFh
  4471 00008329 A2[9BE20000]        <1>         mov     [Y_N_nextline], al
  4472 0000832E 3C59                <1> 	cmp	al, 'Y'
  4473 00008330 7404                <1> 	je	short loc_yes_copy_file
  4474 00008332 3C4E                <1> 	cmp	al, 'N'
  4475 00008334 75E6                <1> 	jne	short loc_copy_ask_for_new_file_again
  4476                              <1> 
  4477                              <1> loc_do_not_copy_file:
  4478                              <1> loc_yes_copy_file:
  4479 00008336 A2[9BE20000]        <1> 	mov	[Y_N_nextline], al
  4480 0000833B 6650                <1> 	push	ax
  4481 0000833D BE[9BE20000]        <1> 	mov	esi, Y_N_nextline
  4482 00008342 E80FD2FFFF          <1> 	call	print_msg
  4483 00008347 6658                <1> 	pop	ax
  4484 00008349 5F                  <1> 	pop	edi ; *
  4485                              <1> 	;cmp	al, 'Y' ; 'yes'
  4486                              <1> 	;cmc
  4487                              <1>         ;jnc	loc_file_rw_restore_retn
  4488 0000834A 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4489 0000834C 0F84C8F2FFFF        <1>         je	loc_file_rw_restore_retn
  4490                              <1> 
  4491                              <1> copy_source_file_to_destination_pass_q:
  4492 00008352 B002                <1> 	mov	al, 2  ; copy procedure Phase 2
  4493 00008354 E8F51B0000          <1> 	call	copy_source_file_to_destination_file
  4494                              <1> 	;jc	short loc_file_write_check_disk_space_err
  4495                              <1> 
  4496                              <1> 	; 24/03/2016
  4497 00008359 6651                <1> 	push	cx
  4498 0000835B BE[FFE30000]        <1> 	mov	esi, msg_copy_nextline
  4499 00008360 E8F1D1FFFF          <1> 	call	print_msg
  4500                              <1> 	;pop	cx
  4501 00008365 6658                <1> 	pop	ax
  4502                              <1> 
  4503                              <1> 	;or	cl, cl
  4504 00008367 08C0                <1> 	or	al, al
  4505 00008369 7419                <1> 	jz	short copy_source_file_to_destination_OK
  4506                              <1> 	
  4507                              <1> 	; 18/03/2016
  4508                              <1> 	;cmp	cl, 1Dh ; write error
  4509 0000836B 3C1D                <1> 	cmp	al, 1Dh
  4510 0000836D 7506                <1> 	jne	short copy_source_file_to_destination_not_OK
  4511                              <1> 	;
  4512                              <1> 	;mov	al, cl ; error number (write fault!)
  4513 0000836F F9                  <1> 	stc
  4514 00008370 E9A5F2FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4515                              <1> 
  4516                              <1> copy_source_file_to_destination_not_OK:
  4517 00008375 BE[3AE40000]        <1> 	mov	esi, Msg_read_file_error_before_EOF
  4518 0000837A E8D7D1FFFF          <1> 	call	print_msg
  4519 0000837F E996F2FFFF          <1> 	jmp	loc_file_rw_restore_retn	      
  4520                              <1>  
  4521                              <1> copy_source_file_to_destination_OK:
  4522 00008384 BE[9FE20000]        <1> 	mov	esi, Msg_OK
  4523 00008389 E8C8D1FFFF          <1> 	call	print_msg
  4524                              <1> 
  4525 0000838E E987F2FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4526                              <1> 
  4527                              <1> ;loc_file_write_check_disk_space_err:
  4528                              <1> 	;cmp	al, 27h ; Insufficient disk space 
  4529                              <1> 	;je	loc_file_write_insuff_disk_space_msg
  4530                              <1>         ;jb	loc_file_rw_cmd_failed
  4531                              <1> 
  4532                              <1> 	;call	print_misc_error_msg ; 15/03/2016
  4533                              <1>         ;jmp	loc_file_rw_restore_retn 
  4534                              <1> 
  4535                              <1> change_fs_file_attributes:
  4536                              <1> 	; 04/03/2016 ; Temporary
  4537                              <1> 	; AL = File or directory attributes
  4538                              <1> 	; AH = 0 -> Attributes are in MS-DOS format
  4539                              <1> 	; AH > 0 -> Attributes are in SINGLIX format
  4540                              <1> 	;push	ebx
  4541                              <1> 	; ... do somethings here ...
  4542                              <1> 	;pop	ebx
  4543                              <1> 	; BL = File or directory attributes
  4544 00008393 C3                  <1> 	retn
  4545                              <1> 
  4546                              <1> set_get_env:
  4547                              <1> 	; 11/04/2016 (TRDOS 386 =  TRDOS v2.0)
  4548                              <1> 	; 02/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_set')
  4549                              <1> 	; 2005 - 28/08/2011 
  4550                              <1> get_setenv_fchar:
  4551                              <1> 	; esi = environment variable/string
  4552 00008394 8A06                <1> 	mov	al, [esi]
  4553 00008396 3C20                <1> 	cmp	al, 20h
  4554 00008398 771E                <1> 	ja	short loc_find_env
  4555                              <1> 
  4556 0000839A BE00300900          <1> 	mov	esi, Env_Page
  4557                              <1> loc_print_setline:
  4558 0000839F 803E00              <1> 	cmp	byte [esi], 0
  4559 000083A2 7613                <1> 	jna	short loc_setenv_retn
  4560 000083A4 E8ADD1FFFF          <1> 	call	print_msg
  4561 000083A9 56                  <1> 	push	esi
  4562 000083AA BE[ABEE0000]        <1> 	mov	esi, nextline
  4563 000083AF E8A2D1FFFF          <1> 	call	print_msg 
  4564 000083B4 5E                  <1> 	pop	esi
  4565 000083B5 EBE8                <1> 	jmp	short loc_print_setline   
  4566                              <1> 
  4567                              <1> loc_setenv_retn: 
  4568 000083B7 C3                  <1> 	retn
  4569                              <1> 
  4570                              <1> loc_find_env:
  4571 000083B8 3C3D                <1> 	cmp	al, '='
  4572 000083BA 0F8430E9FFFF        <1> 	je	loc_cmd_failed
  4573                              <1> 
  4574 000083C0 56                  <1> 	push	esi
  4575                              <1> loc_repeat_env_equal_check:
  4576 000083C1 46                  <1> 	inc	esi
  4577 000083C2 803E3D              <1> 	cmp	byte [esi], '='
  4578 000083C5 7431                <1> 	je	short pass_env_equal_check
  4579 000083C7 803E20              <1> 	cmp	byte [esi], 20h
  4580 000083CA 73F5                <1> 	jnb	short loc_repeat_env_equal_check
  4581 000083CC C60600              <1> 	mov	byte [esi], 0 
  4582 000083CF 5E                  <1> 	pop	esi
  4583 000083D0 BF[8E210100]        <1> 	mov	edi, TextBuffer ; out buffer
  4584 000083D5 B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
  4585 000083DA 30C0                <1> 	xor	al, al ; 0 -> use [ESI]
  4586 000083DC E89E000000          <1> 	call	get_environment_string
  4587 000083E1 72D4                <1> 	jc	short loc_setenv_retn
  4588                              <1> 
  4589 000083E3 BE[8E210100]        <1> 	mov	esi, TextBuffer
  4590 000083E8 E869D1FFFF          <1> 	call	print_msg
  4591 000083ED BE[ABEE0000]        <1> 	mov	esi, nextline
  4592 000083F2 E85FD1FFFF          <1> 	call	print_msg
  4593                              <1> 
  4594 000083F7 C3                  <1> 	retn 
  4595                              <1>               
  4596                              <1> pass_env_equal_check:
  4597 000083F8 46                  <1> 	inc	esi
  4598 000083F9 803E20              <1> 	cmp	byte [esi], 20h
  4599 000083FC 73FA                <1> 	jnb	short pass_env_equal_check
  4600 000083FE C60600              <1> 	mov	byte [esi], 0	
  4601                              <1> 
  4602                              <1> loc_call_set_env_string:
  4603 00008401 5E                  <1> 	pop	esi
  4604 00008402 E83B010000          <1> 	call	set_environment_string
  4605 00008407 73AE                <1> 	jnc	short loc_setenv_retn
  4606                              <1> 
  4607                              <1> loc_set_cmd_failed:
  4608 00008409 3C08                <1> 	cmp	al, 08h
  4609 0000840B 0F85DFE8FFFF        <1> 	jne	loc_cmd_failed
  4610                              <1> 
  4611 00008411 BE[7AE40000]        <1> 	mov	esi, Msg_No_Set_Space
  4612 00008416 E83BD1FFFF          <1> 	call	print_msg
  4613                              <1> 
  4614 0000841B C3                  <1> 	retn
  4615                              <1> 
  4616                              <1> set_get_path:
  4617                              <1> 	; 11/04/2016 (TRDOS 386 =  TRDOS v2.0)
  4618                              <1> 	; 03/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_path')
  4619                              <1> 	; 2005
  4620                              <1> get_path_fchar:
  4621                              <1>  	; esi = path
  4622 0000841C 803E20              <1> 	cmp	byte [esi], 20h
  4623 0000841F 7737                <1> 	ja	short loc_set_path
  4624                              <1> 
  4625 00008421 BE00300900          <1> 	mov	esi, Env_Page
  4626                              <1> loc_print_path:
  4627 00008426 803E00              <1> 	cmp	byte [esi], 0
  4628 00008429 762C                <1> 	jna	short loc_path_retn
  4629                              <1> 
  4630 0000842B BE[D4DE0000]        <1> 	mov	esi, Cmd_Path ; 'PATH' address
  4631 00008430 BF[8E210100]        <1> 	mov	edi, TextBuffer ; oout buffer
  4632 00008435 30C0                <1> 	xor	al, al  ; use [ESI]
  4633 00008437 B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
  4634 0000843C E83E000000          <1> 	call	get_environment_string
  4635 00008441 7214                <1> 	jc	short loc_path_retn
  4636                              <1> 
  4637 00008443 BE[8E210100]        <1> 	mov	esi, TextBuffer
  4638 00008448 E809D1FFFF          <1> 	call	print_msg
  4639 0000844D BE[ABEE0000]        <1> 	mov	esi, nextline
  4640 00008452 E8FFD0FFFF          <1> 	call	print_msg   
  4641                              <1> 
  4642                              <1> loc_path_retn: 
  4643 00008457 C3                  <1> 	retn
  4644                              <1> 
  4645                              <1> loc_set_path:
  4646 00008458 56                  <1> 	push	esi 
  4647                              <1> loc_set_path_find_end:
  4648 00008459 46                  <1> 	inc	esi
  4649 0000845A 803E20              <1> 	cmp	byte [esi], 20h
  4650 0000845D 73FA                <1> 	jnb	short loc_set_path_find_end
  4651 0000845F C60600              <1> 	mov	byte [esi], 0 
  4652                              <1> loc_set_path_header: 
  4653 00008462 5E                  <1> 	pop	esi	  
  4654 00008463 4E                  <1> 	dec	esi
  4655 00008464 C6063D              <1> 	mov	byte [esi], '='
  4656 00008467 4E                  <1> 	dec	esi
  4657 00008468 C60648              <1> 	mov	byte [esi], 'H'
  4658 0000846B 4E                  <1> 	dec	esi
  4659 0000846C C60654              <1> 	mov	byte [esi], 'T'
  4660 0000846F 4E                  <1> 	dec	esi
  4661 00008470 C60641              <1> 	mov	byte [esi], 'A'
  4662 00008473 4E                  <1> 	dec	esi
  4663 00008474 C60650              <1> 	mov	byte [esi], 'P'   
  4664                              <1> 
  4665                              <1> loc_path_call_set_env_string:
  4666 00008477 E8C6000000          <1> 	call	set_environment_string
  4667 0000847C 728B                <1>         jc	short loc_set_cmd_failed
  4668                              <1> 
  4669 0000847E C3                  <1> 	retn              
  4670                              <1> 
  4671                              <1> get_environment_string:
  4672                              <1> 	; 12/04/2016
  4673                              <1> 	; 11/04/2016
  4674                              <1> 	; 05/04/2016 (TRDOS 386 =  TRDOS v2.0)
  4675                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  4676                              <1> 	; 28/08/2011
  4677                              <1> 	; INPUT->
  4678                              <1> 	;	EDI = Output buffer
  4679                              <1> 	;	CX = Buffer length (<= ENV_PAGE_SIZE)
  4680                              <1> 	;
  4681                              <1> 	;	AL > 0 = AL = String sequence number
  4682                              <1> 	;	AL = 0 -> ESI = ASCIIZ Set word 
  4683                              <1> 	;		(environment variable)
  4684                              <1> 	; OUTPUT ->
  4685                              <1> 	;	ESI is not changed
  4686                              <1> 	;	EDI is not changed
  4687                              <1> 	;	EAX = String length (with zero tail)
  4688                              <1> 	;	EDX = Environment variables page address
  4689                              <1> 	;	CF = 1 -> Not found (EAX not valid)
  4690                              <1> 	;
  4691                              <1> 	; (Modified registers: EAX, EDX) 
  4692                              <1> 
  4693 0000847F BA00300900          <1> 	mov	edx, Env_Page
  4694 00008484 803A00              <1> 	cmp	byte [edx], 0
  4695 00008487 7474                <1> 	jz	short get_env_string_with_word_stc_retn
  4696                              <1> 
  4697 00008489 66890D[F82C0100]    <1> 	mov	[env_var_length], cx
  4698                              <1> 
  4699 00008490 51                  <1> 	push	ecx ; *
  4700 00008491 56                  <1> 	push	esi ; **
  4701                              <1> 
  4702 00008492 08C0                <1> 	or	al, al
  4703 00008494 7449                <1> 	jz	short get_env_string_with_word
  4704                              <1> 
  4705                              <1> get_env_string_with_seq_number:
  4706 00008496 B101                <1> 	mov	cl, 1
  4707 00008498 88C5                <1> 	mov	ch, al
  4708 0000849A 31C0                <1> 	xor	eax, eax
  4709 0000849C 89D6                <1> 	mov	esi, edx ; Env_Page
  4710                              <1> 
  4711                              <1> get_env_string_seq_number_check:
  4712 0000849E 38CD                <1> 	cmp	ch, cl
  4713 000084A0 7726                <1> 	ja	short get_env_string_seq_number_next
  4714                              <1> 
  4715                              <1> get_env_string_move_to_buff:
  4716 000084A2 57                  <1> 	push	edi ; ***
  4717                              <1> 
  4718 000084A3 29D2                <1> 	sub	edx, edx
  4719                              <1> 
  4720                              <1> get_env_string_seq_number_repeat1:
  4721 000084A5 42                  <1> 	inc	edx
  4722 000084A6 AC                  <1> 	lodsb
  4723 000084A7 AA                  <1> 	stosb
  4724                              <1> 
  4725 000084A8 66FF0D[F82C0100]    <1> 	dec	word [env_var_length]
  4726 000084AF 7508                <1> 	jnz	short get_env_string_seq_number_repeat3
  4727                              <1> 
  4728                              <1> get_env_string_seq_number_repeat2:
  4729 000084B1 20C0                <1> 	and	al, al
  4730 000084B3 7408                <1> 	jz	short get_env_string_seq_number_ok
  4731 000084B5 42                  <1> 	inc	edx
  4732 000084B6 AC                  <1> 	lodsb
  4733 000084B7 EBF8                <1> 	jmp	short get_env_string_seq_number_repeat2
  4734                              <1> 
  4735                              <1> get_env_string_seq_number_repeat3:
  4736 000084B9 08C0                <1> 	or	al, al
  4737 000084BB 75E8                <1> 	jnz	short get_env_string_seq_number_repeat1
  4738                              <1> 
  4739                              <1> get_env_string_seq_number_ok:
  4740 000084BD 5F                  <1> 	pop	edi ; ***
  4741 000084BE 89D0                <1> 	mov	eax, edx ; Length of the environment string
  4742                              <1> 			 ; (ASCIIZ, includes ZERO tail)
  4743 000084C0 BA00300900          <1> 	mov	edx, Env_Page
  4744                              <1> 
  4745                              <1> get_env_string_stc_retn:
  4746 000084C5 5E                  <1> 	pop	esi ; **
  4747 000084C6 59                  <1> 	pop	ecx ; *
  4748 000084C7 C3                  <1> 	retn   
  4749                              <1> 	
  4750                              <1> get_env_string_seq_number_next:
  4751 000084C8 AC                  <1> 	lodsb
  4752 000084C9 08C0                <1> 	or	al, al
  4753 000084CB 75FB                <1> 	jnz	short get_env_string_seq_number_next
  4754                              <1> 
  4755 000084CD 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; +512 (+4096)
  4756 000084D3 F5                  <1> 	cmc
  4757 000084D4 72EF                <1> 	jc	short get_env_string_stc_retn
  4758                              <1> 
  4759 000084D6 AC                  <1> 	lodsb
  4760 000084D7 3C01                <1> 	cmp	al, 1
  4761 000084D9 72EA                <1> 	jb	short get_env_string_stc_retn
  4762 000084DB FEC1                <1> 	inc	cl
  4763 000084DD EBBF                <1> 	jmp	short get_env_string_seq_number_check
  4764                              <1> 
  4765                              <1> get_env_string_with_word:
  4766 000084DF 31C9                <1> 	xor	ecx, ecx
  4767                              <1> 
  4768                              <1> get_env_string_calc_word_length:
  4769 000084E1 AC                  <1> 	lodsb 
  4770 000084E2 3C20                <1> 	cmp	al, 20h
  4771 000084E4 7211                <1> 	jb	short get_env_string_calc_word_length_ok
  4772                              <1> 	;inc	cx
  4773 000084E6 FEC1                <1> 	inc	cl
  4774                              <1> 
  4775 000084E8 3C61                <1> 	cmp	al, 'a'
  4776 000084EA 72F5                <1> 	jb	short get_env_string_calc_word_length
  4777 000084EC 3C7A                <1> 	cmp	al, 'z'
  4778 000084EE 77F1                <1> 	ja	short get_env_string_calc_word_length
  4779 000084F0 24DF                <1> 	and	al, 0DFh
  4780 000084F2 8846FF              <1> 	mov	[esi-1], al
  4781 000084F5 EBEA                <1> 	jmp	short get_env_string_calc_word_length
  4782                              <1> 	
  4783                              <1> get_env_string_calc_word_length_ok:
  4784 000084F7 08C9                <1> 	or	cl, cl
  4785 000084F9 7506                <1> 	jnz	short get_env_string_calc_word_length_save
  4786                              <1>      
  4787 000084FB 5E                  <1> 	pop	esi ; **
  4788                              <1> 
  4789                              <1> get_env_string_stc_retn1:
  4790 000084FC 59                  <1> 	pop	ecx ; *
  4791                              <1>         
  4792                              <1> get_env_string_with_word_stc_retn:
  4793 000084FD 31C0                <1> 	xor	eax, eax  
  4794 000084FF F9                  <1> 	stc
  4795 00008500 C3                  <1> 	retn
  4796                              <1>   
  4797                              <1> get_env_string_calc_word_length_save:
  4798 00008501 871C24              <1> 	xchg	ebx, [esp] ; **
  4799 00008504 89DE                <1> 	mov	esi, ebx 
  4800                              <1> 		; Start of the env string (to be searched)
  4801                              <1> 
  4802 00008506 57                  <1> 	push	edi ; ***
  4803 00008507 89D7                <1> 	mov	edi, edx ; Env_Page
  4804                              <1> 
  4805                              <1> get_env_string_compare:
  4806 00008509 57                  <1> 	push	edi ; ****
  4807 0000850A 51                  <1> 	push	ecx ; ***** ; Variable name length
  4808                              <1> 
  4809                              <1> get_env_string_compare_rep:
  4810 0000850B AC                  <1> 	lodsb
  4811 0000850C AE                  <1> 	scasb
  4812 0000850D 7511                <1> 	jne	short get_env_string_compare_next1
  4813 0000850F E2FA                <1> 	loop	get_env_string_compare_rep
  4814                              <1> 	
  4815 00008511 803F3D              <1> 	cmp	byte [edi], '='
  4816 00008514 750A                <1> 	jne	short get_env_string_compare_next1
  4817                              <1>  
  4818 00008516 59                  <1> 	pop	ecx ; *****
  4819 00008517 5F                  <1> 	pop	edi ; ****
  4820 00008518 89FE                <1> 	mov	esi, edi
  4821 0000851A 5F                  <1> 	pop	edi ; ***
  4822 0000851B 871C24              <1> 	xchg	ebx, [esp] ; **
  4823 0000851E EB82                <1> 	jmp	short get_env_string_move_to_buff
  4824                              <1> 
  4825                              <1> get_env_string_compare_next1:
  4826 00008520 89FE                <1> 	mov	esi, edi
  4827 00008522 59                  <1> 	pop	ecx ; *****
  4828 00008523 5F                  <1> 	pop	edi ; ****
  4829                              <1> get_env_string_compare_next2:
  4830 00008524 81FEFF310900        <1> 	cmp	esi, Env_Page + Env_Page_Size - 1 ; +511 (+4095)
  4831 0000852A 7310                <1> 	jnb	short get_env_string_compare_not_ok
  4832 0000852C 20C0                <1> 	and	al, al
  4833 0000852E AC                  <1> 	lodsb
  4834 0000852F 75F3                <1> 	jnz	short get_env_string_compare_next2
  4835 00008531 08C0                <1> 	or	al, al
  4836 00008533 7407                <1> 	jz	short get_env_string_compare_not_ok
  4837 00008535 4E                  <1> 	dec	esi ; 12/04/2016
  4838 00008536 89F7                <1> 	mov	edi, esi
  4839 00008538 89DE                <1> 	mov	esi, ebx
  4840 0000853A EBCD                <1> 	jmp	short get_env_string_compare
  4841                              <1> 
  4842                              <1> get_env_string_compare_not_ok:
  4843 0000853C 5F                  <1> 	pop	edi ; ***
  4844 0000853D 89DE                <1> 	mov	esi, ebx
  4845 0000853F 5B                  <1> 	pop	ebx ; **
  4846 00008540 EBBA                <1> 	jmp	short get_env_string_stc_retn1
  4847                              <1> 
  4848                              <1> set_environment_string:
  4849                              <1> 	; 13/04/2016
  4850                              <1> 	; 12/04/2016
  4851                              <1> 	; 11/04/2016
  4852                              <1> 	; 06/04/2016
  4853                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
  4854                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  4855                              <1> 	; 29/08/2011
  4856                              <1> 	; 29/08/2011
  4857                              <1> 	; INPUT->
  4858                              <1> 	;	ESI = ASCIIZ environment string
  4859                              <1> 	; OUTPUT ->
  4860                              <1> 	;	ESI is not changed
  4861                              <1> 	;	CF = 1 -> Could not set, 
  4862                              <1> 	;	     insufficient environment space
  4863                              <1> 	;
  4864                              <1> 	; (EAX, EDX will be changed) 
  4865                              <1> 	;
  4866                              <1> 	;    (EAX = Start address of the env string if > 0)	
  4867                              <1> 	;    (EDX = Environment string length)	
  4868                              <1> 
  4869 00008542 56                  <1> 	push 	esi ; *
  4870                              <1> 
  4871 00008543 31C0                <1> 	xor	eax, eax
  4872                              <1> 
  4873                              <1> set_env_chk_validation1:
  4874 00008545 FEC4                <1> 	inc	ah ; variable (string) length
  4875 00008547 AC                  <1> 	lodsb
  4876 00008548 3C3D                <1> 	cmp	al, '='
  4877 0000854A 7415                <1> 	je	short set_env_chk_validation2
  4878 0000854C 3C20                <1> 	cmp	al, 20h
  4879 0000854E 720F                <1> 	jb	short set_env_string_stc
  4880                              <1> 
  4881                              <1> 	; 06/04/2016
  4882 00008550 3C61                <1> 	cmp	al, 'a'
  4883 00008552 72F1                <1> 	jb	short set_env_chk_validation1
  4884 00008554 3C7A                <1> 	cmp	al, 'z'
  4885 00008556 77ED                <1> 	ja	short set_env_chk_validation1
  4886 00008558 2C20                <1> 	sub	al, 'a'-'A'
  4887 0000855A 8846FF              <1> 	mov	[esi-1], al
  4888 0000855D EBE6                <1> 	jmp	short set_env_chk_validation1
  4889                              <1> 
  4890                              <1> set_env_string_stc:
  4891 0000855F 5E                  <1> 	pop	esi ; *
  4892                              <1> 	;stc
  4893 00008560 C3                  <1> 	retn 
  4894                              <1> 	   
  4895                              <1> set_env_chk_validation2:
  4896 00008561 51                  <1> 	push	ecx ; **
  4897 00008562 53                  <1> 	push	ebx ; *** 
  4898 00008563 57                  <1> 	push	edi ; ****
  4899                              <1> 
  4900                              <1> 	; 12/04/2016
  4901 00008564 8B5C240C            <1> 	mov	ebx, [esp+12]
  4902                              <1> 
  4903                              <1> set_env_chk_validation2w:
  4904 00008568 89F7                <1> 	mov	edi, esi
  4905 0000856A 4F                  <1> 	dec	edi
  4906                              <1> 
  4907 0000856B 807FFF20            <1> 	cmp	byte [edi-1], 20h
  4908 0000856F 771A                <1> 	ja	short set_env_chk_validation2z
  4909                              <1> 	
  4910 00008571 56                  <1> 	push	esi
  4911 00008572 89FE                <1> 	mov	esi, edi
  4912 00008574 4E                  <1> 	dec	esi
  4913                              <1> 
  4914                              <1> set_env_chk_validation2x:
  4915 00008575 4E                  <1> 	dec	esi
  4916                              <1> 
  4917 00008576 39DE                <1> 	cmp	esi, ebx
  4918 00008578 7207                <1> 	jb	short set_env_chk_validation2y
  4919                              <1> 
  4920 0000857A 4F                  <1> 	dec	edi
  4921                              <1> 
  4922 0000857B 8A06                <1> 	mov	al, [esi]
  4923 0000857D 8807                <1> 	mov	[edi], al
  4924                              <1> 
  4925 0000857F EBF4                <1> 	jmp	short set_env_chk_validation2x
  4926                              <1> 
  4927                              <1> set_env_chk_validation2y:
  4928 00008581 5E                  <1> 	pop	esi
  4929                              <1> 
  4930                              <1> 	;mov	byte [ebx], 20h
  4931                              <1> 	
  4932 00008582 43                  <1> 	inc 	ebx
  4933 00008583 895C240C            <1> 	mov	[esp+12], ebx
  4934                              <1> 
  4935 00008587 FECC                <1> 	dec 	ah ; 13/04/2016
  4936                              <1> 
  4937 00008589 EBDD                <1> 	jmp	short set_env_chk_validation2w
  4938                              <1> 	
  4939                              <1> set_env_chk_validation2z:	
  4940 0000858B BA00300900          <1> 	mov	edx, Env_Page
  4941 00008590 89D7                <1> 	mov	edi, edx
  4942                              <1> 
  4943                              <1> set_env_chk_validation3:
  4944 00008592 AC                  <1> 	lodsb
  4945 00008593 3C20                <1> 	cmp	al, 20h
  4946 00008595 74FB                <1> 	je	short set_env_chk_validation3
  4947                              <1> 
  4948 00008597 9C                  <1> 	pushf
  4949                              <1> 
  4950                              <1> 	; 12/04/2016
  4951                              <1> set_env_chk_validation3n:
  4952 00008598 3C61                <1> 	cmp	al, 'a'
  4953 0000859A 720C                <1> 	jb	short set_env_chk_validation3c
  4954 0000859C 3C7A                <1> 	cmp	al, 'z'
  4955 0000859E 7705                <1> 	ja	short set_env_chk_validation3x
  4956 000085A0 2C20                <1> 	sub	al, 'a'-'A'
  4957 000085A2 8846FF              <1> 	mov	[esi-1], al
  4958                              <1> 
  4959                              <1> set_env_chk_validation3x:
  4960 000085A5 AC                  <1> 	lodsb
  4961 000085A6 EBF0                <1> 	jmp	short set_env_chk_validation3n
  4962                              <1> 
  4963                              <1> set_env_chk_validation3c:
  4964 000085A8 3C20                <1> 	cmp	al, 20h
  4965 000085AA 73F9                <1> 	jnb	short set_env_chk_validation3x
  4966                              <1> 		
  4967 000085AC 803F00              <1> 	cmp	byte [edi], 0
  4968 000085AF 7731                <1> 	ja	short set_env_chk_validation4
  4969                              <1> 
  4970 000085B1 9D                  <1> 	popf
  4971 000085B2 7228                <1> 	jb	short set_env_string_nothing
  4972                              <1> 
  4973 000085B4 B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)
  4974                              <1> 
  4975 000085B9 89DE                <1> 	mov	esi, ebx ; 12/04/2016
  4976                              <1> 
  4977                              <1> set_env_string_copy_to_envb:
  4978 000085BB AC                  <1> 	lodsb
  4979 000085BC 3C20                <1> 	cmp	al, 20h
  4980 000085BE 720A                <1> 	jb	short set_env_string_copy_to_envb_z
  4981 000085C0 AA                  <1> 	stosb
  4982 000085C1 E2F8                <1> 	loop	set_env_string_copy_to_envb
  4983                              <1> 
  4984                              <1> 	; 11/04/2016
  4985 000085C3 89D7                <1> 	mov	edi, edx ; Env_Page
  4986 000085C5 B900020000          <1> 	mov	ecx, Env_Page_Size 
  4987                              <1> 
  4988                              <1> set_env_string_copy_to_envb_z:
  4989 000085CA 52                  <1> 	push	edx  ; Start address of the variable
  4990 000085CB BA00020000          <1> 	mov	edx, Env_Page_Size
  4991 000085D0 29CA                <1> 	sub	edx, ecx ; variable (string) length
  4992                              <1> 
  4993 000085D2 28C0                <1> 	sub	al, al ; 0
  4994 000085D4 F3AA                <1>  	rep	stosb ; clear remain bytes of the env page
  4995                              <1> 
  4996 000085D6 58                  <1> 	pop	eax  ; Start address of the variable
  4997                              <1> 
  4998                              <1> set_env_string_allocate_envb_retn:  ; stc or clc return
  4999 000085D7 5F                  <1> 	pop	edi ; ****
  5000 000085D8 5B                  <1> 	pop	ebx ; ***
  5001 000085D9 59                  <1> 	pop	ecx ; **
  5002 000085DA 5E                  <1> 	pop	esi ; *	
  5003 000085DB C3                  <1> 	retn
  5004                              <1> 
  5005                              <1> set_env_string_nothing:
  5006 000085DC 31C0                <1> 	xor	eax, eax
  5007 000085DE 31D2                <1> 	xor	edx, edx ; 11/04/2016
  5008 000085E0 EBF5                <1> 	jmp	short set_env_string_allocate_envb_retn
  5009                              <1> 
  5010                              <1> set_env_chk_validation4:
  5011                              <1> 	; 11/04/2016
  5012 000085E2 9D                  <1> 	popf
  5013                              <1> 
  5014 000085E3 89D6                <1> 	mov	esi, edx  ; Env_Page
  5015                              <1> 
  5016                              <1> set_env_chk_validation5:	
  5017 000085E5 89DF                <1> 	mov	edi, ebx  ; ASCIIZ environment string address	
  5018 000085E7 0FB6CC              <1> 	movzx	ecx, ah ; Variable (string) length (with '=')
  5019                              <1> 
  5020                              <1> set_env_chk_validation5_loop:
  5021 000085EA AC                  <1> 	lodsb
  5022 000085EB AE                  <1> 	scasb
  5023 000085EC 750A                <1> 	jne	short set_env_chk_validation6
  5024 000085EE E2FA                <1> 	loop	set_env_chk_validation5_loop
  5025                              <1> 
  5026 000085F0 3C3D                <1> 	cmp	al, '='
  5027 000085F2 0F8483000000        <1>         je      set_env_change_variable
  5028                              <1> 
  5029                              <1> set_env_chk_validation6:
  5030 000085F8 08C0                <1> 	or	al, al ; 0
  5031 000085FA 7403                <1> 	jz	short set_env_chk_validation7
  5032                              <1> 
  5033 000085FC AC                  <1> 	lodsb
  5034 000085FD EBF9                <1> 	jmp	short set_env_chk_validation6
  5035                              <1> 
  5036                              <1> set_env_chk_validation7:
  5037 000085FF 88E1                <1> 	mov	cl, ah
  5038 00008601 01F1                <1> 	add	ecx, esi
  5039 00008603 81F9FF310900        <1> 	cmp	ecx, Env_Page + Env_Page_Size - 1 
  5040                              <1> 		; 511 (4095) 
  5041                              <1> 		; strlen + '=' + 0
  5042 00008609 72DA                <1> 	jb	short set_env_chk_validation5
  5043                              <1> 
  5044                              <1> set_env_chk_validation8: ; variable not found
  5045 0000860B 0FB6F4              <1> 	movzx	esi, ah  ; variable name length (with '=') 
  5046 0000860E 01DE                <1> 	add	esi, ebx ; position just after of the '='
  5047                              <1> 
  5048                              <1> set_env_chk_validation8_loop:
  5049 00008610 AC                  <1> 	lodsb
  5050 00008611 3C20                <1> 	cmp	al, 20h
  5051 00008613 74FB                <1> 	je	short set_env_chk_validation8_loop	
  5052 00008615 72C5                <1> 	jb	short set_env_string_nothing
  5053                              <1> 
  5054                              <1> set_env_chk_validation9:
  5055 00008617 AC                  <1> 	lodsb
  5056 00008618 3C20                <1> 	cmp	al, 20h
  5057 0000861A 73FB                <1> 	jnb	short set_env_chk_validation9
  5058                              <1> 
  5059                              <1> 	; End of ASCIIZ environment string
  5060                              <1> 
  5061                              <1> set_env_add_variable:
  5062 0000861C 29DE                <1> 	sub	esi, ebx ; variable+definition length
  5063                              <1> 	
  5064 0000861E 56                  <1> 	push	esi ; *****
  5065                              <1> 
  5066 0000861F 89D6                <1> 	mov	esi, edx ; Environment page address
  5067                              <1> 
  5068 00008621 B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)	
  5069                              <1> 
  5070                              <1> set_env_add_variable_loop:
  5071 00008626 AC                  <1> 	lodsb
  5072 00008627 20C0                <1> 	and	al, al		
  5073 00008629 7406                <1> 	jz	short set_env_add_variable_chk1 ; 0
  5074 0000862B E2F9                <1> 	loop	set_env_add_variable_loop
  5075                              <1> 
  5076                              <1> 	; 11/04/2016
  5077 0000862D 884EFF              <1> 	mov	[esi-1], cl ; 0
  5078 00008630 41                  <1> 	inc	ecx
  5079                              <1> 	
  5080                              <1> set_env_add_variable_chk1: 
  5081 00008631 49                  <1> 	dec	ecx
  5082 00008632 7408                <1> 	jz	short set_env_add_variable_nspc
  5083 00008634 AC                  <1> 	lodsb
  5084 00008635 08C0                <1> 	or 	al, al
  5085 00008637 740C                <1> 	jz	short set_env_add_variable_chk2 ; 00
  5086 00008639 49                  <1> 	dec	ecx
  5087 0000863A 75EA                <1> 	jnz	short set_env_add_variable_loop
  5088                              <1> 
  5089                              <1> set_env_add_variable_nspc: ; no space on environment page
  5090 0000863C 58                  <1> 	pop	eax ; *****
  5091 0000863D B808000000          <1> 	mov	eax, 08h ; No space for new environment string
  5092 00008642 F9                  <1> 	stc
  5093 00008643 EB92                <1>         jmp     short set_env_string_allocate_envb_retn
  5094                              <1> 
  5095                              <1> set_env_add_variable_chk2:
  5096 00008645 8B0C24              <1> 	mov	ecx, [esp] ; *****
  5097 00008648 4E                  <1> 	dec	esi ; beginning address of the new variable
  5098 00008649 89F0                <1> 	mov	eax, esi
  5099 0000864B 01C8                <1> 	add	eax, ecx ; string length (with CR)
  5100 0000864D 81C200020000        <1> 	add	edx, Env_Page_Size ; 512 (4096)
  5101 00008653 39D0                <1> 	cmp	eax, edx 
  5102 00008655 77E5                <1> 	ja	short set_env_add_variable_nspc
  5103 00008657 49                  <1> 	dec	ecx ; except CR at the end
  5104 00008658 89CA                <1> 	mov	edx, ecx ; 12/04/2016
  5105 0000865A 89F7                <1> 	mov	edi, esi
  5106 0000865C 893C24              <1> 	mov	[esp], edi ; ***** ; Start address of new variable
  5107 0000865F 89DE                <1> 	mov	esi, ebx ; ASCIIZ environment string address
  5108 00008661 F3A4                <1> 	rep	movsb
  5109 00008663 28C0                <1> 	sub	al, al
  5110 00008665 AA                  <1> 	stosb
  5111 00008666 58                  <1> 	pop	eax ; ***** ; Beginning address of new variable			
  5112 00008667 81FF00320900        <1>         cmp     edi, Env_Page + Env_Page_Size ; 12/04/2016
  5113 0000866D 0F8364FFFFFF        <1>         jnb     set_env_string_allocate_envb_retn ; OK !
  5114 00008673 880F                <1> 	mov	[edi], cl ; 0
  5115 00008675 F8                  <1> 	clc	; 13/04/2016
  5116 00008676 E95CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5117                              <1> 
  5118                              <1> set_env_change_variable:
  5119                              <1> 	; 06/04/2016
  5120                              <1> 	; esi = Variable's address in environment page (after '=')
  5121                              <1> 	; edi = ASCIIZ environment string address (after '=')
  5122                              <1> 
  5123                              <1> 	; ah = variable length from start to the '='
  5124 0000867B 8825[F82C0100]      <1> 	mov	[env_var_length], ah
  5125                              <1> 
  5126 00008681 28C9                <1> 	sub	cl, cl ; ecx = 0
  5127                              <1> 
  5128 00008683 57                  <1> 	push	edi ; *****
  5129                              <1> 
  5130 00008684 89F7                <1> 	mov	edi, esi ; 11/04/2016
  5131                              <1> 
  5132                              <1> set_env_change_variable_calc1:
  5133 00008686 AC                  <1> 	lodsb
  5134 00008687 08C0                <1> 	or	al, al
  5135 00008689 7403                <1> 	jz	short set_env_change_variable_calc2
  5136                              <1> 
  5137 0000868B 41                  <1> 	inc	ecx ; length of environment string (after the '=')
  5138                              <1> 
  5139 0000868C EBF8                <1> 	jmp	short set_env_change_variable_calc1	
  5140                              <1> 
  5141                              <1> set_env_change_variable_calc2:
  5142 0000868E 8B3424              <1> 	mov	esi, [esp] ; ASCIIZ environment string address
  5143                              <1> 	
  5144 00008691 29D2                <1> 	sub	edx, edx
  5145                              <1> 
  5146                              <1> set_env_change_variable_calc3:
  5147 00008693 AC                  <1> 	lodsb
  5148 00008694 3C20                <1> 	cmp	al, 20h
  5149 00008696 7203                <1> 	jb	short set_env_change_variable_calc4
  5150                              <1> 
  5151 00008698 42                  <1> 	inc	edx ; length of ASCIIZ string (after the '=')
  5152                              <1> 	
  5153 00008699 EBF8                <1> 	jmp	short set_env_change_variable_calc3
  5154                              <1> 	
  5155                              <1> set_env_change_variable_calc4:
  5156 0000869B C646FF00            <1> 	mov	byte [esi-1], 0  ; put ZERO instead of CR
  5157                              <1> 	
  5158 0000869F 5E                  <1> 	pop	esi ; ***** ; ASCIIZ string address (after '=')
  5159                              <1> 
  5160                              <1> 	; EDI = Old variable's address (after '=')
  5161                              <1> 	
  5162                              <1> 	; compare the new string with the old string
  5163 000086A0 39CA                <1> 	cmp	edx, ecx
  5164 000086A2 7717                <1> 	ja	short set_env_change_variable_calc5 ; longer
  5165 000086A4 0F828F000000        <1>         jb      set_env_change_variable_calc9 ; shorter
  5166                              <1> 	
  5167                              <1> 	;same length (simple copy)
  5168 000086AA 0FB6C4              <1> 	movzx	eax, ah
  5169 000086AD 01C2                <1> 	add	edx, eax
  5170 000086AF F7D8                <1> 	neg	eax
  5171 000086B1 01F8                <1> 	add	eax, edi
  5172                              <1> 	; EAX = Start address of the variable
  5173                              <1> 	; EDX = Variable length (without ZERO at the end of variable)
  5174                              <1> 
  5175 000086B3 F3A4                <1> 	rep	movsb
  5176 000086B5 F8                  <1> 	clc	; 13/04/2016
  5177 000086B6 E91CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5178                              <1> 
  5179                              <1> set_env_change_variable_calc5:
  5180                              <1> 	; 11/04/2016
  5181 000086BB 52                  <1> 	push	edx ; *****
  5182 000086BC 29CA                <1> 	sub	edx, ecx ; difference ; (the new string is longer)
  5183 000086BE 89F3                <1> 	mov 	ebx, esi
  5184 000086C0 89FE                <1> 	mov	esi, edi
  5185                              <1> 
  5186                              <1> set_env_change_variable_calc6:
  5187 000086C2 AC                  <1> 	lodsb 
  5188 000086C3 20C0                <1> 	and	al, al
  5189 000086C5 75FB                <1> 	jnz	short set_env_change_variable_calc6
  5190                              <1> 
  5191 000086C7 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  5192 000086CD 0F8369FFFFFF        <1>         jnb     set_env_add_variable_nspc
  5193                              <1> 
  5194 000086D3 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  5195 000086D5 89F7                <1> 	mov	edi, esi  ; next variable's address 
  5196                              <1> 
  5197 000086D7 AC                  <1> 	lodsb
  5198 000086D8 08C0                <1> 	or	al, al
  5199 000086DA 7416                <1> 	jz	short set_env_change_variable_calc8 ; 00
  5200                              <1> 
  5201                              <1> set_env_change_variable_calc7:
  5202 000086DC AC                  <1> 	lodsb
  5203 000086DD 20C0                <1> 	and	al, al
  5204 000086DF 75FB                <1> 	jnz	short set_env_change_variable_calc7
  5205                              <1> 
  5206 000086E1 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  5207 000086E7 0F834FFFFFFF        <1>         jnb     set_env_add_variable_nspc
  5208                              <1> 
  5209 000086ED AC                  <1> 	lodsb
  5210 000086EE 08C0                <1> 	or	al, al
  5211 000086F0 75EA                <1> 	jnz	short set_env_change_variable_calc7
  5212                              <1> 
  5213                              <1> set_env_change_variable_calc8:
  5214 000086F2 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  5215                              <1> 
  5216 000086F3 01F2                <1> 	add	edx, esi ; final position of the last 0
  5217                              <1> 
  5218 000086F5 81FA00320900        <1> 	cmp	edx, Env_Page + Env_Page_Size ; 512 (4096)
  5219 000086FB 0F833BFFFFFF        <1>         jnb     set_env_add_variable_nspc
  5220                              <1> 
  5221 00008701 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  5222                              <1> 
  5223 00008703 89F1                <1> 	mov	ecx, esi 
  5224 00008705 29F9                <1> 	sub	ecx, edi ; count of bytes to move forward
  5225                              <1> 
  5226                              <1> 	; 13/04/2016
  5227 00008707 C60200              <1> 	mov	byte [edx], 0
  5228 0000870A 89D7                <1> 	mov	edi, edx
  5229 0000870C 29F2                <1> 	sub	edx, esi ; difference (additional byte count)
  5230 0000870E 4F                  <1> 	dec	edi ; the last zero address (first byte of the 00)
  5231 0000870F 89FE                <1> 	mov	esi, edi
  5232 00008711 29D6                <1> 	sub	esi, edx ; - displacement
  5233                              <1> 	
  5234 00008713 FA                  <1> 	cli	; disable interrupts
  5235 00008714 FD                  <1> 	std	; backward
  5236                              <1> 
  5237 00008715 F3A4                <1> 	rep	movsb ; move ECX bytes from DS:ESI to ES:EDI
  5238                              <1> 
  5239 00008717 FC                  <1> 	cld	; forward (default)
  5240 00008718 FB                  <1> 	sti	; enable interrupts
  5241                              <1> 	
  5242 00008719 89C7                <1> 	mov	edi, eax
  5243 0000871B 59                  <1> 	pop	ecx ; ***** ; byte count (after '=')
  5244 0000871C 89CA                <1> 	mov	edx, ecx
  5245 0000871E 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  5246 00008720 89FB                <1> 	mov	ebx, edi
  5247                              <1> 
  5248 00008722 F3A4                <1> 	rep	movsb
  5249                              <1> 
  5250 00008724 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  5251                              <1> 
  5252 00008726 0FB605[F82C0100]    <1> 	movzx	eax, byte [env_var_length]
  5253 0000872D 01C2                <1> 	add	edx, eax ; variable length (total)
  5254 0000872F F7D8                <1> 	neg	eax
  5255 00008731 01D8                <1> 	add	eax, ebx ; start address of the variable
  5256 00008733 F8                  <1> 	clc	; 13/04/2016
  5257 00008734 E99EFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5258                              <1> 
  5259                              <1> set_env_change_variable_calc9:
  5260                              <1> 	; 11/04/2016
  5261 00008739 21D2                <1> 	and	edx, edx ; is empty ?
  5262 0000873B 753B                <1> 	jnz	short set_env_change_variable_calc15
  5263                              <1> 	
  5264 0000873D 0FB6DC              <1> 	movzx	ebx, ah
  5265 00008740 F7DB                <1> 	neg	ebx
  5266 00008742 01FB                <1> 	add	ebx, edi
  5267                              <1> 
  5268                              <1> 	; EBX = Start address of the variable (in env page)
  5269                              <1> 	; EDX = Variable length = 0
  5270                              <1> 	
  5271 00008744 89FE                <1> 	mov	esi, edi
  5272                              <1> 
  5273                              <1> set_env_change_variable_calc10:
  5274 00008746 AC                  <1> 	lodsb
  5275 00008747 08C0                <1> 	or	al, al
  5276 00008749 75FB                <1> 	jnz	short set_env_change_variable_calc10
  5277                              <1> 
  5278 0000874B B9FF310900          <1> 	mov	ecx, Env_Page + Env_Page_Size - 1
  5279                              <1> 
  5280 00008750 39CE                <1> 	cmp	esi, ecx ; +511 (+4095)
  5281 00008752 7604                <1> 	jna	short set_env_change_variable_calc11
  5282                              <1> 
  5283 00008754 89CE                <1> 	mov	esi, ecx
  5284 00008756 8806                <1> 	mov	[esi], al ; 0
  5285                              <1> 
  5286                              <1> set_env_change_variable_calc11:
  5287 00008758 89DF                <1> 	mov	edi, ebx ; old variable's start address
  5288                              <1> 
  5289                              <1> set_env_change_variable_calc12:
  5290 0000875A AC                  <1> 	lodsb
  5291 0000875B AA                  <1> 	stosb
  5292 0000875C 20C0                <1> 	and	al, al
  5293 0000875E 75FA                <1> 	jnz	short set_env_change_variable_calc12
  5294 00008760 39CE                <1> 	cmp	esi, ecx
  5295 00008762 7706                <1> 	ja	short set_env_change_variable_calc13
  5296 00008764 AC                  <1> 	lodsb
  5297 00008765 AA                  <1> 	stosb
  5298 00008766 20C0                <1> 	and	al, al
  5299 00008768 75F0                <1> 	jnz	short set_env_change_variable_calc12	
  5300                              <1> 
  5301                              <1> set_env_change_variable_calc13:
  5302 0000876A 29F9                <1> 	sub	ecx, edi
  5303 0000876C 7203                <1> 	jb	short set_env_change_variable_calc14
  5304 0000876E 41                  <1> 	inc	ecx ; 1-512 (1-4096)
  5305 0000876F F3AA                <1> 	rep	stosb ; al = 0	
  5306                              <1> 
  5307                              <1> set_env_change_variable_calc14:
  5308 00008771 29C0                <1> 	sub	eax, eax ; Start address of the variable
  5309                              <1> 	; EAX = 0 -> Variable is removed
  5310                              <1> 	; EDX = Variable length = 0	
  5311                              <1> 
  5312 00008773 E95FFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5313                              <1> 	    
  5314                              <1> set_env_change_variable_calc15:	
  5315 00008778 52                  <1> 	push	edx ; *****
  5316 00008779 F7DA                <1> 	neg	edx
  5317 0000877B 01CA                <1> 	add	edx, ecx ; difference (the old string is longer)
  5318 0000877D 89F3                <1> 	mov 	ebx, esi
  5319 0000877F 89FE                <1> 	mov	esi, edi
  5320                              <1> 
  5321                              <1> set_env_change_variable_calc16:
  5322 00008781 AC                  <1> 	lodsb 
  5323 00008782 20C0                <1> 	and	al, al
  5324 00008784 75FB                <1> 	jnz	short set_env_change_variable_calc16
  5325                              <1> 
  5326 00008786 B900320900          <1> 	mov	ecx, Env_Page + Env_Page_Size
  5327                              <1> 
  5328 0000878B 39CE                <1> 	cmp	esi, ecx ; +512 (+4096)
  5329 0000878D 7605                <1> 	jna	short set_env_change_variable_calc17
  5330                              <1> 
  5331 0000878F 89CE                <1> 	mov	esi, ecx
  5332 00008791 8846FF              <1> 	mov	[esi-1], al ; 0
  5333                              <1> 
  5334                              <1> set_env_change_variable_calc17:
  5335 00008794 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  5336 00008796 89F7                <1> 	mov	edi, esi  ; next variable's address 
  5337                              <1> 
  5338 00008798 AC                  <1> 	lodsb
  5339 00008799 08C0                <1> 	or	al, al
  5340 0000879B 741D                <1> 	jz	short set_env_change_variable_calc20
  5341                              <1> 
  5342                              <1> set_env_change_variable_calc18:
  5343 0000879D AC                  <1> 	lodsb
  5344 0000879E 20C0                <1> 	and	al, al
  5345 000087A0 75FB                <1> 	jnz	short set_env_change_variable_calc18
  5346                              <1> 
  5347 000087A2 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size
  5348 000087A8 720B                <1> 	jb	short set_env_change_variable_calc19
  5349 000087AA 740E                <1> 	je	short set_env_change_variable_calc20
  5350                              <1> 
  5351 000087AC BEFF310900          <1> 	mov	esi, Env_Page + Env_Page_Size - 1
  5352 000087B1 8806                <1> 	mov	[esi], al ; 0
  5353 000087B3 EB06                <1> 	jmp	short set_env_change_variable_calc21
  5354                              <1> 
  5355                              <1> set_env_change_variable_calc19:
  5356 000087B5 AC                  <1> 	lodsb
  5357 000087B6 08C0                <1> 	or	al, al
  5358 000087B8 75E3                <1> 	jnz	short set_env_change_variable_calc18
  5359                              <1> 
  5360                              <1> set_env_change_variable_calc20:
  5361 000087BA 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  5362                              <1> 
  5363                              <1> set_env_change_variable_calc21:
  5364                              <1> 	; edx = difference (byte count)
  5365                              <1> 	
  5366 000087BB 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  5367                              <1> 
  5368 000087BD 89F1                <1> 	mov	ecx, esi 
  5369 000087BF 29F9                <1> 	sub	ecx, edi ; count of bytes to move backward
  5370                              <1> 
  5371 000087C1 89FE                <1> 	mov	esi, edi ; next variable's address
  5372 000087C3 29D7                <1> 	sub	edi, edx ; (displacement)
  5373                              <1> 	
  5374 000087C5 F3A4                <1> 	rep	movsb
  5375                              <1> 
  5376 000087C7 880F                <1> 	mov	[edi], cl ; 0 ; 00 ; end of environment variables
  5377                              <1> 
  5378 000087C9 89C7                <1> 	mov	edi, eax
  5379 000087CB 5A                  <1> 	pop	edx ; ***** ; byte count (after '=')
  5380 000087CC 89D1                <1> 	mov	ecx, edx
  5381 000087CE 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  5382 000087D0 89FB                <1> 	mov	ebx, edi
  5383                              <1> 	
  5384 000087D2 F3A4                <1> 	rep	movsb
  5385                              <1> 
  5386 000087D4 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  5387                              <1> 
  5388 000087D6 0FB605[F82C0100]    <1> 	movzx	eax, byte [env_var_length]
  5389 000087DD 01C2                <1> 	add	edx, eax ; variable length (total)
  5390 000087DF F7D8                <1> 	neg	eax
  5391 000087E1 01D8                <1> 	add	eax, ebx ; start address of the variable
  5392 000087E3 F8                  <1> 	clc	; 13/04/2016
  5393 000087E4 E9EEFDFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5394                              <1> 
  5395                              <1> mainprog_startup_configuration:
  5396                              <1> 	; 06/05/2016
  5397                              <1> 	; 14/04/2016 (TRDOS 386 = TRDOS v2.0)
  5398                              <1> 	; 17/09/2011 (TRDOS v1, MAINPROG.ASM)
  5399                              <1> 	;
  5400                              <1> loc_load_mainprog_cfg_file:
  5401 000087E9 BE[4EDE0000]        <1> 	mov	esi, MainProgCfgFile
  5402 000087EE 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  5403 000087F2 E8FBE9FFFF          <1> 	call	find_first_file
  5404 000087F7 7256                <1> 	jc	short loc_load_mainprog_cfg_exit
  5405                              <1> 
  5406                              <1> 	;or	eax, eax
  5407                              <1> 	;jz	short loc_load_mainprog_cfg_exit
  5408                              <1> 
  5409                              <1> loc_start_mainprog_configuration:
  5410                              <1> 	; ESI = FindFile_DirEntry Location
  5411                              <1> 	; EAX = File Size
  5412                              <1> 
  5413 000087F9 A3[7C200100]        <1> 	mov	[MainProgCfg_FileSize], eax
  5414                              <1> 
  5415 000087FE 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  5416 00008802 C1E210              <1> 	shl	edx, 16
  5417 00008805 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  5418 00008809 8915[AC2C0100]      <1> 	mov	[csftdf_sf_cluster], edx
  5419                              <1> 
  5420 0000880F 89C1                <1> 	mov	ecx, eax
  5421 00008811 29C0                <1> 	sub	eax, eax
  5422                              <1> 
  5423                              <1> 	; TRDOS 386 (TRDOS v2.0)
  5424                              <1> 	; Allocate contiguous memory block for loading the file
  5425                              <1> 	
  5426                              <1> 	; eax = 0 (Allocate memory from the beginning)
  5427                              <1> 	; ecx = File (Allocation) size in bytes
  5428                              <1> 	
  5429 00008813 E83FC6FFFF          <1> 	call	allocate_memory_block
  5430 00008818 7235                <1> 	jc	short loc_load_mainprog_cfg_exit
  5431                              <1> 
  5432 0000881A A3[A42C0100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  5433 0000881F 890D[A82C0100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  5434                              <1> 
  5435 00008825 31DB                <1> 	xor	ebx, ebx
  5436                              <1> 	;mov	[csftdf_sf_rbytes], ebx ; 0, reset
  5437                              <1> 
  5438 00008827 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv] ; [FindFile_Drv]
  5439 0000882D BE00010900          <1> 	mov	esi, Logical_DOSDisks
  5440 00008832 01DE                <1> 	add	esi, ebx
  5441                              <1> 
  5442 00008834 8B1D[A42C0100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  5443                              <1> 
  5444 0000883A 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5445 0000883E 7710                <1>         ja	short loc_mcfg_load_fat_file
  5446                              <1> 
  5447 00008840 C705[B42C0100]0000- <1> 	mov	dword [csftdf_r_size], 65536
  5447 00008848 0100                <1>
  5448 0000884A E992010000          <1>         jmp     loc_mcfg_load_fs_file
  5449                              <1> 
  5450                              <1> loc_load_mainprog_cfg_exit:
  5451 0000884F C3                  <1> 	retn 
  5452                              <1> 
  5453                              <1> loc_mcfg_load_fat_file:
  5454 00008850 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
  5455 00008854 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  5456 00008858 F7E1                <1> 	mul	ecx
  5457 0000885A A3[B42C0100]        <1> 	mov	[csftdf_r_size], eax
  5458                              <1> 
  5459                              <1> loc_mcfg_load_fat_file_next:
  5460 0000885F E813010000          <1> 	call	mcfg_read_fat_file_sectors
  5461 00008864 0F82F7000000        <1>         jc      mcfg_deallocate_mem
  5462                              <1> 
  5463 0000886A 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  5464 0000886C 74F1                <1> 	jz	short loc_mcfg_load_fat_file_next
  5465                              <1> 
  5466                              <1> loc_mcfg_load_fat_file_ok:
  5467                              <1> 	; 06/05/2016
  5468 0000886E C705[3C2D0100]-     <1> 	mov	dword [mainprog_return_addr], loc_mcfg_ci_return_addr 
  5468 00008874 [22890000]          <1>
  5469                              <1> 	;
  5470 00008878 8B35[A42C0100]      <1> 	mov	esi, [csftdf_sf_mem_addr]
  5471 0000887E 8935[80200100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  5472                              <1> 	
  5473 00008884 A1[7C200100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  5474 00008889 89C2                <1> 	mov	edx, eax
  5475 0000888B 01F2                <1> 	add	edx, esi
  5476                              <1> 
  5477                              <1> loc_mcfg_process_next_line_check:
  5478 0000888D 89C1                <1> 	mov	ecx, eax
  5479                              <1> 
  5480 0000888F 803E2A              <1> 	cmp	byte [esi], "*" ; Remark sign
  5481 00008892 7503                <1> 	jne	short loc_mcfg_process_next_line
  5482 00008894 46                  <1> 	inc	esi
  5483 00008895 EB17                <1> 	jmp	short loc_move_mainprog_cfg_nl1
  5484                              <1> 
  5485                              <1> loc_mcfg_process_next_line:
  5486 00008897 83F94F              <1> 	cmp	ecx, 79
  5487 0000889A 7605                <1> 	jna	short loc_start_mainprog_cfg_process
  5488                              <1> 	
  5489 0000889C B94F000000          <1> 	mov	ecx, 79 
  5490                              <1> 
  5491                              <1> loc_start_mainprog_cfg_process:
  5492 000088A1 BF[3E210100]        <1> 	mov	edi, CommandBuffer
  5493                              <1> 
  5494                              <1> loc_move_mainprog_cfg_line:
  5495 000088A6 AC                  <1> 	lodsb
  5496 000088A7 3C20                <1> 	cmp	al, 20h
  5497 000088A9 720C                <1> 	jb	short loc_move_mainprog_cfg_nl2
  5498 000088AB AA                  <1> 	stosb
  5499 000088AC E2F8                <1> 	loop	loc_move_mainprog_cfg_line
  5500                              <1> 
  5501                              <1> loc_move_mainprog_cfg_nl1:
  5502 000088AE 39D6                <1> 	cmp	esi, edx ; + configuration file size
  5503 000088B0 7312                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  5504 000088B2 AC                  <1> 	lodsb
  5505 000088B3 3C20                <1> 	cmp	al, 20h
  5506 000088B5 73F7                <1> 	jnb	short loc_move_mainprog_cfg_nl1
  5507                              <1> 
  5508                              <1> loc_move_mainprog_cfg_nl2:
  5509 000088B7 39D6                <1> 	cmp	esi, edx
  5510 000088B9 7309                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  5511 000088BB 8A06                <1> 	mov	al, [esi]
  5512 000088BD 3C20                <1> 	cmp	al, 20h
  5513 000088BF 7703                <1>  	ja	short loc_end_of_mainprog_cfg_line
  5514 000088C1 46                  <1> 	inc	esi
  5515 000088C2 EBF3                <1> 	jmp	short loc_move_mainprog_cfg_nl2	               
  5516                              <1> 
  5517                              <1> loc_end_of_mainprog_cfg_line:
  5518 000088C4 C60700              <1> 	mov	byte [edi], 0
  5519                              <1> 
  5520 000088C7 8935[80200100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  5521                              <1> 	
  5522                              <1> loc_move_mainprog_cfg_command:
  5523 000088CD BE[3E210100]        <1> 	mov	esi, CommandBuffer
  5524 000088D2 89F7                <1> 	mov	edi, esi
  5525 000088D4 31DB                <1> 	xor	ebx, ebx
  5526                              <1> 	;xor	ecx, ecx
  5527 000088D6 30C9                <1> 	xor	cl, cl
  5528                              <1> 
  5529                              <1> loc_move_mcfg_first_cmd_char:
  5530 000088D8 8A041E              <1> 	mov	al, [esi+ebx]
  5531 000088DB FEC3                <1> 	inc	bl 
  5532 000088DD 3C20                <1> 	cmp	al, 20h
  5533 000088DF 7712                <1> 	ja	short loc_move_mcfg_cmd_capitalizing
  5534 000088E1 7237                <1> 	jb	short loc_move_mcfg_cmd_arguments_ok
  5535 000088E3 80FB4F              <1> 	cmp	bl, 79
  5536 000088E6 72F0                <1> 	jb	short loc_move_mcfg_first_cmd_char
  5537 000088E8 EB30                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  5538                              <1> 
  5539                              <1> loc_move_mcfg_next_cmd_char:
  5540 000088EA 8A041E              <1> 	mov	al, [esi+ebx]
  5541 000088ED FEC3                <1> 	inc	bl
  5542 000088EF 3C20                <1> 	cmp	al, 20h
  5543 000088F1 7614                <1> 	jna	short loc_move_mcfg_cmd_ok
  5544                              <1> 
  5545                              <1> loc_move_mcfg_cmd_capitalizing:
  5546 000088F3 3C61                <1> 	cmp	al, 61h ; 'a'
  5547 000088F5 7206                <1> 	jb	short loc_move_mcfg_cmd_caps_ok
  5548 000088F7 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  5549 000088F9 7702                <1> 	ja	short loc_move_mcfg_cmd_caps_ok
  5550 000088FB 24DF                <1> 	and	al, 0DFh ; sub	al, 'a'-'A'
  5551                              <1> 
  5552                              <1> loc_move_mcfg_cmd_caps_ok:
  5553 000088FD AA                  <1> 	stosb 
  5554 000088FE FEC1                <1> 	inc	cl
  5555 00008900 80FB4F              <1> 	cmp	bl, 79
  5556 00008903 72E5                <1> 	jb	short loc_move_mcfg_next_cmd_char
  5557 00008905 EB13                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  5558                              <1> 
  5559                              <1> loc_move_mcfg_cmd_ok:
  5560 00008907 30C0                <1> 	xor	al, al ; 0
  5561                              <1> 
  5562                              <1> loc_move_mcfg_cmd_arguments:
  5563 00008909 8807                <1> 	mov	[edi], al
  5564 0000890B 47                  <1> 	inc	edi
  5565 0000890C 80FB4F              <1> 	cmp	bl, 79
  5566 0000890F 7309                <1> 	jnb	short loc_move_mcfg_cmd_arguments_ok
  5567 00008911 8A041E              <1> 	mov	al, [esi+ebx]
  5568 00008914 FEC3                <1> 	inc	bl
  5569 00008916 3C20                <1> 	cmp	al, 20h
  5570 00008918 73EF                <1> 	jnb	short loc_move_mcfg_cmd_arguments
  5571                              <1> 	
  5572                              <1> loc_move_mcfg_cmd_arguments_ok:
  5573 0000891A C60700              <1> 	mov	byte [edi], 0
  5574                              <1>        
  5575                              <1> loc_mcfg_process_cmd_interpreter:
  5576 0000891D E8F8DFFFFF          <1> 	call    command_interpreter
  5577                              <1> 
  5578                              <1> loc_mcfg_ci_return_addr: 
  5579 00008922 A1[7C200100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  5580 00008927 89C2                <1> 	mov	edx, eax
  5581 00008929 8B35[80200100]      <1> 	mov	esi, [MainProgCfg_LineOffset]
  5582 0000892F 01F2                <1> 	add	edx, esi
  5583 00008931 0305[A42C0100]      <1> 	add	eax, [csftdf_sf_mem_addr]
  5584 00008937 29F0                <1> 	sub	eax, esi
  5585 00008939 0F874EFFFFFF        <1>         ja      loc_mcfg_process_next_line_check
  5586                              <1> 
  5587 0000893F E81D000000          <1> 	call	mcfg_deallocate_mem
  5588                              <1>  
  5589 00008944 B94F000000          <1>  	mov	ecx, 79 ; 80 ?
  5590 00008949 BF[3E210100]        <1> 	mov	edi, CommandBuffer
  5591 0000894E 30C0                <1> 	xor	al, al
  5592 00008950 F3AA                <1> 	rep	stosb
  5593                              <1> 
  5594                              <1> 	; 06/05/2016
  5595 00008952 BE[ABEE0000]        <1> 	mov	esi, nextline
  5596 00008957 E8FACBFFFF          <1> 	call	print_msg
  5597 0000895C E931D6FFFF          <1> 	jmp	dos_prompt
  5598                              <1> 
  5599                              <1> mcfg_deallocate_mem:
  5600 00008961 A1[A42C0100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  5601 00008966 8B0D[A82C0100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
  5602                              <1> 	;call	deallocate_memory_block
  5603                              <1> 	;retn
  5604 0000896C E9E7C6FFFF          <1> 	jmp	deallocate_memory_block
  5605                              <1> 
  5606                              <1> mcfg_read_file_sectors:
  5607                              <1> 	; 14/04/2016
  5608 00008971 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5609 00008975 7669                <1>         jna	short mcfg_read_fs_file_sectors
  5610                              <1> 
  5611                              <1> mcfg_read_fat_file_sectors:
  5612                              <1> 	; return:
  5613                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  5614                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  5615                              <1> 	;   CF = 1 -> read error (error code in AL)	
  5616                              <1> 
  5617                              <1> mcfg_read_fat_file_secs_0:
  5618 00008977 8B15[7C200100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  5619 0000897D 2B15[BC2C0100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  5620 00008983 3B15[B42C0100]      <1> 	cmp	edx, [csftdf_r_size]	
  5621 00008989 7306                <1> 	jnb	short mcfg_read_fat_file_secs_1
  5622 0000898B 8915[B42C0100]      <1> 	mov	[csftdf_r_size], edx
  5623                              <1> 		
  5624                              <1> mcfg_read_fat_file_secs_1:
  5625 00008991 A1[B42C0100]        <1> 	mov	eax, [csftdf_r_size]
  5626 00008996 29D2                <1> 	sub	edx, edx
  5627 00008998 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  5628 0000899C 01C8                <1> 	add	eax, ecx
  5629 0000899E 48                  <1> 	dec	eax
  5630 0000899F F7F1                <1> 	div	ecx
  5631 000089A1 89C1                <1> 	mov	ecx, eax ; sector count
  5632 000089A3 A1[AC2C0100]        <1> 	mov	eax, [csftdf_sf_cluster]
  5633                              <1> 
  5634                              <1> 	; EBX = memory block address (current)
  5635                              <1> 	
  5636 000089A8 E874230000          <1> 	call	read_fat_file_sectors
  5637 000089AD 7230                <1> 	jc	short mcfg_read_fat_file_secs_3
  5638                              <1> 
  5639                              <1> 	; EBX = next memory address
  5640                              <1> 
  5641 000089AF A1[BC2C0100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  5642 000089B4 0305[B42C0100]      <1> 	add	eax, [csftdf_r_size]
  5643 000089BA 8B15[7C200100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  5644 000089C0 39D0                <1> 	cmp	eax, edx
  5645 000089C2 731B                <1> 	jnb	short mcfg_read_fat_file_secs_3 ; edx > 0
  5646 000089C4 A3[BC2C0100]        <1> 	mov	[csftdf_sf_rbytes], eax
  5647                              <1> 
  5648 000089C9 53                  <1> 	push	ebx ; *
  5649                              <1> 	; get next cluster (csftdf_r_size! bytes)
  5650 000089CA A1[AC2C0100]        <1> 	mov	eax, [csftdf_sf_cluster]
  5651 000089CF E81F210000          <1> 	call	get_next_cluster
  5652 000089D4 5B                  <1> 	pop	ebx ; *
  5653 000089D5 7301                <1> 	jnc	short mcfg_read_fat_file_secs_2
  5654                              <1> 
  5655                              <1> 	;mov	eax, 15h ; Read error !
  5656 000089D7 C3                  <1> 	retn
  5657                              <1> 
  5658                              <1> mcfg_read_fat_file_secs_2:
  5659 000089D8 29D2                <1> 	sub	edx, edx ; 0
  5660 000089DA A3[AC2C0100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  5661                              <1> 
  5662                              <1> mcfg_read_fat_file_secs_3:
  5663 000089DF C3                  <1> 	retn
  5664                              <1> 
  5665                              <1> mcfg_read_fs_file_sectors:
  5666 000089E0 C3                  <1> 	retn
  5667                              <1> 
  5668                              <1> loc_mcfg_load_fs_file:
  5669 000089E1 C3                  <1> 	retn
  5670                              <1> 
  5671                              <1> load_and_execute_file:
  5672                              <1> 	; 11/05/2016
  5673                              <1> 	; 07/05/2016
  5674                              <1> 	; 06/05/2016
  5675                              <1> 	; 24/04/2016
  5676                              <1> 	; 23/04/2016
  5677                              <1> 	; 22/04/2016 (TRDOS 386 = TRDOS v2.0)
  5678                              <1> 	; 05/11/2011 
  5679                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'cmp_cmd_run', 'cmp_cmd_external')
  5680                              <1> 	; ('loc_run_check_filename')
  5681                              <1> 	; 29/08/2011
  5682                              <1> 	; 10/09/2011
  5683                              <1> 	; INPUT->
  5684                              <1> 	;	ESI = Path Name address (CommandBuffer address)
  5685                              <1> 	; OUTPUT ->
  5686                              <1> 	;	none (error message will be shown if an error will occur)
  5687                              <1> 	;
  5688                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI, EBP will be changed) 
  5689                              <1> 	;
  5690                              <1> loc_run_check_filename:
  5691 000089E2 803E20              <1> 	cmp	byte [esi], 20h
  5692 000089E5 0F8205E3FFFF        <1> 	jb	loc_cmd_failed
  5693 000089EB 7703                <1> 	ja	short loc_run_check_filename_ok
  5694 000089ED 46                  <1> 	inc	esi
  5695 000089EE EBF2                <1> 	jmp	short loc_run_check_filename
  5696                              <1> 
  5697                              <1> loc_run_check_filename_ok:
  5698 000089F0 C605[EF200100]00    <1> 	mov	byte [CmdArgStart], 0 ; reset
  5699 000089F7 56                  <1> 	push	esi ; *
  5700                              <1> loc_run_get_first_arg_pos:
  5701 000089F8 46                  <1> 	inc	esi
  5702 000089F9 8A06                <1> 	mov	al, [esi]
  5703 000089FB 3C20                <1> 	cmp	al, 20h
  5704 000089FD 77F9                <1> 	ja	short loc_run_get_first_arg_pos
  5705 000089FF C60600              <1> 	mov	byte [esi], 0
  5706                              <1> loc_run_get_external_arg_pos:
  5707                              <1> 	; 11/05/2016
  5708 00008A02 46                  <1> 	inc	esi
  5709 00008A03 8A06                <1> 	mov	al, [esi]
  5710 00008A05 3C20                <1> 	cmp	al, 20h
  5711 00008A07 760C                <1> 	jna	short loc_run_parse_path_name
  5712 00008A09 89F0                <1> 	mov	eax, esi
  5713 00008A0B 2D[3E210100]        <1> 	sub	eax, CommandBuffer
  5714 00008A10 A2[EF200100]        <1> 	mov	byte [CmdArgStart], al
  5715                              <1> loc_run_parse_path_name:
  5716 00008A15 5E                  <1> 	pop	esi ; *
  5717 00008A16 BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  5718 00008A1B E8DC090000          <1> 	call	parse_path_name
  5719 00008A20 0F82CAE2FFFF        <1> 	jc	loc_cmd_failed
  5720                              <1> 
  5721                              <1> loc_run_check_filename_exists:
  5722 00008A26 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5723 00008A2B 803E20              <1> 	cmp	byte [esi], 20h
  5724 00008A2E 0F86BCE2FFFF        <1> 	jna	loc_cmd_failed
  5725                              <1> 
  5726                              <1> loc_run_check_exe_filename_ext:
  5727 00008A34 E897020000          <1> 	call	check_prg_filename_ext
  5728 00008A39 0F82B1E2FFFF        <1> 	jc	loc_cmd_failed
  5729                              <1> 	
  5730                              <1> loc_run_check_exe_filename_ext_ok:
  5731 00008A3F 66A3[3A2D0100]      <1> 	mov	word [EXE_ID], ax
  5732                              <1> 
  5733                              <1> loc_run_drv:
  5734 00008A45 C605[392D0100]00    <1> 	mov	byte [Run_Manual_Path], 0
  5735 00008A4C A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
  5736 00008A51 A3[342D0100]        <1>         mov     [Run_CDirFC], eax
  5737                              <1> 	;
  5738 00008A56 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  5739 00008A5C 8835[EE280100]      <1> 	mov	[RUN_CDRV], dh
  5740                              <1> 
  5741 00008A62 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  5742 00008A68 38F2                <1> 	cmp	dl, dh
  5743 00008A6A 7412                <1> 	je	short loc_run_change_directory
  5744                              <1>                
  5745 00008A6C 8005[392D0100]02    <1> 	add	byte [Run_Manual_Path], 2
  5746                              <1> 
  5747 00008A73 E8DED3FFFF          <1> 	call	change_current_drive
  5748 00008A78 0F829DE2FFFF        <1> 	jc	loc_run_cmd_failed
  5749                              <1> 
  5750                              <1> loc_run_change_directory:
  5751 00008A7E 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  5752 00008A85 7623                <1> 	jna	short loc_run_find_executable_file
  5753                              <1> 
  5754 00008A87 FE05[392D0100]      <1> 	inc	byte [Run_Manual_Path]
  5755                              <1>      
  5756 00008A8D FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  5757                              <1> 
  5758 00008A93 BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  5759 00008A98 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  5760 00008A9A E849030000          <1> 	call	change_current_directory
  5761 00008A9F 0F8276E2FFFF        <1> 	jc	loc_run_cmd_failed
  5762                              <1> 
  5763                              <1> loc_run_change_prompt_dir_string:
  5764 00008AA5 E85E020000          <1> 	call	change_prompt_dir_string
  5765                              <1> 
  5766                              <1> loc_run_find_executable_file:
  5767 00008AAA 66C705[382D0100]00- <1> 	mov	word [Run_Auto_Path], 0
  5767 00008AB2 00                  <1>
  5768                              <1> 
  5769                              <1> loc_run_find_executable_file_next:
  5770 00008AB3 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5771                              <1> loc_run_find_program_file_next:
  5772 00008AB8 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  5773 00008ABC E831E7FFFF          <1> 	call	find_first_file
  5774                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  5775                              <1> 	; EDI = Directory Buffer Directory Entry Location
  5776                              <1> 	; EAX = File size
  5777 00008AC1 0F835C010000        <1> 	jnc	loc_load_and_run_file
  5778                              <1> 	 
  5779 00008AC7 3C02                <1> 	cmp	al, 2 ; file not found
  5780 00008AC9 0F854CE2FFFF        <1> 	jne	loc_run_cmd_failed
  5781                              <1> 
  5782 00008ACF 66A1[3A2D0100]      <1> 	mov	ax, word [EXE_ID]
  5783 00008AD5 80FC2E              <1> 	cmp	ah, '.' ; File name has extension sign
  5784 00008AD8 7424                <1> 	je	short loc_run_check_auto_path
  5785                              <1> 
  5786 00008ADA 08C0                <1> 	or	al, al
  5787 00008ADC 7520                <1> 	jnz	short loc_run_check_auto_path
  5788                              <1> 
  5789 00008ADE 80FC08              <1> 	cmp	ah, 8 ; count of file name chars
  5790 00008AE1 771B                <1> 	ja	short loc_run_check_auto_path
  5791                              <1> 
  5792                              <1> loc_run_change_file_ext_to_prg:
  5793 00008AE3 0FB6DC              <1> 	movzx	ebx, ah ; count of file name chars
  5794 00008AE6 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5795 00008AEB 01F3                <1> 	add	ebx, esi	
  5796                              <1> 	; 07/05/2016
  5797 00008AED C7032E505247        <1> 	mov	dword [ebx],  '.PRG'
  5798 00008AF3 66C705[3A2D0100]50- <1> 	mov	word [EXE_ID], 'P.'
  5798 00008AFB 2E                  <1>
  5799 00008AFC EBBA                <1> 	jmp	short loc_run_find_program_file_next	
  5800                              <1> 
  5801                              <1> loc_run_check_auto_path:
  5802                              <1> 	; NOTE: /// 07/05/2016 ///
  5803                              <1> 	; If the path is given, value of byte [Run_Manual_Path]
  5804                              <1> 	; will not be ZERO. If so, file searching by using
  5805                              <1> 	; Automatic Path (via 'PATH' environment variable)
  5806                              <1> 	; will not be applicable, because the program file 
  5807                              <1> 	; is already/absolutely not found.
  5808                              <1> 
  5809 00008AFE A0[392D0100]        <1> 	mov	al, [Run_Manual_Path]
  5810 00008B03 08C0                <1> 	or	al, al
  5811 00008B05 0F85E5E1FFFF        <1> 	jnz	loc_cmd_failed
  5812                              <1> 
  5813                              <1> loc_run_check_auto_path_again:
  5814 00008B0B 66833D[382D0100]FF  <1> 	cmp	word [Run_Auto_Path], 0FFFFh		 
  5815                              <1> 		; 0FFFFh = Not a valid run path (in ENV block) 
  5816 00008B13 0F83D7E1FFFF        <1> 	jnb	loc_cmd_failed
  5817                              <1> 	; xor	al, al 
  5818 00008B19 BE[D4DE0000]        <1> 	mov	esi, Cmd_Path ; 'PATH'
  5819 00008B1E BF[8E210100]        <1> 	mov	edi, TextBuffer
  5820 00008B23 E857F9FFFF          <1> 	call	get_environment_string
  5821 00008B28 730E                <1> 	jnc	short loc_run_chk_filename_ext_again
  5822 00008B2A 66C705[382D0100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; invalid
  5822 00008B32 FF                  <1>
  5823 00008B33 E9B8E1FFFF          <1> 	jmp	loc_cmd_failed
  5824                              <1> 
  5825                              <1> loc_run_chk_filename_ext_again:
  5826 00008B38 89C1                <1> 	mov	ecx, eax ; string length (with zero tail)
  5827 00008B3A 49                  <1> 	dec	ecx ; without zero tail
  5828 00008B3B 66A1[3A2D0100]      <1> 	mov	ax, [EXE_ID]
  5829 00008B41 80FC2E              <1> 	cmp	ah, '.'
  5830 00008B44 740E                <1> 	je	short loc_run_chk_auto_path_pos
  5831                              <1> 	 
  5832                              <1> loc_run_change_file_ext_to_noext_again:
  5833 00008B46 0FB6DC              <1> 	movzx	ebx, ah
  5834 00008B49 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5835 00008B4E 01F3                <1> 	add 	ebx, esi
  5836 00008B50 29C0                <1> 	sub	eax, eax
  5837 00008B52 8903                <1> 	mov	[ebx], eax ; 0 ; erase extension (.PRG)
  5838                              <1> 
  5839                              <1> loc_run_chk_auto_path_pos:
  5840                              <1> 	;movzx	eax,  word [Run_Auto_Path]
  5841 00008B54 66A1[382D0100]      <1> 	mov	ax, [Run_Auto_Path]
  5842 00008B5A 39C8                <1> 	cmp	eax, ecx ; ecx = string length (except zero tail)
  5843 00008B5C 0F838EE1FFFF        <1> 	jnb	loc_cmd_failed
  5844                              <1> 	;or	eax, eax
  5845 00008B62 6609C0              <1> 	or	ax, ax
  5846 00008B65 7502                <1> 	jnz	short loc_run_auto_path_pos_move
  5847 00008B67 B005                <1> 	mov	al, 5
  5848                              <1> 
  5849                              <1> loc_run_auto_path_pos_move:
  5850 00008B69 89FE                <1> 	mov	esi, edi ; offset TextBuffer
  5851 00008B6B 01C6                <1> 	add	esi, eax
  5852                              <1> 
  5853                              <1> loc_run_auto_path_pos_space_loop:
  5854 00008B6D AC                  <1> 	lodsb
  5855 00008B6E 3C20                <1> 	cmp	al, 20h 
  5856 00008B70 74FB                <1> 	je	short loc_run_auto_path_pos_space_loop
  5857 00008B72 0F8278E1FFFF        <1> 	jb	loc_cmd_failed 
  5858 00008B78 AA                  <1> 	stosb
  5859                              <1> loc_run_auto_path_pos_move_next: 
  5860 00008B79 AC                  <1> 	lodsb
  5861 00008B7A 3C3B                <1> 	cmp	al, ';'
  5862 00008B7C 7414                <1> 	je	short loc_run_auto_path_pos_move_last_byte
  5863 00008B7E 3C20                <1> 	cmp	al, 20h
  5864 00008B80 74F7                <1> 	je	short loc_run_auto_path_pos_move_next
  5865 00008B82 7203                <1> 	jb	short loc_byte_ptr_end_of_path
  5866 00008B84 AA                  <1> 	stosb
  5867 00008B85 EBF2                <1> 	jmp	short loc_run_auto_path_pos_move_next 
  5868                              <1> 
  5869                              <1> loc_byte_ptr_end_of_path: 
  5870 00008B87 66C705[382D0100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; end of path
  5870 00008B8F FF                  <1>
  5871 00008B90 EB0D                <1> 	jmp	short loc_run_auto_path_move_ok 
  5872                              <1> 
  5873                              <1> loc_run_auto_path_pos_move_last_byte:
  5874 00008B92 89F0                <1> 	mov	eax, esi
  5875 00008B94 2D[8E210100]        <1> 	sub	eax, TextBuffer 
  5876 00008B99 66A3[382D0100]      <1> 	mov	[Run_Auto_Path], ax ; next path position
  5877                              <1> 
  5878                              <1> loc_run_auto_path_move_ok:
  5879 00008B9F 4F                  <1> 	dec	edi
  5880 00008BA0 B02F                <1> 	mov	al, '/'
  5881 00008BA2 3807                <1> 	cmp	[edi], al
  5882 00008BA4 7403                <1> 	je	short loc_run_auto_path_move_file_name
  5883 00008BA6 47                  <1> 	inc	edi
  5884 00008BA7 8807                <1> 	mov	[edi], al
  5885                              <1> 
  5886                              <1> loc_run_auto_path_move_file_name:
  5887 00008BA9 47                  <1> 	inc	edi   
  5888 00008BAA BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5889                              <1> 
  5890                              <1> loc_run_auto_path_move_fn_loop:
  5891 00008BAF AC                  <1> 	lodsb
  5892 00008BB0 AA                  <1> 	stosb
  5893 00008BB1 08C0                <1> 	or	al, al
  5894 00008BB3 75FA                <1> 	jnz	short loc_run_auto_path_move_fn_loop
  5895                              <1> 
  5896 00008BB5 BE[8E210100]        <1> 	mov	esi, TextBuffer
  5897 00008BBA BF[322A0100]        <1> 	mov	edi, FindFile_Drv
  5898 00008BBF E838080000          <1> 	call	parse_path_name
  5899 00008BC4 0F8226E1FFFF        <1> 	jc	loc_cmd_failed
  5900                              <1> 
  5901 00008BCA 8A35[8E200100]      <1> 	mov	dh, [Current_Drv]
  5902 00008BD0 8A15[322A0100]      <1> 	mov	dl, [FindFile_Drv]
  5903 00008BD6 38F2                <1> 	cmp	dl, dh
  5904 00008BD8 740B                <1> 	je	short loc_run_change_directory_again
  5905                              <1>                
  5906 00008BDA E877D2FFFF          <1> 	call	change_current_drive
  5907 00008BDF 0F8236E1FFFF        <1> 	jc	loc_run_cmd_failed
  5908                              <1> 
  5909                              <1> loc_run_change_directory_again:
  5910 00008BE5 803D[332A0100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  5911 00008BEC 761D                <1> 	jna	short loc_load_executable_cdir_chk_again
  5912                              <1> 
  5913 00008BEE FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  5914 00008BF4 BE[332A0100]        <1> 	mov	esi, FindFile_Directory
  5915 00008BF9 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  5916 00008BFB E8E8010000          <1> 	call	change_current_directory
  5917 00008C00 0F8215E1FFFF        <1> 	jc	loc_run_cmd_failed
  5918                              <1> 
  5919                              <1> loc_run_chg_prompt_dir_str_again:
  5920 00008C06 E8FD000000          <1> 	call	change_prompt_dir_string
  5921                              <1> 
  5922                              <1> loc_load_executable_cdir_chk_again:
  5923 00008C0B A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
  5924 00008C10 3B05[342D0100]      <1> 	cmp	eax, [Run_CDirFC]
  5925 00008C16 0F8597FEFFFF        <1> 	jne	loc_run_find_executable_file_next
  5926 00008C1C 30C0                <1> 	xor	al, al ; 0
  5927 00008C1E E9E8FEFFFF          <1> 	jmp	loc_run_check_auto_path_again
  5928                              <1> 
  5929                              <1> loc_load_and_run_file:
  5930                              <1> 	; 23/04/2016
  5931 00008C23 BE[742A0100]        <1> 	mov	esi, FindFile_Name
  5932 00008C28 BF[8E210100]        <1> 	mov	edi, TextBuffer
  5933                              <1> 
  5934                              <1>  	; 24/04/2016
  5935 00008C2D 31D2                <1> 	xor	edx, edx
  5936 00008C2F 668915[26310100]    <1> 	mov	word [argc], dx ; 0
  5937 00008C36 8915[D0300100]      <1> 	mov	dword [u.nread], edx ; 0
  5938                              <1> 
  5939                              <1> loc_load_and_run_file_1:
  5940 00008C3C AC                  <1> 	lodsb	
  5941 00008C3D AA                  <1> 	stosb
  5942 00008C3E FF05[D0300100]      <1> 	inc	dword [u.nread]
  5943 00008C44 20C0                <1> 	and	al, al
  5944 00008C46 75F4                <1> 	jnz 	short loc_load_and_run_file_1
  5945                              <1> 	
  5946 00008C48 A0[EF200100]        <1> 	mov	al, [CmdArgStart]
  5947 00008C4D 20C0                <1> 	and	al, al
  5948 00008C4F 7445                <1> 	jz	short loc_load_and_run_file_7
  5949                              <1> 
  5950 00008C51 0FB6F0              <1> 	movzx	esi, al ; 11/05/2016
  5951 00008C54 B950000000          <1> 	mov	ecx, 80
  5952 00008C59 29F1                <1> 	sub	ecx, esi
  5953 00008C5B 81C6[3E210100]      <1> 	add	esi, CommandBuffer
  5954                              <1> 
  5955 00008C61 66FF05[26310100]    <1> 	inc	word [argc] ; 11/05/2016
  5956                              <1> 
  5957                              <1> loc_load_and_run_file_2:
  5958 00008C68 AC                  <1> 	lodsb
  5959 00008C69 3C20                <1> 	cmp	al, 20h
  5960 00008C6B 7717                <1> 	ja	short loc_load_and_run_file_5	
  5961 00008C6D 721E                <1> 	jb	short loc_load_and_run_file_6
  5962                              <1> 
  5963                              <1> loc_load_and_run_file_3:
  5964 00008C6F 803E20              <1> 	cmp	byte [esi], 20h
  5965 00008C72 7707                <1> 	ja	short loc_load_and_run_file_4
  5966 00008C74 7217                <1> 	jb	short loc_load_and_run_file_6
  5967 00008C76 46                  <1> 	inc	esi
  5968 00008C77 E2F6                <1> 	loop	loc_load_and_run_file_3
  5969 00008C79 EB12                <1> 	jmp	short loc_load_and_run_file_6
  5970                              <1> 
  5971                              <1> loc_load_and_run_file_4:
  5972 00008C7B 28C0                <1> 	sub	al, al ; 0
  5973 00008C7D 66FF05[26310100]    <1> 	inc	word [argc]
  5974                              <1> loc_load_and_run_file_5:
  5975 00008C84 AA                  <1> 	stosb
  5976 00008C85 FF05[D0300100]      <1> 	inc	dword [u.nread]
  5977 00008C8B E2DB                <1> 	loop	loc_load_and_run_file_2
  5978                              <1> 			
  5979                              <1> loc_load_and_run_file_6:
  5980 00008C8D 30C0                <1> 	xor	al, al ; 0
  5981 00008C8F AA                  <1> 	stosb
  5982 00008C90 FF05[D0300100]      <1> 	inc	dword [u.nread]
  5983                              <1> loc_load_and_run_file_7:
  5984 00008C96 8807                <1> 	mov 	[edi], al ; 0
  5985 00008C98 66FF05[26310100]    <1> 	inc	word [argc] ; 24/04/2016
  5986 00008C9F FF05[D0300100]      <1> 	inc	dword [u.nread] ; 24/04/2016
  5987 00008CA5 BE[8E210100]        <1> 	mov	esi, TextBuffer
  5988 00008CAA 8B15[A02A0100]      <1> 	mov	edx, [FindFile_DirEntry+DirEntry_FileSize]
  5989 00008CB0 66A1[982A0100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusHI]
  5990 00008CB6 66C1E010            <1> 	shl	ax, 16
  5991 00008CBA 66A1[9E2A0100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusLO]
  5992                              <1> 	; EAX = First Cluster number
  5993                              <1> 	; EDX = File Size
  5994                              <1> 	; ESI = Argument list address
  5995                              <1> 	; [argc] = argument count
  5996                              <1> 	; [u.nread] = argument list length
  5997 00008CC0 E8C4440000          <1> 	call	load_and_run_file ; trdosk6.s
  5998 00008CC5 0F8250E0FFFF        <1>         jc      loc_run_cmd_failed
  5999                              <1> loc_load_and_run_file_8: ; 06/05/2016
  6000 00008CCB E94AE9FFFF          <1> 	jmp	loc_file_rw_restore_retn
  6001                              <1> 
  6002                              <1> check_prg_filename_ext:
  6003                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
  6004                              <1> 	; 10/09/2011 
  6005                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'proc_check_exe_filename_ext')
  6006                              <1> 	; 14/11/2009
  6007                              <1> 	; INPUT -> 
  6008                              <1> 	;	ESI = Dot File Name
  6009                              <1> 	; OUTPUT ->
  6010                              <1> 	;     cf = 0 -> EXE_ID in AL
  6011                              <1> 	;	ESI = Last char + 1 position
  6012                              <1> 	;     cf = 1 -> Invalid executable file name
  6013                              <1> 	;	or no file name extension if AH<=8
  6014                              <1> 	;	AL = Last file name char     
  6015                              <1> 	;     cf = 0 -> AL='P' (PRG), AL=0 (no extension)
  6016                              <1> 	;
  6017                              <1> 	; (Modified registers: EAX, ESI)
  6018                              <1>   
  6019 00008CD0 30E4                <1> 	xor	ah, ah
  6020                              <1> loc_run_check_filename_ext:	
  6021 00008CD2 AC                  <1> 	lodsb
  6022 00008CD3 3C21                <1> 	cmp	al, 21h
  6023 00008CD5 7229                <1> 	jb	short loc_check_exe_fn_retn 
  6024 00008CD7 FEC4                <1> 	inc	ah
  6025 00008CD9 3C2E                <1> 	cmp	al, '.'
  6026 00008CDB 75F5                <1> 	jne	short loc_run_check_filename_ext	
  6027                              <1> 		 
  6028                              <1> loc_run_check_filename_ext_dot:
  6029 00008CDD 80FC02              <1> 	cmp	ah, 2 ; .??? is not valid
  6030 00008CE0 88C4                <1> 	mov	ah, al ; '.' 
  6031 00008CE2 7219                <1> 	jb	short loc_check_prg_fn_retn
  6032                              <1> 
  6033                              <1> loc_run_check_filename_ext_dot_ok:
  6034 00008CE4 AC                  <1> 	lodsb
  6035 00008CE5 24DF                <1> 	and	al, 0DFh 
  6036                              <1> 
  6037                              <1> loc_run_check_filename_ext_prg:
  6038 00008CE7 3C50                <1> 	cmp	al, 'P'
  6039 00008CE9 7212                <1> 	jb	short loc_check_prg_fn_retn
  6040 00008CEB 7711                <1> 	ja	short loc_check_prg_fn_stc
  6041 00008CED AC                  <1> 	lodsb
  6042 00008CEE 24DF                <1> 	and	al, 0DFh 
  6043 00008CF0 3C52                <1> 	cmp	al, 'R'
  6044 00008CF2 750A                <1> 	jne	short loc_check_prg_fn_stc
  6045 00008CF4 AC                  <1> 	lodsb
  6046 00008CF5 24DF                <1> 	and	al, 0DFh
  6047 00008CF7 3C47                <1> 	cmp	al, 'G'
  6048 00008CF9 7503                <1> 	jne	short loc_check_prg_fn_stc
  6049                              <1> 
  6050 00008CFB B050                <1> 	mov	al, 'P'
  6051                              <1> loc_check_prg_fn_retn:
  6052 00008CFD C3                  <1> 	retn
  6053                              <1> 
  6054                              <1> loc_check_prg_fn_stc:
  6055 00008CFE F9                  <1> 	stc
  6056 00008CFF C3                  <1> 	retn
  6057                              <1>  
  6058                              <1> loc_check_exe_fn_retn:
  6059 00008D00 28C0                <1> 	sub	al, al ; 0
  6060 00008D02 C3                  <1> 	retn
  6061                              <1>               
  6062                              <1> find_and_list_files:
  6063 00008D03 C3                  <1> 	retn
  6064                              <1> set_exec_arguments:
  6065 00008D04 C3                  <1> 	retn
  6066                              <1> delete_fs_directory:
  6067 00008D05 31C0                <1> 	xor eax, eax
  6068 00008D07 C3                  <1> 	retn
  1921                                  %include 'trdosk4.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - Directory Functions : trdosk4.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 13/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; DIR.ASM (09/10/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> 
    14                              <1> ; DIR.ASM  [ TRDOS KERNEL - COMMAND EXECUTER SECTION - DIRECTORY FUNCTIONS ]
    15                              <1> ; (c) 2004-2010  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/10/2011
    16                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
    17                              <1> 
    18                              <1> change_prompt_dir_string:
    19                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
    20                              <1> 	; 27/03/2011
    21                              <1> 	; 09/10/2009
    22                              <1> 	; INPUT/OUTPUT => none
    23                              <1> 	; this procedure changes current directory string/text  
    24                              <1> 	; 2005
    25                              <1> 
    26 00008D08 BF[92200100]        <1> 	mov	edi, Current_Directory
    27 00008D0D 8A25[8C200100]      <1> 	mov	ah, [Current_Dir_Level]
    28 00008D13 BE[EF280100]        <1> 	mov	esi, PATH_Array
    29 00008D18 E807000000          <1> 	call	set_current_directory_string
    30 00008D1D 880D[ED200100]      <1> 	mov	[Current_Dir_StrLen], cl
    31                              <1> 
    32 00008D23 C3                  <1> 	retn
    33                              <1> 
    34                              <1> set_current_directory_string:
    35                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
    36                              <1> 	; 27/03/2011
    37                              <1> 	; 09/10/2009
    38                              <1> 	; INPUT:
    39                              <1> 	;    ESI = Path Array Address 
    40                              <1> 	;    EDI = Current Directory String Buffer
    41                              <1> 	;    AH = Current Directory Level
    42                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
    43                              <1> 	;    EDI will be same with input
    44                              <1> 	;    ECX = Current Directory String Length 
    45                              <1> 
    46 00008D24 57                  <1> 	push    edi
    47 00008D25 80FC00              <1> 	cmp     ah, 0
    48 00008D28 7652                <1> 	jna	short pass_write_path
    49 00008D2A 83C610              <1> 	add	esi, 16
    50 00008D2D 89F3                <1> 	mov	ebx, esi
    51                              <1> loc_write_path:
    52 00008D2F B908000000          <1> 	mov	ecx, 8
    53                              <1> path_write_dirname1:
    54 00008D34 AC                  <1> 	lodsb
    55 00008D35 3C20                <1> 	cmp	al, 20h
    56 00008D37 7612                <1> 	jna	short pass_write_dirname1
    57 00008D39 AA                  <1> 	stosb
    58 00008D3A 81FF[EC200100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    59 00008D40 733A                <1> 	jnb	short pass_write_path
    60 00008D42 E2F0                <1> 	loop	path_write_dirname1
    61 00008D44 803E20              <1> 	cmp	byte [esi], 20h
    62 00008D47 7624                <1> 	jna	short pass_write_dirname2
    63 00008D49 EB0A                <1> 	jmp     short loc_put_dot_cont_ext
    64                              <1> pass_write_dirname1:
    65 00008D4B 89DE                <1> 	mov	esi, ebx
    66 00008D4D 83C608              <1> 	add	esi, 8
    67 00008D50 803E20              <1> 	cmp	byte [esi], 20h
    68 00008D53 7618                <1> 	jna	short pass_write_dirname2
    69                              <1> loc_put_dot_cont_ext:
    70 00008D55 C6072E              <1> 	mov	byte [edi], "."
    71                              <1> 	;mov	ecx, 3
    72 00008D58 B103                <1> 	mov	cl, 3
    73                              <1> loc_check_dir_name_ext:
    74 00008D5A AC                  <1> 	lodsb
    75 00008D5B 47                  <1> 	inc	edi
    76 00008D5C 3C20                <1> 	cmp	al, 20h
    77 00008D5E 760D                <1> 	jna	short pass_write_dirname2
    78 00008D60 8807                <1> 	mov	[edi], al
    79 00008D62 81FF[EC200100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    80 00008D68 7312                <1> 	jnb	short pass_write_path
    81 00008D6A E2EE                <1> 	loop    loc_check_dir_name_ext
    82 00008D6C 47                  <1> 	inc	edi
    83                              <1> pass_write_dirname2:
    84 00008D6D FECC                <1> 	dec	ah
    85 00008D6F 740B                <1> 	jz      short pass_write_path
    86 00008D71 83C310              <1> 	add	ebx, 16
    87 00008D74 89DE                <1> 	mov	esi, ebx
    88 00008D76 C6072F              <1> 	mov	byte [edi],"/"
    89 00008D79 47                  <1> 	inc	edi
    90 00008D7A EBB3                <1> 	jmp	short loc_write_path
    91                              <1> pass_write_path:
    92 00008D7C C60700              <1> 	mov	byte [edi], 0
    93 00008D7F 47                  <1> 	inc	edi
    94 00008D80 89F9                <1> 	mov	ecx, edi
    95 00008D82 5F                  <1> 	pop	edi
    96 00008D83 29F9                <1> 	sub	ecx, edi
    97                              <1> 	; ECX = Current Directory String Length
    98 00008D85 C3                  <1> 	retn
    99                              <1> 
   100                              <1> get_current_directory:
   101                              <1> 	; 14/02/2016
   102                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
   103                              <1> 	; 27/03/2011
   104                              <1> 	;
   105                              <1> 	; INPUT-> ESI = Current Directory Buffer
   106                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
   107                              <1> 	;              (0= Default/Current Drive)
   108                              <1> 	;           
   109                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
   110                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
   111                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
   112                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
   113                              <1> 	;            CX/CL = Current Directory String Length
   114                              <1> 	;	     DL = Drive Number (0 based)
   115                              <1> 	;            (If input is 0, output is current drv number) 
   116                              <1> 	;            DH = same with input 
   117                              <1> 	;   cf = 0 -> AL = 0
   118                              <1> 	;   cf = 1 -> error code in AL 
   119                              <1>               
   120                              <1> loc_get_current_drive_0:
   121 00008D86 80FA00              <1> 	cmp	dl, 0
   122 00008D89 7708                <1> 	ja	short loc_get_current_drive_1
   123 00008D8B 8A15[8E200100]      <1> 	mov	dl, [Current_Drv]
   124 00008D91 EB17                <1> 	jmp	short loc_get_current_drive_2
   125                              <1> loc_get_current_drive_1:
   126 00008D93 FECA                <1> 	dec 	dl
   127 00008D95 3A15[07DE0000]      <1> 	cmp	dl, [Last_DOS_DiskNo]
   128 00008D9B 760D                <1> 	jna	short loc_get_current_drive_2
   129 00008D9D B80F000000          <1> 	mov	eax, 0Fh ; Invalid drive
   130 00008DA2 F5                  <1> 	cmc 	; stc
   131 00008DA3 C3                  <1> 	retn
   132                              <1> 
   133                              <1> loc_get_current_drive_not_ready_retn:
   134 00008DA4 5E                  <1> 	pop	esi
   135                              <1> 	;mov	eax, 15h
   136 00008DA5 66B81500            <1> 	mov	ax, 15h ; Drive not ready
   137 00008DA9 C3                  <1> 	retn  
   138                              <1>  
   139                              <1> loc_get_current_drive_2:
   140 00008DAA 31C0                <1> 	xor	eax, eax
   141 00008DAC 88D4                <1> 	mov	ah, dl
   142 00008DAE 56                  <1> 	push	esi
   143 00008DAF BE00010900          <1> 	mov	esi, Logical_DOSDisks
   144 00008DB4 01C6                <1> 	add	esi, eax
   145 00008DB6 8A06                <1> 	mov	al, [esi+LD_Name] 
   146 00008DB8 3C41                <1> 	cmp	al, 'A'
   147 00008DBA 72E8                <1> 	jb	short loc_get_current_drive_not_ready_retn
   148                              <1> 
   149 00008DBC 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   150 00008DBF 08E4                <1> 	or	ah, ah
   151 00008DC1 7506                <1> 	jnz	short loc_get_current_drive_3
   152                              <1> 
   153                              <1> 	;xor	ah, ah ; mov ah, 0
   154 00008DC3 8826                <1> 	mov	[esi], ah
   155 00008DC5 31C9                <1> 	xor	ecx, ecx
   156 00008DC7 EB1C                <1> 	jmp	short loc_get_current_drive_4
   157                              <1> 
   158                              <1> loc_get_current_drive_3:
   159 00008DC9 BF[EF280100]        <1>         mov     edi, PATH_Array
   160 00008DCE 57                  <1> 	push	edi
   161 00008DCF 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   162 00008DD5 B920000000          <1> 	mov	ecx, 32
   163 00008DDA F3A5                <1> 	rep	movsd
   164 00008DDC 5E                  <1> 	pop	esi ; Path Array Address
   165 00008DDD 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset) 
   166                              <1> 	;
   167 00008DDE E841FFFFFF          <1> 	call	set_current_directory_string
   168 00008DE3 89FE                <1> 	mov	esi, edi
   169                              <1> 
   170                              <1> loc_get_current_drive_4:
   171 00008DE5 30C0                <1> 	xor	al, al
   172 00008DE7 C3                  <1> 	retn
   173                              <1> 
   174                              <1> change_current_directory:
   175                              <1> 	; 19/02/2016
   176                              <1> 	; 11/02/2016
   177                              <1> 	; 10/02/2016
   178                              <1> 	; 08/02/2016
   179                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   180                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)	
   181                              <1> 	; 04/10/2009
   182                              <1> 	; 2005
   183                              <1> 	; INPUT -> 
   184                              <1> 	;	ESI = Directory string
   185                              <1> 	;	ah = CD command (CDh = save current dir string)
   186                              <1> 	; OUTPUT -> 
   187                              <1> 	; 	EDI = DOS Drive Description Table
   188                              <1> 	; 	cf = 1 -> error
   189                              <1> 	;	   EAX = Error code
   190                              <1> 	;	cf = 0 -> succesful
   191                              <1> 	;	   ESI = PATH_Array
   192                              <1> 	;	   EAX = Current Directory First Cluster
   193                              <1> 	;
   194                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
   195                              <1> 	
   196 00008DE8 8825[7D290100]      <1> 	mov	[CD_COMMAND], ah
   197 00008DEE 803E2F              <1> 	cmp	byte [esi], '/'
   198 00008DF1 7505                <1> 	jne	short loc_ccd_cdir_level
   199 00008DF3 46                  <1> 	inc	esi
   200 00008DF4 30C0                <1> 	xor	al, al
   201 00008DF6 EB05                <1> 	jmp	short loc_ccd_parse_path_name
   202                              <1> loc_ccd_cdir_level:
   203 00008DF8 A0[8C200100]        <1> 	mov	al, [Current_Dir_Level]
   204                              <1> loc_ccd_parse_path_name:
   205 00008DFD 88C4                <1> 	mov	ah, al
   206 00008DFF BF[EF280100]        <1> 	mov	edi, PATH_Array
   207                              <1> 
   208                              <1> ; Reset directory levels > cdir level
   209                              <1> 	; is this required !?
   210                              <1> 	;
   211                              <1> 	; Relations:
   212                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
   213                              <1> 	; proc_parse_dir_name,
   214                              <1> 	; proc_change_current_directory (this procedure)
   215                              <1> 	; proc_change_prompt_dir_string 
   216                              <1>  
   217 00008E04 0FB6C8              <1> 	movzx	ecx, al
   218 00008E07 FEC1                <1> 	inc	cl
   219 00008E09 C0E104              <1> 	shl	cl, 4
   220 00008E0C 01CF                <1> 	add	edi, ecx
   221 00008E0E B107                <1> 	mov	cl, 7
   222 00008E10 28C1                <1> 	sub	cl, al
   223 00008E12 C0E102              <1> 	shl	cl, 2
   224 00008E15 89C3                <1> 	mov	ebx, eax
   225 00008E17 31C0                <1> 	xor	eax, eax ; 0
   226 00008E19 F3AB                <1> 	rep	stosd
   227 00008E1B 89D8                <1> 	mov	eax, ebx
   228                              <1> 
   229 00008E1D BF[EF280100]        <1> 	mov	edi, PATH_Array
   230                              <1> 
   231 00008E22 803E20              <1> 	cmp	byte [esi], 20h
   232 00008E25 F5                  <1> 	cmc
   233 00008E26 7305                <1> 	jnc	short pass_ccd_parse_dir_name
   234                              <1> 
   235                              <1> 		; ESI = Path name
   236                              <1> 		; AL = CCD_Level
   237 00008E28 E872010000          <1>         call    parse_dir_name
   238                              <1> 		; AL = CCD_Level 
   239                              <1> 		; AH = Last_Dir_Level
   240                              <1> 		; (EDI = PATH_Array)
   241                              <1> 
   242                              <1> pass_ccd_parse_dir_name:
   243 00008E2D 9C                  <1> 	pushf
   244                              <1> 
   245                              <1> 	;mov	[CCD_Level], al
   246                              <1>         ;mov	[Last_Dir_Level], ah
   247 00008E2E 66A3[73290100]      <1> 	mov	[CCD_Level], ax
   248                              <1> 
   249 00008E34 31DB                <1> 	xor	ebx, ebx
   250 00008E36 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
   251 00008E3C BE00010900          <1> 	mov	esi, Logical_DOSDisks
   252 00008E41 01DE                <1> 	add	esi, ebx
   253                              <1> 
   254 00008E43 9D                  <1> 	popf 
   255 00008E44 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
   256                              <1> 
   257 00008E46 8935[6F290100]      <1> 	mov	[CCD_DriveDT], esi
   258                              <1> 
   259 00008E4C 3C07                <1> 	cmp	al, 7
   260 00008E4E 7209                <1> 	jb	short loc_ccd_load_child_dir
   261                              <1> 
   262                              <1> loc_ccd_bad_path_name_retn:
   263 00008E50 87F7                <1> 	xchg	esi, edi
   264                              <1> 	; DOS Error Code 
   265 00008E52 B818000000          <1> 	mov	eax, 18h ; Bad request structure length 
   266 00008E57 F9                  <1> 	stc
   267                              <1> loc_ccd_retn_p:
   268 00008E58 C3                  <1> 	retn
   269                              <1> 
   270                              <1> loc_ccd_load_child_dir:
   271                              <1> 	; AL = CCD_Level
   272 00008E59 08C0                <1> 	or	al, al
   273 00008E5B 7468                <1> 	jz	short loc_ccd_load_root_dir
   274                              <1> 
   275 00008E5D 6689C1              <1> 	mov	cx, ax
   276 00008E60 C0E004              <1> 	shl	al, 4
   277 00008E63 0FB6F0              <1> 	movzx	esi, al
   278 00008E66 01FE                <1>      	add	esi, edi  ; offset PATH_Array
   279                              <1> 
   280 00008E68 8B460C              <1> 	mov	eax, [esi+12]
   281 00008E6B 38E9                <1> 	cmp	cl, ch
   282 00008E6D 0F84FA000000        <1>         je      loc_ccd_load_sub_directory
   283 00008E73 A3[88200100]        <1> 	mov	[Current_Dir_FCluster], eax
   284                              <1> 
   285                              <1> loc_ccd_load_child_dir_next:
   286 00008E78 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
   287                              <1> 
   288                              <1>  	; Directory attribute : 10h
   289 00008E7B B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
   290                              <1> 	;mov	ah, 11001000b ; C8h
   291                              <1> 	; Volume name attribute: 8h
   292 00008E7D B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
   293                              <1> 
   294 00008E7F 6631C9              <1> 	xor	cx, cx  
   295 00008E82 E8B5010000          <1> 	call	locate_current_dir_file
   296 00008E87 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
   297                              <1> 
   298                              <1> 	 ; 19/02/2016
   299                              <1> 	;mov	edi, [CCD_DriveDT]
   300 00008E89 8A25[73290100]      <1> 	mov	ah, [CCD_Level]
   301 00008E8F 803D[7D290100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   302 00008E96 7509                <1> 	jne	short loc_ccd_load_child_dir_err
   303                              <1> 	; It is better to save recent successful part 
   304                              <1> 	; of the (requested) path as current directory.
   305                              <1> 	; (Otherwise the path would be reset to back
   306                              <1> 	; on the next 'CD' command.)
   307 00008E98 88E1                <1> 	mov	cl, ah
   308 00008E9A 50                  <1> 	push	eax
   309 00008E9B E8E3000000          <1> 	call	loc_ccd_save_current_dir
   310 00008EA0 58                  <1> 	pop	eax
   311                              <1> loc_ccd_load_child_dir_err:            
   312 00008EA1 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
   313 00008EA3 7202                <1> 	jb	short loc_ccd_path_not_found_retn
   314 00008EA5 F9                  <1> 	stc
   315 00008EA6 C3                  <1> 	retn
   316                              <1> 
   317                              <1> loc_ccd_path_not_found_retn:
   318 00008EA7 B003                <1> 	mov	al, 3	; Path not found
   319 00008EA9 C3                  <1> 	retn
   320                              <1> 
   321                              <1> loc_ccd_load_FAT_root_dir:
   322 00008EAA 803D[8D200100]02    <1> 	cmp	byte [Current_FATType], 2
   323 00008EB1 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
   324                              <1> 
   325                              <1> 	;mov	esi, [CCD_DriveDT]
   326                              <1> 	;push	esi
   327 00008EB3 E8961D0000          <1> 	call	load_FAT_root_directory
   328                              <1> 	;pop	edi ; Dos Drv Description Table
   329                              <1> 
   330 00008EB8 89F7                <1> 	mov	edi, esi
   331 00008EBA BE[EF280100]        <1> 	mov	esi, PATH_Array
   332 00008EBF 7297                <1> 	jc	short loc_ccd_retn_p
   333                              <1> 
   334 00008EC1 31C0                <1> 	xor	eax, eax
   335 00008EC3 EB78                <1>         jmp	short loc_ccd_set_cdfc
   336                              <1> 
   337                              <1> loc_ccd_load_root_dir:
   338 00008EC5 803D[8D200100]01    <1> 	cmp	byte [Current_FATType], 1
   339 00008ECC 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
   340                              <1> 
   341                              <1> loc_ccd_load_FS_root_dir:
   342 00008ECE E8421E0000          <1> 	call	load_FS_root_directory
   343 00008ED3 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
   344                              <1> 
   345                              <1> loc_ccd_load_FS_sub_directory_next:
   346 00008ED5 E83C1E0000          <1> 	call	load_FS_sub_directory
   347 00008EDA EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr  
   348                              <1> 
   349                              <1> loc_ccd_set_dir_cluster_ptr:
   350                              <1> 	; EDI = Directory Entry
   351 00008EDC 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
   352 00008EE0 C1E010              <1> 	shl	eax, 16
   353 00008EE3 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
   354                              <1> 
   355 00008EE7 8B35[6F290100]      <1> 	mov	esi, [CCD_DriveDT]
   356 00008EED 803D[8D200100]01    <1> 	cmp	byte [Current_FATType], 1
   357 00008EF4 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
   358                              <1> 	;push	esi
   359 00008EF6 E8DE1D0000          <1> 	call	load_FAT_sub_directory
   360                              <1> 	;pop	edi ; Dos Drv Description Table
   361                              <1> 
   362                              <1> pass_ccd_set_dir_cluster_ptr:
   363                              <1> 	;mov	edi, esi
   364 00008EFB BE[EF280100]        <1> 	mov	esi, PATH_Array
   365 00008F00 7264                <1> 	jc	short loc_ccd_retn_c
   366                              <1> 
   367 00008F02 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
   368                              <1> 
   369 00008F07 FE05[73290100]      <1> 	inc	byte [CCD_Level]
   370 00008F0D 0FB61D[73290100]    <1> 	movzx	ebx, byte [CCD_Level]
   371 00008F14 C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)   
   372 00008F17 01DE                <1> 	add	esi, ebx ; 19/02/2016
   373 00008F19 89460C              <1> 	mov	[esi+12], eax
   374 00008F1C EB1F                <1> 	jmp	short loc_ccd_set_cdfc
   375                              <1> 
   376                              <1> loc_ccd_load_FAT32_root_dir:
   377 00008F1E BE[EF280100]        <1> 	mov	esi, PATH_Array
   378 00008F23 8B460C              <1> 	mov	eax, [esi+12]
   379 00008F26 8B35[6F290100]      <1> 	mov	esi, [CCD_DriveDT]
   380                              <1>  
   381                              <1> loc_ccd_load_FAT_sub_directory:
   382                              <1> 	;push	esi
   383 00008F2C E8A81D0000          <1> 	call	load_FAT_sub_directory
   384                              <1> 	;pop	edi ; Dos Drv Description Table
   385                              <1> 
   386                              <1> pass_ccd_load_FAT_sub_directory:
   387                              <1> 	;mov	edi, esi
   388 00008F31 BE[EF280100]        <1> 	mov	esi, PATH_Array
   389 00008F36 722E                <1> 	jc	short loc_ccd_retn_c
   390                              <1> 
   391 00008F38 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
   392                              <1> 
   393                              <1> loc_ccd_set_cdfc:
   394 00008F3D 8A0D[73290100]      <1> 	mov	cl, [CCD_Level]
   395 00008F43 880D[8C200100]      <1> 	mov	[Current_Dir_Level], cl
   396 00008F49 A3[88200100]        <1> 	mov	[Current_Dir_FCluster], eax
   397                              <1> 
   398 00008F4E 8A2D[74290100]      <1> 	mov	ch, [Last_Dir_Level]
   399 00008F54 38E9                <1> 	cmp	cl, ch 
   400 00008F56 0F821CFFFFFF        <1> 	jb	loc_ccd_load_child_dir_next
   401                              <1> 	
   402 00008F5C 803D[7D290100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   403 00008F63 741E                <1> 	je	short loc_ccd_save_current_dir
   404                              <1> 
   405                              <1>         ; jne -> don't save, restore (the previous cdir) later !
   406                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
   407                              <1> 
   408 00008F65 F8                  <1> 	clc
   409                              <1> 
   410                              <1> loc_ccd_retn_c:
   411 00008F66 8B3D[6F290100]      <1> 	mov	edi, [CCD_DriveDT]
   412 00008F6C C3                  <1> 	retn
   413                              <1> 
   414                              <1> loc_ccd_load_sub_directory:
   415 00008F6D 8B35[6F290100]      <1> 	mov	esi, [CCD_DriveDT]
   416 00008F73 803D[8D200100]01    <1> 	cmp	byte [Current_FATType], 1
   417 00008F7A 73B0                <1> 	jnb	short loc_ccd_load_FAT_sub_directory 
   418 00008F7C E8951D0000          <1> 	call	load_FS_sub_directory
   419 00008F81 EBAE                <1> 	jmp	short pass_ccd_load_FAT_sub_directory 
   420                              <1> 
   421                              <1> loc_ccd_save_current_dir:
   422 00008F83 BE[EF280100]        <1> 	mov	esi, PATH_Array ; 19/02/2016
   423 00008F88 8B3D[6F290100]      <1> 	mov	edi, [CCD_DriveDT]
   424 00008F8E 57                  <1> 	push	edi
   425 00008F8F 83C77F              <1>         add     edi, LD_CDirLevel
   426 00008F92 880F                <1> 	mov	[edi], cl
   427 00008F94 47                  <1> 	inc	edi ; LD_CurrentDirectory 
   428 00008F95 56                  <1> 	push	esi
   429                              <1> 	;mov	ecx, 32  ; always < 65536 (in this procedure)
   430 00008F96 66B92000            <1> 	mov	cx, 32
   431 00008F9A F3A5                <1> 	rep	movsd
   432                              <1> 	; Current directory has been saved to 
   433                              <1> 	; the DOS drive description table, cdir area !
   434 00008F9C 5E                  <1> 	pop	esi  ; PATH_Array
   435 00008F9D 5F                  <1> 	pop	edi  ; Dos Drv Description Table
   436                              <1> 
   437 00008F9E C3                  <1> 	retn
   438                              <1> 
   439                              <1> parse_dir_name:
   440                              <1> 	; 11/02/2016
   441                              <1> 	; 10/02/2016
   442                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
   443                              <1> 	; 18/09/2011
   444                              <1> 	; 17/10/2009
   445                              <1> 	; INPUT ->
   446                              <1> 	;	ESI = ASCIIZ Directory String Address
   447                              <1> 	;	AL = Current Directory Level
   448                              <1> 	;	EDI = Destination Adress
   449                              <1> 	;	     (8 levels, each one 12+4 byte)
   450                              <1> 	; OUTPUT ->
   451                              <1> 	;	EDI = Dir Entry Formatted Array
   452                              <1> 	;	     with zero cluster pointer at the last level
   453                              <1> 	;	AH = Last Dir Level
   454                              <1> 	;	AL = Current Dir Level
   455                              <1> 	;
   456                              <1> 	; (esi, ebx, ecx will be changed) 
   457                              <1> 
   458                              <1> 	;mov	[PATH_Array_Ptr], edi
   459 00008F9F 88C4                <1> 	mov	ah, al
   460 00008FA1 66A3[142A0100]      <1> 	mov	[PATH_CDLevel], ax
   461                              <1> repeat_ppdn_check_slash:
   462 00008FA7 AC                  <1> 	lodsb
   463 00008FA8 3C2F                <1> 	cmp	al, '/'
   464 00008FAA 74FB                <1> 	je	short repeat_ppdn_check_slash
   465 00008FAC 3C21                <1> 	cmp	al, 21h
   466 00008FAE 7219                <1> 	jb	short loc_ppdn_retn
   467 00008FB0 57                  <1> 	push	edi
   468                              <1> loc_ppdn_get_dir_name:
   469 00008FB1 B90C000000          <1> 	mov	ecx, 12
   470 00008FB6 BF[162A0100]        <1> 	mov	edi, Dir_File_Name
   471                              <1> repeat_ppdn_get_dir_name:
   472 00008FBB AA                  <1> 	stosb
   473 00008FBC AC                  <1> 	lodsb
   474 00008FBD 3C2F                <1> 	cmp	al, '/'
   475 00008FBF 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
   476 00008FC1 3C20                <1> 	cmp	al, 20h
   477 00008FC3 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
   478 00008FC5 E2F4                <1> 	loop	repeat_ppdn_get_dir_name
   479 00008FC7 5F                  <1> 	pop	edi
   480 00008FC8 F9                  <1> 	stc
   481                              <1> loc_ppdn_retn:
   482 00008FC9 C3                  <1> 	retn
   483                              <1> 
   484                              <1> loc_ppdn_end_of_path_scan:
   485 00008FCA 4E                  <1> 	dec	esi
   486                              <1> loc_check_level_dot_conv_dir_name:
   487 00008FCB 31C0                <1> 	xor	eax, eax
   488 00008FCD AA                  <1> 	stosb
   489 00008FCE 89F3                <1> 	mov	ebx, esi
   490 00008FD0 BE[162A0100]        <1> 	mov	esi, Dir_File_Name
   491 00008FD5 AC                  <1> 	lodsb
   492                              <1> repeat_ppdn_name_check_dot:
   493 00008FD6 3C2E                <1> 	cmp	al, '.'
   494 00008FD8 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
   495                              <1> repeat_ppdn_name_dot_dot:
   496 00008FDA AC                  <1> 	lodsb
   497 00008FDB 3C2E                <1> 	cmp	al, '.'
   498 00008FDD 743E                <1> 	je	short loc_ppdn_dot_dot
   499 00008FDF 3C21                <1> 	cmp	al, 21h
   500 00008FE1 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
   501                              <1> loc_ppdn_convert_sub_dir_name:
   502 00008FE3 8A25[152A0100]      <1> 	mov	ah, [PATH_Level]
   503 00008FE9 80FC07              <1> 	cmp	ah, 7
   504 00008FEC 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
   505 00008FEE FEC4                <1> 	inc	ah  
   506 00008FF0 8825[152A0100]      <1> 	mov	[PATH_Level], ah
   507 00008FF6 BE[162A0100]        <1> 	mov	esi, Dir_File_Name
   508                              <1> 	;mov	edi, [PATH_Array_Ptr]
   509 00008FFB B010                <1> 	mov	al, 16
   510 00008FFD F6E4                <1> 	mul	ah
   511 00008FFF 8B3C24              <1> 	mov	edi, [esp]
   512                              <1> 	;push	edi 
   513 00009002 01C7                <1> 	add	edi, eax
   514 00009004 E828030000          <1> 	call	convert_file_name
   515                              <1> 	;pop	edi
   516                              <1> pass_ppdn_convert_sub_dir_name:
   517 00009009 89DE                <1> 	mov	esi, ebx
   518                              <1> repeat_ppdn_check_last_slash:
   519 0000900B AC                  <1> 	lodsb
   520 0000900C 3C2F                <1> 	cmp	al, '/'
   521 0000900E 74FB                <1> 	je	short repeat_ppdn_check_last_slash
   522 00009010 3C21                <1> 	cmp	al, 21h
   523 00009012 739D                <1> 	jnb	short loc_ppdn_get_dir_name
   524                              <1> end_of_parse_dir_name:
   525 00009014 5F                  <1> 	pop	edi
   526 00009015 F5                  <1> 	cmc  
   527                              <1> 	;mov	al, [PATH_CDLevel]
   528                              <1> 	;mov	ah, [PATH_Level]
   529 00009016 66A1[142A0100]      <1> 	mov	ax, [PATH_CDLevel]
   530 0000901C C3                  <1> 	retn
   531                              <1> 
   532                              <1> loc_ppdn_dot_dot:
   533 0000901D AC                  <1> 	lodsb
   534 0000901E 3C21                <1> 	cmp	al, 21h
   535 00009020 73F2                <1> 	jnb	short end_of_parse_dir_name 
   536                              <1> loc_ppdn_dot_dot_prev_level:
   537 00009022 66A1[142A0100]      <1> 	mov	ax, [PATH_CDLevel]
   538 00009028 80EC01              <1> 	sub	ah, 1
   539 0000902B 80D400              <1> 	adc	ah, 0
   540 0000902E 38E0                <1> 	cmp	al, ah
   541 00009030 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
   542 00009032 88E0                <1> 	mov	al, ah
   543                              <1> pass_ppdn_set_al_to_ah:
   544 00009034 66A3[142A0100]      <1> 	mov	[PATH_CDLevel], ax
   545 0000903A EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
   546                              <1> 
   547                              <1> locate_current_dir_file:
   548                              <1> 	; 14/02/2016
   549                              <1> 	; 13/02/2016
   550                              <1> 	; 10/02/2016
   551                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   552                              <1> 	; 14/08/2010
   553                              <1> 	; 19/09/2009
   554                              <1>         ; 2005
   555                              <1> 	; INPUT ->
   556                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   557                              <1> 	;	AL = Attributes Mask 
   558                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   559                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   560                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   561                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   562                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   563                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   564                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   565                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
   566                              <1> 	;	     proper entry (which fits with Atributes Masks)
   567                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
   568                              <1> 	;	? = Any One Char
   569                              <1> 	;	* = Every Chars
   570                              <1> 	; OUTPUT ->
   571                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
   572                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   573                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   574                              <1> 	;	DL = Attributes
   575                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   576                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   577                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   578                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   579                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   580                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
   581                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   582                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   583                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   584                              <1> 	;	CF = 0 -> 
   585                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
   586                              <1> 
   587                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
   588                              <1> 
   589 0000903C 8935[77290100]      <1> 	mov	[CDLF_FNAddress], esi
   590 00009042 66A3[75290100]      <1> 	mov	[CDLF_AttributesMask], ax
   591 00009048 66890D[7B290100]    <1> 	mov	[CDLF_DEType], cx
   592                              <1> 
   593 0000904F 31DB                <1> 	xor	ebx, ebx
   594 00009051 881D[8C290100]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
   595                              <1> 
   596 00009057 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
   597 0000905D 381D[B8280100]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
   598 00009063 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
   599 00009065 8A1D[B6280100]      <1>         mov     bl, [DirBuff_DRV]
   600 0000906B 80EB41              <1> 	sub	bl, 'A'
   601 0000906E 38DF                <1> 	cmp	bh, bl
   602 00009070 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
   603 00009072 8B15[BD280100]      <1> 	mov	edx, [DirBuff_Cluster]
   604 00009078 3B15[88200100]      <1> 	cmp	edx, [Current_Dir_FCluster]
   605 0000907E 7412                <1> 	je	short loc_cdir_locatefile_search
   606                              <1> 
   607                              <1> loc_lcdf_reload_current_dir1:
   608 00009080 30DB                <1> 	xor	bl, bl
   609                              <1> loc_lcdf_reload_current_dir2:
   610 00009082 89DE                <1> 	mov	esi, ebx
   611 00009084 81C600010900        <1>         add     esi, Logical_DOSDisks
   612 0000908A E872000000          <1> 	call	reload_current_directory 
   613 0000908F 735B                <1> 	jnc	short loc_locatefile_search_again 
   614 00009091 C3                  <1> 	retn  
   615                              <1> 
   616                              <1> loc_cdir_locatefile_search:
   617 00009092 31DB                <1> 	xor	ebx, ebx
   618 00009094 E8A5000000          <1> 	call	find_directory_entry
   619 00009099 7349                <1> 	jnc	short loc_cdir_locate_file_retn
   620                              <1> 
   621                              <1> loc_locatefile_check_stc_reason:
   622 0000909B 08ED                <1> 	or	ch, ch
   623 0000909D 7444                <1> 	jz	short loc_cdir_locate_file_stc_retn
   624                              <1> 
   625                              <1> loc_locatefile_check_next_entryblock:
   626 0000909F 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
   627 000090A5 28DB                <1> 	sub	bl, bl
   628 000090A7 0FB7F3              <1> 	movzx	esi, bx
   629 000090AA 81C600010900        <1>         add     esi, Logical_DOSDisks
   630                              <1> 
   631 000090B0 803D[8C200100]00    <1> 	cmp	byte [Current_Dir_Level], 0
   632 000090B7 760A                <1> 	jna	short loc_locatefile_check_FAT_type
   633                              <1>             
   634 000090B9 803D[8D200100]01    <1> 	cmp	byte [Current_FATType], 1
   635 000090C0 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
   636 000090C2 C3                  <1> 	retn  
   637                              <1> 
   638                              <1> loc_locatefile_check_FAT_type:
   639 000090C3 803D[8D200100]03    <1> 	cmp	byte [Current_FATType], 3
   640 000090CA 7218                <1> 	jb	short loc_cdir_locate_file_retn
   641                              <1> 
   642                              <1> loc_locatefile_load_subdir_cluster:
   643 000090CC A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
   644 000090D1 E81D1A0000          <1> 	call	get_next_cluster
   645 000090D6 730D                <1> 	jnc	short loc_locatefile_next_cluster
   646 000090D8 09C0                <1> 	or	eax, eax
   647 000090DA 7507                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
   648 000090DC F9                  <1> 	stc
   649                              <1> loc_locatefile_file_notfound:
   650 000090DD B802000000          <1> 	mov	eax, 2 ; File/Directory/VolName not found
   651 000090E2 C3                  <1> 	retn
   652                              <1> 
   653                              <1> loc_locatefile_drive_not_ready_read_err:
   654                              <1> 	;mov	eax, 15h ;Drive not ready or read error
   655                              <1> loc_cdir_locate_file_stc_retn:
   656 000090E3 F5                  <1> 	cmc ;stc
   657                              <1> loc_cdir_locate_file_retn:
   658 000090E4 C3                  <1> 	retn
   659                              <1> 
   660                              <1> loc_locatefile_next_cluster:
   661 000090E5 E8EF1B0000          <1> 	call	load_FAT_sub_directory
   662                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
   663 000090EA 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
   664                              <1> 
   665                              <1> loc_locatefile_search_again:
   666 000090EC 8B35[77290100]      <1> 	mov	esi, [CDLF_FNAddress] 
   667 000090F2 66A1[75290100]      <1> 	mov	ax, [CDLF_AttributesMask]
   668 000090F8 668B0D[7B290100]    <1> 	mov	cx, [CDLF_DEType] 
   669 000090FF EB91                <1> 	jmp	short loc_cdir_locatefile_search
   670                              <1> 
   671                              <1> reload_current_directory:
   672                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   673                              <1> 	; 13/06/2010
   674                              <1> 	; 22/09/2009
   675                              <1>         ;
   676                              <1> 	; INPUT ->
   677                              <1> 	;	ESI = Dos drive description table address
   678                              <1> 	
   679                              <1> 	;mov	al, [esi+LD_FATType]
   680 00009101 A0[8D200100]        <1> 	mov	al, [Current_FATType]
   681 00009106 3C02                <1> 	cmp	al, 2
   682 00009108 7729                <1> 	ja	short loc_reload_FAT_sub_directory
   683 0000910A 8A25[8C200100]      <1> 	mov	ah, [Current_Dir_Level]
   684 00009110 08C0                <1> 	or	al, al
   685 00009112 740A                <1> 	jz	short loc_reload_FS_directory
   686 00009114 08E4                <1> 	or	ah, ah
   687 00009116 751B                <1> 	jnz	short loc_reload_FAT_sub_directory
   688                              <1> loc_reload_FAT_12_16_root_directory:
   689 00009118 E8311B0000          <1> 	call	load_FAT_root_directory
   690 0000911D C3                  <1> 	retn
   691                              <1> loc_reload_FS_directory:
   692 0000911E 20E4                <1> 	and	ah, ah
   693 00009120 7506                <1> 	jnz	short loc_reload_FS_sub_directory 
   694                              <1> loc_reload_FS_root_directory: 
   695 00009122 E8EE1B0000          <1> 	call	load_FS_root_directory
   696 00009127 C3                  <1> 	retn
   697                              <1> loc_reload_FS_sub_directory:
   698 00009128 A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
   699 0000912D E8E41B0000          <1> 	call	load_FS_sub_directory
   700 00009132 C3                  <1> 	retn 
   701                              <1> loc_reload_FAT_sub_directory:
   702 00009133 A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
   703 00009138 E89C1B0000          <1> 	call	load_FAT_sub_directory
   704 0000913D C3                  <1> 	retn
   705                              <1> 
   706                              <1> find_directory_entry:
   707                              <1> 	; 14/02/2016
   708                              <1> 	; 13/02/2016
   709                              <1> 	; 10/02/2016
   710                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   711                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
   712                              <1> 	; 19/09/2009
   713                              <1> 	; 2005
   714                              <1> 	; INPUT ->
   715                              <1> 	;	ESI = Sub Dir or File Name Address
   716                              <1> 	;	AL = Attributes Mask 
   717                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   718                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   719                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   720                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   721                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   722                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   723                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   724                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
   725                              <1> 	;            proper entry (which fits with Atributes Masks)
   726                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
   727                              <1> 	;	? = Any One Char
   728                              <1> 	;	* = Every Chars
   729                              <1> 	;	EBX = Current Dir Entry (BX)
   730                              <1> 	;
   731                              <1> 	; OUTPUT -> 
   732                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
   733                              <1> 	;	ESI = Sub Dir or File Name Address
   734                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   735                              <1> 	;	DL = Attributes
   736                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   737                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   738                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   739                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   740                              <1> 	;	EBX = CurrentDirEntry (BX)
   741                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   742                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
   743                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   744                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   745                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   746                              <1> 	;
   747                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)	 
   748                              <1> 
   749 0000913E 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   750 00009145 0F8739010000        <1>         ja      loc_ffde_stc_retn_255
   751                              <1> 
   752                              <1> 	;mov    [DirBuff_CurrentEntry], bx  
   753                              <1> 
   754 0000914B BF00000800          <1>   	mov	edi, Directory_Buffer
   755 00009150 66A3[88290100]      <1> 	mov	[FDE_AttrMask], ax
   756                              <1> 
   757 00009156 29C0                <1> 	sub	eax, eax
   758                              <1>             
   759                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
   760 00009158 66A3[8A290100]      <1> 	mov	[AmbiguousFileName], ax ; 0
   761                              <1> 
   762 0000915E 6689D8              <1> 	mov	ax, bx
   763 00009161 66C1E005            <1> 	shl	ax, 5 ; ; * 32 ; Directory entry size
   764 00009165 01C7                <1> 	add     edi, eax
   765                              <1> 
   766 00009167 08ED                <1> 	or	ch, ch
   767 00009169 0F852C010000        <1>         jnz     loc_find_free_deleted_entry_0
   768                              <1> 
   769 0000916F 08C9                <1> 	or      cl, cl
   770 00009171 0F850D010000        <1>         jnz     loc_ffde_stc_retn_255
   771                              <1>  
   772                              <1> check_find_dir_entry:
   773 00009177 66A1[88290100]      <1> 	mov	ax, [FDE_AttrMask]
   774 0000917D 8A2F                <1> 	mov	ch, [edi]
   775 0000917F 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
   776 00009182 0F86FF000000        <1> 	jna	loc_find_direntry_stc_retn 
   777 00009188 56                  <1> 	push	esi
   778 00009189 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
   779 0000918C 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
   780 0000918F 746D                <1> 	je	short loc_find_dir_next_entry_prevdeleted
   781                              <1> 
   782 00009191 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
   783 00009194 7505                <1> 	jne     short loc_check_attributes_mask
   784 00009196 E8ED010000          <1> 	call	save_longname_sub_component
   785                              <1> 
   786                              <1> loc_check_attributes_mask:
   787 0000919B 88C6                <1> 	mov	dh, al
   788 0000919D 20D6                <1> 	and	dh, dl    
   789 0000919F 38F0                <1> 	cmp	al, dh
   790 000091A1 0F85BA000000        <1>         jne     loc_find_dir_next_entry
   791 000091A7 20D4                <1> 	and	ah, dl
   792 000091A9 0F85B2000000        <1>         jnz     loc_find_dir_next_entry
   793 000091AF 80FA0F              <1> 	cmp	dl, 0Fh
   794 000091B2 751A                <1> 	jne	short pass_direntry_attr_check
   795                              <1> 
   796 000091B4 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
   797 000091B6 0F85A5000000        <1>         jne     loc_find_dir_next_entry
   798                              <1> 
   799 000091BC 5E                  <1> 	pop	esi
   800 000091BD 6631C0              <1> 	xor	ax, ax
   801 000091C0 8A35[8C290100]      <1> 	mov	dh, [PreviousAttr]
   802 000091C6 66891D[B9280100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   803 000091CD C3                  <1> 	retn
   804                              <1> 
   805                              <1> pass_direntry_attr_check:
   806 000091CE 89FD                <1> 	mov	ebp, edi ; 14/02/2016
   807 000091D0 B908000000          <1> 	mov	ecx, 8
   808                              <1> loc_lodsb_find_dir:
   809 000091D5 AC                  <1> 	lodsb
   810 000091D6 3C2A                <1> 	cmp	al, '*'
   811 000091D8 7508                <1> 	jne	short pass_fde_ambiguous1_check
   812 000091DA FE05[8B290100]      <1>         inc     byte [AmbiguousFileName+1]
   813 000091E0 EB28                <1> 	jmp	short loc_check_direntry_extension
   814                              <1> 
   815                              <1> pass_fde_ambiguous1_check:
   816 000091E2 3C3F                <1> 	cmp	al, '?'
   817 000091E4 750D                <1> 	jne	short pass_fde_ambiguous2_check
   818 000091E6 FE05[8A290100]      <1> 	inc	byte [AmbiguousFileName]
   819 000091EC 803F20              <1> 	cmp	byte [edi], 20h
   820 000091EF 764E                <1> 	jna	short loc_find_dir_next_entry_ebp
   821 000091F1 EB14                <1> 	jmp	short loc_scasb_find_dir_inc_di
   822                              <1> 
   823                              <1> pass_fde_ambiguous2_check:
   824 000091F3 3C20                <1> 	cmp	al, 20h
   825 000091F5 750C                <1> 	jne	short loc_scasb_find_dir
   826 000091F7 803F20              <1> 	cmp	byte [edi], 20h
   827 000091FA 7543                <1> 	jne	short loc_find_dir_next_entry_ebp
   828 000091FC EB0C                <1> 	jmp	short loc_check_direntry_extension
   829                              <1> 
   830                              <1> loc_find_dir_next_entry_prevdeleted:
   831 000091FE 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
   832 00009201 EB5E                <1> 	jmp	short loc_find_dir_next_entry
   833                              <1> 
   834                              <1> loc_scasb_find_dir:
   835 00009203 3A07                <1> 	cmp	al, [edi]
   836 00009205 7538                <1> 	jne	short loc_find_dir_next_entry_ebp
   837                              <1> loc_scasb_find_dir_inc_di:
   838 00009207 47                  <1> 	inc	edi
   839 00009208 E2CB                <1> 	loop	loc_lodsb_find_dir
   840                              <1> 
   841                              <1> loc_check_direntry_extension:
   842 0000920A BE08000000          <1> 	mov	esi, 8
   843 0000920F 89F7                <1> 	mov	edi, esi ; 8
   844 00009211 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
   845 00009214 01EF                <1> 	add	edi, ebp
   846 00009216 B103                <1> 	mov	cl, 3
   847                              <1> loc_lodsb_find_dir_ext:
   848 00009218 AC                  <1> 	lodsb
   849 00009219 3C2A                <1> 	cmp	al, '*'
   850 0000921B 7508                <1> 	jne	short pass_fde_ambiguous3_check
   851 0000921D FE05[8B290100]      <1> 	inc	byte [AmbiguousFileName+1]
   852 00009223 EB1E                <1> 	jmp	short loc_find_dir_proper_direntry
   853                              <1> 
   854                              <1> pass_fde_ambiguous3_check:
   855 00009225 3C3F                <1> 	cmp	al, '?'
   856 00009227 750D                <1> 	jne	short pass_fde_ambiguous4_check
   857 00009229 FE05[8A290100]      <1> 	inc	byte [AmbiguousFileName]
   858 0000922F 803F20              <1> 	cmp	byte [edi], 20h
   859 00009232 760B                <1> 	jna	short loc_find_dir_next_entry_ebp
   860 00009234 EB49                <1> 	jmp	short loc_scasb_find_dir_ext_inc_di
   861                              <1> 
   862                              <1> pass_fde_ambiguous4_check:
   863 00009236 3C20                <1> 	cmp	al, 20h
   864 00009238 7541                <1> 	jne	short loc_scasb_find_dir_ext
   865 0000923A 803F20              <1> 	cmp	byte [edi], 20h
   866 0000923D 7404                <1> 	je	short loc_find_dir_proper_direntry
   867                              <1> 
   868                              <1> loc_find_dir_next_entry_ebp:
   869 0000923F 89EF                <1> 	mov	edi, ebp ; 14/02/2016
   870 00009241 EB1E                <1> 	jmp	short loc_find_dir_next_entry
   871                              <1> 
   872                              <1> loc_find_dir_proper_direntry:
   873 00009243 30C9                <1> 	xor	cl, cl
   874                              <1> loc_find_dir_proper_direntry_1:
   875 00009245 5E                  <1> 	pop	esi
   876 00009246 89EF                <1>         mov     edi, ebp
   877 00009248 8A2F                <1> 	mov	ch, [edi]
   878 0000924A 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
   879 0000924D 66A1[8A290100]      <1> 	mov	ax, [AmbiguousFileName]
   880                              <1> loc_find_dir_proper_direntry_2:
   881 00009253 8A35[8C290100]      <1> 	mov     dh, [PreviousAttr]
   882 00009259 66891D[B9280100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   883 00009260 C3                  <1> 	retn
   884                              <1> 
   885                              <1> loc_find_dir_next_entry:
   886 00009261 8815[8C290100]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
   887                              <1> loc_find_dir_next_entry_1:
   888 00009267 5E                  <1> 	pop	esi
   889 00009268 83C720              <1> 	add	edi, 32
   890                              <1> 	;inc	word [DirBuff_EntryCounter]
   891 0000926B 6643                <1> 	inc	bx
   892 0000926D 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   893 00009274 770E                <1> 	ja	short loc_ffde_stc_retn_255
   894 00009276 E9FCFEFFFF          <1>         jmp     check_find_dir_entry 
   895                              <1> 
   896                              <1> loc_scasb_find_dir_ext:
   897 0000927B 3A07                <1> 	cmp	al, [edi]
   898 0000927D 75C0                <1> 	jne	short loc_find_dir_next_entry_ebp
   899                              <1> loc_scasb_find_dir_ext_inc_di:
   900 0000927F 47                  <1> 	inc	edi
   901 00009280 E296                <1> 	loop    loc_lodsb_find_dir_ext
   902 00009282 EBC1                <1> 	jmp	short loc_find_dir_proper_direntry_1
   903                              <1> 
   904                              <1> loc_ffde_stc_retn_255:
   905                              <1> 	;mov	cx, 0FFFFh
   906 00009284 31C9                <1> 	xor	ecx, ecx
   907 00009286 49                  <1> 	dec	ecx ; 0FFFFFFFFh
   908                              <1> 	;xor	eax, eax
   909                              <1> loc_find_direntry_stc_retn:
   910                              <1> loc_check_ffde_retn_1:
   911                              <1> 	;mov	ax, 2
   912 00009287 B802000000          <1> 	mov	eax, 2 ; File Not Found
   913 0000928C 8A35[8C290100]      <1> 	mov	dh, [PreviousAttr]
   914 00009292 66891D[B9280100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   915 00009299 F9                  <1> 	stc
   916 0000929A C3                  <1> 	retn
   917                              <1> 
   918                              <1> loc_find_free_deleted_entry_0:
   919 0000929B 66A1[88290100]      <1> 	mov	ax, [FDE_AttrMask]
   920 000092A1 8A2F                <1> 	mov	ch, [edi]
   921 000092A3 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
   922 000092A6 08C9                <1> 	or	cl, cl 
   923 000092A8 7407                <1> 	jz	short loc_check_ffde_0_repeat
   924                              <1> 	;cmp	cl, 0E5h
   925                              <1> 	;je	short pass_loc_check_ffde_0_err
   926 000092AA 80F9FF              <1> 	cmp	cl, 0FFh
   927 000092AD 7432                <1> 	je	short loc_find_free_deleted_entry_1
   928 000092AF EB4D                <1> 	jmp	short pass_loc_check_ffde_0_err
   929                              <1> 
   930                              <1> loc_check_ffde_0_repeat:
   931 000092B1 08ED                <1> 	or	ch, ch
   932 000092B3 7511                <1> 	jnz	short loc_check_ffde_0_next
   933                              <1> 
   934                              <1> loc_check_ffde_retn_2:
   935 000092B5 6629C0              <1> 	sub	ax, ax
   936 000092B8 8A35[8C290100]      <1> 	mov	dh, [PreviousAttr]
   937 000092BE 66891D[B9280100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   938 000092C5 C3                  <1> 	retn
   939                              <1>  
   940                              <1> loc_check_ffde_0_next:
   941 000092C6 6643                <1> 	inc	bx
   942 000092C8 83C720              <1> 	add	edi, 32
   943                              <1> 	;inc	word [DirBuff_EntryCounter]
   944                              <1> 	 
   945 000092CB 663B1D[BB280100]    <1>         cmp	bx, [DirBuff_LastEntry]
   946 000092D2 77B0                <1> 	ja	short loc_ffde_stc_retn_255
   947 000092D4 8815[8C290100]      <1> 	mov	[PreviousAttr], dl
   948 000092DA 8A2F                <1> 	mov	ch, [edi]
   949 000092DC 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
   950 000092DF EBD0                <1> 	jmp	short loc_check_ffde_0_repeat
   951                              <1> 
   952                              <1> loc_find_free_deleted_entry_1:
   953 000092E1 28D2                <1> 	sub	dl, dl      
   954                              <1> loc_find_free_deleted_entry_2:
   955 000092E3 20ED                <1> 	and	ch, ch  
   956 000092E5 74CE                <1> 	jz	short loc_check_ffde_retn_2
   957 000092E7 80FDE5              <1> 	cmp	ch, 0E5h
   958 000092EA 74C9                <1> 	je	short loc_check_ffde_retn_2
   959 000092EC 6643                <1> 	inc	bx
   960 000092EE 83C720              <1> 	add	edi, 32
   961 000092F1 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   962 000092F8 778A                <1> 	ja	short loc_ffde_stc_retn_255
   963 000092FA 8A2F                <1> 	mov	ch, [edi]
   964 000092FC EBE5                <1> 	jmp	short loc_find_free_deleted_entry_2
   965                              <1> 
   966                              <1> pass_loc_check_ffde_0_err:
   967 000092FE 38CD                <1> 	cmp	ch, cl
   968 00009300 741F                <1> 	je	short loc_check_ffde_attrib 
   969                              <1> 
   970 00009302 6643                <1> 	inc	bx
   971 00009304 83C720              <1> 	add	edi, 32
   972 00009307 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   973 0000930E 0F8770FFFFFF        <1>         ja      loc_ffde_stc_retn_255
   974 00009314 8815[8C290100]      <1> 	mov	[PreviousAttr], dl
   975 0000931A 8A2F                <1> 	mov	ch, [edi]
   976 0000931C 8A570B              <1> 	mov	dl, [edi+0Bh]
   977 0000931F EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
   978                              <1> 
   979                              <1> loc_check_ffde_attrib:
   980 00009321 88C6                <1> 	mov	dh, al
   981 00009323 20D6                <1> 	and	dh, dl    
   982 00009325 38F0                <1> 	cmp	al, dh
   983 00009327 759D                <1> 	jne	short loc_check_ffde_0_next
   984 00009329 20D4                <1> 	and	ah, dl
   985 0000932B 7599                <1> 	jnz	short loc_check_ffde_0_next
   986 0000932D 30C9                <1> 	xor	cl, cl 
   987 0000932F EB84                <1>         jmp     loc_check_ffde_retn_2
   988                              <1> 
   989                              <1> convert_file_name:
   990                              <1> 	; 06/03/2016
   991                              <1> 	; 11/02/2016
   992                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
   993                              <1> 	; 06/10/2009
   994                              <1> 	; 2005
   995                              <1> 	;
   996                              <1> 	; INPUT  ->
   997                              <1> 	;	ESI = Dot File Name Location
   998                              <1> 	;	EDI = Dir Entry Format File Name Location
   999                              <1> 	; OUTPUT ->
  1000                              <1> 	;	EDI = Dir Entry Format File Name Location
  1001                              <1> 	;	ESI = Dot File Name Location (capitalized)
  1002                              <1> 	;
  1003                              <1> 	; (ECX, AL will be changed) 
  1004                              <1>      
  1005 00009331 56                  <1> 	push	esi  
  1006 00009332 57                  <1> 	push	edi
  1007                              <1> 
  1008 00009333 B90B000000          <1> 	mov	ecx, 11
  1009 00009338 B020                <1> 	mov	al, 20h
  1010 0000933A F3AA                <1> 	rep	stosb
  1011                              <1> 
  1012 0000933C 8B3C24              <1> 	mov	edi, [esp]
  1013                              <1> 
  1014 0000933F B10C                <1> 	mov	cl, 12 ; file name length (max.)
  1015                              <1> 	; 06/03/2016
  1016                              <1> 	; Directory entry name limit (11 bytes) check for
  1017                              <1> 	; 'rename_directory_entry' procedure.
  1018                              <1> 	; (EDI points to Directory Entry)
  1019                              <1> 	; (If the file name would not contain a dot
  1020                              <1> 	; and file name length would be 12, this would cause to
  1021                              <1> 	; overwrite the attributes byte of the directory entry.)
  1022                              <1> 	;
  1023 00009341 B50B                <1> 	mov	ch, 11 ; directory entry's name length
  1024                              <1> loc_check_first_dot:
  1025 00009343 8A06                <1> 	mov	al, [esi]
  1026 00009345 3C2E                <1> 	cmp	al, 2Eh
  1027 00009347 750C                <1> 	jne	short pass_check_first_dot
  1028 00009349 8807                <1> 	mov	[edi], al
  1029 0000934B 47                  <1> 	inc	edi
  1030 0000934C 46                  <1> 	inc	esi
  1031 0000934D FEC9                <1> 	dec	cl
  1032 0000934F 75F2                <1> 	jnz	short loc_check_first_dot
  1033                              <1> 	;;(ecx <= 12)
  1034                              <1> 	;;loop	loc_check_first_dot 
  1035 00009351 EB30                <1> 	jmp	short stop_convert_file
  1036                              <1> 
  1037                              <1> loc_get_fchar:
  1038 00009353 8A06                <1> 	mov	al, [esi]
  1039                              <1> pass_check_first_dot:
  1040 00009355 3C61                <1> 	cmp	al, 61h ; 'a'
  1041 00009357 7208                <1> 	jb	short pass_name_capitalize
  1042 00009359 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  1043 0000935B 7704                <1> 	ja	short pass_name_capitalize
  1044 0000935D 24DF                <1> 	and	al, 0DFh
  1045 0000935F 8806                <1> 	mov	[esi], al
  1046                              <1> pass_name_capitalize:
  1047 00009361 3C21                <1> 	cmp	al, 21h
  1048 00009363 721E                <1> 	jb	short stop_convert_file
  1049 00009365 3C2E                <1> 	cmp	al, 2Eh ; '.'
  1050 00009367 750C                <1> 	jne	short pass_dot_space
  1051                              <1> add_dot_space: 
  1052 00009369 80F904              <1> 	cmp	cl, 4
  1053 0000936C 760E                <1> 	jna	short inc_and_loop
  1054 0000936E 47                  <1> 	inc	edi
  1055 0000936F FECD                <1> 	dec	ch ; 06/03/2016
  1056 00009371 FEC9                <1> 	dec	cl
  1057 00009373 EBF4                <1> 	jmp	short add_dot_space
  1058                              <1> 	
  1059                              <1> 	;mov	al, 4
  1060                              <1> 	;cmp	cl, al
  1061                              <1> 	;jna	short inc_and_loop
  1062                              <1> 	;sub	cl, al
  1063                              <1> 	;add	edi, ecx
  1064                              <1> 	;mov	cl, al
  1065                              <1> 	;jmp	short inc_and_loop	
  1066                              <1> 
  1067                              <1> pass_dot_space:
  1068 00009375 8807                <1> 	mov	[edi], al
  1069                              <1> loc_after_double_dot:
  1070                              <1> 	; 06/03/2016
  1071 00009377 FECD                <1> 	dec	ch ; count down for 11 bytes dir entry limit
  1072 00009379 740A                <1> 	jz	short stop_convert_file_x
  1073 0000937B 47                  <1> 	inc	edi
  1074                              <1> inc_and_loop:
  1075 0000937C FEC9                <1> 	dec	cl ; count down for 12 bytes filename limit 
  1076 0000937E 7403                <1> 	jz	short stop_convert_file	
  1077 00009380 46                  <1> 	inc	esi
  1078                              <1> 	;;(ecx <= 12)
  1079                              <1> 	;;loop	loc_get_fchar
  1080 00009381 EBD0                <1> 	jmp	short loc_get_fchar
  1081                              <1> 
  1082                              <1> stop_convert_file:
  1083                              <1> 	; 06/03/2016
  1084 00009383 30ED                <1> 	xor	ch, ch
  1085                              <1> 	; ECX < 256 ; 'find_first_file' -> xor cl, cl
  1086                              <1> stop_convert_file_x:
  1087 00009385 5F                  <1> 	pop	edi
  1088 00009386 5E                  <1> 	pop	esi
  1089 00009387 C3                  <1> 	retn
  1090                              <1>  
  1091                              <1> save_longname_sub_component:
  1092                              <1> 	; 13/02/2016
  1093                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
  1094                              <1> 	; 28/02/2010
  1095                              <1> 	; 17/10/2009
  1096                              <1> 	; INPUT ->
  1097                              <1> 	;	EDI = Directory Entry    
  1098                              <1> 	;     	// This procedure is called
  1099                              <1> 	;	// from 'find_directory_entry' procedure.
  1100                              <1> 	;	// If the last entry returns with
  1101                              <1> 	;	// a non-zero LongnameFound value and
  1102                              <1> 	;	// if LFN_CheckSum value is equal to
  1103                              <1> 	;	// the next shortname checksum,
  1104                              <1> 	;	// long name is valid.
  1105                              <1> 	;	// If a longname is longer than 65 bytes,
  1106                              <1> 	;	// it is invalid for trdos. (>45h)
  1107                              <1>  
  1108 00009388 57                  <1> 	push	edi
  1109 00009389 56                  <1> 	push	esi
  1110                              <1> 	;push	ebx
  1111                              <1> 	;push	ecx
  1112                              <1> 	;push	edx
  1113 0000938A 50                  <1> 	push	eax
  1114                              <1>            
  1115 0000938B 29C9                <1> 	sub	ecx, ecx
  1116                              <1> 	;sub	eax, eax
  1117 0000938D B11A                <1> 	mov	cl, 26
  1118                              <1> 
  1119 0000938F 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
  1120 00009392 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
  1121 00009394 722B                <1> 	jb	short pass_pslnsc_last_long_entry
  1122                              <1> 
  1123 00009396 88C4                <1> 	mov	ah, al
  1124 00009398 80EC40              <1> 	sub	ah, 40h
  1125 0000939B 8825[8E290100]      <1> 	mov	[LFN_EntryLength], ah
  1126                              <1> 	
  1127 000093A1 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
  1128                              <1>  		; Max 130 byte length is usable in TRDOS
  1129                              <1> ; 26*5 = 130
  1130 000093A3 7753                <1> 	ja	short loc_pslnsc_retn
  1131                              <1> 
  1132 000093A5 2407                <1> 	and	al, 07h ; 0Fh
  1133 000093A7 A2[8D290100]        <1> 	mov	[LongNameFound], al
  1134                              <1> 
  1135 000093AC FEC8                <1> 	dec	al
  1136                              <1> 	;mov	cl, 26
  1137 000093AE F6E1                <1> 	mul	cl
  1138                              <1> 
  1139 000093B0 89C6                <1> 	mov	esi, eax
  1140 000093B2 01CE                <1> 	add	esi, ecx
  1141                              <1> 		; to make is an ASCIZZ string
  1142                              <1> 		; with ax+26 bytes length
  1143 000093B4 81C6[90290100]      <1> 	add	esi, LongFileName
  1144 000093BA 66C7060000          <1> 	mov	word [esi], 0   
  1145 000093BF EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2 
  1146                              <1> 
  1147                              <1> pass_pslnsc_last_long_entry:
  1148 000093C1 3C04                <1> 	cmp	al, 04h
  1149 000093C3 7733                <1> 	ja	short loc_pslnsc_retn
  1150 000093C5 FE0D[8D290100]      <1> 	dec	byte [LongNameFound]
  1151 000093CB 3A05[8D290100]      <1> 	cmp	al, [LongNameFound]
  1152 000093D1 7525                <1> 	jne	short loc_pslnsc_retn
  1153                              <1> 
  1154                              <1> loc_pslsc_move_ldir_name1:
  1155 000093D3 FEC8                <1> 	dec	al
  1156                              <1> 	;mov	cl, 26
  1157 000093D5 F6E1                <1> 	mul	cl
  1158                              <1> 
  1159                              <1> loc_pslsc_move_ldir_name2:
  1160 000093D7 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
  1161 000093DA 880D[8F290100]      <1> 	mov	[LFN_CheckSum], cl 
  1162 000093E0 89FE                <1> 	mov	esi, edi ; LDIR_Order
  1163 000093E2 BF[90290100]        <1> 	mov	edi, LongFileName
  1164 000093E7 01C7                <1> 	add	edi, eax
  1165 000093E9 46                  <1> 	inc	esi
  1166 000093EA B105                <1> 	mov	cl, 5 ; chars 1 to 5
  1167 000093EC F366A5              <1> 	rep	movsw
  1168 000093EF 83C603              <1> 	add	esi, 3
  1169 000093F2 A5                  <1> 	movsd	; char 6 & 7 
  1170 000093F3 A5                  <1> 	movsd	; char 8 & 9
  1171 000093F4 A5                  <1> 	movsd	; char 10 & 11
  1172 000093F5 46                  <1> 	inc	esi
  1173 000093F6 46                  <1> 	inc	esi 
  1174 000093F7 A5                  <1> 	movsd   ; char 12 & 13 
  1175                              <1> 
  1176                              <1> loc_pslnsc_retn:
  1177 000093F8 58                  <1>  	pop	eax
  1178                              <1> 	;pop	edx
  1179                              <1> 	;pop	ecx
  1180                              <1> 	;pop	ebx
  1181 000093F9 5E                  <1> 	pop	esi  
  1182 000093FA 5F                  <1> 	pop	edi
  1183                              <1>  
  1184 000093FB C3                  <1>     	retn
  1185                              <1> 
  1186                              <1> parse_path_name:
  1187                              <1> 	; 10/02/2016
  1188                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  1189                              <1> 	; 10/009/2011 ('proc_parse_pathname')
  1190                              <1> 	; 27/11/2009
  1191                              <1> 	; 05/12/2004
  1192                              <1> 	;
  1193                              <1> 	; INPUT ->
  1194                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
  1195                              <1> 	;       EDI = Destination Address
  1196                              <1> 	;	      (which is TR-DOS FindFile data buffer)
  1197                              <1> 	; OUTPUT ->
  1198                              <1> 	;	CF = 1 -> Error
  1199                              <1> 	;	     EAX = Error Code (AL)
  1200                              <1> 	;
  1201                              <1> 	; (Modified registers: eax, ecx, esi, edi) 
  1202                              <1> 	
  1203                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer 
  1204 000093FC 57                  <1> 	push	edi
  1205 000093FD B914000000          <1> 	mov	ecx, 20  ; 80 bytes
  1206 00009402 31C0                <1> 	xor	eax, eax
  1207 00009404 F3AB                <1> 	rep	stosd 
  1208 00009406 5F                  <1> 	pop	edi
  1209                              <1> 
  1210 00009407 668B06              <1> 	mov	ax, [esi]
  1211 0000940A 80FC3A              <1> 	cmp	ah, ':'
  1212 0000940D 741C                <1> 	je	short loc_ppn_change_drive
  1213 0000940F A0[8E200100]        <1> 	mov	al, [Current_Drv]
  1214 00009414 EB33                <1> 	jmp	short pass_ppn_change_drive
  1215                              <1> 
  1216                              <1> pass_ppn_cdir:
  1217 00009416 8B35[B22A0100]      <1> 	mov	esi, [First_Path_Pos]
  1218 0000941C AC                  <1> 	lodsb
  1219                              <1> loc_ppn_get_filename:
  1220 0000941D 83C741              <1> 	add	edi, 65 ; FindFile_Name location
  1221                              <1> 	; TRDOS Filename length must not be more than 12 bytes
  1222                              <1> 	;mov	ecx, 12
  1223 00009420 B10C                <1> 	mov	cl, 12
  1224                              <1> loc_ppn_get_fnchar_next:
  1225 00009422 AA                  <1> 	stosb
  1226 00009423 AC                  <1> 	lodsb
  1227 00009424 3C21                <1> 	cmp	al, 21h
  1228 00009426 7274                <1> 	jb	short loc_ppn_clc_return 
  1229 00009428 E2F8                <1>         loop    loc_ppn_get_fnchar_next
  1230                              <1> loc_ppn_return:
  1231 0000942A C3                  <1> 	retn
  1232                              <1> 
  1233                              <1> loc_ppn_change_drive:
  1234 0000942B 24DF                <1> 	and	al, 0DFh
  1235 0000942D 2C41                <1> 	sub	al, 'A'; A:
  1236 0000942F 726F                <1> 	jc	short loc_ppn_invalid_drive
  1237 00009431 3805[07DE0000]      <1> 	cmp	[Last_DOS_DiskNo], al
  1238 00009437 7267                <1> 	jb	short loc_ppn_invalid_drive
  1239                              <1> 
  1240 00009439 46                  <1> 	inc	esi
  1241 0000943A 46                  <1> 	inc	esi
  1242 0000943B 8A26                <1> 	mov	ah, [esi]
  1243 0000943D 80FC21              <1> 	cmp	ah, 21h
  1244 00009440 7307                <1> 	jnb	short pass_ppn_change_drive
  1245                              <1> 
  1246                              <1> loc_ppn_cmd_failed:
  1247                              <1> 	; File or directory name is not existing
  1248 00009442 8807                <1> 	mov	[edi], al ; Drv 
  1249 00009444 66B80100            <1> 	mov	ax, 1 ; eax = 1
  1250                              <1> 	; TR-DOS Error Code 1h = Bad Command Argument
  1251                              <1> 	; MS-DOS Error Code 1h : Invalid Function Number
  1252                              <1> 	;stc
  1253                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
  1254 00009448 C3                  <1> 	retn
  1255                              <1> 
  1256                              <1> pass_ppn_change_drive:
  1257 00009449 8935[B22A0100]      <1> 	mov	[First_Path_Pos], esi
  1258 0000944F C705[B62A0100]0000- <1> 	mov	dword [Last_Slash_Pos], 0
  1258 00009457 0000                <1>
  1259 00009459 AA                  <1> 	stosb
  1260 0000945A 8A06                <1> 	mov	al, [esi]
  1261                              <1> loc_scan_ppn_dslash:
  1262 0000945C 3C2F                <1> 	cmp	al, '/'
  1263 0000945E 7506                <1>   	jne	short loc_scan_next_slash_pos
  1264 00009460 8935[B62A0100]      <1> 	mov	[Last_Slash_Pos], esi
  1265                              <1> loc_scan_next_slash_pos:
  1266 00009466 46                  <1> 	inc	esi
  1267 00009467 8A06                <1> 	mov	al, [esi]
  1268 00009469 3C20                <1> 	cmp	al, 20h
  1269 0000946B 77EF                <1> 	ja	short loc_scan_ppn_dslash
  1270 0000946D 833D[B62A0100]00    <1> 	cmp	dword [Last_Slash_Pos], 0
  1271 00009474 76A0                <1> 	jna	short pass_ppn_cdir
  1272                              <1> 	
  1273 00009476 8B0D[B62A0100]      <1> 	mov	ecx, [Last_Slash_Pos]
  1274 0000947C 8B35[B22A0100]      <1> 	mov	esi, [First_Path_Pos]
  1275 00009482 29F1                <1> 	sub	ecx, esi
  1276 00009484 41                  <1> 	inc	ecx
  1277                              <1> 	;cmp	ecx, 64
  1278 00009485 80F940              <1> 	cmp	cl, 64
  1279 00009488 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
  1280                              <1> 
  1281 0000948A 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 byte)
  1282 0000948C F3A4                <1> 	rep	movsb
  1283                              <1> 	;mov	[edi], cl ; 0, End of Dir String
  1284 0000948E 8B35[B62A0100]      <1> 	mov	esi, [Last_Slash_Pos]
  1285 00009494 46                  <1> 	inc	esi
  1286 00009495 89C7                <1> 	mov	edi, eax
  1287 00009497 AC                  <1> 	lodsb
  1288 00009498 3C21                <1> 	cmp	al, 21h
  1289 0000949A 7381                <1> 	jnb	short loc_ppn_get_filename
  1290                              <1> loc_ppn_clc_return:
  1291                              <1> 	;clc
  1292 0000949C 31C0                <1> 	xor	eax, eax
  1293 0000949E C3                  <1> 	retn
  1294                              <1> 
  1295                              <1> loc_ppn_invalid_drive_stc:
  1296 0000949F F5                  <1> 	cmc	 ; stc
  1297                              <1> loc_ppn_invalid_drive:
  1298                              <1> 	; cf = 1
  1299                              <1> 	; The Drive Letter/Char < "A" or > "Z"
  1300 000094A0 66B80F00            <1> 	mov	ax, 0Fh
  1301                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
  1302                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
  1303 000094A4 C3                  <1> 	retn
  1304                              <1> 
  1305                              <1> find_longname:
  1306                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1307                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
  1308                              <1> 	; 17/10/2009
  1309                              <1> 	
  1310                              <1> 	; INPUT -> 
  1311                              <1> 	;	ESI = DOS short file name address
  1312                              <1> 	; 	for example: "filename.ext"
  1313                              <1> 	;
  1314                              <1> 	; OUTPUT ->
  1315                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
  1316                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
  1317                              <1> 	;	AL = 0 & CF=1 -> longname not found
  1318                              <1> 	;	     the file/directory has no longname
  1319                              <1> 	; 	cf = 0 -> AL = FAT Type 
  1320                              <1>  
  1321                              <1> 	; 17/10/2009
  1322                              <1> 	; ASCIIZ string will be returned
  1323                              <1> 	; as LongFileName
  1324                              <1> 	; clearing/reset is not needed
  1325                              <1> 	;mov	ecx, 33
  1326                              <1> 	;mov	edi, LongFileName
  1327                              <1> 	;sub	ax, ax ; 0
  1328                              <1> 	;rep	stosw
  1329                              <1> 
  1330                              <1> 	;mov	byte [LongNameFound], 0
  1331                              <1> 
  1332                              <1> 	; ESI = ASCIIZ file/directory name address
  1333                              <1> 	;   AL = Attributes AND mask 
  1334                              <1> 	;	(Result of AND must be equal to AL)
  1335                              <1> 	;   AH = Negative attributes mask 
  1336                              <1> 	;	(Result of AND must be ZERO)
  1337 000094A5 66B80008            <1> 	mov	ax, 0800h 
  1338                              <1> 		; it must not be volume name or longname
  1339 000094A9 E844DDFFFF          <1> 	call	find_first_file
  1340 000094AE 7216                <1> 	jc	short loc_fln_retn
  1341                              <1>  
  1342                              <1> loc_fln_check_FAT_Type:
  1343 000094B0 803D[8D200100]01    <1> 	cmp	byte [Current_FATType], 1
  1344 000094B7 7306                <1> 	jnb	short loc_fln_check_longname_yes_sign
  1345                              <1> 
  1346 000094B9 E839000000          <1> 	call	get_fs_longname
  1347 000094BE C3                  <1> 	retn
  1348                              <1> 
  1349                              <1> loc_fln_check_longname_yes_sign:
  1350 000094BF 08FF                <1> 	or	bh, bh
  1351 000094C1 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
  1352                              <1> loc_fln_longname_not_found_retn:
  1353 000094C3 31C0                <1> 	xor	eax, eax 
  1354                              <1> 	; cf = 1 & al = 0 -> longname not found
  1355 000094C5 F9                  <1> 	stc
  1356                              <1> loc_fln_retn:
  1357 000094C6 C3                  <1> 	retn
  1358                              <1> 
  1359                              <1> loc_fln_check_longnamefound_number:
  1360                              <1> 	; 'LongNameFound' is set by
  1361                              <1>         ; by 'save_longname_sub_component'
  1362                              <1> 	; which is called from
  1363                              <1> 	; 'find_directory_entry' 
  1364                              <1> 	; which is called from 
  1365                              <1> 	; 'find_first_file'
  1366                              <1> 	; It must 1 if the longname is valid
  1367 000094C7 803D[8D290100]01    <1>         cmp     byte [LongNameFound], 1
  1368 000094CE 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
  1369                              <1>              
  1370                              <1> loc_fln_calculate_checksum: 
  1371 000094D0 E813000000          <1> 	call	calculate_checksum
  1372                              <1> 	; AL = shortname checksum
  1373                              <1> 
  1374                              <1> loc_fln_longname_validation:
  1375                              <1> 	; 'LFN_CheckSum' has been set already
  1376                              <1> 	; by 'save_longname_sub_component'
  1377                              <1> 	; which is called from
  1378                              <1> 	; 'find_directory_entry' 
  1379                              <1> 	; which is called from 
  1380                              <1> 	; 'find_first_file'
  1381 000094D5 3805[8F290100]      <1> 	cmp	[LFN_CheckSum], al
  1382 000094DB 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
  1383                              <1> 
  1384 000094DD BE[90290100]        <1> 	mov	esi, LongFileName
  1385 000094E2 A0[8D200100]        <1> 	mov	al, [Current_FATType]
  1386 000094E7 C3                  <1> 	retn
  1387                              <1> 
  1388                              <1> calculate_checksum:
  1389                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1390                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
  1391                              <1>         ;    
  1392                              <1> 	; INPUT ->
  1393                              <1> 	;	ESI = 11 byte DOS File Name location
  1394                              <1> 	;	(in DOS Directory Entry Format)
  1395                              <1> 	; OUTPUT ->
  1396                              <1> 	;	 AL = 8 bit checksum (CRC) value
  1397                              <1> 	;
  1398                              <1> 	; (Modified registers: EAX, ECX, ESI)
  1399                              <1> 
  1400                              <1> 	; Erdogan Tan [ 17-10-2009 ]
  1401                              <1> 	;  'ror al, 1' instruction
  1402                              <1> 
  1403                              <1> 	; Erdogan Tan [ 20-06-2004 ]
  1404                              <1> 	; This 8086 assembly code is an original code
  1405                              <1> 	; which is adapted from C code in
  1406                              <1> 	; Microsoft FAT32 File System Specification
  1407                              <1> 	; Version 1.03, December 6, 2000
  1408                              <1> 	; Page 28
  1409                              <1> 
  1410 000094E8 30C0                <1> 	xor	al, al
  1411 000094EA B90B000000          <1> 	mov	ecx, 11
  1412                              <1> loc_next_sum:
  1413                              <1> 	;xor	ah, ah
  1414                              <1> 	;test	al, 1
  1415                              <1> 	;jz	short pass_ah_80h
  1416                              <1> 	;mov	ah, 80h
  1417                              <1> ;pass_ah_80h:
  1418                              <1> 	;shr	al, 1
  1419 000094EF D0C8                <1> 	ror	al, 1 ; 17/10/2009  
  1420 000094F1 0206                <1> 	add	al, [esi]
  1421 000094F3 46                  <1> 	inc	esi
  1422                              <1> 	;add	al, ah
  1423 000094F4 E2F9                <1> 	loop	loc_next_sum
  1424 000094F6 C3                  <1> 	retn
  1425                              <1> 
  1426                              <1> get_fs_longname:
  1427                              <1> 	; temporary (13/02/2016)
  1428 000094F7 31C0                <1> 	xor eax, eax
  1429 000094F9 F9                  <1> 	stc
  1430 000094FA C3                  <1> 	retn
  1431                              <1> 
  1432                              <1> make_sub_directory:
  1433                              <1> 	; 03/03/2016
  1434                              <1> 	; 02/03/2016
  1435                              <1> 	; 27/02/2026
  1436                              <1> 	; 26/02/2016
  1437                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1438                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
  1439                              <1> 	; 10/07/2010
  1440                              <1> 	; INPUT ->
  1441                              <1> 	; 	ESI = ASCIIZ Directory Name
  1442                              <1> 	;	CL = Directory Attributes
  1443                              <1> 	; OUTPUT ->
  1444                              <1> 	;	EAX = New sub dir's first cluster
  1445                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  1446                              <1> 	;	CF = 1 -> error code in AL (EAX)
  1447                              <1> 
  1448                              <1> 	;test	cl, 10h  ; directory
  1449                              <1> 	;jz	short loc_make_directory_access_denied
  1450                              <1> 	;test	cl, 08h ; volume name
  1451                              <1> 	;jnz	short loc_make_directory_access_denied
  1452                              <1> 
  1453 000094FB 80E107              <1> 	and	cl, 07h
  1454 000094FE 880D[0C2B0100]      <1> 	mov	byte [mkdir_attrib], cl
  1455                              <1> 
  1456 00009504 56                  <1> 	push	esi
  1457 00009505 31DB                <1> 	xor	ebx, ebx
  1458 00009507 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  1459 0000950D BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1460 00009512 01DE                <1> 	add	esi, ebx
  1461 00009514 5B                  <1> 	pop	ebx
  1462                              <1> 
  1463                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
  1464                              <1> 	; LD_DiskType = 0 for write protection (read only) 
  1465 00009515 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  1466 00009519 730B                <1> 	jnb	short loc_mkdir_check_file_sytem
  1467 0000951B B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
  1468 00009520 BA00000000          <1> 	mov	edx, 0
  1469                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
  1470                              <1> 	;ESI = Logical DOS drive description table address
  1471 00009525 C3                  <1> 	retn
  1472                              <1> 
  1473                              <1> ;loc_make_directory_access_denied:
  1474                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
  1475                              <1> 	;stc
  1476                              <1> 	;retn
  1477                              <1> 
  1478                              <1> loc_mkdir_check_file_sytem:
  1479 00009526 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  1480 0000952A 730B                <1> 	jnb	short loc_mkdir_check_free_sectors
  1481                              <1> 
  1482                              <1> loc_make_fs_directory:
  1483 0000952C A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
  1484                              <1> 	; EAX = Parent directory DDT Address
  1485                              <1> 	; ESI = Logical DOS Drive DT Address
  1486                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
  1487 00009531 E8B8150000          <1> 	call	make_fs_directory
  1488 00009536 C3                  <1> 	retn
  1489                              <1> 
  1490                              <1> loc_mkdir_check_free_sectors:
  1491 00009537 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
  1492 0000953B 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1493 0000953E 39C1                <1> 	cmp	ecx, eax
  1494 00009540 7255                <1> 	jb	short loc_mkdir_insufficient_disk_space
  1495                              <1> 
  1496                              <1> loc_make_fat_directory:
  1497 00009542 891D[FC2A0100]      <1> 	mov	[mkdir_DirName_Offset], ebx
  1498 00009548 890D[082B0100]      <1> 	mov	[mkdir_FreeSectors], ecx
  1499                              <1> 
  1500                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
  1501 0000954E A2[0E2B0100]        <1> 	mov	byte [mkdir_SecPerClust], al
  1502                              <1> 
  1503                              <1> loc_mkdir_gffc_1:
  1504 00009553 E8F2170000          <1> 	call	get_first_free_cluster
  1505 00009558 722A                <1> 	jc	short loc_mkdir_gffc_retn
  1506                              <1> 
  1507                              <1> ;loc_mkdir_gffc_1_cont: 
  1508                              <1> 	;cmp	eax, 2
  1509                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1510                              <1> 
  1511                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
  1512 0000955A A3[002B0100]        <1> 	mov	[mkdir_FFCluster], eax
  1513                              <1> 
  1514                              <1> loc_mkdir_locate_ffe:
  1515                              <1> 	; Current directory fcluster <> Directory buffer cluster
  1516                              <1> 	; Current directory will be reloaded by
  1517                              <1> 	; 'locate_current_dir_file' procedure
  1518                              <1> 	;
  1519                              <1> 	; ESI = Logical DOS Drive Description Table Address 
  1520                              <1> 	;push	esi ; 27/02/2016
  1521 0000955F 31C0                <1> 	xor	eax, eax
  1522 00009561 89C1                <1>         mov	ecx, eax
  1523 00009563 6649                <1> 	dec	cx ; FFFFh  
  1524                              <1> 	; CX = FFFFh -> find first deleted or free entry
  1525                              <1> 	; ESI would be ASCIIZ filename address if the call
  1526                              <1> 	; would not be for first free or deleted dir entry
  1527 00009565 E8D2FAFFFF          <1> 	call	locate_current_dir_file
  1528 0000956A 734C                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
  1529                              <1> 	;pop	esi 
  1530                              <1> 	; ESI = Logical DOS Drive Description Table Address 
  1531 0000956C 83F802              <1> 	cmp	eax, 2  ; cmp al, 2 ; File/Dir not found !
  1532 0000956F 752B                <1> 	jne	short loc_mkdir_stc_return
  1533                              <1> 
  1534                              <1> loc_mkdir_add_new_cluster:
  1535 00009571 3805[8D200100]      <1> 	cmp	byte [Current_FATType], al ; 2
  1536                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
  1537 00009577 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
  1538 00009579 803D[8C200100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  1539                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  1540 00009580 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
  1541                              <1> 
  1542 00009582 B00C                <1> 	mov	al, 12 ; No more files 
  1543                              <1> loc_mkdir_gffc_retn:
  1544 00009584 C3                  <1> 	retn
  1545                              <1> 
  1546                              <1> loc_mkdir_add_new_cluster_check_fsc:
  1547 00009585 8B0D[082B0100]      <1> 	mov	ecx, [mkdir_FreeSectors]
  1548                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
  1549 0000958B A0[0E2B0100]        <1> 	mov	al, [mkdir_SecPerClust]
  1550 00009590 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
  1551 00009593 39C1                <1> 	cmp	ecx, eax
  1552 00009595 7350                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
  1553                              <1> 
  1554                              <1> loc_mkdir_insufficient_disk_space:
  1555                              <1> 	;mov	edx, ecx
  1556                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
  1557 00009597 66B82700            <1> 	mov	ax, 27h ; MSDOS err => insufficient disk space
  1558                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
  1559                              <1>         ; ESI -> Dos drive description table address
  1560                              <1> 	;; ecx = edx
  1561                              <1> 	;
  1562 0000959B C3                  <1> 	retn
  1563                              <1> 
  1564                              <1> loc_mkdir_stc_return:
  1565 0000959C F9                  <1> 	stc
  1566 0000959D C3                  <1> 	retn 
  1567                              <1> 
  1568                              <1> loc_mkdir_gffc_2:
  1569 0000959E E8A7170000          <1> 	call	get_first_free_cluster
  1570 000095A3 72DF                <1> 	jc	short loc_mkdir_gffc_retn
  1571                              <1> 
  1572                              <1> ;loc_mkdir_gffc_1_cont: 
  1573                              <1> 	;cmp	eax, 2
  1574                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1575                              <1> 
  1576                              <1> ;loc_mkdir_gffc_2_save_fcluster:  
  1577 000095A5 A3[002B0100]        <1> 	mov	[mkdir_FFCluster], eax
  1578                              <1> 
  1579 000095AA A1[042B0100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1580                              <1> 
  1581 000095AF E825170000          <1> 	call	load_FAT_sub_directory 
  1582 000095B4 72CE                <1> 	jc	short loc_mkdir_gffc_retn
  1583                              <1> 
  1584 000095B6 31FF                <1> 	xor	edi, edi
  1585                              <1> loc_mkdir_set_ff_dir_entry_1:
  1586                              <1> 	; 27/02/2016
  1587 000095B8 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
  1588                              <1> 	; EDI = Directory Entry Address
  1589 000095B9 8B35[FC2A0100]      <1> 	mov	esi, [mkdir_DirName_Offset]
  1590 000095BF A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1591                              <1> 
  1592 000095C4 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
  1593                              <1> 			; CH = 0 -> File size is 0
  1594 000095C8 0A0D[0C2B0100]      <1> 	or	cl, [mkdir_attrib] ; S, H, R  
  1595 000095CE E8B0010000          <1> 	call	make_directory_entry
  1596                              <1> 
  1597 000095D3 5E                  <1> 	pop	esi
  1598                              <1> 
  1599 000095D4 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1600 000095DB E880020000          <1> 	call	save_directory_buffer
  1601 000095E0 0F83DA000000        <1>         jnc     loc_mkdir_set_ff_dir_entry_2
  1602                              <1> 
  1603                              <1> loc_mkdir_return:
  1604 000095E6 C3                  <1> 	retn
  1605                              <1> 
  1606                              <1> loc_mkdir_add_new_subdir_cluster:
  1607 000095E7 8B15[BD280100]      <1> 	mov	edx, [DirBuff_Cluster]
  1608 000095ED 8915[042B0100]      <1> 	mov	[mkdir_LastDirCluster], edx       
  1609                              <1> 
  1610 000095F3 A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1611 000095F8 E8DC160000          <1> 	call	load_FAT_sub_directory 
  1612 000095FD 72E7                <1> 	jc	short loc_mkdir_return
  1613                              <1> 	; eax = 0
  1614                              <1> 	; ecx =  directory buffer sector count (<= 128)
  1615                              <1> 
  1616                              <1> pass_mkdir_add_new_subdir_cluster:
  1617 000095FF 29FF                <1> 	sub	edi, edi ; 0
  1618                              <1> 	;mov	al, 128 ; double word
  1619                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
  1620                              <1> 	;mov	ecx, eax
  1621                              <1> 	;shl	cx, 7 ; 128 * sector count	
  1622 00009601 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1623 00009605 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1624 00009609 66F7E1              <1> 	mul	cx ; max = 128*(512/4) -> 16384 (stosd)
  1625 0000960C 6689C1              <1> 	mov	cx, ax
  1626 0000960F 6629C0              <1> 	sub	ax, ax ; 0
  1627 00009612 F3AB                <1> 	rep	stosd ; clear directory buffer
  1628                              <1> 
  1629 00009614 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1630 0000961B E840020000          <1> 	call	save_directory_buffer 
  1631 00009620 72C4                <1> 	jc	short loc_mkdir_return
  1632                              <1> 
  1633                              <1> loc_mkdir_save_added_cluster:
  1634 00009622 A1[042B0100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1635 00009627 8B0D[002B0100]      <1> 	mov	ecx, [mkdir_FFCluster]
  1636                              <1> 	; 01/03/2016
  1637 0000962D 31D2                <1> 	xor	edx, edx
  1638 0000962F 8915[AE280100]      <1> 	mov	[FAT_ClusterCounter], edx ; 0 ; reset
  1639 00009635 E8E3170000          <1> 	call	update_cluster
  1640 0000963A 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
  1641 0000963C 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1642 0000963E 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
  1643                              <1> 
  1644                              <1> loc_mkdir_save_fat_buffer_0:
  1645 00009640 A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1646 00009645 A3[042B0100]        <1> 	mov	[mkdir_LastDirCluster], eax
  1647                              <1> 
  1648 0000964A 31C9                <1> 	xor	ecx, ecx
  1649 0000964C 49                  <1> 	dec	ecx ; FFFFFFFFh
  1650                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1651 0000964D E8CB170000          <1> 	call	update_cluster
  1652 00009652 731A                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
  1653 00009654 09C0                <1> 	or	eax, eax
  1654 00009656 7416                <1> 	jz	short loc_mkdir_save_fat_buffer_1
  1655                              <1> 
  1656                              <1> loc_mkdir_save_fat_buffer_stc_retn:
  1657                              <1> 	; 01/03/2016
  1658 00009658 803D[AE280100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1659 0000965F 720C                <1> 	jb	short loc_mkdir_save_fat_buffer_retn
  1660                              <1> 
  1661 00009661 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  1662                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  1663 00009665 50                  <1> 	push	eax
  1664 00009666 E8041B0000          <1> 	call	calculate_fat_freespace
  1665 0000966B 58                  <1> 	pop	eax
  1666 0000966C F9                  <1> 	stc
  1667                              <1> loc_mkdir_save_fat_buffer_retn:
  1668 0000966D C3                  <1> 	retn
  1669                              <1> 
  1670                              <1> loc_mkdir_save_fat_buffer_1:
  1671                              <1> 	; byte [FAT_BuffValidData] = 2 
  1672 0000966E E8671A0000          <1> 	call	save_fat_buffer
  1673 00009673 72E3                <1> 	jc	short loc_mkdir_save_fat_buffer_stc_retn
  1674                              <1> 
  1675                              <1> 	; 01/03/2016
  1676 00009675 803D[AE280100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1677 0000967C 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_2
  1678                              <1> 
  1679                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1680 0000967E A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1681 00009683 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  1682 00009687 E8E31A0000          <1> 	call	calculate_fat_freespace
  1683                              <1> 
  1684                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  1685                              <1> 	;jnz	short loc_mkdir_save_fat_buffer_2
  1686                              <1> 
  1687                              <1> 	; ecx > 0 -> Recalculation is needed
  1688 0000968C 09C9                <1> 	or	ecx, ecx 
  1689 0000968E 7409                <1> 	jz	short loc_mkdir_save_fat_buffer_2
  1690                              <1> 
  1691 00009690 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  1692 00009694 E8D61A0000          <1> 	call	calculate_fat_freespace
  1693                              <1> 
  1694                              <1> loc_mkdir_save_fat_buffer_2:
  1695 00009699 C605[0F2B0100]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
  1696 000096A0 E9C4000000          <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
  1697                              <1> 
  1698                              <1> loc_mkdir_update_sub_dir_cluster:
  1699 000096A5 A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1700 000096AA 29C9                <1> 	sub	ecx, ecx ; 0
  1701                              <1> 	; 01/03/2016
  1702 000096AC 890D[AE280100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; Reset
  1703 000096B2 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  1704                              <1> 
  1705                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
  1706 000096B3 E865170000          <1> 	call	update_cluster
  1707 000096B8 7379                <1> 	jnc	short loc_mkdir_save_fat_buffer_3
  1708 000096BA 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1709 000096BC 7475                <1> 	jz	short loc_mkdir_save_fat_buffer_3
  1710                              <1> 	; 01/03/2016
  1711 000096BE EB98                <1> 	jmp	short loc_mkdir_save_fat_buffer_stc_retn
  1712                              <1> 
  1713                              <1> loc_mkdir_set_ff_dir_entry_2:
  1714                              <1> 	; ESI = Logical DOS Drive Description Table address  
  1715 000096C0 A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1716                              <1> 	; Load disk sectors as a directory cluster
  1717 000096C5 E80F160000          <1> 	call	load_FAT_sub_directory 
  1718 000096CA 7266                <1> 	jc	short retn_make_fat_directory
  1719                              <1> 	
  1720                              <1> 	; eax = 0
  1721                              <1> 	; ecx =  directory buffer sector count (<= 128)
  1722                              <1> 
  1723 000096CC BF40000800          <1> 	mov	edi, Directory_Buffer + 64 ; 26/02/2016
  1724                              <1> 
  1725                              <1> 	; 02/03/2016
  1726 000096D1 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1727 000096D5 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1728 000096D9 F7E1                <1> 	mul 	ecx
  1729 000096DB 89C1                <1> 	mov	ecx, eax
  1730 000096DD 6629C0              <1> 	sub	ax, ax
  1731 000096E0 F3AB                <1> 	rep	stosd
  1732                              <1> 
  1733                              <1> 	;;mov	al, 128 ; double word
  1734                              <1> 	;;mul	ecx ; ecx =  directory buffer sector count
  1735                              <1> 	;;mov	ecx, eax
  1736                              <1> 	;shl	cx, 7 ; 128 * sector count	
  1737                              <1> 	;;sub	eax, eax
  1738                              <1> 	;;sub	al, al ; 0
  1739                              <1> 	;rep	stosd ; clear directory buffer
  1740                              <1> 
  1741 000096E2 BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
  1742                              <1> 	
  1743 000096E7 56                  <1> 	push	esi
  1744                              <1> 
  1745 000096E8 BE[102B0100]        <1> 	mov	esi, mkdir_Name
  1746 000096ED 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
  1747                              <1> 
  1748 000096F2 A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1749 000096F7 66B91000            <1> 	mov	cx, 10h ; CL = Directory attribute
  1750                              <1> 			; CH = 0 -> File size is 0
  1751 000096FB E883000000          <1> 	call	make_directory_entry
  1752                              <1> 
  1753 00009700 BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
  1754                              <1> 
  1755                              <1> 	; 03/03/2016
  1756                              <1> 	; Following modification has been done according to 
  1757                              <1> 	; 'Microsoft Extensible Firmware Initiative
  1758                              <1> 	; FAT32 File System Specification' document,
  1759                              <1> 	; 'FAT: General Overview of On-Disk FormatPage 25'.
  1760                              <1> 	; "Finally, you set DIR_FstClusLO and DIR_FstClusHI
  1761                              <1> 	; for the dotdot entry (the second entry) to the
  1762                              <1> 	; first cluster number of the directory in which you 
  1763                              <1> 	; just created the directory (value is 0 if this directory
  1764                              <1> 	; is the root directory even for FAT32 volumes)."
  1765                              <1> 	; (Correctness of this modification has been verified
  1766                              <1> 	;  by using Windows 98 'scandisk.exe'.)
  1767                              <1> 
  1768 00009705 29C0                <1> 	sub	eax, eax
  1769 00009707 3805[8C200100]      <1> 	cmp	byte [Current_Dir_Level], al ; 0
  1770 0000970D 7605                <1> 	jna	short loc_mkdir_set_ff_dir_entry_3
  1771 0000970F A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
  1772                              <1> loc_mkdir_set_ff_dir_entry_3:
  1773 00009714 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
  1774                              <1> 
  1775                              <1> 	;mov	cx, 10h
  1776 0000971A E864000000          <1> 	call	make_directory_entry
  1777                              <1> 
  1778 0000971F 5E                  <1> 	pop	esi
  1779                              <1> 
  1780 00009720 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1781 00009727 E834010000          <1> 	call	save_directory_buffer
  1782 0000972C 0F8373FFFFFF        <1>         jnc     loc_mkdir_update_sub_dir_cluster
  1783                              <1>  
  1784                              <1> retn_make_fat_directory:
  1785 00009732 C3                  <1> 	retn
  1786                              <1> 
  1787                              <1> loc_mkdir_save_fat_buffer_3:
  1788                              <1> 	; 01/03/2016
  1789                              <1> 	; byte [FAT_BuffValidData] = 2 
  1790 00009733 E8A2190000          <1> 	call	save_fat_buffer
  1791 00009738 0F821AFFFFFF        <1>         jc      loc_mkdir_save_fat_buffer_stc_retn
  1792                              <1> 
  1793 0000973E 803D[AE280100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1794 00009745 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_4
  1795                              <1> 
  1796                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1797 00009747 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1798 0000974C 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  1799 00009750 E81A1A0000          <1> 	call	calculate_fat_freespace
  1800                              <1> 
  1801                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  1802                              <1>         ;jnz    short loc_mkdir_save_fat_buffer_4
  1803                              <1> 
  1804                              <1> 	; ecx > 0 -> Recalculation is needed
  1805 00009755 09C9                <1> 	or	ecx, ecx 
  1806 00009757 7409                <1>         jz      short loc_mkdir_save_fat_buffer_4
  1807                              <1> 
  1808 00009759 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
  1809 0000975D E80D1A0000          <1> 	call	calculate_fat_freespace
  1810                              <1> 
  1811                              <1> loc_mkdir_save_fat_buffer_4:	
  1812 00009762 C605[0F2B0100]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
  1813                              <1> 
  1814                              <1> loc_mkdir_upd_parent_dir_lmdt:
  1815 00009769 E88D010000          <1> 	call	update_parent_dir_lmdt
  1816                              <1> 
  1817                              <1> 	; 01/03/2016
  1818 0000976E 803D[0F2B0100]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
  1819 00009775 0F8723FEFFFF        <1>         ja      loc_mkdir_gffc_2
  1820                              <1> 
  1821                              <1> loc_mkdir_retn_new_dir_cluster:
  1822 0000977B A1[002B0100]        <1> 	mov	eax, [mkdir_FFCluster]
  1823 00009780 31D2                <1> 	xor	edx, edx
  1824                              <1> loc_mkdir_retn:
  1825 00009782 C3                  <1> 	retn
  1826                              <1> 
  1827                              <1> make_directory_entry:
  1828                              <1> 	; 02/03/2016
  1829                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1830                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
  1831                              <1> 	; 17/07/2010
  1832                              <1> 	; INPUT ->
  1833                              <1> 	; 	EDI = Directory Entry Address
  1834                              <1> 	;	ESI = Dot File Name Location
  1835                              <1> 	;	EAX = First Cluster
  1836                              <1> 	;	File Size = 0 (Must be set later)
  1837                              <1> 	;	CL = Attributes
  1838                              <1> 	;	CH = 0 (File size = 0) 
  1839                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
  1840                              <1> 	; OUTPUT -> 
  1841                              <1> 	;	EDI = Directory Entry Address
  1842                              <1> 	;	ESI = Dot File Name Location (Capitalized)
  1843                              <1> 	;	If CH input = 0, File Size = 0
  1844                              <1> 	;	Otherwise file size is as dword [EBX] (*)
  1845                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
  1846                              <1> 	;	EBX = same
  1847                              <1> 	;	ECX = same
  1848                              <1> 
  1849 00009783 51                  <1> 	push	ecx
  1850                              <1> 
  1851 00009784 884F0B              <1> 	mov	[edi+11], cl ; Attributes
  1852 00009787 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
  1853 0000978B C1E810              <1> 	shr	eax, 16
  1854 0000978E 66894714            <1> 	mov	[edi+20], ax ; FClusterHw, 20
  1855 00009792 6631C0              <1> 	xor	ax, ax 
  1856 00009795 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
  1857                              <1> 			     ; CrtTimeTenth, 13
  1858 00009799 08ED                <1> 	or	ch, ch
  1859 0000979B 7402                <1> 	jz	short loc_make_direntry_set_filesize
  1860                              <1> 
  1861 0000979D 8B03                <1> 	mov	eax, [ebx]
  1862                              <1>         
  1863                              <1> loc_make_direntry_set_filesize:
  1864 0000979F 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
  1865                              <1> 	
  1866 000097A2 E88AFBFFFF          <1> 	call	convert_file_name
  1867                              <1> 	;EDI = Dir Entry Format File Name Location
  1868                              <1> 	;ESI = Dot File Name Location (capitalized)
  1869                              <1> 
  1870 000097A7 E816000000          <1> 	call	convert_current_date_time
  1871                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1872                              <1>         ; 	    AX = Time in dos dir entry format
  1873 000097AC 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
  1874 000097B0 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
  1875 000097B4 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
  1876 000097B8 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
  1877 000097BC 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
  1878 000097C0 59                  <1> 	pop	ecx
  1879                              <1> 
  1880 000097C1 C3                  <1> 	retn
  1881                              <1> 
  1882                              <1> convert_current_date_time:
  1883                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1884                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
  1885                              <1> 	; converts date&time to dos dir entry format
  1886                              <1> 	; INPUT -> none
  1887                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1888                              <1> 	;           AX = Time in dos dir entry format
  1889                              <1>  
  1890 000097C2 B404                <1> 	mov	ah, 04h ; Return Current Date
  1891 000097C4 E8CFB9FFFF          <1> 	call	int1Ah 
  1892                              <1> 
  1893 000097C9 88E8                <1> 	mov	al, ch ; <- century BCD
  1894 000097CB 240F                <1> 	and	al, 0Fh
  1895 000097CD 88EC                <1> 	mov	ah, ch
  1896 000097CF C0EC04              <1> 	shr	ah, 4
  1897 000097D2 D50A                <1> 	aad
  1898 000097D4 88C5                <1> 	mov	ch, al ; -> century 
  1899                              <1> 
  1900 000097D6 88C8                <1> 	mov	al, cl ; <- year BCD
  1901 000097D8 240F                <1> 	and	al, 0Fh
  1902 000097DA 88CC                <1> 	mov	ah, cl
  1903 000097DC C0EC04              <1> 	shr	ah, 4
  1904 000097DF D50A                <1> 	aad
  1905 000097E1 88C1                <1> 	mov	cl, al ; -> year
  1906                              <1> 
  1907 000097E3 88E8                <1> 	mov	al, ch
  1908 000097E5 B464                <1> 	mov	ah, 100
  1909 000097E7 F6E4                <1> 	mul	ah
  1910 000097E9 30ED                <1> 	xor	ch, ch
  1911 000097EB 6601C8              <1> 	add	ax, cx
  1912 000097EE 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
  1913 000097F2 6689C1              <1> 	mov	cx, ax
  1914                              <1> 
  1915 000097F5 88F0                <1> 	mov	al, dh ; <- month in bcd
  1916 000097F7 240F                <1> 	and	al, 0Fh
  1917 000097F9 88F4                <1> 	mov	ah, dh
  1918 000097FB C0EC04              <1> 	shr	ah, 4
  1919 000097FE D50A                <1> 	aad
  1920 00009800 88C6                <1> 	mov	dh, al ; -> month
  1921                              <1> 
  1922 00009802 88D0                <1> 	mov	al, dl ; <- day BCD
  1923 00009804 240F                <1> 	and	al, 0Fh
  1924 00009806 88D4                <1> 	mov	ah, dl
  1925 00009808 C0EC04              <1> 	shr	ah, 4
  1926 0000980B D50A                <1> 	aad
  1927 0000980D 88C2                <1> 	mov	dl, al ; -> day
  1928                              <1> 
  1929 0000980F 88C8                <1> 	mov	al, cl ; count of years from 1980
  1930 00009811 66C1E004            <1> 	shl	ax, 4
  1931 00009815 08F0                <1> 	or	al, dh ; month of year, 1 to 12
  1932 00009817 66C1E005            <1> 	shl	ax, 5
  1933 0000981B 08D0                <1> 	or	al, dl ; day of year, 1 to 31
  1934                              <1> 	
  1935 0000981D 6650                <1> 	push	ax ; push date
  1936                              <1> 
  1937 0000981F B402                <1> 	mov	ah, 02h ; Return Current Time
  1938 00009821 E872B9FFFF          <1> 	call	int1Ah
  1939                              <1> 
  1940 00009826 88E8                <1> 	mov	al, ch ; <- hours BCD
  1941 00009828 240F                <1> 	and	al, 0Fh
  1942 0000982A 88EC                <1> 	mov	ah, ch
  1943 0000982C C0EC04              <1> 	shr	ah, 4
  1944 0000982F D50A                <1> 	aad
  1945 00009831 88C5                <1> 	mov	ch, al ; -> hours
  1946                              <1> 
  1947 00009833 88C8                <1> 	mov	al, cl ; <- minutes BCD
  1948 00009835 240F                <1> 	and	al, 0Fh
  1949 00009837 88CC                <1> 	mov	ah, cl
  1950 00009839 C0EC04              <1> 	shr	ah, 4
  1951 0000983C D50A                <1> 	aad
  1952 0000983E 88C1                <1> 	mov	cl, al ; -> minutes
  1953                              <1> 
  1954 00009840 88F0                <1> 	mov	al, dh ; <- seconds BCD
  1955 00009842 240F                <1> 	and	al, 0Fh
  1956 00009844 88F4                <1> 	mov	ah, dh
  1957 00009846 C0EC04              <1> 	shr	ah, 4
  1958 00009849 D50A                <1> 	aad
  1959 0000984B 88C6                <1> 	mov	dh, al ; -> seconds
  1960                              <1> 
  1961 0000984D 88E8                <1> 	mov	al, ch ; hours
  1962 0000984F 66C1E006            <1> 	shl	ax, 6
  1963 00009853 08C8                <1> 	or	al, cl ; minutes
  1964 00009855 66C1E005            <1> 	shl	ax, 5
  1965 00009859 D0EE                <1> 	shr	dh, 1 ; 2 seconds
  1966                              <1> 	; There is a bug in TRDOS v1 here !
  1967                              <1> 	; it was 'or al, dl' ! 
  1968 0000985B 08F0                <1> 	or	al, dh ; seconds
  1969                              <1> 
  1970 0000985D 665A                <1> 	pop	dx ; pop date
  1971                              <1> 	
  1972 0000985F C3                  <1> 	retn
  1973                              <1> 
  1974                              <1> save_directory_buffer:
  1975                              <1> 	; 23/03/2016
  1976                              <1> 	; 26/02/2016
  1977                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  1978                              <1> 	; 01/08/2011
  1979                              <1> 	; 14/03/2010
  1980                              <1> 	; INPUT ->
  1981                              <1> 	; 	 none
  1982                              <1> 	; OUTPUT ->
  1983                              <1> 	;  cf = 0 -> write OK...
  1984                              <1> 	;  cf = 1 -> error code in AL (EAX)
  1985                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
  1986                              <1> 	;  EBX = Directory Buffer Address
  1987                              <1> 	;
  1988                              <1> 	;  (EAX, ECX, EDX will be modified)
  1989                              <1>  
  1990 00009860 BB00000800          <1> 	mov	ebx, Directory_Buffer
  1991 00009865 803D[B8280100]02    <1> 	cmp	byte [DirBuff_ValidData], 2
  1992 0000986C 7403                <1> 	je	short loc_save_dir_buffer
  1993 0000986E 31C0                <1> 	xor	eax, eax
  1994 00009870 C3                  <1> 	retn            
  1995                              <1> 
  1996                              <1> loc_save_dir_buffer:
  1997 00009871 56                  <1> 	push	esi
  1998 00009872 31DB                <1> 	xor	ebx, ebx 
  1999 00009874 8A3D[B6280100]      <1>         mov     bh, [DirBuff_DRV]
  2000 0000987A 80EF41              <1> 	sub	bh, 'A'
  2001 0000987D BE00010900          <1>         mov     esi, Logical_DOSDisks
  2002 00009882 01DE                <1> 	add	esi, ebx
  2003 00009884 668B4E03            <1>         mov     cx, [esi+LD_FATType]
  2004                              <1> 	; CH = FS Type (A1h for FS)
  2005                              <1> 	; CL = FAT Type (0 for FS)
  2006 00009888 08C9                <1> 	or	cl, cl
  2007 0000988A 7433                <1> 	jz	short loc_save_dir_buff_stc_retn
  2008                              <1> 
  2009                              <1> loc_save_dir_buffer_check_cluster_no:    
  2010 0000988C A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
  2011 00009891 28FF                <1> 	sub	bh, bh ; ebx = 0
  2012 00009893 09C0                <1> 	or	eax, eax
  2013 00009895 7540                <1> 	jnz	short loc_save_sub_dir_buffer
  2014 00009897 8A25[B7280100]      <1> 	mov	ah, [DirBuff_FATType]
  2015 0000989D FEC3                <1> 	inc	bl ;  bl = 1
  2016 0000989F 38DC                <1> 	cmp	ah, bl
  2017 000098A1 721D                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2018 000098A3 FEC3                <1> 	inc	bl ; bl = 2
  2019 000098A5 38E3                <1> 	cmp	bl, ah
  2020 000098A7 7217                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2021                              <1> 
  2022                              <1> loc_save_root_dir_buffer:
  2023 000098A9 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
  2024 000098AD 6683C30F            <1> 	add	bx, 15
  2025 000098B1 66C1EB04            <1> 	shr	bx, 4 ; 16 dir entries per sector
  2026 000098B5 6609DB              <1> 	or	bx, bx
  2027 000098B8 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
  2028                              <1> 	;mov	ecx, ebx 
  2029 000098BA 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
  2030 000098BD EB23                <1> 	jmp	short loc_write_directory_to_disk
  2031                              <1> 
  2032                              <1> loc_save_dir_buff_stc_retn:
  2033 000098BF F9                  <1> 	stc
  2034                              <1> loc_save_dir_buff_inv_data_retn:
  2035 000098C0 B00D                <1> 	mov	al, 0Dh ; Invalid data !
  2036 000098C2 C605[B8280100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2037 000098C9 EB05                <1> 	jmp	short loc_save_dir_buff_retn 
  2038                              <1> 
  2039                              <1> loc_write_directory_to_disk_err:
  2040                              <1> 	; 23/03/2016
  2041 000098CB B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error 
  2042                              <1> 
  2043                              <1> loc_save_dir_buff_retn:
  2044 000098D0 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2045 000098D5 5E                  <1> 	pop	esi
  2046 000098D6 C3                  <1> 	retn
  2047                              <1>  
  2048                              <1> loc_save_sub_dir_buffer:
  2049                              <1> 	; ebx  = 0
  2050 000098D7 83E802              <1> 	sub	eax, 2
  2051 000098DA 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2052 000098DD F7E3                <1> 	mul	ebx
  2053 000098DF 034668              <1>         add     eax, [esi+LD_DATABegin]
  2054                              <1>  	;mov	ecx, ebx
  2055                              <1> 
  2056                              <1> loc_write_directory_to_disk:
  2057 000098E2 89D9                <1>  	mov	ecx, ebx
  2058 000098E4 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2059 000098E9 E81F410000          <1> 	call	disk_write
  2060 000098EE 72DB                <1> 	jc	short loc_write_directory_to_disk_err
  2061                              <1> 
  2062                              <1> loc_save_dir_buff_validate_retn:
  2063 000098F0 C605[B8280100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2064 000098F7 31C0                <1> 	xor	eax, eax
  2065                              <1> 	; 26/02/2016
  2066 000098F9 EBD5                <1> 	jmp	short loc_save_dir_buff_retn
  2067                              <1> 
  2068                              <1> update_parent_dir_lmdt:
  2069                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  2070                              <1> 	; 01/08/2011
  2071                              <1> 	; 16/10/2010 
  2072                              <1> 	; 
  2073                              <1> 	; INPUT -> 
  2074                              <1> 	;	none
  2075                              <1>  	; OUTPUT ->
  2076                              <1> 	;	(last modification date & time of the parent dir
  2077                              <1> 	;	will be changed/updated)
  2078                              <1> 	;
  2079                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
  2080                              <1> 
  2081 000098FB 29C0                <1> 	sub	eax, eax
  2082 000098FD 8A25[8C200100]      <1> 	mov	ah, [Current_Dir_Level]
  2083 00009903 A0[8D200100]        <1> 	mov	al, [Current_FATType]
  2084 00009908 3C01                <1> 	cmp	al, 1
  2085 0000990A 723A                <1> 	jb	short loc_UPDLMDT_proc_retn
  2086                              <1>     
  2087                              <1> loc_update_parent_dir_lm_date_time:
  2088 0000990C 08E4                <1> 	or	ah, ah
  2089 0000990E 7436                <1> 	jz	short loc_UPDLMDT_proc_retn
  2090                              <1> 
  2091 00009910 56                  <1> 	push	esi ; *
  2092 00009911 8825[302B0100]      <1> 	mov	[UPDLMDT_CDirLevel], ah
  2093 00009917 8B15[88200100]      <1> 	mov	edx, [Current_Dir_FCluster]
  2094 0000991D 8915[312B0100]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
  2095                              <1> 
  2096 00009923 FECC                <1> 	dec	ah
  2097 00009925 B90C000000          <1> 	mov	ecx, 12
  2098 0000992A BE[EF280100]        <1>         mov     esi, PATH_Array
  2099                              <1> 
  2100 0000992F 8825[8C200100]      <1> 	mov	[Current_Dir_Level], ah
  2101 00009935 08E4                <1> 	or	ah, ah
  2102 00009937 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
  2103 00009939 803D[8D200100]02    <1> 	cmp	byte [Current_FATType], 2
  2104 00009940 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
  2105 00009942 28C0                <1> 	sub	al, al ; eax = 0
  2106 00009944 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
  2107                              <1> 
  2108                              <1> loc_UPDLMDT_proc_retn:
  2109 00009946 C3                  <1> 	retn
  2110                              <1>          
  2111                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
  2112 00009947 B010                <1> 	mov	al, 16
  2113 00009949 F6E4                <1> 	mul	ah 
  2114 0000994B 01C6                <1> 	add	esi, eax
  2115                              <1> 
  2116                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:  
  2117 0000994D 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
  2118                              <1> 
  2119                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
  2120 00009950 A3[88200100]        <1> 	mov	[Current_Dir_FCluster], eax
  2121                              <1> 
  2122 00009955 83C610              <1> 	add	esi, 16
  2123 00009958 66BF[162A]          <1> 	mov	di, Dir_File_Name  
  2124 0000995C F3A4                <1> 	rep	movsb
  2125                              <1> 	
  2126 0000995E BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2127 00009963 29DB                <1> 	sub	ebx, ebx
  2128 00009965 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  2129 0000996B 01DE                <1> 	add	esi, ebx
  2130 0000996D E88FF7FFFF          <1> 	call	reload_current_directory
  2131 00009972 7232                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2132                              <1> 
  2133                              <1> loc_update_parent_dir_lmdt_locate_dir: 
  2134 00009974 BE[162A0100]        <1> 	mov	esi, Dir_File_Name        
  2135 00009979 6631C9              <1> 	xor	cx, cx
  2136 0000997C 66B81008            <1> 	mov	ax, 0810h ; Only directories
  2137 00009980 E8B7F6FFFF          <1>         call    locate_current_dir_file
  2138                              <1> 	; EDI = DirBuff Directory Entry Address
  2139 00009985 721F                <1> 	jc short loc_update_parent_dir_lmdt_restore_cdirlevel
  2140                              <1> 
  2141 00009987 E836FEFFFF          <1> 	call	convert_current_date_time
  2142 0000998C 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
  2143 00009990 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
  2144 00009994 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
  2145                              <1> 
  2146 00009998 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2147 0000999F E8BCFEFFFF          <1> 	call	save_directory_buffer
  2148 000099A4 7200                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2149                              <1> 	;xor	al, al 
  2150                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
  2151                              <1>  	;current directory level restoration
  2152 000099A6 8A25[302B0100]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
  2153 000099AC 8825[8C200100]      <1> 	mov	[Current_Dir_Level], ah
  2154 000099B2 8B15[312B0100]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
  2155 000099B8 8915[88200100]      <1> 	mov	[Current_Dir_FCluster], edx
  2156                              <1> 
  2157 000099BE 5E                  <1> 	pop	esi ; *
  2158 000099BF C3                  <1> 	retn
  2159                              <1> 
  2160                              <1> delete_longname:
  2161                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2162                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
  2163                              <1> 	; 14/03/2010
  2164                              <1> 	; INPUT ->
  2165                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
  2166                              <1> 	; OUTPUT ->
  2167                              <1> 	;	cf = 0 -> OK  (EAX = 0)
  2168                              <1> 	; 	cf = 1 -> error code in EAX (AL)
  2169                              <1> 	;
  2170                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
  2171                              <1> 
  2172 000099C0 66A3[5C2B0100]      <1> 	mov	[DLN_EntryNumber], ax
  2173 000099C6 C605[5E2B0100]40    <1>         mov     byte [DLN_40h], 40h
  2174                              <1> 
  2175 000099CD E858000000          <1> 	call	locate_current_dir_entry
  2176 000099D2 7308                <1> 	jnc	short loc_dln_check_attributes
  2177 000099D4 C3                  <1> 	retn
  2178                              <1> 
  2179                              <1> loc_dln_longname_not_found:
  2180 000099D5 B802000000          <1> 	mov	eax, 2
  2181 000099DA F9                  <1> 	stc
  2182 000099DB C3                  <1> 	retn
  2183                              <1> 
  2184                              <1> loc_dln_check_attributes:
  2185 000099DC B00F                <1> 	mov	al, 0Fh  ; long name
  2186 000099DE 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
  2187 000099E1 38C4                <1> 	cmp	ah, al
  2188 000099E3 75F0                <1> 	jne	short loc_dln_longname_not_found
  2189 000099E5 8A27                <1> 	mov	ah, [edi]
  2190 000099E7 2A25[5E2B0100]      <1> 	sub	ah, [DLN_40h]
  2191 000099ED 76E6                <1> 	jna	short loc_dln_longname_not_found         
  2192 000099EF 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
  2193 000099F2 77E1                <1> 	ja	short loc_dln_longname_not_found
  2194                              <1>              
  2195 000099F4 C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
  2196 000099F7 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
  2197 000099FE C605[5E2B0100]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
  2198                              <1> 	  
  2199                              <1> loc_dln_delete_next_ln_entry:
  2200 00009A05 80FC01              <1> 	cmp	ah, 1
  2201 00009A08 7616                <1> 	jna	short loc_dln_longname_retn
  2202                              <1> loc_dln_delete_next_ln_entry_0:
  2203 00009A0A 66FF05[5C2B0100]    <1> 	inc	word [DLN_EntryNumber]
  2204 00009A11 0FB705[5C2B0100]    <1> 	movzx	eax, word [DLN_EntryNumber] 
  2205 00009A18 E80D000000          <1> 	call	locate_current_dir_entry
  2206 00009A1D 73BD                <1> 	jnc	short loc_dln_check_attributes
  2207                              <1> 
  2208                              <1> loc_dln_longname_stc_retn:
  2209 00009A1F C3                  <1> 	retn 
  2210                              <1> 	   
  2211                              <1> loc_dln_longname_retn:
  2212                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2213                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
  2214 00009A20 E83BFEFFFF          <1> 	call	save_directory_buffer
  2215 00009A25 72F8                <1> 	jc	short loc_dln_longname_stc_retn
  2216                              <1> 
  2217                              <1> loc_dln_longname_retn_xor_eax:
  2218 00009A27 31C0                <1> 	xor	eax, eax
  2219 00009A29 C3                  <1> 	retn
  2220                              <1> 
  2221                              <1> locate_current_dir_entry:
  2222                              <1> 	; 23/03/2016
  2223                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2224                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
  2225                              <1> 	; 07/03/2010
  2226                              <1> 	; INPUT ->
  2227                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536) 
  2228                              <1> 	; OUTPUT ->
  2229                              <1> 	;	EDI = Directory Entry Address
  2230                              <1> 	; 	EAX = Cluster Number of Directory Buffer
  2231                              <1> 	;	EBX = Directory Buffer Entry Offset
  2232                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
  2233                              <1> 	;   	If CF = 0 and CL = 2 then
  2234                              <1> 	;	   directory buffer modified and
  2235                              <1> 	;	   must be written to disk.
  2236                              <1> 	; 	If CF = 0  and CL = 1 then
  2237                              <1> 	;	   dir buffer has been written to disk, already.
  2238                              <1> 	;	CF = 1 -> Error code in EAX (AL)
  2239                              <1> 	;
  2240                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
  2241                              <1> 
  2242                              <1> loc_locate_current_dir_entry:
  2243 00009A2A 56                  <1> 	push	esi
  2244 00009A2B 89C1                <1> 	mov	ecx, eax
  2245 00009A2D BA20000000          <1> 	mov	edx, 32
  2246 00009A32 F7E2                <1> 	mul	edx 
  2247 00009A34 A3[682B0100]        <1> 	mov	[LCDE_ByteOffset], eax
  2248 00009A39 31DB                <1> 	xor	ebx, ebx
  2249 00009A3B 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  2250 00009A41 A0[B6280100]        <1>         mov     al, [DirBuff_DRV]
  2251 00009A46 2C41                <1> 	sub	al, 'A'
  2252 00009A48 BE00010900          <1>         mov     esi, Logical_DOSDisks
  2253 00009A4D 01DE                <1> 	add	esi, ebx
  2254 00009A4F 38C7                <1> 	cmp	bh, al
  2255 00009A51 0F8592000000        <1>         jne     loc_lcde_reload_current_directory
  2256                              <1> loc_lcde_cdl_check:
  2257 00009A57 803D[8C200100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2258 00009A5E 772A                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
  2259                              <1> 	; 27/02/2016
  2260                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2261                              <1> 	; (Root Directory Entries for FAT32 = 0)
  2262 00009A60 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2263 00009A64 7324                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
  2264                              <1> 
  2265                              <1> loc_lcde_cdl_check_FAT12_16:
  2266 00009A66 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
  2267 00009A6A 6648                <1> 	dec	ax
  2268                              <1> 	;xor	dx, dx  
  2269 00009A6C 6639C8              <1> 	cmp	ax, cx ; cx = Directory Entry (Index) Number
  2270 00009A6F 720E                <1> 	jb	short loc_lcde_stc_12h_retn
  2271 00009A71 66890D[602B0100]    <1> 	mov	[LCDE_EntryIndex], cx
  2272 00009A78 31C0                <1> 	xor	eax, eax
  2273 00009A7A E993000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
  2274                              <1> 
  2275                              <1> loc_lcde_stc_12h_retn:
  2276 00009A7F 5E                  <1> 	pop	esi
  2277 00009A80 89CB                <1> 	mov	ebx, ecx
  2278 00009A82 89D1                <1> 	mov	ecx, edx
  2279 00009A84 B812000000          <1> 	mov	eax, 12h ; No more files
  2280 00009A89 C3                  <1> 	retn 
  2281                              <1> 
  2282                              <1> loc_lcde_calc_dirbuff_cluster_offset:
  2283 00009A8A 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2284 00009A8D 30FF                <1> 	xor	bh, bh
  2285 00009A8F 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  2286 00009A93 66F7E3              <1> 	mul	bx
  2287 00009A96 6609D2              <1>  	or	dx, dx ; If bytes per cluster > 32KB it is invalid
  2288 00009A99 755D                <1> 	jnz	short loc_lcde_invalid_format
  2289                              <1> 	;mov	ecx, eax
  2290 00009A9B 6689C1              <1> 	mov	cx, ax ; BYTES PER CLUSTER
  2291 00009A9E A1[682B0100]        <1> 	mov	eax, [LCDE_ByteOffset]
  2292                              <1> 	;sub	edx, edx
  2293 00009AA3 F7F1                <1> 	div	ecx
  2294 00009AA5 3DFFFF0000          <1> 	cmp	eax, 65535
  2295 00009AAA 774C                <1> 	ja	short loc_lcde_invalid_format
  2296                              <1> 
  2297                              <1> 	; cluster sequence number of directory (< 65536)
  2298 00009AAC 66A3[622B0100]      <1> 	mov	[LCDE_ClusterSN], ax 
  2299                              <1> 
  2300 00009AB2 6689D0              <1> 	mov	ax, dx ; byte offset in cluster (directory buffer)
  2301 00009AB5 66BB2000            <1> 	mov	bx, 32 ; ; 1 dir entry = 32 bytes
  2302 00009AB9 6629D2              <1>         sub     dx, dx  ; 0
  2303 00009ABC 66F7F3              <1> 	div	bx 
  2304 00009ABF 66A3[602B0100]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
  2305                              <1> 				      ; (in directory buffer/cluster)	  
  2306                              <1> loc_lcde_get_current_sub_dir_fcluster:
  2307 00009AC5 A1[88200100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2308                              <1> 
  2309                              <1> loc_lcde_get_next_cluster:
  2310 00009ACA 66833D[622B0100]00  <1> 	cmp	word [LCDE_ClusterSN], 0
  2311 00009AD2 763E                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
  2312 00009AD4 A3[642B0100]        <1> 	mov	[LCDE_Cluster], eax
  2313 00009AD9 E815100000          <1> 	call	get_next_cluster
  2314 00009ADE 7220                <1> 	jc	short loc_lcde_check_gnc_error
  2315 00009AE0 66FF0D[622B0100]    <1>   	dec	word [LCDE_ClusterSN]
  2316 00009AE7 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
  2317                              <1> 
  2318                              <1> loc_lcde_reload_current_directory:
  2319 00009AE9 51                  <1> 	push	ecx
  2320 00009AEA E812F6FFFF          <1> 	call	reload_current_directory
  2321 00009AEF 59                  <1> 	pop	ecx
  2322 00009AF0 0F8361FFFFFF        <1>         jnc     loc_lcde_cdl_check
  2323 00009AF6 5E                  <1> 	pop	esi
  2324 00009AF7 C3                  <1> 	retn
  2325                              <1> 
  2326                              <1> loc_lcde_invalid_format:
  2327 00009AF8 B80B000000          <1> 	mov	eax, 0Bh ; MSDOS Error code: Invalid Format
  2328                              <1> 	;mov	eax, 0Dh ; MSDOS Error code: Invalid Data
  2329                              <1> loc_lcde_drive_not_ready_read_err:
  2330 00009AFD F9                  <1> 	stc
  2331 00009AFE 5E                  <1> 	pop	esi 
  2332 00009AFF C3                  <1> 	retn  
  2333                              <1> 
  2334                              <1> loc_lcde_check_gnc_error:
  2335 00009B00 09C0                <1> 	or	eax, eax
  2336 00009B02 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
  2337 00009B04 66FF0D[622B0100]    <1> 	dec	word [LCDE_ClusterSN]
  2338 00009B0B 75EB                <1> 	jnz	short loc_lcde_invalid_format 
  2339 00009B0D A1[642B0100]        <1> 	mov	eax, [LCDE_Cluster]
  2340                              <1> 
  2341                              <1> loc_lcde_check_dir_buffer_cluster:
  2342 00009B12 3B05[BD280100]      <1> 	cmp	eax, [DirBuff_Cluster]
  2343 00009B18 755C                <1> 	jne	short loc_lcde_load_dir_cluster
  2344 00009B1A 803D[B8280100]00    <1> 	cmp	byte [DirBuff_ValidData], 0
  2345 00009B21 7727                <1> 	ja	short lcde_check_dir_buffer_cluster_next
  2346 00009B23 803D[8C200100]00    <1> 	cmp	byte [Current_Dir_Level], 0    
  2347 00009B2A 775F                <1> 	ja	short loc_lcde_load_dir_cluster_0
  2348                              <1> 	; 27/02/2016
  2349                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2350 00009B2C 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2351 00009B30 7359                <1> 	jnb	short loc_lcde_load_dir_cluster_0
  2352                              <1> 	;
  2353 00009B32 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
  2354 00009B36 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
  2355 00009B3A 66C1E904            <1> 	shr	cx, 4 ; 1 sector contains 16 dir entries	
  2356                              <1> 
  2357 00009B3E 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
  2358 00009B41 EB54                <1> 	jmp	short loc_lcde_load_dir_cluster_1 
  2359                              <1> 
  2360                              <1> loc_lcde_validate_dirBuff:
  2361 00009B43 C605[B8280100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2362                              <1> 
  2363                              <1> lcde_check_dir_buffer_cluster_next:
  2364 00009B4A 0FB71D[602B0100]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
  2365 00009B51 663B1D[BB280100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  2366 00009B58 779E                <1> 	ja	short loc_lcde_invalid_format 
  2367 00009B5A B820000000          <1> 	mov	eax, 32
  2368 00009B5F F7E3                <1> 	mul	ebx
  2369                              <1> 	;or	edx, edx
  2370                              <1> 	;jnz	short loc_lcde_invalid_format
  2371                              <1> 
  2372 00009B61 BF00000800          <1> 	mov	edi, Directory_Buffer  
  2373 00009B66 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
  2374                              <1> 
  2375                              <1> loc_lcde_dir_buffer_last_check:
  2376 00009B68 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
  2377 00009B6D 0FB60D[B8280100]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
  2378                              <1> 
  2379                              <1> loc_lcde_retn:
  2380 00009B74 5E                  <1> 	pop	esi
  2381 00009B75 C3                  <1> 	retn
  2382                              <1> 
  2383                              <1> loc_lcde_load_dir_cluster:
  2384                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2385                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
  2386 00009B76 50                  <1> 	push	eax
  2387 00009B77 E8E4FCFFFF          <1> 	call	save_directory_buffer
  2388 00009B7C 58                  <1> 	pop	eax
  2389 00009B7D 72F5                <1> 	jc	short loc_lcde_retn
  2390                              <1> 
  2391                              <1> loc_lcde_load_dir_cluster_n2:
  2392 00009B7F C605[B8280100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2393 00009B86 A3[BD280100]        <1> 	mov	[DirBuff_Cluster], eax
  2394                              <1> 
  2395                              <1> loc_lcde_load_dir_cluster_0:
  2396 00009B8B 83E802              <1> 	sub	eax, 2
  2397 00009B8E 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  2398 00009B92 F7E1                <1> 	mul	ecx
  2399 00009B94 034668              <1>         add     eax, [esi+LD_DATABegin]
  2400                              <1> 
  2401                              <1> loc_lcde_load_dir_cluster_1:
  2402 00009B97 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2403                              <1> 	; ecx = sector count
  2404 00009B9C E87B3E0000          <1> 	call	disk_read
  2405 00009BA1 73A0                <1> 	jnc	short loc_lcde_validate_dirBuff
  2406                              <1> 
  2407                              <1> 	; 23/03/2016
  2408 00009BA3 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
  2409 00009BA8 EBCA                <1> 	jmp	short loc_lcde_retn
  2410                              <1> 
  2411                              <1> 
  2412                              <1> remove_file:
  2413                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2414                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
  2415                              <1> 	; 09/08/2010
  2416                              <1> 	; INPUT ->
  2417                              <1> 	;	EDI = Directory Buffer Entry Address
  2418                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2419                              <1> 	;	 BL = Longname Entry Length
  2420                              <1> 	;	 BH = Logical DOS Drive Number 
  2421                              <1> 
  2422 00009BAA 29C0                <1> 	sub	eax, eax
  2423 00009BAC 88FC                <1> 	mov	ah, bh
  2424 00009BAE BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2425 00009BB3 01C6                <1> 	add	esi, eax
  2426                              <1> 
  2427 00009BB5 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2428 00009BB9 7312                <1> 	jnb	short loc_del_fat_file 
  2429                              <1>               
  2430 00009BBB 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  2431 00009BBF 7406                <1> 	je	short loc_del_fs_file
  2432                              <1> 
  2433                              <1> loc_del_file_invalid_format:
  2434 00009BC1 30E4                <1> 	xor	ah, ah
  2435 00009BC3 B00B                <1> 	mov	al, 0Bh ; Invalid Format
  2436 00009BC5 F9                  <1> 	stc 
  2437 00009BC6 C3                  <1> 	retn
  2438                              <1> 
  2439                              <1> loc_del_fs_file:
  2440 00009BC7 E8200F0000          <1> 	call	delete_fs_file
  2441 00009BCC C3                  <1> 	retn
  2442                              <1> 
  2443                              <1> loc_del_fat_file:
  2444 00009BCD E808000000          <1> 	call	delete_directory_entry
  2445 00009BD2 7205                <1> 	jc	short loc_del_file_err_retn 
  2446                              <1> 
  2447                              <1> loc_delfile_unlink_cluster_chain:
  2448 00009BD4 E834170000          <1> 	call	truncate_cluster_chain
  2449                              <1> 	;jc	short loc_del_file_err_retn
  2450                              <1> 
  2451                              <1> loc_delfile_return:
  2452                              <1> loc_del_file_err_retn:
  2453 00009BD9 C3                  <1> 	retn
  2454                              <1> 
  2455                              <1> delete_directory_entry:
  2456                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2457                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
  2458                              <1> 	; 10/04/2011 
  2459                              <1> 	; INPUT ->
  2460                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
  2461                              <1> 	;	EDI = Directory Buffer Entry Address
  2462                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2463                              <1> 	;	 BL = Longname Entry Length
  2464                              <1> 	; OUTPUT ->
  2465                              <1> 	; 	ESI = Logical dos drive descripton table address 
  2466                              <1> 	;	EAX = First cluster to be truncated/unlinked
  2467                              <1> 	;       CF = 1 -> Error code in EAX (AL)
  2468                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
  2469                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
  2470                              <1> 	;
  2471                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
  2472                              <1> 
  2473 00009BDA 881D[FA2A0100]      <1> 	mov	[DelFile_LNEL], bl
  2474 00009BE0 66890D[F82A0100]    <1> 	mov	[DelFile_EntryCounter], cx
  2475                              <1> 
  2476 00009BE7 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  2477 00009BEB C1E010              <1> 	shl	eax, 16
  2478 00009BEE 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  2479                              <1> 
  2480 00009BF2 A3[F42A0100]        <1> 	mov	[DelFile_FCluster], eax
  2481                              <1> 
  2482                              <1> loc_del_short_name:
  2483 00009BF7 C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
  2484                              <1> 
  2485 00009BFA C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2486 00009C01 E85AFCFFFF          <1> 	call	save_directory_buffer
  2487 00009C06 723D                <1> 	jc	short loc_delete_direntry_err_return
  2488                              <1>  
  2489                              <1> loc_del_long_name:
  2490 00009C08 0FB615[FA2A0100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2491 00009C0F 08D2                <1> 	or	dl, dl
  2492 00009C11 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
  2493                              <1> 
  2494 00009C13 8835[FA2A0100]      <1> 	mov	byte [DelFile_LNEL], dh ; 0              
  2495                              <1>   
  2496 00009C19 0FB705[F82A0100]    <1> 	movzx	eax,  word [DelFile_EntryCounter]
  2497 00009C20 29D0                <1> 	sub	eax, edx
  2498                              <1> 	;jnc	short loc_del_long_name_continue
  2499 00009C22 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date   
  2500                              <1> 
  2501                              <1> ;loc_del_direntry_inv_data_return:
  2502                              <1> ;	mov	eax, 0Dh ; Invalid data
  2503                              <1> ;	retn
  2504                              <1> 
  2505                              <1> loc_del_long_name_continue: 
  2506                              <1> 	; AX = Directory Entry Number of the long name last entry
  2507 00009C24 E897FDFFFF          <1> 	call	delete_longname
  2508                              <1> 	;jc	short loc_delete_direntry_err_return
  2509                              <1> 
  2510                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
  2511 00009C29 801D[FA2A0100]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
  2512                              <1> 
  2513 00009C30 E8C6FCFFFF          <1> 	call	update_parent_dir_lmdt
  2514 00009C35 B700                <1> 	mov	bh, 0
  2515 00009C37 80D700              <1> 	adc	bh, 0
  2516                              <1> 
  2517 00009C3A 8A1D[FA2A0100]      <1> 	mov	bl, byte [DelFile_LNEL]
  2518                              <1>  
  2519                              <1> loc_delete_direntry_return:
  2520 00009C40 A1[F42A0100]        <1> 	mov	eax, [DelFile_FCluster]
  2521                              <1> loc_delete_direntry_err_return:
  2522 00009C45 C3                  <1> 	retn
  2523                              <1> 
  2524                              <1> rename_directory_entry:
  2525                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
  2526                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_rename_directory_entry')
  2527                              <1> 	; 19/11/2010
  2528                              <1> 	; INPUT -> (Current Directory)
  2529                              <1> 	;	CX = Directory Entry Number
  2530                              <1> 	;      EAX = First Cluster number of file or directory
  2531                              <1> 	;      EBX = Longname Length (dir entry count) (< 256)
  2532                              <1> 	;      ESI = New file (or directory) name (no path).
  2533                              <1> 	;           (ASCIIZ string)  
  2534                              <1> 	; OUTPUT -> 
  2535                              <1> 	;      CF = 0 -> successfull
  2536                              <1> 	;      CF = 1 -> error code in EAX (AL)
  2537                              <1> 	;
  2538                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2539                              <1> 
  2540 00009C46 803D[8D200100]00    <1> 	cmp	byte [Current_FATType], 0
  2541 00009C4D 7706                <1> 	ja	short loc_rename_directory_entry
  2542                              <1> 
  2543 00009C4F E8990E0000          <1> 	call	rename_fs_file_or_directory
  2544 00009C54 C3                  <1> 	retn 
  2545                              <1> 	
  2546                              <1> loc_rename_directory_entry:
  2547 00009C55 881D[FA2A0100]      <1> 	mov	[DelFile_LNEL], bl
  2548 00009C5B 66890D[F82A0100]    <1> 	mov	[DelFile_EntryCounter], cx
  2549 00009C62 A3[F42A0100]        <1> 	mov	[DelFile_FCluster], eax
  2550                              <1> 
  2551 00009C67 0FB7C1              <1> 	movzx	eax, cx
  2552 00009C6A E8BBFDFFFF          <1> 	call	locate_current_dir_entry
  2553 00009C6F 7308                <1> 	jnc	short loc_rename_direntry_check_fcluster
  2554                              <1> 
  2555                              <1> loc_rename_direntry_pop_retn:
  2556 00009C71 C3                  <1> 	retn
  2557                              <1> 
  2558                              <1> loc_rename_direntry_pop_invd_retn:
  2559 00009C72 F9                  <1> 	stc
  2560                              <1> loc_rename_direntry_invd_retn:
  2561 00009C73 B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
  2562                              <1> loc_rename_retn:
  2563 00009C78 C3                  <1> 	retn 
  2564                              <1> 
  2565                              <1> loc_rename_direntry_check_fcluster:
  2566 00009C79 668B5714            <1> 	mov	dx, [edi+20] ; First Cluster HW
  2567 00009C7D 66C1E210            <1> 	shl	dx, 16
  2568 00009C81 668B571A            <1> 	mov	dx, [edi+26] ; First Cluster LW
  2569 00009C85 3B15[F42A0100]      <1> 	cmp	edx, [DelFile_FCluster]
  2570 00009C8B 75E5                <1> 	jne	short loc_rename_direntry_pop_invd_retn
  2571                              <1> 	; ESI = New file (or directory) name. (ASCIIZ string)
  2572                              <1> 	; 06/03/2016
  2573                              <1> 	; TRDOS v2 - NOTE: 'convert_file_name' procedure
  2574                              <1> 	; has been modified for eliminating following situation.
  2575                              <1> 	; 
  2576                              <1> 	; TRDOS v1 - NOTE: If file/dir name is more than 11 bytes
  2577                              <1> 	; without a dot, attributes (edi+11) byte will be overwritten !
  2578                              <1> 	; (Dot file name input must be proper for 11 byte dir entry
  2579                              <1> 	;  type file name output.) 
  2580 00009C8D E89FF6FFFF          <1> 	call	convert_file_name
  2581                              <1> 
  2582 00009C92 C605[B8280100]02    <1>         mov     byte [DirBuff_ValidData], 2
  2583 00009C99 E8C2FBFFFF          <1> 	call	save_directory_buffer
  2584 00009C9E 72D8                <1> 	jc	short loc_rename_retn
  2585                              <1> 
  2586                              <1> loc_rename_direntry_del_ln:
  2587 00009CA0 0FB615[FA2A0100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2588 00009CA7 08D2                <1> 	or	dl, dl
  2589 00009CA9 7410                <1> 	jz	short loc_rename_direntry_update_parent_dir_lm_date
  2590                              <1> 
  2591 00009CAB 0FB705[F82A0100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  2592 00009CB2 29D0                <1> 	sub	eax, edx
  2593 00009CB4 72BD                <1> 	jc	short loc_rename_direntry_invd_retn
  2594                              <1> 
  2595                              <1> loc_rename_direntry_del_ln_continue: 
  2596                              <1> 	; EAX = Directory Entry Number of the long name last entry
  2597 00009CB6 E805FDFFFF          <1> 	call	delete_longname
  2598                              <1> 
  2599                              <1> loc_rename_direntry_update_parent_dir_lm_date:
  2600 00009CBB E83BFCFFFF          <1> 	call	update_parent_dir_lmdt
  2601 00009CC0 31C0                <1> 	xor	eax, eax 
  2602 00009CC2 C3                  <1> 	retn
  2603                              <1> 
  2604                              <1> move_source_file_to_destination_file:
  2605                              <1> 	; 11/03/2016
  2606                              <1> 	; 10/03/2016 (TRDOS 386 = TRDOS v2.0)
  2607                              <1> 	; 01/08/2011 (FILE.ASM)
  2608                              <1> 	; 04/08/2010
  2609                              <1> 	;
  2610                              <1> 	;   Phase 1 -> Check destination file, 
  2611                              <1> 	;              'not found' is required
  2612                              <1> 	;   Phase 2 -> Check source file
  2613                              <1> 	;              'found' and proper attributes is required
  2614                              <1> 	;   Phase 3 -> Make destination directory entry,
  2615                              <1> 	;           add new dir cluster or section if it is required
  2616                              <1> 	;   Phase 4 -> Delete source directory entry.
  2617                              <1> 	;       cf = 1 causes to return before the phase 4.
  2618                              <1> 	;    (source file protection against any possible errors)    
  2619                              <1> 	;
  2620                              <1> 	; 08/05/2011 major modification
  2621                              <1> 	;            -> destination file deleting is removed   
  2622                              <1> 	;            for msdos move/rename compatibility.
  2623                              <1> 	;            (Access denied error will return if
  2624                              <1> 	;            the destination file is found...)
  2625                              <1> 	; INPUT ->
  2626                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  2627                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  2628                              <1> 	;        AL = 0 --> Interrupt (System call)
  2629                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  2630                              <1> 	;        AL = 1 --> Question Phase
  2631                              <1> 	;        AL = 2 --> Progress Phase        
  2632                              <1> 	; OUTPUT -> 
  2633                              <1> 	;	 cf = 0 -> OK
  2634                              <1> 	;        EAX = Destination directory first cluster
  2635                              <1> 	;        ESI = Logical DOS drive description table 
  2636                              <1> 	;        EBX = Destination file structure offset
  2637                              <1> 	;        CX = 0 (CX > 0 --> calculate free space error)
  2638                              <1> 	;        cf = 1 -> Error code in EAX (AL) 
  2639                              <1> 	;
  2640                              <1> 	;  (EDX, ECX, EBX, ESI, EDI will be changed)
  2641                              <1> 
  2642 00009CC3 3C02                <1> 	cmp	al, 2
  2643 00009CC5 0F846D010000        <1> 	je	msftdf_df2_check_directory
  2644 00009CCB A2[762C0100]        <1> 	mov	[move_cmd_phase], al
  2645                              <1> 
  2646                              <1> msftdf_parse_sf_path:
  2647                              <1> 	; ESI = ASCIIZ pathname (Source)
  2648 00009CD0 57                  <1> 	push	edi 
  2649 00009CD1 BF[742B0100]        <1> 	mov	edi, SourceFile_Drv
  2650 00009CD6 E821F7FFFF          <1> 	call	parse_path_name
  2651 00009CDB 5E                  <1> 	pop	esi
  2652 00009CDC 7211                <1> 	jc	short msftdf_psf_retn
  2653                              <1> 
  2654                              <1> msftdf_parse_df_path:
  2655                              <1> 	; ESI = ASCIIZ pathname	(Destination)
  2656 00009CDE BF[F42B0100]        <1> 	mov	edi, DestinationFile_Drv
  2657 00009CE3 E814F7FFFF          <1> 	call	parse_path_name
  2658 00009CE8 7306                <1> 	jnc	short msftdf_check_sf_drv
  2659                              <1> 
  2660 00009CEA 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  2661 00009CEC 7602                <1> 	jna	short msftdf_check_sf_drv
  2662                              <1> 
  2663                              <1> msftdf_stc_retn:
  2664 00009CEE F9                  <1> 	stc
  2665                              <1> msftdf_psf_retn:
  2666 00009CEF C3                  <1> 	retn 
  2667                              <1> 
  2668                              <1> msftdf_check_sf_drv:
  2669 00009CF0 A0[742B0100]        <1> 	mov	al, [SourceFile_Drv]
  2670                              <1> 
  2671                              <1> msftdf_check_df_drv:
  2672 00009CF5 8A15[F42B0100]      <1> 	mov	dl, [DestinationFile_Drv]
  2673                              <1> 
  2674                              <1> msftdf_compare_sf_df_drv:
  2675 00009CFB 29DB                <1> 	sub	ebx, ebx
  2676 00009CFD 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  2677 00009D03 38C2                <1> 	cmp	dl, al
  2678 00009D05 7409                <1> 	je	short msftdf_check_sf_df_drv_ok
  2679                              <1> 
  2680                              <1> msftdf_not_same_drv:
  2681                              <1>         ; DL = source file's drive number
  2682 00009D07 88C6                <1> 	mov	dh, al ; destination file's drive number
  2683 00009D09 B811000000          <1> 	mov	eax, 11h ; Not the same drive
  2684 00009D0E F9                  <1> 	stc
  2685 00009D0F C3                  <1> 	retn 
  2686                              <1> 
  2687                              <1> msftdf_check_sf_df_drv_ok:
  2688 00009D10 8815[772C0100]      <1> 	mov	[msftdf_sf_df_drv], dl
  2689                              <1> 
  2690 00009D16 29C0                <1>         sub	eax, eax
  2691 00009D18 88D4                <1> 	mov	ah, dl
  2692 00009D1A 0500010900          <1> 	add	eax, Logical_DOSDisks
  2693 00009D1F A3[782C0100]        <1> 	mov	[msftdf_drv_offset], eax
  2694                              <1> 
  2695 00009D24 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  2696 00009D26 7407                <1> 	je	short msftdf_df_check_directory
  2697                              <1> 
  2698                              <1> msftdf_change_drv:
  2699 00009D28 E829C1FFFF          <1> 	call 	change_current_drive
  2700 00009D2D 725B                <1> 	jc	short msftdf_df_error_retn
  2701                              <1> 	  
  2702                              <1> msftdf_check_destination_file:
  2703                              <1> msftdf_df_check_directory:
  2704 00009D2F BE[F52B0100]        <1> 	mov	esi, DestinationFile_Directory
  2705 00009D34 803E20              <1> 	cmp	byte [esi], 20h
  2706 00009D37 760F                <1> 	jna	short msftdf_df_find_1
  2707                              <1> 
  2708                              <1> msftdf_df_change_directory:
  2709 00009D39 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2710 00009D3F 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2711 00009D41 E8A2F0FFFF          <1> 	call	change_current_directory
  2712 00009D46 7242                <1> 	jc	short msftdf_df_error_retn
  2713                              <1> 
  2714                              <1> ;msftdf_df_change_prompt_dir_string:
  2715                              <1> ;	call 	change_prompt_dir_string
  2716                              <1> 
  2717                              <1> msftdf_df_find_1:
  2718 00009D48 BE[362C0100]        <1>         mov     esi, DestinationFile_Name
  2719 00009D4D 803E20              <1> 	cmp	byte [esi], 20h
  2720 00009D50 761F                <1> 	jna	short msftdf_df_copy_sf_name
  2721                              <1> 
  2722                              <1> msftdf_df_find_2:
  2723 00009D52 6631C0              <1> 	xor	ax, ax ; DestinationFile_AttributesMask -> any/zero
  2724 00009D55 E898D4FFFF          <1> 	call	find_first_file
  2725 00009D5A 737F                <1> 	jnc	short msftdf_permission_denied_retn
  2726                              <1> 
  2727                              <1> msftdf_df_check_error_code:
  2728                              <1> 	;cmp	eax, 2 ; File not found error
  2729 00009D5C 3C02                <1> 	cmp	al, 2
  2730 00009D5E 7529                <1> 	jne	short msftdf_df_stc_retn
  2731                              <1>               
  2732                              <1> msftdf_convert_df_direntry_name:
  2733 00009D60 BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  2734 00009D65 BF[462C0100]        <1> 	mov	edi, DestinationFile_DirEntry
  2735 00009D6A E8C2F5FFFF          <1> 	call	convert_file_name
  2736 00009D6F EB1A                <1>   	jmp	short msftdf_restore_current_dir_1
  2737                              <1> 
  2738                              <1> msftdf_df_copy_sf_name:
  2739 00009D71 89F7                <1> 	mov	edi, esi
  2740 00009D73 57                  <1> 	push	edi 
  2741 00009D74 BE[B62B0100]        <1>         mov     esi, SourceFile_Name
  2742 00009D79 B90C000000          <1> 	mov	ecx, 12
  2743                              <1> msftdf_df_copy_sf_name_loop:
  2744 00009D7E AC                  <1> 	lodsb
  2745 00009D7F AA                  <1>         stosb
  2746 00009D80 08C0                <1> 	or	al, al
  2747 00009D82 7402                <1> 	jz	short msftdf_df_copy_sf_name_ok	
  2748 00009D84 E2F8                <1>         loop    msftdf_df_copy_sf_name_loop
  2749                              <1> msftdf_df_copy_sf_name_ok:	
  2750 00009D86 5E                  <1> 	pop	esi  
  2751 00009D87 EBC9                <1> 	jmp	short msftdf_df_find_2
  2752                              <1> 
  2753                              <1> msftdf_df_stc_retn:
  2754 00009D89 F9                  <1> 	stc
  2755                              <1> msftdf_restore_cdir_failed:
  2756                              <1> msftdf_df_error_retn:
  2757 00009D8A C3                  <1> 	retn
  2758                              <1> 
  2759                              <1> msftdf_restore_current_dir_1:
  2760 00009D8B 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  2761 00009D92 760D                <1> 	jna	short msftdf_sf_check_directory
  2762 00009D94 8B35[782C0100]      <1> 	mov	esi, [msftdf_drv_offset] 
  2763 00009D9A E869C1FFFF          <1> 	call	restore_current_directory
  2764 00009D9F 72E9                <1> 	jc	short msftdf_restore_cdir_failed
  2765                              <1> 
  2766                              <1> msftdf_sf_check_directory:
  2767 00009DA1 BE[752B0100]        <1> 	mov	esi, SourceFile_Directory
  2768 00009DA6 803E20              <1> 	cmp	byte [esi], 20h
  2769 00009DA9 760F                <1> 	jna	short msftdf_sf_find
  2770                              <1> msftdf_sf_change_directory:
  2771 00009DAB FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2772 00009DB1 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2773 00009DB3 E830F0FFFF          <1> 	call	change_current_directory
  2774 00009DB8 7227                <1> 	jc	short msftdf_return
  2775                              <1> 
  2776                              <1> ;msftdf_sf_change_prompt_dir_string:
  2777                              <1> ;	call	change_prompt_dir_string
  2778                              <1> 
  2779                              <1> msftdf_sf_find:
  2780 00009DBA BE[B62B0100]        <1>         mov     esi, SourceFile_Name  ; Offset 66
  2781 00009DBF 66B80018            <1> 	mov	ax, 1800h ; Only files
  2782 00009DC3 E82AD4FFFF          <1> 	call	find_first_file
  2783 00009DC8 7217                <1> 	jc	short msftdf_return
  2784                              <1> 
  2785                              <1> msftdf_sf_ambgfn_check:
  2786 00009DCA 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  2787 00009DCD 7407                <1> 	jz	short msftdf_sf_found
  2788                              <1> 
  2789                              <1> msftdf_ambiguous_file_name_error:
  2790 00009DCF B802000000          <1> 	mov	eax, 2 ; File not found error
  2791 00009DD4 F9                  <1> 	stc
  2792 00009DD5 C3                  <1> 	retn
  2793                              <1> 
  2794                              <1> msftdf_sf_found:
  2795 00009DD6 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
  2796 00009DD9 7416                <1> 	jz	short msftdf_save_sf_structure
  2797                              <1> 
  2798                              <1> msftdf_permission_denied_retn:
  2799 00009DDB B805000000          <1> 	mov	eax, 05h ; Access (Permission) denied !
  2800 00009DE0 F9                  <1> 	stc
  2801                              <1> msftdf_rest_cdir_err_retn:
  2802                              <1> msftdf_return:
  2803 00009DE1 C3                  <1> 	retn
  2804                              <1> 
  2805                              <1> msftdf_phase_1_return:
  2806 00009DE2 31C0                <1> 	xor	eax, eax
  2807 00009DE4 A2[762C0100]        <1> 	mov	[move_cmd_phase], al ; 0
  2808 00009DE9 FEC0                <1> 	inc	al ; mov al, 1
  2809 00009DEB BB[389E0000]        <1> 	mov	ebx, msftdf_df2_check_directory
  2810                              <1> 	;mov	edx, 0FFFFFFFFh 
  2811 00009DF0 C3                  <1> 	retn
  2812                              <1> 
  2813                              <1> msftdf_save_sf_structure:
  2814 00009DF1 BE[842A0100]        <1> 	mov	esi, FindFile_DirEntry
  2815 00009DF6 BF[C62B0100]        <1> 	mov	edi, SourceFile_DirEntry
  2816 00009DFB B908000000          <1> 	mov	ecx, 8
  2817 00009E00 F3A5                <1> 	rep	movsd
  2818                              <1> 
  2819                              <1> msftdf_df_copy_sf_parameters:
  2820 00009E02 BE0B000000          <1> 	mov	esi, 11
  2821 00009E07 89F7                <1> 	mov	edi, esi
  2822 00009E09 81C6[C62B0100]      <1> 	add	esi, SourceFile_DirEntry
  2823 00009E0F 81C7[462C0100]      <1> 	add	edi, DestinationFile_DirEntry
  2824                              <1> 	;mov	ecx, 21
  2825 00009E15 B115                <1> 	mov	cl, 21
  2826 00009E17 F3A4                <1> 	rep	movsb
  2827                              <1> 
  2828                              <1> msftdf_restore_current_dir_2:
  2829 00009E19 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  2830 00009E20 760D                <1> 	jna	short msftdf_df2_check_move_cmd_phase
  2831 00009E22 8B35[782C0100]      <1>  	mov	esi, [msftdf_drv_offset]
  2832 00009E28 E8DBC0FFFF          <1> 	call	restore_current_directory
  2833 00009E2D 72B2                <1> 	jc	short msftdf_rest_cdir_err_retn
  2834                              <1> 
  2835                              <1> msftdf_df2_check_move_cmd_phase:
  2836 00009E2F 803D[762C0100]01    <1> 	cmp	byte [move_cmd_phase], 1
  2837 00009E36 74AA                <1> 	je	short msftdf_phase_1_return
  2838                              <1> 
  2839                              <1> msftdf_df2_check_directory:
  2840 00009E38 BE[F52B0100]        <1> 	mov	esi, DestinationFile_Directory
  2841 00009E3D 803E20              <1> 	cmp	byte [esi], 20h
  2842 00009E40 760F                <1> 	jna	short msftdf_make_dfde_locate_ffe_on_directory
  2843                              <1> msftdf_df2_change_directory:
  2844 00009E42 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2845 00009E48 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2846 00009E4A E899EFFFFF          <1> 	call	change_current_directory
  2847 00009E4F 7290                <1> 	jc	short msftdf_return
  2848                              <1> 
  2849                              <1> ;msftdf_df2_change_prompt_dir_string:
  2850                              <1> ;	call	change_prompt_dir_string
  2851                              <1> 
  2852                              <1> msftdf_make_dfde_locate_ffe_on_directory:
  2853                              <1> 	; Current directory fcluster <> Directory buffer cluster
  2854                              <1> 	; Current directory will be reloaded by
  2855                              <1> 	; 'locate_current_dir_file' procedure
  2856                              <1> 	;
  2857                              <1> 	;xor	ax, ax
  2858 00009E51 31C0                <1> 	xor	eax, eax
  2859 00009E53 89C1                <1> 	mov	ecx, eax
  2860 00009E55 6649                <1> 	dec	cx ; FFFFh  
  2861                              <1> 		; CX = FFFFh -> find first deleted or free entry
  2862                              <1> 		; ESI would be ASCIIZ filename address if the call
  2863                              <1> 		; would not be for first free or deleted dir entry  
  2864 00009E57 E8E0F1FFFF          <1> 	call	locate_current_dir_file
  2865 00009E5C 733F                <1> 	jnc	msftdf_make_dfde_set_ff_dir_entry
  2866                              <1> 	
  2867                              <1> 	;cmp	eax, 2
  2868 00009E5E 3C02                <1>         cmp	al, 2
  2869 00009E60 7537                <1> 	jne	short msftdf_error_retn
  2870                              <1> 
  2871                              <1> msftdf_add_new_dir_entry_check_fs:
  2872 00009E62 8B35[782C0100]      <1> 	mov	esi, [msftdf_drv_offset]
  2873 00009E68 A1[BD280100]        <1> 	mov 	eax, [DirBuff_Cluster]
  2874 00009E6D 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2875 00009E71 7711                <1> 	ja	short msftdf_add_new_subdir_cluster
  2876                              <1> 
  2877                              <1> msftdf_add_new_fs_subdir_section:
  2878                              <1> 	;CL=0, CH=E5h --> deleted entry, CH=0 --> free entry
  2879                              <1>         ;xor	cx, cx
  2880 00009E73 30ED                <1> 	xor	ch, ch ; cx = 0 --> add a new subdir section
  2881 00009E75 E8750C0000          <1> 	call	add_new_fs_section
  2882 00009E7A 721E                <1>         jc	short msftdf_dsfde_error_retn
  2883                              <1> 	;mov	[createfile_LastDirCluster], eax
  2884                              <1> 
  2885 00009E7C E8950E0000          <1> 	call	load_FS_sub_directory 
  2886                              <1> 	;mov	ebx, Directory_Buffer 
  2887 00009E81 7318                <1> 	jnc	short msftdf_add_new_fs_subdir_section_ok
  2888 00009E83 C3                  <1> 	retn	 
  2889                              <1> 
  2890                              <1> msftdf_add_new_subdir_cluster:
  2891 00009E84 E863150000          <1> 	call	add_new_cluster
  2892 00009E89 720F                <1> 	jc	short msftdf_dsfde_error_retn
  2893                              <1> 	
  2894                              <1> 	;mov	[createfile_LastDirCluster], eax
  2895                              <1> 
  2896 00009E8B E8490E0000          <1> 	call	load_FAT_sub_directory
  2897 00009E90 7309                <1> 	jnc	short msftdf_add_new_subdir_cluster_ok
  2898                              <1> 	; EBX = Directory buffer address
  2899                              <1> 
  2900                              <1> msftdf_ansdc_update_parent_dir_lmdt:
  2901                              <1> msftdf_make_dfde_err_upd_pdir_lmdt:
  2902 00009E92 50                  <1> 	push	eax
  2903 00009E93 E863FAFFFF          <1> 	call	update_parent_dir_lmdt
  2904 00009E98 58                  <1> 	pop	eax
  2905                              <1> 
  2906                              <1> msftdf_error_retn:
  2907 00009E99 F9                  <1> 	stc
  2908                              <1> msftdf_dsfde_restore_cdir_failed:
  2909                              <1> msftdf_dsfde_error_retn:
  2910 00009E9A C3                  <1> 	retn
  2911                              <1> 
  2912                              <1> msftdf_add_new_fs_subdir_section_ok:
  2913                              <1> msftdf_add_new_subdir_cluster_ok:
  2914 00009E9B 89DF                <1> 	mov	edi, ebx ; Directory buffer address
  2915                              <1> 
  2916                              <1> msftdf_make_dfde_set_ff_dir_entry:
  2917 00009E9D 8B15[88200100]      <1> 	mov	edx, [Current_Dir_FCluster]
  2918 00009EA3 8915[DC2C0100]      <1> 	mov	[createfile_FFCluster], edx
  2919                              <1> 	; EDI = Directory entry offset
  2920 00009EA9 BE[462C0100]        <1> 	mov	esi, DestinationFile_DirEntry
  2921 00009EAE B908000000          <1> 	mov	ecx, 8
  2922 00009EB3 F3A5                <1> 	rep	movsd
  2923                              <1> 
  2924 00009EB5 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  2925 00009EBC E89FF9FFFF          <1> 	call	save_directory_buffer
  2926 00009EC1 72CF                <1> 	jc	short msftdf_make_dfde_err_upd_pdir_lmdt
  2927                              <1> 
  2928                              <1> msftdf_make_dfde_update_pdir_lmdt:
  2929 00009EC3 E833FAFFFF          <1> 	call	update_parent_dir_lmdt
  2930                              <1> 
  2931                              <1> msftdf_dsfde_restore_current_dir_1:
  2932 00009EC8 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  2933 00009ECF 760D                <1> 	jna	short msftdf_dsfde_check_directory
  2934 00009ED1 8B35[782C0100]      <1>  	mov	esi, [msftdf_drv_offset]
  2935 00009ED7 E82CC0FFFF          <1> 	call	restore_current_directory
  2936 00009EDC 72BC                <1> 	jc	short msftdf_dsfde_restore_cdir_failed
  2937                              <1> 
  2938                              <1> msftdf_dsfde_check_directory:
  2939 00009EDE BE[752B0100]        <1> 	mov	esi, SourceFile_Directory
  2940 00009EE3 803E20              <1> 	cmp	byte [esi], 20h
  2941 00009EE6 760F                <1> 	jna	short msftdf_dsfde_find_file
  2942                              <1> 
  2943                              <1> msftdf_dsfde_change_directory:
  2944 00009EE8 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  2945 00009EEE 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
  2946 00009EF0 E8F3EEFFFF          <1> 	call	change_current_directory
  2947 00009EF5 72A3                <1> 	jc	short msftdf_dsfde_error_retn
  2948                              <1> 
  2949                              <1> ;msftdf_dsfde_sf_change_prompt_dir_string:
  2950                              <1> ;	call	change_prompt_dir_string
  2951                              <1> 
  2952                              <1> msftdf_dsfde_find_file:
  2953 00009EF7 BE[B62B0100]        <1> 	mov	esi, SourceFile_Name  ; Offset 66
  2954 00009EFC 668B460E            <1> 	mov	ax, [esi+14] ; 80 -> SourceFile_AttributesMask
  2955 00009F00 E8EDD2FFFF          <1> 	call	find_first_file
  2956 00009F05 7293                <1> 	jc	short msftdf_dsfde_error_retn
  2957                              <1> 
  2958                              <1> msftdf_dsfde_delete_direntry:
  2959 00009F07 8B35[782C0100]      <1> 	mov	esi, [msftdf_drv_offset]
  2960                              <1> 	
  2961 00009F0D 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2962 00009F11 770A                <1> 	ja	short msftdf_delete_FAT_direntry
  2963                              <1> 	
  2964 00009F13 30DB                <1> 	xor	bl, bl
  2965                              <1> 	; BL = 0 -> File
  2966                              <1> 	; EDI -> Directory buffer entry offset/address 
  2967 00009F15 E8D60B0000          <1> 	call	delete_fs_directory_entry
  2968 00009F1A 7315                <1> 	jnc	short msftdf_dsfde_restore_current_dir_2
  2969 00009F1C C3                  <1> 	retn
  2970                              <1> 
  2971                              <1> msftdf_delete_FAT_direntry:	
  2972 00009F1D 8A1D[812A0100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  2973 00009F23 668B0D[AC2A0100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  2974                              <1> 	; ESI = Logical DOS drive description table address
  2975                              <1> 	; EDI = Directory buffer entry offset/address 
  2976 00009F2A E8ABFCFFFF          <1> 	call	delete_directory_entry
  2977 00009F2F 721C                <1> 	jc	short msftdf_retn
  2978                              <1> 
  2979                              <1> msftdf_dsfde_restore_current_dir_2:
  2980 00009F31 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  2981 00009F38 7607                <1> 	jna	short msftdf_new_dir_fcluster_retn
  2982                              <1> 	;mov	esi, [msftdf_drv_offset]
  2983 00009F3A E8C9BFFFFF          <1> 	call	restore_current_directory
  2984 00009F3F 720C                <1> 	jc	short msftdf_retn
  2985                              <1> 
  2986                              <1> msftdf_new_dir_fcluster_retn:
  2987 00009F41 31C9                <1> 	xor	ecx, ecx 
  2988 00009F43 A1[DC2C0100]        <1> 	mov	eax, [createfile_FFCluster]
  2989 00009F48 BB[F42B0100]        <1> 	mov	ebx, DestinationFile_Drv
  2990                              <1> 
  2991                              <1> msftdf_retn:
  2992 00009F4D C3                  <1> 	retn
  2993                              <1> 
  2994                              <1> 
  2995                              <1> copy_source_file_to_destination_file:
  2996                              <1> 	; 31/03/2016
  2997                              <1> 	; 30/03/2016
  2998                              <1> 	; 24/03/2016, 25/03/2016, 28/03/2016
  2999                              <1> 	; 21/03/2016, 22/03/2016, 23/03/2016
  3000                              <1> 	; 16/03/2016, 17/03/2016, 18/03/2016
  3001                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
  3002                              <1> 	; 02/09/2011 (FILE.ASM 'copy_source_file_to_destination_file')
  3003                              <1> 	; 01/08/2010 - 18/05/2011
  3004                              <1> 	;
  3005                              <1> 	;   Command Interpreter phase 1 enter ->
  3006                              <1> 	;           AL = 1 -> Caller is command interpreter
  3007                              <1> 	;           AL = 2 -> The second call, re-enter/continue
  3008                              <1> 	;   Phase 1 -> Check source file
  3009                              <1> 	;              'found' is required
  3010                              <1> 	;   Phase 2 -> Check destination file, 
  3011                              <1> 	;              save 'found' or 'not found' status
  3012                              <1> 	;              'permission denied' error will be return
  3013                              <1> 	;              if attributes have not for ordinary file 
  3014                              <1> 	;              without readonly attribute
  3015                              <1> 	;   Command Interpreter phase 1 return ->
  3016                              <1> 	;              DH = Source file attributes
  3017                              <1> 	;              DL = Destination file found status
  3018                              <1> 	;              EAX = 0 
  3019                              <1> 	;   Command Interpeter phase 2 enter ->
  3020                              <1> 	;              AL = 2 -> Continue from the last position
  3021                              <1> 	;              AH = 
  3022                              <1> 	;   Phase 3 -> Load source file or use read/write cluster method
  3023                              <1> 	;   Phase 4 -> Create destination file if it is not found
  3024                              <1> 	;   Phase 5 -> Open destination file
  3025                              <1> 	;   Phase 6 -> Read from source and write to destination
  3026                              <1> 	;   Phase 7 -> Unload source file, if it is loaded at memory
  3027                              <1> 	;       cf = 1 causes to return before the phase 7
  3028                              <1> 	;              but loaded file will be unloaded
  3029                              <1> 	;	       (allocated memory block will be deallocated) 
  3030                              <1> 	;
  3031                              <1> 	; INPUT -> 
  3032                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  3033                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  3034                              <1> 	;        AL = 0 --> Interrupt (System call)
  3035                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  3036                              <1> 	;        AL = 1 --> Question Phase
  3037                              <1> 	;        AL = 2 --> Progress Phase        
  3038                              <1> 	;
  3039                              <1> 	; OUTPUT -> 
  3040                              <1> 	;	cf = 0 -> OK
  3041                              <1> 	;	EAX = Destination file first cluster
  3042                              <1> 	;
  3043                              <1> 	;        CL > 0 if there is file reading error before EOF
  3044                              <1> 	;	        (incomplete copy) 
  3045                              <1> 	;        CH > 0 if file is (full) loaded at memory
  3046                              <1> 	;
  3047                              <1> 	;	cf = 1 -> Error code in AL (EAX) 
  3048                              <1> 	;
  3049                              <1> 	; (EBX, ECX, ESI, EDI register contents will be changed)           
  3050                              <1> 
  3051                              <1> 
  3052 00009F4E 3C02                <1> 	cmp	al, 2
  3053 00009F50 0F844C020000        <1> 	je	csftdf2_check_cdrv
  3054                              <1> 
  3055                              <1> ; Phase 1
  3056                              <1> 
  3057 00009F56 A2[9C2C0100]        <1> 	mov	byte [copy_cmd_phase], al
  3058                              <1> 
  3059 00009F5B 57                  <1> 	push	edi ; *
  3060                              <1> 
  3061                              <1> csftdf_parse_sf_path:
  3062 00009F5C BF[742B0100]        <1> 	mov	edi, SourceFile_Drv
  3063 00009F61 E896F4FFFF          <1> 	call	parse_path_name
  3064 00009F66 721C                <1> 	jc	short csftdf_parse_sf_path_failed
  3065                              <1> 
  3066                              <1> csftdf_parse_df_path:	
  3067 00009F68 5E                  <1> 	pop	esi ; * (pushed edi) 
  3068                              <1> 
  3069                              <1> csftdf_sf_check_filename_exists:
  3070 00009F69 803D[B62B0100]21    <1> 	cmp	byte [SourceFile_Name], 21h
  3071 00009F70 7215                <1> 	jb	short csftdf_sf_file_not_found_error
  3072                              <1> 
  3073 00009F72 BF[F42B0100]        <1> 	mov	edi, DestinationFile_Drv
  3074 00009F77 E880F4FFFF          <1> 	call	parse_path_name
  3075 00009F7C 7310                <1> 	jnc	short csftdf_check_sf_cdrv
  3076                              <1> 	
  3077 00009F7E 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  3078 00009F80 760C                <1> 	jna	short csftdf_check_sf_cdrv
  3079                              <1> 
  3080                              <1> csftdf_parse_df_path_failed:
  3081 00009F82 F9                  <1> 	stc 
  3082                              <1> csftdf_sf_error_retn: 
  3083 00009F83 C3                  <1> 	retn
  3084                              <1> 
  3085                              <1> csftdf_parse_sf_path_failed:	
  3086 00009F84 5F                  <1> 	pop	edi ; *
  3087 00009F85 EBFC                <1> 	jmp	short csftdf_sf_error_retn
  3088                              <1> 
  3089                              <1> csftdf_sf_file_not_found_error:
  3090 00009F87 B802000000          <1> 	mov	eax, 2 ; File not found 
  3091 00009F8C EBF5                <1> 	jmp	short csftdf_sf_error_retn
  3092                              <1> 
  3093                              <1> csftdf_check_sf_cdrv:
  3094 00009F8E 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  3095                              <1> 
  3096 00009F94 883D[9F2C0100]      <1> 	mov	[csftdf_cdrv], bh ; 23/03/2016
  3097                              <1> 
  3098 00009F9A 8A15[742B0100]      <1> 	mov	dl, [SourceFile_Drv]
  3099 00009FA0 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  3100 00009FA2 7407                <1> 	je	short csftdf_sf_check_directory
  3101                              <1> 
  3102 00009FA4 E8ADBEFFFF          <1> 	call	change_current_drive
  3103 00009FA9 72D8                <1> 	jc	short csftdf_sf_error_retn
  3104                              <1> 
  3105                              <1> csftdf_sf_check_directory:
  3106 00009FAB BE[752B0100]        <1> 	mov	esi, SourceFile_Directory
  3107 00009FB0 803E20              <1> 	cmp	byte [esi], 20h
  3108 00009FB3 760F                <1> 	jna	short csftdf_find_sf
  3109                              <1> 
  3110                              <1> csftdf_sf_change_directory:
  3111 00009FB5 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3112 00009FBB 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3113 00009FBD E826EEFFFF          <1> 	call	change_current_directory
  3114 00009FC2 72BF                <1> 	jc	short csftdf_sf_error_retn
  3115                              <1> 
  3116                              <1> ;csftdf_sf_change_prompt_dir_string:
  3117                              <1> ;	call	change_prompt_dir_string
  3118                              <1> 
  3119                              <1> csftdf_find_sf:
  3120 00009FC4 BE[B62B0100]        <1> 	mov	esi, SourceFile_Name
  3121 00009FC9 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  3122 00009FCD E820D2FFFF          <1> 	call	find_first_file
  3123 00009FD2 72AF                <1> 	jc	short csftdf_sf_error_retn
  3124                              <1> 
  3125                              <1> csftdf_sf_ambgfn_check:
  3126 00009FD4 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3127 00009FD7 7407                <1> 	jz	short csftdf_sf_found
  3128                              <1> 
  3129                              <1> csftdf_ambiguous_file_name_error:
  3130 00009FD9 B802000000          <1> 	mov	eax, 2 ; File not found error
  3131 00009FDE F9                  <1> 	stc
  3132 00009FDF C3                  <1> 	retn
  3133                              <1> 
  3134                              <1> csftdf_sf_found:
  3135 00009FE0 A3[A02C0100]        <1> 	mov	[csftdf_filesize], eax
  3136                              <1> 
  3137 00009FE5 09C0                <1> 	or	eax, eax
  3138 00009FE7 7507                <1> 	jnz	short csftdf_set_source_file_direnry
  3139                              <1> 
  3140                              <1> csftdf_sf_file_size_zero:
  3141 00009FE9 B80E000000          <1> 	mov	eax, 0Eh ; TRDOS zero length error
  3142 00009FEE F9                  <1> 	stc
  3143 00009FEF C3                  <1> 	retn
  3144                              <1> 
  3145                              <1> csftdf_set_source_file_direnry:
  3146 00009FF0 BE[842A0100]        <1> 	mov	esi, FindFile_DirEntry
  3147 00009FF5 BF[C62B0100]        <1> 	mov	edi, SourceFile_DirEntry
  3148 00009FFA B908000000          <1> 	mov	ecx, 8
  3149 00009FFF F3A5                <1> 	rep	movsd
  3150                              <1> 
  3151                              <1> csftdf_sf_restore_cdrv:
  3152                              <1> 	; 22/03/2016
  3153 0000A001 8A15[9F2C0100]      <1> 	mov	dl, [csftdf_cdrv]
  3154 0000A007 3A15[8E200100]      <1> 	cmp	dl, [Current_Drv]
  3155 0000A00D 7407                <1> 	je	short csftdf_sf_restore_cdir
  3156 0000A00F E842BEFFFF          <1> 	call	change_current_drive 
  3157 0000A014 724F                <1> 	jc	short csftdf_df_error_retn ; 30/03/2016
  3158                              <1> 
  3159                              <1> csftdf_sf_restore_cdir:
  3160 0000A016 803D[08DE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
  3161 0000A01D 7612                <1> 	jna	short csftdf_df_check_filename_exists
  3162 0000A01F 29C0                <1> 	sub	eax, eax
  3163 0000A021 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3164 0000A026 88D4                <1> 	mov	ah, dl ; byte [csftdf_cdrv]
  3165 0000A028 01C6                <1> 	add	esi, eax
  3166 0000A02A E8D9BEFFFF          <1> 	call	restore_current_directory
  3167 0000A02F 7234                <1> 	jc	short csftdf_df_error_retn
  3168                              <1>   
  3169                              <1> csftdf_df_check_filename_exists:
  3170 0000A031 803D[362C0100]20    <1> 	cmp	byte [DestinationFile_Name], 20h
  3171 0000A038 7716                <1> 	ja	short csftdf_check_df_cdrv
  3172                              <1> 
  3173                              <1> csftdf_copy_sf_name:
  3174 0000A03A BF[362C0100]        <1> 	mov	edi, DestinationFile_Name
  3175 0000A03F BE[B62B0100]        <1> 	mov	esi, SourceFile_Name
  3176 0000A044 B10C                <1> 	mov	cl, 12
  3177                              <1> 
  3178                              <1> csftdf_df_copy_sf_name_loop:
  3179 0000A046 AC                  <1> 	lodsb
  3180 0000A047 AA                  <1> 	stosb
  3181 0000A048 08C0                <1> 	or	al, al
  3182 0000A04A 7404                <1> 	jz	short csftdf_check_df_cdrv             
  3183 0000A04C FEC9                <1> 	dec	cl
  3184 0000A04E 75F6                <1> 	jnz	csftdf_df_copy_sf_name_loop
  3185                              <1> 
  3186                              <1> csftdf_check_df_cdrv:
  3187 0000A050 8A15[F42B0100]      <1> 	mov	dl, [DestinationFile_Drv]
  3188 0000A056 3A15[8E200100]      <1> 	cmp	dl, [Current_Drv]
  3189 0000A05C 7408                <1> 	je	short csftdf_df_check_directory
  3190                              <1> 
  3191 0000A05E E8F3BDFFFF          <1> 	call	change_current_drive
  3192 0000A063 7301                <1> 	jnc	short csftdf_df_check_directory
  3193                              <1> 
  3194                              <1> csftdf_df_error_retn:
  3195 0000A065 C3                  <1> 	retn
  3196                              <1> 
  3197                              <1> csftdf_df_check_directory:
  3198 0000A066 BE[F52B0100]        <1> 	mov	esi, DestinationFile_Directory
  3199 0000A06B 803E20              <1>         cmp     byte [esi], 20h
  3200 0000A06E 760F                <1> 	jna	short csftdf_find_df
  3201                              <1> 
  3202                              <1> csftdf_df_change_directory:
  3203 0000A070 FE05[08DE0000]      <1> 	inc	byte [Restore_CDIR]
  3204 0000A076 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
  3205 0000A078 E86BEDFFFF          <1> 	call	change_current_directory
  3206 0000A07D 72E6                <1> 	jc	short csftdf_df_error_retn
  3207                              <1> 
  3208                              <1> ;csftdf_df_change_prompt_dir_string:
  3209                              <1> ;	call	change_prompt_dir_string
  3210                              <1> 
  3211                              <1> csftdf_find_df:
  3212                              <1> 	; 23/03/2016
  3213 0000A07F 29DB                <1> 	sub	ebx, ebx
  3214 0000A081 8A3D[F42B0100]      <1> 	mov	bh,  [DestinationFile_Drv]
  3215 0000A087 81C300010900        <1> 	add	ebx, Logical_DOSDisks
  3216 0000A08D 891D[CC2C0100]      <1> 	mov	[csftdf_df_drv_dt], ebx
  3217                              <1> 
  3218 0000A093 BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  3219 0000A098 6631C0              <1> 	xor	ax, ax 
  3220                              <1> 		; DestinationFile_AttributesMask -> any/zero
  3221 0000A09B E852D1FFFF          <1> 	call	find_first_file
  3222 0000A0A0 7218                <1> 	jc	short csftdf_df_check_error_code
  3223                              <1> 
  3224                              <1> csftdf_df_ambgfn_check:
  3225 0000A0A2 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3226 0000A0A5 7511                <1> 	jnz	short csftdf_df_error_stc_retn
  3227                              <1> 	
  3228                              <1> csftdf_df_found:
  3229 0000A0A7 C605[9E2C0100]01    <1> 	mov	byte [DestinationFileFound], 1
  3230 0000A0AE 80E11F              <1> 	and	cl, 1Fh ; Attributes, D-V-S-H-R
  3231 0000A0B1 7451                <1> 	jz	short csftdf_df_save_first_cluster
  3232                              <1> 
  3233                              <1> csftdf_df_permission_denied_retn:	 
  3234 0000A0B3 B805000000          <1> 	mov	eax, 05h ; Access/Permisson denied.
  3235                              <1> csftdf_df_error_stc_retn:
  3236 0000A0B8 F9                  <1> 	stc
  3237 0000A0B9 C3                  <1> 	retn
  3238                              <1> 
  3239                              <1> csftdf_df_check_error_code:
  3240                              <1> 	;cmp	eax, 2
  3241 0000A0BA 3C02                <1> 	cmp	al, 2
  3242 0000A0BC 75FA                <1> 	jne	short csftdf_df_error_stc_retn
  3243                              <1> 
  3244                              <1> 	; 21/03/2016
  3245                              <1> 	; (Capitalized file name)
  3246 0000A0BE BE[742A0100]        <1> 	mov	esi, FindFile_Name
  3247 0000A0C3 BF[362C0100]        <1> 	mov	edi, DestinationFile_Name
  3248 0000A0C8 A5                  <1> 	movsd
  3249 0000A0C9 A5                  <1> 	movsd	
  3250 0000A0CA A5                  <1> 	movsd
  3251                              <1> 	;movsb
  3252                              <1> 
  3253 0000A0CB C605[9E2C0100]00    <1> 	mov	byte [DestinationFileFound], 0
  3254                              <1> 
  3255                              <1> csftdf_check_disk_free_size_0:
  3256 0000A0D2 A1[E22B0100]        <1> 	mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3257                              <1> 
  3258                              <1> csftdf_check_disk_free_size_1:
  3259                              <1> 	;sub	ebx, ebx
  3260                              <1> 	;mov 	esi, Logical_DOSDisks
  3261                              <1> 	;mov	bh,  [DestinationFile_Drv]
  3262                              <1> 	;add	esi, ebx
  3263                              <1> 	
  3264 0000A0D7 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3265                              <1> 
  3266 0000A0DD 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3267 0000A0E1 01C8                <1> 	add	eax, ecx
  3268 0000A0E3 48                  <1> 	dec	eax  ; file size (additional bytes) + 511 (round up)
  3269                              <1> csftdf_check_disk_free_size_3: ; 16/03/2016
  3270 0000A0E4 29D2                <1> 	sub	edx, edx
  3271 0000A0E6 F7F1                <1> 	div	ecx ; bytes per sector
  3272                              <1> 
  3273                              <1> csftdf_check_disk_free_size:
  3274 0000A0E8 3B4674              <1> 	cmp	eax, [esi+LD_FreeSectors]
  3275 0000A0EB 0F8294000000        <1>         jb      csftdf_check_disk_free_size_ok
  3276 0000A0F1 770A                <1> 	ja	short csftdf_df_insufficient_disk_space
  3277                              <1> 
  3278 0000A0F3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0 ; FS needs FDT sector also.
  3279 0000A0F7 0F8788000000        <1>         ja      csftdf_check_disk_free_size_ok 
  3280                              <1> 
  3281                              <1> csftdf_df_insufficient_disk_space:
  3282 0000A0FD B827000000          <1> 	mov	eax, 27h ; insufficient disk space
  3283 0000A102 EBB4                <1> 	jmp	short csftdf_df_error_stc_retn
  3284                              <1> 
  3285                              <1> csftdf_df_save_first_cluster:
  3286                              <1> 	; ESI = FindFile_DirEntry (for the old destination file)
  3287                              <1> 	; EAX = Old destination file size
  3288                              <1> 	; 24/03/2016
  3289                              <1> 	; EDI = Directory entry address (within Dir Buffer boundaries)
  3290 0000A104 81EF00000800        <1> 	sub	edi, Directory_Buffer  ; (<65536)
  3291 0000A10A 66C1EF05            <1> 	shr	di, 5 ; Convert entry offset to entry index/number
  3292 0000A10E 66893D[6E2C0100]    <1> 	mov	[DestinationFile_DirEntryNumber], di ; (<2048)
  3293                              <1> 
  3294                              <1> csftdf_df_check_sf_df_fcluster:
  3295 0000A115 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  3296 0000A119 C1E210              <1> 	shl	edx, 16
  3297 0000A11C 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  3298 0000A120 8915[B02C0100]      <1> 	mov	[csftdf_df_cluster], edx
  3299                              <1> csftdf_df_check_sf_df_fcluster_1:
  3300 0000A126 668B15[DA2B0100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3301 0000A12D C1E210              <1> 	shl	edx, 16
  3302 0000A130 668B15[E02B0100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3303 0000A137 3B15[B02C0100]      <1> 	cmp	edx, [csftdf_df_cluster]
  3304 0000A13D 7512                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3305                              <1> csftdf_df_check_sf_df_drv:
  3306 0000A13F 8A15[742B0100]      <1> 	mov	dl, [SourceFile_Drv]
  3307 0000A145 3A15[F42B0100]      <1> 	cmp	dl, [DestinationFile_Drv]
  3308 0000A14B 7504                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3309                              <1> 
  3310                              <1> 	; source and destination files are same !
  3311                              <1> 	; (they have same first cluster value on same logical disk)
  3312                              <1> 
  3313 0000A14D 31C0                <1> 	xor	eax, eax ; mov eax, 0 -> Bad command or file name !
  3314 0000A14F F9                  <1> 	stc
  3315 0000A150 C3                  <1> 	retn 
  3316                              <1>    
  3317                              <1> csftdf_df_check_sf_df_fcluster_ok:
  3318                              <1> csftdf_df_move_findfile_struct:
  3319                              <1> 	; mov	esi, FindFile_DirEntry
  3320 0000A151 BF[462C0100]        <1> 	mov	edi, DestinationFile_DirEntry
  3321 0000A156 B908000000          <1> 	mov	ecx, 8
  3322 0000A15B F3A5                <1> 	rep	movsd
  3323                              <1> 	
  3324                              <1> csftdf_check_disk_free_size_2:
  3325 0000A15D 89C2                <1> 	mov	edx, eax ; Old destination file size
  3326                              <1> 
  3327                              <1> 	;mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3328 0000A15F A1[A02C0100]        <1> 	mov	eax, [csftdf_filesize] ; 23/03/2016
  3329                              <1> 
  3330                              <1> 	;;sub	ecx, ecx ; 0
  3331                              <1> 	;mov 	esi, Logical_DOSDisks
  3332                              <1> 	;mov	ch,  [DestinationFile_Drv]
  3333                              <1> 	;add	esi, ecx
  3334                              <1> 	;
  3335                              <1> 	;mov	[csftdf_df_drv_dt], esi
  3336                              <1> 
  3337 0000A164 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3338                              <1> 
  3339 0000A16A 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3340 0000A16E 01CA                <1> 	add	edx, ecx ; + 512
  3341 0000A170 01C8                <1> 	add	eax, ecx ; + 512
  3342 0000A172 4A                  <1> 	dec	edx ; old file size + 511 (round up)
  3343 0000A173 48                  <1> 	dec	eax ; new file size + 511 (round up)
  3344 0000A174 F7D9                <1> 	neg	ecx ; -512 ; 0FFFFFE00h
  3345 0000A176 21CA                <1> 	and	edx, ecx ; = old sector count * 512 
  3346 0000A178 21C8                <1> 	and	eax, ecx ; = new sector count * 512 
  3347                              <1> 
  3348 0000A17A 29D0                <1> 	sub	eax, edx ; new file size - old file size (on disk)
  3349 0000A17C 7607                <1> 	jna	short csftdf_check_disk_free_size_ok
  3350                              <1> 
  3351 0000A17E F7D9                <1> 	neg	ecx ; 512 (bytes per sector) ; 200h
  3352                              <1> 	; check free space for additional sectors
  3353                              <1> 	; eax = number of additional sectors * bytes per sector
  3354                              <1> 	; esi = Logical DOS drive number (of destination disk)
  3355 0000A180 E95FFFFFFF          <1>         jmp     csftdf_check_disk_free_size_3
  3356                              <1>  
  3357                              <1> csftdf_check_disk_free_size_ok:
  3358                              <1> 	; 18/03/2016
  3359                              <1> csftdf_df_check_copy_cmd_phase:
  3360 0000A185 A0[9C2C0100]        <1> 	mov	al, [copy_cmd_phase]
  3361 0000A18A 3C01                <1> 	cmp	al, 1
  3362 0000A18C 7514                <1> 	jne	short csftdf2_check_cdrv
  3363                              <1> 	
  3364 0000A18E 31C0                <1> 	xor	eax, eax
  3365 0000A190 A2[9C2C0100]        <1> 	mov	[copy_cmd_phase], al ; 0
  3366                              <1> 
  3367 0000A195 8A15[9E2C0100]      <1> 	mov	dl, [DestinationFileFound]            
  3368 0000A19B 8A35[D12B0100]      <1> 	mov	dh, [SourceFile_DirEntry+11] ; Attributes
  3369                              <1>  
  3370                              <1> csftdf_return:	
  3371 0000A1A1 C3                  <1> 	retn
  3372                              <1> 
  3373                              <1> ; Phase 2
  3374                              <1> 
  3375                              <1> csftdf2_check_cdrv:
  3376                              <1> 	; 18/03/2016
  3377                              <1> 	; Here, destination drive and directory are ready !
  3378                              <1> 	; (checking/restoring is not needed)
  3379                              <1> 	; (Since at the end of the phase 1)
  3380                              <1> 
  3381                              <1> ;	mov	dl, [DestinationFile_Drv]
  3382                              <1> ;	cmp	dl, [Current_Drv]
  3383                              <1> ;	je	short csftdf2_df_check_directory
  3384                              <1> ;
  3385                              <1> ;	call	change_current_drive
  3386                              <1> ;	jc	short csftdf2_read_error
  3387                              <1> ;
  3388                              <1> ;csftdf2_df_check_directory:
  3389                              <1> ;	mov	esi, DestinationFile_Directory  
  3390                              <1> ;	cmp	byte [esi], 20h
  3391                              <1> ;	jna	short csftdf2_df_check_found_or_not
  3392                              <1> ;
  3393                              <1> ;csftdf2_df_change_directory:
  3394                              <1> ;	inc	byte [Restore_CDIR]
  3395                              <1> ;	xor	ah, ah ; CD_COMMAND sign -> 0 
  3396                              <1> ;	call	change_current_directory
  3397                              <1> ;	jc	short csftdf2_stc_return
  3398                              <1> ;
  3399                              <1> ;;csftdf2_df_change_prompt_dir_string:
  3400                              <1> ;;	call	change_prompt_dir_string
  3401                              <1> 
  3402                              <1> csftdf2_df_check_found_or_not:
  3403                              <1> 	; 21/03/2016
  3404 0000A1A2 803D[9E2C0100]00    <1> 	cmp	byte [DestinationFileFound], 0 
  3405 0000A1A9 7739                <1> 	ja	short csftdf2_set_sf_percentage
  3406                              <1> 
  3407                              <1> csftdf2_create_file:
  3408 0000A1AB BE[362C0100]        <1> 	mov	esi, DestinationFile_Name
  3409 0000A1B0 A1[A02C0100]        <1> 	mov	eax, [csftdf_filesize]
  3410 0000A1B5 30C9                <1> 	xor	cl, cl ; 0
  3411                              <1> 
  3412 0000A1B7 31DB                <1> 	xor	ebx, ebx ; 0
  3413 0000A1B9 4B                  <1> 	dec	ebx ; 0FFFFFFFFh 
  3414                              <1> 
  3415                              <1> 	; INPUT ->
  3416                              <1> 	; 	EAX -> File Size
  3417                              <1> 	; 	ESI = ASCIIZ File name
  3418                              <1> 	;	 CL = File attributes
  3419                              <1> 	;	EBX = FFFFFFFFh -> empty file sign for FAT fs
  3420                              <1> 	;	EBX <> FFFFFFFFh -> use file size for FAT fs 
  3421                              <1> 	;
  3422                              <1> 	; OUTPUT ->
  3423                              <1> 	;	EAX = New file's first cluster
  3424                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  3425                              <1> 	;	EBX = CreateFile_Size address
  3426                              <1> 	;	ECX = Sectors per cluster (<256)
  3427                              <1> 	;	EDX = Directory Entry Index/Number (<65536)
  3428                              <1> 	;		
  3429                              <1> 	;	cf = 1 -> error code in AL (EAX)
  3430                              <1> 
  3431 0000A1BA E8EC050000          <1> 	call	create_file
  3432                              <1> 	;pop	esi
  3433 0000A1BF 0F82A3050000        <1>         jc      csftdf2_rw_error
  3434                              <1> 
  3435                              <1> csftdf2_create_file_OK:
  3436 0000A1C5 A3[B02C0100]        <1> 	mov	[csftdf_df_cluster], eax
  3437                              <1> 	
  3438                              <1> 	; 24/03/2016
  3439 0000A1CA 668915[6E2C0100]    <1> 	mov	[DestinationFile_DirEntryNumber], dx 
  3440                              <1> 
  3441                              <1> 	; 21/03/2016
  3442 0000A1D1 BE00000800          <1> 	mov	esi, Directory_Buffer
  3443 0000A1D6 C1E205              <1> 	shl	edx, 5 ; 32 * index number
  3444 0000A1D9 01D6                <1> 	add	esi, edx
  3445 0000A1DB BF[462C0100]        <1> 	mov	edi, DestinationFile_DirEntry	
  3446 0000A1E0 B108                <1> 	mov	cl, 8 ; 32 bytes
  3447 0000A1E2 F3A5                <1> 	rep	movsd
  3448                              <1> 
  3449                              <1> csftdf2_set_sf_percentage:
  3450                              <1> 	; 17/03/2016
  3451 0000A1E4 31C0                <1> 	xor	eax, eax	
  3452 0000A1E6 A2[C42C0100]        <1> 	mov 	[csftdf_percentage], al ; 0, reset
  3453                              <1> 
  3454 0000A1EB A3[BC2C0100]        <1> 	mov	[csftdf_sf_rbytes], eax ; 0, reset
  3455 0000A1F0 A3[C02C0100]        <1> 	mov	[csftdf_df_wbytes], eax ; 0, reset
  3456                              <1> 
  3457 0000A1F5 8A25[742B0100]      <1> 	mov	ah, [SourceFile_Drv]	
  3458 0000A1FB BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3459 0000A200 01C6                <1> 	add	esi, eax
  3460                              <1> 	
  3461 0000A202 8935[C82C0100]      <1> 	mov	[csftdf_sf_drv_dt], esi ; 23/03/2016
  3462                              <1> 
  3463 0000A208 668B15[DA2B0100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3464 0000A20F C1E210              <1> 	shl	edx, 16
  3465 0000A212 668B15[E02B0100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3466 0000A219 8915[AC2C0100]      <1> 	mov	[csftdf_sf_cluster], edx
  3467                              <1> 
  3468                              <1> 	; 16/03/2016
  3469                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3470                              <1> 	;	related calculations) has same offset
  3471                              <1> 	;	values from LD_BPB as in FAT file system.
  3472                              <1> 	;	[esi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3473                              <1> 	;	
  3474 0000A21F 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  3475 0000A223 880D[F22B0100]      <1> 	mov	[SourceFile_SecPerClust], cl
  3476                              <1> 
  3477                              <1> 	; 17/03/2016
  3478 0000A229 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
  3479 0000A22C 7707                <1> 	ja	short csftdf2_set_sf_percent_rsize1
  3480                              <1> 
  3481 0000A22E B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3482 0000A233 EB06                <1> 	jmp	short csftdf2_set_sf_percent_rsize2	
  3483                              <1>  
  3484                              <1> csftdf2_set_sf_percent_rsize1:
  3485 0000A235 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  3486 0000A239 F7E1                <1> 	mul	ecx
  3487                              <1> 	;sub	edx, edx
  3488                              <1> csftdf2_set_sf_percent_rsize2:
  3489 0000A23B A3[B42C0100]        <1> 	mov	[csftdf_r_size], eax
  3490                              <1> 
  3491                              <1> csftdf2_set_df_percentage:
  3492                              <1> 	;sub	eax, eax
  3493                              <1> 	;mov	ah, [DestinationFile_Drv]	
  3494                              <1> 	;mov	edi, Logical_DOSDisks
  3495                              <1> 	;add	edi, eax
  3496                              <1> 	;mov	[csftdf_df_drv_dt], edi ; 17/03/2016
  3497                              <1> 
  3498 0000A240 8B3D[CC2C0100]      <1> 	mov	edi, [csftdf_df_drv_dt] ; 23/03/2016
  3499                              <1> 
  3500                              <1> 	; 16/03/2016
  3501                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3502                              <1> 	;	related calculations) has same offset
  3503                              <1> 	;	values from LD_BPB as in FAT file system.
  3504                              <1> 	;	[edi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3505                              <1> 	;	
  3506                              <1> 	;movzx	ecx, byte [edi+LD_BPB+SecPerClust]
  3507 0000A246 8A4F13              <1> 	mov	cl, [edi+LD_BPB+SecPerClust]
  3508 0000A249 880D[722C0100]      <1> 	mov	[DestinationFile_SecPerClust], cl
  3509                              <1> 
  3510                              <1> 	; 17/03/2016
  3511 0000A24F 386F03              <1> 	cmp	[edi+LD_FATType], ch ; 0
  3512 0000A252 7707                <1> 	ja	short csftdf2_set_df_percent_wsize1
  3513                              <1> 	
  3514 0000A254 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3515 0000A259 EB06                <1> 	jmp	short csftdf2_set_df_percent_wsize2	
  3516                              <1> 
  3517                              <1> csftdf2_set_df_percent_wsize1:
  3518 0000A25B 0FB74711            <1> 	movzx	eax, word [edi+LD_BPB+BytesPerSec]
  3519 0000A25F F7E1                <1> 	mul	ecx
  3520                              <1> 	;sub	edx, edx
  3521                              <1> csftdf2_set_df_percent_wsize2:
  3522 0000A261 A3[B82C0100]        <1> 	mov	[csftdf_w_size], eax
  3523                              <1> 
  3524 0000A266 A1[A02C0100]        <1> 	mov	eax, [csftdf_filesize]
  3525                              <1> 
  3526 0000A26B 3D00000100          <1> 	cmp	eax, 65536 ; 64KB	; small file
  3527 0000A270 721F                <1> 	jb	short csftdf2_load_file ; do not display percentage
  3528                              <1> 	
  3529                              <1> csftdf2_reset_wf_percent_ptr_chk_64k:
  3530 0000A272 B201                <1> 	mov	dl, 1 ; 25/03/2016
  3531                              <1> 
  3532 0000A274 3D00000400          <1> 	cmp	eax, 65536*4 ; 256KB
  3533 0000A279 7310                <1> 	jnb	short csftdf2_enable_percentage_display ; big file
  3534                              <1> 
  3535                              <1> 	; 64-128KB file size for floppy disks
  3536 0000A27B 3815[742B0100]      <1> 	cmp	byte [SourceFile_Drv], dl ; 1 ; read from floppy disk ?
  3537 0000A281 7608                <1> 	jna	short csftdf2_enable_percentage_display
  3538                              <1> 
  3539 0000A283 3815[F42B0100]      <1> 	cmp	byte [DestinationFile_Drv], dl ; 1 ; write to floppy disk ?
  3540 0000A289 7706                <1> 	ja	short csftdf2_load_file
  3541                              <1> 
  3542                              <1> csftdf2_enable_percentage_display:	
  3543 0000A28B 8815[C42C0100]      <1> 	mov	[csftdf_percentage], dl ; 1	
  3544                              <1> 	
  3545                              <1> csftdf2_load_file:
  3546                              <1> 	; 13/05/2016
  3547                              <1> 	; 19/03/2016
  3548                              <1> 	; 18/03/2016
  3549                              <1> 	; 17/03/2016
  3550 0000A291 B40F                <1> 	mov	ah, 0Fh
  3551 0000A293 E8AF70FFFF          <1> 	call	_int10h
  3552                              <1> 	; 13/05/2016
  3553 0000A298 883D[C52C0100]      <1> 	mov	[csftdf_videopage], bh ; active video page
  3554 0000A29E B403                <1> 	mov	ah, 03h
  3555 0000A2A0 E8A270FFFF          <1> 	call	_int10h
  3556 0000A2A5 668915[C62C0100]    <1> 	mov	[csftdf_cursorpos], dx
  3557                              <1> 
  3558 0000A2AC 29C0                <1> 	sub	eax, eax
  3559 0000A2AE A2[9D2C0100]        <1> 	mov	[csftdf_rw_err], al ; 0 
  3560                              <1> 
  3561                              <1> ; ///
  3562                              <1> csftdf_sf_amb: ; 15/03/2016
  3563 0000A2B3 8B0D[A02C0100]      <1> 	mov	ecx, [csftdf_filesize]	; 23/03/2016
  3564                              <1> 
  3565                              <1> 	; TRDOS 386 (TRDOS v2.0)
  3566                              <1> 	; Allocate contiguous memory block for loading the file
  3567                              <1> 	
  3568                              <1> 	;mov	ecx, [SourceFile_DirEntry+DirEntry_FileSize]
  3569                              <1> 	
  3570                              <1> 	;sub	eax, eax ; First free memory aperture
  3571                              <1> 	
  3572                              <1> 	; eax = 0 (Allocate memory from the beginning)
  3573                              <1> 	; ecx = File (Allocation) size in bytes
  3574                              <1> 	
  3575 0000A2B9 E899ABFFFF          <1> 	call	allocate_memory_block
  3576 0000A2BE 7304                <1> 	jnc	short loc_check_sf_save_loading_parms
  3577                              <1> 
  3578 0000A2C0 29C0                <1> 	sub	eax, eax
  3579 0000A2C2 29C9                <1> 	sub	ecx, ecx
  3580                              <1> 	
  3581                              <1> loc_check_sf_save_loading_parms:
  3582 0000A2C4 A3[A42C0100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  3583 0000A2C9 890D[A82C0100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  3584                              <1> ; ///   
  3585                              <1> 	; 19/03/2016
  3586 0000A2CF 8B35[C82C0100]      <1> 	mov	esi, [csftdf_sf_drv_dt] ; logical dos drv desc. tbl.
  3587                              <1> 
  3588                              <1> 	; 17/03/2016
  3589 0000A2D5 09C0                <1> 	or	eax, eax ; contiguous free memory block address 
  3590 0000A2D7 0F845B010000        <1>         jz      csftdf2_read_sf_cluster
  3591                              <1> 
  3592                              <1> 	; 18/03/2016
  3593 0000A2DD 8B1D[A42C0100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  3594                              <1> 
  3595 0000A2E3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3596 0000A2E7 0F8605020000        <1>         jna     csftdf2_load_fs_file
  3597                              <1> 
  3598                              <1> csftdf2_load_fat_file:
  3599 0000A2ED 53                  <1> 	push	ebx ; *
  3600                              <1> 
  3601                              <1> csftdf2_load_fat_file_next:
  3602 0000A2EE BE[5DE40000]        <1> 	mov	esi, msg_reading
  3603 0000A2F3 E85EB2FFFF          <1> 	call	print_msg
  3604                              <1> 
  3605 0000A2F8 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3606 0000A2FF 7605                <1> 	jna	short csftdf2_load_fat_file_1
  3607                              <1> 	
  3608 0000A301 E87C000000          <1> 	call	csftdf2_print_percentage ; 19/03/2016
  3609                              <1> 
  3610                              <1> csftdf2_load_fat_file_1:
  3611 0000A306 8B35[C82C0100]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
  3612 0000A30C 5B                  <1> 	pop	ebx ; *
  3613                              <1> 
  3614                              <1> csftdf2_load_fat_file_2:
  3615 0000A30D E8B8000000          <1> 	call	csftdf2_read_fat_file_sectors ; 19/03/2016
  3616 0000A312 0F8250040000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
  3617                              <1> 
  3618 0000A318 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3619 0000A31A 7520                <1> 	jnz	short csftdf2_load_fat_file_ok
  3620                              <1> 
  3621 0000A31C 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3622 0000A323 76E8                <1> 	jna	short csftdf2_load_fat_file_2
  3623                              <1> 
  3624 0000A325 53                  <1> 	push	ebx ; *	
  3625                              <1> 
  3626                              <1> 	; Set cursor position
  3627                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3628 0000A326 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  3629 0000A32C 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  3630 0000A333 B402                <1> 	mov	ah, 2
  3631 0000A335 E80D70FFFF          <1> 	call	_int10h
  3632 0000A33A EBB2                <1> 	jmp	short csftdf2_load_fat_file_next
  3633                              <1> 	
  3634                              <1> csftdf2_load_fat_file_ok:
  3635 0000A33C 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3636 0000A343 0F8651020000        <1>         jna     csftdf2_save_file ; 25/03/2016
  3637                              <1> 	
  3638                              <1> 	; "Reading... 100%"
  3639 0000A349 BF[75E40000]        <1> 	mov	edi, percentagestr
  3640 0000A34E B031                <1> 	mov	al, '1'
  3641 0000A350 AA                  <1> 	stosb
  3642 0000A351 B030                <1> 	mov	al, '0'
  3643 0000A353 AA                  <1> 	stosb
  3644 0000A354 AA                  <1> 	stosb
  3645                              <1> 
  3646 0000A355 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  3647 0000A35B 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  3648 0000A362 B402                <1> 	mov	ah, 2
  3649 0000A364 E8DE6FFFFF          <1> 	call	_int10h
  3650                              <1> 
  3651 0000A369 BE[5DE40000]        <1> 	mov	esi, msg_reading
  3652 0000A36E E8E3B1FFFF          <1> 	call	print_msg
  3653                              <1> 	
  3654 0000A373 BE[75E40000]        <1> 	mov	esi, percentagestr
  3655 0000A378 E8D9B1FFFF          <1> 	call	print_msg
  3656                              <1> 
  3657 0000A37D E918020000          <1>         jmp     csftdf2_save_file ; 25/03/2016
  3658                              <1> 
  3659                              <1> csftdf2_print_percentage:
  3660                              <1> 	; 19/03/2016
  3661                              <1> 	; 18/03/2016
  3662 0000A382 B020                <1> 	mov	al, 20h
  3663 0000A384 BF[75E40000]        <1> 	mov	edi, percentagestr
  3664 0000A389 AA                  <1> 	stosb
  3665 0000A38A AA                  <1> 	stosb
  3666 0000A38B A1[BC2C0100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  3667 0000A390 BA64000000          <1> 	mov	edx, 100
  3668 0000A395 F7E2                <1> 	mul	edx
  3669 0000A397 8B0D[A02C0100]      <1> 	mov	ecx, [csftdf_filesize]	
  3670 0000A39D F7F1                <1> 	div	ecx
  3671 0000A39F B10A                <1> 	mov	cl, 10
  3672 0000A3A1 F6F1                <1> 	div	cl
  3673 0000A3A3 80C430              <1> 	add	ah, '0'
  3674 0000A3A6 8827                <1> 	mov	[edi], ah
  3675 0000A3A8 20C0                <1> 	and	al, al
  3676 0000A3AA 740A                <1> 	jz	short csftdf2_print_percent_1
  3677 0000A3AC 4F                  <1> 	dec	edi
  3678 0000A3AD 6698                <1> 	cbw
  3679 0000A3AF F6F1                <1> 	div	cl
  3680 0000A3B1 80C430              <1> 	add	ah, '0'
  3681 0000A3B4 8827                <1> 	mov	[edi], ah
  3682                              <1> 	;and	al, al
  3683                              <1> 	;jz	short csftdf2_print_percent_1
  3684                              <1> 	;dec	edi
  3685                              <1> 	;mov	[edi], '1' ; 100%		
  3686                              <1> 
  3687                              <1> csftdf2_print_percent_1:
  3688 0000A3B6 BE[75E40000]        <1> 	mov	esi, percentagestr
  3689                              <1> 	;call	print_msg
  3690                              <1> 	;retn
  3691 0000A3BB E996B1FFFF          <1> 	jmp	print_msg
  3692                              <1> 
  3693                              <1> csftdf2_read_file_sectors:
  3694                              <1> 	; 19/03/2016
  3695 0000A3C0 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3696 0000A3C4 0F8627070000        <1>         jna     csftdf2_read_fs_file_sectors
  3697                              <1> 
  3698                              <1> csftdf2_read_fat_file_sectors:
  3699                              <1> 	; 19/03/2016
  3700                              <1> 	; 18/03/2016
  3701                              <1> 	; return:
  3702                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  3703                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  3704                              <1> 	;   CF = 1 -> read error (error code in AL)	
  3705                              <1> 
  3706                              <1> csftdf2_read_fat_file_secs_0:
  3707 0000A3CA 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  3708 0000A3D0 2B15[BC2C0100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  3709 0000A3D6 3B15[B42C0100]      <1> 	cmp	edx, [csftdf_r_size]	
  3710 0000A3DC 7306                <1> 	jnb	short csftdf2_read_fat_file_secs_1
  3711 0000A3DE 8915[B42C0100]      <1> 	mov	[csftdf_r_size], edx
  3712                              <1> 		
  3713                              <1> csftdf2_read_fat_file_secs_1:
  3714 0000A3E4 A1[B42C0100]        <1> 	mov	eax, [csftdf_r_size]
  3715 0000A3E9 29D2                <1> 	sub	edx, edx
  3716 0000A3EB 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  3717 0000A3EF 01C8                <1> 	add	eax, ecx
  3718 0000A3F1 48                  <1> 	dec	eax
  3719 0000A3F2 F7F1                <1> 	div	ecx
  3720 0000A3F4 89C1                <1> 	mov	ecx, eax ; sector count
  3721 0000A3F6 A1[AC2C0100]        <1> 	mov	eax, [csftdf_sf_cluster]
  3722                              <1> 
  3723                              <1> 	; EBX = memory block address (current)
  3724                              <1> 	
  3725 0000A3FB E821090000          <1> 	call	read_fat_file_sectors
  3726 0000A400 7235                <1> 	jc	short csftdf2_read_fat_file_secs_3
  3727                              <1> 
  3728                              <1> 	; EBX = next memory address
  3729                              <1> 
  3730 0000A402 A1[BC2C0100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  3731 0000A407 0305[B42C0100]      <1> 	add	eax, [csftdf_r_size]
  3732 0000A40D 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  3733 0000A413 39D0                <1> 	cmp	eax, edx
  3734 0000A415 7320                <1> 	jnb	short csftdf2_read_fat_file_secs_3 ; edx > 0
  3735 0000A417 A3[BC2C0100]        <1> 	mov	[csftdf_sf_rbytes], eax
  3736                              <1> 
  3737 0000A41C 53                  <1> 	push	ebx ; *
  3738                              <1> 	; get next cluster (csftdf_r_size! bytes)
  3739 0000A41D A1[AC2C0100]        <1> 	mov	eax, [csftdf_sf_cluster]
  3740 0000A422 E8CC060000          <1> 	call	get_next_cluster
  3741 0000A427 5B                  <1> 	pop	ebx ; *
  3742 0000A428 7306                <1> 	jnc	short csftdf2_read_fat_file_secs_2
  3743                              <1> 
  3744 0000A42A B815000000          <1> 	mov	eax, 15h ; Read error !
  3745 0000A42F C3                  <1> 	retn
  3746                              <1> 
  3747                              <1> csftdf2_read_fat_file_secs_2:
  3748 0000A430 29D2                <1> 	sub	edx, edx ; 0
  3749 0000A432 A3[AC2C0100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  3750                              <1> 
  3751                              <1> csftdf2_read_fat_file_secs_3:
  3752 0000A437 C3                  <1> 	retn
  3753                              <1> 
  3754                              <1> csftdf2_read_sf_cluster:
  3755                              <1> 	; 19/03/2016
  3756 0000A438 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  3757                              <1> 
  3758 0000A43D 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3759 0000A444 760D                <1> 	jna	short csftdf2_read_sf_clust_2
  3760                              <1> 
  3761 0000A446 53                  <1> 	push	ebx ; *	
  3762                              <1> 
  3763                              <1> csftdf2_read_sf_clust_next:
  3764 0000A447 E836FFFFFF          <1> 	call	csftdf2_print_percentage
  3765                              <1> 
  3766                              <1> csftdf2_read_sf_clust_0:
  3767 0000A44C 8B35[C82C0100]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
  3768                              <1> csftdf2_read_sf_clust_1:
  3769 0000A452 5B                  <1> 	pop	ebx ; *
  3770                              <1> 
  3771                              <1> csftdf2_read_sf_clust_2:
  3772 0000A453 89DA                <1> 	mov	edx, ebx
  3773 0000A455 0315[B42C0100]      <1> 	add	edx, [csftdf_r_size]
  3774 0000A45B 81FA00000800        <1> 	cmp	edx, Cluster_Buffer + 65536
  3775 0000A461 772F                <1> 	ja	short csftdf2_write_df_cluster
  3776                              <1> 
  3777 0000A463 E858FFFFFF          <1> 	call	csftdf2_read_file_sectors ; 19/03/2016
  3778 0000A468 0F8280020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
  3779                              <1> 
  3780 0000A46E 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3781 0000A470 7520                <1> 	jnz	short csftdf2_write_df_cluster
  3782                              <1> 
  3783 0000A472 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3784 0000A479 76D8                <1> 	jna	short csftdf2_read_sf_clust_2
  3785                              <1> 
  3786 0000A47B 53                  <1> 	push	ebx ; *	
  3787                              <1> 
  3788                              <1> 	; Set cursor position
  3789                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3790 0000A47C 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  3791 0000A482 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  3792 0000A489 B402                <1> 	mov	ah, 2
  3793 0000A48B E8B76EFFFF          <1> 	call	_int10h
  3794 0000A490 EBB5                <1> 	jmp	short csftdf2_read_sf_clust_next
  3795                              <1> 
  3796                              <1> csftdf2_write_df_cluster:
  3797                              <1> 	; 19/03/2016
  3798 0000A492 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt]	
  3799 0000A498 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  3800                              <1> 
  3801                              <1> csftdf2_write_df_clust_next:
  3802 0000A49D E855000000          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
  3803 0000A4A2 0F8246020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
  3804                              <1> 
  3805 0000A4A8 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3806 0000A4AA 750A                <1> 	jnz	short csftdf2_rw_f_clust_ok
  3807                              <1> 
  3808 0000A4AC 81FB00000800        <1> 	cmp	ebx, Cluster_Buffer + 65536
  3809 0000A4B2 72E9                <1> 	jb	short csftdf2_write_df_clust_next
  3810                              <1> 	
  3811 0000A4B4 EB82                <1> 	jmp	short csftdf2_read_sf_cluster
  3812                              <1>  
  3813                              <1> csftdf2_rw_f_clust_ok:
  3814 0000A4B6 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3815 0000A4BD 0F86B2010000        <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
  3816                              <1> 
  3817                              <1> 	; "100%"
  3818 0000A4C3 BF[75E40000]        <1> 	mov	edi, percentagestr
  3819 0000A4C8 B031                <1> 	mov	al, '1'
  3820 0000A4CA AA                  <1> 	stosb
  3821 0000A4CB B030                <1> 	mov	al, '0'
  3822 0000A4CD AA                  <1> 	stosb
  3823 0000A4CE AA                  <1> 	stosb
  3824                              <1> 
  3825 0000A4CF 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  3826 0000A4D5 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  3827 0000A4DC B402                <1> 	mov	ah, 2
  3828 0000A4DE E8646EFFFF          <1> 	call	_int10h
  3829                              <1> 
  3830 0000A4E3 BE[75E40000]        <1> 	mov	esi, percentagestr
  3831 0000A4E8 E869B0FFFF          <1> 	call	print_msg
  3832                              <1> 
  3833 0000A4ED E983010000          <1>         jmp     csftdf2_save_fat_file_4
  3834                              <1> 
  3835                              <1> csftdf2_load_fs_file:
  3836                              <1> 	; temporary - 18/03/2016
  3837 0000A4F2 E96F020000          <1>         jmp     csftdf2_read_error
  3838                              <1> 
  3839                              <1> csftdf2_write_file_sectors:
  3840                              <1> 	; 19/03/2016
  3841 0000A4F7 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3842 0000A4FB 0F86F1050000        <1>         jna     csftdf2_write_fs_file_sectors
  3843                              <1> 
  3844                              <1> csftdf2_write_fat_file_sectors:
  3845                              <1> 	; 19/03/2016
  3846                              <1> 	; 18/03/2016
  3847                              <1> 	; return:
  3848                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  3849                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  3850                              <1> 	;   CF = 1 -> write error (error code in AL)	
  3851                              <1> 
  3852                              <1> csftdf2_write_fat_file_secs_0:
  3853 0000A501 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  3854 0000A507 2B15[C02C0100]      <1> 	sub	edx, [csftdf_df_wbytes]
  3855 0000A50D 3B15[B82C0100]      <1> 	cmp	edx, [csftdf_w_size]	
  3856 0000A513 7306                <1> 	jnb	short csftdf2_write_fat_file_secs_1
  3857 0000A515 8915[B82C0100]      <1> 	mov	[csftdf_w_size], edx		
  3858                              <1> 
  3859                              <1> csftdf2_write_fat_file_secs_1:
  3860 0000A51B A1[B82C0100]        <1> 	mov	eax, [csftdf_w_size]
  3861 0000A520 29D2                <1> 	sub	edx, edx
  3862 0000A522 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  3863 0000A526 01C8                <1> 	add	eax, ecx
  3864 0000A528 48                  <1> 	dec	eax
  3865 0000A529 F7F1                <1> 	div	ecx
  3866 0000A52B 89C1                <1> 	mov	ecx, eax ; sector count
  3867 0000A52D A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster]
  3868                              <1> 
  3869                              <1> 	; EBX = memory block address (current)	
  3870                              <1> 
  3871 0000A532 E8920F0000          <1> 	call	write_fat_file_sectors
  3872 0000A537 7259                <1> 	jc	short csftdf2_write_fat_file_secs_4
  3873                              <1> 
  3874                              <1> 	; EBX = next memory address
  3875                              <1> 
  3876 0000A539 A1[C02C0100]        <1> 	mov	eax, [csftdf_df_wbytes]
  3877 0000A53E 0305[B82C0100]      <1> 	add	eax, [csftdf_w_size]
  3878 0000A544 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  3879 0000A54A 39D0                <1> 	cmp	eax, edx
  3880 0000A54C 7344                <1> 	jnb	short csftdf2_write_fat_file_secs_4
  3881 0000A54E A3[C02C0100]        <1> 	mov	[csftdf_df_wbytes], eax
  3882                              <1> 	;
  3883 0000A553 A3[622C0100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  3884                              <1> 
  3885 0000A558 53                  <1> 	push	ebx ; *
  3886                              <1> 
  3887 0000A559 803D[9E2C0100]01    <1> 	cmp	byte [DestinationFileFound], 1
  3888 0000A560 7210                <1> 	jb	short csftdf2_write_fat_file_secs_2
  3889                              <1> 
  3890                              <1> 	; get next cluster (csftdf_w_size! bytes)
  3891 0000A562 A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster]
  3892 0000A567 E887050000          <1> 	call	get_next_cluster
  3893 0000A56C 731C                <1> 	jnc	short csftdf2_write_fat_file_secs_3
  3894                              <1> 
  3895 0000A56E 21C0                <1> 	and	eax, eax ; end of cluster chain!?
  3896 0000A570 7521                <1> 	jnz	short csftdf2_write_fat_file_secs_5 ; disk error !
  3897                              <1> 
  3898                              <1> csftdf2_write_fat_file_secs_2:
  3899 0000A572 A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  3900 0000A577 E8700E0000          <1> 	call	add_new_cluster		
  3901 0000A57C 7215                <1> 	jc	short csftdf2_write_fat_file_secs_5
  3902                              <1> 
  3903                              <1> 	; NOTE: Destination file size may be bigger than
  3904                              <1> 	; source file size when the last reading fails after here.
  3905                              <1> 	; (The last -empty- cluster of destination file must be 
  3906                              <1> 	; truncated and LMDT must be current date&time for partial
  3907                              <1> 	; copy result!) 
  3908 0000A57E 8B15[B82C0100]      <1> 	mov	edx, [csftdf_w_size] ; bytes per cluster
  3909 0000A584 0115[622C0100]      <1> 	add	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  3910                              <1> 
  3911                              <1> csftdf2_write_fat_file_secs_3:
  3912 0000A58A 5B                  <1> 	pop	ebx ; *
  3913 0000A58B 29D2                <1> 	sub	edx, edx ; 0
  3914 0000A58D A3[B02C0100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  3915                              <1> 
  3916                              <1> csftdf2_write_fat_file_secs_4:
  3917 0000A592 C3                  <1> 	retn
  3918                              <1> 
  3919                              <1> csftdf2_write_fat_file_secs_5:
  3920 0000A593 5B                  <1> 	pop	ebx ; *
  3921 0000A594 B81D000000          <1> 	mov	eax, 1Dh ; Write error !
  3922 0000A599 C3                  <1> 	retn
  3923                              <1> 
  3924                              <1> csftdf2_save_file:
  3925                              <1> 	; 25/03/2016
  3926                              <1> 	; 19/03/2016
  3927                              <1> 	; 18/03/2016
  3928 0000A59A 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; logical dos drv desc. tbl.
  3929                              <1> 
  3930 0000A5A0 8B1D[A42C0100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  3931                              <1> 
  3932 0000A5A6 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3933 0000A5AA 0F86F4010000        <1>         jna     csftdf2_save_fs_file
  3934                              <1> 
  3935                              <1> csftdf2_save_fat_file:
  3936 0000A5B0 53                  <1> 	push	ebx; *
  3937                              <1> 
  3938 0000A5B1 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3939 0000A5B8 7724                <1> 	ja	short csftdf2_save_fat_file_0
  3940                              <1> 
  3941                              <1> 	; Set cursor position
  3942                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3943 0000A5BA 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  3944 0000A5C0 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  3945 0000A5C7 B402                <1> 	mov	ah, 2
  3946 0000A5C9 E8796DFFFF          <1> 	call	_int10h
  3947                              <1> 	
  3948 0000A5CE BE[69E40000]        <1> 	mov	esi, msg_writing
  3949 0000A5D3 E87EAFFFFF          <1> 	call	print_msg
  3950                              <1> 
  3951                              <1> csftdf2_save_fat_file_next:
  3952 0000A5D8 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 25/03/2016
  3953                              <1> 
  3954                              <1> csftdf2_save_fat_file_0:
  3955 0000A5DE 5B                  <1> 	pop	ebx ; *
  3956                              <1> 
  3957                              <1> csftdf2_save_fat_file_1:
  3958 0000A5DF E813FFFFFF          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016	
  3959 0000A5E4 0F827E010000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
  3960                              <1> 
  3961 0000A5EA 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3962 0000A5EC 756D                <1>         jnz     short csftdf2_save_fat_file_3 ; 25/03/2016
  3963                              <1> 
  3964 0000A5EE 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3965 0000A5F5 76E8                <1> 	jna	short csftdf2_save_fat_file_1
  3966                              <1> 
  3967 0000A5F7 B020                <1> 	mov	al, 20h
  3968 0000A5F9 BF[75E40000]        <1> 	mov	edi, percentagestr
  3969 0000A5FE AA                  <1> 	stosb
  3970 0000A5FF AA                  <1> 	stosb
  3971 0000A600 A1[C02C0100]        <1> 	mov	eax, [csftdf_df_wbytes]
  3972 0000A605 BA64000000          <1> 	mov	edx, 100
  3973 0000A60A F7E2                <1> 	mul	edx
  3974 0000A60C 8B0D[A02C0100]      <1> 	mov	ecx, [csftdf_filesize]	
  3975 0000A612 F7F1                <1> 	div	ecx
  3976 0000A614 B10A                <1> 	mov	cl, 10
  3977 0000A616 F6F1                <1> 	div	cl
  3978 0000A618 80C430              <1> 	add	ah, '0'
  3979 0000A61B 8827                <1> 	mov	[edi], ah
  3980 0000A61D 20C0                <1> 	and	al, al
  3981 0000A61F 740A                <1> 	jz	short csftdf2_save_fat_file_2
  3982 0000A621 4F                  <1> 	dec	edi
  3983 0000A622 6698                <1> 	cbw
  3984 0000A624 F6F1                <1> 	div	cl
  3985 0000A626 80C430              <1> 	add	ah, '0'
  3986 0000A629 8827                <1> 	mov	[edi], ah
  3987                              <1> 	;and	al, al
  3988                              <1> 	;jz	short csftdf2_save_fat_file_2
  3989                              <1> 	;dec	edi
  3990                              <1> 	;mov	[edi], '1' ; 100%		
  3991                              <1> 
  3992                              <1> csftdf2_save_fat_file_2:
  3993 0000A62B 53                  <1> 	push	ebx ; *
  3994                              <1> 
  3995 0000A62C E802000000          <1> 	call	csftdf2_print_wr_percentage ; 25/03/2016
  3996                              <1> 
  3997 0000A631 EBA5                <1>         jmp     csftdf2_save_fat_file_next
  3998                              <1> 
  3999                              <1> csftdf2_print_wr_percentage:
  4000                              <1> 	; Set cursor position
  4001                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4002 0000A633 8A3D[C52C0100]      <1> 	mov	bh, [csftdf_videopage]
  4003 0000A639 668B15[C62C0100]    <1> 	mov	dx, [csftdf_cursorpos]
  4004 0000A640 B402                <1> 	mov	ah, 2
  4005 0000A642 E8006DFFFF          <1> 	call	_int10h
  4006                              <1> 
  4007 0000A647 BE[69E40000]        <1> 	mov	esi, msg_writing
  4008 0000A64C E805AFFFFF          <1> 	call	print_msg
  4009                              <1> 
  4010 0000A651 BE[75E40000]        <1> 	mov	esi, percentagestr
  4011                              <1> 	;call	print_msg
  4012                              <1> 	;retn
  4013 0000A656 E9FBAEFFFF          <1> 	jmp	print_msg
  4014                              <1> 
  4015                              <1> csftdf2_save_fat_file_3:
  4016 0000A65B 803D[C42C0100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4017 0000A662 7611                <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
  4018                              <1> 
  4019                              <1> 	; "100%"
  4020 0000A664 BF[75E40000]        <1> 	mov	edi, percentagestr
  4021 0000A669 B031                <1> 	mov	al, '1'
  4022 0000A66B AA                  <1> 	stosb
  4023 0000A66C B030                <1> 	mov	al, '0'
  4024 0000A66E AA                  <1> 	stosb
  4025 0000A66F AA                  <1> 	stosb
  4026                              <1> 
  4027 0000A670 E8BEFFFFFF          <1> 	call	csftdf2_print_wr_percentage
  4028                              <1> 
  4029                              <1> csftdf2_save_fat_file_4:
  4030 0000A675 803D[9E2C0100]00    <1> 	cmp	byte [DestinationFileFound], 0
  4031 0000A67C 7647                <1> 	jna	short csftdf2_save_fat_file_6
  4032                              <1> 
  4033 0000A67E 8B35[CC2C0100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 31/03/2016	
  4034                              <1> 
  4035 0000A684 A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4036 0000A689 E865040000          <1> 	call	get_next_cluster
  4037 0000A68E 7235                <1> 	jc	short csftdf2_save_fat_file_6 ; eocc! or disk error!
  4038                              <1> 
  4039 0000A690 A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4040                              <1> 	;xor	ecx, ecx
  4041                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  4042                              <1> 	;dec	ecx ; 0FFFFFFFFh
  4043                              <1> 	;shr	ecx, 4 ; 28 bit ; 0FFFFFFFh
  4044 0000A695 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
  4045 0000A69A E87E070000          <1> 	call	update_cluster
  4046 0000A69F 7224                <1> 	jc	short csftdf2_save_fat_file_6 ; really last cluster!?
  4047                              <1> 
  4048 0000A6A1 A3[B02C0100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  4049                              <1> 	
  4050                              <1> 	; byte [FAT_BuffValidData] = 2 
  4051 0000A6A6 E82F0A0000          <1> 	call	save_fat_buffer
  4052 0000A6AB 730E                <1> 	jnc	short csftdf2_save_fat_file_5
  4053                              <1> 	
  4054 0000A6AD 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  4055 0000A6B3 8915[622C0100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4056 0000A6B9 EB58                <1> 	jmp	short csftdf2_save_fat_file_err3
  4057                              <1> 
  4058                              <1> csftdf2_save_fat_file_5:
  4059 0000A6BB A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster]
  4060                              <1> 
  4061                              <1> 	; EAX = First cluster to be truncated/unlinked
  4062                              <1> 	; ESI = Logical dos drive description table address
  4063 0000A6C0 E8480C0000          <1> 	call	truncate_cluster_chain
  4064                              <1> 
  4065                              <1> csftdf2_save_fat_file_6:
  4066                              <1> 	; 28/03/2016
  4067 0000A6C5 BE[D12B0100]        <1> 	mov	esi, SourceFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4068 0000A6CA BF[512C0100]        <1> 	mov	edi, DestinationFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4069 0000A6CF A4                  <1> 	movsb ; +11
  4070 0000A6D0 A5                  <1> 	movsd ; +12 .. +15
  4071 0000A6D1 66A5                <1> 	movsw ; +16 .. +17
  4072                              <1> 		; + 18
  4073 0000A6D3 83C604              <1> 	add	esi, 4
  4074 0000A6D6 83C704              <1> 	add	edi, 4
  4075 0000A6D9 A5                  <1> 	movsd	; DirEntry_WrtTime ; +22 .. +25
  4076                              <1> 
  4077 0000A6DA 8B15[A02C0100]      <1> 	mov	edx, [csftdf_filesize]
  4078 0000A6E0 8915[622C0100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4079                              <1> 
  4080 0000A6E6 E8D7F0FFFF          <1> 	call	convert_current_date_time
  4081                              <1> 	; DX = Date in dos dir entry format
  4082                              <1> 	; AX = Time in dos dir entry format
  4083 0000A6EB EB4D                <1> 	jmp	short csftdf2_save_fat_file_7
  4084                              <1> 
  4085                              <1> csftdf2_save_fat_file_err1:
  4086 0000A6ED 5B                  <1> 	pop	ebx ; *	
  4087                              <1> csftdf2_save_fat_file_err2:
  4088 0000A6EE A1[C02C0100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4089 0000A6F3 8B15[622C0100]      <1> 	mov	edx, [DestinationFile_DirEntry+DirEntry_FileSize]
  4090 0000A6F9 39C2                <1> 	cmp	edx, eax
  4091 0000A6FB 7616                <1> 	jna	short csftdf2_save_fat_file_err3
  4092 0000A6FD A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster] ; last (empty) cluster
  4093                              <1> 	; ESI = Logical dos drive description table address
  4094 0000A702 E8060C0000          <1> 	call	truncate_cluster_chain
  4095 0000A707 720A                <1> 	jc	short csftdf2_save_fat_file_err3
  4096 0000A709 A1[C02C0100]        <1> 	mov	eax, [csftdf_df_wbytes]	
  4097 0000A70E A3[622C0100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  4098                              <1> csftdf2_save_fat_file_err3:
  4099 0000A713 E8AAF0FFFF          <1> 	call	convert_current_date_time
  4100                              <1> 	; DX = Date in dos dir entry format
  4101                              <1> 	; AX = Time in dos dir entry format
  4102 0000A718 C605[532C0100]00    <1> 	mov	byte [DestinationFile_DirEntry+DirEntry_CrtTimeTenth], 0
  4103 0000A71F 66A3[542C0100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtTime], ax
  4104 0000A725 668915[562C0100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtDate], dx		
  4105 0000A72C 66A3[5C2C0100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtTime], ax
  4106 0000A732 668915[5E2C0100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtDate], dx
  4107 0000A739 F9                  <1> 	stc
  4108                              <1> csftdf2_save_fat_file_7:
  4109 0000A73A 9C                  <1> 	pushf
  4110 0000A73B 668915[582C0100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_LastAccDate], dx
  4111 0000A742 BE[462C0100]        <1> 	mov	esi, DestinationFile_DirEntry
  4112 0000A747 BF00000800          <1> 	mov	edi, Directory_Buffer
  4113 0000A74C 0FB70D[6E2C0100]    <1> 	movzx	ecx, word [DestinationFile_DirEntryNumber] ; (<2048)
  4114 0000A753 66C1E105            <1> 	shl	cx, 5 ; 32 * directory entry number
  4115 0000A757 01CF                <1> 	add	edi, ecx
  4116                              <1> 	;mov	ecx, 8
  4117 0000A759 66B90800            <1> 	mov	cx, 8
  4118 0000A75D F3A5                <1> 	rep	movsd
  4119 0000A75F 9D                  <1> 	popf
  4120 0000A760 730B                <1> 	jnc	short csftdf2_write_file_OK
  4121                              <1> 	 		
  4122                              <1> csftdf2_write_error:
  4123                              <1> 	; 18/03/2016
  4124 0000A762 B01D                <1> 	mov	al, 1Dh ; write error
  4125 0000A764 EB02                <1> 	jmp	short csftdf2_rw_error
  4126                              <1> 
  4127                              <1> 	; 16/03/2016
  4128                              <1> csftdf2_read_error:
  4129 0000A766 B015                <1> 	mov	al, 15h ; ; Drive not ready or read error!
  4130                              <1> csftdf2_rw_error:
  4131 0000A768 A2[9D2C0100]        <1> 	mov	[csftdf_rw_err], al 
  4132                              <1> 
  4133                              <1> csftdf2_write_file_OK:
  4134                              <1> 	; 18/03/2016
  4135 0000A76D C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  4136 0000A774 E8E7F0FFFF          <1> 	call	save_directory_buffer
  4137                              <1> 
  4138                              <1>  	; Update last modification date&time of destination
  4139                              <1> 	; file's (parent) directory
  4140 0000A779 E87DF1FFFF          <1> 	call	update_parent_dir_lmdt
  4141                              <1> 	;
  4142 0000A77E A1[A42C0100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  4143                              <1> 
  4144 0000A783 21C0                <1> 	and	eax, eax
  4145 0000A785 750E                <1> 	jnz	short csftdf2_dealloc_mblock
  4146                              <1> 
  4147 0000A787 88C5                <1> 	mov	ch, al ; 0 (Cluster r/w, not full loading)
  4148                              <1> csftdf2_dealloc_retn:
  4149 0000A789 8A0D[9D2C0100]      <1> 	mov	cl, [csftdf_rw_err]
  4150 0000A78F A1[B02C0100]        <1> 	mov	eax, [csftdf_df_cluster]
  4151 0000A794 C3                  <1> 	retn
  4152                              <1> 
  4153                              <1> csftdf2_dealloc_mblock:
  4154 0000A795 8B0D[A82C0100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
  4155 0000A79B E8B8A8FFFF          <1> 	call	deallocate_memory_block
  4156 0000A7A0 B5FF                <1>         mov     ch, 0FFh ; (File was full loaded at memory)
  4157 0000A7A2 EBE5                <1> 	jmp	short csftdf2_dealloc_retn
  4158                              <1> 
  4159                              <1> csftdf2_save_fs_file:
  4160                              <1> 	; temporary - (21/03/2016)
  4161 0000A7A4 B81D000000          <1> 	mov	eax, 1Dh ; write error
  4162 0000A7A9 F9                  <1> 	stc
  4163 0000A7AA C3                  <1> 	retn
  4164                              <1> 
  4165                              <1> create_file:
  4166                              <1> 	; 31/03/2016
  4167                              <1> 	; 24/03/2016
  4168                              <1> 	; 23/03/2016
  4169                              <1> 	; 21/03/2016
  4170                              <1> 	; 20/03/2016
  4171                              <1> 	; 19/03/2016 (TRDOS 396 = TRDOS v2.0)
  4172                              <1> 	; 03/09/2011 (FILE.ASM, 'proc_create_file')
  4173                              <1> 	; 09/08/2010
  4174                              <1> 	;
  4175                              <1> 	; INPUT ->
  4176                              <1> 	; 	EAX = File Size
  4177                              <1> 	; 	ESI = ASCIIZ File Name
  4178                              <1> 	; 	CL = File Attributes 
  4179                              <1> 	;	EBX = FFFFFFFFh -> create empty file 
  4180                              <1> 	;			 (only for FAT fs) 
  4181                              <1> 	; OUTPUT ->
  4182                              <1> 	;     CF = 0 ->
  4183                              <1> 	;	EAX = New file's first cluster
  4184                              <1> 	; 	ESI = Logical Dos Drv Descr. Table Addr.
  4185                              <1> 	; 	EBX = offset CreateFile_Size
  4186                              <1> 	; 	ECX = Sectors per cluster (<256) 
  4187                              <1> 	; 	EDX = Directory entry index/number (<65536)
  4188                              <1> 	;     CF = 1 -> error code in AL
  4189                              <1> 
  4190                              <1> ;	test	cl, 18h (directory or volume name)
  4191                              <1> ;	jnz	short loc_createfile_access_denied
  4192 0000A7AB 80E107              <1> 	and	cl, 07h ; S, H, R
  4193 0000A7AE 880D[EC2C0100]      <1>         mov     [createfile_attrib], cl 
  4194                              <1> 
  4195 0000A7B4 89D9                <1> 	mov	ecx, ebx
  4196 0000A7B6 89F3                <1> 	mov	ebx, esi ; ASCIIZ File Name address
  4197 0000A7B8 29D2                <1> 	sub	edx, edx
  4198 0000A7BA 8A35[8E200100]      <1>         mov     dh, [Current_Drv]
  4199 0000A7C0 BE00010900          <1>         mov     esi, Logical_DOSDisks
  4200 0000A7C5 01D6                <1> 	add	esi, edx
  4201                              <1> 
  4202 0000A7C7 8815[F72C0100]      <1> 	mov	[createfile_UpdatePDir], dl ; 0 ; 31/03/2016 
  4203                              <1> 
  4204                              <1> 	; LD_DiskType = 0 for write protection (read only) 
  4205 0000A7CD 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  4206 0000A7D1 730A                <1> 	jnb	short loc_createfile_check_file_sytem
  4207 0000A7D3 B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
  4208 0000A7D8 66BA0000            <1> 	mov	dx, 0
  4209                              <1> 	; err retn: EDX = 0, EBX = File name offset
  4210                              <1> 	; ESI -> Dos drive description table address	
  4211 0000A7DC C3                  <1> 	retn
  4212                              <1> 
  4213                              <1> ;loc_createfile_access_denied:
  4214                              <1> ;	mov	eax, 05h ; access denied (invalid attributes input)
  4215                              <1> ;	stc
  4216                              <1> ;	retn
  4217                              <1> 
  4218                              <1> loc_createfile_check_file_sytem:
  4219 0000A7DD 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  4220 0000A7E1 730A                <1> 	jnb	short loc_createfile_chk_empty_FAT_file_sign1
  4221                              <1> 
  4222 0000A7E3 A3[D82C0100]        <1> 	mov	[createfile_size], eax
  4223                              <1> 	; ESI = Logical Dos Drive Description Table address
  4224                              <1> 	; EBX = ASCIIZ File Name address
  4225 0000A7E8 E9FE020000          <1> 	jmp	create_fs_file
  4226                              <1> 
  4227                              <1> loc_createfile_chk_empty_FAT_file_sign1:
  4228                              <1> 	; ECX = FFFFFFFFh -> create empty file if drive has FAT fs
  4229 0000A7ED 41                  <1> 	inc	ecx
  4230 0000A7EE 7506                <1> 	jnz	short loc_createfile_chk_empty_FAT_file_sign2
  4231 0000A7F0 890D[D82C0100]      <1> 	mov	[createfile_size], ecx ; 0 ; empty file
  4232                              <1> 
  4233                              <1> loc_createfile_chk_empty_FAT_file_sign2:
  4234                              <1> 	; 23/03/2016
  4235 0000A7F6 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec]
  4236 0000A7FA 66890D[F42C0100]    <1> 	mov	[createfile_BytesPerSec], cx
  4237                              <1> 	
  4238                              <1> 	; EBX = ASCIIZ File Name address
  4239 0000A801 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
  4240 0000A805 8815[ED2C0100]      <1> 	mov	[createfile_SecPerClust], dl
  4241 0000A80B 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  4242 0000A80E 39D1                <1> 	cmp	ecx, edx ; byte [createfile_SecPerClust]
  4243 0000A810 7306                <1> 	jnb	short loc_create_fat_file
  4244                              <1> 	  
  4245                              <1> loc_createfile_insufficient_disk_space:
  4246 0000A812 B827000000          <1> 	mov	eax, 27h
  4247                              <1> loc_createfile_gffc_retn:
  4248 0000A817 C3                  <1> 	retn
  4249                              <1> 
  4250                              <1> loc_create_fat_file:
  4251 0000A818 891D[D02C0100]      <1> 	mov	[createfile_Name_Offset], ebx
  4252 0000A81E 890D[D42C0100]      <1> 	mov	[createfile_FreeSectors], ecx
  4253                              <1> 
  4254                              <1> loc_createfile_gffc_1:
  4255 0000A824 E821050000          <1> 	call	get_first_free_cluster
  4256 0000A829 72EC                <1> 	jc	short loc_createfile_gffc_retn
  4257                              <1> 
  4258 0000A82B A3[DC2C0100]        <1> 	mov	[createfile_FFCluster], eax
  4259                              <1> 
  4260                              <1> loc_createfile_locate_ffe_on_directory:
  4261                              <1> 	; Current directory fcluster <> Directory buffer cluster
  4262                              <1> 	; Current directory will be reloaded by
  4263                              <1> 	; 'locate_current_dir_file' procedure
  4264                              <1> 	;
  4265                              <1> 	; ESI = Logical Dos Drv Desc. Table Adress
  4266 0000A830 56                  <1> 	push	esi ; *
  4267 0000A831 31C0                <1> 	xor	eax, eax
  4268                              <1> 
  4269 0000A833 A3[AE280100]        <1> 	mov	dword [FAT_ClusterCounter], eax ; 0
  4270                              <1> 	; 21/03/2016
  4271 0000A838 A2[F62C0100]        <1> 	mov	byte [createfile_wfc], al ; 0 
  4272                              <1> 
  4273 0000A83D 89C1                <1>  	mov	ecx, eax
  4274 0000A83F 6649                <1> 	dec	cx ; FFFFh  
  4275                              <1> 	; CX = FFFFh -> find first deleted or free entry
  4276                              <1> 	; ESI would be ASCIIZ filename Address if the call
  4277                              <1> 	; would not be for first free or deleted dir entry  
  4278 0000A841 E8F6E7FFFF          <1> 	call	locate_current_dir_file
  4279 0000A846 0F83EE000000        <1> 	jnc	loc_createfile_set_ff_dir_entry
  4280 0000A84C 5E                  <1> 	pop	esi ; *
  4281                              <1> 	 ; ESI = Logical DOS Drv. Description Table Address 
  4282 0000A84D 83F802              <1> 	cmp	eax, 2
  4283 0000A850 7402                <1> 	je	short loc_createfile_add_new_cluster
  4284                              <1> loc_createfile_locate_file_stc_retn:
  4285 0000A852 F9                  <1> 	stc
  4286 0000A853 C3                  <1> 	retn
  4287                              <1> 
  4288                              <1> loc_createfile_add_new_cluster:
  4289 0000A854 803D[8D200100]02    <1> 	cmp	byte [Current_FATType], 2
  4290                              <1> 	;cmp	byte [esi+LD_FATType], 2
  4291 0000A85B 770C                <1> 	ja	short loc_createfile_add_new_cluster_check_fsc
  4292 0000A85D 803D[8C200100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  4293                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  4294 0000A864 7303                <1> 	jnb	short loc_createfile_add_new_cluster_check_fsc
  4295                              <1> 	
  4296                              <1> 	;mov	eax, 12
  4297 0000A866 B00C                <1> 	mov	al, 12 ; No more files 
  4298                              <1> 
  4299                              <1> loc_createfile_anc_retn:
  4300 0000A868 C3                  <1> 	retn
  4301                              <1> 
  4302                              <1> loc_createfile_add_new_cluster_check_fsc:
  4303 0000A869 8B0D[D42C0100]      <1> 	mov	ecx, [createfile_FreeSectors]
  4304 0000A86F 0FB605[ED2C0100]    <1> 	movzx	eax, byte [createfile_SecPerClust]
  4305 0000A876 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
  4306 0000A879 39C1                <1> 	cmp	ecx, eax
  4307 0000A87B 7295                <1>         jb	short loc_createfile_insufficient_disk_space
  4308                              <1> 
  4309                              <1> loc_createfile_add_new_subdir_cluster:
  4310 0000A87D 8B15[BD280100]      <1> 	mov	edx, [DirBuff_Cluster]
  4311 0000A883 8915[E02C0100]      <1> 	mov	[createfile_LastDirCluster], edx	
  4312                              <1> 
  4313 0000A889 A1[DC2C0100]        <1> 	mov	eax, [createfile_FFCluster]
  4314 0000A88E E846040000          <1> 	call	load_FAT_sub_directory 
  4315 0000A893 72D3                <1> 	jc	short loc_createfile_anc_retn
  4316                              <1> 
  4317                              <1> pass_createfile_add_new_subdir_cluster:
  4318                              <1> 	;movzx	eax, word [esi+LD_BPB+BytesPerSec]
  4319 0000A895 0FB705[F42C0100]    <1> 	movzx	eax, word [createfile_BytesPerSec] ; 23/03/2016
  4320 0000A89C F7E1                <1> 	mul	ecx ; ecx = directory buffer sector count
  4321 0000A89E 89C1                <1> 	mov	ecx, eax
  4322 0000A8A0 C1E902              <1> 	shr	ecx, 2 ; dword count
  4323 0000A8A3 29C0                <1> 	sub	eax, eax ; 0
  4324 0000A8A5 F3AB                <1> 	rep	stosd 
  4325                              <1> 	;
  4326 0000A8A7 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  4327 0000A8AE E8ADEFFFFF          <1> 	call	save_directory_buffer
  4328 0000A8B3 72B3                <1> 	jc	short loc_createfile_anc_retn
  4329                              <1> 
  4330                              <1> loc_createfile_save_added_subdir_cluster:
  4331 0000A8B5 A1[E02C0100]        <1> 	mov	eax, [createfile_LastDirCluster]
  4332 0000A8BA 8B0D[DC2C0100]      <1> 	mov	ecx, [createfile_FFCluster]
  4333 0000A8C0 E858050000          <1> 	call	update_cluster
  4334 0000A8C5 7304                <1> 	jnc	short loc_createfile_save_fat_buffer_0
  4335 0000A8C7 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4336 0000A8C9 751A                <1> 	jnz	short loc_createfile_save_fat_buffer_stc_retn
  4337                              <1> 
  4338                              <1> loc_createfile_save_fat_buffer_0:
  4339 0000A8CB A1[DC2C0100]        <1> 	mov	eax, [createfile_FFCluster]
  4340 0000A8D0 A3[E02C0100]        <1> 	mov	[createfile_LastDirCluster], eax
  4341 0000A8D5 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh ; 28 bit
  4342 0000A8DA E83E050000          <1> 	call	update_cluster
  4343 0000A8DF 7306                <1> 	jnc	short loc_createfile_save_fat_buffer_1
  4344 0000A8E1 09C0                <1> 	or	eax, eax ; Was it free cluster
  4345 0000A8E3 7402                <1> 	jz	short loc_createfile_save_fat_buffer_1
  4346                              <1> 
  4347                              <1> loc_createfile_save_fat_buffer_stc_retn:
  4348 0000A8E5 F9                  <1> 	stc
  4349                              <1> loc_createfile_save_fat_buffer_retn:
  4350                              <1> loc_createfile_gffc_2_stc_retn:
  4351 0000A8E6 C3                  <1> 	retn
  4352                              <1> 
  4353                              <1> loc_createfile_save_fat_buffer_1:
  4354                              <1> 	; byte [FAT_BuffValidData] = 2 
  4355 0000A8E7 E8EE070000          <1> 	call	save_fat_buffer
  4356 0000A8EC 72F8                <1> 	jc	short loc_createfile_save_fat_buffer_retn
  4357                              <1> 
  4358 0000A8EE 803D[AE280100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  4359 0000A8F5 7222                <1> 	jb	short loc_createfile_save_fat_buffer_2
  4360                              <1> 
  4361                              <1> 	; ESI = Logical DOS Drive Description Table address 
  4362 0000A8F7 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4363                              <1> 
  4364 0000A8FC C605[AE280100]00    <1> 	mov	byte [FAT_ClusterCounter], 0 ; 21/03/2016
  4365                              <1> 
  4366 0000A903 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  4367 0000A907 E863080000          <1> 	call	calculate_fat_freespace
  4368                              <1> 
  4369                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  4370                              <1> 	;jnz	short loc_createfile_save_fat_buffer_2
  4371                              <1> 
  4372                              <1> 	; ecx > 0 -> Recalculation is needed
  4373 0000A90C 09C9                <1> 	or	ecx, ecx 
  4374 0000A90E 7409                <1> 	jz	short loc_createfile_save_fat_buffer_2
  4375                              <1> 
  4376 0000A910 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  4377 0000A914 E856080000          <1> 	call	calculate_fat_freespace
  4378                              <1> 
  4379                              <1> loc_createfile_save_fat_buffer_2:
  4380                              <1> 	;call	update_parent_dir_lmdt
  4381                              <1> 
  4382                              <1> loc_createfile_gffc_2:
  4383 0000A919 E82C040000          <1> 	call	get_first_free_cluster
  4384 0000A91E 72C6                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  4385                              <1> 
  4386 0000A920 A3[DC2C0100]        <1> 	mov	[createfile_FFCluster], eax
  4387                              <1> 
  4388 0000A925 A1[E02C0100]        <1> 	mov	eax, [createfile_LastDirCluster]
  4389                              <1> 	
  4390 0000A92A E8AA030000          <1> 	call	load_FAT_sub_directory 
  4391 0000A92F 72B5                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  4392                              <1> 
  4393 0000A931 BF00000800          <1> 	mov	edi, Directory_Buffer
  4394                              <1> 
  4395 0000A936 6629DB              <1> 	sub	bx, bx ; directory entry index/number = 0
  4396                              <1> 
  4397 0000A939 56                  <1> 	push	esi ; * ; 23/03/2016
  4398                              <1> 
  4399                              <1> loc_createfile_set_ff_dir_entry:
  4400 0000A93A 66891D[EE2C0100]    <1> 	mov	[createfile_DirIndex], bx
  4401                              <1> 
  4402                              <1>         ; EDI = Directory entry address
  4403 0000A941 8B35[D02C0100]      <1> 	mov	esi, [createfile_Name_Offset]
  4404 0000A947 A1[DC2C0100]        <1> 	mov	eax, [createfile_FFCluster]
  4405 0000A94C A3[E42C0100]        <1> 	mov	[createfile_Cluster], eax ; 24/03/2016
  4406 0000A951 B5FF                <1> 	mov	ch, 0FFh
  4407 0000A953 8A0D[EC2C0100]      <1>         mov	cl, [createfile_attrib] ; file attributes
  4408                              <1> 	; CH > 0 -> File size is in EBX
  4409 0000A959 BB[D82C0100]        <1> 	mov	ebx, createfile_size
  4410                              <1>   
  4411 0000A95E E820EEFFFF          <1> 	call	make_directory_entry
  4412                              <1> 	
  4413 0000A963 5E                  <1> 	pop	esi ; * ; ESI = Logical Dos Drv Desc. Table address
  4414                              <1> 
  4415 0000A964 C605[B8280100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  4416 0000A96B E8F0EEFFFF          <1> 	call	save_directory_buffer
  4417 0000A970 7221                <1> 	jc	short loc_createfile_set_ff_dir_entry_retn
  4418                              <1> 
  4419 0000A972 C605[F72C0100]01    <1> 	mov	byte [createfile_UpdatePDir], 1 ; 31/03/2016 
  4420                              <1> 
  4421                              <1> loc_createfile_get_set_write_file_cluster:
  4422 0000A979 A1[D82C0100]        <1> 	mov	eax, [createfile_size]
  4423 0000A97E 09C0                <1> 	or	eax, eax
  4424 0000A980 7570                <1> 	jnz	short loc_createfile_get_set_wfc_cont
  4425 0000A982 40                  <1> 	inc	eax
  4426                              <1> 	; 23/03/2016
  4427 0000A983 0FB61D[ED2C0100]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
  4428                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
  4429 0000A98A 0FB70D[F42C0100]    <1>         movzx   ecx, word [createfile_BytesPerSec] ; 512
  4430 0000A991 EB7C                <1> 	jmp	loc_createfile_set_cluster_count 
  4431                              <1> 
  4432                              <1> loc_createfile_set_ff_dir_entry_retn:
  4433 0000A993 C3                  <1> 	retn
  4434                              <1> 
  4435                              <1> loc_createfile_write_fcluster_to_disk:
  4436 0000A994 034668              <1> 	add	eax, [esi+LD_DATABegin] ; convert to physical address
  4437 0000A997 BB00000700          <1> 	mov	ebx, Cluster_Buffer
  4438                              <1> 	; ESI = Logical DOS Drv. Desc. Tbl. address
  4439                              <1> 	; EAX = Disk address
  4440                              <1> 	; EBX = Sector Buffer
  4441                              <1> 	; ECX = sectors per cluster
  4442 0000A99C E86C300000          <1> 	call	disk_write
  4443 0000A9A1 7211                <1> 	jc	short loc_createfile_dsk_wr_err
  4444                              <1> 
  4445                              <1> loc_createfile_update_fat_cluster:
  4446                              <1> 	; 21/03/2016	
  4447 0000A9A3 803D[F62C0100]00    <1> 	cmp	byte [createfile_wfc], 0 
  4448 0000A9AA 7712                <1> 	ja	short loc_createfile_update_fat_cluster_n1
  4449                              <1> 
  4450 0000A9AC FE05[F62C0100]      <1> 	inc	byte [createfile_wfc] ; 1
  4451 0000A9B2 EB24                <1> 	jmp	short loc_createfile_update_fat_cluster_n2
  4452                              <1> 
  4453                              <1> loc_createfile_dsk_wr_err:
  4454                              <1> 	; 23/03/2016
  4455 0000A9B4 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
  4456 0000A9B9 E9BD000000          <1> 	jmp	loc_createfile_stc_retn
  4457                              <1> 
  4458                              <1> loc_createfile_update_fat_cluster_n1:
  4459 0000A9BE A1[E82C0100]        <1> 	mov	eax, [createfile_PCluster]
  4460 0000A9C3 8B0D[E42C0100]      <1> 	mov	ecx, [createfile_Cluster]
  4461 0000A9C9 E84F040000          <1> 	call	update_cluster
  4462 0000A9CE 7308                <1> 	jnc	short loc_createfile_update_fat_cluster_n2
  4463 0000A9D0 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4464 0000A9D2 0F85A3000000        <1> 	jnz	loc_createfile_stc_retn
  4465                              <1> 
  4466                              <1> loc_createfile_update_fat_cluster_n2:
  4467 0000A9D8 A1[E42C0100]        <1>         mov	eax, [createfile_Cluster]
  4468 0000A9DD B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
  4469 0000A9E2 E836040000          <1> 	call	update_cluster
  4470 0000A9E7 734E                <1> 	jnc	short loc_createfile_save_fat_buffer_3
  4471 0000A9E9 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4472 0000A9EB 744A                <1> 	jz	short loc_createfile_save_fat_buffer_3
  4473                              <1> 
  4474                              <1> loc_createfile_upd_fat_fcluster_stc_retn:
  4475 0000A9ED E989000000          <1> 	jmp	loc_createfile_stc_retn
  4476                              <1> 
  4477                              <1> loc_createfile_get_set_wfc_cont:
  4478                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512	
  4479 0000A9F2 0FB70D[F42C0100]    <1> 	movzx	ecx, word [createfile_BytesPerSec] ; 512
  4480 0000A9F9 01C8                <1> 	add	eax, ecx
  4481 0000A9FB 48                  <1> 	dec	eax  ; add eax, 511
  4482 0000A9FC 29D2                <1> 	sub	edx, edx
  4483 0000A9FE F7F1                <1> 	div	ecx
  4484 0000AA00 0FB61D[ED2C0100]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
  4485 0000AA07 01D8                <1> 	add	eax, ebx
  4486 0000AA09 48                  <1> 	dec	eax  ; add eax, SecPerClust - 1
  4487 0000AA0A 6631D2              <1> 	xor	dx, dx
  4488 0000AA0D F7F3                <1> 	div	ebx
  4489                              <1> 
  4490                              <1> loc_createfile_set_cluster_count:
  4491 0000AA0F A3[F02C0100]        <1> 	mov 	[createfile_CCount], eax
  4492                              <1> 	
  4493 0000AA14 BF00000700          <1> 	mov	edi, Cluster_Buffer
  4494 0000AA19 89C8                <1> 	mov	eax, ecx ; Bytes per Sector
  4495 0000AA1B F7E3                <1> 	mul	ebx ; Sectors per Cluster 
  4496                              <1> 	; EAX = Bytes per Cluster
  4497 0000AA1D 89C1                <1> 	mov	ecx, eax
  4498 0000AA1F C1E902              <1> 	shr	ecx, 2 ; dword count
  4499 0000AA22 31C0                <1> 	xor	eax, eax
  4500 0000AA24 F3AB                <1> 	rep	stosd ; clear cluster buffer
  4501                              <1> 
  4502 0000AA26 A1[E42C0100]        <1> 	mov	eax, [createfile_Cluster] ; 24/03/2016
  4503                              <1> 
  4504 0000AA2B 89D9                <1> 	mov	ecx, ebx
  4505                              <1> 
  4506                              <1> loc_createfile_get_set_wf_fclust_cont:
  4507 0000AA2D 83E802              <1> 	sub	eax, 2
  4508 0000AA30 F7E1                <1> 	mul	ecx
  4509                              <1> 	; EAX = Logical DOS disk address (offset)
  4510 0000AA32 E95DFFFFFF          <1>         jmp     loc_createfile_write_fcluster_to_disk
  4511                              <1> 
  4512                              <1> loc_createfile_save_fat_buffer_3:
  4513                              <1> 	; byte [FAT_BuffValidData] = 2
  4514 0000AA37 E89E060000          <1> 	call	save_fat_buffer
  4515 0000AA3C 723D                <1> 	jc	loc_createfile_stc_retn
  4516                              <1> 
  4517                              <1> 	; 21/03/2016
  4518 0000AA3E 803D[AE280100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  4519 0000AA45 721B                <1> 	jb	short loc_createfile_save_fat_buffer_4
  4520                              <1> 
  4521                              <1> 	; ESI = Logical DOS Drive Description Table address 
  4522 0000AA47 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4523 0000AA4C 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  4524 0000AA50 E81A070000          <1> 	call	calculate_fat_freespace
  4525                              <1> 
  4526                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  4527                              <1> 	;jnz	short loc_createfile_save_fat_buffer_4
  4528                              <1> 
  4529                              <1> 	; ecx > 0 -> Recalculation is needed
  4530 0000AA55 09C9                <1> 	or	ecx, ecx 
  4531 0000AA57 7409                <1> 	jz	short loc_createfile_save_fat_buffer_4
  4532                              <1> 
  4533 0000AA59 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  4534 0000AA5D E80D070000          <1> 	call	calculate_fat_freespace
  4535                              <1> 
  4536                              <1> loc_createfile_save_fat_buffer_4:
  4537 0000AA62 FF0D[F02C0100]      <1> 	dec	dword [createfile_CCount]
  4538                              <1> 	;jz	short loc_createfile_upd_dir_modif_date_time
  4539 0000AA68 743F                <1> 	jz	short loc_createfile_stc_retn_cc ; 31/03/2016
  4540                              <1> 
  4541                              <1> loc_createfile_get_set_write_next_cluster:
  4542 0000AA6A E8DB020000          <1> 	call	get_first_free_cluster
  4543 0000AA6F 720A                <1> 	jc	short loc_createfile_stc_retn
  4544                              <1> 
  4545                              <1> loc_createfile_get_set_write_next_cluster_1:
  4546 0000AA71 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  4547 0000AA74 7213                <1> 	jb	short loc_createfile_get_set_write_next_cluster_2
  4548                              <1> 
  4549                              <1> loc_createfile_wnc_insufficient_disk_space:	
  4550 0000AA76 B827000000          <1> 	mov	eax, 27h ; Insufficient disk space
  4551                              <1> 
  4552                              <1> loc_createfile_stc_retn:
  4553 0000AA7B 803D[F62C0100]01    <1> 	cmp	byte [createfile_wfc], 1
  4554 0000AA82 7324                <1> 	jnb	short loc_createfile_err_retn
  4555 0000AA84 C3                  <1> 	retn
  4556                              <1> 
  4557                              <1> loc_createfile_wnc_inv_format_retn:
  4558                              <1> 	;mov	eax, 0Bh
  4559 0000AA85 B00B                <1> 	mov	al, 0Bh ; Invalid format
  4560 0000AA87 EBF2                <1> 	jmp	short loc_createfile_stc_retn
  4561                              <1> 	         
  4562                              <1> loc_createfile_get_set_write_next_cluster_2:
  4563 0000AA89 83F802              <1> 	cmp	eax, 2
  4564 0000AA8C 72F7                <1> 	jb	short loc_createfile_wnc_inv_format_retn
  4565                              <1> 
  4566                              <1> loc_createfile_get_set_write_next_cluster_3:
  4567 0000AA8E 8B0D[E42C0100]      <1> 	mov	ecx, [createfile_Cluster]
  4568 0000AA94 A3[E42C0100]        <1> 	mov	[createfile_Cluster], eax
  4569 0000AA99 890D[E82C0100]      <1> 	mov	[createfile_PCluster], ecx
  4570 0000AA9F 0FB60D[ED2C0100]    <1> 	movzx	ecx, byte [createfile_SecPerClust]
  4571 0000AAA6 EB85                <1> 	jmp	short loc_createfile_get_set_wf_fclust_cont
  4572                              <1> 
  4573                              <1> loc_createfile_err_retn:
  4574 0000AAA8 F9                  <1> 	stc
  4575                              <1> 
  4576                              <1> ;loc_createfile_upd_dir_modif_date_time:
  4577                              <1> loc_createfile_stc_retn_cc: ; 31/03/2016
  4578 0000AAA9 9C                  <1> 	pushf	; cpu is here for an error return or completion 
  4579 0000AAAA 50                  <1> 	push	eax ; error code if cf = 1
  4580                              <1> 
  4581                              <1> 	;call	update_parent_dir_lmdt
  4582                              <1> 
  4583                              <1> ;loc_createfile_stc_retn_cc:
  4584 0000AAAB A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4585 0000AAB0 09C0                <1> 	or	eax, eax
  4586 0000AAB2 741A                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  4587 0000AAB4 8A3D[8E200100]      <1> 	mov	bh, [Current_Drv]
  4588 0000AABA B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
  4589                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  4590                              <1> 	; (If EAX value is negative, Free Cluster Count will be decreased)
  4591 0000AABC E8AE060000          <1>   	call	calculate_fat_freespace
  4592                              <1>         ; ESI = Logical DOS Drive Description Table Address 
  4593                              <1>         ;jc	short loc_createfile_stc_retn_pop_eax_cf
  4594 0000AAC1 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  4595 0000AAC3 7409                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  4596                              <1> 
  4597                              <1> loc_createfile_stc_retn_recalc_FAT_freespace:
  4598 0000AAC5 66BB00FF            <1> 	mov	bx, 0FF00h ; bh = 0FFh -> 
  4599                              <1> 	; ESI = Logical DOS Drv DT Addr
  4600                              <1> 	; BL = 0 -> Recalculate 
  4601 0000AAC9 E8A1060000          <1> 	call	calculate_fat_freespace
  4602                              <1> 
  4603                              <1> loc_createfile_stc_retn_pop_eax:
  4604 0000AACE 58                  <1> 	pop	eax
  4605 0000AACF 9D                  <1> 	popf
  4606 0000AAD0 7218                <1> 	jc	short loc_createfile_retn
  4607                              <1> 
  4608                              <1> loc_createfile_retn_fcluster:
  4609 0000AAD2 A1[DC2C0100]        <1> 	mov	eax, [createfile_FFCluster]
  4610 0000AAD7 BB[D82C0100]        <1> 	mov	ebx, createfile_size
  4611                              <1> 	;movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  4612 0000AADC 0FB60D[ED2C0100]    <1> 	movzx	ecx, byte [createfile_SecPerClust] ; 23/03/2016
  4613 0000AAE3 0FB715[EE2C0100]    <1> 	movzx	edx, word [createfile_DirIndex]
  4614                              <1> 
  4615                              <1> loc_createfile_retn:
  4616 0000AAEA C3                  <1> 	retn
  4617                              <1> 
  4618                              <1> create_fs_file:
  4619                              <1> 	; temporary (21/03/2016)
  4620 0000AAEB C3                  <1> 	retn
  4621                              <1> 
  4622                              <1> delete_fs_file:
  4623                              <1> 	; temporary (28/02/2016)
  4624 0000AAEC C3                  <1> 	retn
  4625                              <1> 
  4626                              <1> rename_fs_file_or_directory:
  4627 0000AAED C3                  <1> 	retn
  4628                              <1> 
  4629                              <1> make_fs_directory:
  4630                              <1> 	; temporary (21/02/2016)
  4631 0000AAEE C3                  <1> 	retn
  4632                              <1> 
  4633                              <1> add_new_fs_section:
  4634                              <1> 	; temporary (11/03/2016)
  4635 0000AAEF C3                  <1> 	retn
  4636                              <1> 
  4637                              <1> delete_fs_directory_entry:
  4638                              <1> 	; temporary (11/03/2016)
  4639 0000AAF0 C3                  <1> 	retn
  4640                              <1> 
  4641                              <1> csftdf2_read_fs_file_sectors:
  4642                              <1> 	; temporary (19/03/2016)
  4643 0000AAF1 C3                  <1> 	retn
  4644                              <1> 
  4645                              <1> csftdf2_write_fs_file_sectors:
  4646                              <1> 	; temporary (19/03/2016)
  4647 0000AAF2 C3                  <1> 	retn
  1922                                  %include 'trdosk5.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - File System Procedures : trdosk5s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 16/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; DRV_FAT.ASM (21/08/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; DRV_FAT.ASM (c) 2005-2011 Erdogan TAN [ 07/07/2009 ] Last Update: 21/08/2011
    14                              <1> 
    15                              <1> get_next_cluster:
    16                              <1> 	; 23/03/2016
    17                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
    18                              <1> 	; 05/07/2011
    19                              <1> 	; 07/07/2009
    20                              <1> 	; 2005
    21                              <1> 	; INPUT ->
    22                              <1> 	;	EAX = Cluster Number (32 bit)
    23                              <1> 	;	ESI = Logical DOS Drive Parameters Table
    24                              <1> 	; OUTPUT ->
    25                              <1> 	;	cf = 0 -> No Error, EAX valid
    26                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
    27                              <1> 	;	cf = 1 & EAX > 0 -> Error
    28                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
    29                              <1> 	;	EAX = Next Cluster Number (32 bit)
    30                              <1> 	;
    31                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
    32                              <1> 
    33 0000AAF3 A3[A2280100]        <1> 	mov	[FAT_CurrentCluster], eax
    34                              <1> check_next_cluster_fat_type:
    35 0000AAF8 29D2                <1> 	sub	edx, edx ; 0
    36 0000AAFA 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
    37 0000AAFE 7250                <1> 	jb	short get_FAT12_next_cluster
    38 0000AB00 0F87AF000000        <1>         ja      get_FAT32_next_cluster
    39                              <1> get_FAT16_next_cluster:
    40 0000AB06 BB00030000          <1> 	mov	ebx, 300h ;768
    41 0000AB0B F7F3                <1> 	div	ebx
    42                              <1> 	; EAX = Count of 3 FAT sectors
    43                              <1> 	; EDX = Cluster Offset (< 768)
    44 0000AB0D 66D1E2              <1> 	shl	dx, 1 ; Multiply by 2
    45 0000AB10 89D3                <1> 	mov	ebx, edx ; Byte Offset
    46 0000AB12 81C3001C0900        <1> 	add	ebx, FAT_Buffer
    47 0000AB18 66BA0300            <1> 	mov	dx, 3
    48 0000AB1C F7E2                <1> 	mul	edx  
    49                              <1> 	; EAX = FAT Sector (<= 256)
    50                              <1> 	; EDX = 0
    51 0000AB1E 8A0E                <1> 	mov	cl, [esi+LD_Name]
    52 0000AB20 803D[A6280100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
    53 0000AB27 0F86CC000000        <1>         jna     load_FAT_sectors0
    54 0000AB2D 3A0D[A7280100]      <1> 	cmp	cl, [FAT_BuffDrvName]
    55 0000AB33 0F85C0000000        <1>         jne     load_FAT_sectors0
    56 0000AB39 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
    57 0000AB3F 0F85BA000000        <1>         jne     load_FAT_sectors1
    58                              <1> 	;movzx	eax, word [ebx]
    59 0000AB45 668B03              <1> 	mov	ax, [ebx]
    60                              <1> 	; 01/02/2016
    61                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
    62                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
    63                              <1> 	; (how can i do a such mistake!?)
    64                              <1> 	;cmp	al, 0F7h
    65                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    66                              <1> 	;cmp	ah, 0FFh
    67                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    68 0000AB48 6683F8F7            <1> 	cmp	ax, 0FFF7h
    69 0000AB4C 725A                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
    70                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
    71 0000AB4E EB56                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
    72                              <1> 
    73                              <1> get_FAT12_next_cluster:
    74 0000AB50 BB00040000          <1> 	mov	ebx, 400h ;1024
    75 0000AB55 F7F3                <1> 	div	ebx
    76                              <1> 	; EAX = Count of 3 FAT sectors
    77                              <1> 	; EDX = Cluster Offset (< 1024)
    78 0000AB57 6650                <1> 	push	ax
    79 0000AB59 66B80300            <1> 	mov	ax, 3	
    80 0000AB5D 66F7E2              <1> 	mul	dx    	; Multiply by 3
    81 0000AB60 66D1E8              <1> 	shr	ax, 1	; Divide by 2
    82 0000AB63 6689C3              <1>         mov	bx, ax 	; Byte Offset
    83 0000AB66 81C3001C0900        <1> 	add	ebx, FAT_Buffer
    84 0000AB6C 6658                <1> 	pop	ax
    85 0000AB6E 66BA0300            <1> 	mov	dx, 3
    86 0000AB72 F7E2                <1> 	mul	edx 
    87                              <1> 	; EAX = FAT Sector (<= 12)
    88                              <1> 	; EDX = 0
    89 0000AB74 8A0E                <1> 	mov	cl, [esi+LD_Name]
    90 0000AB76 803D[A6280100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
    91 0000AB7D 767A                <1> 	jna	short load_FAT_sectors0
    92 0000AB7F 3A0D[A7280100]      <1> 	cmp	cl, [FAT_BuffDrvName]
    93 0000AB85 7572                <1> 	jne	short load_FAT_sectors0
    94 0000AB87 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
    95 0000AB8D 7570                <1> 	jne	short load_FAT_sectors1
    96 0000AB8F A1[A2280100]        <1> 	mov	eax, [FAT_CurrentCluster]
    97 0000AB94 66D1E8              <1> 	shr	ax, 1
    98                              <1> 	;movzx	eax, word [ebx]
    99 0000AB97 668B03              <1> 	mov	ax, [ebx]
   100 0000AB9A 7314                <1> 	jnc	short get_FAT12_nc_even
   101 0000AB9C 66C1E804            <1> 	shr	ax, 4
   102                              <1> loc_gnc_fat12_eoc_check:
   103                              <1> 	;cmp	al, 0F7h
   104                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   105                              <1> 	;cmp	ah, 0Fh
   106                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   107 0000ABA0 663DF70F            <1> 	cmp	ax, 0FF7h
   108 0000ABA4 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
   109                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
   110                              <1> 
   111                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
   112 0000ABA6 31C0                <1> 	xor	eax, eax ; 0
   113                              <1> loc_pass_gnc_FAT16_eoc_check:
   114                              <1> loc_pass_gnc_FAT32_eoc_check:
   115 0000ABA8 8B0D[A2280100]      <1> 	mov	ecx, [FAT_CurrentCluster]
   116 0000ABAE F5                  <1> 	cmc
   117 0000ABAF C3                  <1> 	retn
   118                              <1> 
   119                              <1> get_FAT12_nc_even:
   120 0000ABB0 80E40F              <1> 	and	ah, 0Fh
   121 0000ABB3 EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
   122                              <1> 
   123                              <1> get_FAT32_next_cluster:
   124 0000ABB5 BB80010000          <1> 	mov	ebx, 180h ;384
   125 0000ABBA F7F3                <1> 	div	ebx
   126                              <1> 	; EAX = Count of 3 FAT sectors
   127                              <1> 	; EDX = Cluster Offset (< 384)
   128 0000ABBC 66C1E202            <1> 	shl	dx, 2	; Multiply by 4
   129 0000ABC0 89D3                <1> 	mov	ebx, edx ; Byte Offset
   130 0000ABC2 81C3001C0900        <1> 	add	ebx, FAT_Buffer
   131 0000ABC8 66BA0300            <1> 	mov	dx, 3
   132 0000ABCC F7E2                <1> 	mul	edx	
   133                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
   134                              <1> 	; 	for 32KB cluster size:
   135                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512 	
   136                              <1> 	; EDX = 0
   137 0000ABCE 8A0E                <1> 	mov	cl, [esi+LD_Name]
   138 0000ABD0 803D[A6280100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
   139 0000ABD7 7620                <1> 	jna	short load_FAT_sectors0
   140 0000ABD9 3A0D[A7280100]      <1> 	cmp	cl, [FAT_BuffDrvName]
   141 0000ABDF 7518                <1> 	jne	short load_FAT_sectors0
   142 0000ABE1 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
   143 0000ABE7 7516                <1> 	jne	short load_FAT_sectors1
   144 0000ABE9 8B03                <1> 	mov	eax, [ebx]
   145 0000ABEB 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
   146 0000ABF0 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
   147 0000ABF5 72B1                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
   148                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
   149 0000ABF7 EBAD                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
   150                              <1> 
   151                              <1> load_FAT_sectors0:
   152 0000ABF9 880D[A7280100]      <1> 	mov	[FAT_BuffDrvName], cl
   153                              <1> load_FAT_sectors1:
   154 0000ABFF A3[AA280100]        <1> 	mov	[FAT_BuffSector], eax
   155 0000AC04 89C3                <1> 	mov	ebx, eax
   156 0000AC06 034660              <1>         add     eax, [esi+LD_FATBegin]
   157 0000AC09 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
   158 0000AC0D 7706                <1>         ja      short load_FAT_sectors3
   159 0000AC0F 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
   160 0000AC13 EB03                <1> 	jmp	short load_FAT_sectors4
   161                              <1> load_FAT_sectors3:
   162 0000AC15 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
   163                              <1> load_FAT_sectors4:
   164 0000AC18 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
   165 0000AC1A 83F903              <1>         cmp     ecx, 3
   166 0000AC1D 7605                <1>         jna     short load_FAT_sectors5
   167 0000AC1F B903000000          <1> 	mov	ecx, 3
   168                              <1> load_FAT_sectors5:
   169 0000AC24 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   170 0000AC29 E8EE2D0000          <1> 	call	disk_read
   171 0000AC2E 730D                <1> 	jnc	short load_FAT_sectors_ok
   172                              <1> 	; 23/03/2016
   173 0000AC30 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
   174 0000AC35 C605[A6280100]00    <1> 	mov	byte [FAT_BuffValidData], 0
   175 0000AC3C C3                  <1> 	retn
   176                              <1> load_FAT_sectors_ok:
   177 0000AC3D C605[A6280100]01    <1> 	mov	byte [FAT_BuffValidData], 1
   178 0000AC44 A1[A2280100]        <1> 	mov	eax, [FAT_CurrentCluster]
   179 0000AC49 E9AAFEFFFF          <1>         jmp     check_next_cluster_fat_type
   180                              <1> 
   181                              <1> load_FAT_root_directory:
   182                              <1> 	; 07/02/2016
   183                              <1> 	; 02/02/2016
   184                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
   185                              <1> 	; 21/05/2011
   186                              <1> 	; 22/08/2009
   187                              <1> 	;
   188                              <1> 	; INPUT ->
   189                              <1> 	;	ESI = Logical DOS Drive Description Table
   190                              <1> 	; OUTPUT ->
   191                              <1> 	;	cf = 1 -> Root directory could not be loaded
   192                              <1> 	;	    EAX > 0 -> Error number
   193                              <1> 	;	cf = 0 -> EAX = 0
   194                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   195                              <1> 	;	EBX = Directory buffer address
   196                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   197                              <1> 	;
   198                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   199                              <1> 
   200                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
   201                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
   202                              <1> 
   203 0000AC4E 8A1E                <1> 	mov	bl, [esi+LD_Name]
   204 0000AC50 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   205                              <1> 
   206                              <1> 	;mov	[DirBuff_DRV], bl
   207                              <1> 	;mov	[DirBuff_FATType], bh
   208 0000AC53 66891D[B6280100]    <1> 	mov	[DirBuff_DRV], bx
   209                              <1> 	
   210                              <1> 	;cmp	bh, 2
   211                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
   212                              <1> 
   213 0000AC5A 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
   214                              <1> 
   215                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
   216                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
   217                              <1> 
   218 0000AC5E 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
   219 0000AC63 7414                <1> 	je	short lrd_mov_ecx_32
   220 0000AC65 89D0                <1> 	mov	eax, edx
   221 0000AC67 6683C00F            <1> 	add	ax, 15 ; round up 
   222 0000AC6B 66C1E804            <1> 	shr	ax, 4  ; 16 entries per sector (512/32)
   223 0000AC6F 89C1                <1> 	mov	ecx, eax ; Root directory size in sectors
   224 0000AC71 66C1E009            <1> 	shl	ax, 9 ; Root directory size in bytes
   225 0000AC75 664A                <1> 	dec	dx    ; Last entry number of root dir
   226                              <1> 	; cx = Dir Buffer sector count             
   227 0000AC77 EB0B                <1> 	jmp	short lrd_check_dir_buffer
   228                              <1> 
   229                              <1> lrd_mov_ecx_32:
   230 0000AC79 B920000000          <1> 	mov	ecx, 32
   231 0000AC7E 664A                <1> 	dec	dx ; 511
   232 0000AC80 66B80040            <1> 	mov	ax, 32*512 
   233                              <1>  
   234                              <1> lrd_check_dir_buffer:
   235 0000AC84 29DB                <1> 	sub	ebx, ebx ; 0
   236 0000AC86 881D[B8280100]      <1> 	mov	[DirBuff_ValidData], bl ; 0
   237 0000AC8C 668915[BB280100]    <1> 	mov	[DirBuff_LastEntry], dx
   238 0000AC93 891D[BD280100]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
   239 0000AC99 66A3[C1280100]      <1> 	mov	[DirBuffer_Size], ax
   240                              <1> 
   241 0000AC9F 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
   242                              <1> read_directory:
   243 0000ACA2 BB00000800          <1> 	mov	ebx, Directory_Buffer
   244 0000ACA7 51                  <1> 	push	ecx ; Directory buffer sector count
   245 0000ACA8 53                  <1> 	push	ebx
   246 0000ACA9 E86E2D0000          <1> 	call	disk_read
   247 0000ACAE 5B                  <1> 	pop	ebx
   248 0000ACAF 720B                <1> 	jc	short load_DirBuff_error
   249                              <1> 
   250                              <1> validate_DirBuff_and_return:
   251 0000ACB1 59                  <1> 	pop	ecx ; Number of loaded sectors
   252 0000ACB2 C605[B8280100]01    <1> 	mov	byte [DirBuff_ValidData], 1
   253 0000ACB9 31C0                <1> 	xor	eax, eax ; 0 = no error
   254 0000ACBB C3                  <1> 	retn
   255                              <1> 
   256                              <1> load_DirBuff_error:
   257 0000ACBC 89C8                <1> 	mov	eax, ecx ; remaining sectors
   258 0000ACBE 59                  <1> 	pop	ecx ; sector count
   259 0000ACBF 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
   260 0000ACC1 B815000000          <1> 	mov	eax, 15h ; DRV NOT READY OR READ ERROR !
   261 0000ACC6 F9                  <1> 	stc
   262 0000ACC7 C3                  <1>         retn
   263                              <1> 
   264                              <1> load_FAT32_root_directory:
   265                              <1> 	; 02/02/2016 (TRDOS 386 =  TRDOS v2.0)
   266                              <1> 	;
   267                              <1> 	; INPUT ->
   268                              <1> 	;	ESI = Logical DOS Drive Description Table
   269                              <1> 	; OUTPUT ->
   270                              <1> 	;	cf = 1 -> Root directory could not be loaded
   271                              <1> 	;	    EAX > 0 -> Error number
   272                              <1> 	;	cf = 0 -> EAX = 0
   273                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   274                              <1> 	;	EBX = Directory buffer address
   275                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   276                              <1> 	;
   277                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   278                              <1> 
   279                              <1> 
   280 0000ACC8 8A1E                <1> 	mov	bl, [esi+LD_Name]
   281 0000ACCA 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   282                              <1> 
   283                              <1> 	;mov	[DirBuff_DRV], bl
   284                              <1> 	;mov	[DirBuff_FATType], bh
   285 0000ACCD 66891D[B6280100]    <1> 	mov	[DirBuff_DRV], bx
   286                              <1> 
   287                              <1> load_FAT32_root_dir0:
   288 0000ACD4 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   289 0000ACD7 EB0C                <1> 	jmp	short load_FAT_sub_dir0
   290                              <1> 	
   291                              <1> load_FAT_sub_directory:
   292                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
   293                              <1> 	; 05/07/2011
   294                              <1> 	; 23/08/2009
   295                              <1> 	;
   296                              <1> 	; INPUT ->
   297                              <1> 	;	ESI = Logical DOS Drive Description Table
   298                              <1> 	;	EAX = Cluster Number
   299                              <1> 	; OUTPUT ->
   300                              <1> 	;	cf = 1 -> Sub directory could not be loaded
   301                              <1> 	;	    EAX > 0 -> Error number
   302                              <1> 	;	cf = 0 -> EAX = 0
   303                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   304                              <1> 	;	EBX = Directory buffer address
   305                              <1> 	;
   306                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   307                              <1> 	;
   308                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   309                              <1> 
   310 0000ACD9 8A1E                <1> 	mov	bl, [esi+LD_Name]
   311 0000ACDB 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   312                              <1> 
   313                              <1> 	;mov	[DirBuff_DRV], bl
   314                              <1> 	;mov	[DirBuff_FATType], bh
   315 0000ACDE 66891D[B6280100]    <1> 	mov	[DirBuff_DRV], bx
   316                              <1> 
   317                              <1> load_FAT_sub_dir0:
   318 0000ACE5 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
   319                              <1> 
   320 0000ACE9 882D[B8280100]      <1> 	mov	[DirBuff_ValidData], ch ; 0
   321 0000ACEF A3[BD280100]        <1> 	mov	[DirBuff_Cluster], eax
   322                              <1> 
   323 0000ACF4 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
   324 0000ACF8 F7E1                <1> 	mul	ecx
   325 0000ACFA C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
   326 0000ACFD 6648                <1> 	dec	ax ; last entry
   327 0000ACFF 66A3[BB280100]      <1> 	mov	[DirBuff_LastEntry], ax
   328                              <1> 
   329 0000AD05 A1[BD280100]        <1> 	mov	eax, [DirBuff_Cluster]
   330 0000AD0A 83E802              <1> 	sub	eax, 2
   331 0000AD0D F7E1                <1> 	mul	ecx
   332 0000AD0F 034668              <1> 	add	eax, [esi+LD_DATABegin]
   333                              <1> 	; ecx = sector per cluster (dir buffer size = 32 sectors)
   334 0000AD12 EB8E                <1> 	jmp	short read_directory
   335                              <1> 
   336                              <1> ; DRV_FS.ASM
   337                              <1> 
   338                              <1> load_current_FS_directory:
   339 0000AD14 C3                  <1> 	retn
   340                              <1> load_FS_root_directory:
   341 0000AD15 C3                  <1> 	retn
   342                              <1> load_FS_sub_directory:
   343 0000AD16 C3                  <1> 	retn
   344                              <1> 
   345                              <1> read_cluster:
   346                              <1> 	; 18/03/2016
   347                              <1> 	; 16/03/2016
   348                              <1> 	; 17/02/2016
   349                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   350                              <1> 	;
   351                              <1> 	; INPUT ->
   352                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
   353                              <1> 	;	ESI = Logical DOS Drive Description Table address
   354                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
   355                              <1> 	;	Only for SINGLIX FS:
   356                              <1> 	;	EDX = File Number (The 1st FDT address) 
   357                              <1> 	; OUTPUT ->
   358                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
   359                              <1> 	;	    EAX > 0 -> Error number
   360                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
   361                              <1> 	;
   362                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   363                              <1> 	
   364 0000AD17 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
   365                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
   366                              <1> 
   367                              <1> read_file_sectors: ; 16/03/2016
   368 0000AD1B 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
   369 0000AD1F 761C                <1> 	jna	short read_fs_cluster
   370                              <1> 
   371                              <1> read_fat_file_sectors: ; 18/03/2016
   372 0000AD21 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
   373 0000AD24 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
   374 0000AD28 F7E2                <1> 	mul	edx
   375 0000AD2A 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
   376                              <1> 
   377                              <1> 	; EAX = Disk sector address
   378                              <1> 	; ECX = Sector count
   379                              <1> 	; EBX = Buffer address
   380                              <1> 	; (EDX = 0)
   381                              <1> 	; ESI = Logical DOS drive description table address	
   382                              <1> 
   383 0000AD2D E8EA2C0000          <1> 	call	disk_read
   384 0000AD32 7306                <1> 	jnc	short rclust_retn
   385                              <1> 	
   386 0000AD34 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
   387 0000AD39 C3                  <1> 	retn
   388                              <1> 
   389                              <1> rclust_retn:
   390 0000AD3A 29C0                <1> 	sub	eax, eax ; 0
   391 0000AD3C C3                  <1> 	retn
   392                              <1> 
   393                              <1> read_fs_cluster:
   394                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   395                              <1> 	; Singlix FS
   396                              <1> 	
   397                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
   398                              <1> 	
   399                              <1> 	; EDX = File number is the first File Descriptor Table address 
   400                              <1> 	;	of the file. (Absolute address of the FDT).
   401                              <1> 	
   402                              <1> 	; eax = sector index (0 for the first sector)
   403                              <1> 	; edx = FDT0 address
   404                              <1> 		; 64 KB buffer = 128 sectors (limit) 
   405 0000AD3D B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
   406 0000AD42 E801000000          <1> 	call	read_fs_sectors
   407 0000AD47 C3                  <1> 	retn
   408                              <1> 
   409                              <1> read_fs_sectors:
   410                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   411 0000AD48 F9                  <1> 	stc
   412 0000AD49 C3                  <1> 	retn
   413                              <1> 
   414                              <1> get_first_free_cluster:
   415                              <1> 	; 02/03/2016
   416                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
   417                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
   418                              <1> 	; 10/07/2010
   419                              <1> 	; INPUT ->
   420                              <1> 	;	ESI = Logical DOS Drive Description Table address
   421                              <1> 	; OUTPUT ->
   422                              <1> 	;	cf = 1 -> Error code in AL (EAX)
   423                              <1> 	;	cf = 0 -> 
   424                              <1> 	;	  EAX = Cluster number 
   425                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
   426                              <1> 	;	If the drive has FAT32 fs:
   427                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
   428                              <1> 
   429 0000AD4A 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
   430 0000AD4D 40                  <1> 	inc	eax ; add eax, 1
   431 0000AD4E A3[402B0100]        <1> 	mov	[gffc_last_free_cluster], eax
   432                              <1> 
   433 0000AD53 31DB                <1> 	xor	ebx, ebx ; 0 ; 02/03/2016
   434                              <1> 
   435 0000AD55 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
   436 0000AD59 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
   437                              <1> 
   438                              <1> loc_gffc_get_first_fat32_free_cluster:
   439                              <1> 	; 02/03/2016
   440 0000AD5B E834060000          <1> 	call	get_fat32_fsinfo_sector_parms
   441 0000AD60 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0 
   442                              <1> 
   443                              <1> loc_gffc_check_fsinfo_parms:
   444                              <1> 	;;mov	ebx, DOSBootSectorBuff
   445                              <1> 	;cmp	dword [ebx], 41615252h
   446                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   447                              <1> 	;cmp	dword [ebx+484], 61417272h
   448                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   449                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
   450                              <1> 	;EAX = First free cluster 
   451                              <1> 	;(from FAT32 FSInfo sector)
   452 0000AD62 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
   453 0000AD64 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
   454 0000AD67 7205                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
   455                              <1> 
   456                              <1> 	; Start from the 1st cluster of the FAT(32) file system
   457                              <1> loc_gffc_get_first_fat_free_cluster0:
   458 0000AD69 B802000000          <1> 	mov	eax, 2
   459                              <1> 	;xor	edx, edx
   460                              <1> 
   461                              <1> loc_gffc_get_first_fat_free_cluster1:
   462 0000AD6E 53                  <1> 	push	ebx ; 02/03/2016 
   463                              <1> 
   464                              <1> loc_gffc_get_first_fat_free_cluster2:   
   465 0000AD6F A3[3C2B0100]        <1> 	mov	[gffc_first_free_cluster], eax
   466 0000AD74 A3[382B0100]        <1> 	mov	[gffc_next_free_cluster], eax
   467                              <1> 
   468                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   469                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   470                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   471                              <1> 
   472                              <1> loc_gffc_get_first_fat_free_cluster3:
   473 0000AD79 E875FDFFFF          <1> 	call	get_next_cluster
   474 0000AD7E 7307                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster4
   475 0000AD80 09C0                <1> 	or	eax, eax
   476 0000AD82 740B                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
   477 0000AD84 5B                  <1> 	pop	ebx ; 02/03/2016
   478 0000AD85 F5                  <1> 	cmc 	; stc
   479 0000AD86 C3                  <1> 	retn
   480                              <1> 
   481                              <1> loc_gffc_get_first_fat_free_cluster4:
   482 0000AD87 21C0                <1> 	and	eax, eax ; next cluster value
   483 0000AD89 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
   484 0000AD8B 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
   485 0000AD8D EB22                <1> 	jmp	short loc_gffc_check_for_set
   486                              <1>  
   487                              <1> loc_gffc_first_free_fat_cluster_next:
   488 0000AD8F A1[382B0100]        <1> 	mov	eax, [gffc_next_free_cluster]
   489 0000AD94 3B05[402B0100]      <1> 	cmp	eax, [gffc_last_free_cluster]
   490 0000AD9A 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
   491                              <1> pass_gffc_last_cluster_eax_check:
   492 0000AD9C 40                  <1> 	inc	eax ; add eax, 1
   493 0000AD9D A3[382B0100]        <1> 	mov	[gffc_next_free_cluster], eax
   494 0000ADA2 EBD5                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster3
   495                              <1> 
   496                              <1> retn_stc_from_get_first_free_cluster:
   497 0000ADA4 A1[3C2B0100]        <1> 	mov	eax, [gffc_first_free_cluster]
   498 0000ADA9 83F802              <1> 	cmp	eax, 2
   499 0000ADAC 7709                <1> 	ja	short loc_gffc_check_previous_clusters
   500 0000ADAE 29C0                <1> 	sub	eax, eax
   501 0000ADB0 48                  <1> 	dec	eax ; FFFFFFFFh
   502                              <1> 
   503                              <1> loc_gffc_check_for_set:
   504                              <1> 	; 02/03/2016
   505 0000ADB1 5B                  <1> 	pop	ebx
   506                              <1> 
   507                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   508                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   509                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   510                              <1> 
   511 0000ADB2 09DB                <1> 	or	ebx, ebx
   512 0000ADB4 750E                <1> 	jnz	short loc_gffc_set_ffree_fat32_cluster
   513                              <1> 
   514                              <1> 	;cmp	byte [esi+LD_FATType], 3
   515                              <1> 	;jnb	short loc_gffc_set_ffree_fat32_cluster
   516                              <1> 
   517                              <1> 	;xor	ebx, ebx ; 0
   518                              <1> 
   519                              <1> loc_gffc_retn:
   520 0000ADB6 C3                  <1> 	retn
   521                              <1> 
   522                              <1> loc_gffc_check_previous_clusters:
   523 0000ADB7 48                  <1> 	dec	eax ; sub eax, 1
   524 0000ADB8 A3[402B0100]        <1> 	mov	[gffc_last_free_cluster], eax 
   525 0000ADBD B802000000          <1> 	mov	eax, 2
   526                              <1> 	;xor	edx, edx
   527 0000ADC2 EBAB                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
   528                              <1> 
   529                              <1> loc_gffc_set_ffree_fat32_cluster:
   530                              <1> 	;call	set_first_free_cluster
   531                              <1> 	;retn
   532                              <1> 	;jmp	short set_first_free_cluster	
   533                              <1> 
   534                              <1> set_first_free_cluster:
   535                              <1> 	; 23/03/2016
   536                              <1> 	; 02/03/2016
   537                              <1> 	; 29/02/2016
   538                              <1> 	; 26/02/2016
   539                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
   540                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
   541                              <1> 	; 11/07/2010
   542                              <1> 	; INPUT -> 
   543                              <1> 	;	ESI = Logical DOS Drive Description Table address
   544                              <1> 	;	EAX = First free cluster
   545                              <1> 	;	EBX = FSINFO sector buffer address
   546                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
   547                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
   548                              <1> 	; OUTPUT->
   549                              <1> 	;	ESI = Logical DOS Drive Description Table address
   550                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
   551                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
   552                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
   553                              <1> 	;	CF = 0 -> first free cluster is successfully updated 
   554                              <1> 
   555                              <1> 	;cmp	byte [esi+LD_FATType], 3
   556                              <1> 	;jb	short loc_sffc_invalid_drive
   557                              <1> 
   558                              <1> 	; Save First Free Cluster value for 'update_cluster'
   559 0000ADC4 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster	
   560                              <1> 
   561                              <1> 	;or	ebx, ebx
   562                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
   563                              <1> 
   564 0000ADC7 813B52526141        <1> 	cmp     dword [ebx], 41615252h
   565 0000ADCD 7540                <1> 	jne	short loc_sffc_read_fsinfo_sector
   566 0000ADCF 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
   566 0000ADD8 61                  <1>
   567 0000ADD9 7534                <1> 	jne	short loc_sffc_read_fsinfo_sector
   568                              <1> 
   569 0000ADDB 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
   570 0000ADE1 741F                <1> 	je	short loc_sffc_retn
   571                              <1> 
   572                              <1> loc_sffc_write_fsinfo_sector:
   573                              <1> 	; EBX = FSINFO sector buffer
   574                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
   575 0000ADE3 8983EC010000        <1> 	mov	[ebx+492], eax
   576 0000ADE9 A1[502B0100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC] 
   577 0000ADEE B901000000          <1> 	mov	ecx, 1
   578 0000ADF3 53                  <1> 	push	ebx
   579 0000ADF4 E8142C0000          <1> 	call	disk_write
   580 0000ADF9 7208                <1> 	jc      short loc_sffc_read_fsinfo_sector_err1
   581 0000ADFB 5B                  <1> 	pop	ebx
   582                              <1> 
   583 0000ADFC 8B83EC010000        <1> 	mov	eax, [ebx+492] ; First (Next) Free Cluster
   584                              <1> 
   585                              <1> loc_sffc_retn:
   586 0000AE02 C3                  <1> 	retn
   587                              <1> 
   588                              <1> ;loc_sffc_invalid_drive:
   589                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
   590                              <1> ;	push	edx
   591                              <1> 
   592                              <1> loc_sffc_read_fsinfo_sector_err1:
   593 0000AE03 BB00000000          <1> 	mov	ebx, 0
   594                              <1> 	; 23/03/2016
   595 0000AE08 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
   596                              <1> 
   597                              <1> loc_sffc_read_fsinfo_sector_err2:
   598 0000AE0D 5A                  <1> 	pop	edx
   599 0000AE0E C3                  <1> 	retn
   600                              <1> 	
   601                              <1> loc_sffc_read_fsinfo_sector:
   602 0000AE0F 50                  <1> 	push	eax
   603                              <1> 
   604 0000AE10 E87F050000          <1> 	call	get_fat32_fsinfo_sector_parms
   605 0000AE15 72F6                <1> 	jc	short loc_sffc_read_fsinfo_sector_err2
   606                              <1> 
   607 0000AE17 58                  <1> 	pop	eax
   608                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
   609                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
   610                              <1> 	; (edx = old value)
   611 0000AE18 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value) 
   612 0000AE1A 75C7                <1> 	jne	short loc_sffc_write_fsinfo_sector
   613                              <1> 
   614 0000AE1C C3                  <1> 	retn	
   615                              <1> 
   616                              <1> update_cluster:
   617                              <1> 	; 02/03/2016
   618                              <1> 	; 01/03/2016
   619                              <1> 	; 29/02/2016
   620                              <1> 	; 27/02/2016
   621                              <1> 	; 26/02/2016
   622                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
   623                              <1> 	; 11/08/2011  
   624                              <1> 	; 09/02/2005
   625                              <1> 	; INPUT ->
   626                              <1> 	;	EAX = Cluster Number
   627                              <1> 	;	ECX = New Cluster Value
   628                              <1> 	;	ESI = Logical Dos Drive Parameters Table
   629                              <1> 	;
   630                              <1> 	;	/// dword [FAT_ClusterCounter] ///
   631                              <1> 	;
   632                              <1> 	; OUTPUT ->
   633                              <1> 	;	cf = 0 -> No Error, EAX is valid
   634                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
   635                              <1> 	; 	cf = 1 & EAX > 0 -> Error
   636                              <1> 	;		(ECX -> any value)
   637                              <1> 	; 	EAX = Next Cluster
   638                              <1> 	;	ECX = New Cluster Value
   639                              <1> 	;
   640                              <1> 	;	/// [FAT_ClusterCounter] is updated,
   641                              <1> 	;	/// decreased when a free cluster is assigned,
   642                              <1> 	;	/// increased if an assigned cluster is freed.	
   643                              <1> 	;		
   644                              <1> 	;
   645                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
   646                              <1> 	
   647 0000AE1D A3[A2280100]        <1> 	mov	[FAT_CurrentCluster], eax
   648 0000AE22 890D[442B0100]      <1> 	mov	[ClusterValue], ecx
   649                              <1> 
   650                              <1> loc_update_cluster_check_fat_buffer:
   651 0000AE28 8A1E                <1> 	mov	bl, [esi+LD_Name]
   652 0000AE2A 381D[A7280100]      <1> 	cmp	[FAT_BuffDrvName], bl
   653 0000AE30 741A                <1> 	je	short loc_update_cluster_check_fat_type
   654 0000AE32 803D[A6280100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
   655 0000AE39 0F84C2000000        <1>         je      loc_uc_save_fat_buffer
   656                              <1> 
   657                              <1> loc_uc_reset_fat_buffer_validation:
   658 0000AE3F C605[A6280100]00    <1> 	mov	byte [FAT_BuffValidData], 0
   659                              <1> 
   660                              <1> loc_uc_check_fat_type_reset_drvname:
   661 0000AE46 881D[A7280100]      <1> 	mov	[FAT_BuffDrvName], bl
   662                              <1> 
   663                              <1> loc_update_cluster_check_fat_type:
   664 0000AE4C 29D2                <1> 	sub	edx, edx ; 26/02/2016
   665 0000AE4E 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
   666 0000AE51 83F802              <1> 	cmp	eax, 2
   667 0000AE54 0F82BE000000        <1>         jb      update_cluster_inv_data
   668 0000AE5A 80FB02              <1> 	cmp	bl, 2 
   669 0000AE5D 0F877A010000        <1>         ja      update_fat32_cluster
   670                              <1> 	;cmp	bl, 1
   671                              <1> 	;jb	short update_cluster_inv_data
   672 0000AE63 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
   673 0000AE66 41                  <1> 	inc	ecx  
   674 0000AE67 890D[B2280100]      <1> 	mov	[LastCluster], ecx
   675 0000AE6D 39C8                <1> 	cmp	eax, ecx ; dword [LastCluster]
   676 0000AE6F 0F87A6000000        <1>         ja      return_uc_fat_stc
   677                              <1> 	; TRDOS v1 has a FATal bug here ! 
   678                              <1> 		; or bl, bl ; cmp bl, 0
   679                              <1> 		; jz short update_fat12_cluster
   680                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
   681                              <1> 	; ('A:' disks of TRDOS v1 operating system project
   682                              <1> 	; had 'singlix fs', so, I could not differ this mistake
   683                              <1> 	; on a drive 'A:')
   684 0000AE75 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
   685 0000AE78 0F86A2000000        <1>         jna     update_fat12_cluster 
   686                              <1> 
   687                              <1> update_fat16_cluster:
   688                              <1> pass_uc_fat16_errc:
   689                              <1> 	;sub	edx, edx
   690 0000AE7E BB00030000          <1> 	mov	ebx, 300h ;768
   691 0000AE83 F7F3                <1> 	div	ebx
   692                              <1> 	; EAX = Count of 3 FAT sectors
   693                              <1> 	; DX = Cluster offset in FAT buffer
   694 0000AE85 6689D3              <1> 	mov	bx, dx  
   695 0000AE88 66D1E3              <1> 	shl	bx, 1 ; Multiply by 2
   696 0000AE8B 66BA0300            <1> 	mov	dx, 3
   697 0000AE8F F7E2                <1> 	mul	edx  
   698                              <1> 	; EAX = FAT Sector
   699                              <1> 	; EDX = 0
   700                              <1> 	; EBX = Byte offset in FAT buffer
   701 0000AE91 8A0D[A6280100]      <1> 	mov	cl, [FAT_BuffValidData]
   702 0000AE97 80F902              <1> 	cmp	cl, 2
   703 0000AE9A 750A                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
   704                              <1> 
   705                              <1> loc_uc_check_fat16_buff_sector_save:
   706 0000AE9C 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   707 0000AEA2 755D                <1> 	jne	short loc_uc_save_fat_buffer
   708 0000AEA4 EB15                <1> 	jmp	short loc_update_fat16_cell
   709                              <1> 
   710                              <1> loc_uc_check_fat16_buff_sector_load:
   711 0000AEA6 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
   712 0000AEA9 0F85FB010000        <1>         jne     loc_uc_load_fat_sectors
   713 0000AEAF 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   714 0000AEB5 0F85EF010000        <1>         jne     loc_uc_load_fat_sectors
   715                              <1> 
   716                              <1> loc_update_fat16_cell:
   717                              <1> loc_update_fat16_buffer:
   718 0000AEBB 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   719                              <1> 	;movzx	eax, word [ebx]
   720 0000AEC1 668B03              <1> 	mov	ax, [ebx]
   721                              <1> 	; 01/03/2016
   722 0000AEC4 89C2                <1> 	mov	edx, eax ; old value of the cluster
   723 0000AEC6 A3[A2280100]        <1> 	mov	[FAT_CurrentCluster], eax
   724 0000AECB 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   725 0000AED1 66890B              <1> 	mov	[ebx], cx ; 16 bits !
   726                              <1> 
   727 0000AED4 C605[A6280100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   728                              <1> 	
   729 0000AEDB 6683F802            <1> 	cmp	ax, 2
   730 0000AEDF 723A                <1> 	jb	short return_uc_fat_stc
   731 0000AEE1 3B05[B2280100]      <1> 	cmp	eax, [LastCluster]
   732 0000AEE7 7732                <1> 	ja	short return_uc_fat_stc
   733                              <1> 
   734                              <1> loc_fat_buffer_updated:
   735                              <1> 	; 01/03/2016
   736 0000AEE9 F8                  <1> 	clc
   737                              <1> loc_fat_buffer_stc_1:
   738 0000AEEA 9C                  <1> 	pushf
   739 0000AEEB 21C9                <1> 	and	ecx, ecx
   740 0000AEED 7506                <1> 	jnz	short loc_fat_buffer_updated_1
   741                              <1> 
   742                              <1> 	; 01/03/2016 
   743                              <1> 	; new value of the cluster = 0 (free)
   744                              <1> 	; increase free(d) cluster count
   745 0000AEEF FF05[AE280100]      <1> 	inc	dword [FAT_ClusterCounter]
   746                              <1> 
   747                              <1> loc_fat_buffer_updated_1: ; new value of the cluster > 0
   748 0000AEF5 09D2                <1> 	or	edx, edx ; 02/03/2016
   749 0000AEF7 7506                <1> 	jnz	short loc_fat_buffer_updated_2
   750                              <1> 	; old value of the cluster = 0 (it was free cluster)
   751                              <1> 	; decrease free(d) cluster count
   752 0000AEF9 FF0D[AE280100]      <1> 	dec	dword [FAT_ClusterCounter] ; it may be negative number
   753                              <1> 
   754                              <1> loc_fat_buffer_updated_2:
   755 0000AEFF 9D                  <1> 	popf
   756 0000AF00 C3                  <1> 	retn
   757                              <1> 
   758                              <1> loc_uc_save_fat_buffer:
   759                              <1> 	; byte [FAT_BuffValidData] = 2 
   760 0000AF01 E8D4010000          <1> 	call	save_fat_buffer
   761 0000AF06 0F8297010000        <1>         jc      loc_fat_sectors_rw_error2
   762                              <1> 	;mov	byte [FAT_BuffValidData], 1
   763 0000AF0C A1[A2280100]        <1> 	mov	eax, [FAT_CurrentCluster]
   764                              <1> 	;mov	ecx, [ClusterValue]
   765                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
   766 0000AF11 8A1E                <1> 	mov	bl, [esi+LD_Name] ; 01/03/2016
   767 0000AF13 E927FFFFFF          <1>         jmp     loc_uc_reset_fat_buffer_validation
   768                              <1> 
   769                              <1> update_cluster_inv_data:
   770                              <1> 	;mov	eax, 0Dh
   771 0000AF18 B00D                <1> 	mov	al, 0Dh  ; Invalid Data
   772 0000AF1A C3                  <1> 	retn 
   773                              <1> 
   774                              <1> return_uc_fat_stc:
   775                              <1> 	; 01/03/2016
   776 0000AF1B 31C0                <1> 	xor	eax, eax
   777 0000AF1D F9                  <1> 	stc
   778 0000AF1E EBCA                <1> 	jmp	short loc_fat_buffer_stc_1
   779                              <1> 
   780                              <1> update_fat12_cluster:
   781                              <1> pass_uc_fat12_errc:
   782                              <1> 	;sub	edx, edx
   783 0000AF20 BB00040000          <1> 	mov	ebx, 400h ;1024
   784 0000AF25 F7F3                <1> 	div	ebx
   785                              <1> 	; EAX = Count of 3 FAT sectors
   786                              <1> 	; DX = Cluster offset in FAT buffer
   787 0000AF27 66B90300            <1> 	mov	cx, 3
   788 0000AF2B 6689C3              <1> 	mov	bx, ax
   789 0000AF2E 6689C8              <1> 	mov	ax, cx ; 3
   790 0000AF31 66F7E2              <1> 	mul	dx     ; Multiply by 3
   791 0000AF34 66D1E8              <1> 	shr	ax, 1  ; Divide by 2
   792 0000AF37 6693                <1> 	xchg	bx, ax
   793                              <1> 	; EAX = Count of 3 FAT sectors
   794                              <1> 	; EBX = Byte Offset in FAT buffer   
   795 0000AF39 66F7E1              <1> 	mul	cx  ; 3 * AX
   796                              <1> 	; EAX = FAT Beginning Sector
   797                              <1> 	; EDX = 0
   798 0000AF3C 8A0D[A6280100]      <1> 	mov	cl, [FAT_BuffValidData]
   799                              <1> 	; TRDOS v1 has a FATal bug here ! 
   800                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
   801                              <1> 	;  while 'jne' is existing !)
   802 0000AF42 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
   803 0000AF45 750A                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
   804                              <1> 
   805                              <1> loc_uc_check_fat12_buff_sector_save:
   806 0000AF47 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   807 0000AF4D 75B2                <1>         jne     short loc_uc_save_fat_buffer
   808 0000AF4F EB15                <1> 	jmp	short loc_update_fat12_cell
   809                              <1> 
   810                              <1> loc_uc_check_fat12_buff_sector_load:
   811 0000AF51 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
   812 0000AF54 0F8550010000        <1>         jne     loc_uc_load_fat_sectors
   813 0000AF5A 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   814 0000AF60 0F8544010000        <1>         jne     loc_uc_load_fat_sectors
   815                              <1> 
   816                              <1> loc_update_fat12_cell:
   817 0000AF66 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   818 0000AF6C 668B0D[A2280100]    <1> 	mov	cx, [FAT_CurrentCluster]
   819 0000AF73 66D1E9              <1> 	shr	cx, 1
   820 0000AF76 668B03              <1> 	mov	ax, [ebx]
   821 0000AF79 6689C2              <1> 	mov	dx, ax
   822 0000AF7C 7344                <1> 	jnc	short uc_fat12_nc_even
   823                              <1> 
   824 0000AF7E 6683E00F            <1> 	and	ax, 0Fh
   825 0000AF82 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   826 0000AF88 66C1E104            <1> 	shl	cx, 4
   827 0000AF8C 6609C1              <1> 	or	cx, ax
   828 0000AF8F 6689D0              <1> 	mov	ax, dx
   829 0000AF92 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
   830 0000AF95 66C1E804            <1> 	shr	ax, 4 ; al(bit4..7)+ah(bit0..7)
   831                              <1> 
   832                              <1> update_fat12_buffer:
   833 0000AF99 A3[A2280100]        <1> 	mov	[FAT_CurrentCluster], eax
   834 0000AF9E 89C2                <1> 	mov	edx, eax ; 01/03/2016
   835 0000AFA0 C605[A6280100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   836 0000AFA7 6683F802            <1> 	cmp	ax, 2
   837 0000AFAB 0F826AFFFFFF        <1>         jb      return_uc_fat_stc
   838 0000AFB1 3B05[B2280100]      <1> 	cmp	eax, [LastCluster]
   839 0000AFB7 0F875EFFFFFF        <1>         ja      return_uc_fat_stc
   840 0000AFBD E927FFFFFF          <1>         jmp     loc_fat_buffer_updated
   841                              <1> 
   842                              <1> uc_fat12_nc_even:
   843 0000AFC2 662500F0            <1> 	and	ax, 0F000h
   844 0000AFC6 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   845 0000AFCC 80E50F              <1> 	and	ch, 0Fh
   846 0000AFCF 6609C1              <1> 	or	cx, ax
   847 0000AFD2 6689D0              <1> 	mov	ax, dx
   848 0000AFD5 66890B              <1> 	mov	[ebx], cx ; 16 bits !
   849 0000AFD8 80E40F              <1> 	and	ah, 0Fh ; al(bit0..7)+ah(bit0..3)
   850 0000AFDB EBBC                <1> 	jmp	short update_fat12_buffer
   851                              <1> 
   852                              <1> update_fat32_cluster:
   853 0000AFDD 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
   854 0000AFE0 41                  <1> 	inc	ecx
   855 0000AFE1 890D[B2280100]      <1> 	mov	[LastCluster], ecx
   856                              <1> 
   857 0000AFE7 39C8                <1> 	cmp	eax, ecx
   858 0000AFE9 0F872CFFFFFF        <1>         ja      return_uc_fat_stc
   859                              <1> 
   860                              <1> pass_uc_fat32_errc:
   861                              <1> 	;sub	edx, edx
   862 0000AFEF BB80010000          <1> 	mov	ebx, 180h ;384
   863 0000AFF4 F7F3                <1> 	div	ebx
   864                              <1> 	; EAX = Count of 3 FAT sectors
   865                              <1> 	; DX = Cluster offset in FAT buffer
   866 0000AFF6 89D3                <1> 	mov	ebx, edx
   867 0000AFF8 C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
   868 0000AFFB BA03000000          <1> 	mov	edx, 3	
   869 0000B000 F7E2                <1> 	mul	edx
   870                              <1> 	; EBX = Cluster Offset in FAT buffer
   871                              <1> 	; EAX = FAT Sector
   872                              <1> 	; EDX = 0
   873 0000B002 8A0D[A6280100]      <1> 	mov	cl, [FAT_BuffValidData]
   874 0000B008 80F902              <1> 	cmp	cl, 2
   875 0000B00B 750E                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
   876                              <1> 
   877                              <1> loc_uc_check_fat32_buff_sector_save:
   878 0000B00D 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   879 0000B013 0F85E8FEFFFF        <1>         jne     loc_uc_save_fat_buffer
   880 0000B019 EB11                <1> 	jmp	short loc_update_fat32_cell
   881                              <1> 
   882                              <1> loc_uc_check_fat32_buff_sector_load:
   883 0000B01B 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
   884 0000B01E 0F8586000000        <1>         jne     loc_uc_load_fat_sectors
   885 0000B024 3B05[AA280100]      <1> 	cmp	eax, [FAT_BuffSector]
   886 0000B02A 757E                <1>         jne     loc_uc_load_fat_sectors
   887                              <1> 
   888                              <1> loc_update_fat32_cell:
   889                              <1> loc_update_fat32_buffer:
   890 0000B02C 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   891 0000B032 8B03                <1> 	mov	eax, [ebx]
   892 0000B034 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
   893                              <1> 	
   894 0000B039 8B15[A2280100]      <1> 	mov	edx, [FAT_CurrentCluster] ; 01/03/2016
   895                              <1> 
   896 0000B03F A3[A2280100]        <1> 	mov 	[FAT_CurrentCluster], eax
   897 0000B044 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue]
   898 0000B04A 890B                <1> 	mov	[ebx], ecx ; 29/02/2016 
   899                              <1> 
   900 0000B04C C605[A6280100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   901                              <1> 
   902                              <1> 	; 01/03/2016
   903 0000B053 21C0                <1> 	and	eax, eax ; was it free cluster ?
   904 0000B055 7514                <1> 	jnz	short loc_upd_fat32_c0
   905                              <1> 
   906                              <1> 	;or	ecx, ecx ; it will be left free ?!
   907                              <1> 	;jz	short loc_upd_fat32_c3
   908                              <1> 
   909 0000B057 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
   910 0000B05A 7520                <1> 	jne	short loc_upd_fat32_c3
   911                              <1> 
   912 0000B05C 3B15[B2280100]      <1> 	cmp	edx, [LastCluster]
   913 0000B062 7207                <1> 	jb	short loc_upd_fat32_c0
   914                              <1> 
   915 0000B064 BA02000000          <1> 	mov	edx, 2 ; rewind !
   916 0000B069 EB0E                <1> 	jmp	short loc_upd_fat32_c2
   917                              <1> 
   918                              <1> loc_upd_fat32_c0:
   919 0000B06B FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set it to next cluster		
   920 0000B06E EB0C                <1> 	jmp	short loc_upd_fat32_c3
   921                              <1> 
   922                              <1> loc_upd_fat32_c1:
   923 0000B070 09C9                <1> 	or	ecx, ecx ; will it be free cluster ?
   924 0000B072 7508                <1> 	jnz	short loc_upd_fat32_c3
   925                              <1> 
   926 0000B074 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
   927 0000B077 7303                <1> 	jnb	short loc_upd_fat32_c3
   928                              <1> 
   929                              <1> loc_upd_fat32_c2:	
   930 0000B079 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx			
   931                              <1> 
   932                              <1> loc_upd_fat32_c3:
   933 0000B07C 89C2                <1> 	mov	edx, eax
   934                              <1> 
   935                              <1> loc_upd_fat32_c4:
   936 0000B07E 83F802              <1> 	cmp	eax, 2
   937 0000B081 0F8294FEFFFF        <1>         jb      return_uc_fat_stc
   938                              <1> 
   939                              <1> pass_uc_fat32_c_zero_check_2:
   940 0000B087 3B05[B2280100]      <1> 	cmp	eax, [LastCluster]
   941 0000B08D 0F8788FEFFFF        <1>         ja      return_uc_fat_stc
   942                              <1> 	
   943 0000B093 E951FEFFFF          <1> 	jmp     loc_fat_buffer_updated
   944                              <1> 
   945                              <1> loc_fat_sectors_rw_error1:
   946                              <1> 	;mov	byte [FAT_BuffValidData], 0
   947                              <1> 	; 23/03/2016
   948 0000B098 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
   949 0000B09D 8825[A6280100]      <1> 	mov	[FAT_BuffValidData], ah ; 0
   950                              <1> 
   951                              <1> loc_fat_sectors_rw_error2:
   952                              <1> 	;mov	eax, error code
   953                              <1> 	;mov	edx, 0
   954 0000B0A3 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue]
   955 0000B0A9 C3                  <1> 	retn
   956                              <1> 
   957                              <1> loc_uc_load_fat_sectors:
   958 0000B0AA A3[AA280100]        <1> 	mov	[FAT_BuffSector], eax
   959                              <1> 
   960                              <1> load_uc_fat_sectors_zero:
   961 0000B0AF 034660              <1> 	add	eax, [esi+LD_FATBegin]
   962 0000B0B2 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   963 0000B0B7 B903000000          <1> 	mov	ecx, 3
   964 0000B0BC E85B290000          <1> 	call	disk_read
   965 0000B0C1 72D5                <1> 	jc	short loc_fat_sectors_rw_error1
   966                              <1> 
   967 0000B0C3 C605[A6280100]01    <1>         mov     byte [FAT_BuffValidData], 1
   968 0000B0CA A1[A2280100]        <1> 	mov 	eax, [FAT_CurrentCluster]
   969 0000B0CF 8B0D[442B0100]      <1> 	mov	ecx, [ClusterValue]
   970 0000B0D5 E972FDFFFF          <1>         jmp     loc_update_cluster_check_fat_type
   971                              <1> 
   972                              <1> save_fat_buffer:
   973                              <1> 	; 01/03/2016
   974                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
   975                              <1> 	; 11/08/2011
   976                              <1> 	; 09/02/2005 
   977                              <1> 	; INPUT ->
   978                              <1> 	;	None
   979                              <1> 	; OUTPUT ->
   980                              <1> 	;	cf = 0 -> OK.
   981                              <1> 	;	cf = 1 -> error code in AL (EAX)
   982                              <1> 	;
   983                              <1> 	;	EBX = FAT_Buffer address
   984                              <1> 	;
   985                              <1> 	; (EAX, EDX, ECX will be modified)
   986                              <1> 
   987                              <1> 	;cmp	byte [FAT_BuffValidData], 2 
   988                              <1> 	;je	short loc_save_fat_buff
   989                              <1> 
   990                              <1> ;loc_save_fat_buffer_retn:
   991                              <1> ;	xor	eax, eax
   992                              <1> ;	retn
   993                              <1> 
   994                              <1> loc_save_fat_buff:
   995 0000B0DA 31D2                <1> 	xor	edx, edx
   996 0000B0DC 8A35[A7280100]      <1> 	mov	dh, [FAT_BuffDrvName]
   997 0000B0E2 80FE41              <1> 	cmp	dh, 'A'
   998 0000B0E5 722E                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
   999 0000B0E7 80EE41              <1> 	sub	dh, 'A'
  1000 0000B0EA 56                  <1> 	push	esi ; *
  1001 0000B0EB BE00010900          <1>         mov     esi, Logical_DOSDisks
  1002 0000B0F0 01D6                <1> 	add	esi, edx
  1003                              <1> 	
  1004 0000B0F2 8A5603              <1> 	mov	dl, [esi+LD_FATType]
  1005 0000B0F5 20D2                <1> 	and	dl, dl
  1006 0000B0F7 741B                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn 
  1007                              <1> 
  1008 0000B0F9 A1[AA280100]        <1> 	mov	eax, [FAT_BuffSector]
  1009 0000B0FE 80FA02              <1> 	cmp	dl, 2
  1010 0000B101 770A                <1> 	ja	short loc_save_fat32_buff
  1011                              <1> 
  1012                              <1> loc_save_fat_12_16_buff:
  1013                              <1> 	; 01/03/2016
  1014                              <1> 	; TRDOS v1 has a FATal bug here!
  1015                              <1> 	; Correct code: mov dx, word ptr [FAT_BuffSector]+2
  1016                              <1> 	; (DX:AX in TRDOS v1 -> EAX in TRDOS v2)
  1017                              <1> 	;
  1018 0000B103 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs] 
  1019 0000B107 29C1                <1> 	sub	ecx, eax
  1020                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
  1021                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
  1022 0000B109 7609                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
  1023 0000B10B EB15                <1> 	jmp	short loc_save_fat_buffer_check_rs3
  1024                              <1> 
  1025                              <1> loc_save_fat32_buff:
  1026 0000B10D 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
  1027 0000B110 29C1                <1> 	sub	ecx, eax
  1028 0000B112 770E                <1> 	ja	short loc_save_fat_buffer_check_rs3
  1029                              <1> 
  1030                              <1> loc_save_fat_buffer_inv_data_pop_retn:
  1031 0000B114 5E                  <1> 	pop	esi ; *
  1032                              <1> loc_save_fat_buffer_inv_data_retn:
  1033 0000B115 B80D000000          <1> 	mov	eax, 0Dh ; Invalid DATA
  1034 0000B11A C3                  <1> 	retn
  1035                              <1> 
  1036                              <1> loc_save_fat_buff_remain_sectors_3:
  1037 0000B11B B903000000          <1> 	mov	ecx, 3
  1038 0000B120 EB05                <1> 	jmp	short loc_save_fat_buff_continue
  1039                              <1> 
  1040                              <1> loc_save_fat_buffer_check_rs3:
  1041 0000B122 83F903              <1> 	cmp	ecx, 3
  1042 0000B125 77F4                <1> 	ja	short loc_save_fat_buff_remain_sectors_3
  1043                              <1> 
  1044                              <1> loc_save_fat_buff_continue:
  1045 0000B127 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1046 0000B12C 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1047 0000B12F 51                  <1> 	push	ecx
  1048 0000B130 E8D8280000          <1> 	call	disk_write
  1049 0000B135 59                  <1> 	pop	ecx
  1050 0000B136 722B                <1> 	jc	short loc_save_FAT_buff_write_err
  1051                              <1> 	
  1052 0000B138 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1053 0000B13C 7605                <1> 	jna	short loc_calc_2nd_fat12_16_addr
  1054                              <1> 
  1055                              <1> loc_calc_2nd_fat32_addr:
  1056 0000B13E 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
  1057 0000B141 EB04                <1> 	jmp	short loc_calc_2nd_fat_addr
  1058                              <1> 
  1059                              <1> loc_calc_2nd_fat12_16_addr:
  1060 0000B143 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
  1061                              <1> 
  1062                              <1> loc_calc_2nd_fat_addr:
  1063 0000B147 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1064 0000B14A 0305[AA280100]      <1> 	add	eax, [FAT_BuffSector]
  1065 0000B150 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1066                              <1> 	; ecx = 1 to 3
  1067 0000B155 E8B3280000          <1> 	call	disk_write
  1068 0000B15A 7207                <1> 	jc	short loc_save_FAT_buff_write_err
  1069                              <1>  	; Valid  buffer (1 = valid but do not save)
  1070 0000B15C C605[A6280100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1071                              <1> 
  1072                              <1> loc_save_FAT_buff_write_err:
  1073 0000B163 5E                  <1> 	pop	esi ; *
  1074 0000B164 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1075                              <1> 	; 23/03/2016
  1076 0000B169 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
  1077 0000B16E C3                  <1> 	retn
  1078                              <1> 
  1079                              <1> calculate_fat_freespace:
  1080                              <1> 	; 23/03/2016
  1081                              <1> 	; 02/03/2016
  1082                              <1> 	; 01/03/2016
  1083                              <1> 	; 29/02/2016
  1084                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1085                              <1> 	; 30/04/2011
  1086                              <1> 	; 03/04/2010
  1087                              <1> 	; 2005
  1088                              <1> 	; INPUT ->
  1089                              <1> 	;	EAX = Cluster count to be added or subtracted
  1090                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
  1091                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
  1092                              <1> 	; 	BL: 
  1093                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
  1094                              <1> 	; OUTPUT ->
  1095                              <1> 	;	EAX = Free Space in sectors
  1096                              <1> 	;	ESI = Logical Dos Drive Description Table address
  1097                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
  1098                              <1> 	;	BL = Type of operation (same with input value of BL)
  1099                              <1> 	;	ECX = 0 -> valid
  1100                              <1> 	;	ECX > 0 -> error or invalid
  1101                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
  1102                              <1> 	;			          sign due to r/w error   
  1103                              <1> 
  1104 0000B16F 66891D[4A2B0100]    <1> 	mov	[CFS_OPType], bx
  1105 0000B176 A3[4C2B0100]        <1> 	mov	[CFS_CC], eax
  1106                              <1> 	
  1107 0000B17B 80FFFF              <1> 	cmp	bh, 0FFh
  1108 0000B17E 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
  1109                              <1> 
  1110                              <1> loc_calculate_freespace_get_drive_dt_offset:     
  1111 0000B180 31C0                <1> 	xor	eax, eax
  1112 0000B182 88FC                <1>         mov     ah, bh
  1113 0000B184 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1114 0000B189 01C6                <1>         add     esi, eax
  1115                              <1> 
  1116                              <1> pass_calculate_freespace_get_drive_dt_offset:
  1117 0000B18B 08DB                <1> 	or	bl, bl
  1118 0000B18D 7435                <1> 	jz	short loc_reset_fcc
  1119                              <1> 	
  1120                              <1> loc_get_free_sectors:
  1121 0000B18F 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1122                              <1> 
  1123                              <1> 	;xor	ecx, ecx
  1124                              <1> 	;dec	ecx ; 0FFFFFFFFh
  1125                              <1> 	;cmp	eax, ecx ; 29/02/2016
  1126                              <1> 	;je	short loc_get_free_sectors_retn ; recalculation is needed!
  1127                              <1> 	
  1128                              <1> 	; 23/03/2016
  1129 0000B192 8B4E70              <1> 	mov	ecx, [esi+LD_TotalSectors]
  1130 0000B195 39C1                <1> 	cmp	ecx, eax ; Total sectors must be greater than Free sectors !
  1131 0000B197 7707                <1> 	ja	short loc_get_free_sectors_check_optype
  1132                              <1> 	
  1133 0000B199 31C0                <1> 	xor	eax, eax
  1134 0000B19B 48                  <1> 	dec	eax ; 0FFFFFFFFh  ; recalculation is needed!
  1135 0000B19C 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; reset (for recalculation)
  1136                              <1> 		
  1137                              <1> loc_get_free_sectors_retn:
  1138 0000B19F C3                  <1> 	retn
  1139                              <1> 	
  1140                              <1> loc_get_free_sectors_check_optype:
  1141 0000B1A0 80FB03              <1> 	cmp	bl, 3
  1142 0000B1A3 7203                <1> 	jb	short loc_set_fcc
  1143                              <1> 
  1144 0000B1A5 29C9                <1> 	sub	ecx, ecx ; 0
  1145                              <1> 
  1146 0000B1A7 C3                  <1> 	retn	
  1147                              <1> 
  1148                              <1> loc_set_fcc:
  1149 0000B1A8 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1150 0000B1AC 0F87DF000000        <1>         ja      loc_update_FAT32_fs_info_fcc
  1151                              <1> 
  1152                              <1> 	;mov	eax, [esi+LD_FreeSectors]
  1153 0000B1B2 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  1154 0000B1B6 29D2                <1> 	sub	edx, edx
  1155 0000B1B8 F7F1                <1> 	div	ecx
  1156                              <1> 	;or	dx, dx 
  1157                              <1> 	;	; DX -> Remain sectors < SecPerClust
  1158                              <1> 	;	; DX > 0 -> invalid free sector count
  1159                              <1> 	;jnz	short loc_reset_fcc 
  1160                              <1> 
  1161                              <1> ;pass_set_fcc_div32:
  1162 0000B1BA A3[C3280100]        <1> 	mov	[FreeClusterCount], eax
  1163 0000B1BF E988000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
  1164                              <1> 
  1165                              <1> loc_reset_fcc:
  1166 0000B1C4 31C0                <1> 	xor	eax, eax
  1167 0000B1C6 A3[C3280100]        <1> 	mov	[FreeClusterCount], eax ; 0
  1168 0000B1CB 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
  1169 0000B1CE 42                  <1> 	inc	edx
  1170 0000B1CF 8915[B2280100]      <1> 	mov	[LastCluster], edx
  1171                              <1> 
  1172 0000B1D5 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1173 0000B1D9 7647                <1> 	jna	short loc_count_free_fat_clusters_0  
  1174                              <1> 
  1175 0000B1DB 48                  <1> 	dec	eax ; FFFFFFFFh
  1176 0000B1DC A3[542B0100]        <1> 	mov	[CFS_FAT32FC], eax
  1177                              <1> 
  1178                              <1> 	; 29/02/2016
  1179 0000B1E1 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
  1180 0000B1E4 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
  1181                              <1> 	
  1182 0000B1E7 B802000000          <1> 	mov 	eax, 2
  1183                              <1> 
  1184                              <1> loc_count_fc_next_cluster_0:
  1185 0000B1EC 50                  <1> 	push	eax
  1186 0000B1ED E801F9FFFF          <1> 	call	get_next_cluster
  1187 0000B1F2 7310                <1> 	jnc	short loc_check_fat32_ff_cluster
  1188 0000B1F4 09C0                <1> 	or	eax, eax
  1189 0000B1F6 741E                <1> 	jz	short pass_inc_cfs_fcc_0
  1190                              <1> 
  1191                              <1> loc_put_fcc_unknown_sign:
  1192 0000B1F8 58                  <1> 	pop	eax
  1193                              <1> 	; "Free count is Unknown" sign
  1194                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
  1195                              <1> 
  1196                              <1> 	; 29/02/2016
  1197                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
  1198                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
  1199 0000B1F9 8B15[542B0100]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
  1200                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
  1201 0000B1FF 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
  1202                              <1> 	
  1203 0000B202 EB7D                <1>         jmp     loc_put_fcc_invalid_sign
  1204                              <1> 
  1205                              <1> loc_check_fat32_ff_cluster:
  1206 0000B204 09C0                <1> 	or	eax, eax
  1207 0000B206 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
  1208 0000B208 58                  <1> 	pop	eax
  1209 0000B209 A3[542B0100]        <1> 	mov	[CFS_FAT32FC], eax
  1210                              <1> 	;mov	dword [FreeClusterCount], 1
  1211 0000B20E FF05[C3280100]      <1> 	inc	dword [FreeClusterCount]
  1212 0000B214 EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
  1213                              <1> 
  1214                              <1> pass_inc_cfs_fcc_0:
  1215 0000B216 58                  <1> 	pop	eax
  1216                              <1> 
  1217                              <1> pass_inc_cfs_fcc_0c:
  1218 0000B217 40                  <1> 	inc	eax ; add eax, 1
  1219 0000B218 3B05[B2280100]      <1> 	cmp	eax, [LastCluster]
  1220 0000B21E 76CC                <1> 	jna 	short loc_count_fc_next_cluster_0
  1221 0000B220 EB6F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
  1222                              <1> 
  1223                              <1> loc_count_free_fat_clusters_0:
  1224                              <1> 	;mov	eax, 2
  1225 0000B222 B002                <1> 	mov	al, 2
  1226                              <1> 
  1227                              <1> loc_count_fc_next_cluster:
  1228 0000B224 50                  <1> 	push	eax
  1229 0000B225 E8C9F8FFFF          <1> 	call	get_next_cluster
  1230 0000B22A 720C                <1> 	jc	short loc_count_fcc_stc
  1231                              <1> 
  1232                              <1> loc_count_free_clusters_1:
  1233 0000B22C 21C0                <1> 	and	eax, eax
  1234 0000B22E 750C                <1> 	jnz	short pass_inc_cfs_fcc
  1235                              <1> 
  1236 0000B230 FF05[C3280100]      <1> 	inc	dword [FreeClusterCount]
  1237 0000B236 EB04                <1> 	jmp	short pass_inc_cfs_fcc
  1238                              <1> 
  1239                              <1> loc_count_fcc_stc:
  1240 0000B238 09C0                <1> 	or	eax, eax
  1241 0000B23A 75BC                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
  1242                              <1> 
  1243                              <1> pass_inc_cfs_fcc:
  1244 0000B23C 58                  <1> 	pop	eax
  1245                              <1> 
  1246                              <1> pass_inc_cfs_fcc_1:
  1247 0000B23D 40                  <1> 	inc	eax ; add eax, 1
  1248 0000B23E 3B05[B2280100]      <1> 	cmp	eax, [LastCluster]
  1249 0000B244 76DE                <1> 	jna	short loc_count_fc_next_cluster
  1250                              <1> 
  1251                              <1> loc_set_free_sectors:
  1252 0000B246 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1253 0000B24A 7745                <1> 	ja	short loc_update_FAT32_fs_info_fcc
  1254                              <1> 
  1255                              <1> loc_set_free_sectors_FAT12_FAT16:
  1256 0000B24C 803D[4A2B0100]00    <1> 	cmp	byte [CFS_OPType], 0
  1257 0000B253 761C                <1> 	jna	short pass_FAT_add_sub_fcc
  1258 0000B255 A1[4C2B0100]        <1> 	mov	eax, [CFS_CC]
  1259 0000B25A 803D[4A2B0100]01    <1> 	cmp	byte [CFS_OPType], 1
  1260 0000B261 7708                <1> 	ja	short pass_FAT_add_fcc
  1261 0000B263 0105[C3280100]      <1> 	add 	[FreeClusterCount], eax
  1262 0000B269 EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
  1263                              <1> 
  1264                              <1> pass_FAT_add_fcc:
  1265 0000B26B 2905[C3280100]      <1> 	sub	[FreeClusterCount], eax
  1266                              <1> 
  1267                              <1> pass_FAT_add_sub_fcc:
  1268 0000B271 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1269 0000B275 8B15[C3280100]      <1> 	mov	edx, [FreeClusterCount]
  1270 0000B27B F7E2                <1> 	mul	edx
  1271                              <1> 
  1272 0000B27D 31C9                <1> 	xor	ecx, ecx 
  1273 0000B27F EB05                <1> 	jmp	short loc_cfs_retn_params
  1274                              <1> 
  1275                              <1> loc_put_fcc_invalid_sign:
  1276 0000B281 29C0                <1>        	sub	eax, eax ; 0
  1277 0000B283 48                  <1> 	dec	eax ; FFFFFFFFh
  1278                              <1> loc_fat32_ffc_recalc_needed:
  1279 0000B284 89C1                <1> 	mov	ecx, eax
  1280                              <1> 
  1281                              <1> loc_cfs_retn_params:
  1282 0000B286 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
  1283 0000B289 0FB71D[4A2B0100]    <1> 	movzx	ebx, word [CFS_OPType]
  1284 0000B290 C3                  <1> 	retn
  1285                              <1> 
  1286                              <1> loc_update_FAT32_fs_info_fcc:
  1287                              <1> loc_check_fcc_FSINFO_op:
  1288                              <1> 	; 29/02/2016
  1289                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
  1290                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
  1291 0000B291 803D[4A2B0100]01    <1> 	cmp	byte [CFS_OPType], 1
  1292 0000B298 7221                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
  1293 0000B29A 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
  1294                              <1> loc_check_fcc_FSINFO_op2: ; subtract
  1295 0000B29C F71D[4C2B0100]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
  1296                              <1> loc_check_fcc_FSINFO_op1:
  1297                              <1> 	; 01/03/2016
  1298 0000B2A2 31D2                <1> 	xor	edx, edx ; 0
  1299 0000B2A4 4A                  <1> 	dec	edx ; 0FFFFFFFFh
  1300 0000B2A5 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved]
  1301 0000B2A8 39D0                <1> 	cmp	eax, edx
  1302 0000B2AA 73D5                <1> 	jnb	short loc_put_fcc_invalid_sign
  1303 0000B2AC 0305[4C2B0100]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
  1304 0000B2B2 72CD                <1> 	jc	short loc_put_fcc_invalid_sign
  1305                              <1> 	
  1306 0000B2B4 A3[C3280100]        <1> 	mov	[FreeClusterCount], eax
  1307 0000B2B9 EB0E                <1> 	jmp	short loc_cfs_write_FSINFO_sector
  1308                              <1> 
  1309                              <1> loc_cfs_FAT32_get_rcalc_parms:
  1310 0000B2BB 8B15[542B0100]      <1> 	mov	edx, [CFS_FAT32FC]
  1311 0000B2C1 A1[C3280100]        <1> 	mov	eax, [FreeClusterCount]
  1312 0000B2C6 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
  1313                              <1> loc_cfs_write_FSINFO_sector:
  1314 0000B2C9 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
  1315                              <1> 	; 01/03/2016
  1316 0000B2CC E89A000000          <1> 	call	set_fat32_fsinfo_sector_parms
  1317 0000B2D1 72AE                <1>         jc      short loc_put_fcc_invalid_sign
  1318                              <1> 
  1319                              <1> loc_set_FAT32_free_sectors:
  1320                              <1> 	; 29/02/2016
  1321                              <1> 	;mov	eax, [FreeClusterCount]
  1322                              <1> 	;mov	ecx, eax
  1323                              <1> 	;cmp	eax, 0FFFFFFFFh ; Invalid !
  1324                              <1> 	;je	short loc_cfs_retn_params
  1325                              <1> 	;
  1326 0000B2D3 8B0D[C3280100]      <1> 	mov	ecx, [FreeClusterCount]
  1327 0000B2D9 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1328 0000B2DD F7E1                <1> 	mul	ecx
  1329                              <1> 	; 29/02/2016
  1330 0000B2DF 31C9                <1> 	xor	ecx, ecx ; 0
  1331 0000B2E1 09D2                <1> 	or	edx, edx ; 0 ?
  1332 0000B2E3 759C                <1>         jnz     loc_put_fcc_invalid_sign
  1333 0000B2E5 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
  1334 0000B2E8 7697                <1>         jna     short loc_put_fcc_invalid_sign
  1335                              <1> 	;
  1336                              <1> loc_set_FAT32_free_sectors_ok:
  1337 0000B2EA 31D2                <1> 	xor	edx, edx ; 0
  1338 0000B2EC EB98                <1>         jmp     short loc_cfs_retn_params 
  1339                              <1> 	;
  1340                              <1> 
  1341                              <1> get_last_cluster:
  1342                              <1> 	; 27/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1343                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
  1344                              <1> 	; 06/06/2010
  1345                              <1> 	; INPUT ->
  1346                              <1> 	;	EAX = First Cluster Number
  1347                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
  1348                              <1> 	; OUTPUT ->
  1349                              <1> 	;	cf = 0 -> No Error, EAX is valid
  1350                              <1> 	;	cf = 1 -> EAX > 0 -> Error
  1351                              <1> 	;	EAX = Last Cluster Number
  1352                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
  1353                              <1> 	;
  1354                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  1355                              <1> 
  1356 0000B2EE 89C1                <1> 	mov	ecx, eax	
  1357                              <1> 
  1358                              <1> loc_glc_get_next_cluster_1:
  1359 0000B2F0 890D[582B0100]      <1> 	mov	[glc_prevcluster], ecx
  1360                              <1> 
  1361                              <1> loc_glc_get_next_cluster_2:
  1362 0000B2F6 E8F8F7FFFF          <1> 	call	get_next_cluster
  1363                              <1> 	; ecx = current/previous cluster 
  1364                              <1> 	; eax = next/last cluster
  1365 0000B2FB 73F3                <1> 	jnc	short loc_glc_get_next_cluster_1
  1366                              <1> 
  1367 0000B2FD 09C0                <1> 	or	eax, eax
  1368 0000B2FF 7509                <1> 	jnz	short loc_glc_stc_retn
  1369                              <1> 
  1370                              <1> 	; ecx = previous cluster
  1371 0000B301 89C8                <1>         mov	eax, ecx
  1372                              <1> 
  1373                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
  1374                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
  1375                              <1> 
  1376                              <1> loc_glc_prev_cluster_retn:
  1377 0000B303 8B0D[582B0100]      <1> 	mov	ecx, [glc_prevcluster] 
  1378 0000B309 C3                  <1> 	retn
  1379                              <1> 
  1380                              <1> loc_glc_stc_retn:
  1381 0000B30A F5                  <1> 	cmc	;stc
  1382 0000B30B EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
  1383                              <1> 
  1384                              <1> truncate_cluster_chain:
  1385                              <1> 	; 01/03/2016
  1386                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1387                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
  1388                              <1> 	; 11/09/2010
  1389                              <1> 	; INPUT ->
  1390                              <1> 	;	ESI = Logical dos drive description table address
  1391                              <1> 	;	EAX = First cluster to be truncated/unlinked 
  1392                              <1> 	; OUTPUT ->
  1393                              <1> 	;	ESI = Logical dos drive description table address
  1394                              <1> 	; 	ECX = Count of truncated/removed clusters
  1395                              <1> 	; 	CF = 0 -> EAX = Free sectors
  1396                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1397                              <1> 
  1398                              <1> 	; NOTE: This procedure does not update lm date&time ! 
  1399                              <1> 
  1400                              <1> loc_truncate_cc:	
  1401 0000B30D 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
  1402                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1403 0000B30F 890D[AE280100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  1404                              <1> 
  1405                              <1> loc_tcc_unlink_clusters:
  1406 0000B315 E803FBFFFF          <1> 	call	update_cluster
  1407                              <1> 	; EAX = Next Cluster
  1408                              <1> 	; ECX = Cluster Value
  1409                              <1> 	; Note:
  1410                              <1> 	; Returns count of unlinked clusters in
  1411                              <1> 	; dword ptr FAT_ClusterCounter
  1412 0000B31A 73F9                <1> 	jnc short loc_tcc_unlink_clusters
  1413                              <1> 
  1414                              <1> pass_tcc_unlink_clusters:
  1415 0000B31C A2[5F2B0100]        <1> 	mov	byte [TCC_FATErr], al
  1416 0000B321 803D[A6280100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  1417 0000B328 750E                <1> 	jne	short loc_tcc_calculate_FAT_freespace
  1418 0000B32A E8ABFDFFFF          <1> 	call	save_fat_buffer
  1419 0000B32F 7307                <1> 	jnc	short loc_tcc_calculate_FAT_freespace
  1420 0000B331 A2[5F2B0100]        <1> 	mov	byte [TCC_FATErr], al ; Error
  1421                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1422                              <1> 
  1423                              <1> 	; 01/03/2016
  1424 0000B336 EB12                <1> 	jmp	short loc_tcc_recalculate_FAT_freespace
  1425                              <1> 
  1426                              <1> loc_tcc_calculate_FAT_freespace:
  1427 0000B338 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter] ; signed (+-) number
  1428 0000B33D 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
  1429                              <1> 			   ; BL = 1 -> add cluster
  1430 0000B341 E829FEFFFF          <1> 	call	calculate_fat_freespace
  1431 0000B346 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  1432 0000B348 7409                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
  1433                              <1> 
  1434                              <1> loc_tcc_recalculate_FAT_freespace:
  1435 0000B34A 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate !
  1436 0000B34E E81CFEFFFF          <1> 	call	calculate_fat_freespace
  1437                              <1>               
  1438                              <1> loc_tcc_calculate_FAT_freespace_err:
  1439                              <1> pass_truncate_cc_recalc_FAT_freespace:
  1440 0000B353 8B0D[AE280100]      <1> 	mov	ecx, [FAT_ClusterCounter]
  1441                              <1> 
  1442 0000B359 803D[5F2B0100]00    <1> 	cmp	byte [TCC_FATErr], 0
  1443 0000B360 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
  1444                              <1> 
  1445                              <1> loc_tcc_unlink_clusters_error:
  1446 0000B362 0FB605[5F2B0100]    <1> 	movzx	eax, byte [TCC_FATErr]
  1447 0000B369 F9                  <1> 	stc
  1448                              <1> loc_tcc_unlink_clusters_retn:
  1449 0000B36A C3                  <1> 	retn
  1450                              <1> 
  1451                              <1> set_fat32_fsinfo_sector_parms:
  1452                              <1> 	; 23/03/2016
  1453                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1454                              <1> 	; INPUT ->
  1455                              <1> 	;	ESI = Logical dos drive description table address
  1456                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
  1457                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First Free Cluster 
  1458                              <1> 	; OUTPUT ->
  1459                              <1> 	;	ESI = Logical dos drive description table address
  1460                              <1> 	; 	CF = 0 -> OK..
  1461                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1462                              <1> 	;
  1463                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1464                              <1> 
  1465 0000B36B E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
  1466 0000B370 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
  1467                              <1> 
  1468 0000B372 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
  1469 0000B375 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
  1470                              <1> 
  1471                              <1>         ;mov	ebx, DOSBootSectorBuff
  1472 0000B378 8983E8010000        <1> 	mov	[ebx+488], eax
  1473 0000B37E 8993EC010000        <1> 	mov	[ebx+492], edx	
  1474                              <1> 
  1475 0000B384 A1[502B0100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1476 0000B389 B901000000          <1> 	mov	ecx, 1
  1477 0000B38E E87A260000          <1> 	call	disk_write
  1478                              <1> 	;jnc     short update_fat32_fsinfo_sector_retn
  1479                              <1> 
  1480                              <1> 	; 23/03/2016
  1481                              <1> 	;mov	eax, 1Dh ; Drive not ready or write error
  1482                              <1> 
  1483                              <1> update_fat32_fsinfo_sector_retn:
  1484 0000B393 C3                  <1> 	retn
  1485                              <1> 
  1486                              <1> get_fat32_fsinfo_sector_parms:
  1487                              <1> 	; 23/03/2016
  1488                              <1> 	; 01/03/2016
  1489                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1490                              <1> 	; INPUT ->
  1491                              <1> 	;	ESI = Logical dos drive description table address
  1492                              <1> 	; OUTPUT ->
  1493                              <1> 	;	ESI = Logical dos drive description table address
  1494                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
  1495                              <1> 	;	CF = 0 -> OK..
  1496                              <1> 	;	   EAX = FsInfo sector address
  1497                              <1> 	;	   ECX = Free cluster count
  1498                              <1> 	;	   EDX = First free cluster 	
  1499                              <1> 	;	CF = 1 -> Error code in AL (EAX)
  1500                              <1> 	;	   EBX = 0
  1501                              <1> 	;	
  1502                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
  1503                              <1>         ;
  1504                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1505                              <1> 
  1506 0000B394 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
  1507 0000B398 03466C              <1> 	add	eax, [esi+LD_StartSector]
  1508 0000B39B A3[502B0100]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
  1509                              <1> 	
  1510 0000B3A0 BB[A2260100]        <1>         mov     ebx, DOSBootSectorBuff
  1511 0000B3A5 B901000000          <1> 	mov	ecx, 1
  1512 0000B3AA E86D260000          <1> 	call	disk_read
  1513 0000B3AF 7232                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
  1514                              <1> 
  1515 0000B3B1 BB[A2260100]        <1> 	mov	ebx, DOSBootSectorBuff
  1516                              <1> 
  1517 0000B3B6 813B52526141        <1> 	cmp	dword [ebx], 41615252h
  1518 0000B3BC 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1519                              <1> 
  1520 0000B3BE 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
  1520 0000B3C7 61                  <1>
  1521 0000B3C8 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1522                              <1> 
  1523 0000B3CA A1[502B0100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1524 0000B3CF 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
  1525 0000B3D5 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
  1526                              <1> 
  1527 0000B3DB C3                  <1> 	retn
  1528                              <1> 
  1529                              <1> loc_read_FAT32_fsinfo_sec_stc:
  1530 0000B3DC B80B000000          <1> 	mov	eax, 0Bh ; Invalid format!
  1531 0000B3E1 EB05                <1> 	jmp	short loc_read_FAT32_fsinfo_sec_stc_retn
  1532                              <1> 
  1533                              <1> loc_read_FAT32_fsinfo_sec_err:
  1534                              <1> 	; 23/03/2016
  1535 0000B3E3 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
  1536                              <1> 
  1537                              <1> loc_read_FAT32_fsinfo_sec_stc_retn:
  1538 0000B3E8 29DB                <1> 	sub	ebx, ebx ; 0
  1539 0000B3EA F9                  <1> 	stc
  1540 0000B3EB C3                  <1> 	retn
  1541                              <1> 
  1542                              <1> add_new_cluster:
  1543                              <1> 	; 16/05/2016
  1544                              <1> 	; 24/03/2016
  1545                              <1> 	; 18/03/2016
  1546                              <1> 	; 11/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1547                              <1> 	; 30/07/2011 (DRV_FAT.ASM)
  1548                              <1> 	; 11/09/2010
  1549                              <1> 	; INPUT ->
  1550                              <1> 	;	ESI = Logical dos drv desc. table address
  1551                              <1> 	;	EAX = Last cluster
  1552                              <1> 	; OUTPUT ->
  1553                              <1> 	;	ESI = Logical dos drv desc. table address
  1554                              <1> 	;	EAX = New Last cluster (next cluster)
  1555                              <1> 	;	cf = 1 -> error code in EAX (AL)
  1556                              <1> 	;	cf = 1 -> DX = sectors per cluster
  1557                              <1> 	;	ECX = Free sectors
  1558                              <1> 	; NOTE:
  1559                              <1> 	; This procedure does not update lm date&time !
  1560                              <1> 	;
  1561                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, EDI)
  1562                              <1> 	;
  1563                              <1> 
  1564 0000B3EC A3[7C2C0100]        <1> 	mov	[FAT_anc_LCluster], eax
  1565                              <1> 	
  1566 0000B3F1 E854F9FFFF          <1> 	call	get_first_free_cluster
  1567 0000B3F6 720B                <1> 	jc	short loc_add_new_cluster_retn
  1568                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
  1569                              <1> 
  1570 0000B3F8 89C2                <1> 	mov	edx, eax
  1571                              <1> 
  1572 0000B3FA 42                  <1> 	inc	edx
  1573                              <1> 	;jnz	short loc_add_new_cluster_check_ffc_eax
  1574 0000B3FB 7516                <1> 	jnz	short loc_add_new_cluster_save_fcc
  1575                              <1> 
  1576                              <1> loc_add_new_cluster_no_disk_space_retn:
  1577 0000B3FD B827000000          <1> 	mov	eax, 27h ; MSDOS err => insufficient disk space
  1578                              <1> loc_add_new_cluster_stc_retn:
  1579 0000B402 F9                  <1> 	stc
  1580                              <1> loc_add_new_cluster_retn:
  1581 0000B403 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  1582 0000B407 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1583                              <1> 	;xor	edx, edx
  1584                              <1> 	;stc
  1585 0000B40A C3                  <1> 	retn
  1586                              <1> 
  1587                              <1> loc_anc_invalid_format_stc_retn:
  1588 0000B40B F9                  <1> 	stc
  1589                              <1> loc_add_new_cluster_invalid_format_retn:
  1590 0000B40C B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
  1591 0000B411 EBF0                <1> 	jmp	short loc_add_new_cluster_retn 
  1592                              <1> 
  1593                              <1> ;loc_add_new_cluster_check_ffc_eax:
  1594                              <1> ;	cmp	eax, 2
  1595                              <1> ;	jb	short loc_add_new_cluster_invalid_format_retn
  1596                              <1> 
  1597                              <1> loc_add_new_cluster_save_fcc:  
  1598 0000B413 A3[802C0100]        <1> 	mov	[FAT_anc_FFCluster], eax
  1599                              <1> 
  1600 0000B418 83E802              <1> 	sub	eax, 2
  1601 0000B41B 0FB65E13            <1>         movzx   ebx, byte [esi+LD_BPB+SecPerClust]
  1602 0000B41F F7E3                <1> 	mul	ebx
  1603 0000B421 09D2                <1> 	or	edx, edx
  1604 0000B423 75E6                <1> 	jnz	short loc_anc_invalid_format_stc_retn
  1605                              <1> 
  1606                              <1> loc_add_new_cluster_allocate_cluster:
  1607                              <1> 	; 18/03/2016
  1608 0000B425 92                  <1> 	xchg	edx, eax ; eax = 0
  1609                              <1> 	; 16/05/2016
  1610                              <1> 	;cmp	[ClusterBuffer_Valid], al ; 0
  1611                              <1> 	;jna	short loc_anc_clear_cluster_buffer
  1612                              <1> 	;; 'copy' command, 
  1613                              <1> 	;; writing destination file clust after reading source file clust
  1614                              <1> 	;mov	[ClusterBuffer_Valid], al ; 0 ; reset
  1615                              <1> 	;jmp	short loc_add_new_cluster_write_nc_to_disk
  1616                              <1> 
  1617                              <1> loc_anc_clear_cluster_buffer:
  1618                              <1> 	; 11/03/2016
  1619                              <1> 	; Clear buffer
  1620 0000B426 BF00000700          <1> 	mov	edi, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  1621 0000B42B 89D9                <1> 	mov	ecx, ebx ; sector count
  1622 0000B42D C1E107              <1> 	shl	ecx, 7 ; 1 sector = 512 bytes -> 128 double words
  1623                              <1> 	;xor	eax, eax ; 0
  1624 0000B430 F3AB                <1> 	rep	stosd
  1625                              <1> 
  1626                              <1> loc_add_new_cluster_write_nc_to_disk:
  1627                              <1> 	; 11/03/2016
  1628                              <1> 	;xchg	eax, edx ; edx = 0, eax = sector offset
  1629 0000B432 89D0                <1> 	mov	eax, edx
  1630 0000B434 034668              <1>         add     eax, [esi+LD_DATABegin]
  1631 0000B437 72D3                <1> 	jc	short loc_add_new_cluster_invalid_format_retn 
  1632                              <1> 		
  1633 0000B439 89D9                <1> 	mov	ecx, ebx ; ECX = sectors per cluster (<256)
  1634 0000B43B BB00000700          <1> 	mov	ebx, Cluster_Buffer
  1635 0000B440 E8C8250000          <1> 	call	disk_write
  1636 0000B445 7307                <1> 	jnc	short loc_add_new_cluster_update_fat_nlc
  1637                              <1> 	
  1638 0000B447 B81D000000          <1> 	mov	eax, 1Dh ; Write Error
  1639 0000B44C EBB4                <1> 	jmp	short loc_add_new_cluster_stc_retn
  1640                              <1> 
  1641                              <1> loc_add_new_cluster_update_fat_nlc:
  1642 0000B44E A1[802C0100]        <1> 	mov	eax, [FAT_anc_FFCluster]
  1643 0000B453 31C9                <1> 	xor	ecx, ecx
  1644 0000B455 890D[AE280100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  1645 0000B45B 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  1646 0000B45C E8BCF9FFFF          <1> 	call	update_cluster
  1647 0000B461 7304                <1> 	jnc	short loc_add_new_cluster_update_fat_plc
  1648 0000B463 09C0                <1> 	or	eax, eax ;EAX = 0 -> cluster value is 0 or eocc
  1649 0000B465 759B                <1> 	jnz	short loc_add_new_cluster_stc_retn
  1650                              <1> 
  1651                              <1> loc_add_new_cluster_update_fat_plc:
  1652 0000B467 A1[7C2C0100]        <1> 	mov	eax, [FAT_anc_LCluster]
  1653 0000B46C 8B0D[802C0100]      <1> 	mov	ecx, [FAT_anc_FFCluster]
  1654 0000B472 E8A6F9FFFF          <1> 	call	update_cluster
  1655 0000B477 7314                <1> 	jnc	short loc_add_new_cluster_save_fat_buffer
  1656 0000B479 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1657 0000B47B 7410                <1> 	jz	short loc_add_new_cluster_save_fat_buffer
  1658                              <1> 
  1659                              <1> loc_anc_save_fat_buffer_err_retn:
  1660                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
  1661                              <1> 	;jb	short loc_add_new_cluster_retn
  1662                              <1> 
  1663 0000B47D 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  1664                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  1665 0000B481 50                  <1> 	push	eax
  1666 0000B482 E8E8FCFFFF          <1> 	call	calculate_fat_freespace
  1667 0000B487 58                  <1> 	pop	eax
  1668 0000B488 E975FFFFFF          <1>         jmp     loc_add_new_cluster_stc_retn
  1669                              <1> 
  1670                              <1> loc_add_new_cluster_save_fat_buffer:
  1671                              <1> 	;cmp	byte [FAT_BuffValidData], 2
  1672                              <1> 	;jne	short loc_add_new_cluster_calc_FAT_freespace 
  1673                              <1> 	;Byte [FAT_BuffValidData] =  2 
  1674 0000B48D E848FCFFFF          <1> 	call	save_fat_buffer
  1675 0000B492 72E9                <1> 	jc	short loc_anc_save_fat_buffer_err_retn
  1676                              <1> 
  1677                              <1> loc_add_new_cluster_calc_FAT_freespace:
  1678                              <1> 	;mov	eax, 1 ; Only one Cluster
  1679 0000B494 A1[AE280100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1680 0000B499 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI -> Dos drv desc. table
  1681                              <1> 		; BL = 1 -> add cluster
  1682 0000B49D B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
  1683                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  1684                              <1> 	; (Free Cluster Count is decreased when EAX value is negative)
  1685 0000B49F E8CBFCFFFF          <1>         call    calculate_fat_freespace
  1686                              <1> 	;ECX = 0 -> no error, ECX > 0 -> error or invalid return
  1687 0000B4A4 21C9                <1> 	and	ecx, ecx ; ECX = 0 -> valid free sector count
  1688 0000B4A6 7409                <1> 	jz	short loc_add_new_cluster_return_cluster_number
  1689                              <1> 
  1690                              <1> loc_add_new_cluster_recalc_FAT_freespace:
  1691 0000B4A8 66BB00FF            <1> 	mov	bx, 0FF00h  ; recalculate free space
  1692 0000B4AC E8BEFCFFFF          <1>         call    calculate_fat_freespace
  1693                              <1> 	; cf = 0
  1694                              <1> loc_add_new_cluster_return_cluster_number:
  1695 0000B4B1 89C1                <1> 	mov	ecx, eax ; Free sector count
  1696 0000B4B3 A1[802C0100]        <1> 	mov	eax, [FAT_anc_FFCluster]
  1697 0000B4B8 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  1698                              <1> 	;mov	edi, Cluster_Buffer
  1699 0000B4BC 31D2                <1> 	xor	edx, edx
  1700 0000B4BE C3                  <1>         retn
  1701                              <1> 
  1702                              <1> write_cluster:
  1703                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1704                              <1> 	;
  1705                              <1> 	; INPUT ->
  1706                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
  1707                              <1> 	;	ESI = Logical DOS Drive Description Table address
  1708                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
  1709                              <1> 	;	Only for SINGLIX FS:
  1710                              <1> 	;	EDX = File Number (The 1st FDT address) 
  1711                              <1> 	; OUTPUT ->
  1712                              <1> 	;	cf = 1 -> Cluster can not be written onto disk
  1713                              <1> 	;	    EAX > 0 -> Error number
  1714                              <1> 	;	cf = 0 -> Cluster has been written successfully
  1715                              <1> 	;
  1716                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  1717                              <1> 	
  1718 0000B4BF 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
  1719                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  1720                              <1> 
  1721                              <1> write_file_sectors: ; 16/03/2016
  1722 0000B4C3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  1723 0000B4C7 761C                <1> 	jna	short write_fs_cluster
  1724                              <1> 
  1725                              <1> write_fat_file_sectors: 
  1726 0000B4C9 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
  1727 0000B4CC 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
  1728 0000B4D0 F7E2                <1> 	mul	edx
  1729 0000B4D2 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
  1730                              <1> 
  1731                              <1> 	; EAX = Disk sector address
  1732                              <1> 	; ECX = Sector count
  1733                              <1> 	; EBX = Buffer address
  1734                              <1> 	; (EDX = 0)
  1735                              <1> 	; ESI = Logical DOS drive description table address	
  1736                              <1> 
  1737 0000B4D5 E833250000          <1> 	call	disk_write
  1738 0000B4DA 7306                <1> 	jnc	short wclust_retn
  1739                              <1> 	
  1740 0000B4DC B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
  1741 0000B4E1 C3                  <1> 	retn
  1742                              <1> 
  1743                              <1> wclust_retn:
  1744 0000B4E2 29C0                <1> 	sub	eax, eax ; 0
  1745 0000B4E4 C3                  <1> 	retn
  1746                              <1> 
  1747                              <1> write_fs_cluster:
  1748                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1749                              <1> 	; Singlix FS
  1750                              <1> 	
  1751                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
  1752                              <1> 	
  1753                              <1> 	; EDX = File number is the first File Descriptor Table address 
  1754                              <1> 	;	of the file. (Absolute address of the FDT).
  1755                              <1> 	
  1756                              <1> 	; eax = sector index (0 for the first sector)
  1757                              <1> 	; edx = FDT0 address
  1758                              <1> 		; 64 KB buffer = 128 sectors (limit) 
  1759 0000B4E5 B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
  1760 0000B4EA E801000000          <1> 	call	write_fs_sectors
  1761 0000B4EF C3                  <1> 	retn
  1762                              <1> 
  1763                              <1> write_fs_sectors:
  1764                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1765 0000B4F0 F9                  <1> 	stc
  1766 0000B4F1 C3                  <1> 	retn
  1767                              <1> 
  1768                              <1> get_cluster_by_index:
  1769                              <1> 	; 29/04/2016 (TRDOS 386 =  TRDOS v2.0)
  1770                              <1> 	; INPUT ->
  1771                              <1> 	; 	EAX = Beginning cluster
  1772                              <1> 	; 	EDX = Sector index in disk/file section
  1773                              <1> 	;	      (Only for SINGLIX file system!)
  1774                              <1> 	; 	ECX = Cluster sequence number after the beginning cluster
  1775                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  1776                              <1> 	; OUTPUT ->
  1777                              <1> 	;	EAX = Cluster number 
  1778                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  1779                              <1> 	;
  1780                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  1781                              <1> 	;	
  1782 0000B4F2 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  1783 0000B4F6 721E                <1>         jb      get_fs_section_by_index 
  1784                              <1> 
  1785 0000B4F8 3B4E78              <1> 	cmp	ecx, [esi+LD_Clusters]
  1786 0000B4FB 7207                <1> 	jb	short gcbi_1
  1787                              <1> gcbi_0:
  1788 0000B4FD F9                  <1> 	stc
  1789 0000B4FE B823000000          <1> 	mov	eax, 23h ; Cluster not available ! 
  1790                              <1> 			 ; MSDOS error code: FCB unavailable
  1791 0000B503 C3                  <1> 	retn
  1792                              <1> gcbi_1:
  1793 0000B504 51                  <1> 	push	ecx
  1794 0000B505 E8E9F5FFFF          <1> 	call	get_next_cluster
  1795 0000B50A 59                  <1> 	pop	ecx
  1796 0000B50B 7203                <1> 	jc	short gcbi_3
  1797 0000B50D E2F5                <1> 	loop	gcbi_1
  1798                              <1> gcbi_2:
  1799 0000B50F C3                  <1> 	retn
  1800                              <1> gcbi_3:
  1801 0000B510 09C0                <1> 	or	eax, eax
  1802 0000B512 74E9                <1> 	jz	short gcbi_0
  1803 0000B514 F5                  <1> 	cmc 	; stc
  1804 0000B515 C3                  <1> 	retn
  1805                              <1> 
  1806                              <1> get_fs_section_by_index:
  1807                              <1> 	; 29/04/2016 (TRDOS 386 =  TRDOS v2.0)
  1808                              <1> 	; INPUT ->
  1809                              <1> 	; 	EAX = Beginning FDT number/address
  1810                              <1> 	; 	EDX = Sector index in disk/file section
  1811                              <1> 	; 	ECX = Sector sequence number after the beginning FDT
  1812                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  1813                              <1> 	; OUTPUT ->
  1814                              <1> 	; 	EAX = FDT number/address
  1815                              <1> 	; 	EDX = Sector index from FDT sector (0,1,2,3,4...)
  1816                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  1817                              <1> 	;
  1818                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  1819                              <1> 	;
  1820 0000B516 B8FFFFFFFF          <1> 	mov	eax, 0FFFFFFFFh
  1821 0000B51B C3                  <1> 	retn
  1923                                  %include 'trdosk6.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk6.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 11/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    11                              <1> ; u1.s (27/17/2015), u2.s (03/01/2016)
    12                              <1> ; ****************************************************************************
    13                              <1> 
    14                              <1> sysent: ; < enter to system call >
    15                              <1> 	; 06/06/2016
    16                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
    17                              <1> 	; 16/04/2015 - 19/10/2015 (Retro UNIX 386 v1)
    18                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
    19                              <1> 	;
    20                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
    21                              <1> 	; The trap type is determined and an indirect jump is made to 
    22                              <1> 	; the appropriate system call handler. If there is a trap inside
    23                              <1> 	; the system a jump to panic is made. All user registers are saved 
    24                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
    25                              <1> 	; instructor is decoded to get the the system code part (see
    26                              <1> 	; trap instruction in the PDP-11 handbook) and from this 
    27                              <1> 	; the indirect jump address is calculated. If a bad system call is
    28                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
    29                              <1> 	; is called. If the call is legitimate control passes to the
    30                              <1> 	; appropriate system routine.
    31                              <1> 	;
    32                              <1> 	; Calling sequence:
    33                              <1> 	;	Through a trap caused by any sys call outside the system.
    34                              <1> 	; Arguments:
    35                              <1> 	;	Arguments of particular system call.	
    36                              <1> 	; ...............................................................
    37                              <1> 	;	
    38                              <1> 	; Retro UNIX 8086 v1 modification: 
    39                              <1> 	;       System call number is in EAX register.
    40                              <1> 	;
    41                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
    42                              <1> 	;	registers depending of function details.
    43                              <1>   	;
    44                              <1> 	; 16/04/2015
    45 0000B51C 368925[A0300100]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
    46                              <1> 	; save user registers
    47 0000B523 1E                  <1> 	push	ds
    48 0000B524 06                  <1> 	push	es
    49 0000B525 0FA0                <1> 	push	fs
    50 0000B527 0FA8                <1> 	push	gs
    51 0000B529 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
    52                              <1> 	;
    53                              <1> 	; ESPACE = [ss:u.sp] - esp ; 4*12 = 48 ; 17/09/2015 ; 06/06/2016
    54                              <1> 	; 	(ESPACE is size of space in kernel stack 
    55                              <1> 	;	for saving/restoring user registers.)
    56                              <1> 	;
    57 0000B52A 50                  <1> 	push	eax ; 01/07/2015
    58 0000B52B 66B81000            <1> 	mov     ax, KDATA
    59 0000B52F 8ED8                <1>         mov     ds, ax
    60 0000B531 8EC0                <1>         mov     es, ax
    61 0000B533 8EE0                <1>         mov     fs, ax
    62 0000B535 8EE8                <1>         mov     gs, ax
    63 0000B537 A1[C81F0100]        <1> 	mov	eax, [k_page_dir]
    64 0000B53C 0F22D8              <1> 	mov	cr3, eax
    65 0000B53F 58                  <1> 	pop	eax ; 01/07/2015
    66                              <1> 	; 19/10/2015
    67 0000B540 FC                  <1> 	cld
    68                              <1> 	;
    69 0000B541 FE05[9F300100]      <1> 	inc	byte [sysflg]
    70                              <1> 		; incb sysflg / indicate a system routine is in progress
    71 0000B547 FB                  <1>         sti 	; 18/01/2014
    72 0000B548 0F855CA0FFFF        <1> 	jnz     panic ; 24/05/2013
    73                              <1> 		; beq 1f
    74                              <1> 		; jmp panic ; / called if trap inside system
    75                              <1> ;1:
    76                              <1> 	; 16/04/2015
    77 0000B54E A3[A8300100]        <1> 	mov	[u.r0], eax
    78 0000B553 8925[A4300100]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
    79                              <1> 	;
    80                              <1> 		; mov $s.syst+2,clockp
    81                              <1> 		; mov r0,-(sp) / save user registers 
    82                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack 
    83                              <1> 			   ; / in u.r0
    84                              <1> 		; mov r1,-(sp)
    85                              <1> 		; mov r2,-(sp)
    86                              <1> 		; mov r3,-(sp)
    87                              <1> 		; mov r4,-(sp)
    88                              <1> 		; mov r5,-(sp)
    89                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
    90                              <1> 		             ; / arithmetic unit
    91                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
    92                              <1> 		             ; / extended arithmetic unit
    93                              <1> 		; mov sc,-(sp) / "step count" register for the extended
    94                              <1> 		             ; / arithmetic unit
    95                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
    96                              <1> 		; mov 18.(sp),r0 / store pc in r0
    97                              <1> 		; mov -(r0),r0 / sys inst in r0      10400xxx
    98                              <1> 		; sub $sys,r0 / get xxx code
    99 0000B559 C1E002              <1> 	shl	eax, 2
   100                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
   101 0000B55C 3DA0000000          <1> 	cmp	eax, end_of_syscalls - syscalls
   102                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
   103                              <1> 	;jnb	short badsys
   104                              <1> 		; bhis badsys / yes, bad system call
   105 0000B561 F5                  <1> 	cmc
   106 0000B562 9C                  <1> 	pushf	
   107 0000B563 50                  <1> 	push	eax
   108 0000B564 8B2D[A0300100]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
   109 0000B56A B0FE                <1> 	mov	al, 0FEh ; 11111110b
   110 0000B56C 1400                <1> 	adc	al, 0 ; al = al + cf
   111 0000B56E 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
   112                              <1> 		; bic $341,20.(sp) / set users processor priority to 0 
   113                              <1> 				 ; / and clear carry bit
   114 0000B571 5D                  <1> 	pop	ebp ; eax
   115 0000B572 9D                  <1> 	popf
   116 0000B573 0F8254010000        <1>         jc      badsys
   117 0000B579 A1[A8300100]        <1> 	mov	eax, [u.r0]
   118                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
   119 0000B57E FFA5[84B50000]      <1> 	jmp	dword [ebp+syscalls]
   120                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
   121                              <1> 		            ; / to proper system routine.
   122                              <1> syscalls: ; 1:
   123                              <1> 	; 20/05/2016
   124                              <1> 	; 19/05/2016
   125                              <1> 	; 16/05/2016
   126                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   127                              <1> 	; 21/09/2015
   128                              <1> 	; 01/07/2015
   129                              <1> 	; 16/04/2015 (32 bit address modification) 
   130                              <1> 	;dd sysrele	; / 0
   131 0000B584 [A9D80000]          <1> 	dd sysver	; 0 ; Get TRDOS 386 version number (v2.0)	
   132 0000B588 [2DB70000]          <1> 	dd sysexit 	; / 1
   133 0000B58C [97B80000]          <1> 	dd sysfork 	; / 2
   134 0000B590 [AAB90000]          <1> 	dd sysread 	; / 3
   135 0000B594 [C5B90000]          <1> 	dd syswrite 	; / 4
   136 0000B598 [2FBA0000]          <1> 	dd sysopen 	; / 5
   137 0000B59C [69BB0000]          <1> 	dd sysclose 	; / 6
   138 0000B5A0 [19B80000]          <1> 	dd syswait 	; / 7
   139 0000B5A4 [DFBA0000]          <1> 	dd syscreat 	; / 8
   140 0000B5A8 [76C60000]          <1> 	dd syslink 	; / 9
   141 0000B5AC [38C70000]          <1> 	dd sysunlink 	; / 10
   142 0000B5B0 [0BC80000]          <1> 	dd sysexec 	; / 11
   143 0000B5B4 [65CC0000]          <1> 	dd syschdir 	; / 12
   144 0000B5B8 [49CD0000]          <1> 	dd systime 	; / 13
   145 0000B5BC [20BB0000]          <1> 	dd sysmkdir 	; / 14
   146 0000B5C0 [B7CC0000]          <1> 	dd syschmod 	; / 15
   147 0000B5C4 [19CD0000]          <1> 	dd syschown 	; / 16
   148 0000B5C8 [7CCD0000]          <1> 	dd sysbreak 	; / 17
   149 0000B5CC [D6C90000]          <1> 	dd sysstat 	; / 18
   150 0000B5D0 [41CE0000]          <1> 	dd sysseek 	; / 19
   151 0000B5D4 [53CE0000]          <1> 	dd systell 	; / 20
   152 0000B5D8 [54CF0000]          <1> 	dd sysmount 	; / 21
   153 0000B5DC [06D00000]          <1> 	dd sysumount 	; / 22
   154 0000B5E0 [D1CE0000]          <1> 	dd syssetuid 	; / 23
   155 0000B5E4 [02CF0000]          <1> 	dd sysgetuid 	; / 24
   156 0000B5E8 [58CD0000]          <1> 	dd sysstime 	; / 25
   157 0000B5EC [C5CE0000]          <1> 	dd sysquit 	; / 26
   158 0000B5F0 [B9CE0000]          <1> 	dd sysintr 	; / 27
   159 0000B5F4 [B2C90000]          <1> 	dd sysfstat 	; / 28
   160 0000B5F8 [85BB0000]          <1> 	dd sysemt 	; / 29
   161 0000B5FC [CABC0000]          <1> 	dd sysmdate 	; / 30
   162                              <1> 	;dd sysstty	; / 31
   163 0000B600 [15BD0000]          <1> 	dd sysvideo 	; 31 ; TRDOS 386 Video Functions (16/05/2016)
   164                              <1> 	;dd sysgtty	; / 32
   165 0000B604 [64C60000]          <1> 	dd sysaudio 	; 32 ; TRDOS 386 Audio Functions (16/05/2016)
   166                              <1> 	;dd sysilgins	; / 33
   167 0000B608 [9EBB0000]          <1> 	dd systimer 	; 33 ; TRDOS 386 Timer Functions (18/05/2016)
   168 0000B60C [61D00000]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
   169                              <1> 			     ; 11/06/2014
   170 0000B610 [90D00000]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
   171                              <1> 			     ; 01/07/2015
   172 0000B614 [66D10000]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
   173                              <1> 			     ; 21/09/2015 - get last error number
   174 0000B618 [B8D80000]          <1> 	dd sysreserved1 ; 37 ;; TRDOS 386 (19/05/2016)
   175 0000B61C [C7D80000]          <1> 	dd syspri 	; 38 ; change priority - TRDOS 386 (20/05/2016)
   176 0000B620 [97B60000]          <1> 	dd sysrele	; 39 ; TRDOS 386 (19/05/2016) (0 -> 39)
   177                              <1> 
   178                              <1> end_of_syscalls:
   179                              <1> 
   180                              <1> error:
   181                              <1> 	; 18/05/2016
   182                              <1> 	; 13/05/2016
   183                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   184                              <1> 	; 16/04/2015 - 17/09/2015 (Retro UNIX 386 v1)
   185                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
   186                              <1> 	;
   187                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
   188                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
   189                              <1> 	;
   190                              <1> 	; INPUTS -> none
   191                              <1> 	; OUTPUTS ->
   192                              <1> 	;	processor status - carry (c) bit is set (means error)
   193                              <1> 	;
   194                              <1> 	; 26/05/2013 (Stack pointer must be reset here! 
   195                              <1> 	; 	      Because, jumps to error procedure
   196                              <1> 	;	      disrupts push-pop nesting balance)
   197                              <1> 	;
   198 0000B624 8B2D[A0300100]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
   199 0000B62A 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
   200                              <1> 				 ; (system call will return with cf = 1)
   201                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
   202                              <1> 		               ; / users stack
   203                              <1> 	; 17/09/2015
   204 0000B62E 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
   205                              <1> 				 ; for saving/restoring user registers	
   206                              <1> 	;cmp	ebp, [u.usp]
   207                              <1> 	;je	short err0	
   208 0000B631 892D[A4300100]      <1> 	mov	[u.usp], ebp
   209                              <1> ;err0:
   210                              <1> 	; 01/09/2015
   211 0000B637 8B25[A4300100]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
   212                              <1> 				    ; 10/04/2013
   213                              <1> 				    ; (If an I/O error occurs during disk I/O,
   214                              <1> 				    ; related procedures will jump to 'error'
   215                              <1> 				    ; procedure directly without returning to 
   216                              <1> 				    ; the caller procedure. So, stack pointer
   217                              <1>                                     ; must be restored here.)
   218                              <1> 	; 13/05/2016
   219                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
   220                              <1> 	;	'get last error' system call later. 	
   221                              <1> 
   222                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
   223 0000B63D C605[0F310100]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
   224                              <1> 
   225                              <1> sysret: ; < return from system call>
   226                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   227                              <1> 	; 16/04/2015 - 10/09/2015 (Retro UNIX 386 v1)
   228                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
   229                              <1> 	;
   230                              <1> 	; 'sysret' first checks to see if process is about to be 
   231                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
   232                              <1> 	; If not, following happens:	 
   233                              <1> 	; 	1) The user's stack pointer is restored.
   234                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
   235                              <1> 	;	   i-node has been modified. If it has, it is written out
   236                              <1> 	;	   via 'ppoke'.
   237                              <1> 	;	3) If the super block has been modified, it is written out
   238                              <1> 	;	   via 'ppoke'.				
   239                              <1> 	;	4) If the dismountable file system's super block has been
   240                              <1> 	;	   modified, it is written out to the specified device
   241                              <1> 	;	   via 'ppoke'.
   242                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
   243                              <1> 	;	   during his execution. If so, 'tswap' is called to give
   244                              <1> 	;	   another user a chance to run.
   245                              <1> 	;	6) 'sysret' now goes into 'sysrele'. 
   246                              <1> 	;	    (See 'sysrele' for conclusion.)		
   247                              <1> 	;
   248                              <1> 	; Calling sequence:
   249                              <1> 	;	jump table or 'br sysret'
   250                              <1> 	; Arguments: 
   251                              <1> 	;	-	
   252                              <1> 	; ...............................................................
   253                              <1> 	;	
   254                              <1> 	; ((AX=r1 for 'iget' input))
   255                              <1> 	;	
   256 0000B644 6631C0              <1> 	xor	ax, ax ; 04/05/2013
   257                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
   258 0000B647 FEC0                <1> 	inc	al ; 04/05/2013
   259 0000B649 3805[F6300100]      <1> 	cmp	[u.bsys], al ; 1
   260                              <1> 		; tstb u.bsys / is a process about to be terminated because
   261 0000B64F 0F83D8000000        <1>         jnb     sysexit ; 04/05/2013
   262                              <1> 		; bne sysexit / of an error? yes, go to sysexit
   263                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
   264                              <1> 		; mov u.sp,sp / no point stack to users stack
   265 0000B655 FEC8                <1> 	dec 	al ; mov ax, 0
   266                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
   267 0000B657 E89E230000          <1> 	call	iget
   268                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
   269                              <1> 		            ; / it is written out
   270 0000B65C 6631C0              <1> 	xor 	ax, ax ; 0
   271 0000B65F 3805[9D300100]      <1> 	cmp	[smod], al ; 0
   272                              <1> 		; tstb	smod / has the super block been modified
   273 0000B665 7614                <1> 	jna	short sysret1
   274                              <1> 		; beq	1f / no, 1f
   275 0000B667 A2[9D300100]        <1> 	mov	[smod], al ; 0
   276                              <1> 		; clrb smod / yes, clear smod
   277 0000B66C BB[55390100]        <1> 	mov	ebx, sb0 ;; 07/08//2013
   278 0000B671 66810B0002          <1>    	or	word [ebx], 200h ;;
   279                              <1> 	;or	word [sb0], 200h ; write bit, bit 9
   280                              <1> 		; bis $1000,sb0 / set write bit in I/O queue for super block
   281                              <1> 		      	      ; / output
   282                              <1> 	; AX = 0
   283 0000B676 E880230000          <1> 	call 	poke ; 07/08/2013
   284                              <1> 	; call	ppoke
   285                              <1> 	; AX = 0
   286                              <1> 		; jsr r0,ppoke / write out modified super block to disk
   287                              <1> sysret1: ;1:
   288 0000B67B 3805[9E300100]      <1> 	cmp	[mmod], al ; 0
   289                              <1> 		; tstb	mmod / has the super block for the dismountable file
   290                              <1> 		           ; / system
   291 0000B681 7614                <1> 	jna	short sysrel0
   292                              <1> 		; beq 1f / been modified?  no, 1f
   293 0000B683 A2[9E300100]        <1> 	mov	[mmod], al ; 0	
   294                              <1> 		; clrb	mmod / yes, clear mmod
   295                              <1>         ;mov    ax, [mntd]
   296                              <1>         ;;mov   al, [mdev] ; 26/04/2013
   297 0000B688 BB[5D3B0100]        <1> 	mov	ebx, sb1 ;; 07/08//2013
   298                              <1>         ;;mov	[ebx], al
   299                              <1> 	;mov    [sb1], al
   300                              <1> 		; movb	mntd,sb1 / set the I/O queue
   301 0000B68D 66810B0002          <1> 	or	word [ebx], 200h
   302                              <1> 	;or	word [sb1], 200h ; write bit, bit 9
   303                              <1> 		; bis $1000,sb1 / set write bit in I/O queue for detached sb
   304 0000B692 E864230000          <1> 	call	poke ; 07/08/2013
   305                              <1> 	;call	ppoke 
   306                              <1> 		; jsr r0,ppoke / write it out to its device
   307                              <1>         ;xor    al, al ; 26/04/2013       
   308                              <1> ;1:
   309                              <1> 		; tstb uquant / is the time quantum 0?
   310                              <1> 		; bne 1f / no, don't swap it out
   311                              <1> 
   312                              <1> sysrele: ; < release >
   313                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   314                              <1> 	; 16/04/2015 - 14/10/2015 (Retro UNIX 386 v1)
   315                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
   316                              <1> 	;
   317                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
   318                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
   319                              <1> 	; turns off the system flag. It then checked to see if there is
   320                              <1> 	; an interrupt from the user by calling 'isintr'. If there is, 
   321                              <1> 	; the output gets flashed (see isintr) and interrupt action is
   322                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
   323                              <1> 	; the user, a rti is made.
   324                              <1> 	;
   325                              <1> 	; Calling sequence:
   326                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
   327                              <1> 	; Arguments:
   328                              <1> 	;	-	
   329                              <1> 	; ...............................................................
   330                              <1> 	;	
   331                              <1> 	; 23/02/2014 (swapret)
   332                              <1> 	; 22/09/2013
   333                              <1> sysrel0: ;1:
   334 0000B697 803D[EA300100]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
   335                              <1> 		; tstb uquant / is the time quantum 0?
   336 0000B69E 7705                <1>         ja      short swapret
   337                              <1> 		; bne 1f / no, don't swap it out
   338                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
   339 0000B6A0 E8D1200000          <1> 	call	tswap
   340                              <1> 		; jsr r0,tswap / yes, swap it out
   341                              <1> 	
   342                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
   343                              <1> swapret: ;1:
   344                              <1> 	; 10/09/2015
   345                              <1> 	; 01/09/2015
   346                              <1> 	; 14/05/2015
   347                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
   348                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
   349                              <1> 	; cli
   350                              <1> 	; 24/07/2015
   351                              <1> 	;
   352                              <1> 	;; 'esp' must be already equal to '[u.usp]' here ! 
   353                              <1> 	;; mov	esp, [u.usp]
   354                              <1> 
   355                              <1> 	; 22/09/2013
   356 0000B6A5 E852230000          <1> 	call	isintr
   357                              <1> 	; 20/10/2013
   358 0000B6AA 7405                <1> 	jz	short sysrel1
   359 0000B6AC E865000000          <1> 	call	intract
   360                              <1> 		; jsr r0,isintr / is there an interrupt from the user
   361                              <1> 		;     br intract / yes, output gets flushed, take interrupt
   362                              <1> 		               ; / action
   363                              <1> sysrel1:
   364 0000B6B1 FA                  <1> 	cli ; 14/10/2015
   365 0000B6B2 FE0D[9F300100]      <1> 	dec	byte [sysflg]
   366                              <1> 		; decb sysflg / turn system flag off
   367 0000B6B8 A1[01310100]        <1> 	mov     eax, [u.pgdir]
   368 0000B6BD 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
   369                              <1> 			  ; (others are different than kernel page tables) 
   370                              <1> 	; 10/09/2015
   371 0000B6C0 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
   372                              <1> 		; mov (sp)+,sc / restore user registers
   373                              <1> 		; mov (sp)+,mq
   374                              <1> 		; mov (sp)+,ac
   375                              <1> 		; mov (sp)+,r5
   376                              <1> 		; mov (sp)+,r4
   377                              <1> 		; mov (sp)+,r3
   378                              <1> 		; mov (sp)+,r2
   379                              <1> 	;
   380 0000B6C1 A1[A8300100]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
   381 0000B6C6 0FA9                <1> 	pop	gs
   382 0000B6C8 0FA1                <1> 	pop	fs
   383 0000B6CA 07                  <1> 	pop	es
   384 0000B6CB 1F                  <1> 	pop	ds
   385 0000B6CC CF                  <1> 	iretd	
   386                              <1> 		; rti / no, return from interrupt
   387                              <1> 
   388                              <1> badsys:
   389                              <1> 	; 18/04/2016 (TRDOS 386 = TRDOS v2.0)
   390                              <1> 	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
   391                              <1> 	; 03/02/2011 ('trdos_ifc_routine')
   392                              <1> 	;
   393                              <1> 	; 16/04/2015 (Retro UNIX 386 v1, 'badsys')
   394                              <1> 	; (EIP, EAX values will be shown on screen with error message)
   395                              <1> 	; (EIP = 'CD 40h' instruction address -INT 40h-)
   396                              <1> 	; (EAX = Function number)  
   397                              <1> 	;
   398 0000B6CD FE05[F6300100]      <1> 	inc	byte [u.bsys]
   399                              <1> 	;
   400 0000B6D3 8B1D[A0300100]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
   401 0000B6D9 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
   402 0000B6DB 83E802              <1> 	sub	eax, 2 ; CDh, ##h
   403 0000B6DE E89576FFFF          <1> 	call	dwordtohex
   404 0000B6E3 8915[1BE50000]      <1> 	mov	[eip_str], edx
   405 0000B6E9 A3[1FE50000]        <1> 	mov	[eip_str+4], eax
   406 0000B6EE A1[A8300100]        <1> 	mov	eax, [u.r0]
   407 0000B6F3 E88076FFFF          <1> 	call	dwordtohex
   408 0000B6F8 8915[0AE50000]      <1> 	mov	[eax_str], edx
   409 0000B6FE A3[0EE50000]        <1> 	mov	[eax_str+4], eax
   410                              <1> 
   411 0000B703 C605[FFE40000]40    <1> 	mov	byte [int_num_str], 40h
   412                              <1> 
   413 0000B70A BE[D1E40000]        <1> 	mov	esi, ifc_msg ; "invalid funtion call !" msg (trdosk9.s)
   414 0000B70F E8429EFFFF          <1> 	call	print_msg
   415                              <1> 
   416 0000B714 EB17                <1> 	jmp	sysexit
   417                              <1> 
   418                              <1> intract: ; / interrupt action
   419                              <1> 	; 14/10/2015
   420                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
   421                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
   422                              <1> 	;
   423                              <1> 	; Retro UNIX 8086 v1 modification !
   424                              <1> 	; (Process/task switching and quit routine by using
   425                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
   426                              <1> 	;
   427                              <1> 	; input -> 'u.quit'  (also value of 'u.intr' > 0)
   428                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
   429                              <1> 	;		'intract' will jump to 'sysexit'.
   430                              <1> 	;	    Intract will return to the caller 
   431                              <1> 	;		if value of 'u.quit' <> FFFFh. 	 
   432                              <1> 	; 14/10/2015
   433 0000B716 FB                  <1> 	sti
   434                              <1> 	; 07/12/2013	
   435 0000B717 66FF05[EE300100]    <1> 	inc 	word [u.quit]
   436 0000B71E 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
   437 0000B720 66FF0D[EE300100]    <1> 	dec	word [u.quit]
   438                              <1> 	; 16/04/2015
   439 0000B727 C3                  <1> 	retn
   440                              <1> intrct0:	
   441 0000B728 58                  <1> 	pop	eax ; call intract -> retn
   442                              <1> 	;
   443 0000B729 31C0                <1> 	xor 	eax, eax
   444 0000B72B FEC0                <1> 	inc	al  ; mov ax, 1
   445                              <1> ;;;
   446                              <1> 	; UNIX v1 original 'intract' routine... 
   447                              <1> 	; / interrupt action
   448                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
   449                              <1> 		; bne 1f / no, 1f
   450                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
   451                              <1> 	; 1: / now in user area
   452                              <1> 		; mov r1,-(sp) / save r1
   453                              <1> 		; mov u.ttyp,r1 
   454                              <1> 			; / pointer to tty buffer in control-to r1
   455                              <1> 		; cmpb 6(r1),$177
   456                              <1> 			; / is the interrupt char equal to "del"
   457                              <1> 		; beq 1f / yes, 1f
   458                              <1> 		; clrb 6(r1) 
   459                              <1> 		        ; / no, clear the byte 
   460                              <1> 			; / (must be a quit character)
   461                              <1> 		; mov (sp)+,r1 / restore r1
   462                              <1> 		; clr u.quit / clear quit flag
   463                              <1> 		; bis $20,2(sp) 
   464                              <1> 		    	; / set trace for quit (sets t bit of 
   465                              <1> 			; / ps-trace trap)
   466                              <1> 		; rti   ;  / return from interrupt
   467                              <1> 	; 1: / interrupt char = del
   468                              <1> 		; clrb 6(r1) / clear the interrupt byte 
   469                              <1> 			   ; / in the buffer
   470                              <1> 		; mov (sp)+,r1 / restore r1
   471                              <1> 		; cmp u.intr,$core / should control be 
   472                              <1> 				; / transferred to loc core?
   473                              <1> 		; blo 1f
   474                              <1> 		; jmp *u.intr / user to do rti yes, 
   475                              <1> 				; / transfer to loc core
   476                              <1> 	; 1:
   477                              <1> 		; sys 1 / exit
   478                              <1> 
   479                              <1> sysexit: ; <terminate process>
   480                              <1> 	; 10/06/2016
   481                              <1> 	; 06/06/2016
   482                              <1> 	; 23/05/2016
   483                              <1> 	; 19/05/2016
   484                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   485                              <1> 	; 16/04/2015 - 01/09/2015 (Retro UNIX 386 v1)
   486                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
   487                              <1> 	;
   488                              <1> 	; 'sysexit' terminates a process. First each file that
   489                              <1> 	; the process has opened is closed by 'flose'. The process
   490                              <1> 	; status is then set to unused. The 'p.pid' table is then
   491                              <1> 	; searched to find children of the dying process. If any of
   492                              <1> 	; children are zombies (died by not waited for), they are
   493                              <1> 	; set free. The 'p.pid' table is then searched to find the
   494                              <1> 	; dying process's parent. When the parent is found, it is
   495                              <1> 	; checked to see if it is free or it is a zombie. If it is
   496                              <1> 	; one of these, the dying process just dies. If it is waiting
   497                              <1> 	; for a child process to die, it notified that it doesn't 
   498                              <1> 	; have to wait anymore by setting it's status from 2 to 1
   499                              <1> 	; (waiting to active). It is awakened and put on runq by
   500                              <1> 	; 'putlu'. The dying process enters a zombie state in which
   501                              <1> 	; it will never be run again but stays around until a 'wait'
   502                              <1> 	; is completed by it's parent process. If the parent is not
   503                              <1> 	; found, process just dies. This means 'swap' is called with
   504                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
   505                              <1> 	; to write out the process and 'rswap' reads the new process
   506                              <1> 	; over the one that dies..i.e., the dying process is 
   507                              <1> 	; overwritten and destroyed.	
   508                              <1>  	;
   509                              <1> 	; Calling sequence:
   510                              <1> 	;	sysexit or conditional branch.
   511                              <1> 	; Arguments:
   512                              <1> 	;	-	
   513                              <1> 	; ...............................................................
   514                              <1> 	;	
   515                              <1> 	; Retro UNIX 8086 v1 modification: 
   516                              <1> 	;       System call number (=1) is in EAX register.
   517                              <1> 	;
   518                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
   519                              <1> 	;       registers depending of function details.
   520                              <1> 	;
   521                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
   522                              <1> 	;
   523                              <1> ; / terminate process
   524                              <1> 	; AX = 1
   525 0000B72D 6648                <1> 	dec 	ax ; 0
   526 0000B72F 66A3[EC300100]      <1> 	mov	[u.intr], ax ; 0
   527                              <1> 		; clr u.intr / clear interrupt control word
   528                              <1> 		; clr r1 / clear r1
   529                              <1> 	; AX = 0
   530                              <1> sysexit_1: ; 1:
   531                              <1> 	; AX = File descriptor
   532                              <1> 		; / r1 has file descriptor (index to u.fp list)
   533                              <1> 		; / Search the whole list
   534 0000B735 E832130000          <1> 	call	fclose
   535                              <1> 		; jsr r0,fclose / close all files the process opened
   536                              <1> 	;; ignore error return
   537                              <1> 		; br .+2 / ignore error return
   538                              <1> 	;inc	ax
   539 0000B73A FEC0                <1> 	inc	al
   540                              <1> 		; inc r1 / increment file descriptor
   541                              <1> 	;cmp	ax, 10
   542 0000B73C 3C0A                <1> 	cmp	al, 10
   543                              <1> 		; cmp r1,$10. / end of u.fp list?
   544 0000B73E 72F5                <1> 	jb	short sysexit_1
   545                              <1> 		; blt 1b / no, go back
   546 0000B740 0FB61D[F7300100]    <1> 	movzx	ebx, byte [u.uno]
   547                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
   548 0000B747 88A3[1B2E0100]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   549                              <1> 		; clrb p.stat-1(r1) / free the process
   550                              <1> 	;shl	bx, 1
   551 0000B74D D0E3                <1> 	shl	bl, 1
   552                              <1> 		; asl r1 / use r1 for index into the below tables
   553 0000B74F 668B8B[8A2D0100]    <1> 	mov	cx, [ebx+p.pid-2]
   554                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
   555 0000B756 668B93[AA2D0100]    <1> 	mov	dx, [ebx+p.ppid-2]
   556                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
   557                              <1> 	; xor 	bx, bx ; 0
   558 0000B75D 30DB                <1> 	xor	bl, bl ; 0
   559                              <1> 		; clr r2
   560 0000B75F 31F6                <1> 	xor	esi, esi ; 0
   561                              <1> 		; clr r5 / initialize reg
   562                              <1> sysexit_2: ; 1:
   563                              <1> 	        ; / find children of this dying process, 
   564                              <1> 		; / if they are zombies, free them
   565                              <1> 	;add	bx, 2
   566 0000B761 80C302              <1> 	add	bl, 2
   567                              <1> 		; add $2,r2 / search parent process table 
   568                              <1> 		          ; / for dying process's name
   569 0000B764 66398B[AA2D0100]    <1> 	cmp	[ebx+p.ppid-2], cx
   570                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
   571 0000B76B 7513                <1> 	jne	short sysexit_4
   572                              <1> 		; bne 3f / no
   573                              <1> 	;shr	bx, 1
   574 0000B76D D0EB                <1> 	shr	bl, 1
   575                              <1> 		; asr r2 / yes, it is a parent
   576 0000B76F 80BB[1B2E0100]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB
   577                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this 
   578                              <1> 				     ; / dying process a zombie
   579 0000B776 7506                <1> 	jne	short sysexit_3 
   580                              <1> 		; bne 2f / no
   581 0000B778 88A3[1B2E0100]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   582                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
   583                              <1> sysexit_3: ; 2:
   584                              <1> 	;shr	bx, 1
   585 0000B77E D0E3                <1> 	shl	bl, 1
   586                              <1> 		; asl r2
   587                              <1> sysexit_4: ; 3:
   588                              <1> 		; / search the process name table 
   589                              <1> 		; / for the dying process's parent
   590 0000B780 663993[8A2D0100]    <1> 	cmp	[ebx+p.pid-2], dx
   591                              <1> 		; cmp p.pid-2(r2),r4 / found it?
   592 0000B787 7502                <1> 	jne	short sysexit_5
   593                              <1> 		; bne 3f / no
   594 0000B789 89DE                <1> 	mov	esi, ebx
   595                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
   596                              <1> 		          ; / process # x2) in r5
   597                              <1> sysexit_5: ; 3:
   598                              <1> 	;cmp	bx, nproc + nproc
   599 0000B78B 80FB20              <1> 	cmp	bl, nproc + nproc
   600                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
   601 0000B78E 72D1                <1> 	jb	short sysexit_2
   602                              <1> 		; blt 1b / no, go back
   603                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
   604 0000B790 21F6                <1> 	and	esi, esi ; r5=r1
   605 0000B792 7431                <1> 	jz	short sysexit_6
   606                              <1> 		; beq 2f / no parent has been found. 
   607                              <1> 		       ; / The process just dies
   608 0000B794 66D1EE              <1> 	shr	si, 1
   609                              <1> 		; asr r1 / set up index to p.stat
   610 0000B797 8A86[1B2E0100]      <1> 	mov	al, [esi+p.stat-1]
   611                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
   612 0000B79D 20C0                <1> 	and	al, al
   613 0000B79F 7424                <1> 	jz	short sysexit_6
   614                              <1> 		; beq 2f / if its been freed, 2f
   615 0000B7A1 3C03                <1> 	cmp	al, 3
   616                              <1> 		; cmp r2,$3 / is parent a zombie?
   617 0000B7A3 7420                <1> 	je	short sysexit_6
   618                              <1> 		; beq 2f / yes, 2f
   619                              <1> 	; BH = 0
   620 0000B7A5 8A1D[F7300100]      <1> 	mov	bl, [u.uno]
   621                              <1> 		; movb u.uno,r3 / move dying process's number to r3
   622 0000B7AB C683[1B2E0100]03    <1> 	mov	byte [ebx+p.stat-1], 3  ; SZOMB
   623                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
   624 0000B7B2 3C01                <1> 	cmp	al, 1 ; SRUN
   625 0000B7B4 740F                <1> 	je	short sysexit_6
   626                              <1> 	;cmp	al, 2
   627                              <1> 		; cmp r2,$2 / is the parent waiting for 
   628                              <1> 			  ; / this child to die
   629                              <1> 	;jne	short sysexit_6	
   630                              <1> 		; bne 2f / yes, notify parent not to wait any more
   631                              <1> 	; p.stat = 2 --> waiting
   632                              <1> 	; p.stat = 4 --> sleeping
   633 0000B7B6 C686[1B2E0100]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN
   634                              <1> 	;dec	byte [esi+p.stat-1]
   635                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
   636 0000B7BD 6689F0              <1> 	mov	ax, si ; r1  (process number in AL)
   637                              <1> 	; 
   638                              <1> 	;mov	ebx, runq + 4
   639                              <1> 		; mov $runq+4,r2 / on the runq
   640 0000B7C0 E8C4200000          <1> 	call	putlu
   641                              <1> 		; jsr r0, putlu
   642                              <1> sysexit_6: 
   643                              <1> 	; 10/06/2016
   644                              <1> 	; 06/06/2016
   645                              <1> 	; 23/05/2016
   646                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   647                              <1> 	; Check and stop/clear timer event(s) of this (dying) process
   648                              <1> 	; if there is.
   649 0000B7C5 8A86[6B2E0100]      <1> 	mov 	al, [esi+p.timer-1]
   650 0000B7CB 20C0                <1> 	and	al, al
   651 0000B7CD 743C                <1> 	jz	short sysexit_12 ; no timer events for this process
   652 0000B7CF C686[6B2E0100]00    <1> 	mov	byte [esi+p.timer-1], 0 ; reset
   653 0000B7D6 A0[4F2D0100]        <1> 	mov	al, [timer_events]
   654                              <1> 	;or	al, al
   655                              <1>  	;jz	short sysexit_12 ; no timer events
   656 0000B7DB 88C1                <1> 	mov	cl, al
   657 0000B7DD 8A25[F7300100]      <1> 	mov	ah, [u.uno]
   658 0000B7E3 FA                  <1> 	cli	; disable interrupts 
   659 0000B7E4 B310                <1> 	mov	bl, 16
   660 0000B7E6 BE[6C3D0100]        <1> 	mov	esi, timer_set ; beginning address of timer events
   661                              <1> sysexit_7:
   662 0000B7EB 8A06                <1> 	mov	al, [esi] ; process number (of timer event)
   663 0000B7ED 38E0                <1> 	cmp	al, ah ; process number comparison
   664 0000B7EF 7411                <1> 	je	short sysexit_10
   665 0000B7F1 20C0                <1> 	and	al, al
   666 0000B7F3 7404                <1> 	jz	short sysexit_9
   667                              <1> sysexit_8:
   668 0000B7F5 FEC9                <1> 	dec	cl
   669 0000B7F7 7410                <1> 	jz	short sysexit_11
   670                              <1> sysexit_9:
   671 0000B7F9 FECB                <1> 	dec	bl
   672 0000B7FB 740C                <1> 	jz	short sysexit_11
   673 0000B7FD 83C610              <1> 	add	esi, 16
   674 0000B800 EBE9                <1> 	jmp	short sysexit_7
   675                              <1> 
   676                              <1> sysexit_10:
   677                              <1> 	;mov	byte [esi], 0
   678 0000B802 66C7060000          <1> 	mov	word [esi], 0
   679                              <1> 	;mov	dword [esi+12], 0
   680 0000B807 EBEC                <1> 	jmp	short sysexit_8
   681                              <1> 
   682                              <1> sysexit_11:
   683 0000B809 30C0                <1> 	xor	al, al
   684                              <1> sysexit_12: ; 2:
   685 0000B80B FB                  <1> 	sti	; enable interrupts 
   686                              <1> 	;
   687 0000B80C A2[F7300100]        <1> 	mov	[u.uno], al ; 0
   688                              <1> 		; / the process dies
   689                              <1> 	;mov	byte [u.uno], 0
   690                              <1> 		; clrb u.uno / put zero as the process number, 
   691                              <1> 	           ; / so "swap" will
   692 0000B811 E8831F0000          <1> 	call	swap
   693                              <1> 		; jsr r0,swap / overwrite process with another process
   694                              <1> hlt_sys:
   695                              <1> 	;sti
   696                              <1> hlts0:
   697 0000B816 F4                  <1> 	hlt
   698 0000B817 EBFD                <1> 	jmp	short hlts0
   699                              <1> 		; 0 / and thereby kill it; halt?
   700                              <1> 
   701                              <1> syswait: ; < wait for a processs to die >
   702                              <1> 	; 17/09/2015
   703                              <1> 	; 02/09/2015
   704                              <1> 	; 01/09/2015
   705                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
   706                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
   707                              <1> 	;
   708                              <1> 	; 'syswait' waits for a process die. 
   709                              <1> 	; It works in following way:
   710                              <1> 	;    1) From the parent process number, the parent's 
   711                              <1> 	; 	process name is found. The p.ppid table of parent
   712                              <1> 	;	names is then searched for this process name.
   713                              <1> 	;	If a match occurs, r2 contains child's process
   714                              <1> 	;	number. The child status is checked to see if it is
   715                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
   716                              <1> 	;	If it is, the child process is freed and it's name
   717                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
   718                              <1> 	;	If the child is not a zombie, nothing happens and
   719                              <1> 	;	the search goes on through the p.ppid table until
   720                              <1> 	;	all processes are checked or a zombie is found.
   721                              <1> 	;    2) If no zombies are found, a check is made to see if
   722                              <1> 	;	there are any children at all. If there are none,
   723                              <1> 	;	an error return is made. If there are, the parent's
   724                              <1> 	;	status is set to 2 (waiting for child to die),
   725                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
   726                              <1> 	;	is made to wait on the next process.
   727                              <1> 	;
   728                              <1> 	; Calling sequence:
   729                              <1> 	;	?
   730                              <1> 	; Arguments:
   731                              <1> 	;	-
   732                              <1> 	; Inputs: - 
   733                              <1> 	; Outputs: if zombie found, it's name put in u.r0.	
   734                              <1> 	; ...............................................................
   735                              <1> 	;				
   736                              <1> 	
   737                              <1> ; / wait for a process to die
   738                              <1> 
   739                              <1> syswait_0:
   740 0000B819 0FB61D[F7300100]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
   741                              <1> 		; movb u.uno,r1 / put parents process number in r1
   742 0000B820 D0E3                <1> 	shl	bl, 1
   743                              <1> 	;shl	bx, 1
   744                              <1> 		; asl r1 / x2 to get index into p.pid table
   745 0000B822 668B83[8A2D0100]    <1> 	mov	ax, [ebx+p.pid-2]
   746                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
   747 0000B829 31F6                <1> 	xor	esi, esi
   748                              <1> 		; clr r2
   749 0000B82B 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
   750                              <1> 	;xor 	cl, cl
   751                              <1> 		; clr r3 / initialize reg 3
   752                              <1> syswait_1: ; 1:
   753 0000B82D 6683C602            <1> 	add	si, 2
   754                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
   755                              <1> 			  ; / search table of parent processes 
   756                              <1> 			  ; / for this process name
   757 0000B831 663B86[AA2D0100]    <1> 	cmp	ax, [esi+p.ppid-2]
   758                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs 
   759                              <1> 			            ; / process number
   760 0000B838 7535                <1> 	jne	short syswait_3
   761                              <1> 		;bne 3f / branch if no match of parent process name
   762                              <1> 	;inc	cx
   763 0000B83A FEC1                <1> 	inc	cl
   764                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
   765 0000B83C 66D1EE              <1> 	shr	si, 1
   766                              <1> 		; asr r2 / r2/2 to get index to p.stat table
   767                              <1> 	; The possible states ('p.stat' values) of a process are:
   768                              <1> 	;	0 = free or unused
   769                              <1> 	;	1 = active
   770                              <1> 	;	2 = waiting for a child process to die
   771                              <1> 	;	3 = terminated, but not yet waited for (zombie).	
   772 0000B83F 80BE[1B2E0100]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
   773                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
   774 0000B846 7524                <1> 	jne	short syswait_2
   775                              <1> 		; bne 2f / no, skip it
   776 0000B848 88BE[1B2E0100]      <1> 	mov	[esi+p.stat-1], bh ; 0
   777                              <1> 		; clrb p.stat-1(r2) / yes, free it
   778 0000B84E 66D1E6              <1> 	shl	si, 1
   779                              <1> 		; asl r2 / r2x2 to get index into p.pid table
   780 0000B851 0FB786[8A2D0100]    <1> 	movzx	eax, word [esi+p.pid-2]
   781 0000B858 A3[A8300100]        <1> 	mov	[u.r0], eax
   782                              <1> 		; mov p.pid-2(r2),*u.r0 
   783                              <1> 			      ; / put childs process name in (u.r0)
   784                              <1> 	;
   785                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
   786                              <1> 	;
   787                              <1> 	; Parent process ID -p.ppid- field (of the child process)
   788                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
   789                              <1> 	; system call loop from the application/program if it calls
   790                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
   791                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
   792                              <1> 	;
   793                              <1> 	; Note: syswait will return with error if there is not a
   794                              <1> 	;       zombie or running process to wait.	
   795                              <1> 	;
   796 0000B85D 6629C0              <1> 	sub	ax, ax
   797 0000B860 668986[AA2D0100]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
   798 0000B867 E9DBFDFFFF          <1> 	jmp	sysret0 ; ax = 0
   799                              <1> 	;
   800                              <1> 	;jmp	sysret
   801                              <1> 		; br sysret1 / return cause child is dead
   802                              <1> syswait_2: ; 2:
   803 0000B86C 66D1E6              <1> 	shl	si, 1
   804                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
   805                              <1> syswait_3: ; 3:
   806 0000B86F 6683FE20            <1> 	cmp	si, nproc+nproc
   807                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
   808 0000B873 72B8                <1> 	jb	short syswait_1
   809                              <1> 		; blt 1b / no, continue search
   810                              <1> 	;and	cx, cx
   811 0000B875 20C9                <1> 	and	cl, cl
   812                              <1> 		; tst r3 / one gets here if there are no children 
   813                              <1> 		       ; / or children that are still active
   814                              <1> 	; 30/10/2013
   815 0000B877 750B                <1> 	jnz	short syswait_4
   816                              <1> 	;jz	error
   817                              <1> 		; beq error1 / there are no children, error
   818 0000B879 890D[A8300100]      <1> 	mov	[u.r0], ecx ; 0
   819 0000B87F E9A0FDFFFF          <1> 	jmp	error
   820                              <1> syswait_4:
   821 0000B884 8A1D[F7300100]      <1> 	mov	bl, [u.uno]
   822                              <1> 		; movb u.uno,r1 / there are children so put 
   823                              <1> 			      ; / parent process number in r1
   824 0000B88A FE83[1B2E0100]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
   825                              <1> 		; incb p.stat-1(r1) / it is waiting for 
   826                              <1> 				  ; / other children to die
   827                              <1> 	; 04/11/2013
   828 0000B890 E8041F0000          <1> 	call	swap
   829                              <1> 		; jsr r0,swap / swap it out, because it's waiting
   830 0000B895 EB82                <1> 	jmp	syswait_0
   831                              <1> 		; br syswait / wait on next process
   832                              <1> 
   833                              <1> sysfork: ; < create a new process >
   834                              <1> 	; 18/09/2015
   835                              <1> 	; 04/09/2015
   836                              <1> 	; 02/09/2015
   837                              <1> 	; 01/09/2015
   838                              <1> 	; 28/08/2015
   839                              <1> 	; 14/05/2015
   840                              <1> 	; 10/05/2015
   841                              <1> 	; 09/05/2015
   842                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
   843                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
   844                              <1> 	;
   845                              <1> 	; 'sysfork' creates a new process. This process is referred
   846                              <1> 	; to as the child process. This new process core image is
   847                              <1> 	; a copy of that of the caller of 'sysfork'. The only
   848                              <1> 	; distinction is the return location and the fact that (u.r0)
   849                              <1> 	; in the old process (parent) contains the process id (p.pid)
   850                              <1> 	; of the new process (child). This id is used by 'syswait'.
   851                              <1> 	; 'sysfork' works in the following manner: 	
   852                              <1> 	;    1) The process status table (p.stat) is searched to find
   853                              <1> 	;	a process number that is unused. If none are found
   854                              <1> 	;	an error occurs.
   855                              <1> 	;    2) when one is found, it becomes the child process number
   856                              <1> 	;	and it's status (p.stat) is set to active.
   857                              <1> 	;    3) If the parent had a control tty, the interrupt 
   858                              <1> 	;	character in that tty buffer is cleared.
   859                              <1> 	;    4) The child process is put on the lowest priority run 
   860                              <1> 	;	queue via 'putlu'.
   861                              <1> 	;    5) A new process name is gotten from 'mpid' (actually 
   862                              <1> 	;	it is a unique number) and is put in the child's unique
   863                              <1> 	;	identifier; process id (p.pid).
   864                              <1> 	;    6) The process name of the parent is then obtained and
   865                              <1> 	;	placed in the unique identifier of the parent process
   866                              <1> 	;	name is then put in 'u.r0'.	
   867                              <1> 	;    7) The child process is then written out on disk by
   868                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
   869                              <1> 	;	and the child is born. (The child process is written 
   870                              <1> 	;	out on disk/drum with 'u.uno' being the child process
   871                              <1> 	;	number.)
   872                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
   873                              <1> 	;    9) The child process name is put in 'u.r0'.
   874                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
   875                              <1> 	;	create the return address for the parent process.
   876                              <1> 	;   11) The 'u.fp' list as then searched to see what files
   877                              <1> 	;	the parent has opened. For each file the parent has
   878                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
   879                              <1> 	;	to indicate that the child process also has opened
   880                              <1> 	;	the file. A branch to 'sysret' is then made.	 			 				
   881                              <1> 	;
   882                              <1> 	; Calling sequence:
   883                              <1> 	;	from shell ?
   884                              <1> 	; Arguments:
   885                              <1> 	;	-
   886                              <1> 	; Inputs: -
   887                              <1> 	; Outputs: *u.r0 - child process name
   888                              <1> 	; ...............................................................
   889                              <1> 	;	
   890                              <1> 	; Retro UNIX 8086 v1 modification: 
   891                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
   892                              <1> 	;	= process id of child a parent process returns
   893                              <1> 	;	= process id of parent when a child process returns
   894                              <1> 	;
   895                              <1> 	;       In original UNIX v1, sysfork is called and returns as
   896                              <1> 	;	in following manner: (with an example: c library, fork)
   897                              <1> 	;	
   898                              <1> 	;	1:
   899                              <1> 	;		sys	fork
   900                              <1> 	;			br 1f  / child process returns here
   901                              <1> 	;		bes	2f     / parent process returns here
   902                              <1> 	;		/ pid of new process in r0
   903                              <1> 	;		rts	pc
   904                              <1> 	;	2: / parent process condionally branches here
   905                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
   906                              <1> 	;		rts	pc
   907                              <1> 	;
   908                              <1> 	;	1: / child process brances here
   909                              <1> 	;		clr	r0   / pid = 0 in child process
   910                              <1> 	;		rts	pc
   911                              <1> 	;
   912                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
   913                              <1> 	;		// pid = fork();
   914                              <1> 	;		//
   915                              <1> 	;		// pid == 0 in child process; 
   916                              <1> 	;		// pid == -1 means error return
   917                              <1> 	;		// in child, 
   918                              <1> 	;		//	parents id is in par_uid if needed
   919                              <1> 	;		
   920                              <1> 	;		_fork:
   921                              <1> 	;			mov	$.fork,eax
   922                              <1> 	;			int	$0x30
   923                              <1> 	;			jmp	1f
   924                              <1> 	;			jnc	2f
   925                              <1> 	;			jmp	cerror
   926                              <1> 	;		1:
   927                              <1> 	;			mov	eax,_par_uid
   928                              <1> 	;			xor	eax,eax
   929                              <1> 	;		2:
   930                              <1> 	;			ret
   931                              <1> 	;
   932                              <1> 	;	In Retro UNIX 8086 v1,
   933                              <1> 	;	'sysfork' returns in following manner:
   934                              <1> 	;	
   935                              <1> 	;		mov	ax, sys_fork
   936                              <1> 	;		mov	bx, offset @f ; routine for child
   937                              <1> 	;		int	20h
   938                              <1> 	;		jc	error
   939                              <1> 	;		
   940                              <1> 	;	; Routine for parent process here (just after 'jc')
   941                              <1> 	;		mov	word ptr [pid_of_child], ax
   942                              <1> 	;		jmp	next_routine_for_parent	
   943                              <1> 	;
   944                              <1> 	;	@@: ; routine for child process here				
   945                              <1> 	;		....	
   946                              <1> 	;	NOTE: 'sysfork' returns to specified offset
   947                              <1> 	;	       for child process by using BX input.
   948                              <1> 	;	      (at first, parent process will return then 
   949                              <1> 	;	      child process will return -after swapped in-
   950                              <1> 	;	      'syswait' is needed in parent process
   951                              <1> 	;	      if return from child process will be waited for.)
   952                              <1> 	;	  				
   953                              <1> 	
   954                              <1> ; / create a new process
   955                              <1> 	; EBX = return address for child process 
   956                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
   957 0000B897 31F6                <1> 	xor 	esi, esi
   958                              <1> 		; clr r1
   959                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
   960 0000B899 46                  <1> 	inc	esi
   961                              <1> 		; inc r1
   962 0000B89A 80BE[1B2E0100]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
   963                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
   964 0000B8A1 760B                <1> 	jna	short sysfork_2	
   965                              <1> 		; beq 1f / it's unused so branch
   966 0000B8A3 6683FE10            <1> 	cmp	si, nproc
   967                              <1> 		; cmp r1,$nproc / all processes checked
   968 0000B8A7 72F0                <1> 	jb	short sysfork_1
   969                              <1> 		; blt 1b / no, branch back
   970                              <1> 	;
   971                              <1> 	; Retro UNIX 8086 v1. modification:
   972                              <1> 	;	Parent process returns from 'sysfork' to address 
   973                              <1> 	;	which is just after 'sysfork' system call in parent
   974                              <1> 	;	process. Child process returns to address which is put
   975                              <1> 	;	in BX register by parent process for 'sysfork'. 
   976                              <1> 	;
   977                              <1> 		;add $2,18.(sp) / add 2 to pc when trap occured, points
   978                              <1> 		             ; / to old process return
   979                              <1> 		; br error1 / no room for a new process
   980 0000B8A9 E976FDFFFF          <1> 	jmp	error
   981                              <1> sysfork_2: ; 1:
   982 0000B8AE E8338DFFFF          <1> 	call	allocate_page
   983 0000B8B3 0F826BFDFFFF        <1> 	jc	error
   984 0000B8B9 50                  <1> 	push	eax   ; UPAGE (user structure page) address
   985                              <1> 	; Retro UNIX 386 v1 modification!
   986 0000B8BA E8368FFFFF          <1> 	call	duplicate_page_dir
   987                              <1> 		; EAX = New page directory 
   988 0000B8BF 730B                <1> 	jnc	short sysfork_3
   989 0000B8C1 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
   990 0000B8C2 E8FD8EFFFF          <1> 	call 	deallocate_page
   991 0000B8C7 E958FDFFFF          <1> 	jmp	error
   992                              <1> sysfork_3:
   993                              <1> 	; Retro UNIX 386 v1 modification !
   994 0000B8CC 56                  <1> 	push	esi
   995 0000B8CD E8551F0000          <1> 	call	wswap ; save current user (u) structure, user registers
   996                              <1> 		      ; and interrupt return components (for IRET)
   997 0000B8D2 8705[01310100]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
   998 0000B8D8 A3[05310100]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
   999 0000B8DD 5E                  <1> 	pop	esi
  1000 0000B8DE 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
  1001                              <1> 		; [u.usp] = esp
  1002 0000B8DF 89F7                <1> 	mov	edi, esi
  1003 0000B8E1 66C1E702            <1> 	shl	di, 2
  1004 0000B8E5 8987[282E0100]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
  1005 0000B8EB A3[F8300100]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
  1006                              <1> 	; 28/08/2015
  1007 0000B8F0 0FB605[F7300100]    <1> 	movzx	eax, byte [u.uno] ; parent process number
  1008                              <1> 		; movb u.uno,-(sp) / save parent process number
  1009 0000B8F7 89C7                <1> 	mov	edi, eax
  1010 0000B8F9 50                  <1>         push	eax ; ** 
  1011 0000B8FA 8A87[EB2D0100]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
  1012                              <1> 	; 18/09/2015
  1013                              <1> 	;mov     [esi+p.ttyc-1], al ; set child's console tty
  1014                              <1> 	;mov     [esi+p.waitc-1], ah ; 0 ; reset child's wait channel
  1015 0000B900 668986[EB2D0100]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
  1016                              <1> 				   ; ah - reset child's wait channel	
  1017 0000B907 89F0                <1> 	mov	eax, esi
  1018 0000B909 A2[F7300100]        <1> 	mov	[u.uno], al ; child process number
  1019                              <1> 		;movb r1,u.uno / set child process number to r1
  1020 0000B90E FE86[1B2E0100]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
  1021                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
  1022                              <1> 				; / process to active status
  1023                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
  1024                              <1> 			      ; / control tty buffer in r2
  1025                              <1>                 ; beq 2f / branch, if no such tty assigned
  1026                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
  1027                              <1> 	; 2:
  1028 0000B914 53                  <1> 	push	ebx  ; * return address for the child process
  1029                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
  1030                              <1> 	; (Retro UNIX 8086 v1 modification!)
  1031                              <1> 		; mov $runq+4,r2
  1032 0000B915 E86F1F0000          <1> 	call	putlu 
  1033                              <1>  		; jsr r0,putlu / put child process on lowest priority 
  1034                              <1> 			   ; / run queue
  1035 0000B91A 66D1E6              <1> 	shl	si, 1
  1036                              <1> 		; asl r1 / multiply r1 by 2 to get index 
  1037                              <1> 		       ; / into p.pid table
  1038 0000B91D 66FF05[92300100]    <1> 	inc	word [mpid]
  1039                              <1> 		; inc mpid / increment m.pid; get a new process name
  1040 0000B924 66A1[92300100]      <1> 	mov	ax, [mpid]
  1041 0000B92A 668986[8A2D0100]    <1> 	mov	[esi+p.pid-2], ax
  1042                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
  1043                              <1> 				    ; / in child process' name slot
  1044 0000B931 5A                  <1> 	pop	edx  ; * return address for the child process
  1045                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
  1046 0000B932 5B                  <1>   	pop	ebx  ; **
  1047                              <1> 	;mov	ebx, [esp] ; ** parent process number
  1048                              <1> 		; movb (sp),r2 / put parent process number in r2
  1049 0000B933 66D1E3              <1> 	shl 	bx, 1
  1050                              <1> 		;asl r2 / multiply by 2 to get index into below tables
  1051                              <1> 	;movzx eax, word [ebx+p.pid-2]
  1052 0000B936 668B83[8A2D0100]    <1> 	mov	ax, [ebx+p.pid-2]
  1053                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
  1054                              <1> 				   ; / process
  1055 0000B93D 668986[AA2D0100]    <1> 	mov	[esi+p.ppid-2], ax
  1056                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name 
  1057                              <1> 			  ; / in parent process slot for child
  1058 0000B944 A3[A8300100]        <1> 	mov	[u.r0], eax	
  1059                              <1> 		; mov r2,*u.r0 / put parent process name on stack 
  1060                              <1> 			     ; / at location where r0 was saved
  1061 0000B949 8B2D[A0300100]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
  1062 0000B94F 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
  1063                              <1> 			   ; * return address for the child process
  1064                              <1> 		; mov $sysret1,-(sp) /
  1065                              <1> 		; mov sp,u.usp / contents of sp at the time when 
  1066                              <1> 			      ; / user is swapped out
  1067                              <1> 		; mov $sstack,sp / point sp to swapping stack space
  1068                              <1> 	; 04/09/2015 - 01/09/2015
  1069                              <1> 	; [u.usp] = esp
  1070 0000B952 68[44B60000]        <1> 	push	sysret ; ***
  1071 0000B957 8925[A4300100]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
  1072                              <1> 			     ; (for child process)	
  1073 0000B95D 31C0                <1> 	xor 	eax, eax
  1074 0000B95F 66A3[D8300100]      <1> 	mov 	[u.ttyp], ax ; 0
  1075                              <1> 	;
  1076 0000B965 E8BD1E0000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
  1077                              <1> 		;jsr r0,wswap / put child process out on drum
  1078                              <1> 		;jsr r0,unpack / unpack user stack
  1079                              <1> 		;mov u.usp,sp / restore user stack pointer
  1080                              <1> 		; tst (sp)+ / bump stack pointer
  1081                              <1> 	; Retro UNIX 386 v1 modification !
  1082 0000B96A 58                  <1> 	pop	eax ; ***
  1083 0000B96B 66D1E3              <1> 	shl	bx, 1
  1084 0000B96E 8B83[282E0100]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
  1085 0000B974 E8D71E0000          <1> 	call	rswap ; restore parent process 'u' structure, 
  1086                              <1> 		      ; registers and return address (for IRET)
  1087                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
  1088 0000B979 0FB705[92300100]    <1>         movzx   eax, word [mpid]
  1089 0000B980 A3[A8300100]        <1> 	mov	[u.r0], eax
  1090                              <1> 		; mov mpid,*u.r0 / put child process name on stack 
  1091                              <1> 			       ; / where r0 was saved
  1092                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
  1093                              <1> 			          ; / process return
  1094                              <1> 	;xor	ebx, ebx
  1095 0000B985 31F6                <1> 	xor     esi, esi
  1096                              <1> 		;clr r1
  1097                              <1> sysfork_4: ; 1: / search u.fp list to find the files 
  1098                              <1> 	      ; / opened by the parent process
  1099                              <1> 	; 01/09/2015
  1100                              <1> 	;xor	bh, bh
  1101                              <1> 	;mov 	bl, [esi+u.fp]
  1102 0000B987 8A86[AE300100]      <1> 	mov 	al, [esi+u.fp]
  1103                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
  1104                              <1>         ;or      bl, bl
  1105 0000B98D 08C0                <1> 	or	al, al
  1106 0000B98F 740D                <1> 	jz	short sysfork_5	
  1107                              <1> 		; beq 2f / file has not been opened by parent, 
  1108                              <1> 		       ; / so branch
  1109 0000B991 B40A                <1> 	mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
  1110 0000B993 F6E4                <1> 	mul	ah
  1111                              <1> 	;movzx	ebx, ax
  1112 0000B995 6689C3              <1> 	mov	bx, ax
  1113                              <1> 	;shl     bx, 3
  1114                              <1> 		; asl r2 / multiply by 8
  1115                              <1>        		; asl r2 / to get index into fsp table
  1116                              <1>        		; asl r2
  1117 0000B998 FE83[7A2E0100]      <1>   	inc     byte [ebx+fsp-2]
  1118                              <1> 		; incb fsp-2(r2) / increment number of processes
  1119                              <1> 			     ; / using file, because child will now be
  1120                              <1> 			     ; / using this file
  1121                              <1> sysfork_5: ; 2:
  1122 0000B99E 46                  <1>         inc     esi
  1123                              <1> 		; inc r1 / get next open file
  1124 0000B99F 6683FE0A            <1>         cmp     si, 10
  1125                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
  1126                              <1> 			  ; / can be opened
  1127 0000B9A3 72E2                <1> 	jb	short sysfork_4	
  1128                              <1> 		; blt 1b / check next entry
  1129 0000B9A5 E99AFCFFFF          <1> 	jmp	sysret
  1130                              <1> 		; br sysret1
  1131                              <1> 
  1132                              <1> sysread: ; < read from file >
  1133                              <1> 	; 13/05/2015
  1134                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  1135                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  1136                              <1> 	;
  1137                              <1> 	; 'sysread' is given a buffer to read into and the number of
  1138                              <1> 	; characters to be read. If finds the file from the file
  1139                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
  1140                              <1> 	; is returned from a successful open call (sysopen).
  1141                              <1> 	; The i-number of file is obtained via 'rw1' and the data
  1142                              <1> 	; is read into core via 'readi'.
  1143                              <1> 	;
  1144                              <1> 	; Calling sequence:
  1145                              <1> 	;	sysread; buffer; nchars
  1146                              <1> 	; Arguments:
  1147                              <1> 	;	buffer - location of contiguous bytes where 
  1148                              <1> 	;		 input will be placed.
  1149                              <1> 	;	nchars - number of bytes or characters to be read.
  1150                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  1151                              <1> 	; Outputs: *u.r0 - number of bytes read.	
  1152                              <1> 	; ...............................................................
  1153                              <1> 	;				
  1154                              <1> 	; Retro UNIX 8086 v1 modification: 
  1155                              <1> 	;       'sysread' system call has three arguments; so,
  1156                              <1> 	;	* 1st argument, file descriptor is in BX register
  1157                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  1158                              <1> 	;	* 3rd argument, number of bytes is in DX register
  1159                              <1> 	;
  1160                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1161                              <1> 	;	to the user with number of bytes read. 
  1162                              <1> 	;
  1163 0000B9AA E83D000000          <1> 	call	rw1
  1164 0000B9AF 0F826FFCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
  1165                              <1> 		; jsr r0,rw1 / get i-number of file to be read into r1
  1166 0000B9B5 F6C480              <1> 	test	ah, 80h
  1167                              <1> 		; tst r1 / negative i-number?
  1168 0000B9B8 0F8566FCFFFF        <1> 	jnz	error
  1169                              <1> 		; ble error1 / yes, error 1 to read
  1170                              <1> 			   ; / it should be positive
  1171 0000B9BE E8E11A0000          <1> 	call	readi
  1172                              <1> 		; jsr r0,readi / read data into core
  1173 0000B9C3 EB18                <1> 	jmp	short rw0
  1174                              <1> 		; br 1f
  1175                              <1> syswrite: ; < write to file >
  1176                              <1> 	; 13/05/2015
  1177                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  1178                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  1179                              <1> 	;
  1180                              <1> 	; 'syswrite' is given a buffer to write onto an output file
  1181                              <1> 	; and the number of characters to write. If finds the file
  1182                              <1> 	; from the file descriptor located in *u.r0 (r0). This file 
  1183                              <1> 	; descriptor is returned from a successful open or create call
  1184                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
  1185                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
  1186                              <1> 	;
  1187                              <1> 	; Calling sequence:
  1188                              <1> 	;	syswrite; buffer; nchars
  1189                              <1> 	; Arguments:
  1190                              <1> 	;	buffer - location of contiguous bytes to be writtten.
  1191                              <1> 	;	nchars - number of characters to be written.
  1192                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  1193                              <1> 	; Outputs: *u.r0 - number of bytes written.	
  1194                              <1> 	; ...............................................................
  1195                              <1> 	;				
  1196                              <1> 	; Retro UNIX 8086 v1 modification: 
  1197                              <1> 	;       'syswrite' system call has three arguments; so,
  1198                              <1> 	;	* 1st argument, file descriptor is in BX register
  1199                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  1200                              <1> 	;	* 3rd argument, number of bytes is in DX register
  1201                              <1> 	;
  1202                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1203                              <1> 	;	to the user with number of bytes written. 
  1204                              <1> 	;
  1205 0000B9C5 E822000000          <1> 	call	rw1
  1206 0000B9CA 0F8254FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
  1207                              <1> 		; jsr r0,rw1 / get i-number in r1 of file to write
  1208 0000B9D0 F6C480              <1>         test	ah, 80h
  1209                              <1> 		; tst r1 / positive i-number ?
  1210 0000B9D3 744E                <1>         jz	short rw3 ; 13/05/2015
  1211                              <1> 	;jz	error
  1212                              <1> 		; bge error1 / yes, error 1 
  1213                              <1> 			   ; / negative i-number means write
  1214 0000B9D5 66F7D8              <1>         neg	ax
  1215                              <1> 		; neg r1 / make it positive
  1216 0000B9D8 E820200000          <1> 	call	writei
  1217                              <1>         	; jsr r0,writei / write data
  1218                              <1> rw0: ; 1:
  1219 0000B9DD A1[D0300100]        <1>         mov	eax, [u.nread]
  1220 0000B9E2 A3[A8300100]        <1> 	mov	[u.r0], eax
  1221                              <1> 		; mov u.nread,*u.r0 / put no. of bytes transferred
  1222                              <1> 				  ; / into (u.r0)
  1223 0000B9E7 E958FCFFFF          <1> 	jmp	sysret
  1224                              <1>         	; br sysret1
  1225                              <1> rw1:	
  1226                              <1> 	; 14/05/2015
  1227                              <1> 	; 13/05/2015
  1228                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  1229                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
  1230                              <1> 	; System call registers: bx, cx, dx (through 'sysenter')
  1231                              <1> 	;
  1232                              <1> 	;mov	[u.base], ecx 	; buffer address/offset 
  1233                              <1> 				;(in the user's virtual memory space)
  1234                              <1> 	;mov	[u.count], edx 
  1235                              <1> 		; jsr r0,arg; u.base / get buffer pointer
  1236                              <1>         	; jsr r0,arg; u.count / get no. of characters
  1237                              <1> 	;;mov	eax, ebx ; file descriptor
  1238                              <1> 		; mov *u.r0,r1 / put file descriptor 
  1239                              <1> 		             ; / (index to u.fp table) in r1
  1240                              <1> 	; 13/05/2015
  1241 0000B9EC C705[A8300100]0000- <1> 	mov	dword [u.r0], 0 ; r/w transfer count = 0 (reset)
  1241 0000B9F4 0000                <1>
  1242                              <1> 	;
  1243                              <1> 	;; call	getf
  1244                              <1>         ; eBX = File descriptor
  1245 0000B9F6 E8BC100000          <1> 	call	getf1 ; calling point in 'getf' from 'rw1'
  1246                              <1> 		; jsr r0,getf / get i-number of the file in r1
  1247                              <1> 	; AX = I-number of the file ; negative i-number means write
  1248                              <1> 	; 13/05/2015
  1249 0000B9FB 6683F801            <1> 	cmp 	ax, 1
  1250 0000B9FF 7217                <1> 	jb	short rw2
  1251                              <1> 	;
  1252 0000BA01 890D[C8300100]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
  1253                              <1> 				;(in the user's virtual memory space)
  1254 0000BA07 8915[CC300100]      <1> 	mov	[u.count], edx 
  1255                              <1> 	; 14/05/2015
  1256 0000BA0D C705[FD300100]0000- <1>         mov     dword [u.error], 0 ; reset the last error code
  1256 0000BA15 0000                <1>
  1257 0000BA17 C3                  <1> 	retn
  1258                              <1>         	; rts r0
  1259                              <1> rw2:
  1260                              <1> 	; 13/05/2015
  1261 0000BA18 C705[FD300100]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
  1261 0000BA20 0000                <1>
  1262 0000BA22 C3                  <1> 	retn
  1263                              <1> rw3: 
  1264                              <1> 	; 13/05/2015
  1265 0000BA23 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
  1265 0000BA2B 0000                <1>
  1266 0000BA2D F9                  <1> 	stc
  1267 0000BA2E C3                  <1> 	retn
  1268                              <1> 
  1269                              <1> sysopen: ;<open file>
  1270                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1271                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
  1272                              <1> 	;
  1273                              <1> 	; 'sysopen' opens a file in following manner:
  1274                              <1> 	;    1) The second argument in a sysopen says whether to
  1275                              <1> 	;	open the file ro read (0) or write (>0).
  1276                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
  1277                              <1> 	;    3) The file is opened by 'iopen'.
  1278                              <1> 	;    4) Next housekeeping is performed on the fsp table
  1279                              <1> 	;	and the user's open file list - u.fp.
  1280                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
  1281                              <1> 	;	b) An entry for the file is created in the fsp table.
  1282                              <1> 	;	c) The number of this entry is put on u.fp list.
  1283                              <1> 	;	d) The file descriptor index to u.fp list is pointed
  1284                              <1> 	;	   to by u.r0.
  1285                              <1> 	;
  1286                              <1> 	; Calling sequence:
  1287                              <1> 	;	sysopen; name; mode
  1288                              <1> 	; Arguments:
  1289                              <1> 	;	name - file name or path name
  1290                              <1> 	;	mode - 0 to open for reading
  1291                              <1> 	;	       1 to open for writing
  1292                              <1> 	; Inputs: (arguments)
  1293                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
  1294                              <1> 	;		  is put into r0's location on the stack.	
  1295                              <1> 	; ...............................................................
  1296                              <1> 	;				
  1297                              <1> 	; Retro UNIX 8086 v1 modification: 
  1298                              <1> 	;       'sysopen' system call has two arguments; so,
  1299                              <1> 	;	* 1st argument, name is pointed to by BX register
  1300                              <1> 	;	* 2nd argument, mode is in CX register
  1301                              <1> 	;
  1302                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1303                              <1> 	;	to the user with the file descriptor/number 
  1304                              <1> 	;	(index to u.fp list).
  1305                              <1> 	;
  1306                              <1> 	;call	arg2
  1307                              <1> 	; * name - 'u.namep' points to address of file/path name
  1308                              <1> 	;          in the user's program segment ('u.segmnt')
  1309                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1310                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1311                              <1> 	;          which is on top of stack.
  1312                              <1> 	;
  1313                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
  1314                              <1> 	;
  1315                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
  1316                              <1> 
  1317 0000BA2F 891D[C0300100]      <1> 	mov	[u.namep], ebx
  1318 0000BA35 6651                <1> 	push	cx
  1319 0000BA37 E8B2100000          <1> 	call	namei
  1320                              <1> 		; jsr r0,namei / i-number of file in r1
  1321                              <1>      	;and	ax, ax
  1322                              <1> 	;jz	error ; File not found
  1323 0000BA3C 723B                <1> 	jc	short fnotfound ; 14/05/2015
  1324                              <1> 	;jc	error ; 27/05/2013
  1325                              <1> 		; br  error2 / file not found
  1326 0000BA3E 665A                <1>    	pop	dx ; mode
  1327 0000BA40 6652                <1> 	push	dx
  1328                              <1> 	;or	dx, dx
  1329 0000BA42 08D2                <1> 	or	dl, dl
  1330                              <1> 		; tst (sp) / is mode = 0 (2nd arg of call; 
  1331                              <1> 		         ; / 0 means, open for read)
  1332 0000BA44 7403                <1> 	jz	short sysopen_0
  1333                              <1> 		; beq 1f / yes, leave i-number positive
  1334                              <1> syscreat_0: ; 27/12/2015
  1335 0000BA46 66F7D8              <1> 	neg	ax
  1336                              <1>         	; neg r1 / open for writing so make i-number negative
  1337                              <1> sysopen_0: ;1:
  1338 0000BA49 E8B01F0000          <1> 	call	iopen
  1339                              <1> 		;jsr r0,iopen / open file whose i-number is in r1
  1340 0000BA4E 665A                <1> 	pop	dx
  1341                              <1> 	;and	dx, dx
  1342 0000BA50 20D2                <1> 	and	dl, dl
  1343                              <1>         	; tst (sp)+ / pop the stack and test the mode
  1344 0000BA52 7403                <1> 	jz	short sysopen_2
  1345                              <1>         	; beq op1 / is open for read op1
  1346                              <1> sysopen_1: ;op0:
  1347 0000BA54 66F7D8              <1> 	neg	ax
  1348                              <1>         	; neg r1 
  1349                              <1> 		     ;/ make i-number positive if open for writing [???]
  1350                              <1> 	;; NOTE: iopen always make i-number positive.
  1351                              <1> 	;; Here i-number becomes negative again. [22/05/2013]
  1352                              <1> sysopen_2: ;op1:
  1353 0000BA57 31F6                <1>         xor     esi, esi
  1354                              <1>         	; clr r2 / clear registers
  1355 0000BA59 31DB                <1>         xor     ebx, ebx
  1356                              <1> 		; clr r3
  1357                              <1> sysopen_3: ;1: / scan the list of entries in fsp table
  1358 0000BA5B 389E[AE300100]      <1>         cmp     [esi+u.fp], bl ; 0
  1359                              <1> 		; tstb u.fp(r2) / test the entry in the u.fp list
  1360 0000BA61 7625                <1>         jna      short sysopen_4
  1361                              <1> 		; beq 1f / if byte in list is 0 branch
  1362 0000BA63 46                  <1>         inc     esi
  1363                              <1> 		; inc r2 / bump r2 so next byte can be checked
  1364 0000BA64 6683FE0A            <1>         cmp     si, 10
  1365                              <1> 		; cmp r2,$10. / reached end of list?
  1366 0000BA68 72F1                <1> 	jb	short sysopen_3
  1367                              <1> 		; blt 1b / no, go back
  1368                              <1> toomanyf:
  1369                              <1> 	; 14/05/2015
  1370 0000BA6A C705[FD300100]0D00- <1> 	mov	dword [u.error], ERR_TOO_MANY_FILES ; too many open files !
  1370 0000BA72 0000                <1>
  1371 0000BA74 E9ABFBFFFF          <1> 	jmp	error
  1372                              <1>         	; br error2 / yes, error (no files open)
  1373                              <1> fnotfound: 
  1374                              <1> 	; 14/05/2015
  1375 0000BA79 C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; file not found !
  1375 0000BA81 0000                <1>
  1376 0000BA83 E99CFBFFFF          <1> 	jmp	error
  1377                              <1> 
  1378                              <1> sysopen_4: ; 1:
  1379 0000BA88 6683BB[7C2E0100]00  <1>         cmp     word [ebx+fsp], 0
  1380                              <1> 		; tst fsp(r3) / scan fsp entries
  1381 0000BA90 7610                <1>         jna     short sysopen_5
  1382                              <1> 		; beq 1f / if 0 branch
  1383                              <1> 	; 14/05/2015 - Retro UNIX 386 v1 modification !
  1384 0000BA92 6683C30A            <1>         add     bx, 10 ; fsp structure size = 10 bytes/entry
  1385                              <1> 		; add $8.,r3 / add 8 to r3 
  1386                              <1> 			; / to bump it to next entry mfsp table
  1387 0000BA96 6681FBF401          <1>         cmp     bx, nfiles*10
  1388                              <1> 		; cmp r3,$[nfiles*8.] / done scanning
  1389 0000BA9B 72EB                <1> 	jb	short sysopen_4
  1390                              <1>        		; blt 1b / no, back
  1391 0000BA9D E982FBFFFF          <1> 	jmp	error
  1392                              <1>         	; br error2 / yes, error
  1393                              <1> sysopen_5: ; 1: / r2 has index to u.fp list; r3, has index to fsp table
  1394 0000BAA2 668983[7C2E0100]    <1>         mov     [ebx+fsp], ax
  1395                              <1> 		; mov r1,fsp(r3) / put i-number of open file 
  1396                              <1> 			; / into next available entry in fsp table,
  1397 0000BAA9 668B3D[8A300100]    <1> 	mov	di, [cdev] ; word ? byte ?
  1398 0000BAB0 6689BB[7E2E0100]    <1>         mov     [ebx+fsp+2], di ; device number
  1399                              <1> 		; mov cdev,fsp+2(r3) / put # of device in next word
  1400 0000BAB7 31FF                <1>         xor	edi, edi
  1401 0000BAB9 89BB[802E0100]      <1>         mov     [ebx+fsp+4], edi ; offset pointer (0)
  1402                              <1> 		; clr fsp+4(r3)
  1403 0000BABF 6689BB[842E0100]    <1>         mov     [ebx+fsp+8], di ; open count (0), deleted flag (0)
  1404                              <1>        		; clr fsp+6(r3) / clear the next two words
  1405 0000BAC6 89D8                <1>   	mov	eax, ebx
  1406 0000BAC8 B30A                <1> 	mov	bl, 10
  1407 0000BACA F6F3                <1> 	div	bl 
  1408                              <1> 		; asr r3
  1409                              <1> 		; asr r3 / divide by 8 
  1410                              <1> 		; asr r3 ; / to get number of the fsp entry-1
  1411 0000BACC FEC0                <1> 	inc	al
  1412                              <1>         	; inc r3 / add 1 to get fsp entry number
  1413 0000BACE 8886[AE300100]      <1>         mov     [esi+u.fp], al
  1414                              <1> 		; movb r3,u.fp(r2) / move entry number into 
  1415                              <1> 			; / next available slot in u.fp list
  1416 0000BAD4 8935[A8300100]      <1>         mov     [u.r0], esi
  1417                              <1> 		; mov r2,*u.r0 / move index to u.fp list 
  1418                              <1> 			     ; / into r0 loc on stack
  1419 0000BADA E965FBFFFF          <1>         jmp	sysret
  1420                              <1> 		; br sysret2
  1421                              <1> 
  1422                              <1> 	;
  1423                              <1> 	; 'fsp' table (10 bytes/entry)
  1424                              <1> 	; bit 15				   bit 0
  1425                              <1> 	; ---|-------------------------------------------
  1426                              <1> 	; r/w|		i-number of open file
  1427                              <1> 	; ---|-------------------------------------------
  1428                              <1> 	;		   device number
  1429                              <1> 	; -----------------------------------------------
  1430                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
  1431                              <1> 	; -----------------------------------------------
  1432                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
  1433                              <1> 	; ----------------------|------------------------
  1434                              <1> 	;  flag that says file 	| number of processes
  1435                              <1> 	;   has been deleted	| that have file open 
  1436                              <1> 	; ----------------------|------------------------
  1437                              <1> 	;
  1438                              <1> 
  1439                              <1> syscreat: ; < create file >
  1440                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
  1441                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1442                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
  1443                              <1> 	;
  1444                              <1> 	; 'syscreat' called with two arguments; name and mode.
  1445                              <1> 	; u.namep points to name of the file and mode is put
  1446                              <1> 	; on the stack. 'namei' is called to get i-number of the file.		
  1447                              <1> 	; If the file aready exists, it's mode and owner remain 
  1448                              <1> 	; unchanged, but it is truncated to zero length. If the file
  1449                              <1> 	; did not exist, an i-node is created with the new mode via
  1450                              <1> 	; 'maknod' whether or not the file already existed, it is
  1451                              <1> 	; open for writing. The fsp table is then searched for a free
  1452                              <1> 	; entry. When a free entry is found, proper data is placed
  1453                              <1> 	; in it and the number of this entry is put in the u.fp list.
  1454                              <1> 	; The index to the u.fp (also know as the file descriptor)
  1455                              <1> 	; is put in the user's r0. 			
  1456                              <1> 	;
  1457                              <1> 	; Calling sequence:
  1458                              <1> 	;	syscreate; name; mode
  1459                              <1> 	; Arguments:
  1460                              <1> 	;	name - name of the file to be created
  1461                              <1> 	;	mode - mode of the file to be created
  1462                              <1> 	; Inputs: (arguments)
  1463                              <1> 	; Outputs: *u.r0 - index to u.fp list 
  1464                              <1> 	;		   (the file descriptor of new file)
  1465                              <1> 	; ...............................................................
  1466                              <1> 	;				
  1467                              <1> 	; Retro UNIX 8086 v1 modification: 
  1468                              <1> 	;       'syscreate' system call has two arguments; so,
  1469                              <1> 	;	* 1st argument, name is pointed to by BX register
  1470                              <1> 	;	* 2nd argument, mode is in CX register
  1471                              <1> 	;
  1472                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1473                              <1> 	;	to the user with the file descriptor/number 
  1474                              <1> 	;	(index to u.fp list).
  1475                              <1> 	;
  1476                              <1> 	;call	arg2
  1477                              <1> 	; * name - 'u.namep' points to address of file/path name
  1478                              <1> 	;          in the user's program segment ('u.segmnt')
  1479                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1480                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1481                              <1> 	;          which is on top of stack.
  1482                              <1> 	;
  1483                              <1>         	; jsr r0,arg2 / put file name in u.namep put mode 
  1484                              <1> 			    ; / on stack
  1485 0000BADF 891D[C0300100]      <1> 	mov	[u.namep], ebx ; file name address
  1486 0000BAE5 6651                <1> 	push	cx ; mode
  1487 0000BAE7 E802100000          <1> 	call 	namei        	
  1488                              <1> 		; jsr r0,namei / get the i-number
  1489                              <1>         ;and	ax, ax
  1490                              <1> 	;jz	short syscreat_1	       	
  1491 0000BAEC 721E                <1> 	jc	short syscreat_1
  1492                              <1> 		; br  2f / if file doesn't exist 2f
  1493                              <1> 	; 27/12/2015
  1494 0000BAEE 6683F829            <1> 	cmp	ax, 41 ; device inode ?
  1495 0000BAF2 0F824EFFFFFF        <1>         jb      syscreat_0 ; yes
  1496                              <1> 	;
  1497 0000BAF8 66F7D8              <1> 	neg 	ax
  1498                              <1>         	; neg r1 / if file already exists make i-number 
  1499                              <1> 		       ; / negative (open for writing)
  1500 0000BAFB E8FE1E0000          <1> 	call	iopen
  1501                              <1>         	; jsr r0,iopen /
  1502 0000BB00 E8FB1E0000          <1> 	call	itrunc
  1503                              <1>         	; jsr r0,itrunc / truncate to 0 length
  1504 0000BB05 6659                <1> 	pop	cx ; pop mode (did not exist in original Unix v1 !?)
  1505 0000BB07 E948FFFFFF          <1>         jmp     sysopen_1
  1506                              <1>         	; br op0
  1507                              <1> syscreat_1: ; 2: / file doesn't exist
  1508 0000BB0C 6658                <1> 	pop	ax
  1509                              <1>         	; mov (sp)+,r1 / put the mode in r1
  1510 0000BB0E 30E4                <1> 	xor	ah, ah	
  1511                              <1>         	; bic $!377,r1 / clear upper byte
  1512 0000BB10 E8AC120000          <1> 	call 	maknod
  1513                              <1>         	; jsr r0,maknod / make an i-node for this file
  1514 0000BB15 66A1[DA300100]      <1> 	mov	ax, [u.dirbuf]
  1515                              <1>         	; mov u.dirbuf,r1 / put i-number 
  1516                              <1> 			        ; / for this new file in r1
  1517 0000BB1B E934FFFFFF          <1>         jmp     sysopen_1
  1518                              <1>         	; br op0 / open the file
  1519                              <1> 
  1520                              <1> sysmkdir: ; < make directory >
  1521                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1522                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  1523                              <1> 	;
  1524                              <1> 	; 'sysmkdir' creates an empty directory whose name is
  1525                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.	
  1526                              <1> 	; The special entries '.' and '..' are not present.
  1527                              <1> 	; Errors are indicated if the directory already exists or		
  1528                              <1> 	; user is not the super user. 
  1529                              <1> 	;
  1530                              <1> 	; Calling sequence:
  1531                              <1> 	;	sysmkdir; name; mode
  1532                              <1> 	; Arguments:
  1533                              <1> 	;	name - points to the name of the directory
  1534                              <1> 	;	mode - mode of the directory
  1535                              <1> 	; Inputs: (arguments)
  1536                              <1> 	; Outputs: -
  1537                              <1> 	;    (sets 'directory' flag to 1; 
  1538                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
  1539                              <1> 	; ...............................................................
  1540                              <1> 	;				
  1541                              <1> 	; Retro UNIX 8086 v1 modification: 
  1542                              <1> 	;       'sysmkdir' system call has two arguments; so,
  1543                              <1> 	;	* 1st argument, name is pointed to by BX register
  1544                              <1> 	;	* 2nd argument, mode is in CX register
  1545                              <1> 	;
  1546                              <1> 		
  1547                              <1> ; / make a directory
  1548                              <1> 
  1549                              <1> 	;call	arg2
  1550                              <1> 	; * name - 'u.namep' points to address of file/path name
  1551                              <1> 	;          in the user's program segment ('u.segmnt')
  1552                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1553                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1554                              <1> 	;          which is on top of stack.
  1555                              <1> 
  1556                              <1> 		; jsr r0,arg2 / put file name in u.namep put mode 
  1557                              <1> 			    ; / on stack
  1558 0000BB20 891D[C0300100]      <1> 	mov	[u.namep], ebx
  1559 0000BB26 6651                <1> 	push	cx ; mode
  1560 0000BB28 E8C10F0000          <1> 	call	namei
  1561                              <1>         	; jsr r0,namei / get the i-number
  1562                              <1>         	;     br .+4 / if file not found branch around error
  1563                              <1>         ;xor 	ax, ax
  1564                              <1> 	;jnz	error
  1565 0000BB2D 731C                <1> 	jnc	short dir_exists ; 14/05/2015
  1566                              <1> 	;jnc	error	
  1567                              <1> 		; br  error2 / directory already exists (error)
  1568 0000BB2F 803D[F4300100]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
  1569                              <1>         	;tstb u.uid / is user the super user
  1570 0000BB36 7622                <1> 	jna	short dir_access_err ; 14/05/2015
  1571                              <1> 	;jna	error
  1572                              <1>         	;bne error2 / no, not allowed
  1573 0000BB38 6658                <1> 	pop	ax
  1574                              <1>         	;mov (sp)+,r1 / put the mode in r1
  1575 0000BB3A 6683E0CF            <1> 	and	ax, 0FFCFh ; 1111111111001111b
  1576                              <1>         	;bic $!317,r1 / all but su and ex
  1577                              <1> 	;or	ax , 4000h ; 1011111111111111b
  1578 0000BB3E 80CC40              <1> 	or	ah, 40h ; Set bit 14 to 1
  1579                              <1>         	;bis $40000,r1 / directory flag
  1580 0000BB41 E87B120000          <1> 	call	maknod
  1581                              <1>         	;jsr r0,maknod / make the i-node for the directory
  1582 0000BB46 E9F9FAFFFF          <1> 	jmp	sysret
  1583                              <1>         	;br sysret2 /
  1584                              <1> dir_exists:
  1585                              <1> 	; 14/05/2015
  1586 0000BB4B C705[FD300100]0E00- <1> 	mov	dword [u.error], ERR_DIR_EXISTS ; dir. already exists !
  1586 0000BB53 0000                <1>
  1587 0000BB55 E9CAFAFFFF          <1> 	jmp	error
  1588                              <1> dir_access_err:
  1589                              <1> 	; 14/05/2015
  1590 0000BB5A C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_DIR_ACCESS ; permission denied !
  1590 0000BB62 0000                <1>
  1591 0000BB64 E9BBFAFFFF          <1> 	jmp	error
  1592                              <1> 
  1593                              <1> sysclose: ;<close file>
  1594                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1595                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
  1596                              <1> 	;
  1597                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
  1598                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
  1599                              <1> 	; is put in r1 and 'fclose' is called.
  1600                              <1> 	;
  1601                              <1> 	; Calling sequence:
  1602                              <1> 	;	sysclose
  1603                              <1> 	; Arguments:
  1604                              <1> 	;	-  
  1605                              <1> 	; Inputs: *u.r0 - file descriptor
  1606                              <1> 	; Outputs: -
  1607                              <1> 	; ...............................................................
  1608                              <1> 	;				
  1609                              <1> 	; Retro UNIX 8086 v1 modification:
  1610                              <1> 	;	 The user/application program puts file descriptor
  1611                              <1> 	;        in BX register as 'sysclose' system call argument.
  1612                              <1> 	; 	 (argument transfer method 1)
  1613                              <1> 
  1614                              <1> 	; / close the file
  1615                              <1> 	
  1616 0000BB69 89D8                <1> 	mov 	eax, ebx
  1617 0000BB6B E8FC0E0000          <1> 	call 	fclose
  1618                              <1> 		; mov *u.r0,r1 / move index to u.fp list into r1
  1619                              <1> 		; jsr r0,fclose / close the file
  1620                              <1>                	; br error2 / unknown file descriptor
  1621                              <1> 		; br sysret2
  1622                              <1> 	; 14/05/2015
  1623 0000BB70 0F83CEFAFFFF        <1> 	jnc	sysret
  1624 0000BB76 C705[FD300100]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
  1624 0000BB7E 0000                <1>
  1625 0000BB80 E99FFAFFFF          <1> 	jmp	error
  1626                              <1> 
  1627                              <1> sysemt: ; enable (or disable) multi tasking -time sharing-
  1628                              <1> 	;
  1629                              <1> 	; 23/05/2016 - TRDOS 386 (TRDOS v2.0)
  1630                              <1> 	; 14/05/2015 (Retro UNIX 386 v1)
  1631                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
  1632                              <1> 	;
  1633                              <1> 	; Retro UNIX 8086 v1 modification: 
  1634                              <1> 	;	'Enable Multi Tasking'  system call instead 
  1635                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
  1636                              <1> 	;
  1637                              <1> 	; Retro UNIX 8086 v1 feature only!
  1638                              <1> 	;	Using purpose: Kernel will start without time-out
  1639                              <1> 	;	(internal clock/timer) functionality.
  1640                              <1> 	;	Then etc/init will enable clock/timer for
  1641                              <1> 	;	multi tasking. 
  1642                              <1> 	;
  1643                              <1> 	; INPUT ->
  1644                              <1> 	;	BL = 0 -> disable multi tasking
  1645                              <1> 	;	BL > 1 -> enable multi tasking (time sharing) 
  1646                              <1> 	; OUTPUT ->
  1647                              <1> 	;	none	
  1648                              <1> 	;
  1649                              <1> 	;  Note: Multi tasking is disabled during system
  1650                              <1> 	;	 initialization, it must be enabled by using
  1651                              <1> 	;	 this system call. (Otherwise, running proces 
  1652                              <1> 	;	 will not be changed by another process within
  1653                              <1> 	;	 run time sequence/schedule, if running process
  1654                              <1> 	;	 will not 'release' itself. Only 'wakeup' procedure
  1655                              <1> 	;	 for waiting processes and programmed timer events
  1656                              <1> 	;	 for other processes can change running process 
  1657                              <1> 	;	 while multi tasking is disabled.) ** 23/05/2016 **
  1658                              <1> 
  1659 0000BB85 803D[F4300100]00    <1> 	cmp	byte [u.uid], 0 ; root ?
  1660                              <1> 	;ja	error
  1661 0000BB8C 0F873BFBFFFF        <1> 	ja	badsys ; 14/05/2015
  1662                              <1> 	;
  1663 0000BB92 FA                  <1> 	cli
  1664 0000BB93 881D[4E2D0100]      <1> 	mov	[multi_tasking], bl ; 0 to disable, >0 to enable
  1665 0000BB99 E9A6FAFFFF          <1> 	jmp	sysret
  1666                              <1> 
  1667                              <1> systimer:
  1668                              <1> 	; 10/06/2016
  1669                              <1> 	; 07/06/2016
  1670                              <1> 	; 06/06/2016
  1671                              <1> 	; 21/05/2016
  1672                              <1> 	; 19/05/2016
  1673                              <1> 	; 18/05/2016 - TRDOS 386 (TRDOS v2.0)
  1674                              <1> 	; (TRDOS 386 feature only!)
  1675                              <1> 	;
  1676                              <1> 	; (start or stop timer event(s))	
  1677                              <1> 	;
  1678                              <1> 	; INPUT ->
  1679                              <1> 	;	BL = Signal return byte (response byte)
  1680                              <1> 	;	     (Any requested value between 0 and 255)
  1681                              <1> 	;	     (Kernel will put it at the requested address)    	
  1682                              <1> 	;	BH = Time count unit
  1683                              <1> 	;	     0 = Stop timer event
  1684                              <1> 	;	     1 = 18.2 ticks per second
  1685                              <1> 	;	     2 = 10 milliseconds  		
  1686                              <1> 	;	     3 = 1 second (for real time clock interrupt) 	 
  1687                              <1> 	;	     4 to 255 = undefined
  1688                              <1> 	;	BH = 0 -> Stop timer event
  1689                              <1> 	;	BL = Timer event number (1 to 255) if BH = 0     	
  1690                              <1> 	;	     If BL = 0, all timer events (which are belongs
  1691                              <1> 	;	      to running process) will be stopped 		    
  1692                              <1> 	;	ECX = Time/Tick count (depending on time count unit)
  1693                              <1> 	;	EDX = Signal return (Response) byte address
  1694                              <1> 	;	      (virtual address in user's memory space)
  1695                              <1> 	; OUTPUT ->
  1696                              <1> 	;	AL = Timer event number	(1 to 255) (max. value = 16)
  1697                              <1> 	;	IF BH Input = 0 & CF = 0 & AL = 0 -> 
  1698                              <1> 	;	     timer event(s) has/have been stopped/finished
  1699                              <1> 	;	CF = 1 & AL = 0 -> no timer setting space to set
  1700                              <1> 	;	CF = 1 & AL > 0 -> timer count unit is not usable
  1701                              <1> 	;
  1702                              <1> 	;	NOTE: To modify a time count for a user function,
  1703                              <1> 	;	      at first, current timer event must be stopped
  1704                              <1> 	;	      then a new timer event (which is related with
  1705                              <1> 	;	      same user function) must be started.
  1706                              <1> 	;		
  1707                              <1> 	;	      Signal return (response) byte may be used for 
  1708                              <1> 	;	      several purposes. Kernel will put this value 
  1709                              <1> 	;	      to requested address during timer interrupt,
  1710                              <1> 	;	      program/user can check this value to understand
  1711                              <1> 	;	      which event has been occurred and what is changed.
  1712                              <1> 	;	      (Multi timer events can share same signal address)
  1713                              <1> 	;	
  1714                              <1> 	;	NOTE: If the process is running while the time count
  1715                              <1> 	;	      is reached, kernel will put signal return (response)
  1716                              <1> 	;	      byte value at requested address during timer
  1717                              <1> 	;	      interrupt and the process will continue to run.
  1718                              <1> 	;	      Program/process must call (jump to) it's timer event
  1719                              <1> 	;	      function as required, for checking the timer event
  1720                              <1> 	;	      status via signal return (response) byte address. 
  1721                              <1> 	;
  1722                              <1> 	;	      If the process is not running (waiting or sleeping
  1723                              <1> 	;	      or released) while the time count is reached,
  1724                              <1> 	;	      it is restarted from where it left, to ensure
  1725                              <1> 	;	      proper multi media (video, audio, clock, timer)
  1726                              <1> 	;	      functionality.
  1727                              <1> 	;
  1728                              <1> 	;	      (It is better to use 'syswait' or 'syssleep',
  1729                              <1> 	;	      or 'sysrele' system call just after the timer
  1730                              <1> 	;	      function. Otherwise, timer events may block other
  1731                              <1> 	;	      processes which are not using timer events.)  	 		 			 		 	
  1732                              <1> 	;	     	      		 			
  1733                              <1> 	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  1734                              <1> 	;       Owner:	        resb 1 ; 0 = free
  1735                              <1> 	;		  	       ;>0 = process number (u.uno)
  1736                              <1> 	;	Reserved:	resb 1 ; 0
  1737                              <1> 	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  1738                              <1> 	;		   	       ; 1 = Real Time Clock interrupt 
  1739                              <1> 	;	Response:       resb 1 ; 0 to 255, signal return value
  1740                              <1> 	;	Count Limit:	resd 1 ; count of ticks (total/set)
  1741                              <1> 	;	Current Count: 	resd 1 ; count of ticks (current)
  1742                              <1> 	;	Response Addr:  resd 1 ; response byte (pointer) address
  1743                              <1> 	;
  1744                              <1> 
  1745 0000BB9E 80FF02              <1> 	cmp	bh, 2
  1746 0000BBA1 7445                <1>         je      short systimer_5  ; only 18.2 ticks per second is usable
  1747                              <1> 				  ; 10 milliseconds (100 Hertz) timer 
  1748                              <1> 				  ; will be set later (18/05/2016)
  1749 0000BBA3 774B                <1>         ja      short systimer_6 
  1750                              <1> 
  1751 0000BBA5 20FF                <1> 	and	bh, bh
  1752 0000BBA7 0F8490000000        <1>         jz      systimer_9        ; stop timer event(s)
  1753                              <1> 
  1754                              <1> 	; bh = 1 (timer interrupt, 18.2 Hz, IBM PC/AT ROMBIOS default)
  1755                              <1> 
  1756 0000BBAD B00A                <1> 	mov	al, 10 ; (*)
  1757                              <1> 
  1758                              <1> systimer_0:
  1759 0000BBAF B710                <1> 	mov	bh, 16
  1760                              <1> 	;
  1761 0000BBB1 383D[4F2D0100]      <1> 	cmp	[timer_events], bh ; 16 ; 07/06/2016
  1762 0000BBB7 7319                <1> 	jnb 	short systimer_3  ; max. 16 timer events
  1763                              <1> 	;
  1764 0000BBB9 50                  <1> 	push	eax ; (*)
  1765                              <1> 
  1766 0000BBBA BF[6C3D0100]        <1> 	mov	edi, timer_set  ; beginning address of timer events
  1767                              <1> 				; setting space
  1768 0000BBBF 30C0                <1> 	xor	al, al ; 0
  1769                              <1> systimer_1:
  1770 0000BBC1 FEC0                <1> 	inc	al
  1771 0000BBC3 803F00              <1> 	cmp	byte [edi], 0 	; is it free space ?
  1772 0000BBC6 7631                <1> 	jna	short systimer_7 ; yes
  1773 0000BBC8 FECF                <1> 	dec	bh
  1774 0000BBCA 7405                <1> 	jz	short systimer_2
  1775 0000BBCC 83C710              <1> 	add	edi, 16
  1776 0000BBCF EBF0                <1> 	jmp	short  systimer_1 ; next event space
  1777                              <1> 
  1778                              <1> systimer_2:
  1779 0000BBD1 58                  <1> 	pop	eax ; (*) discard
  1780                              <1> systimer_3:
  1781 0000BBD2 C605[A8300100]00    <1> 	mov	byte [u.r0], 0
  1782                              <1> systimer_4:
  1783 0000BBD9 C705[FD300100]1A00- <1>         mov     dword [u.error], ERR_MISC
  1783 0000BBE1 0000                <1>
  1784                              <1>                                 ; one of miscellaneous/other errors
  1785 0000BBE3 E93CFAFFFF          <1> 	jmp	error ; cf -> 1
  1786                              <1> 
  1787                              <1> systimer_5:
  1788 0000BBE8 883D[A8300100]      <1> 	mov	[u.r0], bh ; Time count unit (=2 or >3)
  1789 0000BBEE EBE9                <1> 	jmp	short systimer_4 ; 07/06/2016
  1790                              <1> 
  1791                              <1> systimer_6:
  1792 0000BBF0 80FF03              <1> 	cmp	bh, 3
  1793 0000BBF3 77F3                <1>         ja      short systimer_5  ; undefined time count unit
  1794                              <1> 
  1795                              <1> 	; bh = 3
  1796                              <1> 	; timer event via real time clock interrupt
  1797                              <1> 	; interrupt/update frequency: 1 Hz (1 tick per second)
  1798                              <1> 	
  1799 0000BBF5 B0B6                <1> 	mov	al, 182 ; (*) ; 18.2 * 10
  1800 0000BBF7 EBB6                <1>         jmp     short systimer_0
  1801                              <1> 
  1802                              <1> systimer_7:
  1803 0000BBF9 A2[A8300100]        <1> 	mov	[u.r0], al ; timer event number
  1804                              <1> 	;
  1805                              <1> 	; edi = address of empty timer event area
  1806 0000BBFE A0[F7300100]        <1> 	mov	al, [u.uno]
  1807 0000BC03 FA                  <1> 	cli 	; disable interrupts 
  1808 0000BC04 AA                  <1> 	stosb	; process number
  1809 0000BC05 D0E0                <1> 	shl	al, 1
  1810 0000BC07 89C6                <1> 	mov	esi, eax
  1811 0000BC09 28C0                <1> 	sub	al, al
  1812 0000BC0B AA                  <1> 	stosb 	; reserved (=0)
  1813 0000BC0C B001                <1> 	mov	al, 1 ; this is for real time clock interrupt
  1814 0000BC0E AA                  <1> 	stosb	; interrupt type
  1815 0000BC0F 88D8                <1> 	mov	al, bl ; Signal return (Response) value
  1816 0000BC11 AA                  <1> 	stosb  ; response byte
  1817 0000BC12 58                  <1> 	pop	eax ; (*) ; 10 or 182
  1818 0000BC13 89D3                <1> 	mov	ebx, edx ; virtual address for response/signal byte
  1819 0000BC15 F7E1                <1> 	mul	ecx
  1820                              <1> 	; (eax = 10 * count of 18.2 Hz timer ticks)
  1821                              <1> 	; (count down step = 10)
  1822 0000BC17 AB                  <1> 	stosd  ; count limit (reset value)
  1823 0000BC18 AB                  <1> 	stosd  ; current count value
  1824                              <1> 	; ebx = virtual address
  1825                              <1> 	; [u.pgdir] = page directory's physical address
  1826 0000BC19 E8E090FFFF          <1> 	call	get_physical_addr
  1827 0000BC1E 720D                <1> 	jc	short systimer_8 ; 07/06/2016
  1828                              <1> 	; eax = physical address of the virtual address in user's space
  1829 0000BC20 AB                  <1> 	stosd	; response address (physical)
  1830 0000BC21 FE05[4F2D0100]      <1> 	inc	byte [timer_events] ; 07/06/201
  1831 0000BC27 FB                  <1> 	sti 	; enable interrupts
  1832 0000BC28 E917FAFFFF          <1> 	jmp	sysret
  1833                              <1> 
  1834                              <1> systimer_8:
  1835                              <1> 	; 10/06/2016
  1836                              <1> 	; 07/06/2016
  1837 0000BC2D 28C0                <1> 	sub	al, al ; 0
  1838 0000BC2F 8847F4              <1> 	mov	[edi-12], al ; clear process nummber (free timer event)
  1839                              <1> 	;mov	dword [edi], eax ; 0
  1840 0000BC32 FB                  <1> 	sti
  1841 0000BC33 A2[A8300100]        <1> 	mov	[u.r0], al ; 0
  1842 0000BC38 E9E7F9FFFF          <1> 	jmp	error
  1843                              <1> 
  1844                              <1> systimer_9:
  1845                              <1> 	; 10/06/2016
  1846                              <1> 	; 07/06/2016
  1847 0000BC3D 28C0                <1> 	sub	al, al
  1848 0000BC3F A2[A8300100]        <1> 	mov	byte [u.r0], al ; 0
  1849 0000BC44 3805[4F2D0100]      <1> 	cmp     byte [timer_events], al ;  0
  1850 0000BC4A 7631                <1> 	jna	short systimer_12
  1851                              <1> 
  1852                              <1> 	; Note: ecx and edx are undefined here
  1853                              <1> 	;	(for stop timer function)
  1854                              <1> 
  1855 0000BC4C BE[6C3D0100]        <1> 	mov	esi, timer_set  ; beginning address of timer events
  1856                              <1> 				; setting space	 
  1857 0000BC51 A0[F7300100]        <1> 	mov	al, [u.uno]
  1858                              <1> 	
  1859 0000BC56 B710                <1> 	mov	bh, 16
  1860                              <1> 
  1861 0000BC58 08DB                <1> 	or	bl, bl
  1862 0000BC5A 7544                <1> 	jnz	short systimer_15
  1863                              <1> 
  1864                              <1> 	; clear timer event areas belong to current process
  1865                              <1> 	; (for stopping all timer events belong to current process) 
  1866 0000BC5C FA                  <1> 	cli 	; disable interrupts
  1867                              <1> systimer_10:
  1868                              <1> 	; 10/06/2016
  1869                              <1> 	; 07/06/2016 	
  1870 0000BC5D 8A26                <1> 	mov	ah, [esi]
  1871 0000BC5F 08E4                <1> 	or	ah, ah ; 0 ?
  1872 0000BC61 7411                <1> 	jz	short systimer_11
  1873 0000BC63 38C4                <1> 	cmp	ah, al ; is the process ID (owner) same ?
  1874 0000BC65 750D                <1>         jne     short systimer_11 ; no
  1875                              <1> 
  1876                              <1> 	;mov	byte [esi], 0
  1877 0000BC67 66C7060000          <1> 	mov	word [esi], 0 ; clear
  1878                              <1> 	;mov	dword [esi+12], 0 ; clear
  1879                              <1> 
  1880 0000BC6C FE0D[4F2D0100]      <1> 	dec	byte [timer_events]
  1881 0000BC72 7409                <1> 	jz	short systimer_12
  1882                              <1> 
  1883                              <1> systimer_11:
  1884 0000BC74 FECF                <1> 	dec	bh
  1885 0000BC76 7405                <1> 	jz	short systimer_12
  1886 0000BC78 83C610              <1> 	add	esi, 16
  1887 0000BC7B EBE0                <1> 	jmp	short systimer_10
  1888                              <1> 
  1889                              <1> systimer_12:
  1890 0000BC7D 0FB635[F7300100]    <1> 	movzx	esi, byte [u.uno]
  1891 0000BC84 08DB                <1> 	or	bl, bl ; all timer events or one timer event ?
  1892 0000BC86 740C                <1> 	jz	short systimer_13
  1893 0000BC88 8A9E[6B2E0100]      <1> 	mov	bl, [esi+p.timer-1]
  1894 0000BC8E 20DB                <1> 	and	bl, bl	; previous number of timer events for the process
  1895 0000BC90 7408                <1> 	jz	short systimer_14
  1896 0000BC92 FECB                <1> 	dec	bl  ; previous number of timer events for the process - 1
  1897                              <1> systimer_13:
  1898 0000BC94 889E[6B2E0100]      <1> 	mov	[esi+p.timer-1], bl ; 0 ; no timer events for process
  1899                              <1> systimer_14:
  1900 0000BC9A FB                  <1> 	sti	; enable interrupts
  1901 0000BC9B E9A4F9FFFF          <1> 	jmp	sysret
  1902                              <1> 
  1903                              <1> systimer_15:
  1904 0000BCA0 38FB                <1> 	cmp	bl, bh ; 16
  1905 0000BCA2 0F8731FFFFFF        <1>         ja      systimer_4      ; max. 16 timer events !
  1906                              <1> 	;
  1907 0000BCA8 88DA                <1> 	mov	dl, bl
  1908 0000BCAA FECA                <1> 	dec	dl  ; 16 -> 15 ... 1 -> 0 
  1909 0000BCAC C0E204              <1> 	shl	dl, 4 ; * 16
  1910 0000BCAF 0FB6FA              <1> 	movzx	edi, dl
  1911 0000BCB2 01F7                <1> 	add	edi, esi ; timer_set 
  1912                              <1> 	
  1913 0000BCB4 3A07                <1> 	cmp	al, [edi] ; process number
  1914 0000BCB6 0F851DFFFFFF        <1>         jne     systimer_4
  1915                              <1> 	
  1916                              <1> 	; same process ID
  1917 0000BCBC FA                  <1> 	cli	; disable interrupts
  1918                              <1>  	; 10/06/2016
  1919                              <1> 	;mov	byte [esi], 0 
  1920 0000BCBD 66C7060000          <1> 	mov	word [esi], 0 ; clear
  1921                              <1> 	;mov	dword [esi+12], 0 ; clear
  1922 0000BCC2 FE0D[4F2D0100]      <1> 	dec	byte [timer_events]
  1923 0000BCC8 EBB3                <1> 	jmp	short systimer_12
  1924                              <1> 
  1925                              <1> sysmdate: ; < change the modification time of a file >
  1926                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
  1927                              <1> 	; 03/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  1928                              <1> 	;
  1929                              <1> 	; 'sysmdate' is given a file name. It gets inode of this 
  1930                              <1> 	; file into core. The user is checked if he is the owner 
  1931                              <1> 	; or super user. If he is neither an error occurs.
  1932                              <1> 	; 'setimod' is then called to set the i-node modification
  1933                              <1> 	; byte and the modification time, but the modification time
  1934                              <1> 	; is overwritten by whatever get put on the stack during
  1935                              <1> 	; a 'systime' system call. This calls are restricted to
  1936                              <1> 	; the super user.		
  1937                              <1> 	;
  1938                              <1> 	; Calling sequence:
  1939                              <1> 	;	sysmdate; name
  1940                              <1> 	; Arguments:
  1941                              <1> 	;	name - points to the name of file
  1942                              <1> 	; Inputs: (arguments)
  1943                              <1> 	; Outputs: -
  1944                              <1> 	; ...............................................................
  1945                              <1> 	;				
  1946                              <1> 	; Retro UNIX 8086 v1 modification: 
  1947                              <1> 	;	 The user/application program puts address 
  1948                              <1> 	;	 of the file name in BX register 
  1949                              <1> 	;	 as 'sysmdate' system call argument.
  1950                              <1> 	;
  1951                              <1> ; / change the modification time of a file
  1952                              <1> 		; jsr r0,arg; u.namep / point u.namep to the file name
  1953 0000BCCA 891D[C0300100]      <1>         mov	[u.namep], ebx
  1954 0000BCD0 E8190E0000          <1> 	call	namei
  1955                              <1> 		; jsr r0,namei / get its i-number
  1956 0000BCD5 0F829EFDFFFF        <1>         jc	fnotfound ; file not found !
  1957                              <1> 	;jc	error       
  1958                              <1> 		; br error2 / no, such file
  1959 0000BCDB E81A1D0000          <1> 	call	iget
  1960                              <1> 		; jsr r0,iget / get i-node into core
  1961 0000BCE0 A0[F4300100]        <1> 	mov	al, [u.uid]
  1962 0000BCE5 3A05[6F2D0100]      <1> 	cmp	al, [i.uid]
  1963                              <1>         	; cmpb u.uid,i.uid / is user same as owner
  1964 0000BCEB 7413                <1> 	je	short mdate_1
  1965                              <1>         	; beq 1f / yes
  1966 0000BCED 20C0                <1> 	and	al, al
  1967                              <1> 		; tstb u.uid / no, is user the super user
  1968                              <1> 	;jnz	error
  1969                              <1> 		; bne error2 / no, error
  1970 0000BCEF 740F                <1> 	jz	short mdate_1
  1971 0000BCF1 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
  1971 0000BCF9 0000                <1>
  1972 0000BCFB E924F9FFFF          <1> 	jmp	error
  1973                              <1> mdate_1: ;1:
  1974 0000BD00 E8FC1C0000          <1> 	call	setimod
  1975                              <1>         	; jsr r0,setimod / fill in modification data,
  1976                              <1> 		               ; / time etc.
  1977 0000BD05 BE[0C200100]        <1> 	mov	esi, p_time
  1978 0000BD0A BF[862D0100]        <1> 	mov	edi, i.mtim
  1979 0000BD0F A5                  <1> 	movsd
  1980                              <1> 		; mov 4(sp),i.mtim / move present time to
  1981                              <1>         	; mov 2(sp),i.mtim+2 / modification time
  1982 0000BD10 E92FF9FFFF          <1>         jmp	sysret
  1983                              <1> 		; br sysret2
  1984                              <1> 
  1985                              <1> sysvideo: ; VIDEO DATA TRANSFER FUNCTIONS
  1986                              <1> 	; 11/07/2016
  1987                              <1> 	; 13/06/2016
  1988                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  1989                              <1> 	;
  1990                              <1> 	;
  1991                              <1> 	; VIDEO DATA TRANSFER FUNCTIONS:
  1992                              <1> 	;
  1993                              <1> 	; Inputs:
  1994                              <1> 	;	BH = 0 = VIDEO BIOS Mode 3, tty/text mode data transfers
  1995                              <1> 	;	     BL = 
  1996                              <1> 	;		Bits 0&1, Transfer direction
  1997                              <1> 	;	     	 	0 - System to system
  1998                              <1> 	;			1 - User to system
  1999                              <1> 	;			2 - System to user
  2000                              <1> 	;			3 - User to user
  2001                              <1> 	;		Bits 2&3, Transfer Type
  2002                              <1> 	;			0 - Display page transfer	
  2003                              <1> 	;	     		1 - Display page window transfer
  2004                              <1> 	;	     		2 - Frame/Viewport/Window address transfer
  2005                              <1> 	;			3 - Window handle transfer		
  2006                              <1> 	;
  2007                              <1> 	;	     /// BL = 0 -> System to system (display page) transfer
  2008                              <1> 	;		 CL = Source page 
  2009                              <1> 	;		 DL = Destination page
  2010                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2011                              <1> 	;		 ECX = User buffer
  2012                              <1> 	;		 DL = Video page
  2013                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2014                              <1> 	;		(window in current display page and in current mode)	 	 		
  2015                              <1> 	;		 ESI = User's buffer address
  2016                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2017                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2018                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2019                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2020                              <1>         ;                If BL = 5 ->
  2021                              <1> 	;		 EDI = Swap address (in user's memory space)
  2022                              <1> 	;		 (If swap address > 0, previous content of the window
  2023                              <1> 	;		 will be saved into swap area in user's memory space)		
  2024                              <1> 	;	     /// BL = 4 -> system to system transfer 
  2025                              <1> 	;		 ESI = System's source buffer (video page) address
  2026                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2027                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2028                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2029                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2030                              <1> 	;		 EDI = System's destination buffer (video page) address
  2031                              <1> 	;
  2032                              <1> 	;	BH = 1 = CGA Graphics (0B8000h) data transfers
  2033                              <1> 	;	     BL = 
  2034                              <1> 	;	     	0 = Fill color (color in CL] (32K)
  2035                              <1> 	;		1 = User to system display page transfer
  2036                              <1> 	;		2 = System to user display page transfer
  2037                              <1> 	;		3 = NOT bits in window (ECX, EDX)
  2038                              <1> 	;		4 = Window copy (system to system)	
  2039                              <1> 	;	     	5 = User to system window transfer
  2040                              <1> 	;	     	6 = System to user window transfer
  2041                              <1> 	;		7 = AND display page bytes with CL
  2042                              <1> 	;		8 = OR display page bytes with CL
  2043                              <1> 	;		9 = XOR display page bytes with CL
  2044                              <1> 	;
  2045                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2046                              <1> 	;		 CL = Color value 
  2047                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2048                              <1> 	;		 ECX = User buffer
  2049                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2050                              <1> 	;		(window in current display page and in current mode)	 	 		
  2051                              <1> 	;		 ESI = User's buffer address
  2052                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2053                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2054                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2055                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2056                              <1>         ;	     /// BL = 4 -> system to system (window) transfer 
  2057                              <1> 	;		 ESI = System's source buffer (video page) address
  2058                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2059                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2060                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2061                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2062                              <1> 	;		 EDI = System's destination buffer (video page) address
  2063                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2064                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2065                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2066                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2067                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2068                              <1> 	;
  2069                              <1> 	;	BH = 2 = VGA Graphics (0A0000h) data transfers
  2070                              <1> 	;	     BL = 
  2071                              <1> 	;	     	x0h = Fill color (color in CL] (64K)
  2072                              <1> 	;		x1h = User to system display page transfer
  2073                              <1> 	;		x2h = System to user display page transfer
  2074                              <1> 	;		x3h = NOT bits in window (ECX, EDX)
  2075                              <1> 	;		x4h = Window copy (system to system)	
  2076                              <1> 	;	     	x5h = User to system window transfer
  2077                              <1> 	;	     	x6h = System to user window transfer
  2078                              <1> 	;		x7h = AND display page bytes with CL
  2079                              <1> 	;		x8h = OR display page bytes with CL
  2080                              <1> 	;		x9h = XOR display page bytes with CL
  2081                              <1> 	;		x = 0 -> screen width = 320
  2082                              <1> 	;		x = 1 -> screen width = 640
  2083                              <1> 	;		x = 2 -> screen width = 800
  2084                              <1> 	;
  2085                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2086                              <1> 	;		 CL = Color value 
  2087                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2088                              <1> 	;		 ECX = User buffer
  2089                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2090                              <1> 	;		(window in current display page and in current mode)	 	 		
  2091                              <1> 	;		 ESI = User's buffer address
  2092                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2093                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2094                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2095                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2096                              <1>        	;	     /// BL = 4 -> system to system (window) transfer 
  2097                              <1> 	;		 ESI = System's source buffer (video page) address
  2098                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2099                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2100                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2101                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2102                              <1> 	;		 EDI = System's destination buffer (video page) address
  2103                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2104                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2105                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2106                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2107                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2108                              <1> 	;
  2109                              <1> 	;	BH = 3 = Super VGA, LINEAR FRAME BUFFER data transfers
  2110                              <1> 	;	     BL = 
  2111                              <1> 	;	     	0 = Fill color (color in ECX] (Frame buffer size)
  2112                              <1> 	;		1 = User to system display page transfer
  2113                              <1> 	;		2 = System to user display page transfer
  2114                              <1> 	;		3 = NOT bits in window (ECX, EDX)
  2115                              <1> 	;		4 = Window copy (system to system)	
  2116                              <1> 	;	     	5 = User to system window transfer
  2117                              <1> 	;	     	6 = System to user window transfer
  2118                              <1> 	;		7 = AND display page bytes with ECX
  2119                              <1> 	;		8 = OR display page bytes with ECX
  2120                              <1> 	;		9 = XOR display page bytes with ECX
  2121                              <1> 	;
  2122                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2123                              <1> 	;		 CL = Color value 
  2124                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2125                              <1> 	;		 ECX = User buffer
  2126                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2127                              <1> 	;		(window in current display page and in current mode)	 	 		
  2128                              <1> 	;		 ESI = User's buffer address
  2129                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2130                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2131                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2132                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2133                              <1> 	;	     /// BL = 4 -> system to system (window) transfer 
  2134                              <1> 	;		 ESI = System's source buffer (video page) address
  2135                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2136                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2137                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2138                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2139                              <1> 	;		 EDI = System's destination buffer (video page) address
  2140                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2141                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2142                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2143                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2144                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2145                              <1> 	;
  2146                              <1> 	; Outputs:
  2147                              <1> 	;	EAX = transfer/byte count
  2148                              <1> 	;
  2149                              <1> 	;	NOTE: If the source or destination address passes out of
  2150                              <1> 	;	video pages (display memory limits), data will not be transferred
  2151                              <1> 	;	and EAX will return as 0.
  2152                              <1> 	;
  2153                              <1> 	;
  2154                              <1> 	; DIRECT (STANDARD VGA/CGA) DISPLAY MEMORY ACCESS FUNCTIONS:
  2155                              <1> 	;
  2156                              <1> 	;	BH = 4 = CGA direct video memory (0B8000h, 32K) access
  2157                              <1> 	;		Page directory & page tables of the user's
  2158                              <1> 	;		program will be updated to direct access to
  2159                              <1> 	;		0B8000h (32K) video (CGA, color) memory; if
  2160                              <1> 	;		there is not a permission  conflict or lock!  
  2161                              <1> 	;	        (User's program/process will have permision to
  2162                              <1> 	;		access locked display memory if the owner is
  2163                              <1> 	;		it's parent.)
  2164                              <1>         ;
  2165                              <1> 	;	    Screen width = 320	
  2166                              <1> 	;
  2167                              <1> 	;	BH = 5 = VGA direct video memory (0A0000h, 64K) access
  2168                              <1> 	;		Page directory & page tables of the user's
  2169                              <1> 	;		program will be updated to direct access to
  2170                              <1> 	;		0A0000h (64K) video (VGA) memory; if there is not
  2171                              <1> 	;		a permission conflict or lock!  
  2172                              <1> 	;	        (User's program/process will have permision to
  2173                              <1> 	;		access locked display memory if the owner is
  2174                              <1> 	;		it's parent.)
  2175                              <1> 	;		
  2176                              <1> 	;	    BL = Screen width (320, 640, 800) 
  2177                              <1> 	;			
  2178                              <1> 	; Outputs:
  2179                              <1> 	;	EAX = Display mmory address for direct access
  2180                              <1> 	;	      0A0000h for VGA, 0B8000h for CGA	
  2181                              <1> 	;	(Display memory size: 32K for CGA, 64K for VGA)
  2182                              <1> 	; 	EAX = 0 if display page access permission has been denied. 
  2183                              <1> 	;	      (Locked!) 	
  2184                              <1> 	;	      	 	
  2185                              <1> 	; LINEAR FRAME BUFFER ACCESS FUNCTIONS:
  2186                              <1> 	;
  2187                              <1> 	;	BH = 6 = Linear Frame Buffer direct video memory access
  2188                              <1> 	;
  2189                              <1> 	;		Page directory & page tables of the user's
  2190                              <1> 	;		program will be updated to direct access to
  2191                              <1> 	;		the configured LFB (Linear Frame Buffer) address,
  2192                              <1> 	;		if there is not a permission conflict or lock!  
  2193                              <1> 	;	        (User's program/process will have permision to
  2194                              <1> 	;		access locked display memory if the owner is
  2195                              <1> 	;		it's parent.)
  2196                              <1> 	;			
  2197                              <1> 	;		Return: EAX = Linear Frame Buffer address
  2198                              <1> 	;			EDX = Frame Buffer Size in bytes	
  2199                              <1> 	;	
  2200                              <1> 	;	BH = 7 = Get Linear Frame Buffer info (for current mode)
  2201                              <1> 	;		
  2202                              <1> 	;		Return:
  2203                              <1> 	;		EAX = Frame Buffer Address (0 = is not in use)
  2204                              <1> 	;		EDX = Frame Buffer Size in bytes
  2205                              <1> 	;		BL = Current Video Mode
  2206                              <1> 	;		     BL = 0FFh -> Super VGA (Extended VGA)
  2207                              <1> 	;		     If BL = 0FFh, 
  2208                              <1>         ;                       BH = 0 = 16 colors
  2209                              <1> 	;			BH = 1 = 256 colors
  2210                              <1> 	;			BH = 2 = 66536 colors
  2211                              <1> 	;			BH = 3 = 24 bits TRUE (16M) colors
  2212                              <1> 	;			BH = 4 = 32 bits TRUE (16M) colors
  2213                              <1> 	;		ECX = Pixel resolution
  2214                              <1> 	;		      CX = Width (640, 800, 1024, 1366, 1920)
  2215                              <1> 	;		      High 16 bits of ECX = Height  
  2216                              <1> 	;
  2217                              <1> 	;	NOTE: Each process will have it's own frame buffer
  2218                              <1> 	;	      address and resolution parameters in 'u' area.
  2219                              <1> 	;	      Then, if the current frame buffer & resolution
  2220                              <1> 	;	      is different, frame buffer r/w functions
  2221                              <1> 	;	      will use scale factor to convert process's
  2222                              <1>         ;             pixel coordinates to actual screen coordinates.                            
  2223                              <1> 	;	      resolution -> dimensional scale
  2224                              <1> 	;	      color size -> color scale
  2225                              <1> 	;	     * RGB (TRUE) colors to 256 colors conversion:	
  2226                              <1>         ;             TRUE Colors -> 8,8,8 (R,G,B; byte 0 is R)            
  2227                              <1> 	;	      256 colors -> 2,2,2,2 (R,G,B,L; bit 0&1 is R)
  2228                              <1> 	; 		  bit 6&7 -> luminosity base level (0,1,2,3)
  2229                              <1> 	;		  bit 4&5 -> blue level (0,1,2,3)
  2230                              <1> 	;		  bit 2%3 -> green level (0,1,2,3)
  2231                              <1> 	;		  bit 0&1 -> red level (0,1,2,3)
  2232                              <1> 	;	      Example: total red level : luminosity + red level   				
  2233                              <1> 	;	      Luminosity base level: 0 -> 16
  2234                              <1> 	;		 		     1 -> 32
  2235                              <1> 	;				     2 -> 64
  2236                              <1> 	;				     3 -> 128
  2237                              <1> 	;	      Color level:	
  2238                              <1> 	;				    0 -> 0
  2239                              <1> 	;				    1 -> luminosity level
  2240                              <1> 	;				    2 -> luminosity level + 64
  2241                              <1> 	;				    3 -> 255
  2242                              <1> 	;	     Luminosity base level = min (R,G,B)
  2243                              <1> 	;			if it is <16, it will be set to 16
  2244                              <1> 	;	     Color levels: Color values are fixed to (nearest) 
  2245                              <1> 	;		   one of all possible set level (step) values
  2246                              <1> 	;		   (according to luminosity base level); then
  2247                              <1> 	;		   color levels are set to R-L, G-L, B-L.
  2248                              <1> 	;	 For example: If luminosity base level is 32
  2249                              <1> 	;		  all possible set values are 0, 32, 96, 255. 	 			
  2250                              <1> 	;
  2251                              <1> 	;	    * RGB (TRUE) colors to 16 colors conversion:
  2252                              <1> 	;	    16 colors: R, B,G, L bits (4 bits)
  2253                              <1> 	;	    	   If any one of R,G,B >= 128 L = 1 		     	
  2254                              <1>  	;		   If max. value of (R,G,B) >= 32, it is 1
  2255                              <1> 	;		      else all color bits (R&G&B&L) are 0
  2256                              <1> 	;		   If the second value >= max. value / 2
  2257                              <1> 	;		      it is 1
  2258                              <1> 	;		   If third value value >= max. value / 2
  2259                              <1> 	;		      it is 1
  2260                              <1> 	;	    Example: R = 132, G = 64, B = 78
  2261                              <1> 	;		     L = 1, R = 1
  2262                              <1> 	;		     G < 66 --> G = 0
  2263                              <1> 	;		     B >= 66 --> B = 1	 		 	  								 	 					
  2264                              <1> 
  2265                              <1> 	; 16/05/2016
  2266 0000BD15 31C0                <1> 	xor	eax, eax
  2267 0000BD17 A3[A8300100]        <1> 	mov	[u.r0], eax
  2268                              <1> 
  2269 0000BD1C 20FF                <1> 	and	bh, bh
  2270 0000BD1E 0F8572020000        <1> 	jnz	sysvideo_13 ; 11/07/2016
  2271                              <1> 	
  2272                              <1> 	; Video mode 0, 80*25 text mode, CGA 16 colors  ; [CRT_MODE] = 3
  2273 0000BD24 88DF                <1> 	mov	bh, bl
  2274 0000BD26 C0EF02              <1> 	shr	bh, 2
  2275 0000BD29 20FF                <1> 	and	bh, bh
  2276 0000BD2B 0F8598000000        <1>         jnz     sysvideo_4
  2277 0000BD31 BF00800B00          <1> 	mov	edi, 0B8000h
  2278 0000BD36 20D2                <1> 	and	dl, dl
  2279 0000BD38 7413                <1> 	jz	short sysvideo_1
  2280 0000BD3A 80FA07              <1> 	cmp	dl, 7
  2281 0000BD3D 0F8701F9FFFF        <1> 	ja	sysret
  2282                              <1> sysvideo_0:
  2283 0000BD43 81C7A00F0000        <1> 	add	edi, 80*25*2
  2284 0000BD49 FECA                <1> 	dec	dl
  2285 0000BD4B 75F6                <1> 	jnz	short sysvideo_0	
  2286                              <1> sysvideo_1:	
  2287 0000BD4D 80E303              <1> 	and	bl, 3
  2288 0000BD50 7530                <1> 	jnz	short sysvideo_2
  2289 0000BD52 80F907              <1> 	cmp	cl, 7
  2290 0000BD55 0F87E9F8FFFF        <1> 	ja	sysret
  2291                              <1> 	; system to system video/display page transfer (mode 0)
  2292 0000BD5B BE00800B00          <1> 	mov	esi, 0B8000h
  2293 0000BD60 0FB6C1              <1> 	movzx	eax, cl
  2294 0000BD63 BAA00F0000          <1> 	mov	edx, 80*25*2
  2295 0000BD68 F7E2                <1> 	mul	edx
  2296 0000BD6A 01C6                <1> 	add	esi, eax
  2297 0000BD6C B9A00F0000          <1> 	mov	ecx, (80*25*2)
  2298 0000BD71 890D[A8300100]      <1> 	mov	[u.r0], ecx
  2299 0000BD77 66C1E902            <1> 	shr	cx, 2 ; /4
  2300 0000BD7B F3A5                <1> 	rep	movsd
  2301 0000BD7D E9C2F8FFFF          <1> 	jmp	sysret	
  2302                              <1> sysvideo_2:  
  2303 0000BD82 80FB02              <1> 	cmp	bl, 2
  2304 0000BD85 0F87B9F8FFFF        <1>         ja      sysret
  2305 0000BD8B 721F                <1> 	jb	short sysvideo_3
  2306                              <1> 	; system to user video/display page transfer (mode 0)
  2307 0000BD8D 89FE                <1> 	mov	esi, edi
  2308 0000BD8F 89CF                <1> 	mov	edi, ecx ; user buffer
  2309 0000BD91 B9A00F0000          <1> 	mov	ecx, 80*25*2
  2310 0000BD96 E8D91B0000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2311 0000BD9B 0F82A3F8FFFF        <1> 	jc	sysret
  2312 0000BDA1 890D[A8300100]      <1> 	mov	[u.r0], ecx
  2313 0000BDA7 E998F8FFFF          <1> 	jmp	sysret 	
  2314                              <1> sysvideo_3: 
  2315                              <1> 	; user to system video/display page transfer (mode 0)	
  2316 0000BDAC 89CE                <1> 	mov	esi, ecx ; user buffer
  2317                              <1> 	; edi = video page address
  2318 0000BDAE B9A00F0000          <1> 	mov	ecx, 80*25*2
  2319 0000BDB3 E8061C0000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2320 0000BDB8 0F8286F8FFFF        <1> 	jc	sysret
  2321 0000BDBE 890D[A8300100]      <1> 	mov	[u.r0], ecx		
  2322 0000BDC4 E97BF8FFFF          <1> 	jmp	sysret
  2323                              <1> sysvideo_4:
  2324 0000BDC9 80E303              <1> 	and	bl, 3
  2325 0000BDCC 0F85F6000000        <1>         jnz     sysvideo_9
  2326 0000BDD2 80F907              <1> 	cmp	cl, 7
  2327 0000BDD5 0F8769F8FFFF        <1> 	ja	sysret
  2328                              <1> 	; system to system video/display page window transfer (mode 0)
  2329 0000BDDB 81FE00800B00        <1> 	cmp	esi, 0B8000h
  2330 0000BDE1 0F825DF8FFFF        <1> 	jb	sysret
  2331 0000BDE7 81FE00FD0B00        <1> 	cmp	esi, 0B8000h+(80*25*2*8)
  2332 0000BDED 0F8351F8FFFF        <1> 	jnb	sysret
  2333 0000BDF3 81FF00800B00        <1> 	cmp	edi, 0B8000h
  2334 0000BDF9 0F8245F8FFFF        <1> 	jb	sysret
  2335 0000BDFF 81FF00FD0B00        <1>         cmp     edi, 0B8000h+(80*25*2*8)
  2336 0000BE05 0F8339F8FFFF        <1> 	jnb	sysret
  2337                              <1> 	;
  2338 0000BE0B 51                  <1> 	push	ecx
  2339 0000BE0C 52                  <1> 	push	edx
  2340 0000BE0D 0FB7C1              <1> 	movzx	eax, cx ; top left column
  2341 0000BE10 50                  <1> 	push	eax
  2342 0000BE11 C1E910              <1> 	shr	ecx, 16 ; top row
  2343 0000BE14 66B8A000            <1> 	mov	ax, 80*2 ; 80 colums, 160 bytes per row
  2344 0000BE18 F7E1                <1> 	mul	ecx
  2345 0000BE1A 01C6                <1> 	add	esi, eax
  2346 0000BE1C 01C7                <1> 	add	edi, eax
  2347 0000BE1E 58                  <1> 	pop	eax
  2348 0000BE1F 66D1E0              <1> 	shl	ax, 1 ; *2 	
  2349 0000BE22 01C6                <1> 	add	esi, eax
  2350 0000BE24 01C7                <1> 	add	edi, eax
  2351 0000BE26 5A                  <1> 	pop	edx
  2352 0000BE27 59                  <1> 	pop	ecx
  2353 0000BE28 B800FD0B00          <1> 	mov	eax, 0B8000h+(80*25*2*8)
  2354 0000BE2D 39C6                <1> 	cmp	esi, eax
  2355 0000BE2F 0F830FF8FFFF        <1> 	jnb	sysret
  2356 0000BE35 39C6                <1> 	cmp	esi, eax
  2357 0000BE37 0F8307F8FFFF        <1> 	jnb	sysret	
  2358                              <1> 
  2359 0000BE3D 56                  <1> 	push	esi ; ****
  2360 0000BE3E 57                  <1> 	push	edi ; ***
  2361 0000BE3F 52                  <1> 	push	edx ; **
  2362 0000BE40 51                  <1> 	push	ecx ; *
  2363 0000BE41 C1E910              <1> 	shr	ecx, 16 ; top row
  2364 0000BE44 C1EA10              <1> 	shr	edx, 16 ; bottom row
  2365 0000BE47 83F918              <1> 	cmp	ecx, 24 ; max. 25 rows
  2366 0000BE4A 7773                <1> 	ja	short sysvideo_6
  2367 0000BE4C 83FA18              <1> 	cmp	edx, 24 ; max. 25 rows
  2368 0000BE4F 776E                <1> 	ja	short sysvideo_6		
  2369 0000BE51 28CA                <1> 	sub	dl, cl
  2370 0000BE53 726A                <1> 	jc	short sysvideo_6
  2371 0000BE55 50                  <1> 	push	eax ; *****
  2372 0000BE56 89D3                <1> 	mov	ebx, edx ; row count - 1
  2373 0000BE58 B8A0000000          <1> 	mov	eax, 80*2
  2374 0000BE5D F7E0                <1> 	mul	eax
  2375 0000BE5F 01C6                <1> 	add	esi, eax
  2376 0000BE61 01C7                <1> 	add	edi, eax
  2377 0000BE63 58                  <1> 	pop	eax ; *****
  2378 0000BE64 39C6                <1> 	cmp	esi, eax
  2379 0000BE66 7757                <1> 	ja	short sysvideo_6
  2380 0000BE68 39C7                <1> 	cmp	edi, eax
  2381 0000BE6A 7753                <1> 	ja	short sysvideo_6
  2382 0000BE6C 59                  <1> 	pop	ecx ; *
  2383 0000BE6D 5A                  <1> 	pop	edx ; **
  2384 0000BE6E 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  2385 0000BE74 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  2386 0000BE7A 83F94F              <1> 	cmp	ecx, 79 ; max. 80 columns
  2387 0000BE7D 7742                <1> 	ja	short sysvideo_7
  2388 0000BE7F 83FA4F              <1> 	cmp	edx, 79 ; max. 80 columns
  2389 0000BE82 773D                <1> 	ja	short sysvideo_7
  2390 0000BE84 28CA                <1> 	sub	dl, cl
  2391 0000BE86 7639                <1> 	jna	short sysvideo_7
  2392                              <1> 	; edx = column count (width) - 1
  2393 0000BE88 D0E2                <1> 	shl	dl, 1
  2394 0000BE8A 01D6                <1> 	add	esi, edx
  2395 0000BE8C 01D7                <1> 	add	edi, edx
  2396 0000BE8E 39C6                <1> 	cmp	esi, eax
  2397 0000BE90 772F                <1> 	ja	short sysvideo_7
  2398 0000BE92 39C7                <1> 	cmp	edi, eax
  2399 0000BE94 772B                <1> 	ja	short sysvideo_7
  2400 0000BE96 5F                  <1> 	pop	edi ; ***
  2401 0000BE97 5E                  <1> 	pop	esi ; ****
  2402 0000BE98 FEC3                <1> 	inc	bl
  2403 0000BE9A FEC2                <1> 	inc	dl ; column count
  2404 0000BE9C 88D7                <1> 	mov	bh, dl
  2405 0000BE9E D0E2                <1> 	shl	dl, 1
  2406 0000BEA0 B8A0000000          <1> 	mov	eax, 80*2
  2407 0000BEA5 28D0                <1> 	sub	al, dl ; (80 - columns) * 2
  2408                              <1> sysvideo_5:	
  2409 0000BEA7 88F9                <1> 	mov	cl, bh
  2410 0000BEA9 0115[A8300100]      <1> 	add	[u.r0], edx
  2411 0000BEAF F366A5              <1> 	rep	movsw
  2412 0000BEB2 01C6                <1> 	add	esi, eax ; next row
  2413 0000BEB4 01C7                <1> 	add	edi, eax ; next row
  2414 0000BEB6 FECB                <1> 	dec	bl
  2415 0000BEB8 75ED                <1> 	jnz	short sysvideo_5
  2416 0000BEBA E985F7FFFF          <1> 	jmp	sysret
  2417                              <1> 
  2418                              <1> sysvideo_6:
  2419 0000BEBF 59                  <1> 	pop	ecx ; *
  2420 0000BEC0 5A                  <1> 	pop	edx ; **
  2421                              <1> sysvideo_7:	
  2422 0000BEC1 5F                  <1> 	pop	edi ; ***
  2423 0000BEC2 5E                  <1> 	pop	esi ; ****
  2424 0000BEC3 E97CF7FFFF          <1> 	jmp	sysret
  2425                              <1> 
  2426                              <1> sysvideo_9:  
  2427 0000BEC8 80FB02              <1> 	cmp	bl, 2
  2428 0000BECB 0F8773F7FFFF        <1>         ja      sysret
  2429                              <1> 
  2430 0000BED1 56                  <1> 	push	esi ; ****
  2431 0000BED2 57                  <1> 	push	edi ; ***
  2432 0000BED3 52                  <1> 	push	edx ; **
  2433 0000BED4 51                  <1> 	push	ecx ; *
  2434                              <1> 
  2435 0000BED5 C1E910              <1> 	shr	ecx, 16 ; top row
  2436 0000BED8 C1EA10              <1> 	shr	edx, 16 ; bottom row
  2437 0000BEDB 83F918              <1> 	cmp	ecx, 24 ; max. 25 rows
  2438 0000BEDE 77DF                <1> 	ja	short sysvideo_6
  2439 0000BEE0 83FA18              <1> 	cmp	edx, 24 ; max. 25 rows
  2440 0000BEE3 77DA                <1> 	ja	short sysvideo_6		
  2441 0000BEE5 28CA                <1> 	sub	dl, cl
  2442 0000BEE7 72D6                <1> 	jc	short sysvideo_6
  2443                              <1> 
  2444 0000BEE9 88CD                <1> 	mov	ch, cl ; top row
  2445 0000BEEB 8A0D[F61F0100]      <1> 	mov	cl, [ACTIVE_PAGE]
  2446 0000BEF1 BFA00F0000          <1> 	mov	edi, 80*25*2
  2447 0000BEF6 D3E7                <1> 	shl	edi, cl 
  2448 0000BEF8 81C760700B00        <1> 	add	edi, 0B8000h - 80*25*2
  2449                              <1> 
  2450 0000BEFE 88D7                <1> 	mov	bh, dl ; row count - 1
  2451 0000BF00 88EA                <1> 	mov	dl, ch ; top row
  2452 0000BF02 B8A0000000          <1> 	mov	eax, 80*2
  2453 0000BF07 F7E2                <1> 	mul	edx
  2454 0000BF09 01C7                <1> 	add	edi, eax
  2455                              <1> 
  2456 0000BF0B 59                  <1> 	pop	ecx ; *
  2457 0000BF0C 5A                  <1> 	pop	edx ; **
  2458 0000BF0D 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  2459 0000BF13 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  2460 0000BF19 83F94F              <1> 	cmp	ecx, 79 ; max. 80 columns
  2461 0000BF1C 77A3                <1> 	ja	short sysvideo_7
  2462 0000BF1E 83FA4F              <1> 	cmp	edx, 79 ; max. 80 columns
  2463 0000BF21 779E                <1> 	ja	short sysvideo_7
  2464                              <1> 	
  2465 0000BF23 28CA                <1> 	sub	dl, cl
  2466 0000BF25 769A                <1> 	jna	short sysvideo_7
  2467                              <1> 	
  2468 0000BF27 0FB6C1              <1> 	movzx	eax, cl ; left column
  2469 0000BF2A D0E0                <1> 	shl	al, 1  ; column * 2
  2470 0000BF2C 01C7                <1> 	add	edi, eax
  2471                              <1> 
  2472 0000BF2E FEC2                <1> 	inc	dl ; column count
  2473 0000BF30 D0E2                <1> 	shl	dl, 1
  2474 0000BF32 88D1                <1> 	mov	cl, dl ; column count * 2
  2475 0000BF34 B2A0                <1> 	mov	dl, 80*2
  2476 0000BF36 58                  <1> 	pop	eax ; *** (swap address)
  2477 0000BF37 5E                  <1> 	pop	esi ; ****
  2478 0000BF38 FEC7                <1> 	inc	bh
  2479                              <1> 	
  2480                              <1> 	;mov	edx, 80*2
  2481 0000BF3A B2A0                <1> 	mov	dl, 80*2
  2482                              <1> 	;
  2483 0000BF3C 80FB01              <1> 	cmp	bl, 1
  2484 0000BF3F 7735                <1> 	ja	short sysvideo_11
  2485                              <1> 
  2486                              <1> 	; user to system video/display page window transfer (mode 0)	
  2487 0000BF41 21C0                <1> 	and	eax, eax ; swap address
  2488 0000BF43 7413                <1> 	jz	short sysvideo_10 ; no window swap
  2489                              <1> 	; save previous window content in user's buffer (swap address)
  2490 0000BF45 56                  <1> 	push	esi ; user buffer
  2491 0000BF46 57                  <1> 	push	edi ; beginning address of the window
  2492 0000BF47 89FE                <1> 	mov	esi, edi
  2493 0000BF49 89C7                <1> 	mov	edi, eax
  2494 0000BF4B E8241A0000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2495 0000BF50 5F                  <1> 	pop	edi
  2496 0000BF51 5E                  <1> 	pop	esi
  2497 0000BF52 0F82ECF6FFFF        <1> 	jc	sysret
  2498                              <1> sysvideo_10: 
  2499                              <1> 	; user to system video/display page window transfer (mode 0)	
  2500                              <1> 	; esi =	user buffer
  2501 0000BF58 E8611A0000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2502 0000BF5D 0F82E1F6FFFF        <1> 	jc	sysret
  2503 0000BF63 010D[A8300100]      <1> 	add	[u.r0], ecx
  2504 0000BF69 01D7                <1> 	add	edi, edx ; next row
  2505 0000BF6B 01CE                <1> 	add	esi, ecx
  2506 0000BF6D FECF                <1> 	dec	bh
  2507 0000BF6F 75E7                <1> 	jnz	short sysvideo_10
  2508 0000BF71 E9CEF6FFFF          <1> 	jmp	sysret
  2509                              <1> 	
  2510                              <1> sysvideo_11:
  2511                              <1> 	; system to user video/display page window transfer (mode 0)
  2512 0000BF76 87FE                <1> 	xchg	edi, esi
  2513                              <1> sysvideo_12:
  2514                              <1> 	; esi = beginning address of the window
  2515                              <1> 	; edi =	user buffer	
  2516 0000BF78 E8F7190000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2517 0000BF7D 0F82C1F6FFFF        <1> 	jc	sysret
  2518 0000BF83 010D[A8300100]      <1> 	add	[u.r0], ecx
  2519 0000BF89 01D6                <1> 	add	esi, edx ; next row
  2520 0000BF8B 01CF                <1> 	add	edi, ecx
  2521 0000BF8D FECF                <1> 	dec	bh
  2522 0000BF8F 75E7                <1> 	jnz	short sysvideo_12
  2523 0000BF91 E9AEF6FFFF          <1> 	jmp	sysret
  2524                              <1> 
  2525                              <1> sysvideo_13:
  2526 0000BF96 80FF01              <1> 	cmp	bh, 1
  2527 0000BF99 0F871F030000        <1>         ja      sysvideo_38
  2528                              <1> 	; BH = 1 = CGA Graphics (0B8000h) data transfers
  2529                              <1> 
  2530 0000BF9F 20DB                <1> 	and	bl, bl
  2531 0000BFA1 751A                <1> 	jnz	short sysvideo_14
  2532                              <1> 
  2533                              <1> 	; BL =	0 = Fill color (color in CL] (32K)
  2534                              <1> 
  2535 0000BFA3 88C8                <1> 	mov	al, cl
  2536 0000BFA5 B900800000          <1> 	mov	ecx, 32768
  2537 0000BFAA 66890D[A8300100]    <1> 	mov	[u.r0], cx
  2538 0000BFB1 BF00800B00          <1> 	mov	edi, 0B8000h
  2539 0000BFB6 F3AB                <1> 	rep	stosd
  2540 0000BFB8 E987F6FFFF          <1> 	jmp	sysret
  2541                              <1> 
  2542                              <1> sysvideo_14:
  2543 0000BFBD 80FB01              <1> 	cmp	bl, 1
  2544 0000BFC0 7723                <1> 	ja	short sysvideo_16
  2545                              <1> 
  2546 0000BFC2 89CE                <1> 	mov	esi, ecx ; user buffer
  2547                              <1> 	; BL = 1 = user to system video/display page transfer
  2548                              <1> sysvideo_15:	
  2549 0000BFC4 BF00800B00          <1> 	mov	edi, 0B8000h
  2550                              <1> 	; edi = video page address
  2551 0000BFC9 B900800000          <1> 	mov	ecx, 32768
  2552 0000BFCE E8EB190000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2553 0000BFD3 0F826BF6FFFF        <1> 	jc	sysret ; [u.r0] = 0
  2554 0000BFD9 66890D[A8300100]    <1> 	mov	[u.r0], cx		
  2555 0000BFE0 E95FF6FFFF          <1> 	jmp	sysret
  2556                              <1> 
  2557                              <1> sysvideo_16:
  2558 0000BFE5 80FB02              <1> 	cmp	bl, 2	
  2559 0000BFE8 7723                <1> 	ja	short sysvideo_18
  2560                              <1> 
  2561 0000BFEA 89CF                <1> 	mov	edi, ecx ; user buffer
  2562                              <1> 	; BL = 2 = system to user video/display page transfer
  2563                              <1> sysvideo_17:	
  2564 0000BFEC BE00800B00          <1> 	mov	esi, 0B8000h
  2565 0000BFF1 B900800000          <1> 	mov	ecx, 32768
  2566 0000BFF6 E879190000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2567 0000BFFB 0F8243F6FFFF        <1> 	jc	sysret ; [u.r0] = 0
  2568 0000C001 66890D[A8300100]    <1> 	mov	[u.r0], cx
  2569 0000C008 E937F6FFFF          <1> 	jmp	sysret 	
  2570                              <1> 
  2571                              <1> sysvideo_18:
  2572 0000C00D 80FB03              <1> 	cmp	bl, 3
  2573 0000C010 777E                <1> 	ja	short sysvideo_23
  2574                              <1> 
  2575                              <1> 	; BL = 3 = NOT bits in window (ECX, EDX)
  2576                              <1> 
  2577 0000C012 BF00800B00          <1> 	mov	edi, 0B8000h
  2578 0000C017 89FE                <1> 	mov	esi, edi
  2579                              <1> 	
  2580 0000C019 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  2581 0000C01B 7716                <1> 	ja	short sysvideo_20 ; window
  2582                              <1> 	; full screen (update)
  2583 0000C01D B900800000          <1> 	mov	ecx, 32768
  2584 0000C022 66890D[A8300100]    <1> 	mov	[u.r0], cx
  2585                              <1> sysvideo_19:
  2586 0000C029 F616                <1> 	not	byte [esi] ; NOT operation
  2587 0000C02B 46                  <1> 	inc	esi
  2588 0000C02C E2FB                <1> 	loop	sysvideo_19
  2589 0000C02E E911F6FFFF          <1> 	jmp	sysret
  2590                              <1> sysvideo_20:
  2591 0000C033 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  2592 0000C036 6629C8              <1> 	sub	ax, cx  ; - top left column
  2593 0000C039 0F8205F6FFFF        <1>         jb      sysret ; invalid
  2594 0000C03F 6640                <1> 	inc	ax ; same column no == 1 column	 
  2595 0000C041 50                  <1> 	push	eax ; byte count per window row
  2596 0000C042 52                  <1> 	push	edx
  2597 0000C043 BB40010000          <1> 	mov	ebx, 320 ; screen width
  2598 0000C048 89C8                <1> 	mov	eax, ecx
  2599 0000C04A C1E810              <1> 	shr	eax, 16  ; top row
  2600 0000C04D F7E3                <1> 	mul	ebx
  2601 0000C04F 6689CA              <1> 	mov	dx, cx ; top left column
  2602 0000C052 01D0                <1> 	add	eax, edx
  2603 0000C054 01C6                <1> 	add	esi, eax ; start address 
  2604 0000C056 59                  <1> 	pop	ecx ; edx
  2605 0000C057 89C8                <1> 	mov	eax, ecx
  2606 0000C059 C1E810              <1> 	shr	eax, 16 ; bottom row
  2607 0000C05C F7E3                <1> 	mul	ebx
  2608 0000C05E 6689CA              <1> 	mov	dx, cx ; bottom right column
  2609 0000C061 01D0                <1> 	add	eax, edx
  2610 0000C063 01C7                <1> 	add	edi, eax ; stop address (included)
  2611 0000C065 5A                  <1> 	pop	edx ; byte count per window row
  2612 0000C066 81FFFFFF0B00        <1> 	cmp	edi, 0BFFFFh
  2613 0000C06C 0F87D2F5FFFF        <1> 	ja	sysret	
  2614 0000C072 56                  <1> 	push	esi
  2615 0000C073 4E                  <1> 	dec	esi
  2616                              <1> sysvideo_21:
  2617 0000C074 89D1                <1> 	mov	ecx, edx
  2618                              <1> sysvideo_22:
  2619 0000C076 46                  <1> 	inc	esi
  2620 0000C077 F616                <1> 	not	byte [esi]
  2621 0000C079 E2FB                <1> 	loop	sysvideo_22
  2622 0000C07B 01DE                <1> 	add	esi, ebx ; bytes per screen row
  2623                              <1> 	;
  2624 0000C07D 39FE                <1> 	cmp	esi, edi ; stop address (included in loop)
  2625 0000C07F 76F3                <1> 	jna	short sysvideo_21
  2626 0000C081 5E                  <1> 	pop	esi
  2627 0000C082 29F7                <1> 	sub	edi, esi
  2628 0000C084 66893D[A8300100]    <1> 	mov	[u.r0], di
  2629 0000C08B E9B4F5FFFF          <1> 	jmp	sysret
  2630                              <1> 
  2631                              <1> sysvideo_23:
  2632 0000C090 80FB04              <1> 	cmp	bl, 4
  2633 0000C093 0F87A7000000        <1>         ja      sysvideo_26
  2634                              <1> 
  2635                              <1> 	; BL = 4 = window copy (system to system)
  2636                              <1> 
  2637 0000C099 B800800B00          <1> 	mov	eax, 0B8000h
  2638 0000C09E 39C6                <1> 	cmp	esi, eax
  2639 0000C0A0 0F829EF5FFFF        <1> 	jb	sysret
  2640 0000C0A6 39C7                <1> 	cmp	edi, eax
  2641 0000C0A8 0F8296F5FFFF        <1> 	jb	sysret
  2642 0000C0AE 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  2643 0000C0B2 39C6                <1> 	cmp	esi, eax
  2644 0000C0B4 0F878AF5FFFF        <1> 	ja	sysret
  2645 0000C0BA 39C7                <1> 	cmp	edi, eax
  2646 0000C0BC 0F8782F5FFFF        <1> 	ja	sysret
  2647                              <1> 	
  2648 0000C0C2 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  2649 0000C0C4 7714                <1> 	ja	short sysvideo_24 ; window
  2650                              <1> 	; full screen copy
  2651 0000C0C6 89C1                <1> 	mov	ecx, eax
  2652 0000C0C8 29F9                <1> 	sub	ecx, edi
  2653 0000C0CA 6641                <1> 	inc	cx
  2654 0000C0CC 66890D[A8300100]    <1> 	mov	[u.r0], cx
  2655 0000C0D3 F3A4                <1> 	rep	movsb
  2656 0000C0D5 E96AF5FFFF          <1> 	jmp	sysret
  2657                              <1> sysvideo_24:
  2658 0000C0DA 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  2659 0000C0DD 6629C8              <1> 	sub	ax, cx  ; - top left column
  2660 0000C0E0 0F825EF5FFFF        <1>         jb      sysret ; invalid
  2661 0000C0E6 6640                <1> 	inc	ax ; same column no == 1 column	 
  2662 0000C0E8 50                  <1> 	push	eax ; byte count per window row
  2663                              <1> 	;
  2664 0000C0E9 52                  <1> 	push	edx
  2665 0000C0EA BB40010000          <1> 	mov	ebx, 320 ; screen width
  2666 0000C0EF 89C8                <1> 	mov	eax, ecx
  2667 0000C0F1 C1E810              <1> 	shr	eax, 16	; top row
  2668 0000C0F4 F7E3                <1> 	mul	ebx
  2669 0000C0F6 6689CA              <1> 	mov	dx, cx ; top left column
  2670 0000C0F9 01D0                <1> 	add	eax, edx
  2671 0000C0FB 01C7                <1> 	add	edi, eax ; start address 
  2672 0000C0FD 01C6                <1> 	add	esi, eax
  2673 0000C0FF 59                  <1> 	pop	ecx ; edx
  2674 0000C100 89C8                <1> 	mov	eax, ecx
  2675 0000C102 C1E810              <1> 	shr	eax, 16 ; bottom row
  2676 0000C105 F7E3                <1> 	mul	ebx
  2677 0000C107 6689CA              <1> 	mov	dx, cx ; bottom right column
  2678 0000C10A 01D0                <1> 	add	eax, edx
  2679 0000C10C 5A                  <1> 	pop	edx ; byte count per window row
  2680 0000C10D 0500800B00          <1> 	add	eax, 0B8000h
  2681 0000C112 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  2682 0000C117 0F8727F5FFFF        <1> 	ja	sysret
  2683 0000C11D 57                  <1> 	push	edi ; start address 
  2684 0000C11E 50                  <1> 	push	eax ; stop address (included)
  2685                              <1> sysvideo_25:
  2686 0000C11F 89D1                <1> 	mov	ecx, edx
  2687 0000C121 F3A4                <1> 	rep	movsb
  2688 0000C123 4F                  <1> 	dec	edi
  2689 0000C124 4E                  <1> 	dec	esi
  2690 0000C125 01DF                <1> 	add	edi, ebx ; bytes per screen row
  2691 0000C127 01DE                <1> 	add	esi, ebx
  2692                              <1> 	;
  2693 0000C129 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  2694 0000C12C 76F1                <1> 	jna	short sysvideo_25
  2695 0000C12E 5B                  <1> 	pop	ebx ; stop address
  2696 0000C12F 5F                  <1> 	pop	edi ; start address
  2697 0000C130 29FB                <1> 	sub	ebx, edi
  2698 0000C132 6643                <1> 	inc	bx
  2699 0000C134 66891D[A8300100]    <1> 	mov	[u.r0], bx	
  2700 0000C13B E904F5FFFF          <1> 	jmp	sysret
  2701                              <1> 
  2702                              <1> sysvideo_26:
  2703 0000C140 80FB05              <1> 	cmp	bl, 5
  2704 0000C143 0F8795000000        <1>         ja      sysvideo_29
  2705                              <1> 
  2706                              <1> 	; BL = 5 = window copy (user to system)
  2707                              <1> 
  2708 0000C149 B800800B00          <1> 	mov	eax, 0B8000h
  2709 0000C14E 39C7                <1> 	cmp	edi, eax
  2710 0000C150 0F82EEF4FFFF        <1> 	jb	sysret
  2711 0000C156 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  2712 0000C15A 39C7                <1> 	cmp	edi, eax
  2713 0000C15C 0F87E2F4FFFF        <1> 	ja	sysret
  2714                              <1> 
  2715                              <1> 	; esi = user buffer (in user's memory space)
  2716 0000C162 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  2717 0000C164 0F865AFEFFFF        <1>         jna     sysvideo_15 ; full screen copy
  2718                              <1> 
  2719 0000C16A 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  2720 0000C16D 6629C8              <1> 	sub	ax, cx  ; - top left column
  2721 0000C170 0F82CEF4FFFF        <1>         jb      sysret ; invalid
  2722 0000C176 6640                <1> 	inc	ax ; same column no == 1 column	 
  2723 0000C178 50                  <1> 	push	eax ; byte count per window row
  2724                              <1> 
  2725 0000C179 52                  <1> 	push	edx
  2726 0000C17A BB40010000          <1> 	mov	ebx, 320 ; screen width
  2727 0000C17F 89C8                <1> 	mov	eax, ecx
  2728 0000C181 C1E810              <1> 	shr	eax, 16	; top row
  2729 0000C184 F7E3                <1> 	mul	ebx
  2730 0000C186 6689CA              <1> 	mov	dx, cx ; top left column
  2731 0000C189 01D0                <1> 	add	eax, edx
  2732 0000C18B 01C7                <1> 	add	edi, eax ; start address 
  2733 0000C18D 59                  <1> 	pop	ecx ; edx
  2734 0000C18E 89C8                <1> 	mov	eax, ecx
  2735 0000C190 C1E810              <1> 	shr	eax, 16 ; bottom row
  2736 0000C193 F7E3                <1> 	mul	ebx
  2737 0000C195 6689CA              <1> 	mov	dx, cx ; bottom right column
  2738 0000C198 01D0                <1> 	add	eax, edx
  2739 0000C19A 5A                  <1> 	pop	edx ; byte count per window row
  2740 0000C19B 0500800B00          <1> 	add	eax, 0B8000h
  2741 0000C1A0 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  2742 0000C1A5 0F8799F4FFFF        <1> 	ja	sysret
  2743 0000C1AB 57                  <1> 	push	edi ; start address 
  2744 0000C1AC 50                  <1> 	push	eax ; stop address (included)
  2745                              <1> sysvideo_27:
  2746 0000C1AD 89D1                <1> 	mov	ecx, edx ; byte count
  2747                              <1> 	; user to system video/display page window transfer
  2748                              <1> 	; esi =	user buffer
  2749 0000C1AF E80A180000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2750 0000C1B4 7221                <1> 	jc	short sysvideo_28
  2751 0000C1B6 010D[A8300100]      <1> 	add	[u.r0], ecx
  2752 0000C1BC 01DF                <1> 	add	edi, ebx ; next row
  2753 0000C1BE 01CE                <1> 	add	esi, ecx
  2754 0000C1C0 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  2755 0000C1C3 76E8                <1> 	jna	short sysvideo_27
  2756 0000C1C5 5B                  <1> 	pop	ebx ; stop address
  2757 0000C1C6 5F                  <1> 	pop	edi ; start address
  2758 0000C1C7 29FB                <1> 	sub	ebx, edi
  2759 0000C1C9 6643                <1> 	inc	bx
  2760 0000C1CB 66891D[A8300100]    <1> 	mov	[u.r0], bx	
  2761 0000C1D2 E96DF4FFFF          <1> 	jmp	sysret
  2762                              <1> sysvideo_28:
  2763 0000C1D7 58                  <1> 	pop	eax
  2764 0000C1D8 5A                  <1> 	pop	edx
  2765 0000C1D9 E966F4FFFF          <1> 	jmp	sysret
  2766                              <1> 
  2767                              <1> sysvideo_29:
  2768 0000C1DE 80FB06              <1> 	cmp	bl, 6
  2769 0000C1E1 0F8797000000        <1>         ja      sysvideo_32
  2770                              <1> 
  2771                              <1> 	; BL = 6 = window copy (system to user)
  2772                              <1> 
  2773 0000C1E7 89F7                <1> 	mov	edi, esi ; user buffer
  2774                              <1> 
  2775 0000C1E9 B800800B00          <1> 	mov	eax, 0B8000h
  2776 0000C1EE 39C6                <1> 	cmp	esi, eax
  2777 0000C1F0 0F824EF4FFFF        <1> 	jb	sysret
  2778 0000C1F6 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  2779 0000C1FA 39C6                <1> 	cmp	esi, eax
  2780 0000C1FC 0F8742F4FFFF        <1> 	ja	sysret
  2781                              <1> 
  2782                              <1> 	; edi = user buffer (in user's memory space)
  2783 0000C202 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  2784 0000C204 0F86E2FDFFFF        <1>         jna     sysvideo_17 ; full screen copy
  2785                              <1> 
  2786 0000C20A 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  2787 0000C20D 6629C8              <1> 	sub	ax, cx  ; - top left column
  2788 0000C210 0F822EF4FFFF        <1>         jb      sysret ; invalid
  2789 0000C216 6640                <1> 	inc	ax ; same column no == 1 column	 
  2790 0000C218 50                  <1> 	push	eax ; byte count per window row
  2791                              <1> 
  2792 0000C219 52                  <1> 	push	edx
  2793 0000C21A BB40010000          <1> 	mov	ebx, 320 ; screen width
  2794 0000C21F 89C8                <1> 	mov	eax, ecx
  2795 0000C221 C1E810              <1> 	shr	eax, 16	; top row
  2796 0000C224 F7E3                <1> 	mul	ebx
  2797 0000C226 6689CA              <1> 	mov	dx, cx ; top left column
  2798 0000C229 01D0                <1> 	add	eax, edx
  2799 0000C22B 01C6                <1> 	add	esi, eax ; start address 
  2800 0000C22D 59                  <1> 	pop	ecx ; edx
  2801 0000C22E 89C8                <1> 	mov	eax, ecx
  2802 0000C230 C1E810              <1> 	shr	eax, 16 ; bottom row
  2803 0000C233 F7E3                <1> 	mul	ebx
  2804 0000C235 6689CA              <1> 	mov	dx, cx ; bottom right column
  2805 0000C238 01D0                <1> 	add	eax, edx
  2806 0000C23A 5A                  <1> 	pop	edx ; byte count per window row
  2807 0000C23B 0500800B00          <1> 	add	eax, 0B8000h
  2808 0000C240 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  2809 0000C245 0F87F9F3FFFF        <1> 	ja	sysret
  2810 0000C24B 56                  <1> 	push	esi ; start address 
  2811 0000C24C 50                  <1> 	push	eax ; stop address (included)
  2812                              <1> sysvideo_30:
  2813 0000C24D 89D1                <1> 	mov	ecx, edx ; byte count
  2814                              <1> 	; user to system video/display page window transfer
  2815                              <1> 	; esi =	user buffer
  2816 0000C24F E820170000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2817 0000C254 7221                <1> 	jc	short sysvideo_31
  2818 0000C256 010D[A8300100]      <1> 	add	[u.r0], ecx
  2819 0000C25C 01DF                <1> 	add	edi, ebx ; next row
  2820 0000C25E 01CE                <1> 	add	esi, ecx
  2821 0000C260 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  2822 0000C263 76E8                <1> 	jna	short sysvideo_30
  2823 0000C265 5B                  <1> 	pop	ebx ; stop address
  2824 0000C266 5F                  <1> 	pop	edi ; start address
  2825 0000C267 29FB                <1> 	sub	ebx, edi
  2826 0000C269 6643                <1> 	inc	bx
  2827 0000C26B 66891D[A8300100]    <1> 	mov	[u.r0], bx	
  2828 0000C272 E9CDF3FFFF          <1> 	jmp	sysret
  2829                              <1> sysvideo_31:
  2830 0000C277 58                  <1> 	pop	eax
  2831 0000C278 5A                  <1> 	pop	edx
  2832 0000C279 E9C6F3FFFF          <1> 	jmp	sysret
  2833                              <1> 
  2834                              <1> sysvideo_32:
  2835 0000C27E 80FB07              <1> 	cmp	bl, 7
  2836 0000C281 770F                <1> 	ja	short sysvideo_34
  2837                              <1> 
  2838                              <1> 	; BL = 7 = AND display page bytes with CL
  2839                              <1> 
  2840 0000C283 BE00800B00          <1> 	mov	esi, 0B8000h
  2841 0000C288 B900800000          <1> 	mov	ecx, 32768
  2842                              <1> sysvideo_33:
  2843 0000C28D 200E                <1> 	and	byte [esi], cl
  2844 0000C28F 46                  <1> 	inc	esi
  2845 0000C290 E2FB                <1> 	loop	sysvideo_33
  2846                              <1> 
  2847                              <1> sysvideo_34:
  2848 0000C292 80FB08              <1> 	cmp	bl, 8
  2849 0000C295 770F                <1> 	ja	short sysvideo_36
  2850                              <1> 
  2851                              <1> 	; BL = 8 = OR display page bytes with CL
  2852                              <1> 
  2853 0000C297 BE00800B00          <1> 	mov	esi, 0B8000h
  2854 0000C29C B900800000          <1> 	mov	ecx, 32768
  2855                              <1> sysvideo_35:
  2856 0000C2A1 080E                <1> 	or	byte [esi], cl
  2857 0000C2A3 46                  <1> 	inc	esi
  2858 0000C2A4 E2FB                <1> 	loop	sysvideo_35	
  2859                              <1> 
  2860                              <1> sysvideo_36:
  2861 0000C2A6 80FB09              <1> 	cmp	bl, 9
  2862 0000C2A9 0F8795F3FFFF        <1>         ja      sysret ; nothing to do
  2863                              <1> 
  2864                              <1> 	; BL = 9 = XOR display page bytes with CL
  2865                              <1> 
  2866 0000C2AF BE00800B00          <1> 	mov	esi, 0B8000h
  2867 0000C2B4 B900800000          <1> 	mov	ecx, 32768
  2868                              <1> sysvideo_37:
  2869 0000C2B9 300E                <1> 	xor	byte [esi], cl
  2870 0000C2BB 46                  <1> 	inc	esi
  2871 0000C2BC E2FB                <1> 	loop	sysvideo_37
  2872                              <1> 
  2873                              <1> sysvideo_38:
  2874 0000C2BE 80FF02              <1> 	cmp	bh, 2
  2875 0000C2C1 0F8733030000        <1>         ja      sysvideo_64
  2876                              <1> 	; BH = 2 = VGA Graphics (0A0000h) data transfers
  2877                              <1> 
  2878 0000C2C7 88DC                <1> 	mov	ah, bl
  2879 0000C2C9 80E30F              <1> 	and	bl, 0Fh	
  2880 0000C2CC C0EC04              <1> 	shr	ah, 4
  2881 0000C2CF C1E310              <1> 	shl	ebx, 16
  2882 0000C2D2 66BB4001            <1> 	mov	bx, 320 ; 320*200, 320*240
  2883 0000C2D6 20E4                <1> 	and	ah, ah
  2884 0000C2D8 7413                <1> 	jz	short sysvideo_39
  2885 0000C2DA 66D1E3              <1> 	shl	bx, 1 ; 640*200, 640 * 400, 640*480
  2886 0000C2DD 80FC02              <1> 	cmp	ah, 2
  2887 0000C2E0 720B                <1> 	jb	short sysvideo_39 		
  2888 0000C2E2 0F875CF3FFFF        <1> 	ja	sysret ; invalid
  2889                              <1> 	; 800*600
  2890 0000C2E8 6681C3A000          <1> 	add	bx, 160 ; 800
  2891                              <1> sysvideo_39:
  2892 0000C2ED C1CB10              <1> 	ror	ebx, 16
  2893                              <1> 		
  2894 0000C2F0 20DB                <1>  	and	bl, bl
  2895 0000C2F2 7519                <1> 	jnz	short sysvideo_40
  2896                              <1> 
  2897                              <1> 	; BL =	0 = Fill color (color in CL] (64K)
  2898                              <1> 
  2899 0000C2F4 88C8                <1> 	mov	al, cl
  2900 0000C2F6 B900000100          <1> 	mov	ecx, 65536
  2901 0000C2FB 890D[A8300100]      <1> 	mov	[u.r0], ecx
  2902 0000C301 BF00000A00          <1> 	mov	edi, 0A0000h
  2903 0000C306 F3AB                <1> 	rep	stosd
  2904 0000C308 E937F3FFFF          <1> 	jmp	sysret
  2905                              <1> 
  2906                              <1> sysvideo_40:
  2907 0000C30D 80FB01              <1> 	cmp	bl, 1
  2908 0000C310 7722                <1> 	ja	short sysvideo_42
  2909                              <1> 
  2910 0000C312 89CE                <1> 	mov	esi, ecx ; user buffer
  2911                              <1> 	; BL = 1 = user to system video/display page transfer
  2912                              <1> sysvideo_41:	
  2913 0000C314 BF00000A00          <1> 	mov	edi, 0A0000h
  2914                              <1> 	; edi = video page address
  2915 0000C319 B900000100          <1> 	mov	ecx, 65536
  2916 0000C31E E89B160000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2917 0000C323 0F821BF3FFFF        <1> 	jc	sysret ; [u.r0] = 0
  2918 0000C329 890D[A8300100]      <1> 	mov	[u.r0], ecx		
  2919 0000C32F E910F3FFFF          <1> 	jmp	sysret
  2920                              <1> 
  2921                              <1> sysvideo_42:
  2922 0000C334 80FB02              <1> 	cmp	bl, 2	
  2923 0000C337 7722                <1> 	ja	short sysvideo_44
  2924                              <1> 
  2925 0000C339 89CF                <1> 	mov	edi, ecx ; user buffer
  2926                              <1> 	; BL = 2 = system to user video/display page transfer
  2927                              <1> sysvideo_43:	
  2928 0000C33B BE00000A00          <1> 	mov	esi, 0A0000h
  2929 0000C340 B900000100          <1> 	mov	ecx, 65536
  2930 0000C345 E82A160000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2931 0000C34A 0F82F4F2FFFF        <1> 	jc	sysret ; [u.r0] = 0
  2932 0000C350 890D[A8300100]      <1> 	mov	[u.r0], ecx
  2933 0000C356 E9E9F2FFFF          <1> 	jmp	sysret 	
  2934                              <1> 
  2935                              <1> sysvideo_44:
  2936 0000C35B 80FB03              <1> 	cmp	bl, 3
  2937 0000C35E 777A                <1> 	ja	short sysvideo_49
  2938                              <1> 
  2939                              <1> 	; BL = 3 = NOT bits in window (ECX, EDX)
  2940                              <1> 
  2941 0000C360 BF00000A00          <1> 	mov	edi, 0A0000h
  2942 0000C365 89FE                <1> 	mov	esi, edi
  2943                              <1> 	
  2944 0000C367 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  2945 0000C369 770B                <1> 	ja	short sysvideo_45 ; window
  2946                              <1> 	; full screen (update)
  2947 0000C36B B900000100          <1> 	mov	ecx, 65536
  2948 0000C370 890D[A8300100]      <1> 	mov	[u.r0], ecx
  2949                              <1> sysvideo_45:
  2950 0000C376 F616                <1> 	not	byte [esi] ; NOT operation
  2951 0000C378 46                  <1> 	inc	esi
  2952 0000C379 E2FB                <1> 	loop	sysvideo_45
  2953 0000C37B E9C4F2FFFF          <1> 	jmp	sysret
  2954                              <1> sysvideo_46:
  2955 0000C380 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  2956 0000C383 6629C8              <1> 	sub	ax, cx  ; - top left column
  2957 0000C386 0F82B8F2FFFF        <1>         jb      sysret ; invalid
  2958 0000C38C 6640                <1> 	inc	ax ; same column no == 1 column	 
  2959 0000C38E 50                  <1> 	push	eax ; byte count per window row
  2960 0000C38F 52                  <1> 	push	edx
  2961 0000C390 C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  2962 0000C393 89C8                <1> 	mov	eax, ecx
  2963 0000C395 C1E810              <1> 	shr	eax, 16  ; top row
  2964 0000C398 F7E3                <1> 	mul	ebx
  2965 0000C39A 6689CA              <1> 	mov	dx, cx ; top left column
  2966 0000C39D 01D0                <1> 	add	eax, edx
  2967 0000C39F 01C6                <1> 	add	esi, eax ; start address 
  2968 0000C3A1 59                  <1> 	pop	ecx ; edx
  2969 0000C3A2 89C8                <1> 	mov	eax, ecx
  2970 0000C3A4 C1E810              <1> 	shr	eax, 16 ; bottom row
  2971 0000C3A7 F7E3                <1> 	mul	ebx
  2972 0000C3A9 6689CA              <1> 	mov	dx, cx ; bottom right column
  2973 0000C3AC 01D0                <1> 	add	eax, edx
  2974 0000C3AE 01C7                <1> 	add	edi, eax ; stop address (included)
  2975 0000C3B0 5A                  <1> 	pop	edx ; byte count per window row
  2976 0000C3B1 81FFFFFF0A00        <1> 	cmp	edi, 0AFFFFh
  2977 0000C3B7 0F8787F2FFFF        <1> 	ja	sysret	
  2978 0000C3BD 56                  <1> 	push	esi
  2979 0000C3BE 4E                  <1> 	dec	esi
  2980                              <1> sysvideo_47:
  2981 0000C3BF 89D1                <1> 	mov	ecx, edx
  2982                              <1> sysvideo_48:
  2983 0000C3C1 46                  <1> 	inc	esi
  2984 0000C3C2 F616                <1> 	not	byte [esi]
  2985 0000C3C4 E2FB                <1> 	loop	sysvideo_48
  2986 0000C3C6 01DE                <1> 	add	esi, ebx ; bytes per screen row
  2987                              <1> 	;
  2988 0000C3C8 39FE                <1> 	cmp	esi, edi ; stop address (included in loop)
  2989 0000C3CA 76F3                <1> 	jna	short sysvideo_47
  2990 0000C3CC 5E                  <1> 	pop	esi
  2991 0000C3CD 29F7                <1> 	sub	edi, esi
  2992 0000C3CF 893D[A8300100]      <1> 	mov	[u.r0], edi
  2993 0000C3D5 E96AF2FFFF          <1> 	jmp	sysret
  2994                              <1> 
  2995                              <1> sysvideo_49:
  2996 0000C3DA 80FB04              <1> 	cmp	bl, 4
  2997 0000C3DD 0F87A1000000        <1>         ja      sysvideo_52
  2998                              <1> 
  2999                              <1> 	; BL = 4 = window copy (system to system)
  3000                              <1> 
  3001 0000C3E3 B800000A00          <1> 	mov	eax, 0A0000h
  3002 0000C3E8 39C6                <1> 	cmp	esi, eax
  3003 0000C3EA 0F8254F2FFFF        <1> 	jb	sysret
  3004 0000C3F0 39C7                <1> 	cmp	edi, eax
  3005 0000C3F2 0F824CF2FFFF        <1> 	jb	sysret
  3006 0000C3F8 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3007 0000C3FC 39C6                <1> 	cmp	esi, eax
  3008 0000C3FE 0F8740F2FFFF        <1> 	ja	sysret
  3009 0000C404 39C7                <1> 	cmp	edi, eax
  3010 0000C406 0F8738F2FFFF        <1> 	ja	sysret
  3011                              <1> 	
  3012 0000C40C 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3013 0000C40E 7712                <1> 	ja	short sysvideo_50 ; window
  3014                              <1> 	; full screen copy
  3015 0000C410 89C1                <1> 	mov	ecx, eax
  3016 0000C412 29F9                <1> 	sub	ecx, edi
  3017 0000C414 41                  <1> 	inc	ecx
  3018 0000C415 890D[A8300100]      <1> 	mov	[u.r0], ecx
  3019 0000C41B F3A4                <1> 	rep	movsb
  3020 0000C41D E922F2FFFF          <1> 	jmp	sysret
  3021                              <1> sysvideo_50:
  3022 0000C422 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3023 0000C425 6629C8              <1> 	sub	ax, cx  ; - top left column
  3024 0000C428 0F8216F2FFFF        <1>         jb      sysret ; invalid
  3025 0000C42E 6640                <1> 	inc	ax ; same column no == 1 column	 
  3026 0000C430 50                  <1> 	push	eax ; byte count per window row
  3027                              <1> 	;
  3028 0000C431 52                  <1> 	push	edx
  3029 0000C432 C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  3030 0000C435 89C8                <1> 	mov	eax, ecx
  3031 0000C437 C1E810              <1> 	shr	eax, 16	; top row
  3032 0000C43A F7E3                <1> 	mul	ebx
  3033 0000C43C 6689CA              <1> 	mov	dx, cx ; top left column
  3034 0000C43F 01D0                <1> 	add	eax, edx
  3035 0000C441 01C7                <1> 	add	edi, eax ; start address 
  3036 0000C443 01C6                <1> 	add	esi, eax
  3037 0000C445 59                  <1> 	pop	ecx ; edx
  3038 0000C446 89C8                <1> 	mov	eax, ecx
  3039 0000C448 C1E810              <1> 	shr	eax, 16 ; bottom row
  3040 0000C44B F7E3                <1> 	mul	ebx
  3041 0000C44D 6689CA              <1> 	mov	dx, cx ; bottom right column
  3042 0000C450 01D0                <1> 	add	eax, edx
  3043 0000C452 5A                  <1> 	pop	edx ; byte count per window row
  3044 0000C453 0500000A00          <1> 	add	eax, 0A0000h
  3045 0000C458 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3046 0000C45D 0F87E1F1FFFF        <1> 	ja	sysret
  3047 0000C463 57                  <1> 	push	edi ; start address 
  3048 0000C464 50                  <1> 	push	eax ; stop address (included)
  3049                              <1> sysvideo_51:
  3050 0000C465 89D1                <1> 	mov	ecx, edx
  3051 0000C467 F3A4                <1> 	rep	movsb
  3052 0000C469 4F                  <1> 	dec	edi
  3053 0000C46A 4E                  <1> 	dec	esi
  3054 0000C46B 01DF                <1> 	add	edi, ebx ; bytes per screen row
  3055 0000C46D 01DE                <1> 	add	esi, ebx
  3056                              <1> 	;
  3057 0000C46F 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3058 0000C472 76F1                <1> 	jna	short sysvideo_51
  3059 0000C474 5B                  <1> 	pop	ebx ; stop address
  3060 0000C475 5F                  <1> 	pop	edi ; start address
  3061 0000C476 29FB                <1> 	sub	ebx, edi
  3062 0000C478 43                  <1> 	inc	ebx
  3063 0000C479 891D[A8300100]      <1> 	mov	[u.r0], ebx	
  3064 0000C47F E9C0F1FFFF          <1> 	jmp	sysret
  3065                              <1> 
  3066                              <1> sysvideo_52:
  3067 0000C484 80FB05              <1> 	cmp	bl, 5
  3068 0000C487 0F8791000000        <1>         ja      sysvideo_55
  3069                              <1> 
  3070                              <1> 	; BL = 5 = window copy (user to system)
  3071                              <1> 
  3072 0000C48D B800000A00          <1> 	mov	eax, 0A0000h
  3073 0000C492 39C7                <1> 	cmp	edi, eax
  3074 0000C494 0F82AAF1FFFF        <1> 	jb	sysret
  3075 0000C49A 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3076 0000C49E 39C7                <1> 	cmp	edi, eax
  3077 0000C4A0 0F879EF1FFFF        <1> 	ja	sysret
  3078                              <1> 
  3079                              <1> 	; esi = user buffer (in user's memory space)
  3080 0000C4A6 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3081 0000C4A8 0F8666FEFFFF        <1>         jna     sysvideo_41 ; full screen copy
  3082                              <1> 
  3083 0000C4AE 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3084 0000C4B1 6629C8              <1> 	sub	ax, cx  ; - top left column
  3085 0000C4B4 0F828AF1FFFF        <1>         jb      sysret ; invalid
  3086 0000C4BA 6640                <1> 	inc	ax ; same column no == 1 column	 
  3087 0000C4BC 50                  <1> 	push	eax ; byte count per window row
  3088                              <1> 
  3089 0000C4BD 52                  <1> 	push	edx
  3090 0000C4BE C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  3091 0000C4C1 89C8                <1> 	mov	eax, ecx
  3092 0000C4C3 C1E810              <1> 	shr	eax, 16	; top row
  3093 0000C4C6 F7E3                <1> 	mul	ebx
  3094 0000C4C8 6689CA              <1> 	mov	dx, cx ; top left column
  3095 0000C4CB 01D0                <1> 	add	eax, edx
  3096 0000C4CD 01C7                <1> 	add	edi, eax ; start address 
  3097 0000C4CF 59                  <1> 	pop	ecx ; edx
  3098 0000C4D0 89C8                <1> 	mov	eax, ecx
  3099 0000C4D2 C1E810              <1> 	shr	eax, 16 ; bottom row
  3100 0000C4D5 F7E3                <1> 	mul	ebx
  3101 0000C4D7 6689CA              <1> 	mov	dx, cx ; bottom right column
  3102 0000C4DA 01D0                <1> 	add	eax, edx
  3103 0000C4DC 5A                  <1> 	pop	edx ; byte count per window row
  3104 0000C4DD 0500000A00          <1> 	add	eax, 0A0000h
  3105 0000C4E2 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3106 0000C4E7 0F8757F1FFFF        <1> 	ja	sysret
  3107 0000C4ED 57                  <1> 	push	edi ; start address 
  3108 0000C4EE 50                  <1> 	push	eax ; stop address (included)
  3109                              <1> sysvideo_53:
  3110 0000C4EF 89D1                <1> 	mov	ecx, edx ; byte count
  3111                              <1> 	; user to system video/display page window transfer
  3112                              <1> 	; esi =	user buffer
  3113 0000C4F1 E8C8140000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3114 0000C4F6 721F                <1> 	jc	short sysvideo_54
  3115 0000C4F8 010D[A8300100]      <1> 	add	[u.r0], ecx
  3116 0000C4FE 01DF                <1> 	add	edi, ebx ; next row
  3117 0000C500 01CE                <1> 	add	esi, ecx
  3118 0000C502 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3119 0000C505 76E8                <1> 	jna	short sysvideo_53
  3120 0000C507 5B                  <1> 	pop	ebx ; stop address
  3121 0000C508 5F                  <1> 	pop	edi ; start address
  3122 0000C509 29FB                <1> 	sub	ebx, edi
  3123 0000C50B 43                  <1> 	inc	ebx
  3124 0000C50C 891D[A8300100]      <1> 	mov	[u.r0], ebx	
  3125 0000C512 E92DF1FFFF          <1> 	jmp	sysret
  3126                              <1> sysvideo_54:
  3127 0000C517 58                  <1> 	pop	eax
  3128 0000C518 5A                  <1> 	pop	edx
  3129 0000C519 E926F1FFFF          <1> 	jmp	sysret
  3130                              <1> 
  3131                              <1> sysvideo_55:
  3132 0000C51E 80FB06              <1> 	cmp	bl, 6
  3133 0000C521 0F8793000000        <1>         ja      sysvideo_58
  3134                              <1> 
  3135                              <1> 	; BL = 6 = window copy (system to user)
  3136                              <1> 
  3137 0000C527 89F7                <1> 	mov	edi, esi ; user buffer
  3138                              <1> 
  3139 0000C529 B800000A00          <1> 	mov	eax, 0A0000h
  3140 0000C52E 39C6                <1> 	cmp	esi, eax
  3141 0000C530 0F820EF1FFFF        <1> 	jb	sysret
  3142 0000C536 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3143 0000C53A 39C6                <1> 	cmp	esi, eax
  3144 0000C53C 0F8702F1FFFF        <1> 	ja	sysret
  3145                              <1> 
  3146                              <1> 	; edi = user buffer (in user's memory space)
  3147 0000C542 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3148 0000C544 0F86A2FAFFFF        <1>         jna     sysvideo_17 ; full screen copy
  3149                              <1> 
  3150 0000C54A 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3151 0000C54D 6629C8              <1> 	sub	ax, cx  ; - top left column
  3152 0000C550 0F82EEF0FFFF        <1>         jb      sysret ; invalid
  3153 0000C556 6640                <1> 	inc	ax ; same column no == 1 column	 
  3154 0000C558 50                  <1> 	push	eax ; byte count per window row
  3155                              <1> 
  3156 0000C559 52                  <1> 	push	edx
  3157 0000C55A C1EB10              <1> 	shr	ebx, 16 ; 320, 640,800 ; screen width
  3158 0000C55D 89C8                <1> 	mov	eax, ecx
  3159 0000C55F C1E810              <1> 	shr	eax, 16	; top row
  3160 0000C562 F7E3                <1> 	mul	ebx
  3161 0000C564 6689CA              <1> 	mov	dx, cx ; top left column
  3162 0000C567 01D0                <1> 	add	eax, edx
  3163 0000C569 01C6                <1> 	add	esi, eax ; start address 
  3164 0000C56B 59                  <1> 	pop	ecx ; edx
  3165 0000C56C 89C8                <1> 	mov	eax, ecx
  3166 0000C56E C1E810              <1> 	shr	eax, 16 ; bottom row
  3167 0000C571 F7E3                <1> 	mul	ebx
  3168 0000C573 6689CA              <1> 	mov	dx, cx ; bottom right column
  3169 0000C576 01D0                <1> 	add	eax, edx
  3170 0000C578 5A                  <1> 	pop	edx ; byte count per window row
  3171 0000C579 0500000A00          <1> 	add	eax, 0A0000h
  3172 0000C57E 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3173 0000C583 0F87BBF0FFFF        <1> 	ja	sysret
  3174 0000C589 56                  <1> 	push	esi ; start address 
  3175 0000C58A 50                  <1> 	push	eax ; stop address (included)
  3176                              <1> sysvideo_56:
  3177 0000C58B 89D1                <1> 	mov	ecx, edx ; byte count
  3178                              <1> 	; user to system video/display page window transfer
  3179                              <1> 	; esi =	user buffer
  3180 0000C58D E8E2130000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3181 0000C592 721F                <1> 	jc	short sysvideo_57
  3182 0000C594 010D[A8300100]      <1> 	add	[u.r0], ecx
  3183 0000C59A 01DF                <1> 	add	edi, ebx ; next row
  3184 0000C59C 01CE                <1> 	add	esi, ecx
  3185 0000C59E 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3186 0000C5A1 76E8                <1> 	jna	short sysvideo_56
  3187 0000C5A3 5B                  <1> 	pop	ebx ; stop address
  3188 0000C5A4 5F                  <1> 	pop	edi ; start address
  3189 0000C5A5 29FB                <1> 	sub	ebx, edi
  3190 0000C5A7 43                  <1> 	inc	ebx
  3191 0000C5A8 891D[A8300100]      <1> 	mov	[u.r0], ebx	
  3192 0000C5AE E991F0FFFF          <1> 	jmp	sysret
  3193                              <1> sysvideo_57:
  3194 0000C5B3 58                  <1> 	pop	eax
  3195 0000C5B4 5A                  <1> 	pop	edx
  3196 0000C5B5 E98AF0FFFF          <1> 	jmp	sysret
  3197                              <1> 
  3198                              <1> sysvideo_58:
  3199 0000C5BA 80FB07              <1> 	cmp	bl, 7
  3200 0000C5BD 770F                <1> 	ja	short sysvideo_60
  3201                              <1> 
  3202                              <1> 	; BL = 7 = AND display page bytes with CL
  3203                              <1> 
  3204 0000C5BF BE00000A00          <1> 	mov	esi, 0A0000h
  3205 0000C5C4 B900000100          <1> 	mov	ecx, 65536
  3206                              <1> sysvideo_59:
  3207 0000C5C9 200E                <1> 	and	byte [esi], cl
  3208 0000C5CB 46                  <1> 	inc	esi
  3209 0000C5CC E2FB                <1> 	loop	sysvideo_59
  3210                              <1> 
  3211                              <1> sysvideo_60:
  3212 0000C5CE 80FB08              <1> 	cmp	bl, 8
  3213 0000C5D1 770F                <1> 	ja	short sysvideo_62
  3214                              <1> 
  3215                              <1> 	; BL = 8 = OR display page bytes with CL
  3216                              <1> 
  3217 0000C5D3 BE00000A00          <1> 	mov	esi, 0A0000h
  3218 0000C5D8 B900000100          <1> 	mov	ecx, 65536
  3219                              <1> sysvideo_61:
  3220 0000C5DD 080E                <1> 	or	byte [esi], cl
  3221 0000C5DF 46                  <1> 	inc	esi
  3222 0000C5E0 E2FB                <1> 	loop	sysvideo_61	
  3223                              <1> 
  3224                              <1> sysvideo_62:
  3225 0000C5E2 80FB09              <1> 	cmp	bl, 9
  3226 0000C5E5 0F8759F0FFFF        <1>         ja      sysret ; nothing to do
  3227                              <1> 
  3228                              <1> 	; BL = 9 = XOR display page bytes with CL
  3229                              <1> 
  3230 0000C5EB BE00000A00          <1> 	mov	esi, 0A0000h
  3231 0000C5F0 B900000100          <1> 	mov	ecx, 65536
  3232                              <1> sysvideo_63:
  3233 0000C5F5 300E                <1> 	xor	byte [esi], cl
  3234 0000C5F7 46                  <1> 	inc	esi
  3235 0000C5F8 E2FB                <1> 	loop	sysvideo_63
  3236                              <1> 
  3237                              <1> sysvideo_64:
  3238 0000C5FA 80FF03              <1> 	cmp	bh, 3
  3239 0000C5FD 7460                <1> 	je	short sysvideo_68
  3240 0000C5FF 80FF04              <1> 	cmp	bh, 4
  3241 0000C602 771F                <1> 	ja	short sysvideo_65
  3242                              <1> 	
  3243                              <1> 	; BH = 4
  3244                              <1> 	; Direct User Access for CGA video memory.
  3245                              <1> 	; Setup user's page tables for direct access to 0B8000h.
  3246                              <1> 	;
  3247                              <1> 	; Permission checks are not implemented yet !
  3248                              <1> 	; (11/07/2016)
  3249                              <1> 
  3250 0000C604 B800800B00          <1> 	mov	eax, 0B8000h
  3251 0000C609 B908000000          <1> 	mov	ecx, 8 ; 8 pages (8*4K=32K)
  3252 0000C60E E8B58AFFFF          <1> 	call	direct_memory_access	
  3253 0000C613 0F822BF0FFFF        <1> 	jc	sysret
  3254                              <1> 	; eax = 0B8000h if there is not an error
  3255 0000C619 A3[A8300100]        <1> 	mov	[u.r0], eax
  3256 0000C61E E921F0FFFF          <1> 	jmp	sysret
  3257                              <1> 
  3258                              <1> sysvideo_65:
  3259 0000C623 80FF05              <1> 	cmp	bh, 5
  3260 0000C626 771F                <1> 	ja	short sysvideo_66
  3261                              <1> 
  3262                              <1> 	; BH = 5
  3263                              <1> 	; Direct User Access for VGA video memory.
  3264                              <1> 	; Setup user's page tables for direct access to 0A0000h.
  3265                              <1> 	;
  3266                              <1> 	; Permission checks are not implemented yet !
  3267                              <1> 	; (11/07/2016)
  3268                              <1> 
  3269 0000C628 B800000A00          <1> 	mov	eax, 0A0000h
  3270 0000C62D B910000000          <1> 	mov	ecx, 16 ; 16 pages (16*4K=64K)
  3271 0000C632 E8918AFFFF          <1> 	call	direct_memory_access	
  3272 0000C637 0F8207F0FFFF        <1> 	jc	sysret
  3273                              <1> 	; eax = 0A0000h if there is not an error
  3274 0000C63D A3[A8300100]        <1> 	mov	[u.r0], eax
  3275 0000C642 E9FDEFFFFF          <1> 	jmp	sysret
  3276                              <1> 
  3277                              <1> sysvideo_66:
  3278 0000C647 80FF06              <1> 	cmp	bh, 6
  3279 0000C64A 7705                <1> 	ja	short sysvideo_67
  3280                              <1> 	; BH = 6
  3281                              <1> 	; Direct User Access for (Super VGA) Linear Frame Buffer.
  3282                              <1> 	; Setup user's page tables for direct access to LFB.
  3283                              <1> 	;
  3284                              <1> 	; Not implemented yet !
  3285                              <1> 	; (11/07/2016)
  3286 0000C64C E9F3EFFFFF          <1> 	jmp	sysret
  3287                              <1> 
  3288                              <1> sysvideo_67:
  3289 0000C651 80FF07              <1> 	cmp	bh, 7
  3290 0000C654 0F87EAEFFFFF        <1> 	ja	sysret ; invalid !
  3291                              <1> 
  3292                              <1> 	; BH = 7
  3293                              <1> 	; Get (Super/Extended VGA) Linear Frame Buffer info.
  3294                              <1> 	;
  3295                              <1> 	; Not implemented yet !
  3296                              <1> 	; (11/07/2016)
  3297 0000C65A E9E5EFFFFF          <1> 	jmp	sysret
  3298                              <1> 
  3299                              <1> sysvideo_68:
  3300                              <1> 	; BH = 3
  3301                              <1> 	; Super VGA, LINEAR FRAME BUFFER data transfers
  3302                              <1> 	; Not implemented for yet ! (11/07/2016)
  3303 0000C65F E9E0EFFFFF          <1> 	jmp	sysret
  3304                              <1> 
  3305                              <1> sysaudio: ; AUDIO FUNCTIONS
  3306                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  3307                              <1> 	;
  3308                              <1> 	; Inputs:
  3309                              <1> 	;	BH = 0 -> Beep (PC Speaker)
  3310                              <1> 	;	     BL = Duration Counter (1 for 1/64 second)
  3311                              <1> 	;	     CX = Frequency Divisor (1193180/Frequency)
  3312                              <1> 	;		 (1331 for 886 Hz)			
  3313                              <1> 	;
  3314                              <1> 	; Outputs:
  3315                              <1> 	;	none
  3316                              <1> 	;
  3317 0000C664 20FF                <1> 	and	bh, bh
  3318 0000C666 0F85D8EFFFFF        <1> 	jnz	sysret
  3319 0000C66C E89F55FFFF          <1> 	call	beep
  3320 0000C671 E9CEEFFFFF          <1> 	jmp	sysret
  3321                              <1>  
  3322                              <1> syslink:
  3323                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  3324                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
  3325                              <1> 	;
  3326                              <1> 	; 'syslink' is given two arguments, name 1 and name 2.
  3327                              <1> 	; name 1 is a file that already exists. name 2 is the name
  3328                              <1> 	; given to the entry that will go in the current directory.
  3329                              <1> 	; name2 will then be a link to the name 1 file. The i-number
  3330                              <1> 	; in the name 2 entry of current directory is the same
  3331                              <1> 	; i-number for the name 1 file.
  3332                              <1> 	;
  3333                              <1> 	; Calling sequence:
  3334                              <1> 	;	syslink; name 1; name 2
  3335                              <1> 	; Arguments:
  3336                              <1> 	;	name 1 - file name to which link will be created.
  3337                              <1> 	;	name 2 - name of entry in current directory that
  3338                              <1> 	;		 links to name 1.
  3339                              <1> 	; Inputs: -
  3340                              <1> 	; Outputs: -
  3341                              <1> 	; ...............................................................
  3342                              <1> 	;	
  3343                              <1> 	; Retro UNIX 8086 v1 modification: 
  3344                              <1> 	;       'syslink' system call has two arguments; so,
  3345                              <1> 	;	* 1st argument, name 1 is pointed to by BX register
  3346                              <1> 	;	* 2nd argument, name 2 is pointed to by CX register
  3347                              <1> 	;
  3348                              <1> 		; / name1, name2
  3349                              <1> 		;jsr r0,arg2 / u.namep has 1st arg u.off has 2nd
  3350 0000C676 891D[C0300100]      <1> 	mov	[u.namep], ebx
  3351 0000C67C 51                  <1> 	push	ecx
  3352 0000C67D E86C040000          <1> 	call	namei
  3353                              <1> 		; jsr r0,namei / find the i-number associated with
  3354                              <1> 			     ; / the 1st path name
  3355                              <1>      	;;and	ax, ax
  3356                              <1> 	;;jz	error ; File not found
  3357                              <1> 	;jc	error 
  3358                              <1> 		; br error9 / cannot be found
  3359 0000C682 730F                <1> 	jnc	short syslink0
  3360                              <1> 	;pop 	ecx
  3361                              <1> 	; 'file not found !' error
  3362 0000C684 C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
  3362 0000C68C 0000                <1>
  3363 0000C68E E991EFFFFF          <1> 	jmp	error
  3364                              <1> syslink0:
  3365 0000C693 E862130000          <1> 	call	iget
  3366                              <1> 		; jsr r0,iget / get the i-node into core
  3367 0000C698 8F05[C0300100]      <1> 	pop	dword [u.namep] ; ecx
  3368                              <1> 		; mov (sp)+,u.namep / u.namep points to 2nd name
  3369 0000C69E 6650                <1> 	push	ax
  3370                              <1> 		; mov r1,-(sp) / put i-number of name1 on the stack
  3371                              <1> 			    ; / (a link to this file is to be created)
  3372 0000C6A0 66FF35[8A300100]    <1> 	push	word [cdev]
  3373                              <1> 		; mov cdev,-(sp) / put i-nodes device on the stack
  3374 0000C6A7 E855000000          <1> 	call	isdir
  3375                              <1> 		; jsr r0,isdir / is it a directory
  3376 0000C6AC E83D040000          <1> 	call	namei
  3377                              <1> 		; jsr r0,namei / no, get i-number of name2
  3378                              <1> 	;jnc	error
  3379                              <1> 		; br .+4   / not found 
  3380                              <1> 			 ; / so r1 = i-number of current directory
  3381                              <1> 			 ; / ii = i-number of current directory
  3382                              <1> 		; br error9 / file already exists., error
  3383 0000C6B1 720F                <1> 	jc	short syslink1
  3384                              <1> 	; pop ax
  3385                              <1> 	; pop ax
  3386                              <1> 	; 'file exists !' error
  3387 0000C6B3 C705[FD300100]0E00- <1> 	mov	dword [u.error], ERR_FILE_EXISTS ; 14
  3387 0000C6BB 0000                <1>
  3388 0000C6BD E962EFFFFF          <1> 	jmp	error
  3389                              <1> syslink1:
  3390 0000C6C2 6659                <1> 	pop	cx
  3391                              <1> 	;cmp	cx, [cdev]
  3392 0000C6C4 3A0D[8A300100]      <1> 	cmp	cl, [cdev]
  3393                              <1> 	;jne	error
  3394                              <1> 		; cmp (sp)+,cdev / u.dirp now points to 
  3395                              <1> 			       ; / end of current directory
  3396                              <1> 	        ; bne error9
  3397 0000C6CA 740F                <1> 	je	short syslink2
  3398                              <1> 	; 'not same drive !' error
  3399 0000C6CC C705[FD300100]1500- <1> 	mov	dword [u.error],  ERR_DRV_NOT_SAME ; 21
  3399 0000C6D4 0000                <1>
  3400 0000C6D6 E949EFFFFF          <1> 	jmp	error
  3401                              <1> syslink2:
  3402 0000C6DB 6658                <1> 	pop	ax
  3403 0000C6DD 6650                <1> 	push	ax
  3404 0000C6DF 66A3[DA300100]      <1> 	mov	[u.dirbuf], ax
  3405                              <1> 		; mov (sp),u.dirbuf / i-number of name1 into u.dirbuf
  3406 0000C6E5 E8A8000000          <1> 	call	mkdir
  3407                              <1> 		; jsr r0,mkdir / make directory entry for name2 
  3408                              <1> 		 	     ; / in current directory
  3409 0000C6EA 6658                <1> 	pop	ax
  3410                              <1> 		; mov (sp)+,r1 / r1 has i-number of name1
  3411 0000C6EC E809130000          <1> 	call	iget
  3412                              <1> 		; jsr r0,iget / get i-node into core
  3413 0000C6F1 FE05[6E2D0100]      <1> 	inc	byte [i.nlks]
  3414                              <1> 		; incb i.nlks / add 1 to its number of links
  3415 0000C6F7 E805130000          <1> 	call	setimod
  3416                              <1> 		; jsr r0,setimod / set the i-node modified flag
  3417 0000C6FC E943EFFFFF          <1> 	jmp	sysret
  3418                              <1> 
  3419                              <1> isdir:
  3420                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  3421                              <1> 	; 04/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  3422                              <1> 	;
  3423                              <1> 	; 'isdir' check to see if the i-node whose i-number is in r1
  3424                              <1> 	;  is a directory. If it is, an error occurs, because 'isdir'
  3425                              <1> 	;  called by syslink and sysunlink to make sure directories
  3426                              <1> 	;  are not linked. If the user is the super user (u.uid=0),
  3427                              <1> 	; 'isdir' does not bother checking. The current i-node
  3428                              <1> 	;  is not disturbed.			
  3429                              <1> 	;		
  3430                              <1> 	; INPUTS ->
  3431                              <1> 	;    r1 - contains the i-number whose i-node is being checked.
  3432                              <1> 	;    u.uid - user id
  3433                              <1> 	; OUTPUTS ->
  3434                              <1> 	;    r1 - contains current i-number upon exit
  3435                              <1> 	;    	 (current i-node back in core) 
  3436                              <1> 	;	
  3437                              <1> 	; ((AX = R1))
  3438                              <1> 	;
  3439                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
  3440                              <1> 	;
  3441                              <1> 
  3442                              <1> 	; / if the i-node whose i-number is in r1 is a directory 
  3443                              <1> 	; / there is an error unless super user made the call
  3444                              <1> 	
  3445 0000C701 803D[F4300100]00    <1> 	cmp	byte [u.uid], 0 
  3446                              <1> 		; tstb u.uid / super user
  3447 0000C708 762D                <1> 	jna	short isdir1
  3448                              <1> 		; beq 1f / yes, don't care
  3449 0000C70A 66FF35[2D310100]    <1> 	push	word [ii]
  3450                              <1> 		; mov ii,-(sp) / put current i-number on stack
  3451 0000C711 E8E4120000          <1> 	call	iget
  3452                              <1> 		; jsr r0,iget / get i-node into core (i-number in r1)
  3453 0000C716 66F705[6C2D0100]00- <1> 	test 	word [i.flgs], 4000h ; Bit 14 : Directory flag
  3453 0000C71E 40                  <1>
  3454                              <1> 		; bit $40000,i.flgs / is it a directory
  3455                              <1> 	;jnz	error
  3456                              <1> 		; bne error9 / yes, error
  3457 0000C71F 740F                <1> 	jz	short isdir0
  3458 0000C721 C705[FD300100]0B00- <1> 	mov 	dword [u.error], ERR_NOT_FILE  ; 11 ; ERR_DIR_ACCESS 
  3458 0000C729 0000                <1>
  3459                              <1> 				; 'permission denied !' error
  3460                              <1> 	; pop	ax
  3461 0000C72B E9F4EEFFFF          <1> 	jmp	error	
  3462                              <1> isdir0:	
  3463 0000C730 6658                <1> 	pop	ax
  3464                              <1> 		; mov (sp)+,r1 / no, put current i-number in r1 (ii)
  3465 0000C732 E8C3120000          <1> 	call	iget
  3466                              <1> 		; jsr r0,iget / get it back in
  3467                              <1> isdir1: ; 1:
  3468 0000C737 C3                  <1> 	retn
  3469                              <1> 		; rts r0
  3470                              <1> 
  3471                              <1> sysunlink:
  3472                              <1> 	; 04/12/2015 (14 byte file names)
  3473                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  3474                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
  3475                              <1> 	;
  3476                              <1> 	; 'sysunlink' removes the entry for the file pointed to by
  3477                              <1> 	; name from its directory. If this entry was the last link
  3478                              <1> 	; to the file, the contents of the file are freed and the
  3479                              <1> 	; file is destroyed. If, however, the file was open in any
  3480                              <1> 	; process, the actual destruction is delayed until it is 
  3481                              <1> 	; closed, even though the directory entry has disappeared.
  3482                              <1> 	; 
  3483                              <1> 	; The error bit (e-bit) is set to indicate that the file	
  3484                              <1> 	; does not exist or that its directory can not be written.
  3485                              <1> 	; Write permission is not required on the file itself.
  3486                              <1> 	; It is also illegal to unlink a directory (except for
  3487                              <1> 	; the superuser).
  3488                              <1> 	;
  3489                              <1> 	; Calling sequence:
  3490                              <1> 	;	sysunlink; name
  3491                              <1> 	; Arguments:
  3492                              <1> 	;	name - name of directory entry to be removed 
  3493                              <1> 	; Inputs: -
  3494                              <1> 	; Outputs: -
  3495                              <1> 	; ...............................................................
  3496                              <1> 	;				
  3497                              <1> 	; Retro UNIX 8086 v1 modification:
  3498                              <1> 	;	 The user/application program puts address of the name
  3499                              <1> 	;        in BX register as 'sysunlink' system call argument.
  3500                              <1> 
  3501                              <1> 	; / name - remove link name
  3502 0000C738 891D[C0300100]      <1> 	mov	[u.namep], ebx
  3503                              <1> 		;jsr r0,arg; u.namep / u.namep points to name
  3504 0000C73E E8AB030000          <1> 	call	namei
  3505                              <1> 		; jsr r0,namei / find the i-number associated 
  3506                              <1> 			     ; / with the path name
  3507                              <1> 	;jc	error
  3508                              <1> 		; br error9 / not found
  3509 0000C743 730F                <1> 	jnc	short sysunlink1
  3510                              <1> 	; 'file not found !' error
  3511 0000C745 C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
  3511 0000C74D 0000                <1>
  3512 0000C74F E9D0EEFFFF          <1> 	jmp	error
  3513                              <1> sysunlink1:
  3514 0000C754 6650                <1> 	push	ax
  3515                              <1> 		; mov r1,-(sp) / put its i-number on the stack
  3516 0000C756 E8A6FFFFFF          <1> 	call	isdir
  3517                              <1> 		; jsr r0,isdir / is it a directory
  3518 0000C75B 6631C0              <1> 	xor 	ax, ax
  3519 0000C75E 66A3[DA300100]      <1> 	mov	[u.dirbuf], ax ; 0
  3520                              <1> 		; clr u.dirbuf / no, clear the location that will
  3521                              <1> 			   ; / get written into the i-number portion
  3522                              <1> 			 ; / of the entry
  3523 0000C764 832D[C4300100]10    <1> 	sub	dword [u.off], 16 ; 04/12/2015 (10 -> 16) 
  3524                              <1> 		; sub $10.,u.off / move u.off back 1 directory entry
  3525 0000C76B E86E000000          <1> 	call	wdir
  3526                              <1> 		; jsr r0,wdir / free the directory entry
  3527 0000C770 6658                <1> 	pop	ax
  3528                              <1> 		; mov (sp)+,r1 / get i-number back
  3529 0000C772 E883120000          <1> 	call	iget
  3530                              <1> 		; jsr r0,iget / get i-node
  3531 0000C777 E885120000          <1> 	call	setimod
  3532                              <1> 		; jsr r0,setimod / set modified flag
  3533 0000C77C FE0D[6E2D0100]      <1> 	dec	byte [i.nlks]
  3534                              <1> 		; decb i.nlks / decrement the number of links
  3535 0000C782 0F85BCEEFFFF        <1> 	jnz	sysret
  3536                              <1> 		; bgt sysret9 / if this was not the last link
  3537                              <1> 			    ; / to file return
  3538                              <1> 	; AX = r1 = i-number
  3539 0000C788 E886070000          <1> 	call	anyi
  3540                              <1> 		; jsr r0,anyi / if it was, see if anyone has it open.
  3541                              <1> 			 ; / Then free contents of file and destroy it.
  3542 0000C78D E9B2EEFFFF          <1> 	jmp	sysret
  3543                              <1> 		; br sysret9
  3544                              <1> 
  3545                              <1> mkdir:
  3546                              <1> 	; 04/12/2015 (14 byte directory names)
  3547                              <1> 	; 12/10/2015
  3548                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
  3549                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
  3550                              <1> 	;
  3551                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
  3552                              <1> 	; by u.namep into the current directory.
  3553                              <1> 	;
  3554                              <1> 	; INPUTS ->
  3555                              <1> 	;    u.namep - points to a file name 
  3556                              <1> 	;	           that is about to be a directory entry.
  3557                              <1> 	;    ii - current directory's i-number.	
  3558                              <1> 	; OUTPUTS ->
  3559                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name. 
  3560                              <1> 	;    u.off - points to entry to be filled 
  3561                              <1> 	;	     in the current directory		
  3562                              <1> 	;    u.base - points to start of u.dirbuf.
  3563                              <1> 	;    r1 - contains i-number of current directory 
  3564                              <1> 	;	
  3565                              <1> 	; ((AX = R1)) output
  3566                              <1> 	;
  3567                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
  3568                              <1>         ;    ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
  3569                              <1> 	;
  3570                              <1> 
  3571                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
  3572 0000C792 31C0                <1> 	xor 	eax, eax
  3573 0000C794 BF[DC300100]        <1> 	mov     edi, u.dirbuf+2
  3574 0000C799 89FE                <1> 	mov	esi, edi
  3575 0000C79B AB                  <1> 	stosd
  3576 0000C79C AB                  <1> 	stosd
  3577                              <1> 	; 04/12/2015 (14 byte directory names)
  3578 0000C79D AB                  <1> 	stosd
  3579 0000C79E 66AB                <1> 	stosw
  3580                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
  3581 0000C7A0 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
  3582                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
  3583                              <1> 	;mov 	ebp, [u.namep]
  3584 0000C7A2 E88C040000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
  3585                              <1> 		; esi = physical address (page start + offset)
  3586                              <1> 		; ecx = byte count in the page (1 - 4096)
  3587                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
  3588                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
  3589                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
  3590                              <1> mkdir_1: ; 1: 
  3591 0000C7A7 45                  <1> 	inc	ebp ; 12/10/2015
  3592                              <1> 	;
  3593                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
  3594                              <1> 	 ; 01/08/2013
  3595 0000C7A8 AC                  <1> 	lodsb
  3596                              <1> 		; movb (r2)+,r1 / move character in name to r1
  3597 0000C7A9 20C0                <1> 	and 	al, al
  3598 0000C7AB 7427                <1> 	jz 	short mkdir_3 	  
  3599                              <1> 		; beq 1f / if null, done
  3600 0000C7AD 3C2F                <1> 	cmp	al, '/'
  3601                              <1> 		; cmp r1,$'/ / is it a "/"?
  3602 0000C7AF 7414                <1> 	je	short mkdir_err
  3603                              <1> 	;je	error
  3604                              <1> 		; beq error9 / yes, error
  3605                              <1> 	; 12/10/2015
  3606 0000C7B1 6649                <1> 	dec	cx
  3607 0000C7B3 7505                <1> 	jnz	short mkdir_2
  3608                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
  3609 0000C7B5 E87F040000          <1> 	call	trans_addr_nm ; convert virtual address to physical
  3610                              <1> 		; esi = physical address (page start + offset)
  3611                              <1> 		; ecx = byte count in the page
  3612                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
  3613                              <1> mkdir_2:
  3614 0000C7BA 81FF[EA300100]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16) 
  3615                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
  3616                              <1> 				     ; / a char?
  3617 0000C7C0 74E5                <1> 	je	short mkdir_1
  3618                              <1> 		; beq 1b / yes, go back
  3619 0000C7C2 AA                  <1> 	stosb
  3620                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
  3621 0000C7C3 EBE2                <1> 	jmp 	short mkdir_1
  3622                              <1> 		; br 1b / get next char
  3623                              <1> mkdir_err:
  3624                              <1> 	; 17/06/2015
  3625 0000C7C5 C705[FD300100]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
  3625 0000C7CD 0000                <1>
  3626 0000C7CF E950EEFFFF          <1> 	jmp	error
  3627                              <1> 
  3628                              <1> mkdir_3: ; 1:
  3629 0000C7D4 A1[BC300100]        <1> 	mov	eax, [u.dirp]
  3630 0000C7D9 A3[C4300100]        <1> 	mov	[u.off], eax
  3631                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
  3632                              <1> 				 ; / slot to u.off
  3633                              <1> wdir: ; 29/04/2013
  3634 0000C7DE C705[C8300100]-     <1>         mov     dword [u.base], u.dirbuf
  3634 0000C7E4 [DA300100]          <1>
  3635                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
  3636 0000C7E8 C705[CC300100]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
  3636 0000C7F0 0000                <1>
  3637                              <1> 		; mov $10.,u.count / u.count = 10
  3638 0000C7F2 66A1[2D310100]      <1> 	mov	ax, [ii] 
  3639                              <1> 		; mov ii,r1 / r1 has i-number of current directory
  3640 0000C7F8 B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
  3641 0000C7FA E806120000          <1> 	call 	access
  3642                              <1> 		; jsr r0,access; 1 / get i-node and set its file up 
  3643                              <1> 				 ; / for writing
  3644                              <1> 	; AX = i-number of current directory
  3645                              <1> 	; 01/08/2013
  3646 0000C7FF FE05[0F310100]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign	
  3647 0000C805 E8F3110000          <1> 	call	writei
  3648                              <1> 		; jsr r0,writei / write into directory
  3649 0000C80A C3                  <1> 	retn	
  3650                              <1> 		; rts r0
  3651                              <1> 
  3652                              <1> sysexec:
  3653                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
  3654                              <1> 	; 23/06/2015 - 23/10/2015 (Retro UNIX 386 v1)
  3655                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
  3656                              <1> 	;
  3657                              <1> 	; 'sysexec' initiates execution of a file whose path name if
  3658                              <1> 	; pointed to by 'name' in the sysexec call. 
  3659                              <1> 	; 'sysexec' performs the following operations:
  3660                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
  3661                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
  3662                              <1> 	;    3. sets trap vectors to system routines.
  3663                              <1> 	;    4. loads arguments to be passed to executing file into
  3664                              <1> 	;	highest locations of user's core
  3665                              <1> 	;    5. puts pointers to arguments in locations immediately
  3666                              <1> 	;	following arguments.
  3667                              <1> 	;    6.	saves number of arguments in next location.
  3668                              <1> 	;    7. intializes user's stack area so that all registers
  3669                              <1> 	;	will be zeroed and the PS is cleared and the PC set
  3670                              <1> 	;	to core when 'sysret' restores registers 
  3671                              <1> 	;	and does an rti.
  3672                              <1> 	;    8. inializes u.r0 and u.sp
  3673                              <1> 	;    9. zeros user's core down to u.r0
  3674                              <1> 	;   10.	reads executable file from storage device into core
  3675                              <1> 	;	starting at location 'core'.
  3676                              <1> 	;   11.	sets u.break to point to end of user's code with
  3677                              <1> 	;	data area appended.
  3678                              <1> 	;   12.	calls 'sysret' which returns control at location
  3679                              <1> 	;	'core' via 'rti' instruction. 		  		
  3680                              <1> 	;
  3681                              <1> 	; Calling sequence:
  3682                              <1> 	;	sysexec; namep; argp
  3683                              <1> 	; Arguments:
  3684                              <1> 	;	namep - points to pathname of file to be executed
  3685                              <1> 	;	argp  - address of table of argument pointers
  3686                              <1> 	;	argp1... argpn - table of argument pointers
  3687                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
  3688                              <1> 	; Inputs: (arguments)
  3689                              <1> 	; Outputs: -	
  3690                              <1> 	; ...............................................................
  3691                              <1> 	;
  3692                              <1> 	; Retro UNIX 386 v1 modification: 
  3693                              <1> 	;	User application runs in it's own virtual space 
  3694                              <1> 	;	which is izolated from kernel memory (and other
  3695                              <1> 	;	memory pages) via 80386	paging in ring 3 
  3696                              <1> 	;	privilige mode. Virtual start address is always 0.
  3697                              <1> 	;	User's core memory starts at linear address 400000h
  3698                              <1> 	;	(the end of the 1st 4MB).
  3699                              <1> 	;
  3700                              <1> 	; Retro UNIX 8086 v1 modification: 
  3701                              <1> 	;	user/application segment and system/kernel segment
  3702                              <1> 	;	are different and sysenter/sysret/sysrele routines
  3703                              <1> 	;	are different (user's registers are saved to 
  3704                              <1> 	;	and then restored from system's stack.)
  3705                              <1> 	;
  3706                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
  3707                              <1> 	;	      arguments which were in these registers;
  3708                              <1> 	;	      but, it returns by putting the 1st argument
  3709                              <1> 	;	      in 'u.namep' and the 2nd argument
  3710                              <1> 	;	      on top of stack. (1st argument is offset of the
  3711                              <1> 	;	      file/path name in the user's program segment.)		 	
  3712                              <1> 	
  3713                              <1> 	;call	arg2
  3714                              <1> 	; * name - 'u.namep' points to address of file/path name
  3715                              <1> 	;          in the user's program segment ('u.segmnt')
  3716                              <1> 	;          with offset in BX register (as sysopen argument 1).
  3717                              <1> 	; * argp - sysexec argument 2 is in CX register 
  3718                              <1> 	;          which is on top of stack.
  3719                              <1> 	;
  3720                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
  3721                              <1> 
  3722                              <1> 	; 23/06/2015 (32 bit modifications)
  3723                              <1> 
  3724 0000C80B 891D[C0300100]      <1> 	mov	[u.namep], ebx ; argument 1
  3725                              <1>         ; 18/10/2015
  3726 0000C811 890D[28310100]      <1> 	mov     [argv], ecx  ; * ; argument 2
  3727 0000C817 E8D2020000          <1> 	call	namei
  3728                              <1> 		; jsr r0,namei / namei returns i-number of file 
  3729                              <1> 			     ; / named in sysexec call in r1
  3730                              <1> 	;jc	error
  3731                              <1> 		; br error9
  3732 0000C81C 731E                <1> 	jnc	short sysexec_0
  3733                              <1> 	;
  3734                              <1> 	; 'file not found !' error
  3735 0000C81E C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND
  3735 0000C826 0000                <1>
  3736 0000C828 E9F7EDFFFF          <1> 	jmp	error 
  3737                              <1> sysexec_not_exf:
  3738                              <1> 	; 'not executable file !' error
  3739 0000C82D C705[FD300100]1600- <1> 	mov	dword [u.error], ERR_NOT_EXECUTABLE
  3739 0000C835 0000                <1>
  3740 0000C837 E9E8EDFFFF          <1> 	jmp	error 
  3741                              <1> sysexec_0:
  3742 0000C83C E8B9110000          <1> 	call	iget
  3743                              <1> 		; jsr r0,iget / get i-node for file to be executed
  3744 0000C841 66F705[6C2D0100]10- <1>         test    word [i.flgs], 10h
  3744 0000C849 00                  <1>
  3745                              <1> 		; bit $20,i.flgs / is file executable
  3746 0000C84A 74E1                <1> 	jz	short sysexec_not_exf
  3747                              <1> 	;jz	error
  3748                              <1> 		; beq error9
  3749                              <1> 	;;
  3750 0000C84C E8AD110000          <1> 	call	iopen
  3751                              <1> 		; jsr r0,iopen / gets i-node for file with i-number
  3752                              <1> 			     ; / given in r1 (opens file)
  3753                              <1> 	; AX = i-number of the file
  3754 0000C851 66F705[6C2D0100]20- <1> 	test	word [i.flgs], 20h
  3754 0000C859 00                  <1>
  3755                              <1> 		; bit $40,i.flgs / test user id on execution bit
  3756 0000C85A 7415                <1> 	jz	short sysexec_1
  3757                              <1> 		; beq 1f
  3758 0000C85C 803D[F4300100]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013
  3759                              <1> 		; tstb u.uid / test user id
  3760 0000C863 760C                <1> 	jna	short sysexec_1
  3761                              <1> 		; beq 1f / super user
  3762 0000C865 8A0D[6F2D0100]      <1> 	mov	cl, [i.uid]
  3763 0000C86B 880D[F4300100]      <1> 	mov	[u.uid], cl ; 02/08/2013
  3764                              <1> 		; movb i.uid,u.uid / put user id of owner of file
  3765                              <1> 				 ; / as process user id
  3766                              <1> sysexec_1:
  3767                              <1> 	; 18/10/2215
  3768                              <1> 	; 10/10/2015
  3769                              <1> 	; 24/07/2015
  3770                              <1> 	; 21/07/2015
  3771                              <1> 	; 25/06/2015
  3772                              <1> 	; 24/06/2015
  3773                              <1>         ; Moving arguments to the end of [u.upage]
  3774                              <1> 	; (by regarding page borders in user's memory space)
  3775                              <1> 	;
  3776                              <1> 	; 10/10/2015
  3777                              <1> 	; 21/07/2015
  3778 0000C871 89E5                <1> 	mov	ebp, esp ; (**)
  3779                              <1> 	; 18/10/2015
  3780 0000C873 89EF                <1> 	mov 	edi, ebp
  3781 0000C875 B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
  3782                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
  3783 0000C87A 29CF                <1> 	sub	edi, ecx
  3784 0000C87C 89FC                <1> 	mov	esp, edi
  3785 0000C87E 31C0                <1> 	xor	eax, eax
  3786 0000C880 A3[D0300100]        <1> 	mov 	[u.nread], eax ; 0
  3787 0000C885 49                  <1> 	dec	ecx ; 256 - 1
  3788 0000C886 890D[CC300100]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
  3789                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
  3790                              <1> sysexec_2:
  3791 0000C88C 8B35[28310100]      <1> 	mov	esi, [argv] ; 18/10/2015 
  3792 0000C892 E866000000          <1> 	call	get_argp
  3793 0000C897 B904000000          <1> 	mov	ecx, 4 ; mov ecx, 4
  3794                              <1> sysexec_3:
  3795 0000C89C 21C0                <1> 	and	eax, eax
  3796 0000C89E 0F84C4090000        <1>         jz      sysexec_6
  3797                              <1> 	; 18/10/2015
  3798 0000C8A4 010D[28310100]      <1> 	add	[argv], ecx ; 4
  3799 0000C8AA 66FF05[26310100]    <1> 	inc	word [argc]
  3800                              <1> 	;
  3801 0000C8B1 A3[C8300100]        <1> 	mov	[u.base], eax
  3802                              <1>  	; 23/10/2015
  3803 0000C8B6 66C705[0D310100]00- <1> 	mov	word [u.pcount], 0
  3803 0000C8BE 00                  <1>
  3804                              <1> sysexec_4:
  3805 0000C8BF E850100000          <1> 	call	cpass ; get a character from user's core memory
  3806 0000C8C4 750E                <1>         jnz      short sysexec_5
  3807                              <1> 		; (max. 255 chars + null)
  3808                              <1> 	; 18/10/2015
  3809 0000C8C6 28C0                <1> 	sub 	al, al
  3810 0000C8C8 AA                  <1> 	stosb
  3811 0000C8C9 FF05[D0300100]      <1> 	inc	dword [u.nread]
  3812 0000C8CF E994090000          <1> 	jmp	sysexec_6 ; 24/04/2016
  3813                              <1> sysexec_5:
  3814 0000C8D4 AA                  <1> 	stosb
  3815 0000C8D5 20C0                <1> 	and 	al, al
  3816 0000C8D7 75E6                <1> 	jnz	short sysexec_4
  3817 0000C8D9 B904000000          <1> 	mov	ecx, 4
  3818 0000C8DE 390D[24310100]      <1> 	cmp	[ncount], ecx ; 4
  3819 0000C8E4 72A6                <1> 	jb	short sysexec_2
  3820 0000C8E6 8B35[20310100]      <1> 	mov	esi, [nbase]
  3821 0000C8EC 010D[20310100]      <1> 	add	[nbase], ecx ; 4	
  3822 0000C8F2 66290D[24310100]    <1> 	sub	[ncount], cx 
  3823 0000C8F9 8B06                <1> 	mov	eax, [esi]
  3824 0000C8FB EB9F                <1> 	jmp	short sysexec_3
  3825                              <1> 
  3826                              <1> get_argp:
  3827                              <1> 	; 18/10/2015 (nbase, ncount)
  3828                              <1> 	; 21/07/2015
  3829                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
  3830                              <1> 	; Get (virtual) address of argument from user's core memory
  3831                              <1> 	;
  3832                              <1> 	; INPUT:
  3833                              <1> 	;	esi = virtual address of argument pointer
  3834                              <1> 	; OUTPUT:
  3835                              <1> 	;	eax = virtual address of argument
  3836                              <1> 	;
  3837                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
  3838                              <1> 	;
  3839 0000C8FD 833D[05310100]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
  3840                              <1> 				    ; (the caller is kernel)
  3841 0000C904 7667                <1>         jna     short get_argpk 
  3842                              <1> 	;
  3843 0000C906 89F3                <1>      	mov	ebx, esi
  3844 0000C908 E8F183FFFF          <1> 	call	get_physical_addr ; get physical address
  3845 0000C90D 0F8289000000        <1>         jc      get_argp_err
  3846 0000C913 A3[20310100]        <1> 	mov 	[nbase], eax ; physical address	
  3847 0000C918 66890D[24310100]    <1> 	mov	[ncount], cx ; remain byte count in page (1-4096)
  3848 0000C91F B804000000          <1> 	mov	eax, 4 ; 21/07/2015
  3849 0000C924 6639C1              <1> 	cmp	cx, ax ; 4
  3850 0000C927 735D                <1> 	jnb	short get_argp2
  3851 0000C929 89F3                <1> 	mov	ebx, esi
  3852 0000C92B 01CB                <1> 	add	ebx, ecx
  3853 0000C92D E8CC83FFFF          <1> 	call	get_physical_addr ; get physical address
  3854 0000C932 7268                <1> 	jc	short get_argp_err
  3855                              <1> 	;push	esi
  3856 0000C934 89C6                <1> 	mov	esi, eax
  3857 0000C936 66870D[24310100]    <1> 	xchg	cx, [ncount]
  3858 0000C93D 8735[20310100]      <1> 	xchg	esi, [nbase]
  3859 0000C943 B504                <1> 	mov	ch, 4
  3860 0000C945 28CD                <1> 	sub	ch, cl
  3861                              <1> get_argp0:
  3862 0000C947 AC                  <1> 	lodsb
  3863 0000C948 6650                <1> 	push	ax
  3864 0000C94A FEC9                <1> 	dec	cl
  3865 0000C94C 75F9                <1>         jnz     short get_argp0
  3866 0000C94E 8B35[20310100]      <1> 	mov	esi, [nbase]
  3867                              <1> 	; 21/07/2015
  3868 0000C954 0FB6C5              <1> 	movzx	eax, ch
  3869 0000C957 0105[20310100]      <1> 	add	[nbase], eax
  3870 0000C95D 662905[24310100]    <1> 	sub	[ncount], ax
  3871                              <1> get_argp1:
  3872 0000C964 AC                  <1> 	lodsb
  3873 0000C965 FECD                <1> 	dec	ch
  3874 0000C967 743D                <1>         jz      short get_argp3
  3875 0000C969 6650                <1>         push	ax
  3876 0000C96B EBF7                <1> 	jmp     short get_argp1
  3877                              <1> get_argpk:
  3878                              <1> 	; Argument is in kernel's memory space
  3879 0000C96D 66C705[24310100]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
  3879 0000C975 10                  <1>
  3880 0000C976 8935[20310100]      <1> 	mov	[nbase], esi
  3881 0000C97C 8305[20310100]04    <1> 	add	dword [nbase], 4
  3882 0000C983 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physcal addr.
  3883 0000C985 C3                  <1> 	retn
  3884                              <1> get_argp2:
  3885                              <1> 	; 21/07/2015
  3886                              <1> 	;mov	eax, 4
  3887 0000C986 8B15[20310100]      <1> 	mov 	edx, [nbase] ; 18/10/2015
  3888 0000C98C 0105[20310100]      <1> 	add	[nbase], eax
  3889 0000C992 662905[24310100]    <1> 	sub	[ncount], ax
  3890                              <1> 	;
  3891 0000C999 8B02                <1> 	mov	eax, [edx]
  3892 0000C99B C3                  <1> 	retn
  3893                              <1> get_argp_err:
  3894 0000C99C A3[FD300100]        <1> 	mov	[u.error], eax
  3895 0000C9A1 E97EECFFFF          <1> 	jmp	error
  3896                              <1> get_argp3:
  3897 0000C9A6 B103                <1> 	mov	cl, 3
  3898                              <1> get_argp4:
  3899 0000C9A8 C1E008              <1> 	shl	eax, 8
  3900 0000C9AB 665A                <1> 	pop	dx
  3901 0000C9AD 88D0                <1> 	mov 	al, dl
  3902 0000C9AF E2F7                <1>         loop    get_argp4
  3903                              <1> 	;pop	esi
  3904 0000C9B1 C3                  <1> 	retn	
  3905                              <1> 
  3906                              <1> sysfstat: 
  3907                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  3908                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
  3909                              <1> 	;
  3910                              <1> 	; 'sysfstat' is identical to 'sysstat' except that it operates
  3911                              <1> 	; on open files instead of files given by name. It puts the
  3912                              <1> 	; buffer address on the stack, gets the i-number and
  3913                              <1> 	; checks to see if the file is open for reading or writing.
  3914                              <1> 	; If the file is open for writing (i-number is negative)
  3915                              <1> 	; the i-number is set positive and a branch into 'sysstat'
  3916                              <1> 	; is made.	
  3917                              <1> 	;
  3918                              <1> 	; Calling sequence:
  3919                              <1> 	;	sysfstat; buf
  3920                              <1> 	; Arguments:
  3921                              <1> 	;	buf - buffer address
  3922                              <1> 	;
  3923                              <1> 	; Inputs: *u.r0 - file descriptor
  3924                              <1> 	; Outputs: buffer is loaded with file information
  3925                              <1> 	; ...............................................................
  3926                              <1> 	;				
  3927                              <1> 	; Retro UNIX 8086 v1 modification:
  3928                              <1> 	;       'sysfstat' system call has two arguments; so,
  3929                              <1> 	;	* 1st argument, file descriptor is in BX register
  3930                              <1> 	;	* 2nd argument, buf is pointed to by CX register
  3931                              <1> 
  3932                              <1> 	; / set status of open file
  3933                              <1> 		; jsr r0,arg; u.off / put buffer address in u.off
  3934 0000C9B2 51                  <1> 	push	ecx
  3935                              <1> 		; mov u.off,-(sp) / put buffer address on the stack
  3936                              <1> 		; mov *u.r0,r1 / put file descriptor in r1
  3937                              <1> 		; jsr r0,getf / get the files i-number
  3938                              <1> 	; BX = file descriptor (file number)
  3939 0000C9B3 E8FF000000          <1> 	call	getf1
  3940 0000C9B8 6621C0              <1> 	and	ax, ax ; i-number of the file
  3941                              <1> 		; tst	r1 / is it 0?
  3942                              <1> 	;jz	error
  3943                              <1> 		; beq error3 / yes, error
  3944 0000C9BB 750F                <1> 	jnz	short sysfstat1
  3945 0000C9BD C705[FD300100]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
  3945 0000C9C5 0000                <1>
  3946 0000C9C7 E958ECFFFF          <1> 	jmp	error
  3947                              <1> sysfstat1:
  3948 0000C9CC 80FC80              <1> 	cmp	ah, 80h
  3949 0000C9CF 7223                <1>         jb      short sysstat1
  3950                              <1> 		; bgt 1f / if i-number is negative (open for writing)
  3951 0000C9D1 66F7D8              <1> 	neg	ax
  3952                              <1> 		; neg r1 / make it positive, then branch
  3953 0000C9D4 EB1E                <1> 	jmp	short sysstat1
  3954                              <1> 		; br 1f / to 1f
  3955                              <1> sysstat:
  3956                              <1> 	; 18/10/2015
  3957                              <1> 	; 07/10/2015
  3958                              <1> 	; 02/09/2015
  3959                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  3960                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
  3961                              <1> 	;
  3962                              <1> 	; 'sysstat' gets the status of a file. Its arguments are the
  3963                              <1> 	; name of the file and buffer address. The buffer is 34 bytes
  3964                              <1> 	; long and information about the file placed in it.	
  3965                              <1> 	; sysstat calls 'namei' to get the i-number of the file.
  3966                              <1> 	; Then 'iget' is called to get i-node in core. The buffer
  3967                              <1> 	; is then loaded and the results are given in the UNIX
  3968                              <1> 	; Programmers Manual sysstat (II).	
  3969                              <1> 	;
  3970                              <1> 	; Calling sequence:
  3971                              <1> 	;	sysstat; name; buf
  3972                              <1> 	; Arguments:
  3973                              <1> 	;	name - points to the name of the file
  3974                              <1> 	;	buf - address of a 34 bytes buffer
  3975                              <1> 	; Inputs: -
  3976                              <1> 	; Outputs: buffer is loaded with file information
  3977                              <1> 	; ...............................................................
  3978                              <1> 	;				
  3979                              <1> 	; Retro UNIX 8086 v1 modification: 
  3980                              <1> 	;       'sysstat' system call has two arguments; so,
  3981                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
  3982                              <1> 	;	to get sysstat system call arguments from the user;
  3983                              <1> 	;	* 1st argument, name is pointed to by BX register
  3984                              <1> 	;	* 2nd argument, buf is pointed to by CX register
  3985                              <1> 	;
  3986                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
  3987                              <1> 	;	      arguments which were in these registers;
  3988                              <1> 	;	      but, it returns by putting the 1st argument
  3989                              <1> 	;	      in 'u.namep' and the 2nd argument
  3990                              <1> 	;	      on top of stack. (1st argument is offset of the
  3991                              <1> 	;	      file/path name in the user's program segment.)		 	
  3992                              <1> 	
  3993                              <1> 	; / ; name of file; buffer - get files status
  3994                              <1> 		; jsr r0,arg2 / get the 2 arguments
  3995 0000C9D6 891D[C0300100]      <1> 	mov	[u.namep], ebx
  3996 0000C9DC 51                  <1> 	push	ecx
  3997 0000C9DD E80C010000          <1> 	call	namei
  3998                              <1> 		; jsr r0,namei / get the i-number for the file
  3999                              <1> 	;jc	error
  4000                              <1> 		; br error3 / no such file, error
  4001 0000C9E2 7310                <1> 	jnc	short sysstat1
  4002                              <1> 	; pop 	ecx
  4003                              <1> sysstat_err0:
  4004                              <1> 	; 'file not found !' error
  4005 0000C9E4 C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
  4005 0000C9EC 0000                <1>
  4006 0000C9EE E931ECFFFF          <1> 	jmp	error
  4007                              <1> 
  4008 0000C9F3 00                  <1> statx: db 0
  4009                              <1> 
  4010                              <1> sysstat1: ; 1:
  4011 0000C9F4 E801100000          <1> 	call	iget
  4012                              <1> 		; jsr r0,iget / get the i-node into core
  4013                              <1> 	; 07/10/2015 (ax = [ii], inode number)
  4014                              <1> 	; 02/09/2015
  4015 0000C9F9 8F05[C8300100]      <1> 	pop	dword [u.base]
  4016                              <1> 		; mov (sp)+,r3 / move u.off to r3 (points to buffer)
  4017 0000C9FF E858000000          <1> 	call	sysstat_gpa ; get physical address
  4018 0000CA04 730A                <1> 	jnc 	short sysstat2
  4019                              <1> sysstat_err1:
  4020 0000CA06 A3[FD300100]        <1> 	mov	dword [u.error], eax ; error code
  4021 0000CA0B E914ECFFFF          <1> 	jmp	error
  4022                              <1> sysstat2:
  4023 0000CA10 A0[2D310100]        <1> 	mov 	al, [ii] ; 07/10/2015 (result of 'iget' call, above)
  4024 0000CA15 AA                  <1> 	stosb
  4025 0000CA16 FF05[C8300100]      <1> 	inc 	dword [u.base]
  4026 0000CA1C 6649                <1> 	dec 	cx
  4027 0000CA1E 7505                <1> 	jnz	short sysstat3
  4028 0000CA20 E837000000          <1> 	call	sysstat_gpa
  4029                              <1> 	;jc	short sysstat_err1
  4030                              <1> sysstat3:
  4031 0000CA25 A0[2E310100]        <1> 	mov 	al, [ii+1] ; 07/10/2015 (result of 'iget' call, above)
  4032 0000CA2A AA                  <1> 	stosb
  4033                              <1> 		; mov r1,(r3)+ / put i-number in 1st word of buffer
  4034 0000CA2B FF05[C8300100]      <1> 	inc 	dword [u.base]
  4035                              <1> 	;dec 	word [u.pcount]
  4036 0000CA31 6649                <1> 	dec	cx
  4037 0000CA33 7505                <1> 	jnz	short sysstat4
  4038 0000CA35 E822000000          <1> 	call	sysstat_gpa
  4039                              <1> 	;jc	short sysstat_err1	
  4040                              <1> sysstat4:
  4041 0000CA3A BE[6C2D0100]        <1> 	mov	esi, inode
  4042                              <1> 		; mov $inode,r2 / r2 points to i-node
  4043                              <1> sysstat5: ; 1:
  4044 0000CA3F A4                  <1> 	movsb
  4045                              <1> 		; mov (r2)+,(r3)+ / move rest of i-node to buffer
  4046 0000CA40 FF05[C8300100]      <1> 	inc 	dword [u.base]
  4047                              <1> 	;dec 	word [u.pcount]
  4048 0000CA46 6649                <1> 	dec	cx
  4049 0000CA48 7505                <1> 	jnz	short sysstat6
  4050 0000CA4A E80D000000          <1> 	call	sysstat_gpa
  4051                              <1> 	;jc	short sysstat_err1
  4052                              <1> sysstat6:		
  4053 0000CA4F 81FE[8C2D0100]      <1> 	cmp	esi, inode + 32
  4054                              <1> 		; cmp r2,$inode+32 / done?
  4055 0000CA55 75E8                <1> 	jne	short sysstat5
  4056                              <1> 		; bne 1b / no, go back
  4057 0000CA57 E9E8EBFFFF          <1> 	jmp	sysret
  4058                              <1> 		; br sysret3 / return through sysret
  4059                              <1> 	;
  4060                              <1> sysstat_gpa: ; get physical address of file status buffer
  4061                              <1> 	; 02/09/2015
  4062 0000CA5C 8B1D[C8300100]      <1> 	mov 	ebx, [u.base]
  4063                              <1> 	; 07/10/2015
  4064 0000CA62 E89782FFFF          <1> 	call	get_physical_addr ; get physical address
  4065                              <1> 	;jc	short sysstat_gpa1
  4066 0000CA67 729D                <1> 	jc	short sysstat_err1
  4067                              <1> 	; 18/10/2015
  4068 0000CA69 89C7                <1> 	mov	edi, eax ; physical address
  4069                              <1> 	;mov	[u.pcount], cx ; remain bytes in page
  4070                              <1> ;sysstat_gpa1:
  4071 0000CA6B C3                  <1> 	retn
  4072                              <1> 
  4073                              <1> fclose:
  4074                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
  4075                              <1> 	;            (32 bit offset pointer modification)
  4076                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
  4077                              <1> 	;
  4078                              <1> 	; Given the file descriptor (index to the u.fp list)
  4079                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
  4080                              <1> 	; If i-node is active (i-number > 0) the entry in 
  4081                              <1> 	; u.fp list is cleared. If all the processes that opened
  4082                              <1> 	; that file close it, then fsp etry is freed and the file
  4083                              <1> 	; is closed. If not a return is taken. 
  4084                              <1> 	; If the file has been deleted while open, 'anyi' is called
  4085                              <1> 	; to see anyone else has it open, i.e., see if it is appears
  4086                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
  4087                              <1> 	; a check is made to see if the file is special.	
  4088                              <1> 	;
  4089                              <1> 	; INPUTS ->
  4090                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
  4091                              <1> 	;    u.fp - list of entries in the fsp table
  4092                              <1> 	;    fsp - table of entries (4 words/entry) of open files.	 
  4093                              <1> 	; OUTPUTS ->
  4094                              <1> 	;    r1 - contains the same file descriptor
  4095                              <1> 	;    r2 - contains i-number
  4096                              <1> 	;
  4097                              <1> 	; ((AX = R1))
  4098                              <1> 	; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))
  4099                              <1> 	;
  4100                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
  4101                              <1> 	;              if i-number of the file is 0. (error)  	
  4102                              <1> 	;
  4103 0000CA6C 0FB7D0              <1> 	movzx	edx, ax ; **
  4104 0000CA6F 6650                <1> 	push	ax ; ***
  4105                              <1> 		; mov r1,-(sp) / put r1 on the stack (it contains 
  4106                              <1> 			     ; / the index to u.fp list)
  4107 0000CA71 E83F000000          <1> 	call	getf
  4108                              <1> 		; jsr r0,getf / r1 contains i-number, 
  4109                              <1> 			    ; / cdev has device =, u.fofp 
  4110                              <1> 			    ; / points to 3rd word of fsp entry
  4111 0000CA76 6683F801            <1> 	cmp	ax, 1 ; r1
  4112                              <1> 		; tst r1 / is i-number 0?
  4113 0000CA7A 7236                <1> 	jb	short fclose_2
  4114                              <1> 		; beq 1f / yes, i-node not active so return
  4115                              <1> 		; tst (r0)+ / no, jump over error return
  4116 0000CA7C 89D3                <1> 	mov	ebx, edx ; **
  4117 0000CA7E 6689C2              <1> 	mov 	dx, ax ; *
  4118                              <1> 		; mov r1,r2 / move i-number to r2 ;*
  4119                              <1> 		; mov (sp),r1 / restore value of r1 from the stack
  4120                              <1> 			    ; / which is index to u.fp ; **
  4121 0000CA81 C683[AE300100]00    <1> 	mov	byte [ebx+u.fp], 0
  4122                              <1> 		; clrb u.fp(r1) / clear that entry in the u.fp list
  4123 0000CA88 8B1D[B8300100]      <1> 	mov	ebx, [u.fofp]
  4124                              <1> 		; mov u.fofp,r1 / r1 points to 3rd word in fsp entry
  4125                              <1> fclose_0:
  4126 0000CA8E FE4B04              <1> 	dec	byte [ebx+4] ; 18/06/2015
  4127                              <1> 		; decb 2(r1) / decrement the number of processes 
  4128                              <1> 			   ; / that have opened the file
  4129 0000CA91 791F                <1> 	jns	short fclose_2 ; jump if not negative (jump if bit 7 is 0)	 
  4130                              <1> 		; bge 1f / if all processes haven't closed the file, return
  4131                              <1> 	;
  4132 0000CA93 6652                <1> 	push	dx ;*
  4133                              <1> 		; mov r2,-(sp) / put r2 on the stack (i-number)
  4134 0000CA95 6631C0              <1> 	xor	ax, ax ; 0
  4135 0000CA98 668943FC            <1> 	mov	[ebx-4], ax ; 0
  4136                              <1> 		; clr -4(r1) / clear 1st word of fsp entry
  4137 0000CA9C 8A4305              <1> 	mov	al, [ebx+5] ; 18/06/2015
  4138                              <1> 		; tstb	3(r1) / has this file been deleted
  4139 0000CA9F 20C0                <1> 	and	al, al
  4140 0000CAA1 7408                <1> 	jz	short fclose_1
  4141                              <1> 		; beq 2f / no, branch
  4142 0000CAA3 6689D0              <1> 	mov	ax, dx ; *
  4143                              <1> 		; mov r2,r1 / yes, put i-number back into r1
  4144                              <1> 	; AX = inode number
  4145 0000CAA6 E868040000          <1> 	call	anyi
  4146                              <1> 		; jsr r0,anyi / free all blocks related to i-number
  4147                              <1> 			    ; / check if file appears in fsp again
  4148                              <1> fclose_1: ; 2:
  4149 0000CAAB 6658                <1> 	pop	ax ; *
  4150                              <1> 		; mov (sp)+,r1 / put i-number back into r1
  4151 0000CAAD E84D0F0000          <1> 	call	iclose ; close if it is special file 
  4152                              <1> 		; jsr r0,iclose / check to see if its a special file
  4153                              <1> fclose_2: ; 1:
  4154 0000CAB2 6658                <1> 	pop	ax ; ***
  4155                              <1> 		; mov (sp)+,r1 / put index to u.fp back into r1
  4156 0000CAB4 C3                  <1> 	retn
  4157                              <1> 		; rts r0
  4158                              <1> 
  4159                              <1> getf:	; / get the device number and the i-number of an open file
  4160                              <1> 	; 13/05/2015
  4161                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  4162                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
  4163                              <1> 	;
  4164 0000CAB5 89C3                <1> 	mov	ebx, eax
  4165                              <1> getf1: ;; Calling point from 'rw1' (23/05/2013)
  4166 0000CAB7 83FB0A              <1> 	cmp	ebx, 10
  4167                              <1> 		; cmp r1,$10. / user limited to 10 open files
  4168 0000CABA 730A                <1>         jnb	short getf2 ; 13/05/2015
  4169                              <1> 	;jnb     error
  4170                              <1> 		; bhis error3 / u.fp is table of users open files, 
  4171                              <1> 			    ; / index in fsp table
  4172 0000CABC 8A9B[AE300100]      <1> 	mov	bl, [ebx+u.fp]
  4173                              <1> 		; movb	u.fp(r1),r1 / r1 contains number of entry 
  4174                              <1> 		                  ; / in fsp table
  4175 0000CAC2 08DB                <1> 	or	bl, bl
  4176 0000CAC4 7503                <1> 	jnz	short getf3
  4177                              <1> 	;jz	short getf4
  4178                              <1> 		; beq 1f / if its zero return
  4179                              <1> getf2:
  4180                              <1> 	; 'File not open !' error (ax=0)
  4181 0000CAC6 29C0                <1> 	sub	eax, eax
  4182 0000CAC8 C3                  <1> 	retn
  4183                              <1> getf3:	
  4184                              <1> 	; Retro UNIX 386 v1 modification ! (11/05/2015)
  4185                              <1> 	;
  4186                              <1> 	; 'fsp' table (10 bytes/entry)
  4187                              <1> 	; bit 15				   bit 0
  4188                              <1> 	; ---|-------------------------------------------
  4189                              <1> 	; r/w|		i-number of open file
  4190                              <1> 	; ---|-------------------------------------------
  4191                              <1> 	;		   device number
  4192                              <1> 	; -----------------------------------------------
  4193                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
  4194                              <1> 	; -----------------------------------------------
  4195                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
  4196                              <1> 	; ----------------------|------------------------
  4197                              <1> 	;  flag that says file 	| number of processes
  4198                              <1> 	;   has been deleted	| that have file open 
  4199                              <1> 	; ----------------------|------------------------
  4200                              <1> 	;
  4201 0000CAC9 B80A000000          <1> 	mov	eax, 10
  4202 0000CACE F6E3                <1> 	mul	bl
  4203 0000CAD0 BB[762E0100]        <1> 	mov	ebx, fsp - 6 ; the 3rd word in the fsp entry
  4204 0000CAD5 01C3                <1> 	add	ebx, eax
  4205                              <1> 		; asl r1
  4206                              <1> 		; asl r1 / multiply by 8 to get index into 
  4207                              <1> 		       ; / fsp table entry
  4208                              <1> 		; asl r1
  4209                              <1> 		; add $fsp-4,r1 / r1 is pointing at the 3rd word 
  4210                              <1> 			      ; / in the fsp entry
  4211 0000CAD7 891D[B8300100]      <1> 	mov	[u.fofp], ebx
  4212                              <1> 		; mov r1,u.fofp / save address of 3rd word 
  4213                              <1> 			      ; / in fsp entry in u.fofp
  4214 0000CADD 4B                  <1> 	dec	ebx
  4215 0000CADE 4B                  <1> 	dec	ebx
  4216 0000CADF 668B03              <1> 	mov	ax, [ebx]
  4217                              <1> 	;mov	[cdev], al ; ;;Retro UNIX 8086 v1 ! 
  4218 0000CAE2 66A3[8A300100]      <1> 	mov	[cdev], ax ; ;;in fact (!) 
  4219                              <1> 			     ;;dev number is in 1 byte
  4220                              <1> 		; mov -(r1),cdev / remove the device number  cdev
  4221 0000CAE8 4B                  <1> 	dec	ebx
  4222 0000CAE9 4B                  <1> 	dec	ebx
  4223 0000CAEA 668B03              <1> 	mov	ax, [ebx]
  4224                              <1> 		; mov -(r1),r1 / and the i-number  r1
  4225                              <1> getf4:	; 1:
  4226 0000CAED C3                  <1> 	retn
  4227                              <1> 		; rts r0
  4228                              <1> 
  4229                              <1> namei:
  4230                              <1> 	; 04/12/2015 (14 byte file names)
  4231                              <1> 	; 18/10/2015 (nbase, ncount)
  4232                              <1> 	; 12/10/2015
  4233                              <1> 	; 21/08/2015
  4234                              <1> 	; 18/07/2015
  4235                              <1> 	; 02/07/2015
  4236                              <1> 	; 17/06/2015
  4237                              <1> 	; 16/06/2015 (Retro UNIX 386 v1 - Beginning)
  4238                              <1> 	; 24/04/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  4239                              <1> 	;
  4240                              <1> 	; 'namei' takes a file path name and returns i-number of
  4241                              <1> 	; the file in the current directory or the root directory
  4242                              <1> 	; (if the first character of the pathname is '/').	
  4243                              <1> 	;
  4244                              <1> 	; INPUTS ->
  4245                              <1> 	;    u.namep - points to a file path name
  4246                              <1> 	;    u.cdir - i-number of users directory
  4247                              <1> 	;    u.cdev - device number on which user directory resides	
  4248                              <1> 	; OUTPUTS ->
  4249                              <1> 	;    r1 - i-number of file
  4250                              <1> 	;    cdev
  4251                              <1> 	;    u.dirbuf - points to directory entry where a match 
  4252                              <1> 	;               occurs in the search for file path name.
  4253                              <1> 	;	        If no match u.dirb points to the end of 
  4254                              <1> 	;               the directory and r1 = i-number of the current
  4255                              <1> 	;	        directory.	
  4256                              <1> 	; ((AX = R1))
  4257                              <1> 	;
  4258                              <1> 	; (Retro UNIX Prototype : 07/10/2012 - 05/01/2013, UNIXCOPY.ASM)
  4259                              <1>         ; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))  
  4260                              <1> 	;
  4261                              <1> 
  4262 0000CAEE 66A1[AC300100]      <1> 	mov	ax, [u.cdir]
  4263                              <1> 		; mov u.cdir,r1 / put the i-number of current directory
  4264                              <1> 			      ; / in r1
  4265 0000CAF4 668B15[F2300100]    <1> 	mov	dx, [u.cdrv]
  4266 0000CAFB 668915[8A300100]    <1> 	mov	[cdev], dx 	    ; NOTE: Retro UNIX 8086 v1 
  4267                              <1> 				    ; device/drive number is in 1 byte, 
  4268                              <1> 				    ; not in 1 word!
  4269                              <1> 		; mov u.cdev,cdev / device number for users directory 
  4270                              <1> 				; / into cdev
  4271                              <1> 	; 12/10/2015
  4272                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
  4273                              <1>       	 ; convert virtual (pathname) addr to physical address
  4274 0000CB02 E82C010000          <1> 	call    trans_addr_nmbp ; 12/10/2015
  4275                              <1> 		; esi = physical address of [u.namep]
  4276                              <1> 		; ecx = byte count in the page
  4277 0000CB07 803E2F              <1> 	cmp	byte [esi], '/'
  4278                              <1> 		; cmpb *u.namep,$'/ / is first char in file name a /
  4279 0000CB0A 751E                <1> 	jne	short namei_1
  4280                              <1> 		; bne 1f
  4281 0000CB0C FF05[C0300100]      <1> 	inc	dword [u.namep]
  4282                              <1> 		; inc u.namep / go to next char
  4283 0000CB12 6649                <1> 	dec	cx ; remain byte count in the page
  4284 0000CB14 7506                <1> 	jnz	short namei_0
  4285                              <1> 	; 12/10/2015
  4286 0000CB16 E818010000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
  4287                              <1> 		; esi = physical address (page start + offset)
  4288                              <1> 		; ecx = byte count in the page
  4289 0000CB1B 4E                  <1> 	dec	esi
  4290                              <1> namei_0:
  4291 0000CB1C 46                  <1> 	inc 	esi  ; go to next char
  4292 0000CB1D 66A1[94300100]      <1> 	mov	ax, [rootdir] ; 09/07/2013
  4293                              <1> 		; mov rootdir,r1 / put i-number of rootdirectory in r1
  4294 0000CB23 C605[8A300100]00    <1> 	mov	byte [cdev], 0
  4295                              <1> 		; clr cdev / clear device number
  4296                              <1> namei_1: ; 1:
  4297 0000CB2A F606FF              <1> 	test	byte [esi], 0FFh
  4298 0000CB2D 74BE                <1> 	jz	short getf4
  4299                              <1> 	;jz      nig
  4300                              <1> 		; tstb *u.namep / is the character in file name a nul
  4301                              <1> 		; beq nig / yes, end of file name reached; 
  4302                              <1> 			; / branch to "nig"
  4303                              <1> namei_2: ; 1:
  4304                              <1> 	; 18/10/2015
  4305 0000CB2F 8935[20310100]      <1> 	mov 	[nbase], esi
  4306 0000CB35 66890D[24310100]    <1> 	mov 	[ncount], cx
  4307                              <1> 	;
  4308                              <1> 	;mov	dx, 2
  4309 0000CB3C B202                <1> 	mov	dl, 2 ; user flag (read, non-owner)
  4310 0000CB3E E8C20E0000          <1> 	call	access
  4311                              <1> 		; jsr r0,access; 2 / get i-node with i-number r1
  4312                              <1> 	; 'access' will not return here if user has not "r" permission !
  4313 0000CB43 66F705[6C2D0100]00- <1> 	test 	word [i.flgs], 4000h
  4313 0000CB4B 40                  <1>
  4314                              <1> 		; bit $40000,i.flgs / directory i-node?
  4315 0000CB4C 746A                <1>         jz      short namei_err
  4316                              <1> 		; beq error3 / no, got an error
  4317                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
  4318 0000CB4E 31C0                <1> 	xor	eax, eax
  4319 0000CB50 A3[C4300100]        <1> 	mov	[u.off], eax ; 0
  4320 0000CB55 66A1[31310100]      <1> 	mov	ax, [i.size]
  4321 0000CB5B A3[BC300100]        <1> 	mov	[u.dirp], eax
  4322                              <1> 		; mov i.size,u.dirp / put size of directory in u.dirp
  4323                              <1> 		; clr u.off / u.off is file offset used by user
  4324 0000CB60 C705[B8300100]-     <1> 	mov	dword [u.fofp], u.off
  4324 0000CB66 [C4300100]          <1>
  4325                              <1> 		; mov $u.off,u.fofp / u.fofp is a pointer to 
  4326                              <1> 				  ; / the offset portion of fsp entry
  4327                              <1> namei_3: ; 2:
  4328 0000CB6A C705[C8300100]-     <1> 	mov	dword [u.base], u.dirbuf
  4328 0000CB70 [DA300100]          <1>
  4329                              <1> 		; mov $u.dirbuf,u.base / u.dirbuf holds a file name 
  4330                              <1> 				    ; / copied from a directory
  4331 0000CB74 C705[CC300100]1000- <1> 	mov 	dword [u.count], 16 ; 04/12/2015 (10 -> 16) 	
  4331 0000CB7C 0000                <1>
  4332                              <1>  		; mov $10.,u.count / u.count is byte count 
  4333                              <1> 				 ; / for reads and writes
  4334 0000CB7E 66A1[2D310100]      <1> 	mov 	ax, [ii]
  4335                              <1> 	; 31/07/2013 ('namei_r') - 16/06/2015 ('u.kcall')
  4336 0000CB84 FE05[0F310100]      <1>  	inc     byte [u.kcall] ; the caller is 'namei' sign	
  4337 0000CB8A E815090000          <1>     	call	readi
  4338                              <1> 		; jsr r0,readi / read 10. bytes of file 
  4339                              <1> 		      ; with i-number (r1); i.e. read a directory entry
  4340 0000CB8F 8B0D[D0300100]      <1> 	mov 	ecx, [u.nread]
  4341 0000CB95 09C9                <1> 	or 	ecx, ecx
  4342                              <1> 		; tst u.nread
  4343 0000CB97 741B                <1> 	jz	short nib
  4344                              <1> 		; ble nib / gives error return
  4345                              <1> 	;
  4346 0000CB99 668B1D[DA300100]    <1> 	mov 	bx, [u.dirbuf]
  4347 0000CBA0 6621DB              <1> 	and 	bx, bx       
  4348                              <1> 		; tst u.dirbuf /
  4349 0000CBA3 7522                <1> 	jnz	short namei_4
  4350                              <1> 		; bne 3f / branch when active directory entry 
  4351                              <1> 		       ; / (i-node word in entry non zero)
  4352 0000CBA5 A1[C4300100]        <1> 	mov	eax, [u.off]
  4353 0000CBAA 83E810              <1> 	sub	eax, 16 ; 04/12/2015 (10 -> 16) 
  4354 0000CBAD A3[BC300100]        <1> 	mov	[u.dirp], eax
  4355                              <1> 		; mov u.off,u.dirp
  4356                              <1> 		; sub $10.,u.dirp
  4357 0000CBB2 EBB6                <1> 	jmp	short namei_3
  4358                              <1> 		; br 2b
  4359                              <1> 
  4360                              <1> 	; 18/07/2013
  4361                              <1> nib: 
  4362 0000CBB4 31C0                <1> 	xor	eax, eax  ; xor ax, ax ; ax = 0 -> file not found 
  4363 0000CBB6 F9                  <1> 	stc
  4364                              <1> nig:
  4365 0000CBB7 C3                  <1> 	retn
  4366                              <1> 
  4367                              <1> namei_err:
  4368                              <1> 	; 16/06/2015
  4369 0000CBB8 C705[FD300100]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a directory !' error
  4369 0000CBC0 0000                <1>
  4370 0000CBC2 E95DEAFFFF          <1> 	jmp	error
  4371                              <1> 
  4372                              <1> namei_4: ; 3:
  4373                              <1> 	; 18/10/2015
  4374                              <1> 	; 12/10/2015
  4375                              <1> 	; 21/08/2015
  4376                              <1> 	; 18/07/2015
  4377 0000CBC7 8B2D[C0300100]      <1> 	mov	ebp, [u.namep]
  4378                              <1> 		; mov u.namep,r2 / u.namep points into a file name string
  4379 0000CBCD BF[DC300100]        <1> 	mov 	edi, u.dirbuf + 2
  4380                              <1> 		; mov $u.dirbuf+2,r3 / points to file name of directory entry
  4381                              <1> 	; 18/10/2015
  4382 0000CBD2 8B35[20310100]      <1> 	mov	esi, [nbase]	
  4383 0000CBD8 668B0D[24310100]    <1> 	mov	cx, [ncount]
  4384                              <1> 	;
  4385 0000CBDF 6621C9              <1> 	and	cx, cx
  4386 0000CBE2 7505                <1> 	jnz	short namei_5	
  4387                              <1> 	;
  4388 0000CBE4 E850000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
  4389                              <1> 		; esi = physical address (page start + offset)
  4390                              <1> 		; ecx = byte count in the page
  4391                              <1> namei_5: ; 3:
  4392 0000CBE9 45                  <1> 	inc	ebp ; 18/07/2015
  4393 0000CBEA AC                  <1> 	lodsb   ; mov al, [esi] ; inc esi (al = r4)
  4394                              <1> 		; movb (r2)+,r4 / move a character from u.namep string into r4
  4395 0000CBEB 08C0                <1> 	or 	al, al
  4396 0000CBED 741D                <1> 	jz 	short namei_7
  4397                              <1> 		; beq 3f / if char is nul, then the last char in string
  4398                              <1> 			; / has been moved
  4399 0000CBEF 3C2F                <1> 	cmp	al, '/'
  4400                              <1> 		; cmp r4,$'/ / is char a </>
  4401 0000CBF1 7419                <1> 	je 	short namei_7
  4402                              <1> 		; beq 3f	
  4403                              <1> 	; 12/10/2015
  4404 0000CBF3 6649                <1> 	dec	cx ; remain byte count in the page
  4405 0000CBF5 7505                <1> 	jnz	short namei_6
  4406 0000CBF7 E83D000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
  4407                              <1> 		; esi = physical address (page start + offset)
  4408                              <1> 		; ecx = byte count in the page
  4409                              <1> namei_6:
  4410 0000CBFC 81FF[EA300100]      <1>         cmp     edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
  4411                              <1> 		; cmp r3,$u.dirbuf+10. / have I checked
  4412                              <1> 				     ; / all 8 bytes of file name
  4413 0000CC02 74E5                <1> 	je	short namei_5
  4414                              <1> 		; beq 3b
  4415 0000CC04 AE                  <1> 	scasb	
  4416                              <1> 		; cmpb (r3)+,r4 / compare char in u.namep string to file name 
  4417                              <1> 			      ; / char read from directory
  4418 0000CC05 74E2                <1> 	je 	short namei_5
  4419                              <1> 		; beq 3b / branch if chars match
  4420                              <1> 
  4421 0000CC07 E95EFFFFFF          <1>         jmp    namei_3 ; 2b
  4422                              <1> 		; br 2b / file names do not match go to next directory entry
  4423                              <1> namei_7: ; 3:
  4424 0000CC0C 81FF[EA300100]      <1> 	cmp	edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
  4425                              <1> 		; cmp r3,$u.dirbuf+10. / if equal all 8 bytes were matched
  4426 0000CC12 740A                <1> 	je	short namei_8
  4427                              <1> 		; beq 3f
  4428 0000CC14 8A27                <1> 	mov 	ah, [edi]
  4429                              <1> 	;inc 	edi 
  4430 0000CC16 20E4                <1> 	and 	ah, ah
  4431                              <1> 		; tstb (r3)+ /
  4432 0000CC18 0F854CFFFFFF        <1>         jnz     namei_3
  4433                              <1> 		; bne 2b
  4434                              <1> namei_8: ; 3
  4435 0000CC1E 892D[C0300100]      <1> 	mov	[u.namep], ebp ; 18/07/2015
  4436                              <1> 		; mov r2,u.namep / u.namep points to char 
  4437                              <1> 			       ; / following a / or nul
  4438                              <1> 	;mov	bx, [u.dirbuf]
  4439                              <1> 		; mov u.dirbuf,r1 / move i-node number in directory 
  4440                              <1> 				; / entry to r1
  4441 0000CC24 20C0                <1> 	and 	al, al
  4442                              <1> 		; tst r4 / if r4 = 0 the end of file name reached,
  4443                              <1> 		      ;  / if r4 = </> then go to next directory
  4444                              <1> 	; mov	ax, bx
  4445 0000CC26 66A1[DA300100]      <1> 	mov 	ax, [u.dirbuf] ; 17/06/2015
  4446 0000CC2C 0F85FDFEFFFF        <1>         jnz     namei_2 
  4447                              <1> 		; bne 1b
  4448                              <1> 	; AX = i-number of the file
  4449                              <1> ;;nig:
  4450 0000CC32 C3                  <1> 	retn
  4451                              <1> 		; tst (r0)+ / gives non-error return
  4452                              <1> ;;nib:
  4453                              <1> ;;	xor	ax, ax ; Retro UNIX 8086 v1 modification !
  4454                              <1> 		       ; ax = 0 -> file not found 
  4455                              <1> ;;	stc	; 27/05/2013
  4456                              <1> ;;	retn
  4457                              <1> 		; rts r0
  4458                              <1> 
  4459                              <1> trans_addr_nmbp:
  4460                              <1> 	; 18/10/2015
  4461                              <1> 	; 12/10/2015
  4462 0000CC33 8B2D[C0300100]      <1> 	mov 	ebp, [u.namep]
  4463                              <1> trans_addr_nm: 
  4464                              <1> 	; Convert virtual (pathname) address to physical address
  4465                              <1> 	; (Retro UNIX 386 v1 feature only !)
  4466                              <1> 	; 18/10/2015
  4467                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
  4468                              <1> 	; 02/07/2015
  4469                              <1> 	; 17/06/2015
  4470                              <1> 	; 16/06/2015
  4471                              <1> 	;
  4472                              <1> 	; INPUTS: 
  4473                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
  4474                              <1> 	;	[u.pgdir] = user's page directory
  4475                              <1> 	; OUTPUT:
  4476                              <1> 	;       esi = physical address of the pathname
  4477                              <1> 	;	ecx = remain byte count in the page
  4478                              <1> 	;
  4479                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
  4480                              <1> 	;
  4481 0000CC39 833D[05310100]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
  4482 0000CC40 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
  4483                              <1> 				     ; it is already physical address
  4484 0000CC42 50                  <1>    	push	eax	
  4485 0000CC43 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
  4486 0000CC45 E8B480FFFF          <1>        	call	get_physical_addr ; get physical address
  4487 0000CC4A 7204                <1> 	jc	short tr_addr_nm_err
  4488                              <1> 	; 18/10/2015
  4489                              <1> 	; eax = physical address 
  4490                              <1> 	; cx = remain byte count in page (1-4096) 
  4491                              <1> 		; 12/10/2015 (cx = [u.pncount])
  4492 0000CC4C 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
  4493 0000CC4E 58                  <1> 	pop	eax 
  4494 0000CC4F C3                  <1> 	retn
  4495                              <1> 
  4496                              <1> tr_addr_nm_err:
  4497 0000CC50 A3[FD300100]        <1> 	mov	[u.error], eax
  4498                              <1> 	;pop 	eax
  4499 0000CC55 E9CAE9FFFF          <1> 	jmp	error
  4500                              <1> 
  4501                              <1> trans_addr_nmk:
  4502                              <1> 	; 12/10/2015
  4503                              <1> 	; 02/07/2015
  4504 0000CC5A 8B35[C0300100]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
  4505 0000CC60 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
  4506 0000CC64 C3                  <1> 	retn
  4507                              <1> 
  4508                              <1> syschdir:
  4509                              <1> 	; / makes the directory specified in the argument
  4510                              <1> 	; / the current directory
  4511                              <1> 	;
  4512                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4513                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
  4514                              <1> 	;
  4515                              <1> 	; 'syschdir' makes the directory specified in its argument
  4516                              <1> 	; the current working directory.
  4517                              <1> 	;
  4518                              <1> 	; Calling sequence:
  4519                              <1> 	;	syschdir; name
  4520                              <1> 	; Arguments:
  4521                              <1> 	;	name - address of the path name of a directory
  4522                              <1> 	;	       terminated by nul byte.	
  4523                              <1> 	; Inputs: -
  4524                              <1> 	; Outputs: -
  4525                              <1> 	; ...............................................................
  4526                              <1> 	;				
  4527                              <1> 	; Retro UNIX 8086 v1 modification:
  4528                              <1> 	;	 The user/application program puts address of 
  4529                              <1> 	;	 the path name in BX register as 'syschdir' 
  4530                              <1> 	; 	 system call argument.
  4531                              <1> 
  4532 0000CC65 891D[C0300100]      <1> 	mov	[u.namep], ebx
  4533                              <1> 		;jsr r0,arg; u.namep / u.namep points to path name
  4534 0000CC6B E87EFEFFFF          <1> 	call	namei
  4535                              <1> 		; jsr r0,namei / find its i-number
  4536                              <1> 	;jc	error
  4537                              <1> 		; br error3
  4538 0000CC70 730F                <1> 	jnc	short syschdir0
  4539                              <1> 	; 'directory not found !' error
  4540 0000CC72 C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_DIR_NOT_FOUND ; 12
  4540 0000CC7A 0000                <1>
  4541 0000CC7C E9A3E9FFFF          <1> 	jmp	error
  4542                              <1> syschdir0:
  4543 0000CC81 E87F0D0000          <1> 	call	access
  4544                              <1> 		; jsr r0,access; 2 / get i-node into core
  4545 0000CC86 66F705[6C2D0100]00- <1> 	test	word [i.flgs], 4000h
  4545 0000CC8E 40                  <1>
  4546                              <1> 		; bit $40000,i.flgs / is it a directory?
  4547                              <1> 	;jz	error 
  4548                              <1> 		; beq error3 / no error
  4549 0000CC8F 750F                <1> 	jnz	short syschdir1
  4550 0000CC91 C705[FD300100]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
  4550 0000CC99 0000                <1>
  4551 0000CC9B E984E9FFFF          <1> 	jmp	error
  4552                              <1> syschdir1:
  4553 0000CCA0 66A3[AC300100]      <1> 	mov	[u.cdir], ax
  4554                              <1> 		; mov r1,u.cdir / move i-number to users 
  4555                              <1> 			      ; / current directory
  4556 0000CCA6 66A1[8A300100]      <1> 	mov	ax, [cdev]
  4557 0000CCAC 66A3[F2300100]      <1> 	mov	[u.cdrv], ax
  4558                              <1> 		; mov cdev,u.cdev / move its device to users 
  4559                              <1> 			        ; / current device
  4560 0000CCB2 E98DE9FFFF          <1> 	jmp	sysret
  4561                              <1> 		; br sysret3
  4562                              <1> 	
  4563                              <1> syschmod: ; < change mode of file >
  4564                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4565                              <1> 	; 20/06/2013 - 07/07/2013 (Retro UNIX 8086 v1)
  4566                              <1> 	;
  4567                              <1> 	; 'syschmod' changes mode of the file whose name is given as
  4568                              <1> 	; null terminated string pointed to by 'name' has it's mode 
  4569                              <1> 	; changed to 'mode'.
  4570                              <1> 	;
  4571                              <1> 	; Calling sequence:
  4572                              <1> 	;	syschmod; name; mode
  4573                              <1> 	; Arguments:
  4574                              <1> 	;	name - address of the file name
  4575                              <1> 	;	       terminated by null byte.
  4576                              <1> 	;	mode - (new) mode/flags < attributes >
  4577                              <1> 	;	
  4578                              <1> 	; Inputs: -
  4579                              <1> 	; Outputs: -
  4580                              <1> 	; ...............................................................
  4581                              <1> 	;				
  4582                              <1> 	; Retro UNIX 8086 v1 modification: 
  4583                              <1> 	;       'syschmod' system call has two arguments; so,
  4584                              <1> 	;	* 1st argument, name is pointed to by BX register
  4585                              <1> 	;	* 2nd argument, mode is in CX register
  4586                              <1> 	;
  4587                              <1> 	; Mode bits (Flags):
  4588                              <1> 	;	bit 0 - write permission for non-owner (1)
  4589                              <1> 	;	bit 1 - read permission for non-owner (2)
  4590                              <1> 	;	bit 2 - write permission for owner (4)
  4591                              <1> 	;	bit 3 - read permission for owner (8)
  4592                              <1> 	;	bit 4 - executable flag (16) 	
  4593                              <1> 	;	bit 5 - set user ID on execution flag (32) 
  4594                              <1> 	;	bit 6,7,8,9,10,11 are not used (undefined)
  4595                              <1> 	;	bit 12 - large file flag (4096)
  4596                              <1> 	;	bit 13 - file has modified flag (always on) (8192)
  4597                              <1> 	;	bit 14 - directory flag (16384)
  4598                              <1> 	;	bit 15 - 'i-node is allocated' flag (32768)
  4599                              <1> 
  4600                              <1> 	; / name; mode
  4601 0000CCB7 E814000000          <1> 	call	isown
  4602                              <1> 		;jsr r0,isown / get the i-node and check user status
  4603 0000CCBC 66F705[6C2D0100]00- <1> 	test	word [i.flgs], 4000h
  4603 0000CCC4 40                  <1>
  4604                              <1> 		; bit	$40000,i.flgs / directory?
  4605 0000CCC5 7402                <1> 	jz	short syschmod1
  4606                              <1> 		; beq 2f / no
  4607                              <1> 	; AL = (new) mode
  4608 0000CCC7 24CF                <1> 	and	al, 0CFh ; 11001111b (clears bit 4 & 5)
  4609                              <1> 		; bic $60,r2 / su & ex / yes, clear set user id and 
  4610                              <1> 			   ; / executable modes
  4611                              <1> syschmod1: ; 2:
  4612 0000CCC9 A2[6C2D0100]        <1> 	mov	[i.flgs], al	
  4613                              <1> 		; movb r2,i.flgs / move remaining mode to i.flgs
  4614 0000CCCE EB42                <1> 	jmp	short isown1
  4615                              <1> 		; br 1f
  4616                              <1> 
  4617                              <1> isown:
  4618                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4619                              <1> 	; 04/05/2013 - 07/07/2013 (Retro UNIX 8086 v1)
  4620                              <1> 	;
  4621                              <1> 	; 'isown' is given a file name (the 1st argument).
  4622                              <1> 	;  It find the i-number of that file via 'namei' 
  4623                              <1> 	;  then gets the i-node into core via 'iget'.
  4624                              <1> 	;  It then tests to see if the user is super user. 
  4625                              <1> 	;  If not, it cheks to see if the user is owner of 
  4626                              <1> 	;  the file. If he is not an error occurs.
  4627                              <1> 	;  If user is the owner 'setimod' is called to indicate
  4628                              <1> 	;  the inode has been modificed and the 2nd argument of
  4629                              <1> 	;  the call is put in r2.
  4630                              <1> 	;
  4631                              <1> 	; INPUTS ->
  4632                              <1> 	;    arguments of syschmod and syschown calls
  4633                              <1> 	; OUTPUTS ->
  4634                              <1> 	;    u.uid - id of user
  4635                              <1> 	;    imod - set to a 1
  4636                              <1> 	;    r2 - contains second argument of the system call				 	
  4637                              <1> 	;
  4638                              <1> 	;   ((AX=R2) output as 2nd argument)
  4639                              <1> 	;
  4640                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
  4641                              <1> 	;
  4642                              <1> 		; jsr r0,arg2 / u.namep points to file name
  4643                              <1> 	;; ! 2nd argument on top of stack !
  4644                              <1> 	;; 22/06/2015 - 32 bit modifications
  4645                              <1> 	;; 07/07/2013
  4646 0000CCD0 891D[C0300100]      <1> 	mov	[u.namep], ebx ;; 1st argument
  4647 0000CCD6 51                  <1> 	push 	ecx ;; 2nd argument
  4648                              <1> 	;;
  4649 0000CCD7 E812FEFFFF          <1> 	call	namei
  4650                              <1> 		; jsr r0,namei / get its i-number
  4651                              <1>        ; Retro UNIX 8086 v1 modification !
  4652                              <1>        ; ax = 0 -> file not found 
  4653                              <1> 	;and	ax, ax
  4654                              <1> 	;jz	error
  4655                              <1> 	;jc	error ; 27/05/2013
  4656                              <1> 		; br error3
  4657 0000CCDC 730F                <1> 	jnc	short isown0
  4658                              <1> 	; 'file not found !' error
  4659 0000CCDE C705[FD300100]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
  4659 0000CCE6 0000                <1>
  4660 0000CCE8 E937E9FFFF          <1> 	jmp	error
  4661                              <1> isown0:
  4662 0000CCED E8080D0000          <1> 	call	iget
  4663                              <1> 		; jsr r0,iget / get i-node into core
  4664 0000CCF2 A0[F4300100]        <1> 	mov	al, [u.uid] ; 02/08/2013
  4665 0000CCF7 08C0                <1> 	or	al, al
  4666                              <1> 		; tstb u.uid / super user?
  4667 0000CCF9 7417                <1> 	jz	short isown1
  4668                              <1> 		; beq 1f / yes, branch
  4669 0000CCFB 3A05[6F2D0100]      <1> 	cmp	al, [i.uid]
  4670                              <1> 		; cmpb i.uid,u.uid / no, is this the owner of
  4671                              <1> 				 ; / the file
  4672                              <1> 	;jne	error
  4673                              <1> 		; beq 1f / yes
  4674                              <1> 		; jmp error3 / no, error
  4675 0000CD01 740F                <1> 	je	short isown1
  4676                              <1> 
  4677 0000CD03 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER  ; 11
  4677 0000CD0B 0000                <1>
  4678                              <1> 			;  'permission denied !' error
  4679 0000CD0D E912E9FFFF          <1> 	jmp	error
  4680                              <1> isown1: ; 1:
  4681 0000CD12 E8EA0C0000          <1> 	call	setimod
  4682                              <1> 		; jsr r0,setimod / indicates 
  4683                              <1> 		;	       ; / i-node has been modified
  4684 0000CD17 58                  <1> 	pop	eax ; 2nd argument
  4685                              <1> 		; mov (sp)+,r2 / mode is put in r2 
  4686                              <1> 		       ; / (u.off put on stack with 2nd arg)
  4687 0000CD18 C3                  <1> 	retn
  4688                              <1> 		; rts r0
  4689                              <1> 
  4690                              <1> ;;arg:  ; < get system call arguments >
  4691                              <1> 	; 'arg' extracts an argument for a routine whose call is 
  4692                              <1> 	; of form:
  4693                              <1> 	;	sys 'routine' ; arg1
  4694                              <1> 	;		or
  4695                              <1> 	;	sys 'routine' ; arg1 ; arg2
  4696                              <1> 	;		or
  4697                              <1> 	;	sys 'routine' ; arg1;...;arg10 (sys exec) 
  4698                              <1> 	;	
  4699                              <1> 	; INPUTS ->
  4700                              <1> 	;    u.sp+18 - contains a pointer to one of arg1..argn
  4701                              <1> 	;	This pointers's value is actually the value of
  4702                              <1> 	;	update pc at the the trap to sysent (unkni) is
  4703                              <1> 	;	made to process the sys instruction
  4704                              <1> 	;    r0 - contains the return address for the routine
  4705                              <1> 	;	that called arg. The data in the word pointer 
  4706                              <1> 	;	to by the return address is used as address
  4707                              <1> 	;	in which the extracted argument is stored   		
  4708                              <1> 	;    	
  4709                              <1> 	; OUTPUTS ->
  4710                              <1> 	;    'address' - contains the extracted argument 
  4711                              <1> 	;    u.sp+18 - is incremented by 2 
  4712                              <1> 	;    r1 - contains the extracted argument
  4713                              <1> 	;    r0 - points to the next instruction to be
  4714                              <1> 	;	 executed in the calling routine.
  4715                              <1> 	;
  4716                              <1>   
  4717                              <1> 	; mov u.sp,r1
  4718                              <1> 	; mov *18.(r1),*(r0)+ / put argument of system call
  4719                              <1> 			; / into argument of arg2
  4720                              <1> 	; add $2,18.(r1) / point pc on stack 
  4721                              <1> 			      ; / to next system argument
  4722                              <1> 	; rts r0
  4723                              <1> 
  4724                              <1> ;;arg2: ; < get system calls arguments - with file name pointer>
  4725                              <1> 	; 'arg2' takes first argument in system call
  4726                              <1> 	;  (pointer to name of the file) and puts it in location
  4727                              <1> 	;  u.namep; takes second argument and puts it in u.off
  4728                              <1> 	;  and on top of the stack
  4729                              <1> 	;	
  4730                              <1> 	; INPUTS ->
  4731                              <1> 	;    u.sp, r0
  4732                              <1> 	;    	
  4733                              <1> 	; OUTPUTS ->
  4734                              <1> 	;    u.namep
  4735                              <1> 	;    u.off 
  4736                              <1> 	;    u.off pushed on stack
  4737                              <1> 	;    r1
  4738                              <1> 	;
  4739                              <1> 
  4740                              <1> 	; jsr	r0,arg; u.namep / u.namep contains value of
  4741                              <1> 				; / first arg in sys call
  4742                              <1> 	; jsr r0,arg; u.off / u.off contains value of 
  4743                              <1> 				; / second arg in sys call
  4744                              <1> 	; mov r0,r1 / r0 points to calling routine
  4745                              <1> 	; mov (sp),r0 / put operation code back in r0
  4746                              <1> 	; mov u.off,(sp) / put pointer to second argument 
  4747                              <1> 			; / on stack
  4748                              <1> 	; jmp (r1) / return to calling routine
  4749                              <1> 
  4750                              <1> syschown: ; < change owner of file >
  4751                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4752                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  4753                              <1> 	;
  4754                              <1> 	; 'syschown' changes the owner of the file whose name is given
  4755                              <1> 	; as null terminated string pointed to by 'name' has it's owner
  4756                              <1> 	; changed to 'owner'
  4757                              <1> 	;
  4758                              <1> 	; Calling sequence:
  4759                              <1> 	;	syschown; name; owner
  4760                              <1> 	; Arguments:
  4761                              <1> 	;	name - address of the file name
  4762                              <1> 	;	       terminated by null byte.
  4763                              <1> 	;	owner - (new) owner (number/ID)
  4764                              <1> 	;	
  4765                              <1> 	; Inputs: -
  4766                              <1> 	; Outputs: -
  4767                              <1> 	; ...............................................................
  4768                              <1> 	;				
  4769                              <1> 	; Retro UNIX 8086 v1 modification: 
  4770                              <1> 	;       'syschown' system call has two arguments; so,
  4771                              <1> 	;	* 1st argument, name is pointed to by BX register
  4772                              <1> 	;	* 2nd argument, owner number is in CX register
  4773                              <1> 	;
  4774                              <1> 	; / name; owner
  4775 0000CD19 E8B2FFFFFF          <1> 	call	isown
  4776                              <1> 		; jsr r0,isown / get the i-node and check user status
  4777 0000CD1E 803D[F4300100]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013 
  4778                              <1> 		; tstb u.uid / super user
  4779 0000CD25 7418                <1> 	jz	short syschown1
  4780                              <1> 		; beq 2f / yes, 2f
  4781 0000CD27 F605[6C2D0100]20    <1>         test    byte [i.flgs], 20h ; 32
  4782                              <1> 		; bit $40,i.flgs / no, set userid on execution?
  4783                              <1> 	;jnz	error
  4784                              <1> 		; bne 3f / yes error, could create Trojan Horses
  4785 0000CD2E 740F                <1> 	jz	short syschown1
  4786                              <1> 	; 'permission denied !'
  4787 0000CD30 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS  ; 11
  4787 0000CD38 0000                <1>
  4788 0000CD3A E9E5E8FFFF          <1> 	jmp	error
  4789                              <1> syschown1: ; 2:
  4790                              <1> 	; AL = owner (number/ID)
  4791 0000CD3F A2[6F2D0100]        <1> 	mov	[i.uid], al ; 23/06/2015
  4792                              <1> 		;  movb	r2,i.uid / no, put the new owners id 
  4793                              <1> 			       ; / in the i-node
  4794 0000CD44 E9FBE8FFFF          <1> 	jmp	sysret
  4795                              <1> 	; 1: 
  4796                              <1> 		; jmp sysret4
  4797                              <1> 	; 3:
  4798                              <1> 		; jmp	error
  4799                              <1> 
  4800                              <1> systime: ; / get time of year
  4801                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4802                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
  4803                              <1> 	;
  4804                              <1> 	; 20/06/2013
  4805                              <1> 	; 'systime' gets the time of the year.
  4806                              <1> 	; The present time is put on the stack.
  4807                              <1> 	;
  4808                              <1> 	; Calling sequence:
  4809                              <1> 	;	systime
  4810                              <1> 	; Arguments: -
  4811                              <1> 	;	
  4812                              <1> 	; Inputs: -
  4813                              <1> 	; Outputs: sp+2, sp+4 - present time
  4814                              <1> 	; ...............................................................
  4815                              <1> 	;	
  4816                              <1> 	; Retro UNIX 8086 v1 modification: 
  4817                              <1> 	;       'systime' system call will return to the user
  4818                              <1> 	;	with unix time (epoch) in DX:AX register pair
  4819                              <1> 	;
  4820                              <1> 	; 	!! Major modification on original Unix v1 'systime' 
  4821                              <1> 	;	system call for PC compatibility !!		 	
  4822                              <1> 
  4823 0000CD49 E8B90C0000          <1> 	call 	epoch
  4824 0000CD4E A3[A8300100]        <1> 	mov 	[u.r0], eax
  4825                              <1> 		; mov s.time,4(sp)
  4826                              <1> 		; mov s.time+2,2(sp) / put the present time 
  4827                              <1> 				   ; / on the stack
  4828                              <1> 		; br sysret4
  4829 0000CD53 E9ECE8FFFF          <1> 	jmp	sysret 
  4830                              <1> 
  4831                              <1> sysstime: ; / set time
  4832                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4833                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  4834                              <1> 	;
  4835                              <1> 	; 'sysstime' sets the time. Only super user can use this call.
  4836                              <1> 	;
  4837                              <1> 	; Calling sequence:
  4838                              <1> 	;	sysstime
  4839                              <1> 	; Arguments: -
  4840                              <1> 	;	
  4841                              <1> 	; Inputs: sp+2, sp+4 - time system is to be set to.
  4842                              <1> 	; Outputs: -
  4843                              <1> 	; ...............................................................
  4844                              <1> 	;	
  4845                              <1> 	; Retro UNIX 8086 v1 modification: 
  4846                              <1> 	;	the user calls 'sysstime' with unix (epoch) time
  4847                              <1> 	;	(to be set) is in CX:BX register pair as two arguments.
  4848                              <1> 	; 
  4849                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
  4850                              <1> 	;	to get sysstime system call arguments from the user;
  4851                              <1> 	;	* 1st argument, lowword of unix time is in BX register
  4852                              <1> 	;	* 2nd argument, highword of unix time is in CX register		 	
  4853                              <1> 	;
  4854                              <1> 	; 	!! Major modification on original Unix v1 'sysstime' 
  4855                              <1> 	;	system call for PC compatibility !!	
  4856                              <1> 
  4857 0000CD58 803D[F4300100]00    <1> 	cmp	byte [u.uid], 0
  4858                              <1> 		; tstb u.uid / is user the super user
  4859                              <1> 	;ja	error
  4860                              <1> 		; bne error4 / no, error
  4861 0000CD5F 760F                <1> 	jna	short systime1
  4862                              <1> 	; 'permission denied !'
  4863 0000CD61 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11 
  4863 0000CD69 0000                <1>
  4864 0000CD6B E9B4E8FFFF          <1> 	jmp	error
  4865                              <1> systime1:
  4866                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - 32 bit version)
  4867                              <1> 	; EBX = unix (epoch) time (from user)
  4868 0000CD70 89D8                <1> 	mov	eax, ebx
  4869 0000CD72 E8910C0000          <1> 	call 	set_date_time
  4870                              <1> 		; mov 4(sp),s.time
  4871                              <1> 		; mov 2(sp),s.time+2 / set the system time
  4872 0000CD77 E9C8E8FFFF          <1> 	jmp	sysret
  4873                              <1> 		; br sysret4
  4874                              <1> 
  4875                              <1> sysbreak:
  4876                              <1> 	; 18/10/2015
  4877                              <1> 	; 07/10/2015
  4878                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4879                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
  4880                              <1> 	;
  4881                              <1> 	; 'sysbreak' sets the programs break points. 
  4882                              <1> 	; It checks the current break point (u.break) to see if it is
  4883                              <1> 	; between "core" and the stack (sp). If it is, it is made an
  4884                              <1> 	; even address (if it was odd) and the area between u.break
  4885                              <1> 	; and the stack is cleared. The new breakpoint is then put
  4886                              <1> 	; in u.break and control is passed to 'sysret'.
  4887                              <1> 	;
  4888                              <1> 	; Calling sequence:
  4889                              <1> 	;	sysbreak; addr
  4890                              <1> 	; Arguments: -
  4891                              <1> 	;	
  4892                              <1> 	; Inputs: u.break - current breakpoint
  4893                              <1> 	; Outputs: u.break - new breakpoint 
  4894                              <1> 	;	area between old u.break and the stack (sp) is cleared.
  4895                              <1> 	; ...............................................................
  4896                              <1> 	;	
  4897                              <1> 	; Retro UNIX 8086 v1 modification:
  4898                              <1> 	;	The user/application program puts breakpoint address
  4899                              <1> 	;       in BX register as 'sysbreak' system call argument.
  4900                              <1> 	; 	(argument transfer method 1)
  4901                              <1> 	;
  4902                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
  4903                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
  4904                              <1> 	;  NOTE:
  4905                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
  4906                              <1> 	;	'u.break' address) of user's memory for original unix's
  4907                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
  4908                              <1> 
  4909                              <1> 		; mov u.break,r1 / move users break point to r1
  4910                              <1> 		; cmp r1,$core / is it the same or lower than core?
  4911                              <1> 		; blos 1f / yes, 1f
  4912                              <1> 	; 23/06/2015
  4913 0000CD7C 8B2D[D4300100]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
  4914                              <1> 	;and	ebp, ebp
  4915                              <1> 	;jz	short sysbreak_3 
  4916                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
  4917                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
  4918 0000CD82 8B15[A0300100]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
  4919 0000CD88 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
  4920                              <1> 	; 07/10/2015
  4921 0000CD8B 891D[D4300100]      <1> 	mov	[u.break], ebx ; virtual address !!!
  4922                              <1> 	;
  4923 0000CD91 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
  4924                              <1> 			   ; with top of user's stack (virtual!)
  4925 0000CD93 7327                <1> 	jnb	short sysbreak_3
  4926                              <1> 		; cmp r1,sp / is it the same or higher 
  4927                              <1> 			  ; / than the stack?
  4928                              <1> 		; bhis 1f / yes, 1f
  4929 0000CD95 89DE                <1> 	mov	esi, ebx
  4930 0000CD97 29EE                <1> 	sub	esi, ebp ; new break point - old break point
  4931 0000CD99 7621                <1> 	jna	short sysbreak_3 
  4932                              <1> 	;push	ebx
  4933                              <1> sysbreak_1:
  4934 0000CD9B 89EB                <1> 	mov	ebx, ebp  
  4935 0000CD9D E85C7FFFFF          <1> 	call	get_physical_addr ; get physical address
  4936 0000CDA2 0F82A8FEFFFF        <1> 	jc	tr_addr_nm_err
  4937                              <1> 	; 18/10/2015
  4938 0000CDA8 89C7                <1> 	mov	edi, eax 
  4939 0000CDAA 29C0                <1> 	sub	eax, eax ; 0
  4940                              <1> 		 ; ECX = remain byte count in page (1-4096)
  4941 0000CDAC 39CE                <1> 	cmp	esi, ecx
  4942 0000CDAE 7302                <1> 	jnb	short sysbreak_2
  4943 0000CDB0 89F1                <1> 	mov	ecx, esi
  4944                              <1> sysbreak_2:
  4945 0000CDB2 29CE                <1> 	sub	esi, ecx
  4946 0000CDB4 01CD                <1> 	add	ebp, ecx
  4947 0000CDB6 F3AA                <1> 	rep 	stosb
  4948 0000CDB8 09F6                <1> 	or	esi, esi
  4949 0000CDBA 75DF                <1> 	jnz	short sysbreak_1
  4950                              <1> 	;
  4951                              <1> 		; bit $1,r1 / is it an odd address
  4952                              <1> 		; beq 2f / no, its even
  4953                              <1> 		; clrb (r1)+ / yes, make it even
  4954                              <1> 	; 2: / clear area between the break point and the stack
  4955                              <1> 		; cmp r1,sp / is it higher or same than the stack
  4956                              <1> 		; bhis 1f / yes, quit
  4957                              <1> 		; clr (r1)+ / clear word
  4958                              <1> 		; br 2b / go back
  4959                              <1> 	;pop	ebx
  4960                              <1> sysbreak_3: ; 1:
  4961                              <1> 	;mov	[u.break], ebx ; virtual address !!!
  4962                              <1> 		; jsr r0,arg; u.break / put the "address" 
  4963                              <1> 			; / in u.break (set new break point)
  4964                              <1> 		; br sysret4 / br sysret
  4965 0000CDBC E983E8FFFF          <1> 	jmp	sysret
  4966                              <1> 
  4967                              <1> 
  4968                              <1> maknod: 
  4969                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4970                              <1> 	; 02/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  4971                              <1> 	;
  4972                              <1> 	; 'maknod' creates an i-node and makes a directory entry
  4973                              <1> 	; for this i-node in the current directory.
  4974                              <1> 	;
  4975                              <1> 	; INPUTS ->
  4976                              <1> 	;    r1 - contains mode
  4977                              <1> 	;    ii - current directory's i-number	
  4978                              <1> 	;    	
  4979                              <1> 	; OUTPUTS ->
  4980                              <1> 	;    u.dirbuf - contains i-number of free i-node 
  4981                              <1> 	;    i.flgs - flags in new i-node 
  4982                              <1> 	;    i.uid - filled with u.uid
  4983                              <1> 	;    i.nlks - 1 is put in the number of links
  4984                              <1> 	;    i.ctim - creation time				
  4985                              <1> 	;    i.ctim+2 - modification time
  4986                              <1> 	;    imod - set via call to setimod
  4987                              <1> 	;	
  4988                              <1> 	; ((AX = R1)) input
  4989                              <1> 	;
  4990                              <1> 	; (Retro UNIX Prototype : 
  4991                              <1> 	;	30/10/2012 - 01/03/2013, UNIXCOPY.ASM)
  4992                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
  4993                              <1> 
  4994                              <1> 	; / r1 contains the mode
  4995 0000CDC1 80CC80              <1> 	or 	ah, 80h  ; 10000000b
  4996                              <1> 		; bis	$100000,r1 / allocate flag set
  4997 0000CDC4 6650                <1> 	push	ax
  4998                              <1> 		; mov r1,-(sp) / put mode on stack
  4999                              <1> 	; 31/07/2013
  5000 0000CDC6 66A1[2D310100]      <1> 	mov	ax, [ii] ; move current i-number to AX/r1
  5001                              <1> 		; mov ii,r1 / move current i-number to r1
  5002 0000CDCC B201                <1> 	mov	dl, 1 ; owner flag mask
  5003 0000CDCE E8320C0000          <1> 	call	access	
  5004                              <1> 		; jsr r0,access; 1 / get its i-node into core
  5005 0000CDD3 6650                <1> 	push	ax
  5006                              <1> 		; mov r1,-(sp) / put i-number on stack
  5007 0000CDD5 66B82800            <1> 	mov	ax, 40
  5008                              <1> 		; mov $40.,r1 / r1 = 40
  5009                              <1> maknod1: ; 1: / scan for a free i-node (next 4 instructions)
  5010 0000CDD9 6640                <1> 	inc	ax
  5011                              <1> 		; inc r1 / r1 = r1 + 1
  5012 0000CDDB E8290C0000          <1> 	call	imap
  5013                              <1> 		; jsr r0,imap / get byte address and bit position in 
  5014                              <1> 			    ; /	inode map in r2 & m
  5015                              <1>           ; DX (MQ) has a 1 in the calculated bit position
  5016                              <1>           ; eBX (R2) has byte address of the byte with allocation bit
  5017                              <1> 	; 22/06/2015 - NOTE for next Retro UNIX version: 
  5018                              <1> 	;	       Inode count must be checked here
  5019                              <1> 	; (Original UNIX v1 did not check inode count here !?) 	
  5020 0000CDE0 8413                <1> 	test	[ebx], dl
  5021                              <1> 		; bitb mq,(r2) / is the i-node active
  5022 0000CDE2 75F5                <1> 	jnz	short maknod1
  5023                              <1> 		; bne 1b / yes, try the next one
  5024 0000CDE4 0813                <1> 	or	[ebx], dl
  5025                              <1> 		; bisb mq,(r2) / no, make it active 
  5026                              <1> 			     ; / (put a 1 in the bit map)
  5027 0000CDE6 E80F0C0000          <1> 	call	iget
  5028                              <1> 		; jsr r0,iget / get i-node into core
  5029 0000CDEB 66F705[6C2D0100]00- <1> 	test	word [i.flgs], 8000h 
  5029 0000CDF3 80                  <1>
  5030                              <1> 		; tst i.flgs / is i-node already allocated
  5031 0000CDF4 75E3                <1> 	jnz	short maknod1	
  5032                              <1> 		; blt 1b / yes, look for another one
  5033 0000CDF6 66A3[DA300100]      <1> 	mov	[u.dirbuf], ax
  5034                              <1> 		; mov r1,u.dirbuf / no, put i-number in u.dirbuf
  5035 0000CDFC 6658                <1> 	pop	ax
  5036                              <1> 		; mov (sp)+,r1 / get current i-number back
  5037 0000CDFE E8F70B0000          <1> 	call	iget
  5038                              <1> 		; jsr r0,iget / get i-node in core
  5039 0000CE03 E88AF9FFFF          <1> 	call	mkdir
  5040                              <1> 		; jsr r0,mkdir / make a directory entry 
  5041                              <1> 			     ; / in current directory
  5042 0000CE08 66A1[DA300100]      <1> 	mov	ax, [u.dirbuf]
  5043                              <1> 		; mov u.dirbuf,r1 / r1 = new inode number
  5044 0000CE0E E8E70B0000          <1> 	call	iget
  5045                              <1> 		; jsr r0,iget / get it into core
  5046                              <1> 		; jsr r0,copyz; inode; inode+32. / 0 it out
  5047 0000CE13 B908000000          <1> 	mov	ecx, 8 
  5048 0000CE18 31C0                <1> 	xor	eax, eax ; 0
  5049 0000CE1A BF[6C2D0100]        <1> 	mov	edi, inode 
  5050 0000CE1F F3AB                <1> 	rep	stosd
  5051                              <1> 	;
  5052 0000CE21 668F05[6C2D0100]    <1> 	pop	word [i.flgs]
  5053                              <1> 		; mov (sp)+,i.flgs / fill flags
  5054 0000CE28 8A0D[F4300100]      <1> 	mov 	cl, [u.uid] ; 02/08/2013
  5055 0000CE2E 880D[6F2D0100]      <1> 	mov 	[i.uid], cl
  5056                              <1> 		; movb u.uid,i.uid / user id	
  5057 0000CE34 C605[6E2D0100]01    <1> 	mov     byte [i.nlks], 1
  5058                              <1> 		; movb $1,i.nlks / 1 link
  5059                              <1> 	;call	epoch ; Retro UNIX 8086 v1 modification !
  5060                              <1> 	;mov	eax, [s.time]
  5061                              <1> 	;mov 	[i.ctim], eax
  5062                              <1> 	 	; mov s.time,i.ctim / time created
  5063                              <1> 	 	; mov s.time+2,i.ctim+2 / time modified
  5064                              <1> 	; Retro UNIX 8086 v1 modification !
  5065                              <1> 	; i.ctime=0, i.ctime+2=0 and
  5066                              <1>         ; 'setimod' will set ctime of file via 'epoch'
  5067 0000CE3B E8C10B0000          <1> 	call setimod
  5068                              <1> 		; jsr r0,setimod / set modified flag
  5069 0000CE40 C3                  <1> 	retn
  5070                              <1> 		; rts r0 / return
  5071                              <1> 
  5072                              <1> sysseek: ; / moves read write pointer in an fsp entry
  5073                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5074                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  5075                              <1> 	;
  5076                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
  5077                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
  5078                              <1> 	; The file descriptor refers to a file open for reading or
  5079                              <1> 	; writing. The read (or write) pointer is set as follows:
  5080                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
  5081                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
  5082                              <1> 	;	  current location plus offset.
  5083                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
  5084                              <1> 	;	  size of file plus offset.
  5085                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
  5086                              <1> 	;
  5087                              <1> 	; Calling sequence:
  5088                              <1> 	;	sysseek; offset; ptrname
  5089                              <1> 	; Arguments:
  5090                              <1> 	;	offset - number of bytes desired to move 
  5091                              <1> 	;		 the r/w pointer
  5092                              <1> 	;	ptrname - a switch indicated above
  5093                              <1> 	;
  5094                              <1> 	; Inputs: r0 - file descriptor 
  5095                              <1> 	; Outputs: -
  5096                              <1> 	; ...............................................................
  5097                              <1> 	;	
  5098                              <1> 	; Retro UNIX 8086 v1 modification: 
  5099                              <1> 	;       'sysseek' system call has three arguments; so,
  5100                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
  5101                              <1> 	;	* 2nd argument, offset is in CX register
  5102                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register	
  5103                              <1> 	;	
  5104                              <1> 
  5105 0000CE41 E823000000          <1> 	call	seektell
  5106                              <1> 	; AX = u.count
  5107                              <1> 	; BX = *u.fofp
  5108                              <1> 		; jsr r0,seektell / get proper value in u.count
  5109                              <1> 		; add u.base,u.count / add u.base to it
  5110 0000CE46 0305[C8300100]      <1> 	add	eax, [u.base] ; add offset (u.base) to base
  5111 0000CE4C 8903                <1> 	mov	[ebx], eax
  5112                              <1> 		; mov u.count,*u.fofp / put result into r/w pointer
  5113 0000CE4E E9F1E7FFFF          <1> 	jmp	sysret
  5114                              <1> 		; br sysret4
  5115                              <1> 
  5116                              <1> systell: ; / get the r/w pointer
  5117                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5118                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  5119                              <1> 	;
  5120                              <1> 	; Retro UNIX 8086 v1 modification:
  5121                              <1> 	; ! 'systell' does not work in original UNIX v1,
  5122                              <1> 	; 	    it returns with error !
  5123                              <1> 	; Inputs: r0 - file descriptor 
  5124                              <1> 	; Outputs: r0 - file r/w pointer
  5125                              <1> 
  5126                              <1> 	;xor	ecx, ecx ; 0
  5127 0000CE53 BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
  5128                              <1> 	;call 	seektell
  5129 0000CE58 E812000000          <1> 	call 	seektell0 ; 05/08/2013
  5130                              <1> 	;mov	ebx, [u.fofp]
  5131 0000CE5D 8B03                <1> 	mov	eax, [ebx]
  5132 0000CE5F A3[A8300100]        <1> 	mov	[u.r0], eax
  5133 0000CE64 E9DBE7FFFF          <1> 	jmp	sysret
  5134                              <1> 
  5135                              <1> ; Original unix v1 'systell' system call:
  5136                              <1> 		; jsr r0,seektell
  5137                              <1> 		; br error4
  5138                              <1> 
  5139                              <1> seektell:
  5140                              <1> 	; 03/01/2016
  5141                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5142                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  5143                              <1> 	;
  5144                              <1> 	; 'seektell' puts the arguments from sysseek and systell
  5145                              <1> 	; call in u.base and u.count. It then gets the i-number of
  5146                              <1> 	; the file from the file descriptor in u.r0 and by calling
  5147                              <1> 	; getf. The i-node is brought into core and then u.count
  5148                              <1> 	; is checked to see it is a 0, 1, or 2.
  5149                              <1> 	; If it is 0 - u.count stays the same
  5150                              <1> 	;          1 - u.count = offset (u.fofp)
  5151                              <1> 	;	   2 - u.count = i.size (size of file)
  5152                              <1> 	; 	 		
  5153                              <1> 	; !! Retro UNIX 8086 v1 modification:
  5154                              <1> 	;	Argument 1, file descriptor is in BX;
  5155                              <1> 	;	Argument 2, offset is in CX;
  5156                              <1> 	;	Argument 3, ptrname/switch is in DX register.	
  5157                              <1> 	;
  5158                              <1> 	; mov 	ax, 3 ; Argument transfer method 3 (three arguments)	
  5159                              <1> 	; call 	arg
  5160                              <1> 	;
  5161                              <1> 	; ((Return -> ax = base for offset (position= base+offset))
  5162                              <1> 	;
  5163 0000CE69 890D[C8300100]      <1> 	mov 	[u.base], ecx ; offset
  5164                              <1> 		; jsr r0,arg; u.base / puts offset in u.base
  5165                              <1> seektell0:
  5166 0000CE6F 8915[CC300100]      <1> 	mov 	[u.count], edx
  5167                              <1> 		; jsr r0,arg; u.count / put ptr name in u.count
  5168                              <1> 	; mov	ax, bx
  5169                              <1> 		; mov *u.r0,r1 / file descriptor in r1 
  5170                              <1> 			     ; / (index in u.fp list)
  5171                              <1> 	; call	getf
  5172                              <1> 		; jsr r0,getf / u.fofp points to 3rd word in fsp entry
  5173                              <1> 	; BX = file descriptor (file number)
  5174 0000CE75 E83DFCFFFF          <1> 	call	getf1
  5175 0000CE7A 6609C0              <1> 	or	ax, ax ; i-number of the file
  5176                              <1> 		; mov r1,-(sp) / r1 has i-number of file, 
  5177                              <1> 		             ; / put it on the stack
  5178                              <1> 	;jz	error
  5179                              <1> 		; beq error4 / if i-number is 0, not active so error
  5180 0000CE7D 750F                <1> 	jnz	short seektell1
  5181 0000CE7F C705[FD300100]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
  5181 0000CE87 0000                <1>
  5182 0000CE89 E996E7FFFF          <1> 	jmp	error
  5183                              <1> seektell1:
  5184                              <1> 	;push	eax
  5185 0000CE8E 80FC80              <1> 	cmp	ah, 80h
  5186 0000CE91 7203                <1> 	jb	short seektell2
  5187                              <1> 		; bgt .+4 / if its positive jump
  5188 0000CE93 66F7D8              <1> 	neg	ax
  5189                              <1> 		; neg r1 / if not make it positive
  5190                              <1> seektell2:
  5191 0000CE96 E85F0B0000          <1> 	call	iget
  5192                              <1> 		; jsr r0,iget / get its i-node into core
  5193 0000CE9B 8B1D[B8300100]      <1>         mov     ebx, [u.fofp] ; 05/08/2013
  5194 0000CEA1 803D[CC300100]01    <1> 	cmp	byte [u.count], 1
  5195                              <1> 		; cmp u.count,$1 / is ptr name =1
  5196 0000CEA8 7705                <1> 	ja	short seektell3
  5197                              <1> 		; blt 2f / no its zero
  5198 0000CEAA 740A                <1> 	je	short seektell_4
  5199                              <1> 		; beq 1f / yes its 1
  5200 0000CEAC 31C0                <1> 	xor	eax, eax
  5201                              <1> 	;jmp	short seektell_5
  5202 0000CEAE C3                  <1> 	retn
  5203                              <1> seektell3:
  5204                              <1> 	; 03/01/2016
  5205                              <1> 	;movzx	eax, word [i.size]
  5206 0000CEAF 66A1[31310100]      <1>         mov   	ax, [i.size]
  5207                              <1>                 ; mov i.size,u.count /  put number of bytes 
  5208                              <1>                                    ; / in file in u.count
  5209                              <1> 	;jmp	short seektell_5
  5210                              <1> 		; br 2f
  5211 0000CEB5 C3                  <1> 	retn
  5212                              <1> seektell_4: ; 1: / ptrname =1
  5213                              <1> 	;mov	ebx, [u.fofp]
  5214 0000CEB6 8B03                <1> 	mov	eax, [ebx]
  5215                              <1> 		; mov *u.fofp,u.count / put offset in u.count
  5216                              <1> ;seektell_5: ; 2: / ptrname =0
  5217                              <1> 	;mov	[u.count], eax
  5218                              <1> 	;pop	eax 
  5219                              <1> 		; mov (sp)+,r1 / i-number on stack  r1
  5220 0000CEB8 C3                  <1> 	retn
  5221                              <1> 		; rts r0
  5222                              <1> 
  5223                              <1> sysintr: ; / set interrupt handling
  5224                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5225                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
  5226                              <1> 	;
  5227                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
  5228                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
  5229                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
  5230                              <1> 	; If one does the interrupt character in the tty buffer is
  5231                              <1> 	; cleared and 'sysret'is called. If one does not exits
  5232                              <1> 	; 'sysret' is just called.	
  5233                              <1> 	;
  5234                              <1> 	; Calling sequence:
  5235                              <1> 	;	sysintr; arg
  5236                              <1> 	; Argument:
  5237                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
  5238                              <1> 	;	    - if 1, intterupts cause their normal result
  5239                              <1> 	;		 i.e force an exit.
  5240                              <1> 	;	    - if arg is a location within the program,
  5241                              <1> 	;		control is passed to that location when
  5242                              <1> 	;		an interrupt occurs.	
  5243                              <1> 	; Inputs: -
  5244                              <1> 	; Outputs: -
  5245                              <1> 	; ...............................................................
  5246                              <1> 	;	
  5247                              <1> 	; Retro UNIX 8086 v1 modification: 
  5248                              <1> 	;       'sysintr' system call sets u.intr to value of BX
  5249                              <1> 	;	then branches into sysquit.
  5250                              <1> 	;
  5251 0000CEB9 66891D[EC300100]    <1> 	mov	[u.intr], bx
  5252                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
  5253                              <1> 		; br 1f / go into quit routine
  5254 0000CEC0 E97FE7FFFF          <1> 	jmp	sysret
  5255                              <1> 
  5256                              <1> sysquit:
  5257                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5258                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
  5259                              <1> 	;
  5260                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
  5261                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
  5262                              <1> 	; tty exists. If one does the interrupt character in the tty
  5263                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
  5264                              <1> 	; 'sysret' is just called.	
  5265                              <1> 	;
  5266                              <1> 	; Calling sequence:
  5267                              <1> 	;	sysquit; arg
  5268                              <1> 	; Argument:
  5269                              <1> 	;	arg - if 0, this call diables quit signals from the
  5270                              <1> 	;		typewriter (ASCII FS)
  5271                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
  5272                              <1> 	;		cease and a core image to be produced.
  5273                              <1> 	;		 i.e force an exit.
  5274                              <1> 	;	    - if arg is an addres in the program,
  5275                              <1> 	;		a quit causes control to sent to that
  5276                              <1> 	;		location.	
  5277                              <1> 	; Inputs: -
  5278                              <1> 	; Outputs: -
  5279                              <1> 	; ...............................................................
  5280                              <1> 	;	
  5281                              <1> 	; Retro UNIX 8086 v1 modification: 
  5282                              <1> 	;       'sysquit' system call sets u.quit to value of BX
  5283                              <1> 	;	then branches into 'sysret'.
  5284                              <1> 	;
  5285 0000CEC5 66891D[EE300100]    <1> 	mov	[u.quit], bx
  5286 0000CECC E973E7FFFF          <1> 	jmp	sysret
  5287                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
  5288                              <1> 	;1:
  5289                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
  5290                              <1> 			      ; / to r1
  5291                              <1> 		; beq sysret4 / return to user
  5292                              <1> 		; clrb 6(r1) / clear the interrupt character 
  5293                              <1> 			   ; / in the tty buffer
  5294                              <1> 		; br sysret4 / return to user
  5295                              <1> 
  5296                              <1> syssetuid: ; / set process id
  5297                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5298                              <1> 	; 07/07/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  5299                              <1> 	;
  5300                              <1> 	; 'syssetuid' sets the user id (u.uid) of the current process
  5301                              <1> 	; to the process id in (u.r0). Both the effective user and 
  5302                              <1> 	; u.uid and the real user u.ruid are set to this. 
  5303                              <1> 	; Only the super user can make this call.	
  5304                              <1> 	;
  5305                              <1> 	; Calling sequence:
  5306                              <1> 	;	syssetuid
  5307                              <1> 	; Arguments: -
  5308                              <1> 	;
  5309                              <1> 	; Inputs: (u.r0) - contains the process id.
  5310                              <1> 	; Outputs: -
  5311                              <1> 	; ...............................................................
  5312                              <1> 	;	
  5313                              <1> 	; Retro UNIX 8086 v1 modification: 
  5314                              <1> 	;       BL contains the (new) user ID of the current process
  5315                              <1> 
  5316                              <1> 		; movb *u.r0,r1 / move process id (number) to r1
  5317 0000CED1 3A1D[F5300100]      <1> 	cmp	bl, [u.ruid] 
  5318                              <1> 		; cmpb r1,u.ruid / is it equal to the real user 
  5319                              <1> 			       ; / id number
  5320 0000CED7 741E                <1> 	je	short setuid1
  5321                              <1> 		; beq 1f / yes
  5322 0000CED9 803D[F4300100]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
  5323                              <1> 		; tstb u.uid / no, is current user the super user?
  5324                              <1> 	;ja	error
  5325                              <1> 		; bne error4 / no, error
  5326 0000CEE0 760F                <1> 	jna	short setuid0
  5327 0000CEE2 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11
  5327 0000CEEA 0000                <1>
  5328                              <1> 				;  'permission denied !' error
  5329 0000CEEC E933E7FFFF          <1> 	jmp	error
  5330                              <1> setuid0:
  5331 0000CEF1 881D[F5300100]      <1> 	mov	[u.ruid], bl
  5332                              <1> setuid1: ; 1:
  5333 0000CEF7 881D[F4300100]      <1> 	mov	[u.uid], bl ; 02/08/2013
  5334                              <1> 		; movb r1,u.uid / put process id in u.uid
  5335                              <1> 		; movb r1,u.ruid / put process id in u.ruid
  5336 0000CEFD E942E7FFFF          <1> 	jmp	sysret
  5337                              <1> 		; br sysret4 / system return
  5338                              <1> 
  5339                              <1> sysgetuid: ; < get user id >
  5340                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5341                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
  5342                              <1> 	;
  5343                              <1> 	; 'sysgetuid' returns the real user ID of the current process.
  5344                              <1> 	; The real user ID identifies the person who is logged in,
  5345                              <1> 	; in contradistinction to the effective user ID, which
  5346                              <1> 	; determines his access permission at each moment. It is thus
  5347                              <1> 	; useful to programs which operate using the 'set user ID'
  5348                              <1> 	; mode, to find out who invoked them.	
  5349                              <1> 	;
  5350                              <1> 	; Calling sequence:
  5351                              <1> 	;	syssetuid
  5352                              <1> 	; Arguments: -
  5353                              <1> 	;
  5354                              <1> 	; Inputs: -
  5355                              <1> 	; Outputs: (u.r0) - contains the real user's id.
  5356                              <1> 	; ...............................................................
  5357                              <1> 	;	
  5358                              <1> 	; Retro UNIX 8086 v1 modification: 
  5359                              <1> 	;       AL contains the real user ID at return.
  5360                              <1> 	;
  5361 0000CF02 0FB605[F5300100]    <1> 	movzx 	eax, byte [u.ruid]
  5362 0000CF09 A3[A8300100]        <1> 	mov	[u.r0], eax
  5363                              <1> 		; movb	u.ruid,*u.r0 / move the real user id to (u.r0)
  5364 0000CF0E E931E7FFFF          <1> 	jmp	sysret
  5365                              <1> 		; br sysret4 / systerm return, sysret
  5366                              <1> 
  5367                              <1> anyi: 
  5368                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  5369                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
  5370                              <1> 	;
  5371                              <1> 	; 'anyi' is called if a file deleted while open.
  5372                              <1> 	; "anyi" checks to see if someone else has opened this file.
  5373                              <1> 	;
  5374                              <1> 	; INPUTS ->
  5375                              <1> 	;    r1 - contains an i-number
  5376                              <1> 	;    fsp - start of table containing open files
  5377                              <1> 	;
  5378                              <1> 	; OUTPUTS ->
  5379                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
  5380                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
  5381                              <1> 	;    if file not found - bit in i-node map is cleared
  5382                              <1> 	;    			 (i-node is freed)
  5383                              <1> 	;               all blocks related to i-node are freed
  5384                              <1> 	;	        all flags in i-node are cleared
  5385                              <1> 	; ((AX = R1)) input
  5386                              <1> 	;
  5387                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
  5388                              <1>         ;    ((Modified registers: eDX, eCX, eBX, eSI, eDI, eBP))  
  5389                              <1> 	;
  5390                              <1> 		; / r1 contains an i-number
  5391 0000CF13 BB[7C2E0100]        <1> 	mov	ebx, fsp
  5392                              <1> 		; mov $fsp,r2 / move start of fsp table to r2
  5393                              <1> anyi_1: ; 1:
  5394 0000CF18 663B03              <1> 	cmp	ax, [ebx]
  5395                              <1> 		; cmp r1,(r2) / do i-numbers match?
  5396 0000CF1B 7433                <1> 	je	short anyi_3
  5397                              <1> 		; beq 1f / yes, 1f
  5398 0000CF1D 66F7D8              <1> 	neg	ax
  5399                              <1> 		; neg r1 / no complement r1
  5400 0000CF20 663B03              <1> 	cmp	ax, [ebx]
  5401                              <1> 		; cmp r1,(r2) / do they match now?
  5402 0000CF23 742B                <1> 	je	short anyi_3
  5403                              <1> 		; beq 1f / yes, transfer
  5404                              <1> 		; / i-numbers do not match
  5405 0000CF25 83C30A              <1> 	add	ebx, 10 ; fsp table size is 10 bytes
  5406                              <1> 			; in Retro UNIX 386 v1 (22/06/2015)
  5407                              <1> 		; add $8,r2 / no, bump to next entry in fsp table
  5408 0000CF28 81FB[70300100]      <1> 	cmp	ebx, fsp + (nfiles*10) ; 22/06/2015 
  5409                              <1> 		; cmp r2,$fsp+[nfiles*8] 
  5410                              <1> 				; / are we at last entry in the table
  5411 0000CF2E 72E8                <1> 	jb	short anyi_1
  5412                              <1> 		; blt 1b / no, check next entries i-number
  5413                              <1> 	;cmp	ax, 32768
  5414 0000CF30 80FC80              <1> 	cmp	ah, 80h ; negative number check
  5415                              <1> 		; tst r1 / yes, no match
  5416                              <1> 		; bge .+4
  5417 0000CF33 7203                <1> 	jb	short anyi_2
  5418 0000CF35 66F7D8              <1> 	neg	ax
  5419                              <1> 		; neg r1 / make i-number positive
  5420                              <1> anyi_2:	
  5421 0000CF38 E8CC0A0000          <1> 	call	imap
  5422                              <1> 		; jsr r0,imap / get address of allocation bit 
  5423                              <1> 			    ; / in the i-map in r2
  5424                              <1> 	;; DL/DX (MQ) has a 1 in the calculated bit position
  5425                              <1>         ;; eBX (R2) has address of the byte with allocation bit
  5426                              <1>  	; not	dx
  5427 0000CF3D F6D2                <1> 	not 	dl ;; 0 at calculated bit position, other bits are 1
  5428                              <1>         ;and	[ebx], dx
  5429 0000CF3F 2013                <1> 	and 	[ebx], dl 
  5430                              <1> 		; bicb mq,(r2) / clear bit for i-node in the imap
  5431 0000CF41 E8BA0A0000          <1> 	call	itrunc
  5432                              <1> 		; jsr r0,itrunc / free all blocks related to i-node
  5433 0000CF46 66C705[6C2D0100]00- <1>  	mov 	word [i.flgs], 0
  5433 0000CF4E 00                  <1>
  5434                              <1> 		; clr i.flgs / clear all flags in the i-node
  5435 0000CF4F C3                  <1> 	retn
  5436                              <1> 		;rts	r0 / return
  5437                              <1> anyi_3: ; 1: / i-numbers match
  5438 0000CF50 FE4309              <1> 	inc 	byte [ebx+9] ; 22/06/2015
  5439                              <1> 		;incb 7(r2) / increment upper byte of the 4th word
  5440                              <1> 		   ; / in that fsp entry (deleted flag of fsp entry)
  5441 0000CF53 C3                  <1> 	retn
  5442                              <1> 		; rts r0
  5443                              <1> 
  5444                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u7.s
  5445                              <1> ; Last Modification: 14/11/2015
  5446                              <1> 
  5447                              <1> sysmount: ; / mount file system; args special; name
  5448                              <1> 	; 14/11/2015
  5449                              <1> 	; 24/10/2015
  5450                              <1> 	; 13/10/2015
  5451                              <1> 	; 10/07/2015
  5452                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
  5453                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
  5454                              <1> 	;
  5455                              <1> 	; 'sysmount' anounces to the system that a removable 
  5456                              <1> 	; file system has been mounted on a special file.
  5457                              <1> 	; The device number of the special file is obtained via
  5458                              <1> 	; a call to 'getspl'. It is put in the I/O queue entry for
  5459                              <1> 	; dismountable file system (sb1) and the I/O queue entry is
  5460                              <1> 	; set up to read (bit 10 is set). 'ppoke' is then called to
  5461                              <1> 	; to read file system into core, i.e. the first block on the
  5462                              <1> 	; mountable file system is read in. This block is super block
  5463                              <1> 	; for the file system. This call is super user restricted.	
  5464                              <1> 	;
  5465                              <1> 	; Calling sequence:
  5466                              <1> 	;	sysmount; special; name
  5467                              <1> 	; Arguments:
  5468                              <1> 	;	special - pointer to name of special file (device)
  5469                              <1> 	;	name -  pointer to name of the root directory of the
  5470                              <1> 	;		newly mounted file system. 'name' should 
  5471                              <1> 	;		always be a directory.
  5472                              <1> 	; Inputs: - 
  5473                              <1> 	; Outputs: -
  5474                              <1> 	; ...............................................................
  5475                              <1> 	;				
  5476                              <1> 	; Retro UNIX 8086 v1 modification: 
  5477                              <1> 	;       'sysmount' system call has two arguments; so,
  5478                              <1> 	;	* 1st argument, special is pointed to by BX register
  5479                              <1> 	;	* 2nd argument, name is in CX register
  5480                              <1> 	;
  5481                              <1> 	;	NOTE: Device numbers, names and related procedures are 
  5482                              <1> 	;	       already modified for IBM PC compatibility and 
  5483                              <1> 	;	       Retro UNIX 8086 v1 device configuration.	
  5484                              <1> 	
  5485                              <1> 	;call	arg2
  5486                              <1> 		; jsr r0,arg2 / get arguments special and name
  5487 0000CF54 891D[C0300100]      <1> 	mov	[u.namep], ebx
  5488 0000CF5A 51                  <1> 	push	ecx ; directory name
  5489 0000CF5B 66833D[90300100]00  <1> 	cmp	word [mnti], 0
  5490                              <1> 		; tst mnti / is the i-number of the cross device file
  5491                              <1> 			 ; / zero?
  5492                              <1> 	;ja	error
  5493                              <1>         	; bne errora / no, error
  5494 0000CF63 0F87E9000000        <1> 	ja	sysmnt_err0
  5495                              <1> 	;
  5496 0000CF69 E8CC000000          <1> 	call	getspl
  5497                              <1> 		; jsr r0,getspl / get special files device number in r1
  5498                              <1> 	; 13/10/2015
  5499 0000CF6E 0FB7D8              <1> 	movzx	ebx, ax ; ; Retro UNIX 8086 v1 device number (0 to 5)
  5500 0000CF71 F683[64ED0000]80    <1>         test    byte [ebx+drv.status], 80h ; 24/10/2015 
  5501 0000CF78 750F                <1> 	jnz	short sysmnt_1
  5502                              <1> sysmnt_err1:
  5503 0000CF7A C705[FD300100]0F00- <1>         mov     dword [u.error], ERR_DRV_NOT_RDY ; drive not ready !
  5503 0000CF82 0000                <1>
  5504 0000CF84 E99BE6FFFF          <1> 	jmp	error
  5505                              <1> sysmnt_1:
  5506 0000CF89 8F05[C0300100]      <1> 	pop	dword [u.namep]
  5507                              <1>         	; mov (sp)+,u.namep / put the name of file to be placed
  5508                              <1> 				  ; / on the device
  5509                              <1> 	; 14/11/2015
  5510 0000CF8F 53                  <1> 	push	ebx ; 13/10/2015
  5511                              <1> 		; mov r1,-(sp) / save the device number
  5512                              <1>         ;
  5513 0000CF90 E859FBFFFF          <1> 	call	namei
  5514                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
  5515                              <1> 		       ; ax = 0 -> file not found 	
  5516                              <1> 	;jz	error
  5517                              <1> 	;jc	error
  5518                              <1> 		; jsr r0,namei / get the i-number of the file
  5519                              <1>                	; br errora
  5520 0000CF95 730F                <1> 	jnc	short sysmnt_2
  5521                              <1> sysmnt_err2:
  5522 0000CF97 C705[FD300100]0C00- <1>         mov     dword [u.error], ERR_FILE_NOT_FOUND ; drive not ready !
  5522 0000CF9F 0000                <1>
  5523 0000CFA1 E97EE6FFFF          <1> 	jmp	error
  5524                              <1> sysmnt_2:	
  5525 0000CFA6 66A3[90300100]      <1> 	mov	[mnti], ax
  5526                              <1>         	; mov r1,mnti / put it in mnti
  5527                              <1> ;	mov	ebx, sb1 ; super block buffer (of mounted disk)
  5528                              <1> sysmnt_3: ;1:
  5529                              <1>         ;cmp	byte [ebx+1], 0
  5530                              <1> 		; tstb sb1+1 / is 15th bit of I/O queue entry for
  5531                              <1> 			   ; / dismountable device set?
  5532                              <1>         ;jna	short sysmnt_4		
  5533                              <1> 		; bne 1b / (inhibit bit) yes, skip writing
  5534                              <1> 	;call	idle 	; (wait for hardware interrupt)
  5535                              <1> 	;jmp	short sysmnt_3
  5536                              <1> sysmnt_4:   
  5537 0000CFAC 58                  <1> 	pop	eax ; Retro UNIX 8086 v1 device number/ID (0 to 5)     
  5538 0000CFAD A2[8D300100]        <1> 	mov	[mdev], al
  5539                              <1> 		; mov  (sp),mntd / no, put the device number in mntd
  5540 0000CFB2 8803                <1> 	mov	[ebx], al
  5541                              <1>         	; movb (sp),sb1 / put the device number in the lower byte
  5542                              <1> 			      ; / of the I/O queue entry
  5543                              <1> 	;mov	byte [cdev], 1 ; mounted device/drive
  5544                              <1>         	; mov (sp)+,cdev / put device number in cdev
  5545 0000CFB4 66810B0004          <1>         or	word [ebx], 400h ; Bit 10, 'read' flag/bit
  5546                              <1> 		; bis $2000,sb1 / set the read bit
  5547                              <1> 	; Retro UNIX 386 v1 modification : 
  5548                              <1> 	;	32 bit block number at buffer header offset 4
  5549 0000CFB9 C7430401000000      <1> 	mov	dword [ebx+4], 1 ; physical block number = 1
  5550 0000CFC0 E8450A0000          <1> 	call 	diskio
  5551 0000CFC5 731C                <1> 	jnc	short sysmnt_5
  5552 0000CFC7 31C0                <1> 	xor 	eax, eax
  5553 0000CFC9 66A3[90300100]      <1> 	mov	[mnti], ax ; 0
  5554 0000CFCF A2[8D300100]        <1> 	mov	[mdev], al ; 0
  5555                              <1> 	;mov	[cdev], al ; 0
  5556                              <1> sysmnt_invd:
  5557                              <1> 	; 14/11/2015
  5558 0000CFD4 FEC8                <1> 	dec 	al
  5559 0000CFD6 8903                <1> 	mov	[ebx], eax ; 000000FFh
  5560 0000CFD8 FEC0                <1> 	inc	al
  5561 0000CFDA 48                  <1> 	dec	eax
  5562 0000CFDB 894304              <1> 	mov	[ebx+4], eax ; 0FFFFFFFFh
  5563 0000CFDE E941E6FFFF          <1> 	jmp	error
  5564                              <1> sysmnt_5:
  5565                              <1> 	; 14/11/2015 (Retro UNIX 386 v1 modification)
  5566                              <1> 	; (Following check is needed to prevent mounting an
  5567                              <1> 	; in valid valid file system (in valid super block).
  5568                              <1> 	; 
  5569 0000CFE3 0FB603              <1> 	movzx	eax, byte [ebx] ; device number
  5570 0000CFE6 C0E002              <1> 	shl	al, 2 ; 4*index
  5571 0000CFE9 8B88[48ED0000]      <1> 	mov	ecx, [eax+drv.size] ; volume (fs) size
  5572 0000CFEF C1E103              <1> 	shl 	ecx, 3
  5573 0000CFF2 0FB715[613B0100]    <1> 	movzx	edx, word [sb1+4] ; the 1st data word
  5574 0000CFF9 39D1                <1> 	cmp	ecx, edx ; compare free map bits and volume size
  5575                              <1> 			 ; (in sectors), if they are not equal
  5576                              <1> 			 ; the disk to be mounted is an...	
  5577 0000CFFB 75D7                <1> 	jne	short sysmnt_invd ; invalid disk !
  5578                              <1> 			 ; (which has not got a valid super block)
  5579                              <1> 	;
  5580 0000CFFD C6430100            <1> 	mov	byte [ebx+1], 0
  5581                              <1> 	       	; jsr r0,ppoke / read in entire file system
  5582                              <1> ;sysmnt_6: ;1:
  5583                              <1> 	;;cmp	byte [sb1+1], 0
  5584                              <1> 		; tstb   sb1+1 / done reading?
  5585                              <1>    	;;jna	sysret
  5586                              <1> 	;;call	idle ; (wait for hardware interrupt)
  5587                              <1> 	;;jmp	short sysmnt_6
  5588                              <1> 		;bne 1b / no, wait
  5589                              <1>         	;br sysreta / yes
  5590 0000D001 E93EE6FFFF          <1> 	jmp	sysret
  5591                              <1> 
  5592                              <1> sysumount: ; / special dismount file system
  5593                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
  5594                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
  5595                              <1> 	;
  5596                              <1> 	; 04/11/2013
  5597                              <1> 	; 09/07/2013
  5598                              <1> 	; 'sysumount' anounces to the system that the special file, 
  5599                              <1> 	; indicated as an argument is no longer contain a removable
  5600                              <1> 	; file system. 'getspl' gets the device number of the special
  5601                              <1> 	; file. If no file system was mounted on that device an error
  5602                              <1> 	; occurs. 'mntd' and 'mnti' are cleared and control is passed
  5603                              <1> 	; to 'sysret'.
  5604                              <1> 	;
  5605                              <1> 	; Calling sequence:
  5606                              <1> 	;	sysmount; special
  5607                              <1> 	; Arguments:
  5608                              <1> 	;	special - special file to dismount (device)
  5609                              <1> 	;
  5610                              <1> 	; Inputs: - 
  5611                              <1> 	; Outputs: -
  5612                              <1> 	; ...............................................................
  5613                              <1> 	;				
  5614                              <1> 	; Retro UNIX 8086 v1 modification: 
  5615                              <1> 	;       'sysumount' system call has one argument; so,
  5616                              <1> 	;	* Single argument, special is pointed to by BX register
  5617                              <1> 	;
  5618                              <1> 	
  5619                              <1> 	;mov 	ax, 1 ; one/single argument, put argument in BX	
  5620                              <1> 	;call	arg
  5621                              <1> 		; jsr r0,arg; u.namep / point u.namep to special
  5622 0000D006 891D[C0300100]      <1>         mov	[u.namep], ebx
  5623 0000D00C E829000000          <1> 	call	getspl
  5624                              <1> 		; jsr r0,getspl / get the device number in r1
  5625 0000D011 3A05[8D300100]      <1> 	cmp	al, [mdev]
  5626                              <1> 		; cmp r1,mntd / is it equal to the last device mounted?
  5627 0000D017 7539                <1> 	jne	short sysmnt_err0 ; 'permission denied !' error
  5628                              <1> 	;jne	error
  5629                              <1>         	; bne errora / no error
  5630 0000D019 30C0                <1> 	xor	al, al ; ah = 0
  5631                              <1> sysumnt_0: ;1:
  5632 0000D01B 3805[5E3B0100]      <1>      	cmp 	[sb1+1], al ; 0
  5633                              <1> 		; tstb sb1+1 / yes, is the device still doing I/O 
  5634                              <1> 			   ; / (inhibit bit set)?
  5635 0000D021 7607                <1> 	jna	short sysumnt_1		
  5636                              <1> 		; bne 1b / yes, wait
  5637 0000D023 E8E3090000          <1> 	call	idle ; (wait for hardware interrupt)
  5638 0000D028 EBF1                <1> 	jmp	short sysumnt_0
  5639                              <1> sysumnt_1:        
  5640 0000D02A A2[8D300100]        <1> 	mov	[mdev], al
  5641                              <1> 	     	; clr mntd / no, clear these
  5642 0000D02F 66A3[90300100]      <1>    	mov	[mnti], ax
  5643                              <1>         	; clr mnti
  5644 0000D035 E90AE6FFFF          <1>         jmp	sysret
  5645                              <1> 		; br sysreta / return
  5646                              <1> 
  5647                              <1> getspl: ; / get device number from a special file name
  5648 0000D03A E8AFFAFFFF          <1> 	call	namei
  5649                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
  5650                              <1> 		       ; ax = 0 -> file not found 	
  5651 0000D03F 0F8252FFFFFF        <1>         jc      sysmnt_err2 ; 'file not found !' error
  5652                              <1> 	;jz	error
  5653                              <1> 	;jc	error
  5654                              <1> 		; jsr r0,namei / get the i-number of the special file
  5655                              <1>                 ; br errora / no such file
  5656 0000D045 6683E803            <1>         sub	ax, 3 ; Retro UNIX 8086 v1 modification !
  5657                              <1> 		      ;	i-number-3, 0 = fd0, 5 = hd3 
  5658                              <1> 		; sub $4,r1 / i-number-4 rk=1,tap=2+n
  5659 0000D049 7207                <1>         jc	short sysmnt_err0 ; 'permission denied !' error
  5660                              <1> 	;jc	error
  5661                              <1> 		; ble errora / less than 0?  yes, error
  5662 0000D04B 6683F805            <1>         cmp	ax, 5 ;
  5663                              <1> 		; cmp  r1,$9. / greater than 9  tap 7
  5664 0000D04F 7701                <1> 	ja	short sysmnt_err0 ; 'permission denied !' error
  5665                              <1> 	;ja	error
  5666                              <1>         	; bgt errora / yes, error
  5667                              <1>         ; AX = Retro UNIX 8086 v1 Device Number (0 to 5)
  5668                              <1> iopen_retn:
  5669 0000D051 C3                  <1> 	retn
  5670                              <1> 		; rts    r0 / return with device number in r1
  5671                              <1> sysmnt_err0:
  5672 0000D052 C705[FD300100]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
  5672 0000D05A 0000                <1>
  5673 0000D05C E9C3E5FFFF          <1> 	jmp	error
  5674                              <1> 
  5675                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
  5676                              <1> ; Last Modification: 09/12/2015
  5677                              <1> 
  5678                              <1> syssleep:
  5679                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
  5680                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
  5681                              <1> 	;
  5682                              <1> 	; Retro UNIX 8086 v1 feature only
  5683                              <1> 	; (INPUT -> none)
  5684                              <1> 	;
  5685 0000D061 0FB61D[F7300100]    <1> 	movzx	ebx, byte [u.uno] ; process number
  5686 0000D068 8AA3[EB2D0100]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
  5687 0000D06E E899090000          <1> 	call	sleep
  5688 0000D073 E9CCE5FFFF          <1> 	jmp	sysret
  5689                              <1> 
  5690                              <1> _vp_clr:
  5691                              <1> 	; Reset/Clear Video Page
  5692                              <1> 	;
  5693                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
  5694                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
  5695                              <1> 	;
  5696                              <1> 	; Retro UNIX 8086 v1 feature only !
  5697                              <1> 	;
  5698                              <1> 	; INPUTS -> 
  5699                              <1> 	;   BH = video page number	 
  5700                              <1> 	;
  5701                              <1> 	; OUTPUT ->
  5702                              <1> 	;   none
  5703                              <1> 	; ((Modified registers: eAX, BH, eCX, eDX, eSI, eDI))
  5704                              <1> 	;
  5705                              <1> 	; 04/12/2013
  5706 0000D078 28C0                <1> 	sub	al, al
  5707                              <1> 	; al = 0 (clear video page)
  5708                              <1> 	; bh = video page ; 13/05/2016
  5709 0000D07A B407                <1> 	mov	ah, 07h
  5710                              <1> 	; ah = 7 (attribute/color)
  5711 0000D07C 6631C9              <1> 	xor 	cx, cx ; 0, left upper column (cl) & row (cl)
  5712 0000D07F 66BA4F18            <1> 	mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
  5713 0000D083 E8F147FFFF          <1> 	call	_scroll_up
  5714                              <1> 	; bh = video page
  5715 0000D088 6631D2              <1> 	xor	dx, dx ; 0 (cursor position) 
  5716 0000D08B E9274BFFFF          <1> 	jmp 	_set_cpos
  5717                              <1> 
  5718                              <1> sysmsg:
  5719                              <1> 	; 13/05/2016
  5720                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  5721                              <1> 	; 01/07/2015 - 11/11/2015 (Retro UNIX 386 v1)
  5722                              <1> 	; Print user-application message on user's console tty
  5723                              <1> 	;
  5724                              <1> 	; Input -> EBX = Message address
  5725                              <1> 	;	   ECX = Message length (max. 255)
  5726                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
  5727                              <1> 	;
  5728 0000D090 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
  5729 0000D096 0F87A8E5FFFF        <1> 	ja	sysret ; nothing to do with big message size
  5730 0000D09C 08C9                <1> 	or	cl, cl
  5731 0000D09E 0F84A0E5FFFF        <1> 	jz	sysret
  5732 0000D0A4 20D2                <1> 	and	dl, dl
  5733 0000D0A6 7502                <1> 	jnz	short sysmsg0
  5734 0000D0A8 B207                <1> 	mov	dl, 07h ; default color
  5735                              <1> 		; (black background, light gray character) 
  5736                              <1> sysmsg0:
  5737 0000D0AA 891D[C8300100]      <1> 	mov	[u.base], ebx
  5738 0000D0B0 8815[F71F0100]      <1> 	mov	[ccolor], dl ; color attributes
  5739 0000D0B6 89E5                <1> 	mov	ebp, esp
  5740 0000D0B8 31DB                <1> 	xor	ebx, ebx ; 0
  5741 0000D0BA 891D[D0300100]      <1> 	mov	[u.nread], ebx ; 0
  5742                              <1> 	;
  5743 0000D0C0 381D[0F310100]      <1> 	cmp	[u.kcall], bl ; 0
  5744 0000D0C6 7769                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
  5745                              <1> 	;
  5746 0000D0C8 890D[CC300100]      <1> 	mov	[u.count], ecx
  5747 0000D0CE 41                  <1> 	inc	ecx ; + 00h ; ASCIIZ
  5748 0000D0CF 29CC                <1> 	sub	esp, ecx
  5749 0000D0D1 89E7                <1> 	mov	edi, esp
  5750 0000D0D3 89E6                <1> 	mov	esi, esp
  5751 0000D0D5 66891D[0D310100]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
  5752                              <1> 	; 11/11/2015
  5753 0000D0DC 8A25[D8300100]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
  5754                              <1> 	; 0 = none
  5755 0000D0E2 FECC                <1> 	dec	ah
  5756 0000D0E4 790C                <1> 	jns	short sysmsg1 
  5757 0000D0E6 8A1D[F7300100]      <1> 	mov	bl, [u.uno] ; process number	
  5758 0000D0EC 8AA3[EB2D0100]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
  5759                              <1> sysmsg1:
  5760 0000D0F2 8825[FC300100]      <1> 	mov	[u.ttyn], ah
  5761                              <1> sysmsg2:
  5762 0000D0F8 E817080000          <1> 	call	cpass
  5763 0000D0FD 7416                <1> 	jz	short sysmsg5
  5764 0000D0FF AA                  <1> 	stosb
  5765 0000D100 20C0                <1> 	and	al, al
  5766 0000D102 75F4                <1> 	jnz	short sysmsg2
  5767                              <1> sysmsg3:
  5768 0000D104 80FC07              <1> 	cmp	ah, 7 ; tty number
  5769 0000D107 7711                <1> 	ja	short sysmsg6 ; serial port
  5770 0000D109 E83E000000          <1> 	call	print_cmsg
  5771                              <1> sysmsg4:
  5772 0000D10E 89EC                <1> 	mov	esp, ebp	
  5773 0000D110 E92FE5FFFF          <1> 	jmp	sysret
  5774                              <1> sysmsg5:
  5775 0000D115 C60700              <1> 	mov	byte [edi], 0
  5776 0000D118 EBEA                <1> 	jmp	short sysmsg3
  5777                              <1> sysmsg6:
  5778 0000D11A 8A06                <1> 	mov	al, [esi]
  5779 0000D11C E8E3080000          <1> 	call	sndc
  5780 0000D121 72EB                <1> 	jc	short sysmsg4
  5781 0000D123 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
  5782 0000D126 76E6                <1> 	jna	short sysmsg4
  5783 0000D128 46                  <1> 	inc 	esi
  5784 0000D129 8A25[FC300100]      <1> 	mov	ah, [u.ttyn]
  5785 0000D12F EBE9                <1> 	jmp	short sysmsg6
  5786                              <1> 
  5787                              <1> sysmsgk: ; Temporary (01/07/2015)
  5788                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
  5789                              <1> 	; (ECX -character count- will not be considered)
  5790 0000D131 8B35[C8300100]      <1> 	mov	esi, [u.base]
  5791 0000D137 8A25[F61F0100]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
  5792 0000D13D 8825[FC300100]      <1> 	mov	[u.ttyn], ah
  5793 0000D143 C605[0F310100]00    <1> 	mov	byte [u.kcall], 0
  5794 0000D14A EBB8                <1> 	jmp	short sysmsg3
  5795                              <1> 	
  5796                              <1> print_cmsg: 
  5797                              <1> 	; 13/05/2016 - TRDOS 386 (TRDOS v2.0)
  5798                              <1> 	; 01/07/2015 (Retro UNIX 386 v1)
  5799                              <1> 	;
  5800                              <1> 	; print message (on user's console tty) 
  5801                              <1> 	;	with requested color
  5802                              <1> 	;
  5803                              <1> 	; INPUTS:
  5804                              <1> 	;	esi = message address
  5805                              <1> 	;	[u.ttyn] = tty number (0 to 7)
  5806                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
  5807                              <1> 	
  5808 0000D14C 8A3D[FC300100]      <1> 	mov	bh, [u.ttyn]
  5809                              <1> 	;mov	bh, ah
  5810                              <1> 
  5811 0000D152 AC                  <1> 	lodsb
  5812                              <1> pcmsg1:
  5813 0000D153 56                  <1> 	push 	esi
  5814 0000D154 8A1D[F71F0100]      <1> 	mov	bl, [ccolor]
  5815                              <1> 	;mov	bh, [u.ttyn]
  5816 0000D15A E8C249FFFF          <1> 	call 	_write_tty
  5817 0000D15F 5E                  <1> 	pop	esi
  5818 0000D160 AC                  <1> 	lodsb
  5819 0000D161 20C0                <1> 	and 	al, al  ; 0
  5820 0000D163 75EE                <1> 	jnz 	short pcmsg1
  5821 0000D165 C3                  <1> 	retn
  5822                              <1> 
  5823                              <1> sysgeterr:
  5824                              <1> 	; 09/12/2015
  5825                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
  5826                              <1> 	; Get last error number or page fault count
  5827                              <1> 	; (for debugging)
  5828                              <1> 	;
  5829                              <1> 	; Input -> EBX = return type
  5830                              <1> 	;	   0 = last error code (which is in 'u.error')	
  5831                              <1> 	;	   FFFFFFFFh = page fault count for running process
  5832                              <1> 	;	   FFFFFFFEh = total page fault count
  5833                              <1> 	;	   1 .. FFFFFFFDh = undefined 
  5834                              <1> 	;
  5835                              <1> 	; Output -> EAX = last error number or page fault count
  5836                              <1> 	;	   (depending on EBX input)
  5837                              <1> 	; 	
  5838 0000D166 21DB                <1> 	and 	ebx, ebx
  5839 0000D168 750B                <1> 	jnz	short glerr_2
  5840                              <1> glerr_0:
  5841 0000D16A A1[FD300100]        <1> 	mov	eax, [u.error]
  5842                              <1> glerr_1:
  5843 0000D16F A3[A8300100]        <1> 	mov	[u.r0], eax
  5844 0000D174 C3                  <1>  	retn
  5845                              <1> glerr_2:
  5846 0000D175 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
  5847 0000D176 74FD                <1> 	jz	short glerr_2 ; page fault count for process
  5848 0000D178 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
  5849 0000D179 75EF                <1> 	jnz	short glerr_0
  5850 0000D17B A1[8C3E0100]        <1> 	mov	eax, [PF_Count] ; total page fault count
  5851 0000D180 EBED                <1>         jmp     short glerr_1
  5852                              <1> glerr_3:
  5853 0000D182 A1[11310100]        <1> 	mov 	eax, [u.pfcount]
  5854 0000D187 EBE6                <1> 	jmp	short glerr_1
  5855                              <1> 
  5856                              <1> load_and_run_file:
  5857                              <1> 	; 06/06/2016
  5858                              <1> 	; 06/05/2016
  5859                              <1> 	; 03/05/2016
  5860                              <1> 	; 02/05/2016
  5861                              <1> 	; 24/04/2016
  5862                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
  5863                              <1> 	; 23/10/2015 (Retro UNIX 386 v1, 'sysexec')
  5864                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  5865                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
  5866                              <1> 	; EAX = First Cluster number
  5867                              <1> 	; EDX = File Size
  5868                              <1> 	; ESI = Argument list address
  5869                              <1> 	; [argc] = argument count
  5870                              <1> 	; [u.nread] = argument list length
  5871                              <1> 	; [esp] = return address to the caller (*)
  5872                              <1> 	;
  5873 0000D189 8935[28310100]      <1> 	mov	[argv], esi
  5874 0000D18F 8915[31310100]      <1> 	mov	[i.size], edx
  5875 0000D195 A3[2D310100]        <1> 	mov	[ii], eax
  5876                              <1> 
  5877                              <1> 	; 06/05/2016
  5878                              <1> 	; Set 'sysexit' return order to MainProg
  5879                              <1> 	;
  5880 0000D19A 58                  <1> 	pop	eax ; * 'loc_load_and_run_file_8:' address
  5881 0000D19B 8B25[641F0100]      <1> 	mov	esp, [tss.esp0]
  5882                              <1> 	;
  5883                              <1> 	; 'loc_load_run_file_8' address has 
  5884                              <1> 	; 'jmp loc_file_rw_restore_retn' instruction
  5885                              <1> 	; 'loc_file_rw_restore_retn:' will return to
  5886                              <1> 	; [mainprog_return_addr] 
  5887                              <1> 	; just after 'call command_interpreter'
  5888                              <1> 	;
  5889 0000D1A1 68[34550000]        <1> 	push	_end_of_mainprog ; we must not return to here !
  5890 0000D1A6 FF35[3C2D0100]      <1> 	push	dword [mainprog_return_addr]
  5891 0000D1AC 89E5                <1> 	mov	ebp, esp ; **
  5892                              <1> 	;	
  5893 0000D1AE 9C                  <1> 	pushfd  ; EFLAGS      ; IRETD
  5894 0000D1AF 6A08                <1> 	push	KCODE ; cs    ; IRETD
  5895 0000D1B1 50                  <1> 	push	eax ; * (eip) ; IRETD
  5896 0000D1B2 8925[A0300100]      <1> 	mov	[u.sp], esp
  5897 0000D1B8 1E                  <1> 	push	ds
  5898 0000D1B9 06                  <1> 	push	es
  5899 0000D1BA 0FA0                <1> 	push	fs
  5900 0000D1BC 0FA8                <1> 	push	gs	
  5901 0000D1BE 60                  <1> 	pushad
  5902 0000D1BF 68[44B60000]        <1> 	push	sysret
  5903 0000D1C4 8925[A4300100]      <1> 	mov	[u.usp], esp
  5904                              <1> 	;
  5905 0000D1CA E858060000          <1> 	call	wswap ; Save MainProg (process 1) 'u' structure
  5906                              <1> 		      ; and registers for return (from program)	
  5907 0000D1CF 89EC                <1> 	mov	esp, ebp ; **
  5908 0000D1D1 50                  <1> 	push	eax  ; * 'loc_load_and_run_file_8:' address
  5909                              <1> 	;
  5910                              <1> 	;;; 02/05/2016
  5911                              <1> 	;;; Create a new process (parent: MainProg)	
  5912 0000D1D2 31F6                <1> 	xor 	esi, esi
  5913                              <1> cnpm_1: ; search p.stat table for unused process number
  5914 0000D1D4 46                  <1> 	inc	esi
  5915 0000D1D5 80BE[1B2E0100]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE
  5916                              <1> 				; is process active, unused, dead
  5917 0000D1DC 760B                <1> 	jna	short cnpm_2	; it's unused so branch
  5918 0000D1DE 6683FE10            <1> 	cmp	si, nproc 	; all processes checked
  5919 0000D1E2 72F0                <1> 	jb	short cnpm_1    ; no, branch back
  5920 0000D1E4 E9C183FFFF          <1> 	jmp	panic 
  5921                              <1> cnpm_2:
  5922 0000D1E9 A1[01310100]        <1> 	mov	eax, [u.pgdir] ; page directory of MainProg
  5923 0000D1EE A3[05310100]        <1> 	mov	[u.ppgdir], eax ; parent's page directory
  5924 0000D1F3 E8EE73FFFF          <1> 	call	allocate_page
  5925 0000D1F8 0F82AC83FFFF        <1> 	jc	panic
  5926                              <1> 	; EAX = UPAGE (user structure page) address
  5927 0000D1FE A3[F8300100]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
  5928 0000D203 89F7                <1> 	mov	edi, esi
  5929 0000D205 66C1E702            <1> 	shl	di, 2
  5930 0000D209 8987[282E0100]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
  5931 0000D20F E84C74FFFF          <1> 	call	clear_page ; 03/05/2016
  5932                              <1> 	;movzx	eax, byte [p.ttyc] ; console tty (for MainProg)
  5933 0000D214 6629C0              <1> 	sub	ax, ax ; 0
  5934 0000D217 668986[EB2D0100]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
  5935                              <1> 				   ; ah - reset child's wait channel	
  5936 0000D21E 89F0                <1> 	mov	eax, esi
  5937 0000D220 A2[F7300100]        <1> 	mov	[u.uno], al ; child process number
  5938 0000D225 FE86[1B2E0100]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN
  5939 0000D22B 66D1E6              <1> 	shl	si, 1 ; multiply si by 2 to get index into p.pid table
  5940 0000D22E 66FF05[92300100]    <1> 	inc	word [mpid] ; increment m.pid; get a new process name
  5941 0000D235 66A1[92300100]      <1> 	mov	ax, [mpid]
  5942 0000D23B 668986[8A2D0100]    <1> 	mov	[esi+p.pid-2], ax ; put new process name 
  5943                              <1> 				  ; in child process' name slot
  5944                              <1> 	;mov	ax, [p.pid]  ; get process name of MainProg
  5945 0000D242 66B80100            <1> 	mov	ax, 1
  5946 0000D246 668986[AA2D0100]    <1> 	mov	[esi+p.ppid-2], ax ; put parent process name 
  5947                              <1> 			           ; in parent process slot for child
  5948 0000D24D 6648                <1> 	dec	ax ; 0
  5949 0000D24F 66A3[D8300100]      <1> 	mov 	[u.ttyp], ax ; 0
  5950                              <1> 	;;;
  5951 0000D255 A1[2D310100]        <1> 	mov 	eax,  [ii]
  5952                              <1> 	; Retro UNIX 386 v1, 'sysexec' (u2.s)
  5953 0000D25A E89F070000          <1> 	call	iopen
  5954                              <1> 	; 06/06/2016
  5955 0000D25F C605[EB300100]01    <1> 	mov	byte [u.pri], 1 ; normal priority
  5956                              <1> 	;
  5957 0000D266 EB0A                <1> 	jmp	short sysexec_7 ; 02/05/2016
  5958                              <1> 
  5959                              <1> sysexec_6:
  5960                              <1> 	;;02/05/2016
  5961                              <1> 	; 23/04/2016
  5962                              <1> 	; 18/10/2015 ('sysexec_6')
  5963                              <1> 	; 23/06/2015
  5964                              <1> 	;;mov	eax, [u.pgdir] ; parent's page directory
  5965                              <1> 	;;cmp 	eax, [k_page_dir] ; TRDOS MainProg ? 
  5966                              <1> 	;;je	short sysexec_7
  5967 0000D268 A1[01310100]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
  5968 0000D26D E8AD74FFFF          <1> 	call	deallocate_page_dir
  5969                              <1> sysexec_7:
  5970 0000D272 E8DD73FFFF          <1> 	call	make_page_dir
  5971 0000D277 0F822D83FFFF        <1> 	jc	panic  ; allocation error 
  5972                              <1> 		       ; after a deallocation would be nonsence !?
  5973                              <1> 	; 24/07/2015
  5974                              <1> 	; map kernel pages (1st 4MB) to PDE 0
  5975                              <1> 	;     of the user's page directory
  5976                              <1> 	;     (It is needed for interrupts!)
  5977                              <1> 	; 18/10/2015
  5978 0000D27D 8B15[C81F0100]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
  5979 0000D283 8B02                <1> 	mov	eax, [edx] ; physical address of
  5980                              <1> 			   ; kernel's first page table (1st 4 MB)
  5981                              <1> 			   ; (PDE 0 of kernel's page directory)
  5982 0000D285 8B15[01310100]      <1> 	mov 	edx, [u.pgdir]
  5983 0000D28B 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
  5984                              <1> 	;
  5985                              <1> 	; 20/07/2015
  5986 0000D28D BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
  5987                              <1> 	; 18/10/2015
  5988 0000D292 BE[18310100]        <1> 	mov	esi, pcore ; physical start address
  5989                              <1> sysexec_8:	
  5990 0000D297 B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
  5991 0000D29C E8D173FFFF          <1> 	call	make_page_table
  5992 0000D2A1 0F820383FFFF        <1> 	jc	panic
  5993                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
  5994 0000D2A7 E8D473FFFF          <1> 	call	make_page ; make new page, clear and set the pte 
  5995 0000D2AC 0F82F882FFFF        <1> 	jc	panic
  5996                              <1> 	;
  5997 0000D2B2 8906                <1> 	mov	[esi], eax ; 24/06/2015
  5998                              <1> 	; ebx = virtual address (24/07/2015)
  5999 0000D2B4 E86F79FFFF          <1> 	call 	add_to_swap_queue
  6000                              <1> 	; 18/10/2015
  6001 0000D2B9 81FE[1C310100]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
  6002 0000D2BF 740C                <1> 	je	short sysexec_9 ; yes
  6003 0000D2C1 BE[1C310100]        <1> 	mov	esi, ecore  ; physical address of the last page 
  6004                              <1> 	; 20/07/2015
  6005 0000D2C6 BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
  6006                              <1> 	; ebx = virtual end address + segment base address - 4K
  6007 0000D2CB EBCA                <1>         jmp     short sysexec_8
  6008                              <1> sysexec_9:
  6009                              <1> 	; 24/04/2016
  6010                              <1> 	; 18/10/2015
  6011                              <1> 	; 26/08/2015
  6012                              <1> 	; 25/06/2015
  6013                              <1> 	; move arguments from kernel stack to [ecore]
  6014                              <1> 	; (argument list/line will be copied from kernel stack
  6015                              <1> 	; frame to the last (stack) page of user's core memory)
  6016                              <1> 	; 18/10/2015
  6017 0000D2CD 8B3D[1C310100]      <1> 	mov	edi, [ecore]
  6018 0000D2D3 81C700100000        <1> 	add	edi, PAGE_SIZE
  6019 0000D2D9 0FB705[26310100]    <1> 	movzx	eax, word [argc]
  6020 0000D2E0 09C0                <1> 	or	eax, eax
  6021 0000D2E2 7509                <1> 	jnz	short sysexec_10
  6022 0000D2E4 89FB                <1> 	mov 	ebx, edi
  6023 0000D2E6 83EB04              <1> 	sub	ebx, 4 
  6024 0000D2E9 8903                <1> 	mov	[ebx], eax ; 0
  6025 0000D2EB EB44                <1> 	jmp 	short sysexec_13
  6026                              <1> sysexec_10:
  6027 0000D2ED 8B0D[D0300100]      <1> 	mov	ecx, [u.nread]
  6028                              <1> 	;mov	esi, TextBuffer
  6029 0000D2F3 8B35[28310100]      <1> 	mov	esi, [argv] ; 24/04/2016 (TRDOS 386  = TRDOS v2.0)
  6030 0000D2F9 29CF                <1> 	sub	edi, ecx ; page end address - argument list length
  6031 0000D2FB 89C2                <1> 	mov	edx, eax
  6032 0000D2FD FEC2                <1> 	inc	dl ; argument count + 1 for argc value  
  6033 0000D2FF C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
  6034 0000D302 89FB                <1> 	mov	ebx, edi
  6035 0000D304 80E3FC              <1> 	and	bl, 0FCh ; 32 bit (dword) alignment
  6036 0000D307 29D3                <1> 	sub 	ebx, edx
  6037 0000D309 89FA                <1> 	mov	edx, edi
  6038 0000D30B F3A4                <1> 	rep	movsb
  6039 0000D30D 89D6                <1> 	mov 	esi, edx
  6040 0000D30F 89DF                <1> 	mov 	edi, ebx
  6041 0000D311 BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
  6042 0000D316 2B15[1C310100]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical) 
  6043 0000D31C AB                  <1> 	stosd	; eax = argument count	
  6044                              <1> sysexec_11:
  6045 0000D31D 89F0                <1> 	mov	eax, esi
  6046 0000D31F 01D0                <1> 	add	eax, edx
  6047 0000D321 AB                  <1> 	stosd  ; eax = virtual address
  6048 0000D322 FE0D[26310100]      <1> 	dec	byte [argc]
  6049 0000D328 7407                <1> 	jz	short sysexec_13
  6050                              <1> sysexec_12:
  6051 0000D32A AC                  <1> 	lodsb
  6052 0000D32B 20C0                <1> 	and	al, al
  6053 0000D32D 75FB                <1> 	jnz	short sysexec_12
  6054 0000D32F EBEC                <1> 	jmp	short sysexec_11
  6055                              <1> sysexec_13:
  6056                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
  6057                              <1> 	; 23/06/2015 - 19/10/2015 (Retro UNIX 386 v1, 'sysexec_13')
  6058                              <1> 	;
  6059                              <1> 	; moving arguments to [ecore] is OK here..
  6060                              <1> 	;
  6061                              <1> 	; ebx = beginning addres of argument list pointers
  6062                              <1> 		;	in user's stack
  6063 0000D331 2B1D[1C310100]      <1> 	sub 	ebx, [ecore]
  6064 0000D337 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
  6065                              <1> 			; end of core - 4096 (last page)
  6066                              <1> 			; (virtual address)
  6067 0000D33D 891D[28310100]      <1> 	mov	[argv], ebx
  6068 0000D343 891D[D4300100]      <1> 	mov	[u.break], ebx ; available user memory
  6069                              <1> 	;
  6070 0000D349 29C0                <1> 	sub	eax, eax
  6071 0000D34B C705[CC300100]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
  6071 0000D353 0000                <1>
  6072 0000D355 C705[B8300100]-     <1> 	mov	dword [u.fofp], u.off
  6072 0000D35B [C4300100]          <1>
  6073 0000D35F A3[C4300100]        <1> 	mov	[u.off], eax ; 0
  6074 0000D364 A3[C8300100]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
  6075 0000D369 A1[2D310100]        <1> 	mov	eax, [ii] ; Fist Cluster of the Program (PRG) file
  6076                              <1> 	; EAX = First cluster of the executable file
  6077 0000D36E E831010000          <1> 	call	readi
  6078                              <1> 
  6079 0000D373 8B0D[D4300100]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
  6080 0000D379 890D[CC300100]      <1> 	mov	[u.count], ecx ; save for overrun check
  6081                              <1> 	;
  6082 0000D37F 8B0D[D0300100]      <1> 	mov	ecx, [u.nread]
  6083 0000D385 890D[D4300100]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
  6084 0000D38B 80F920              <1> 	cmp	cl, 32
  6085 0000D38E 7540                <1>         jne     short sysexec_15
  6086                              <1> 	;:
  6087                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
  6088 0000D390 8B35[18310100]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
  6089                              <1> 		             ; (phys. start addr. of the exec. file)
  6090 0000D396 AD                  <1> 	lodsd
  6091 0000D397 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
  6092 0000D39B 7533                <1> 	jne	short sysexec_15
  6093 0000D39D AD                  <1> 	lodsd
  6094 0000D39E 89C1                <1> 	mov	ecx, eax ; text (code) section size
  6095 0000D3A0 AD                  <1> 	lodsd
  6096 0000D3A1 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
  6097 0000D3A3 89CB                <1> 	mov	ebx, ecx
  6098 0000D3A5 AD                  <1> 	lodsd	
  6099 0000D3A6 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
  6100 0000D3A8 3B1D[CC300100]      <1> 	cmp	ebx, [u.count]
  6101 0000D3AE 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
  6102                              <1> 	;
  6103                              <1> 	; add bss section size to [u.break]
  6104 0000D3B0 0105[D4300100]      <1> 	add 	[u.break], eax
  6105                              <1> 	;
  6106 0000D3B6 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
  6107                              <1> 	;cmp	ecx, [u.count]
  6108                              <1> 	;jnb	short sysexec_16
  6109 0000D3B9 890D[CC300100]      <1> 	mov	[u.count], ecx ; required read count
  6110 0000D3BF EB29                <1> 	jmp	short sysexec_16
  6111                              <1> sysexec_14:
  6112                              <1> 	; insufficient (out of) memory
  6113 0000D3C1 C705[FD300100]0100- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
  6113 0000D3C9 0000                <1>
  6114 0000D3CB E954E2FFFF          <1> 	jmp	error
  6115                              <1> sysexec_15:
  6116 0000D3D0 8B15[31310100]      <1>         mov	edx, [i.size] ; file size
  6117 0000D3D6 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
  6118 0000D3D8 7626                <1> 	jna	short sysexec_17 ; no need to next read
  6119 0000D3DA 01D1                <1> 	add	ecx, edx ; [i.size]
  6120 0000D3DC 3B0D[CC300100]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
  6121 0000D3E2 77DD                <1> 	ja	short sysexec_14
  6122 0000D3E4 8915[CC300100]      <1> 	mov	[u.count], edx
  6123                              <1> sysexec_16:
  6124 0000D3EA A1[2D310100]        <1> 	mov	eax, [ii] ; first cluster
  6125 0000D3EF E8B0000000          <1> 	call	readi
  6126 0000D3F4 8B0D[D0300100]      <1> 	mov	ecx, [u.nread]
  6127 0000D3FA 010D[D4300100]      <1> 	add	[u.break], ecx
  6128                              <1> sysexec_17:
  6129 0000D400 A1[2D310100]        <1> 	mov	eax, [ii] ; first cluster
  6130 0000D405 E8F5050000          <1> 	call	iclose
  6131 0000D40A 31C0                <1> 	xor     eax, eax
  6132 0000D40C FEC0                <1> 	inc	al
  6133 0000D40E 66A3[EC300100]      <1> 	mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
  6134 0000D414 66A3[EE300100]      <1> 	mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled) 
  6135 0000D41A 833D[05310100]00    <1>         cmp	dword [u.ppgdir], 0  ; is the caller MainProg (kernel) ?
  6136 0000D421 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
  6137                              <1> 	; If the caller is kernel (MainProg), 'sysexec' will come here
  6138 0000D423 8B15[C81F0100]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
  6139 0000D429 8915[05310100]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here 
  6140                              <1> sysexec_18:
  6141                              <1> 	; 02/05/2016
  6142                              <1> 	; 24/04/2016 (TRDOS 386 = TRDOS v2.0)
  6143                              <1> 	; 18/10/2015 (Retro UNIX 386 v1)
  6144                              <1> 	; 05/08/2015
  6145                              <1> 	; 29/07/2015
  6146 0000D42F 8B2D[28310100]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
  6147                              <1> 			    ; list pointers (argument count)
  6148 0000D435 FA                  <1> 	cli
  6149 0000D436 8B25[641F0100]      <1>         mov     esp, [tss.esp0]  ; ring 0 (kernel) stack pointer
  6150                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
  6151                              <1> 			    ; for this process	 
  6152                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
  6153                              <1> 	;xor	eax, eax ; 0
  6154 0000D43C FEC8                <1> 	dec	al ; eax = 0
  6155 0000D43E 66BA2300            <1> 	mov	dx, UDATA
  6156 0000D442 6652                <1> 	push	dx  ; user's stack segment
  6157 0000D444 55                  <1> 	push	ebp ; user's stack pointer
  6158                              <1> 		    ; (points to number of arguments)
  6159 0000D445 FB                  <1> 	sti
  6160 0000D446 9C                  <1> 	pushfd	; EFLAGS
  6161                              <1> 		; Set IF for enabling interrupts in user mode	
  6162                              <1> 	;or	dword [esp], 200h 
  6163                              <1> 	;
  6164                              <1> 	;mov	bx, UCODE
  6165                              <1> 	;push	bx ; user's code segment
  6166 0000D447 6A1B                <1> 	push	UCODE
  6167                              <1> 	;push	0
  6168 0000D449 50                  <1> 	push	eax ; EIP (=0) - start address -	
  6169 0000D44A 8925[A0300100]      <1> 	mov	[u.sp], esp ; 29/07/2015
  6170                              <1> 	; 05/08/2015
  6171                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
  6172                              <1> 	; ('push dx' would cause to general protection fault, 
  6173                              <1> 	; after 'pop ds' etc.)
  6174                              <1> 	;
  6175                              <1> 	;; push dx ; ds (UDATA)
  6176                              <1> 	;; push dx ; es (UDATA)
  6177                              <1> 	;; push dx ; fs (UDATA)
  6178                              <1> 	;; push dx ; gs (UDATA)
  6179                              <1> 	;
  6180                              <1> 	; This is a trick to prevent general protection fault
  6181                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
  6182 0000D450 8EC2                <1> 	mov 	es, dx ; UDATA
  6183 0000D452 06                  <1> 	push 	es ; ds (UDATA)
  6184 0000D453 06                  <1> 	push 	es ; es (UDATA)
  6185 0000D454 06                  <1> 	push 	es ; fs (UDATA)
  6186 0000D455 06                  <1> 	push	es ; gs (UDATA)
  6187 0000D456 66BA1000            <1> 	mov	dx, KDATA
  6188 0000D45A 8EC2                <1> 	mov	es, dx
  6189                              <1> 	;
  6190                              <1> 	;; pushad simulation
  6191 0000D45C 89E5                <1> 	mov	ebp, esp ; esp before pushad
  6192 0000D45E 50                  <1> 	push	eax ; eax (0)
  6193 0000D45F 50                  <1> 	push	eax ; ecx (0)
  6194 0000D460 50                  <1> 	push	eax ; edx (0)
  6195 0000D461 50                  <1> 	push	eax ; ebx (0)
  6196 0000D462 55                  <1> 	push	ebp ; esp before pushad
  6197 0000D463 50                  <1> 	push	eax ; ebp (0)
  6198 0000D464 50                  <1> 	push	eax ; esi (0)		
  6199 0000D465 50                  <1> 	push	eax ; edi (0)	
  6200                              <1> 	;
  6201 0000D466 A3[A8300100]        <1> 	mov	[u.r0], eax ; eax = 0
  6202 0000D46B 8925[A4300100]      <1> 	mov	[u.usp], esp
  6203                              <1> 
  6204                              <1> 	; 02/05/2016
  6205 0000D471 FE05[9F300100]      <1> 	inc	byte [sysflg] ; 0FFh -> 0
  6206 0000D477 0FB61D[F7300100]    <1> 	movzx	ebx, byte [u.uno]	
  6207 0000D47E 6683BB[AA2D0100]01  <1> 	cmp	word [ebx+p.ppid-2], 1 ; MainProg
  6208 0000D486 0F87BBE1FFFF        <1> 	ja	sysret0 ; 03/05/2016
  6209 0000D48C 68[44B60000]        <1> 	push	sysret ; * 
  6210 0000D491 8925[A4300100]      <1> 	mov	[u.usp], esp
  6211 0000D497 E88B030000          <1> 	call	wswap ; save child process 'u' structure and
  6212                              <1> 		      ; registers
  6213 0000D49C 8305[A4300100]04    <1> 	add	dword [u.usp], 4 ; 03/05/2016 
  6214                              <1> sysexec_19: ; 02/05/2016
  6215 0000D4A3 C3                  <1> 	retn ; * 'sysret' ; byte [sysflg] -> 0FFh
  6216                              <1> 
  6217                              <1> readi:
  6218                              <1> 	; 01/05/2016
  6219                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  6220                              <1> 	; 20/05/2015 - Retro UNIX 386 v1
  6221                              <1> 	; 11/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  6222                              <1> 	;
  6223                              <1> 	; Reads from a file whose the first cluster number in EAX
  6224                              <1> 	; 
  6225                              <1> 	; INPUTS ->
  6226                              <1> 	;    EAX - First cluster number of the file
  6227                              <1> 	;    u.count - byte count user desires
  6228                              <1> 	;    u.base - points to user buffer
  6229                              <1> 	;    u.fofp - points to dword with current file offset
  6230                              <1> 	;    i.size - file size
  6231                              <1> 	; OUTPUTS ->
  6232                              <1> 	;    u.count - cleared
  6233                              <1> 	;    u.nread - accumulates total bytes passed back
  6234                              <1> 	;
  6235                              <1> 	; ((EAX)) input/output
  6236                              <1> 	; (Retro UNIX Prototype : 01/03/2013 - 14/12/2012, UNIXCOPY.ASM)
  6237                              <1>         ; ((Modified registers: edx, ebx, ecx, esi, esi, ebp))  
  6238                              <1> 
  6239 0000D4A4 31D2                <1> 	xor	edx, edx ; 0
  6240 0000D4A6 8915[D0300100]      <1> 	mov 	[u.nread], edx ; 0
  6241 0000D4AC 668915[0D310100]    <1> 	mov	[u.pcount], dx ; 19/05/2015
  6242 0000D4B3 3915[CC300100]      <1> 	cmp 	[u.count], edx ; 0
  6243 0000D4B9 7701                <1> 	ja 	short readi_1
  6244 0000D4BB C3                  <1> 	retn
  6245                              <1> readi_1:
  6246                              <1> dskr:
  6247                              <1> 	; 01/05/2016
  6248                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  6249                              <1> 	; 24/05/2015 - 12/10/2015 (Retro UNIX 386 v1)
  6250                              <1> 	; 26/04/2013 - 03/08/2013 (Retro UNIX 8086 v1)
  6251                              <1> dskr_0:
  6252 0000D4BC 8B15[31310100]      <1>         mov	edx, [i.size]
  6253 0000D4C2 8B1D[B8300100]      <1> 	mov	ebx, [u.fofp]
  6254 0000D4C8 2B13                <1> 	sub	edx, [ebx]
  6255 0000D4CA 7647                <1> 	jna	short dskr_4
  6256                              <1> 	;
  6257 0000D4CC 50                  <1> 	push	eax ; 01/05/2016
  6258 0000D4CD 3B15[CC300100]      <1> 	cmp     edx, [u.count] 
  6259 0000D4D3 7306                <1> 	jnb	short dskr_1
  6260 0000D4D5 8915[CC300100]      <1> 	mov	[u.count], edx
  6261                              <1> dskr_1:
  6262                              <1> 	; EAX = First Cluster
  6263                              <1> 	; [Current_Drv] = Physical drive number 
  6264 0000D4DB E83B000000          <1> 	call	mget_r
  6265                              <1> 	; NOTE: in 'mget_r', relevant sector will be read in buffer
  6266                              <1> 	; if it not already in buffer !
  6267 0000D4E0 BB[3D310100]        <1> 	mov	ebx, readi_buffer
  6268 0000D4E5 803D[0F310100]00    <1> 	cmp	byte [u.kcall], 0 ; the caller is 'namei' sign (=1)
  6269 0000D4EC 770F                <1> 	ja	short dskr_3	  ; zf=0 -> the caller is 'namei'
  6270 0000D4EE 66833D[0D310100]00  <1> 	cmp	word [u.pcount], 0
  6271 0000D4F6 7705                <1> 	ja	short dskr_3
  6272                              <1> dskr_2:
  6273                              <1> 	; [u.base] = virtual address to transfer (as destination address)
  6274 0000D4F8 E89A010000          <1> 	call	trans_addr_w ; translate virtual address to physical (w)
  6275                              <1> dskr_3:
  6276                              <1> 	; EBX (r5) = system (I/O) buffer address -physical-
  6277 0000D4FD E8F3010000          <1> 	call	sioreg
  6278 0000D502 87F7                <1> 	xchg	esi, edi
  6279                              <1> 	; EDI = file (user data) offset
  6280                              <1> 	; ESI = sector (I/O) buffer offset
  6281                              <1> 	; ECX = byte count
  6282 0000D504 F3A4                <1> 	rep	movsb
  6283                              <1> 	; eax = remain bytes in buffer
  6284                              <1>         ;       (check if remain bytes in the buffer > [u.pcount])
  6285 0000D506 09C0                <1> 	or	eax, eax
  6286 0000D508 75EE                <1> 	jnz	short dskr_2 ; (page end before system buffer end!)		
  6287 0000D50A 58                  <1> 	pop	eax  ; (first cluster number)
  6288 0000D50B 390D[CC300100]      <1> 	cmp	[u.count], ecx ; 0
  6289 0000D511 77A9                <1> 	ja	short dskr_0
  6290                              <1> dskr_4:
  6291 0000D513 C605[0F310100]00    <1> 	mov	byte [u.kcall], 0
  6292 0000D51A C3                  <1> 	retn
  6293                              <1> 
  6294                              <1> mget_r:
  6295                              <1> 	; 29/04/2016
  6296                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  6297                              <1> 	; 03/06/2015 (Retro UNIX 386 v1, 'mget', u.5s)
  6298                              <1> 	; 22/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  6299                              <1> 	;
  6300                              <1> 	; Get existing or (allocate) a new disk block for file
  6301                              <1> 	; 
  6302                              <1> 	; INPUTS ->
  6303                              <1> 	;    u.fofp = file offset pointer
  6304                              <1> 	;    EAX = First Cluster
  6305                              <1> 	;    (u.off = file offset)
  6306                              <1> 	; OUTPUTS ->
  6307                              <1> 	;    EAX = logical sector number
  6308                              <1> 	;    ESI = Logical Dos Drive Description Table address	
  6309                              <1> 	;
  6310                              <1> 	; Modified registers: EDX, EBX, ECX, ESI, EDI, EBP  
  6311                              <1> 
  6312 0000D51B 8B35[B8300100]      <1> 	mov     esi, [u.fofp]
  6313 0000D521 8B1E                <1> 	mov	ebx, [esi] ; u.off
  6314                              <1> 
  6315 0000D523 29C9                <1> 	sub	ecx, ecx
  6316 0000D525 8A2D[8E200100]      <1> 	mov	ch, [Current_Drv]
  6317                              <1> 
  6318 0000D52B BE00010900          <1> 	mov	esi, Logical_DOSDisks
  6319 0000D530 01CE                <1> 	add	esi, ecx
  6320                              <1> 
  6321 0000D532 380D[FC2C0100]      <1> 	cmp	[readi.valid], cl ; 0
  6322 0000D538 764B                <1> 	jna	short mget_r_0
  6323                              <1> 	
  6324 0000D53A 3A2D[FD2C0100]      <1> 	cmp	ch, [readi.drv]
  6325 0000D540 7543                <1> 	jne	short mget_r_0
  6326                              <1> 
  6327 0000D542 3B05[102D0100]      <1> 	cmp	eax, [readi.fclust]
  6328 0000D548 7567                <1> 	jne	short mget_r_3
  6329                              <1> 	
  6330 0000D54A 668B0D[042D0100]    <1> 	mov	cx, [readi.bpc]
  6331 0000D551 41                  <1> 	inc	ecx ; <= 65536
  6332 0000D552 29D2                <1> 	sub	edx, edx
  6333 0000D554 F7F1                <1> 	div	ecx
  6334                              <1> 
  6335 0000D556 8B3D[0C2D0100]      <1> 	mov	edi, [readi.c_index] ; cluster index
  6336                              <1> 
  6337 0000D55C 39F8                <1> 	cmp	eax, edi
  6338 0000D55E 0F858B000000        <1>         jne     mget_r_5  ; (*)
  6339                              <1> 
  6340                              <1> 	; edx = byte offset in cluster (<= 65535)
  6341 0000D564 668915[062D0100]    <1> 	mov	[readi.offset], dx
  6342 0000D56B 66C1EA09            <1> 	shr	dx, 9 ; / 512
  6343 0000D56F 8815[FF2C0100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
  6344                              <1> 	
  6345 0000D575 A1[082D0100]        <1> 	mov	eax, [readi.cluster]
  6346 0000D57A 8B15[142D0100]      <1> 	mov	edx, [readi.fs_index]
  6347 0000D580 E9AF000000          <1>         jmp     mget_r_8
  6348                              <1> 	
  6349                              <1> mget_r_0:
  6350 0000D585 882D[FD2C0100]      <1> 	mov	[readi.drv], ch ; physical drive number
  6351 0000D58B 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  6352 0000D58F 7707                <1> 	ja	short  mget_r_1
  6353 0000D591 8A4E12              <1> 	mov	cl, [esi+LD_FS_BytesPerSec+1]
  6354 0000D594 D0E9                <1> 	shr	cl, 1 ;  ; 1 for 512 bytes, 4 for 2048 bytes
  6355 0000D596 EB03                <1> 	jmp	short mget_r_2	
  6356                              <1> mget_r_1:
  6357 0000D598 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]
  6358                              <1> mget_r_2:
  6359 0000D59B 880D[FE2C0100]      <1> 	mov	[readi.spc], cl  ; sectors per cluster
  6360                              <1> 	; NOTE: readi bytes per sector value is always 512 ! 
  6361 0000D5A1 66C1E109            <1> 	shl	cx, 9 ; * 512
  6362 0000D5A5 6649                <1> 	dec	cx ; bytes per cluster - 1
  6363 0000D5A7 66890D[042D0100]    <1> 	mov	[readi.bpc], cx
  6364 0000D5AE 6629C9              <1> 	sub	cx, cx
  6365                              <1> mget_r_3:
  6366 0000D5B1 A3[102D0100]        <1> 	mov	[readi.fclust], eax ; first cluster (or FDT address)
  6367 0000D5B6 880D[FC2C0100]      <1> 	mov	[readi.valid], cl ; 0 
  6368 0000D5BC 880D[FF2C0100]      <1> 	mov	[readi.s_index], cl ; 0
  6369 0000D5C2 66890D[062D0100]    <1> 	mov	[readi.offset], cx ; 0
  6370 0000D5C9 890D[0C2D0100]      <1> 	mov	[readi.c_index], ecx ; 0
  6371 0000D5CF 890D[082D0100]      <1> 	mov	[readi.cluster], ecx ; 0
  6372 0000D5D5 890D[002D0100]      <1> 	mov	[readi.sector], ecx ; 0
  6373                              <1> mget_r_4:	
  6374 0000D5DB 89D8                <1> 	mov	eax, ebx ; file offset
  6375 0000D5DD 668B0D[042D0100]    <1> 	mov	cx, [readi.bpc]
  6376 0000D5E4 41                  <1> 	inc	ecx ; <= 65536
  6377 0000D5E5 29D2                <1> 	sub	edx, edx
  6378 0000D5E7 F7F1                <1> 	div	ecx
  6379 0000D5E9 8B3D[0C2D0100]      <1> 	mov	edi, [readi.c_index] ; previous cluster index
  6380                              <1> mget_r_5:
  6381 0000D5EF A3[0C2D0100]        <1> 	mov	[readi.c_index], eax ; cluster index
  6382                              <1> 	; edx = byte offset in cluster (<= 65535)
  6383 0000D5F4 668915[062D0100]    <1> 	mov	[readi.offset], dx
  6384 0000D5FB 66C1EA09            <1> 	shr	dx, 9 ; / 512
  6385 0000D5FF 8815[FF2C0100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
  6386                              <1> 
  6387 0000D605 89C1                <1> 	mov	ecx, eax ; current cluster index
  6388 0000D607 A1[102D0100]        <1> 	mov	eax, [readi.fclust]
  6389 0000D60C 09C9                <1> 	or	ecx, ecx ; cluster index
  6390 0000D60E 741F                <1> 	jz	short mget_r_7
  6391                              <1> 
  6392 0000D610 39CF                <1> 	cmp	edi, ecx
  6393 0000D612 7710                <1> 	ja	short mget_r_6 ; old cluster index is higher
  6394 0000D614 8B15[082D0100]      <1> 	mov	edx, [readi.cluster]
  6395 0000D61A 21D2                <1> 	and	edx, edx
  6396 0000D61C 7406                <1> 	jz	short mget_r_6
  6397                              <1> 	; valid 'readi' parameters (*)
  6398 0000D61E 89D0                <1> 	mov	eax, edx
  6399 0000D620 29F9                <1> 	sub	ecx, edi
  6400 0000D622 7410                <1> 	jz	short mget_r_8
  6401                              <1> mget_r_6:
  6402                              <1> 	; EAX = Beginning cluster
  6403                              <1> 	; EDX = Sector index in disk/file section
  6404                              <1> 	;	(Only for SINGLIX file system!)
  6405                              <1> 	; ECX = Cluster sequence number after the beginning cluster
  6406                              <1> 	; ESI = Logical DOS Drive Description Table address
  6407 0000D624 E8C9DEFFFF          <1> 	call	get_cluster_by_index
  6408 0000D629 0F82F5DFFFFF        <1> 	jc	error
  6409                              <1> 	; EAX = Cluster number		
  6410                              <1> mget_r_7:
  6411 0000D62F A3[082D0100]        <1> 	mov	[readi.cluster], eax ; FDT number for Singlix File System
  6412                              <1> mget_r_8:
  6413 0000D634 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  6414 0000D638 764E                <1> 	jna	short  mget_r_13
  6415                              <1> 
  6416 0000D63A 83E802              <1> 	sub	eax, 2
  6417 0000D63D 0FB615[FE2C0100]    <1> 	movzx	edx, byte [readi.spc]
  6418 0000D644 F7E2                <1> 	mul	edx
  6419                              <1> 
  6420 0000D646 034668              <1> 	add	eax, [esi+LD_DATABegin]
  6421 0000D649 8A15[FF2C0100]      <1> 	mov	dl, [readi.s_index]
  6422 0000D64F 01D0                <1> 	add	eax, edx
  6423                              <1> msget_r_9:
  6424                              <1> 	; eax = logical sector number
  6425 0000D651 803D[FC2C0100]00    <1> 	cmp	byte [readi.valid], 0
  6426 0000D658 7608                <1> 	jna	short mget_r_10
  6427 0000D65A 3B05[002D0100]      <1> 	cmp	eax, [readi.sector]
  6428 0000D660 7425                <1> 	je	short mget_r_12 ; sector is already in 'readi' buffer
  6429                              <1> mget_r_10:
  6430 0000D662 A3[002D0100]        <1> 	mov	[readi.sector], eax
  6431 0000D667 BB[3D310100]        <1> 	mov	ebx, readi_buffer ; buffer address
  6432 0000D66C B901000000          <1> 	mov	ecx, 1
  6433                              <1> 	; 29/04/2016
  6434                              <1> 	;xor	dl, dl
  6435                              <1> 
  6436                              <1> 	; EAX = Logical sector number
  6437                              <1> 	; ECX = Sector count
  6438                              <1> 	; EBX = Buffer address
  6439                              <1> 	; (EDX = 0)
  6440                              <1> 	; ESI = Logical DOS drive description table address	
  6441                              <1> 
  6442 0000D671 E8A6030000          <1> 	call	disk_read
  6443 0000D676 730A                <1> 	jnc	short mget_r_11
  6444                              <1> 
  6445 0000D678 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
  6446 0000D67D E9A2DFFFFF          <1> 	jmp	error
  6447                              <1> mget_r_11:
  6448 0000D682 A1[002D0100]        <1> 	mov	eax, [readi.sector]
  6449                              <1> mget_r_12:
  6450 0000D687 C3                  <1> 	retn
  6451                              <1> mget_r_13:
  6452                              <1> 	; EAX = FDT number
  6453                              <1> 	; EDX = Sector index from FDT sector (0,1,2,3,4...)
  6454 0000D688 40                  <1> 	inc	eax ; the first data sector in FS disk section	
  6455 0000D689 8915[142D0100]      <1> 	mov	[readi.fs_index], edx
  6456 0000D68F 01D0                <1> 	add	eax, edx
  6457 0000D691 EBBE                <1> 	jmp	short msget_r_9
  6458                              <1> 
  6459                              <1> trans_addr_r:
  6460                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
  6461                              <1> 	; Translate virtual address to physical address 
  6462                              <1> 	; for reading from user's memory space
  6463                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
  6464                              <1> 
  6465 0000D693 31D2                <1> 	xor	edx, edx ; 0 (read access sign)
  6466 0000D695 EB04                <1> 	jmp 	short trans_addr_rw
  6467                              <1> 
  6468                              <1> trans_addr_w:
  6469                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6470                              <1> 	; Translate virtual address to physical address 
  6471                              <1> 	; for writing to user's memory space
  6472                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
  6473                              <1> 	
  6474 0000D697 29D2                <1> 	sub	edx, edx
  6475 0000D699 FEC2                <1> 	inc	dl ; 1 (write access sign)
  6476                              <1> trans_addr_rw:
  6477 0000D69B 50                  <1> 	push	eax
  6478 0000D69C 53                  <1> 	push	ebx
  6479 0000D69D 52                  <1> 	push 	edx ; r/w sign (in DL)
  6480                              <1> 	;
  6481 0000D69E 8B1D[C8300100]      <1> 	mov	ebx, [u.base]
  6482 0000D6A4 E85576FFFF          <1> 	call	get_physical_addr ; get physical address
  6483 0000D6A9 730A                <1> 	jnc	short passc_0
  6484 0000D6AB A3[FD300100]        <1> 	mov	[u.error], eax
  6485                              <1> 	;pop	edx
  6486                              <1> 	;pop 	ebx
  6487                              <1> 	;pop	eax
  6488 0000D6B0 E96FDFFFFF          <1> 	jmp	error
  6489                              <1> passc_0:
  6490 0000D6B5 F6C202              <1> 	test	dl, PTE_A_WRITE ; writable page
  6491 0000D6B8 5A                  <1> 	pop	edx
  6492 0000D6B9 751C                <1> 	jnz	short passc_1
  6493                              <1> 	
  6494 0000D6BB 20D2                <1> 	and 	dl, dl
  6495 0000D6BD 7418                <1> 	jz	short passc_1
  6496                              <1> 	; read only (duplicated) page -must be copied to a new page-
  6497                              <1> 	; EBX = linear address
  6498 0000D6BF 51                  <1> 	push 	ecx
  6499 0000D6C0 E8CF72FFFF          <1> 	call 	copy_page
  6500 0000D6C5 59                  <1> 	pop	ecx
  6501 0000D6C6 721E                <1> 	jc	short passc_2
  6502 0000D6C8 50                  <1> 	push	eax ; physical address of the new/allocated page
  6503 0000D6C9 E85A75FFFF          <1> 	call	add_to_swap_queue	
  6504 0000D6CE 58                  <1> 	pop	eax
  6505 0000D6CF 81E3FF0F0000        <1> 	and 	ebx, PAGE_OFF ; 0FFFh
  6506                              <1> 	;mov 	ecx, PAGE_SIZE
  6507                              <1> 	;sub	ecx, ebx 
  6508 0000D6D5 01D8                <1> 	add	eax, ebx  
  6509                              <1> passc_1: 
  6510 0000D6D7 A3[09310100]        <1> 	mov 	[u.pbase], eax ; physical address	
  6511 0000D6DC 66890D[0D310100]    <1> 	mov	[u.pcount], cx ; remain byte count in page (1-4096)
  6512 0000D6E3 5B                  <1> 	pop	ebx
  6513 0000D6E4 58                  <1> 	pop	eax
  6514 0000D6E5 C3                  <1> 	retn
  6515                              <1> passc_2:
  6516 0000D6E6 C705[FD300100]0100- <1> 	mov	dword [u.error], ERR_MINOR_IM ; "Insufficient memory !" error
  6516 0000D6EE 0000                <1>
  6517                              <1> 	;pop 	ebx
  6518                              <1> 	;pop	eax
  6519 0000D6F0 E92FDFFFFF          <1> 	jmp	error
  6520                              <1> 
  6521                              <1> sioreg: 
  6522                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6523                              <1> 	; 19/05/2015 - 25/07/2015 (Retro UNIX 386 v1)
  6524                              <1> 	; 12/03/2013 - 22/07/2013 (Retro UNIX 8086 v1)
  6525                              <1> 	; INPUTS -> 
  6526                              <1> 	;     EBX = system buffer (data) address (r5)
  6527                              <1> 	;     [u.fofp] = pointer to file offset pointer
  6528                              <1> 	;     [u.base] = virtual address of the user buffer
  6529                              <1> 	;     [u.pbase] = physical address of the user buffer
  6530                              <1> 	;     [u.count] = byte count
  6531                              <1> 	;     [u.pcount] = byte count within page frame 			
  6532                              <1> 	; OUTPUTS -> 
  6533                              <1> 	;     ESI = user data offset (r1)
  6534                              <1> 	;     EDI = system (I/O) buffer offset (r2)
  6535                              <1> 	;     ECX = byte count (r3)
  6536                              <1> 	;     EAX = remain bytes after byte count within page frame
  6537                              <1> 	;	(If EAX > 0, transfer will continue from the next page)
  6538                              <1>         ;
  6539                              <1> 	; ((Modified registers:  EDX))
  6540                              <1>  
  6541 0000D6F5 8B35[B8300100]      <1>         mov     esi, [u.fofp]
  6542 0000D6FB 8B3E                <1>         mov     edi, [esi]
  6543 0000D6FD 89F9                <1> 	mov	ecx, edi
  6544 0000D6FF 81C900FEFFFF        <1> 	or	ecx, 0FFFFFE00h
  6545 0000D705 81E7FF010000        <1> 	and	edi, 1FFh
  6546 0000D70B 01DF                <1> 	add	edi, ebx ; EBX = system buffer (data) address
  6547 0000D70D F7D9                <1> 	neg	ecx
  6548 0000D70F 3B0D[CC300100]      <1> 	cmp	ecx, [u.count]
  6549 0000D715 7606                <1> 	jna	short sioreg_0
  6550 0000D717 8B0D[CC300100]      <1> 	mov	ecx, [u.count]
  6551                              <1> sioreg_0:
  6552 0000D71D 803D[0F310100]00    <1> 	cmp	byte [u.kcall], 0 
  6553 0000D724 7613                <1> 	jna	short sioreg_1
  6554                              <1> 	 ; the caller is 'mkdir' or 'namei'
  6555 0000D726 A1[C8300100]        <1> 	mov	eax, [u.base]
  6556 0000D72B A3[09310100]        <1> 	mov 	[u.pbase], eax ; physical address = virtual address
  6557 0000D730 66890D[0D310100]    <1> 	mov	word [u.pcount], cx ; remain bytes in buffer (1 sector)
  6558 0000D737 EB0B                <1> 	jmp	short sioreg_2
  6559                              <1> sioreg_1:
  6560 0000D739 0FB715[0D310100]    <1> 	movzx	edx, word [u.pcount]
  6561 0000D740 39D1                <1> 	cmp	ecx, edx	
  6562 0000D742 772A                <1> 	ja	short sioreg_4 ; transfer count > [u.pcount]
  6563                              <1> sioreg_2: ; 2:
  6564 0000D744 31C0                <1> 	xor 	eax, eax
  6565                              <1> sioreg_3:
  6566 0000D746 010D[D0300100]      <1> 	add 	[u.nread], ecx
  6567 0000D74C 290D[CC300100]      <1> 	sub 	[u.count], ecx
  6568 0000D752 010D[C8300100]      <1> 	add 	[u.base], ecx
  6569 0000D758 010E                <1>         add 	[esi], ecx 
  6570 0000D75A 8B35[09310100]      <1> 	mov	esi, [u.pbase]
  6571 0000D760 66290D[0D310100]    <1> 	sub	[u.pcount], cx
  6572 0000D767 010D[09310100]      <1> 	add	[u.pbase], ecx
  6573 0000D76D C3                  <1>         retn
  6574                              <1> sioreg_4:
  6575                              <1> 	; transfer count > [u.pcount] 
  6576                              <1> 	; (ecx > edx)
  6577 0000D76E 89C8                <1> 	mov	eax, ecx
  6578 0000D770 29D0                <1> 	sub	eax, edx ; remain bytes for 1 sector (block) transfer 
  6579 0000D772 89D1                <1> 	mov	ecx, edx ; current transfer count = [u.pcount]
  6580 0000D774 EBD0                <1> 	jmp	short sioreg_3
  6581                              <1> 
  6582                              <1> tswitch: ; Retro UNIX 386 v1
  6583                              <1> tswap:
  6584                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0)
  6585                              <1> 	; 10/05/2015 - 01/09/2015 (Retro UNIX 386 v1)
  6586                              <1> 	; 14/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
  6587                              <1> 	; time out swap, called when a user times out.
  6588                              <1> 	; the user is put on the low priority queue.
  6589                              <1> 	; This is done by making a link from the last user
  6590                              <1> 	; on the low priority queue to him via a call to 'putlu'.
  6591                              <1> 	; then he is swapped out.
  6592                              <1> 
  6593                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 21/05/2016 **
  6594                              <1> 	;     * when a high priority (event) process will be stopped
  6595                              <1> 	;	(swapped out, swithched out/off), 'tswap/tswitch' will
  6596                              <1> 	;	not add it to a run queue. 
  6597                              <1> 	;	/// What for: Process may be already in a run queue, 
  6598                              <1> 	;	it is unspeficied state because process might be started
  6599                              <1> 	;	by a timer event which does not regard previous priority
  6600                              <1> 	;	level and run queue of the process (for fast executing!).
  6601                              <1> 	;	After the 'run for event', process will be sequenced
  6602                              <1> 	;	to run by it's actual run queue. ///
  6603                              <1> 	;
  6604                              <1> 	; Retro UNIX 386 v1 modification ->
  6605                              <1> 	;       swap (software task switch) is performed by changing
  6606                              <1> 	;	user's page directory (u.pgdir) instead of segment change
  6607                              <1> 	;	as in Retro UNIX 8086 v1.
  6608                              <1> 	;
  6609                              <1> 	; RETRO UNIX 8086 v1 modification ->
  6610                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6611                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6612                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6613                              <1> 	;	compatibles was using 1MB segmented memory 
  6614                              <1> 	;	in 8086/8088 times.
  6615                              <1> 	;
  6616                              <1> 	; INPUTS ->
  6617                              <1> 	;    u.uno - users process number
  6618                              <1> 	;    runq+4 - lowest priority queue
  6619                              <1> 	; OUTPUTS ->
  6620                              <1> 	;    r0 - users process number
  6621                              <1> 	;    r2 - lowest priority queue address
  6622                              <1> 	;
  6623                              <1> 	; ((AX = R0, BX = R2)) output
  6624                              <1> 	; ((Modified registers: EDX, EBX, ECX, ESI, EDI))  	
  6625                              <1> 	;
  6626                              <1> 
  6627                              <1> 	NOTE:
  6628                              <1> 	;* [u.pri] priority level is specified by run queue which is process 
  6629                              <1> 	;  comes to run from.
  6630                              <1> 	;* Initial [u.pri] is 1 ('normal/regular') for programs 
  6631                              <1> 	;  (which are launched by MainProg or 'sysexec'), it is changed
  6632                              <1> 	;  to 2 ('high') by timer event, if program uses 'systimer' system call.
  6633                              <1> 	;* Program (Process) also can change it's running priority 
  6634                              <1> 	;  from 1 to 0 or up to 2 by using 'syspri' system call; but,
  6635                              <1> 	;  if program selects priority level 2 (high) for running, next time 
  6636                              <1> 	;  it is reduced to 1 (normal/regular) because 'syspri' adds this
  6637                              <1> 	;  program to 'run for normal' queue while running duration is a bit
  6638                              <1> 	;  protected from swap/switch out immediate, behalf of other high 
  6639                              <1> 	;  priority process in sequence. Program (with high priority) will not 
  6640                              <1> 	;  be swapped/switched out (by timer event) before it's time quantum 
  6641                              <1> 	;  will be elapsed, but, this will be temporary if program is not using 
  6642                              <1> 	;  timer event function.	  			 	
  6643                              <1> 
  6644                              <1> 	;For example:
  6645                              <1> 	;If a process frequently gets a timer event, it runs at high priority
  6646                              <1> 	;level but when it returns from running it returns to actual run queue,
  6647                              <1> 	;not to 'run for event' queue again.
  6648                              <1> 	;'tswap' will not change the sequence at return/stop(swap out) stage.
  6649                              <1> 	;But if priority level not high (=2, 'run for event'), 'tswap/tswitch'
  6650                              <1> 	;will add the stopping process to relevant run queue according to
  6651                              <1> 	;[u.pri] priority level.
  6652                              <1> 
  6653                              <1> 	; 21/05/2016
  6654 0000D776 803D[EB300100]02    <1> 	cmp	byte [u.pri], 2	; high priority (run for event) ?
  6655 0000D77D 731A                <1> 	jnb	short swap      ; yes, do not add process to the run queue   
  6656                              <1> 	
  6657 0000D77F BB[98300100]        <1> 	mov	ebx, runq+2 	; 'runq_normal' ; normal/regular priority
  6658 0000D784 803D[EB300100]00    <1> 	cmp	byte [u.pri], 0
  6659 0000D78B 7702                <1> 	ja	short tswap_1	; normal priority
  6660                              <1> 
  6661 0000D78D 43                  <1> 	inc	ebx
  6662 0000D78E 43                  <1> 	inc	ebx		; runq+4, 'runq_background', low priority
  6663                              <1> tswap_1:
  6664 0000D78F A0[F7300100]        <1> 	mov 	al, [u.uno]
  6665                              <1> 	       	; movb u.uno,r1 / move users process number to r1
  6666                              <1> 		; mov  $runq+4,r2 
  6667                              <1> 			; / move lowest priority queue address to r2
  6668                              <1>       	; ebx = run queue
  6669 0000D794 E8F0000000          <1> 	call 	putlu
  6670                              <1> 		; jsr r0,putlu / create link from last user on Q to 
  6671                              <1> 		             ; / u.uno's user
  6672                              <1> 
  6673                              <1> switch: ; Retro UNIX 386 v1
  6674                              <1> swap:
  6675                              <1> 	; 21/05/2016
  6676                              <1> 	; 20/05/2016
  6677                              <1> 	; 02/05/2016
  6678                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6679                              <1> 	; 10/05/2015 - 02/09/2015 (Retro UNIX 386 v1)
  6680                              <1> 	; 14/04/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6681                              <1> 	;
  6682                              <1> 	; 'swap' is routine that controls the swapping of processes
  6683                              <1> 	; in and out of core.
  6684                              <1> 	;
  6685                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 20/05/2016 **
  6686                              <1> 	;     * 3 different priority level is applied 
  6687                              <1> 	;	(just as original unix v1)
  6688                              <1> 	;	1) high priority (event) run queue, 'runq_event'
  6689                              <1> 	;	2) normal priority (regular) run queue, 'runq_normal'
  6690                              <1> 	;	3) low priority (background) run queue, 'runq_backgroud'
  6691                              <1> 	;	'swap' code will run a process which has max. priority
  6692                              <1>         ;       (for earliest event at first)
  6693                              <1> 	;
  6694                              <1> 	; Retro UNIX 386 v1 modification ->
  6695                              <1> 	;       swap (software task switch) is performed by changing
  6696                              <1> 	;	user's page directory (u.pgdir) instead of segment change
  6697                              <1> 	;	as in Retro UNIX 8086 v1.
  6698                              <1> 	;
  6699                              <1> 	; RETRO UNIX 8086 v1 modification ->
  6700                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6701                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6702                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6703                              <1> 	;	compatibles was using 1MB segmented memory 
  6704                              <1> 	;	in 8086/8088 times.
  6705                              <1> 	;
  6706                              <1> 	; INPUTS ->
  6707                              <1> 	;    runq table - contains processes to run.
  6708                              <1> 	;    p.link - contains next process in line to be run.
  6709                              <1> 	;    u.uno - process number of process in core	
  6710                              <1> 	;    s.stack - swap stack used as an internal stack for swapping.	
  6711                              <1> 	; OUTPUTS ->
  6712                              <1> 	;    (original unix v1 -> present process to its disk block)
  6713                              <1> 	;    (original unix v1 -> new process into core -> 
  6714                              <1> 	;	   Retro Unix 8086 v1 -> segment registers changed 
  6715                              <1> 	;	   for new process)
  6716                              <1> 	;    u.quant = 3 (Time quantum for a process)
  6717                              <1> 	; 	((INT 1Ch count down speed -> 18.2 times per second)	 	
  6718                              <1> 	;    RETRO UNIX 8086 v1 will use INT 1Ch (18.2 times per second)
  6719                              <1> 	;	 for now, it will swap the process if there is not
  6720                              <1> 	;	 a keyboard event (keystroke) (Int 15h, function 4Fh)
  6721                              <1> 	;	 or will count down from 3 to 0 even if there is a
  6722                              <1> 	;        keyboard event locking due to repetitive key strokes.
  6723                              <1> 	;	 u.quant will be reset to 3 for RETRO UNIX 8086 v1.
  6724                              <1> 	;
  6725                              <1> 	; ((Modified registers: EAX, EDX, EBX, ECX, ESI, EDI))  	
  6726                              <1> 
  6727                              <1> 	;NOTE:
  6728                              <1> 	;High priority queue is the first for selecting a process to run.
  6729                              <1> 	;If there is not a process in high priority level run queue,
  6730                              <1> 	;a process in normal priority run queue will be selected
  6731                              <1> 	;or a proces in low priority run queue will be selected if normal
  6732                              <1> 	;priority level run queue is empty.
  6733                              <1> 	
  6734                              <1> 	; 21/05/2016 -(3 priority levels, 3 run queues)
  6735 0000D799 BE[96300100]        <1> 	mov	esi, runq ; 'runq_event' ; high priority, 'run for event'
  6736 0000D79E C605[4C2D0100]03    <1> 	mov	byte [priority], 3 ; high priority + 1
  6737                              <1> swap_0: ; 1: / search runq table for highest priority process
  6738 0000D7A5 66AD                <1> 	lodsw  ; mov ax, [esi], add esi+2
  6739 0000D7A7 31DB                <1> 	xor	ebx, ebx ; 02/05/2016
  6740 0000D7A9 6621C0              <1> 	and 	ax, ax ; are there any processes to run in this Q entry
  6741 0000D7AC 750E                <1> 	jnz	short swap_2 
  6742                              <1> 	; 21/05/2026
  6743                              <1> 	; runq_normal = runq+2, runq_background = runq+4
  6744 0000D7AE FE0D[4C2D0100]      <1> 	dec	byte [priority] ; 3 -> 3, 2 -> 1, 1-> 0
  6745 0000D7B4 75EF                <1> 	jnz	short swap_0	
  6746                              <1> 	;cmp	esi, runq+6  ; if zero compare address to end of table
  6747                              <1> 	;jb	short swap_0 ; if not at end, go back
  6748                              <1> swap_1:
  6749                              <1> 	; 02/05/2016
  6750                              <1> 	; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  6751                              <1> 	; No user process to run...
  6752                              <1> 	; Run the kernel process... MainProg: Internal Command Interpreter  
  6753 0000D7B6 FEC0                <1> 	inc	al ; mov al, 1  ; process number of MainProg
  6754 0000D7B8 FEC3                <1> 	inc	bl ; mov bl, al ; 1
  6755 0000D7BA EB1E                <1> 	jmp	short swap_4
  6756                              <1> swap_2:
  6757                              <1> 	; 21/05/2016
  6758 0000D7BC FE0D[4C2D0100]      <1> 	dec	byte [priority] ; priority level of present user/process
  6759                              <1> 			        ; 0, 1, 2	   
  6760 0000D7C2 4E                  <1> 	dec	esi
  6761 0000D7C3 4E                  <1>         dec     esi
  6762                              <1> 	;
  6763 0000D7C4 88C3                <1> 	mov	bl, al
  6764 0000D7C6 38E0                <1> 	cmp	al, ah ; is there only 1 process in the queue to be run
  6765 0000D7C8 740A                <1> 	je	short swap_3 ; yes
  6766 0000D7CA 8AA3[0B2E0100]      <1> 	mov	ah, [ebx+p.link-1] 
  6767 0000D7D0 8826                <1>        	mov	[esi], ah ; move next process in line into run queue
  6768 0000D7D2 EB06                <1> 	jmp	short swap_4
  6769                              <1> swap_3: 
  6770 0000D7D4 6631D2              <1> 	xor	dx, dx
  6771 0000D7D7 668916              <1> 	mov	[esi], dx ; zero the entry; no processes on the Q
  6772                              <1> swap_4: 
  6773 0000D7DA 8A25[F7300100]      <1> 	mov 	ah, [u.uno]
  6774 0000D7E0 38C4                <1> 	cmp	ah, al ;is this process the same as the process in core?
  6775 0000D7E2 743B                <1>        	je	short swap_8 ; yes, don't have to swap
  6776 0000D7E4 08E4                <1> 	or	ah, ah  ; is the process # = 0
  6777 0000D7E6 740D                <1>        	jz	short swap_6 ; 'sysexit'
  6778 0000D7E8 8925[A4300100]      <1> 	mov	[u.usp], esp ; return  address for 'syswait' & 'sleep'
  6779 0000D7EE E834000000          <1> 	call	wswap   ; write out core to disk
  6780 0000D7F3 EB1C                <1> 	jmp 	short swap_7
  6781                              <1> swap_6:
  6782                              <1> 	; Deallocate memory pages belong to the process
  6783                              <1> 	; which is being terminated.
  6784                              <1> 	; (Retro UNIX 386 v1 modification !)
  6785                              <1> 	;
  6786 0000D7F5 53                  <1> 	push	ebx
  6787 0000D7F6 A1[01310100]        <1> 	mov 	eax, [u.pgdir]  ; page directory of the process
  6788 0000D7FB 8B1D[05310100]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  6789 0000D801 E8196FFFFF          <1> 	call	deallocate_page_dir
  6790 0000D806 A1[F8300100]        <1> 	mov	eax, [u.upage] ; 'user' structure page of the process
  6791 0000D80B E8B46FFFFF          <1> 	call	deallocate_page
  6792 0000D810 5B                  <1> 	pop	ebx
  6793                              <1> swap_7: 
  6794 0000D811 C0E302              <1> 	shl	bl, 2 ; * 4 
  6795 0000D814 8B83[282E0100]      <1> 	mov	eax, [ebx+p.upage-4] ; the 'u' page of the new process
  6796 0000D81A E831000000          <1> 	call	rswap ; read new process into core
  6797                              <1> swap_8: 
  6798                              <1> 	; Retro UNIX  8086 v1 modification !
  6799 0000D81F C605[EA300100]04    <1> 	mov	byte [u.quant], time_count 
  6800 0000D826 C3                  <1> 	retn
  6801                              <1> 
  6802                              <1> wswap:  ; < swap out, swap to disk >
  6803                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6804                              <1> 	; 09/05/2015 (Retro UNIX 386 v1)
  6805                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6806                              <1> 	; 'wswap' writes out the process that is in core onto its 
  6807                              <1> 	; appropriate disk area.
  6808                              <1> 	;
  6809                              <1> 	; Retro UNIX 386 v1 modification ->
  6810                              <1> 	;       User (u) structure content and the user's register content
  6811                              <1> 	;	will be copied to the process's/user's UPAGE (a page for
  6812                              <1> 	;	saving 'u' structure and user registers for task switching).
  6813                              <1> 	;	u.usp - points to kernel stack address which contains
  6814                              <1> 	;		user's registers while entering system call.  
  6815                              <1> 	;	u.sp  - points to kernel stack address 
  6816                              <1> 	;		to return from system call -for IRET-.
  6817                              <1> 	;	[u.usp]+32+16 = [u.sp] 
  6818                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx, 
  6819                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
  6820                              <1> 	;
  6821                              <1> 	; Retro UNIX 8086 v1 modification ->
  6822                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6823                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6824                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6825                              <1> 	;	compatibles was using 1MB segmented memory 
  6826                              <1> 	;	in 8086/8088 times.
  6827                              <1> 	;
  6828                              <1> 	; INPUTS ->
  6829                              <1> 	;    u.break - points to end of program
  6830                              <1> 	;    u.usp - stack pointer at the moment of swap
  6831                              <1> 	;    core - beginning of process program		
  6832                              <1> 	;    ecore - end of core 	
  6833                              <1> 	;    user - start of user parameter area		
  6834                              <1> 	;    u.uno - user process number	
  6835                              <1> 	;    p.dska - holds block number of process	
  6836                              <1> 	; OUTPUTS ->
  6837                              <1> 	;    swp I/O queue
  6838                              <1> 	;    p.break - negative word count of process 
  6839                              <1> 	;    r1 - process disk address	
  6840                              <1> 	;    r2 - negative word count
  6841                              <1> 	;
  6842                              <1> 	; RETRO UNIX 8086 v1 input/output:
  6843                              <1> 	;
  6844                              <1> 	; INPUTS ->
  6845                              <1> 	;    u.uno - process number (to be swapped out)
  6846                              <1> 	; OUTPUTS ->
  6847                              <1> 	;    none
  6848                              <1> 	;
  6849                              <1> 	;   ((Modified registers: ECX, ESI, EDI))  
  6850                              <1> 	;
  6851 0000D827 8B3D[F8300100]      <1> 	mov	edi, [u.upage] ; process's user (u) structure page addr
  6852 0000D82D B91E000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
  6853 0000D832 BE[A0300100]        <1> 	mov	esi, user ; active user (u) structure	
  6854 0000D837 F3A5                <1> 	rep	movsd
  6855                              <1> 	;
  6856 0000D839 8B35[A4300100]      <1> 	mov	esi, [u.usp] ; esp (system stack pointer, 
  6857                              <1> 			     ;      points to user registers)
  6858 0000D83F 8B0D[A0300100]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
  6859                              <1> 			     ; (for IRET)
  6860                              <1> 			     ; [u.sp] -> EIP (user)
  6861                              <1> 			     ; [u.sp+4]-> CS (user)
  6862                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
  6863                              <1> 			     ; [u.sp+12] -> ESP (user)
  6864                              <1> 			     ; [u.sp+16] -> SS (user)	
  6865 0000D845 29F1                <1> 	sub	ecx, esi     ; required space for user registers
  6866 0000D847 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
  6867                              <1> 			     ; (for IRET) 	
  6868 0000D84A C1E902              <1> 	shr	ecx, 2	     		
  6869 0000D84D F3A5                <1> 	rep	movsd
  6870 0000D84F C3                  <1> 	retn
  6871                              <1> 
  6872                              <1> rswap:  ; < swap in, swap from disk >
  6873                              <1> 	; 21/05/2016
  6874                              <1> 	; 03/05/2016
  6875                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6876                              <1> 	; 09/05/2015 - 15/09/2015 (Retro UNIX 386 v1)
  6877                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6878                              <1> 	; 'rswap' reads a process whose number is in r1, 
  6879                              <1> 	; from disk into core.
  6880                              <1> 	;
  6881                              <1> 	; Retro UNIX 386 v1 modification ->
  6882                              <1> 	;       User (u) structure content and the user's register content
  6883                              <1> 	;	will be restored from process's/user's UPAGE (a page for
  6884                              <1> 	;	saving 'u' structure and user registers for task switching).
  6885                              <1> 	;	u.usp - points to kernel stack address which contains
  6886                              <1> 	;		user's registers while entering system call.  
  6887                              <1> 	;	u.sp  - points to kernel stack address 
  6888                              <1> 	;		to return from system call -for IRET-.
  6889                              <1> 	;	[u.usp]+32+16 = [u.sp] 
  6890                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx, 
  6891                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
  6892                              <1> 	;
  6893                              <1> 	; RETRO UNIX 8086 v1 modification ->
  6894                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6895                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6896                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6897                              <1> 	;	compatibles was using 1MB segmented memory 
  6898                              <1> 	;	in 8086/8088 times.
  6899                              <1> 	;
  6900                              <1> 	; INPUTS ->
  6901                              <1> 	;    r1 - process number of process to be read in
  6902                              <1> 	;    p.break - negative of word count of process 
  6903                              <1> 	;    p.dska - disk address of the process		
  6904                              <1> 	;    u.emt - determines handling of emt's 	
  6905                              <1> 	;    u.ilgins - determines handling of illegal instructions		
  6906                              <1> 	; OUTPUTS ->
  6907                              <1> 	;    8 = (u.ilgins)
  6908                              <1> 	;    24 = (u.emt)
  6909                              <1> 	;    swp - bit 10 is set to indicate read 
  6910                              <1> 	;		(bit 15=0 when reading is done)	
  6911                              <1> 	;    swp+2 - disk block address
  6912                              <1> 	;    swp+4 - negative word count 	
  6913                              <1> 	;      ((swp+6 - address of user structure)) 
  6914                              <1> 	;
  6915                              <1> 	; RETRO UNIX 8086 v1 input/output:
  6916                              <1> 	;
  6917                              <1> 	; INPUTS ->
  6918                              <1> 	;    AL	- new process number (to be swapped in)	 
  6919                              <1> 	; OUTPUTS ->
  6920                              <1> 	;    none
  6921                              <1> 	;
  6922                              <1> 	;   ((Modified registers: EAX, ECX, ESI, EDI, ESP)) 
  6923                              <1> 	;
  6924                              <1> 	; Retro UNIX 386 v1 - modification ! 14/05/2015
  6925 0000D850 89C6                <1> 	mov	esi, eax  ; process's user (u) structure page addr
  6926 0000D852 B91E000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
  6927 0000D857 BF[A0300100]        <1> 	mov	edi, user ; active user (u) structure	
  6928 0000D85C F3A5                <1> 	rep	movsd
  6929 0000D85E 58                  <1> 	pop	eax	; 'rswap' return address
  6930                              <1> 	; 
  6931                              <1> 	;; 21/05/2016
  6932 0000D85F 8A0D[4C2D0100]      <1> 	mov	cl, [priority]
  6933 0000D865 880D[EB300100]      <1> 	mov	[u.pri], cl  ; running priority level 
  6934                              <1> 			     ; (specifies run queue which is 
  6935                              <1> 			     ; process comes from)
  6936                              <1> 	;cli
  6937 0000D86B 8B3D[A4300100]      <1> 	mov	edi, [u.usp] ; esp (system stack pointer, 
  6938                              <1> 			     ;     points to user registers)
  6939 0000D871 8B0D[A0300100]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
  6940                              <1> 			     ; (for IRET)
  6941                              <1> 			     ; [u.sp] -> EIP (user)
  6942                              <1> 			     ; [u.sp+4]-> CS (user)
  6943                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
  6944                              <1> 			     ; [u.sp+12] -> ESP (user)
  6945                              <1> 			     ; [u.sp+16] -> SS (user)		
  6946 0000D877 29F9                <1> 	sub	ecx, edi     ; required space for user registers
  6947 0000D879 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
  6948                              <1> 			     ; (for IRET) 	
  6949 0000D87C C1E902              <1> 	shr	ecx, 2	       		
  6950 0000D87F F3A5                <1> 	rep	movsd
  6951 0000D881 8B25[A4300100]      <1> 	mov	esp, [u.usp] ; 15/09/2015
  6952                              <1> 	;sti
  6953 0000D887 50                  <1> 	push	eax	; 'rswap' return address
  6954 0000D888 C3                  <1> 	retn
  6955                              <1> 
  6956                              <1> putlu: 
  6957                              <1> 	; 20/05/2016
  6958                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6959                              <1> 	; 10/05/2015 - 12/09/2015 (Retro UNIX 386 v1)
  6960                              <1> 	; 15/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
  6961                              <1> 	; 'putlu' is called with a process number in r1 and a pointer
  6962                              <1> 	; to lowest priority Q (runq+4) in r2. A link is created from
  6963                              <1> 	; the last process on the queue to process in r1 by putting
  6964                              <1> 	; the process number in r1 into the last process's link.
  6965                              <1> 	;
  6966                              <1> 	; INPUTS ->
  6967                              <1> 	;    r1 - user process number
  6968                              <1> 	;    r2 - points to lowest priority queue 
  6969                              <1> 	;    p.dska - disk address of the process		
  6970                              <1> 	;    u.emt - determines handling of emt's 	
  6971                              <1> 	;    u.ilgins - determines handling of illegal instructions		
  6972                              <1> 	; OUTPUTS ->
  6973                              <1> 	;    r3 - process number of last process on the queue upon
  6974                              <1> 	;	  entering putlu
  6975                              <1> 	;    p.link-1 + r3 - process number in r1
  6976                              <1> 	;    r2 - points to lowest priority queue
  6977                              <1> 	;
  6978                              <1> 	; ((Modified registers: EDX, EBX)) 
  6979                              <1> 	;
  6980                              <1> 	; / r1 = user process no.; r2 points to lowest priority queue
  6981                              <1> 
  6982                              <1> 	; EBX = r2
  6983                              <1> 	; EAX = r1 (AL=r1b)
  6984                              <1> 
  6985                              <1> 	; 20/05/2016
  6986                              <1> 	; AL = process number (1 to 16) // Retro UNIX 8086, 386 v1 // 
  6987                              <1> 	;     (max. 16 processes available for current kernel version) 
  6988                              <1> 	; EBX = run queue address ; 20/05/2016 (TRDOS 386)
  6989                              <1> 		; which is one of following addresses:
  6990                              <1> 		;  1) 'runq_event' high priority run queue	 	
  6991                              <1> 		;  2) 'runq_normal' normal/regular priority run queue
  6992                              <1> 		;  3) 'runq_background' low priority run queue
  6993                              <1> 
  6994                              <1> 	;mov	ebx, runq
  6995 0000D889 0FB613              <1> 	movzx  	edx, byte [ebx]
  6996 0000D88C 43                  <1> 	inc	ebx
  6997 0000D88D 20D2                <1> 	and	dl, dl
  6998                              <1> 		; tstb (r2)+ / is queue empty?
  6999 0000D88F 740A                <1>        	jz	short putlu_1
  7000                              <1> 		; beq 1f / yes, branch
  7001 0000D891 8A13                <1> 	mov 	dl, [ebx] ; 12/09/2015
  7002                              <1> 		; movb (r2),r3 / no, save the "last user" process number
  7003                              <1> 			     ; / in r3
  7004 0000D893 8882[0B2E0100]      <1>        	mov	[edx+p.link-1], al
  7005                              <1> 		; movb r1,p.link-1(r3) / put pointer to user on 
  7006                              <1> 			     ; / "last users" link
  7007 0000D899 EB03                <1> 	jmp	short putlu_2
  7008                              <1> 		; br 2f /
  7009                              <1> putlu_1: ; 1:
  7010 0000D89B 8843FF              <1> 	mov	[ebx-1], al
  7011                              <1>        		; movb r1,-1(r2) / user is only user; 
  7012                              <1> 			    ; / put process no. at beginning and at end
  7013                              <1> putlu_2: ; 2: 
  7014 0000D89E 8803                <1> 	mov	[ebx], al
  7015                              <1>        		; movb r1,(r2) / user process in r1 is now the last entry
  7016                              <1> 			     ; / on the queue
  7017 0000D8A0 88C2                <1> 	mov	dl, al
  7018 0000D8A2 88B2[0B2E0100]      <1>         mov     [edx+p.link-1], dh ; 0
  7019                              <1> 		; dec r2 / restore r2
  7020 0000D8A8 C3                  <1>         retn
  7021                              <1> 		; rts r0
  7022                              <1> sysver:
  7023                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  7024 0000D8A9 C705[A8300100]0002- <1> 	mov	dword [u.r0], 200h ; AH = major version, AL = minor version 
  7024 0000D8B1 0000                <1>
  7025 0000D8B3 E98CDDFFFF          <1> 	jmp	sysret
  7026                              <1> 
  7027                              <1> sysreserved1:
  7028                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  7029                              <1> 	; // name and contect will be changed later //
  7030 0000D8B8 C705[A8300100]E007- <1> 	mov	dword [u.r0], 2016
  7030 0000D8C0 0000                <1>
  7031 0000D8C2 E97DDDFFFF          <1> 	jmp	sysret
  7032                              <1> 
  7033                              <1> syspri: ; change running priority (of the process)
  7034                              <1> 	; 21/05/2016
  7035                              <1> 	; 20/05/2026 - TRDOS 386 (TRDOS v2.0)
  7036                              <1> 	; INPUT ->
  7037                              <1> 	;	BL = priority level
  7038                              <1> 	;	   0 = low running priority (running on background)
  7039                              <1> 	;	   1 = normal/regular priority (running as regular)
  7040                              <1> 	;	   2 = high/event priority (running for event)
  7041                              <1> 	;	   >2 = invalid, it will accepted as 2 (event)
  7042                              <1> 	;	   0FFh = get/return current running priority only	
  7043                              <1> 	; OUTPUT -> 	
  7044                              <1> 	;	* if current [u.pri] < 2
  7045                              <1> 	;	  if BL input < 0FFh ->
  7046                              <1> 	;	     [u.pri] is updated as in BL input (0,1,2)
  7047                              <1> 	;	  if BL input = 0FFh -> AL = [u.pri] (current)
  7048                              <1> 	;	      
  7049                              <1> 	;	* if current [u.pri] = 2
  7050                              <1> 	;	  if BL input < 0FFh -> cf = 1 & AL = 2
  7051                              <1> 	;	  if BL input = 0FFh -> cf = 0 & AL = 2  
  7052                              <1> 	;	
  7053                              <1> 	;	NOTE: 	
  7054                              <1> 	;	If [u.pri] = 2, it can not be changed to 1 or 0;
  7055                              <1> 	;	because, run queue of the running process is unspecified
  7056                              <1> 	;	at this	stage. Process might be started by a timer event
  7057                              <1> 	;	or priority might be changed to high by previous
  7058                              <1> 	;	'syspri' system	call. In both cases, the process is in
  7059                              <1> 	;	'runq_normal' or 'runq_background' queue.
  7060                              <1> 	;	As result of this fact, when the [u.quant] time quantum
  7061                              <1> 	;	of the process is elapsed or 'sysrele' system call is
  7062                              <1> 	;	instructed by the process, 'tswap' ('tswitch') procedure
  7063                              <1> 	;	will be called (to 'swap' or 'switch' out the procedure)
  7064                              <1> 	;	and it will not call 'putlu' to add the (stopping)
  7065                              <1> 	;	process to relevant run queue when [u.pri] = 2.
  7066                              <1> 	;	(Otherwise, it would be possible to add process to
  7067                              <1> 	;	a run queue while it is already in a run queue, wrongly.)
  7068                              <1>   	;
  7069                              <1> 	;	If [u.pri]< 2, 'tswap/tswitch' procedure will call 
  7070                              <1> 	;	'putlu' to add process to relevant run queue
  7071                              <1> 	;	according to [u.pri] value. ('runq_normal' for 1, 
  7072                              <1> 	;	'runq_background' for 0).
  7073                              <1> 	;
  7074                              <1> 	;	If BL input >= 2 and < 0FFh while [u.pri] < 2,
  7075                              <1> 	;	process will be added to 'runq_normal' queue and
  7076                              <1> 	;	[u.pri] will be set to 2. (in 'syspri' system call)
  7077                              <1> 	;
  7078                              <1> 
  7079 0000D8C7 29C0                <1> 	sub	eax, eax ; 0
  7080 0000D8C9 A3[FD300100]        <1> 	mov	[u.error], eax
  7081                              <1> 
  7082 0000D8CE A0[EB300100]        <1> 	mov	al, [u.pri]
  7083 0000D8D3 A3[A8300100]        <1> 	mov	[u.r0], eax
  7084                              <1> 
  7085 0000D8D8 FEC3                <1> 	inc	bl
  7086 0000D8DA 0F8464DDFFFF        <1> 	jz	sysret ; 0FFh -> 0, get priority level
  7087                              <1> 	
  7088 0000D8E0 3C02                <1> 	cmp	al, 2
  7089 0000D8E2 0F833CDDFFFF        <1> 	jnb	error ; CF = 1 & AL = 2 (& last error = 0)
  7090                              <1> 
  7091 0000D8E8 FECB                <1> 	dec	bl
  7092 0000D8EA 80FB02              <1> 	cmp	bl, 2
  7093 0000D8ED 7602                <1> 	jna	short syspri_1
  7094 0000D8EF B302                <1> 	mov	bl, 2
  7095                              <1> syspri_1:
  7096 0000D8F1 881D[EB300100]      <1> 	mov	[u.pri], bl
  7097 0000D8F7 80FB02              <1> 	cmp	bl, 2
  7098 0000D8FA 0F8244DDFFFF        <1>         jb      sysret
  7099                              <1> 
  7100                              <1> 	; here...
  7101                              <1> 	; Priority of current process has been changed to high
  7102                              <1> 	; ('run for event') but current process will be added to
  7103                              <1> 	; 'run as normal' queue. ('run for event' high priority
  7104                              <1> 	; queue is under control of timer -& RTC- interrupt only!) 
  7105                              <1> 	;
  7106                              <1> 	; (Otherwise, process can fall into black hole!
  7107                              <1> 	; e.g. if it is not in waiting list and it has not got 
  7108                              <1> 	; a timer event and it is not in a run queue!
  7109                              <1> 	; Because, when [u.pri] is 2, 'tswap/tswitch' will not 
  7110                              <1> 	; add the stopping process to a run queue.)
  7111                              <1> 
  7112 0000D900 A0[F7300100]        <1> 	mov	al, [u.uno]
  7113 0000D905 BB[98300100]        <1> 	mov	ebx, runq_normal ; normal priority !
  7114                              <1> 				 ; [u.pri] is set to high
  7115                              <1> 				 ; but 'runq_event' queue is set
  7116                              <1> 				 ; only by the kernel's timer
  7117                              <1> 				 ; event function (timer interrupt). 
  7118 0000D90A E87AFFFFFF          <1> 	call	putlu
  7119 0000D90F E930DDFFFF          <1> 	jmp	sysret
  7120                              <1> 
  7121                              <1> cpass: ; / get next character from user area of core and put it in AL (r1)
  7122                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
  7123                              <1> 	; 19/05/2015 - 18/10/2015 (Retro UNIX 386 v1)
  7124                              <1> 	; 14/08/2013 - 20/09/2013 (Retro UNIX 8086 v1)
  7125                              <1> 	; INPUTS -> 
  7126                              <1> 	;     [u.base] = virtual address in user area
  7127                              <1> 	;     [u.count] = byte count (max.)
  7128                              <1> 	;     [u.pcount] = byte count in page (0 = reset)		
  7129                              <1> 	; OUTPUTS -> 
  7130                              <1> 	;     AL = the character which is pointed by [u.base]
  7131                              <1> 	;     zf = 1 -> transfer count has been completed	
  7132                              <1>         ;
  7133                              <1> 	; ((Modified registers:  EAX, EDX, ECX))
  7134                              <1> 	;
  7135 0000D914 833D[CC300100]00    <1> 	cmp 	dword [u.count], 0  ; have all the characters been transferred
  7136                              <1> 			    	    ; i.e., u.count, # of chars. left
  7137 0000D91B 763F                <1> 	jna	short cpass_3	    ; to be transferred = 0?) yes, branch
  7138 0000D91D FF0D[CC300100]      <1> 	dec	dword [u.count]	    ; no, decrement u.count
  7139                              <1>         ; 19/05/2015 
  7140                              <1> 	;(Retro UNIX 386 v1 - translation from user's virtual address
  7141                              <1> 	;		      to physical address
  7142 0000D923 66833D[0D310100]00  <1> 	cmp	word [u.pcount], 0 ; byte count in page = 0 (initial value)
  7143                              <1> 			     ; 1-4095 --> use previous physical base address
  7144                              <1> 			     ; in [u.pbase]
  7145 0000D92B 770E                <1> 	ja	short cpass_1
  7146 0000D92D 833D[05310100]00    <1> 	cmp     dword [u.ppgdir], 0  ; is the caller os kernel
  7147 0000D934 7427                <1>         je      short cpass_k       ; (sysexec, '/etc/init') ?  (MainProg)
  7148 0000D936 E858FDFFFF          <1> 	call	trans_addr_r
  7149                              <1> cpass_1:
  7150 0000D93B 66FF0D[0D310100]    <1> 	dec	word [u.pcount]
  7151                              <1> cpass_2: 
  7152 0000D942 8B15[09310100]      <1> 	mov	edx, [u.pbase]
  7153 0000D948 8A02                <1> 	mov	al, [edx]	; take the character pointed to 
  7154                              <1> 				; by u.base and put it in r1
  7155 0000D94A FF05[D0300100]      <1> 	inc	dword [u.nread] ; increment no. of bytes transferred
  7156 0000D950 FF05[C8300100]      <1> 	inc	dword [u.base]  ; increment the buffer address to point to the
  7157                              <1> 			        ; next byte
  7158 0000D956 FF05[09310100]      <1> 	inc	dword [u.pbase]
  7159                              <1> cpass_3:
  7160 0000D95C C3                  <1> 	retn
  7161                              <1> cpass_k:
  7162                              <1> 	; 02/07/2015
  7163                              <1> 	; The caller is os kernel 
  7164                              <1> 	; (get sysexec arguments from kernel's memory space)
  7165 0000D95D 8B1D[C8300100]      <1> 	mov	ebx, [u.base]
  7166 0000D963 66C705[0D310100]00- <1>         mov     word [u.pcount], PAGE_SIZE ; 4096
  7166 0000D96B 10                  <1>
  7167 0000D96C 891D[09310100]      <1> 	mov	[u.pbase], ebx
  7168 0000D972 EBCE                <1> 	jmp	short cpass_2
  7169                              <1> 
  7170                              <1> transfer_to_user_buffer: ; fast transfer
  7171                              <1> 	; 27/05/2016
  7172                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  7173                              <1> 	;
  7174                              <1> 	; INPUT ->
  7175                              <1> 	;	ESI = source address in system space
  7176                              <1> 	;	EDI = user's buffer address
  7177                              <1> 	;	ECX = transfer (byte) count
  7178                              <1> 	;	[u.pgdir] = user's page directory
  7179                              <1> 	; OUTPUT ->
  7180                              <1> 	;	ecx = actual transfer count
  7181                              <1> 	;	cf = 1 -> error
  7182                              <1> 	;	[u.count] = remain byte count
  7183                              <1> 	;
  7184                              <1> 	; Modified registers: eax, ecx
  7185                              <1> 	;
  7186                              <1> 
  7187 0000D974 21C9                <1> 	and	ecx, ecx
  7188 0000D976 743B                <1> 	jz	short ttub_4
  7189                              <1> 
  7190 0000D978 890D[CC300100]      <1> 	mov	[u.count], ecx
  7191                              <1> 	
  7192 0000D97E 57                  <1> 	push	edi
  7193 0000D97F 56                  <1> 	push	esi
  7194 0000D980 53                  <1> 	push	ebx
  7195 0000D981 52                  <1> 	push	edx
  7196 0000D982 51                  <1> 	push	ecx
  7197                              <1> 
  7198 0000D983 89FB                <1> 	mov	ebx, edi
  7199 0000D985 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
  7200                              <1> ttub_1:
  7201                              <1> 	; ebx = virtual (linear) address
  7202                              <1> 	; [u.pgdir] = user's page directory
  7203 0000D98B E87473FFFF          <1>        	call	get_physical_addr_x ; get physical address
  7204 0000D990 7222                <1> 	jc	short ttub_5
  7205                              <1> 	; eax = physical address 
  7206                              <1> 	; ecx = remain byte count in page (1-4096)
  7207 0000D992 89C7                <1> 	mov	edi, eax
  7208 0000D994 A1[CC300100]        <1> 	mov	eax, [u.count]
  7209 0000D999 39C1                <1> 	cmp	ecx, eax
  7210 0000D99B 7602                <1> 	jna	short ttub_2
  7211 0000D99D 89C1                <1> 	mov	ecx, eax
  7212                              <1> ttub_2:	
  7213 0000D99F 29C8                <1> 	sub	eax, ecx
  7214 0000D9A1 01CB                <1> 	add	ebx, ecx
  7215 0000D9A3 F3A4                <1> 	rep	movsb
  7216 0000D9A5 A3[CC300100]        <1> 	mov	[u.count], eax
  7217 0000D9AA 09C0                <1> 	or	eax, eax
  7218 0000D9AC 75DD                <1> 	jnz	short ttub_1
  7219                              <1> ttub_retn:
  7220                              <1> tfub_retn:
  7221 0000D9AE 59                  <1> 	pop	ecx ; transfer count = actual transfer count
  7222                              <1> ttub_3:
  7223 0000D9AF 5A                  <1> 	pop	edx
  7224 0000D9B0 5B                  <1> 	pop	ebx
  7225 0000D9B1 5E                  <1> 	pop	esi
  7226 0000D9B2 5F                  <1> 	pop	edi
  7227                              <1> ttub_4:
  7228 0000D9B3 C3                  <1> 	retn
  7229                              <1> ttub_5:
  7230 0000D9B4 59                  <1> 	pop	ecx
  7231 0000D9B5 2B0D[CC300100]      <1> 	sub	ecx, [u.count] ; actual transfer count
  7232 0000D9BB F9                  <1> 	stc
  7233 0000D9BC EBF1                <1> 	jmp	short ttub_3
  7234                              <1> 
  7235                              <1> transfer_from_user_buffer: ; fast transfer
  7236                              <1> 	; 27/05/2016
  7237                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  7238                              <1> 	;
  7239                              <1> 	; INPUT ->
  7240                              <1> 	;	ESI = user's buffer address
  7241                              <1> 	;	EDI = destination address in system space
  7242                              <1> 	;	ECX = transfer (byte) count
  7243                              <1> 	;	[u.pgdir] = user's page directory
  7244                              <1> 	; OUTPUT ->
  7245                              <1> 	;	ecx = actual transfer count
  7246                              <1> 	;	cf = 1 -> error
  7247                              <1> 	;	[u.count] = remain byte count
  7248                              <1> 	;
  7249                              <1> 	; Modified registers: eax, ecx
  7250                              <1> 	;
  7251                              <1> 
  7252 0000D9BE 21C9                <1> 	and	ecx, ecx
  7253                              <1> 	;jz	short tfub_4
  7254 0000D9C0 74F1                <1> 	jz	short ttub_4
  7255                              <1> 
  7256 0000D9C2 890D[CC300100]      <1> 	mov	[u.count], ecx
  7257                              <1> 	
  7258 0000D9C8 57                  <1> 	push	edi
  7259 0000D9C9 56                  <1> 	push	esi
  7260 0000D9CA 53                  <1> 	push	ebx
  7261 0000D9CB 52                  <1> 	push	edx
  7262 0000D9CC 51                  <1> 	push	ecx
  7263                              <1> 
  7264 0000D9CD 89F3                <1> 	mov	ebx, esi
  7265 0000D9CF 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
  7266                              <1> tfub_1:
  7267                              <1> 	; ebx = virtual (linear) address
  7268                              <1> 	; [u.pgdir] = user's page directory
  7269 0000D9D5 E82A73FFFF          <1>        	call	get_physical_addr_x ; get physical address
  7270                              <1> 	;jc	short tfub_5
  7271 0000D9DA 72D8                <1> 	jc	short ttub_5
  7272                              <1> 	; eax = physical address 
  7273                              <1> 	; ecx = remain byte count in page (1-4096)
  7274 0000D9DC 89C6                <1> 	mov	esi, eax
  7275 0000D9DE A1[CC300100]        <1> 	mov	eax, [u.count]
  7276 0000D9E3 39C1                <1> 	cmp	ecx, eax
  7277 0000D9E5 7602                <1> 	jna	short tfub_2
  7278 0000D9E7 89C1                <1> 	mov	ecx, eax
  7279                              <1> tfub_2:	
  7280 0000D9E9 29C8                <1> 	sub	eax, ecx
  7281 0000D9EB 01CB                <1> 	add	ebx, ecx
  7282 0000D9ED F3A4                <1> 	rep	movsb
  7283 0000D9EF A3[CC300100]        <1> 	mov	[u.count], eax
  7284 0000D9F4 09C0                <1> 	or	eax, eax
  7285 0000D9F6 75DD                <1> 	jnz	short tfub_1
  7286                              <1> 
  7287 0000D9F8 EBB4                <1> 	jmp	short tfub_retn
  7288                              <1> 
  7289                              <1> ;tfub_retn:
  7290                              <1> ;	pop	ecx ; transfer count = actual transfer count
  7291                              <1> ;tfub_3:
  7292                              <1> ;	pop	edx
  7293                              <1> ;	pop	ebx
  7294                              <1> ;	pop	esi
  7295                              <1> ;	pop	edi
  7296                              <1> ;tfub_4:
  7297                              <1> ;	retn
  7298                              <1> ;tfub_5:
  7299                              <1> ;	pop	ecx
  7300                              <1> ;	sub	ecx, [u.count] ; actual transfer count
  7301                              <1> ;	stc
  7302                              <1> ;	jmp	short tfub_3
  7303                              <1> 	
  7304                              <1> ; temporary - 24/01/2016
  7305                              <1> 
  7306                              <1> iget:
  7307 0000D9FA C3                  <1> 	retn
  7308                              <1> poke:
  7309 0000D9FB C3                  <1> 	retn
  7310                              <1> isintr:
  7311 0000D9FC C3                  <1> 	retn
  7312                              <1> writei:
  7313 0000D9FD C3                  <1> 	retn
  7314                              <1> iopen:
  7315 0000D9FE C3                  <1> 	retn
  7316                              <1> iclose:
  7317 0000D9FF C3                  <1> 	retn
  7318                              <1> itrunc:
  7319 0000DA00 C3                  <1> 	retn
  7320                              <1> setimod:
  7321 0000DA01 C3                  <1> 	retn
  7322                              <1> ottyp:
  7323 0000DA02 C3                  <1> 	retn
  7324                              <1> cttyp:
  7325 0000DA03 C3                  <1> 	retn
  7326                              <1> sndc:
  7327 0000DA04 C3                  <1> 	retn
  7328                              <1> access:
  7329 0000DA05 C3                  <1> 	retn
  7330                              <1> passc:
  7331 0000DA06 C3                  <1> 	retn
  7332                              <1> epoch:
  7333 0000DA07 C3                  <1> 	retn
  7334                              <1> set_date_time:
  7335 0000DA08 C3                  <1> 	retn
  7336                              <1> imap:
  7337 0000DA09 C3                  <1> 	retn
  7338                              <1> diskio:
  7339 0000DA0A C3                  <1> 	retn
  7340                              <1> idle:
  7341 0000DA0B C3                  <1> 	retn
  7342                              <1> sleep:
  7343 0000DA0C C3                  <1> 	retn
  1924                                  %include 'trdosk7.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DISK READ&WRITE : trdosk7.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 25/02/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; DISK_IO.ASM (20/07/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; DISK_IO.ASM (c) 2009-2011 Erdogan TAN [ 04/07/2009 ] Last Update: 20/07/2011
    14                              <1> 
    15                              <1> disk_write:
    16                              <1> 	; 25/02/2016
    17                              <1> 	; 24/02/2016
    18                              <1> 	; 23/02/2016
    19 0000DA0D 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    20 0000DA11 777B                <1>         ja      short lba_write
    21                              <1> 
    22                              <1> chs_write:
    23                              <1> 	; 25/02/2016
    24                              <1> 	; 23/02/2016
    25 0000DA13 C605[81290100]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
    26 0000DA1A EB0D                <1> 	jmp	short chs_rw
    27                              <1> 
    28                              <1> disk_read:
    29                              <1> 	; 25/02/2016
    30                              <1> 	; 24/02/2016
    31                              <1> 	; 23/02/2016
    32                              <1> 	; 17/02/2016
    33                              <1> 	; 14/02/2016
    34                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
    35                              <1> 	; 17/10/2010
    36                              <1> 	; 18/04/2010
    37                              <1> 	;
    38                              <1> 	; INPUT -> EAX = Logical Block Address
    39                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
    40                              <1> 	;	   ECX = Sector Count	
    41                              <1> 	; 	   EBX = Destination Buffer
    42                              <1> 	; OUTPUT -> 
    43                              <1> 	;	   cf = 0 or cf = 1
    44                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
    45                              <1> 
    46 0000DA1C 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    47 0000DA20 7775                <1>         ja      short lba_read
    48                              <1> 
    49                              <1> chs_read:
    50                              <1> 	; 25/02/2016
    51                              <1> 	; 24/02/2016
    52                              <1> 	; 23/02/2016
    53                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
    54                              <1> 	; 20/07/2011
    55                              <1> 	; 04/07/2009
    56                              <1> 	;
    57                              <1> 	; INPUT -> EAX = Logical Block Address
    58                              <1> 	;	   ECX = Number of sectors to read
    59                              <1> 	; 	   ESI = Logical Dos Disk Table Offset (DRV)
    60                              <1> 	; 	   EBX = Destination Buffer
    61                              <1> 	; OUTPUT -> 
    62                              <1> 	;	   cf = 0 or cf = 1
    63                              <1> 	; (Modified registers: EAX; EBX, ECX, EDX)
    64                              <1> 
    65                              <1> 	; 23/02/2016
    66 0000DA22 C605[81290100]02    <1> 	mov	byte [disk_rw_op], 2 ; CHS read
    67                              <1> 
    68                              <1> chs_rw:
    69                              <1> 	;;movzx	edx, word [esi+LD_BPB+SecPerTrack]
    70                              <1> 	;movzx	edx, byte [esi+LD_BPB+SecPerTrack] ; <= 63
    71                              <1> 	;mov	[disk_rw_spt], dl
    72                              <1> 
    73                              <1> chs_read_next_sector:
    74 0000DA29 C605[82290100]04    <1> 	mov	byte [retry_count], 4
    75                              <1>      
    76                              <1> chs_read_retry:
    77                              <1> 	;mov	[sector_count], ecx ; 23/02/2016
    78                              <1> 
    79 0000DA30 50                  <1> 	push	eax			; Linear sector #
    80 0000DA31 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
    81                              <1>                 
    82 0000DA32 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
    83                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
    84 0000DA36 29D2                <1> 	sub	edx, edx
    85 0000DA38 F7F1                <1> 	div	ecx
    86                              <1> 	; eax = track, dx (dl ) = sector (on track)
    87                              <1> 	;sub	cl, dl ; 24/02/2016 (spt - sec)
    88                              <1> 	;push	ecx ; *
    89 0000DA3A 6689D1              <1> 	mov	cx, dx			; Sector (zero based)
    90 0000DA3D 6641                <1> 	inc	cx			; To make it 1 based
    91 0000DA3F 6651                <1> 	push	cx
    92 0000DA41 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
    93 0000DA45 6629D2              <1> 	sub	dx, dx
    94 0000DA48 F7F1                <1> 	div	ecx			; Convert track to head & cyl
    95                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
    96 0000DA4A 88D6                <1> 	mov	dh, dl
    97 0000DA4C 6659                <1> 	pop	cx			; AX=Cyl, DH=Head, CX=Sector
    98 0000DA4E 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
    99                              <1> 
   100 0000DA51 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !                   
   101 0000DA53 C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
   102 0000DA56 08E1                <1> 	or	cl, ah
   103                              <1> 
   104                              <1> 	; 24/02/2016
   105                              <1> 	;pop	eax ; * (spt - sec) (example: 63 - 0 = 63)
   106                              <1> 	;cmp	eax, [sector_count]
   107                              <1> 	;jb	short chs_write_sectors
   108                              <1> 	;je	short chs_read_sectors
   109                              <1> 	;; (# of sectors to read is more than remaining sectors on the track)
   110                              <1> 	;mov	al, [sector_count]
   111                              <1> ;chs_read_sectors: ; read or write !
   112 0000DA58 B001                <1> 	mov	al, 1 ; 25/02/2016
   113 0000DA5A 8A25[81290100]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
   114                              <1> 	;
   115 0000DA60 E81062FFFF          <1> 	call	int13h			; BIOS Service func ( ah ) = 2
   116                              <1>                                         ; Read disk sectors
   117                              <1>                                         ; AL-sec num CH-track CL-sec
   118                              <1>                                         ; DH-head DL-drive ES:BX-buffer
   119                              <1>                                         ; CF-flag AH-stat AL-sec read
   120                              <1> 	                                ; If CF = 1 then (If AH > 0)
   121 0000DA65 8825[83290100]      <1> 	mov	[disk_rw_err], ah
   122                              <1> 	
   123 0000DA6B 59                  <1> 	pop	ecx
   124 0000DA6C 58                  <1> 	pop	eax
   125 0000DA6D 7314                <1> 	jnc	short chs_read_ok
   126                              <1> 
   127 0000DA6F 803D[83290100]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
   128 0000DA76 7408                <1> 	je	short chs_read_error_retn
   129                              <1>              
   130 0000DA78 FE0D[82290100]      <1> 	dec	byte [retry_count]
   131 0000DA7E 75B0                <1> 	jnz	short chs_read_retry
   132                              <1> 
   133                              <1> chs_read_error_retn:
   134 0000DA80 F9                  <1> 	stc
   135                              <1> 	;retn
   136 0000DA81 EB69                <1> 	jmp	short update_drv_error_byte
   137                              <1> 
   138                              <1> ;chs_write_sectors: ; read or write 
   139                              <1> 	;; (# of sectors to read is less than remaining sectors on the track)
   140                              <1> 	;mov	[sector_count], al
   141                              <1> 	;jmp	short chs_read_sectors
   142                              <1> 
   143                              <1> chs_read_ok:
   144                              <1> 	;; 23/02/2016
   145                              <1> 	;movzx	edx, byte [sector_count] ; sector count (<= spt)	
   146                              <1>         ;sub    ecx, edx  ; remaining sector count
   147                              <1> 	;jna	short update_drv_error_byte	
   148                              <1> 	;add	eax, edx ; next disk sector
   149                              <1> 	;shl	edx, 9 ; 512 * sector count
   150                              <1> 	;add	ebx, edx ; next buffer byte address 
   151                              <1>         ;jmp     chs_read_next_sector        
   152                              <1> 	; 25/02/2016
   153 0000DA83 40                  <1> 	inc	eax ; next sector
   154 0000DA84 81C300020000        <1> 	add	ebx, 512
   155 0000DA8A E29D                <1> 	loop	chs_read_next_sector
   156 0000DA8C EB5E                <1> 	jmp	short update_drv_error_byte
   157                              <1> 
   158                              <1> lba_write:
   159                              <1> 	; 23/02/2016
   160 0000DA8E C605[81290100]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
   161 0000DA95 EB07                <1> 	jmp	short lba_rw
   162                              <1> 
   163                              <1> lba_read:
   164                              <1> 	; 23/02/2016
   165                              <1> 	; 17/02/2016
   166                              <1> 	; 14/02/2016
   167                              <1> 	; 13/02/2016
   168                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
   169                              <1> 	; 10/07/2015 (Retro UNIX 386 v1)
   170                              <1> 	;
   171                              <1> 	; INPUT -> EAX = Logical Block Address
   172                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
   173                              <1> 	;	   ECX = Sector Count	
   174                              <1> 	; 	   EBX = Destination Buffer
   175                              <1> 	; OUTPUT -> 
   176                              <1> 	;	   cf = 0 or cf = 1
   177                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
   178                              <1> 
   179                              <1> 	; LBA read/write (with private LBA function) 
   180                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   181                              <1> 
   182                              <1> 
   183                              <1> 	; 23/02/2016
   184 0000DA97 C605[81290100]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
   185                              <1> 
   186                              <1> lba_rw:
   187                              <1> 	; 17/02/2016
   188 0000DA9E 57                  <1> 	push	edi
   189                              <1> 
   190 0000DA9F 890D[84290100]      <1> 	mov	[sector_count], ecx ; total sector (read) count
   191                              <1> 
   192 0000DAA5 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
   193                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   194                              <1> 
   195                              <1> lba_read_next:
   196 0000DAA8 81F900010000        <1> 	cmp	ecx, 256
   197 0000DAAE 7605                <1> 	jna	short lba_read_rsc
   198 0000DAB0 B900010000          <1> 	mov	ecx, 256 ; 17/02/2016
   199                              <1> lba_read_rsc:
   200 0000DAB5 290D[84290100]      <1> 	sub	[sector_count], ecx ; remain sectors
   201                              <1> 
   202 0000DABB 89CF                <1> 	mov	edi, ecx 
   203 0000DABD 89C1                <1> 	mov	ecx, eax ; sector number/address
   204                              <1> 
   205 0000DABF C605[82290100]04    <1> 	mov	byte [retry_count], 4
   206                              <1> lba_read_retry:
   207 0000DAC6 89F8                <1> 	mov	eax, edi
   208                              <1> 	;
   209                              <1> 	; ecx = sector number
   210                              <1> 	; al = sector count (0 - 255) /// (0 = 256)
   211                              <1> 	; dl = drive number
   212                              <1> 	; ebx = buffer offset
   213                              <1> 	;
   214                              <1> 	; Function 1Bh = LBA read, 1Ch = LBA write
   215                              <1> 	; 23/02/2016
   216 0000DAC8 8A25[81290100]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
   217 0000DACE E8A261FFFF          <1> 	call	int13h
   218                              <1> 	; al = ? (changed)
   219                              <1> 	; ah = error code
   220 0000DAD3 8825[83290100]      <1> 	mov	[disk_rw_err], ah
   221 0000DAD9 7334                <1> 	jnc	short lba_read_ok
   222 0000DADB 80FC80              <1> 	cmp	ah, 80h ; time out?
   223 0000DADE 740A                <1>         je      short lba_read_stc_retn
   224 0000DAE0 FE0D[82290100]      <1> 	dec	byte [retry_count]
   225 0000DAE6 7FDE                <1> 	jg	short lba_read_retry
   226 0000DAE8 743A                <1> 	jz	short lba_read_reset
   227                              <1> 	; sf =  1
   228                              <1> 
   229                              <1> lba_read_stc_retn:
   230 0000DAEA F9                  <1> 	stc
   231                              <1> lba_read_retn:
   232 0000DAEB 5F                  <1> 	pop	edi
   233                              <1> 
   234                              <1> update_drv_error_byte:
   235 0000DAEC 9C                  <1> 	pushf
   236 0000DAED 53                  <1> 	push	ebx
   237 0000DAEE 6651                <1> 	push	cx
   238                              <1> 	;or	ecx, ecx
   239                              <1> 	;jz	short udrv_errb0
   240 0000DAF0 8A0D[83290100]      <1> 	mov	cl, [disk_rw_err]
   241                              <1> udrv_errb0:
   242 0000DAF6 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
   243 0000DAFA 80FB02              <1> 	cmp	bl, 2
   244 0000DAFD 7203                <1>         jb      short udrv_errb1
   245 0000DAFF 80EB7E              <1> 	sub	bl, 7Eh
   246                              <1> 	;cmp	bl, 5
   247                              <1> 	;ja	short udrv_errb2	
   248                              <1> udrv_errb1:
   249 0000DB02 81C3[6BED0000]      <1>         add     ebx, drv.error ; 13/02/2016
   250 0000DB08 880B                <1> 	mov	[ebx], cl ; error code
   251                              <1> udrv_errb2:
   252 0000DB0A 6659                <1> 	pop	cx
   253 0000DB0C 5B                  <1> 	pop	ebx
   254 0000DB0D 9D                  <1> 	popf
   255 0000DB0E C3                  <1> 	retn
   256                              <1> 
   257                              <1> lba_read_ok:
   258 0000DB0F 89C8                <1> 	mov	eax, ecx ; sector number
   259 0000DB11 01F8                <1> 	add	eax, edi ; sector number (next)
   260 0000DB13 C1E709              <1> 	shl	edi, 9 ; sector count * 512
   261 0000DB16 01FB                <1> 	add	ebx, edi ; next buffer offset
   262                              <1> 
   263 0000DB18 8B0D[84290100]      <1> 	mov	ecx, [sector_count] ; remaining sectors
   264 0000DB1E 09C9                <1> 	or	ecx, ecx
   265 0000DB20 7586                <1> 	jnz	short lba_read_next
   266 0000DB22 EBC7                <1> 	jmp	short lba_read_retn
   267                              <1> 
   268                              <1> lba_read_reset:
   269 0000DB24 B40D                <1> 	mov	ah, 0Dh ; Alternate reset
   270 0000DB26 E84A61FFFF          <1>         call	int13h
   271                              <1> 	; al = ? (changed)
   272                              <1> 	; ah = error code
   273 0000DB2B 7399                <1> 	jnc	short lba_read_retry
   274 0000DB2D EBBC                <1> 	jmp	short lba_read_retn
  1925                                  %include 'trdosk8.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk8.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/06/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    11                              <1> ; u0.s (20/11/2015), u4.s (14/10/2015)
    12                              <1> ; ****************************************************************************
    13                              <1> 
    14                              <1> set_run_sequence:
    15                              <1> 	; 10/06/2016
    16                              <1> 	; 22/05/2016
    17                              <1> 	; 20/05/2016
    18                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    19                              <1> 	; TRDOS 386 feature only !
    20                              <1> 	;
    21                              <1> 	; INPUT ->
    22                              <1> 	;	AL = process number (next process)
    23                              <1> 	;
    24                              <1> 	;	this process must be added to run sequence
    25                              <1> 	;
    26                              <1> 	;	[u.pri] = priority of present process
    27                              <1> 	;
    28                              <1> 	;	DL = priority (queue)
    29                              <1> 	;	     0 = background (low) ; run on background 
    30                              <1> 	;	     1 = regular (normal) ; run as regular
    31                              <1> 	;	     2 = event (high)     ; run for event
    32                              <1> 	;
    33                              <1> 	;	1) If the requested process is already running:
    34                              <1> 	;	   a) If present priority is high ([u.pri]=2) 
    35                              <1> 	;	      and requested priority is also high, 
    36                              <1> 	;	      there is nothing to do! Because it has been
    37                              <1> 	;	      done already (before this attempt).		 	
    38                              <1> 	;	   b) If present priority is high ([u.pri]=2)
    39                              <1> 	;	      and requested priority is not high, there is
    40                              <1> 	;	      nothing to do! Because, it's current
    41                              <1> 	;	      run queue is unspecified, here. (It may be in
    42                              <1> 	;	      a waiting list or in a run queue; if the new
    43                              <1> 	;	      priority would be used to add it to relavant
    44                              <1>         ;             run queue, this would be wrong, unnecessary
    45                              <1> 	;	      and destabilizing duplication!)
    46                              <1> 	;	   c) If present priority is not high ([u.pri]<2)
    47                              <1>         ;             and requested priority is high (event),
    48                              <1> 	;	      process will be added to present priority's
    49                              <1> 	;	      run queue and then, priority will be changed
    50                              <1> 	;	      to high ([u.pri]=2).
    51                              <1> 	;	   d) If present priority is not high ([u.pri]<2)
    52                              <1> 	;	      and requested priority is not high, [u.pri]
    53                              <1> 	;	      value will be changed. There is nothing to do
    54                              <1> 	;	      in addition. (The new priority value will be
    55                              <1> 	;	      used by 'tswap/tswitch' procedure at 'sysret'
    56                              <1> 	;	      or 'sysrele' stage.)
    57                              <1> 	;
    58                              <1> 	;	2) If the requested process is not running:
    59                              <1> 	;	   a) If requested priority of the requested
    60                              <1> 	;	      (next) process is high (event) and priority
    61                              <1> 	;	      of present process is not high, the requested
    62                              <1> 	;	      process will be added to ('runq_event') high
    63                              <1> 	;	      priority run queue and then present (running)
    64                              <1> 	;	      process will be stopped (swapped/switched out)
    65                              <1> 	;	      immediately if it is in user mode, or it's 
    66                              <1> 	;	      [u.quant] value will be reset to 0 and (then) 
    67                              <1> 	;	      it will be stopped at 'sysret' stage.			
    68                              <1> 	;	   b) If requested priority of the requested
    69                              <1> 	;	      (next) process is high (event) and priority
    70                              <1> 	;	      of present process is also high, the requested
    71                              <1> 	;	      process will be added to ('runq_event') high
    72                              <1> 	;	      priority run queue and present (running) 
    73                              <1> 	;	      process will be allowed to run until it's 
    74                              <1> 	;	      time quantum will be elapsed ([u.quant]=0).	
    75                              <1> 	;	   c) If requested priority of the requested
    76                              <1> 	;	      (next) process is not high ('run for event'), 
    77                              <1> 	;	      there is nothing to do. Because, it's current
    78                              <1> 	;	      run queue is unspecified, here. (It may be in
    79                              <1> 	;	      a waiting list or in a run queue; if the new
    80                              <1> 	;	      priority would be used to add it to relavant
    81                              <1>         ;             run queue, this would be wrong, unnecessary
    82                              <1> 	;	      and destabilizing duplication!) 
    83                              <1> 	;
    84                              <1> 	; OUTPUT ->
    85                              <1> 	;	none
    86                              <1> 	;
    87                              <1> 	;	[u.pri] = priority of present process
    88                              <1> 	;
    89                              <1> 	;	cf = 1, if the request could not be fulfilled.
    90                              <1> 	;			 	     	  
    91                              <1> 	;	NOTE: 
    92                              <1>         ;          * Processes in 'run as regular' queue can run
    93                              <1> 	;	     if there is no process in 'run for event' queue
    94                              <1> 	;	     ('run for event' processes have higher priority)	 		 
    95                              <1> 	;	   * When [u.quant] time quantum of a process is
    96                              <1> 	;	     elapsed, it's high priority ('run for event')
    97                              <1> 	;	     status will be disabled, it can be run in sequence
    98                              <1> 	;	     of it's actual run queue.
    99                              <1> 	;	   * A 'run on background' process will always be 
   100                              <1> 	;	     sequenced in 'run on background' (low priority)
   101                              <1> 	;	     queue, it can run only when other priority queues
   102                              <1> 	;	     are empty. (idle time processes, e.g. printing)  	 	
   103                              <1> 	;
   104                              <1> 	; Modified registers: eax, ebx, edx, edi
   105                              <1> 	;
   106                              <1> 
   107                              <1> srunseq_0:
   108 0000DB2F 89C3                <1> 	mov	ebx, eax
   109 0000DB31 31C0                <1> 	xor	eax, eax
   110 0000DB33 BF[8C2D0100]        <1> 	mov	edi, p.pid
   111                              <1> srunseq_1:
   112 0000DB38 3A05[F7300100]      <1>         cmp     al, [u.uno]     ; same process ?
   113 0000DB3E 7514                <1> 	jne	short srunseq_4 ; no
   114                              <1> 
   115 0000DB40 8A25[EB300100]      <1> 	mov	ah, [u.pri] 	; present/current priority
   116 0000DB46 80FC02              <1> 	cmp	ah, 2       	; 'run for event' priority level
   117 0000DB49 7229                <1> 	jb	short srunseq_8 ; no
   118                              <1> 
   119                              <1> srunseq_2:
   120                              <1> 	; there is nothing to do!
   121 0000DB4B C3                  <1> 	retn
   122                              <1> 
   123                              <1> srunseq_3:
   124 0000DB4C 3C10                <1>         cmp     al, nproc       ; number of processes = 16 
   125 0000DB4E 7322                <1> 	jnb	short srunseq_7 ; 'p.pid' values do not match !!!???
   126                              <1> 
   127 0000DB50 47                  <1> 	inc	edi
   128 0000DB51 47                  <1> 	inc	edi
   129 0000DB52 EBE4                <1> 	jmp	short srunseq_1
   130                              <1> 
   131                              <1> srunseq_4:
   132                              <1> 	; dl = priority
   133 0000DB54 80FA02              <1> 	cmp	dl, 2 		; event queue
   134 0000DB57 72F2                <1> 	jb	short srunseq_2 ; requested process is not present
   135                              <1> 				; process and priority of requested
   136                              <1> 				; process is not high (event), 
   137                              <1> 				; there is nothing to do!
   138                              <1> 	
   139                              <1> 	; requested process is not present process
   140                              <1> 	; & priority of requested process is high
   141 0000DB59 3A15[EB300100]      <1> 	cmp	dl, [u.pri] 	; priority of present process
   142 0000DB5F 7606                <1> 	jna	short srunseq_5 ; is high, also
   143                              <1> 	;
   144                              <1> 	; present process will be swapped/switched out
   145 0000DB61 FE05[4D2D0100]      <1> 	inc	byte [p_change] ; 1
   146                              <1> 
   147                              <1> srunseq_5:
   148                              <1> 	; add process to 'runq_event' queue for new event
   149 0000DB67 BB[96300100]        <1> 	mov	ebx, runq_event ; high priority run queue
   150                              <1> 
   151                              <1> srunseq_6:
   152                              <1> 	; al = process number
   153                              <1> 	; ebx = run queue
   154 0000DB6C E818FDFFFF          <1> 	call	putlu
   155 0000DB71 C3                  <1> 	retn
   156                              <1> 
   157                              <1> srunseq_7:
   158 0000DB72 F5                  <1> 	cmc
   159 0000DB73 C3                  <1> 	retn
   160                              <1> 
   161                              <1> srunseq_8:
   162                              <1> 	; present priority of the process is not high
   163                              <1> 	
   164 0000DB74 8815[EB300100]      <1> 	mov	[u.pri], dl ; new priority 
   165                              <1> 			    ; (will be used by 'tswap')
   166                              <1> 
   167 0000DB7A 80FA02              <1> 	cmp	dl, 2 		; high priority ?
   168 0000DB7D 72F3                <1> 	jb	short srunseq_7 ; no, there is nothing to do
   169                              <1> 				; in addition
   170                              <1> 
   171                              <1> 	; process must be added to relevant run queue, here!
   172                              <1> 	; (new priority is high/event priority and process
   173                              <1> 	; will not be added to a run queue by 'tswap')
   174                              <1> 
   175 0000DB7F BB[98300100]        <1> 	mov	ebx, runq_normal ; 'run as regular' queue
   176                              <1> 
   177 0000DB84 20E4                <1> 	and	ah, ah  ;  previous value of [u.pri]
   178 0000DB86 75E4                <1> 	jnz	short srunseq_6
   179                              <1> 
   180 0000DB88 43                  <1> 	inc	ebx
   181 0000DB89 43                  <1> 	inc	ebx
   182                              <1> 	; ebx = runq_background ; 'run on backgroud' queue 
   183                              <1> 
   184 0000DB8A EBE0                <1> 	jmp	short srunseq_6
   185                              <1> 
   186                              <1> clock:
   187                              <1> 	; 23/05/2016
   188                              <1> 	; 22/05/2016
   189                              <1> 	; 20/05/2016
   190                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   191                              <1> 	; 14/05/2015 - 14/10/2015 (Retro UNIX 386 v1)
   192                              <1> 	; 07/12/2013 - 10/04/2014 (Retro UNIX 8086 v1)
   193                              <1> 
   194 0000DB8C 803D[EA300100]00    <1> 	cmp	byte [u.quant], 0
   195 0000DB93 772C                <1> 	ja	short clk_1
   196                              <1> 	;
   197 0000DB95 803D[F7300100]01    <1> 	cmp     byte [u.uno], 1 ; /etc/init ? (for Retro UNIX 8086 & 386 v1)
   198                              <1> 				; MainProg (Kernel's Command Interpreter)
   199                              <1> 				; for TRDOS 386.
   200 0000DB9C 7623                <1> 	jna	short clk_1 ; yes, do not swap out
   201                              <1> 	;
   202 0000DB9E 803D[9F300100]FF    <1> 	cmp     byte [sysflg], 0FFh ; user or system space ?
   203 0000DBA5 7520                <1> 	jne	short clk_2 	    ; system space (sysflg <> 0FFh)
   204                              <1> 	;
   205 0000DBA7 66833D[EC300100]00  <1> 	cmp	word [u.intr], 0
   206 0000DBAF 7616                <1> 	jna	short clk_2
   207                              <1> 	;
   208                              <1> 	; 23/05/2016
   209 0000DBB1 803D[4E2D0100]00    <1> 	cmp	byte [multi_tasking], 0
   210 0000DBB8 760D                <1> 	jna	short clk_2
   211                              <1> 	;
   212 0000DBBA FE05[4D2D0100]      <1> 	inc	byte [p_change] ; it is time to change running process	
   213 0000DBC0 C3                  <1> 	retn
   214                              <1> clk_1:
   215 0000DBC1 FE0D[EA300100]      <1> 	dec	byte [u.quant]
   216                              <1> clk_2:
   217 0000DBC7 C3                  <1> 	retn   ; return to (hardware) timer interrupt routine
   218                              <1> 
   219                              <1> 
   220                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   221                              <1> int34h:  ; #IOCTL# (I/O port access support for ring 3)
   222                              <1> ; 23/05/2016
   223                              <1> 	; 20/06/2016
   224                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   225                              <1> 	;
   226                              <1> 	; INPUT ->
   227                              <1> 	;	AH = 0 -> read port  (physical IO port)
   228                              <1> 	;	AH = 1 -> write port (physical IO port)
   229                              <1> 	;	AL = data byte
   230                              <1> 	;	DX = Port number (<= 0FFFFh)    	
   231                              <1> 	; OUTPUT ->
   232                              <1> 	;	AL = data byte
   233                              <1> 	;
   234                              <1> 	; Modified registers: none (except AL)
   235                              <1> 	;
   236 0000DBC8 FB                  <1> 	sti	; enable interrupts
   237 0000DBC9 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   238 0000DBCE 80FC01              <1> 	cmp	ah, 1
   239 0000DBD1 7706                <1> 	ja	short int34h_3
   240 0000DBD3 7202                <1> 	jb	short int34h_2
   241                              <1> 	; AH = 1 -> write port
   242 0000DBD5 EE                  <1> 	out	dx, al
   243 0000DBD6 CF                  <1> 	iretd
   244                              <1> int34h_2:
   245                              <1> 	; AH = 0 -> read port
   246 0000DBD7 EC                  <1> 	in	al, dx	
   247 0000DBD8 CF                  <1> 	iretd
   248                              <1> int34h_3:
   249                              <1> 	; AH > 1 -> invalid function for now ; 20/06/2016
   250 0000DBD9 30C0                <1> 	xor	al, al ; 0
   251 0000DBDB 804C240801          <1> 	or	byte [esp+8], 1	; set carry bit of eflags register
   252 0000DBE0 CF                  <1> 	iretd
   253                              <1> 
   254                              <1> INT4Ah:
   255                              <1> 	; 24/01/2016
   256                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
   257 0000DBE1 C3                  <1> 	retn
   258                              <1> 
   259                              <1> ; u0.s
   260                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
   261                              <1> ; Last Modification: 20/11/2015
   262                              <1> 
   263                              <1> com2_int:
   264                              <1> 	; 07/11/2015 
   265                              <1> 	; 24/10/2015
   266                              <1> 	; 23/10/2015
   267                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   268                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   269                              <1> 	; < serial port 2 interrupt handler >
   270                              <1> 	;
   271 0000DBE2 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   272                              <1> 	;push	eax
   273 0000DBE5 66B80900            <1> 	mov	ax, 9
   274 0000DBE9 EB07                <1> 	jmp	short comm_int
   275                              <1> com1_int:
   276                              <1> 	; 07/11/2015
   277                              <1> 	; 24/10/2015
   278 0000DBEB 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   279                              <1> 	; 23/10/2015
   280                              <1> 	;push	eax
   281 0000DBEE 66B80800            <1> 	mov	ax, 8
   282                              <1> comm_int:
   283                              <1> 	; 20/11/2015
   284                              <1> 	; 18/11/2015
   285                              <1> 	; 17/11/2015
   286                              <1> 	; 16/11/2015
   287                              <1> 	; 09/11/2015
   288                              <1> 	; 08/11/2015
   289                              <1> 	; 07/11/2015
   290                              <1> 	; 06/11/2015 (serial4.asm, 'serial')	
   291                              <1> 	; 01/11/2015
   292                              <1> 	; 26/10/2015
   293                              <1> 	; 23/10/2015
   294 0000DBF2 53                  <1> 	push	ebx
   295 0000DBF3 56                  <1> 	push	esi
   296 0000DBF4 57                  <1> 	push	edi
   297 0000DBF5 1E                  <1> 	push 	ds
   298 0000DBF6 06                  <1> 	push 	es
   299                              <1> 	; 18/11/2015
   300 0000DBF7 0F20DB              <1> 	mov	ebx, cr3
   301 0000DBFA 53                  <1> 	push	ebx ; ****
   302                              <1> 	;
   303 0000DBFB 51                  <1> 	push	ecx ; ***
   304 0000DBFC 52                  <1> 	push	edx ; **
   305                              <1> 	;
   306 0000DBFD BB10000000          <1> 	mov	ebx, KDATA
   307 0000DC02 8EDB                <1> 	mov	ds, bx
   308 0000DC04 8EC3                <1> 	mov	es, bx
   309                              <1> 	;
   310 0000DC06 8B0D[C81F0100]      <1> 	mov	ecx, [k_page_dir]
   311 0000DC0C 0F22D9              <1> 	mov	cr3, ecx
   312                              <1> 	; 20/11/2015
   313                              <1> 	; Interrupt identification register
   314 0000DC0F 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
   315                              <1> 	;
   316 0000DC13 3C08                <1> 	cmp 	al, 8 
   317 0000DC15 7702                <1> 	ja 	short com_i0
   318                              <1> 	;
   319                              <1> 	; 20/11/2015
   320                              <1> 	; 17/11/2015
   321                              <1> 	; 16/11/2015
   322                              <1> 	; 15/11/2015
   323                              <1> 	; 24/10/2015
   324                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   325                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   326                              <1> 	; < serial port 1 interrupt handler >
   327                              <1> 	;
   328 0000DC17 FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
   329                              <1> com_i0:
   330                              <1> 	;push	eax ; *
   331                              <1> 	; 07/11/2015
   332 0000DC19 A2[32200100]        <1> 	mov 	byte [ccomport], al
   333                              <1> 	; 09/11/2015
   334 0000DC1E 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
   335                              <1> 	; 17/11/2015
   336                              <1>  	; reset request for response status
   337 0000DC21 88A3[28200100]      <1> 	mov	[ebx+req_resp-8], ah ; 0
   338                              <1> 	;
   339                              <1> 	; 20/11/2015
   340 0000DC27 EC                  <1> 	in	al, dx		; read interrupt id. register
   341 0000DC28 EB00                <1> 	JMP	$+2	   	; I/O DELAY
   342 0000DC2A 2404                <1> 	and	al, 4		; received data available?	
   343 0000DC2C 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
   344                              <1> 	;
   345                              <1> 	; 20/11/2015
   346 0000DC2E 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
   347 0000DC31 EC                  <1> 	in	al, dx     	; read character
   348                              <1> 	;JMP	$+2	   	; I/O DELAY
   349                              <1> 	; 08/11/2015
   350                              <1> 	; 07/11/2015
   351 0000DC32 89DE                <1> 	mov	esi, ebx 
   352 0000DC34 89DF                <1> 	mov	edi, ebx
   353 0000DC36 81C6[2C200100]      <1> 	add 	esi, rchar - 8 ; points to last received char
   354 0000DC3C 81C7[2E200100]      <1> 	add	edi, schar - 8 ; points to last sent char
   355 0000DC42 8806                <1> 	mov	[esi], al ; received char (current char)
   356                              <1> 	; query
   357 0000DC44 20C0                <1> 	and	al, al
   358 0000DC46 7527                <1> 	jnz	short com_i2
   359                              <1>    	; response
   360                              <1> 	; 17/11/2015
   361                              <1> 	; set request for response status
   362 0000DC48 FE83[28200100]      <1>         inc     byte [ebx+req_resp-8] ; 1 
   363                              <1> 	;
   364 0000DC4E 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
   365 0000DC52 EC                  <1> 	in	al, dx	   	; read line status register 
   366 0000DC53 EB00                <1> 	JMP	$+2	   	; I/O DELAY
   367 0000DC55 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
   368 0000DC57 7445                <1> 	jz	short com_eoi 	; no
   369 0000DC59 B0FF                <1> 	mov 	al, 0FFh   	; response			
   370 0000DC5B 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
   371 0000DC5F EE                  <1> 	out	dx, al	   	; send on serial port
   372                              <1> 	; 17/11/2015
   373 0000DC60 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
   374 0000DC63 7502                <1> 	jne 	short com_i1    ; no
   375 0000DC65 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
   376                              <1> com_i1:
   377                              <1> 	; 17/11/2015
   378                              <1> 	; reset request for response status (again)
   379 0000DC67 FE8B[28200100]      <1>         dec     byte [ebx+req_resp-8] ; 0 
   380 0000DC6D EB2F                <1> 	jmp	short com_eoi
   381                              <1> com_i2:	
   382                              <1> 	; 08/11/2015
   383 0000DC6F 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
   384 0000DC71 7417                <1> 	je	short com_i3	; (check for response signal)
   385                              <1> 	; 07/11/2015
   386 0000DC73 3C04                <1> 	cmp	al, 04h	; EOT
   387 0000DC75 751C                <1> 	jne	short com_i4	
   388                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
   389                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
   390                              <1> 	; 08/11/2015
   391                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
   392 0000DC77 861D[F61F0100]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
   393 0000DC7D E84D79FFFF          <1> 	call 	ctrlbrk
   394 0000DC82 861D[F61F0100]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
   395                              <1> 	;mov	al, 04h ; EOT
   396                              <1> 	; 08/11/2015
   397 0000DC88 EB09                <1> 	jmp	short com_i4	
   398                              <1> com_i3:
   399                              <1> 	; 08/11/2015
   400                              <1> 	; If 0FFh has been received just after a query
   401                              <1> 	; (schar, ZERO), it is a response signal.
   402                              <1> 	; 17/11/2015
   403 0000DC8A 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
   404 0000DC8D 7704                <1> 	ja	short com_i4 ; no
   405                              <1> 	; reset query status (schar)
   406 0000DC8F 8807                <1> 	mov	[edi], al ; 0FFh
   407 0000DC91 FEC0                <1> 	inc	al ; 0
   408                              <1> com_i4:
   409                              <1> 	; 27/07/2014
   410                              <1> 	; 09/07/2014
   411 0000DC93 D0E3                <1> 	shl	bl, 1	
   412 0000DC95 81C3[F81F0100]      <1> 	add	ebx, ttychr
   413                              <1> 	; 23/07/2014 (always overwrite)
   414                              <1> 	;;cmp	word [ebx], 0
   415                              <1> 	;;ja	short com_eoi
   416                              <1> 	;
   417 0000DC9B 668903              <1> 	mov	[ebx], ax   ; Save ascii code
   418                              <1> 			    ; scan code = 0
   419                              <1> com_eoi:
   420                              <1> 	;mov	al, 20h
   421                              <1> 	;out	20h, al	   ; end of interrupt
   422                              <1> 	;
   423                              <1> 	; 07/11/2015
   424                              <1>       	;pop	eax ; *
   425 0000DC9E A0[32200100]        <1> 	mov	al, byte [ccomport] ; current COM port
   426                              <1> 	 ; al = tty number (8 or 9)
   427 0000DCA3 E85E010000          <1>         call	wakeup
   428                              <1> com_iret:
   429                              <1> 	; 23/10/2015
   430 0000DCA8 5A                  <1> 	pop	edx ; **
   431 0000DCA9 59                  <1> 	pop	ecx ; ***
   432                              <1> 	; 18/11/2015
   433                              <1> 	;pop	eax ; ****
   434                              <1> 	;mov	cr3, eax
   435                              <1> 	;jmp	iiret
   436 0000DCAA E9242DFFFF          <1> 	jmp	iiretp
   437                              <1> 
   438                              <1> ;iiretp: ; 01/09/2015
   439                              <1> ;	; 28/08/2015
   440                              <1> ;	pop	eax ; (*) page directory
   441                              <1> ;	mov	cr3, eax
   442                              <1> ;iiret:
   443                              <1> ;	; 22/08/2014
   444                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
   445                              <1> ;	out	20h, al	; 8259 PORT
   446                              <1> ;	;
   447                              <1> ;	pop	es
   448                              <1> ;	pop	ds
   449                              <1> ;	pop	edi
   450                              <1> ;	pop	esi
   451                              <1> ;	pop	ebx ; 29/08/2014
   452                              <1> ;	pop 	eax
   453                              <1> ;	iretd
   454                              <1> 
   455                              <1> sp_init:
   456                              <1> 	; 07/11/2015
   457                              <1> 	; 29/10/2015
   458                              <1> 	; 26/10/2015
   459                              <1> 	; 23/10/2015
   460                              <1> 	; 29/06/2015
   461                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
   462                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
   463                              <1> 	; Initialization of Serial Port Communication Parameters
   464                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   465                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   466                              <1> 	;
   467                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   468                              <1> 	;
   469                              <1> 	; INPUT:  (29/06/2015)
   470                              <1> 	;	AL = 0 for COM1
   471                              <1> 	;	     1 for COM2
   472                              <1> 	;	AH = Communication parameters	
   473                              <1> 	;
   474                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   475                              <1> 	;	Bit	4	3	2	1	0
   476                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
   477                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   478                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   479                              <1> 	;		11 = even
   480                              <1> 	;  Baud rate setting bits: (29/06/2015)
   481                              <1> 	;		Retro UNIX 386 v1 feature only !
   482                              <1> 	;	Bit	7    6    5  | Baud rate
   483                              <1> 	;		------------------------
   484                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   485                              <1> 	;		0    0    1  | 9600 (12)
   486                              <1> 	;		0    1    0  | 19200 (6) 
   487                              <1> 	;		0    1	  1  | 38400 (3) 
   488                              <1> 	;		1    0	  0  | 14400 (8)
   489                              <1> 	;		1    0	  1  | 28800 (4)
   490                              <1> 	;		1    1    0  | 57600 (2)
   491                              <1> 	;		1    1    1  | 115200 (1) 	
   492                              <1> 	
   493                              <1> 	; References:	
   494                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
   495                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
   496                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
   497                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
   498                              <1> 	;
   499                              <1> 	; Set communication parameters for COM1 (= 03h)	
   500                              <1> 	;
   501 0000DCAF BB[2E200100]        <1> 	mov	ebx, com1p		; COM1 parameters  
   502 0000DCB4 66BAF803            <1> 	mov	dx, 3F8h		; COM1
   503                              <1> 	 ; 29/10/2015
   504 0000DCB8 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   505 0000DCBC E86F000000          <1> 	call	sp_i3	; call A4	
   506 0000DCC1 A880                <1> 	test	al, 80h
   507 0000DCC3 7410                <1> 	jz	short sp_i0 ; OK..
   508                              <1> 		; Error !
   509                              <1> 	;mov	dx, 3F8h
   510 0000DCC5 80EA05              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
   511 0000DCC8 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   512 0000DCCC E85F000000          <1> 	call	sp_i3	; call A4	
   513 0000DCD1 A880                <1> 	test	al, 80h
   514 0000DCD3 7508                <1> 	jnz	short sp_i1
   515                              <1> sp_i0:
   516                              <1>         ; (Note: Serial port interrupts will be disabled here...)	
   517                              <1>         ; (INT 14h initialization code disables interrupts.)
   518                              <1> 	;
   519 0000DCD5 C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   520 0000DCD8 E8DC000000          <1> 	call	sp_i5 ; 29/06/2015
   521                              <1> sp_i1:
   522 0000DCDD 43                  <1> 	inc	ebx
   523 0000DCDE 66BAF802            <1> 	mov	dx, 2F8h		; COM2
   524                              <1> 	 ; 29/10/2015
   525 0000DCE2 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   526 0000DCE6 E845000000          <1> 	call	sp_i3	; call A4	
   527 0000DCEB A880                <1> 	test	al, 80h
   528 0000DCED 7410                <1> 	jz	short sp_i2 ; OK..
   529                              <1> 		; Error !
   530                              <1> 	;mov	dx, 2F8h
   531 0000DCEF 80EA05              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
   532 0000DCF2 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   533 0000DCF6 E835000000          <1> 	call	sp_i3	; call A4	
   534 0000DCFB A880                <1> 	test	al, 80h
   535 0000DCFD 7530                <1> 	jnz	short sp_i7
   536                              <1> sp_i2:
   537 0000DCFF C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   538                              <1> sp_i6:
   539                              <1> 	;; COM2 - enabling IRQ 3
   540                              <1> 	; 07/11/2015
   541                              <1> 	; 26/10/2015
   542 0000DD02 9C                  <1> 	pushf
   543 0000DD03 FA                  <1> 	cli
   544                              <1> 	;
   545 0000DD04 66BAFC02            <1> 	mov	dx, 2FCh   		; modem control register
   546 0000DD08 EC                  <1> 	in	al, dx 	   		; read register
   547 0000DD09 EB00                <1> 	JMP	$+2	   		; I/O DELAY
   548 0000DD0B 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
   549 0000DD0D EE                  <1> 	out	dx, al     		; write back to register
   550 0000DD0E EB00                <1> 	JMP	$+2	   		; I/O DELAY
   551 0000DD10 66BAF902            <1> 	mov	dx, 2F9h   		; interrupt enable register
   552 0000DD14 EC                  <1> 	in	al, dx     		; read register
   553 0000DD15 EB00                <1> 	JMP	$+2	   		; I/O DELAY
   554                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   555 0000DD17 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
   556 0000DD19 EE                  <1> 	out	dx, al 	   		; write back to register
   557 0000DD1A EB00                <1> 	JMP	$+2        		; I/O DELAY
   558 0000DD1C E421                <1> 	in	al, 21h    		; read interrupt mask register
   559 0000DD1E EB00                <1> 	JMP	$+2	   		; I/O DELAY
   560 0000DD20 24F7                <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
   561 0000DD22 E621                <1> 	out	21h, al    		; write back to register
   562                              <1> 	;
   563                              <1> 	; 23/10/2015
   564 0000DD24 B8[E2DB0000]        <1> 	mov 	eax, com2_int
   565 0000DD29 A3[01DE0000]        <1> 	mov	[com2_irq3], eax
   566                              <1> 	; 26/10/2015
   567 0000DD2E 9D                  <1> 	popf	
   568                              <1> sp_i7:
   569 0000DD2F C3                  <1> 	retn
   570                              <1> 
   571                              <1> sp_i3:
   572                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
   573                              <1> 	; 28/10/2015
   574 0000DD30 FEC2                <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
   575 0000DD32 B000                <1> 	mov	al, 0
   576 0000DD34 EE                  <1> 	out	dx, al			; disable serial port interrupt
   577 0000DD35 EB00                <1> 	JMP	$+2			; I/O DELAY
   578 0000DD37 80C202              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
   579 0000DD3A B080                <1> 	mov	al, 80h			
   580 0000DD3C EE                  <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
   581                              <1> 	;-----	SET BAUD RATE DIVISOR
   582                              <1> 	; 26/10/2015
   583 0000DD3D 80EA03              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
   584                              <1> 					; of the divisor value
   585 0000DD40 88C8                <1> 	mov	al, cl	; 1
   586 0000DD42 EE                  <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
   587                              <1> 					; 2 = 57600 baud
   588                              <1> 					; 3 = 38400 baud
   589                              <1> 					; 6 = 19200 baud
   590                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
   591 0000DD43 EB00                <1> 	JMP	$+2			; I/O DELAY
   592 0000DD45 28C0                <1> 	sub	al, al
   593 0000DD47 FEC2                <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
   594                              <1> 					; of the divisor value
   595 0000DD49 EE                  <1> 	out	dx, al ; 0
   596 0000DD4A EB00                <1> 	JMP	$+2			; I/O DELAY
   597                              <1> 	;	
   598 0000DD4C 88E8                <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
   599                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
   600 0000DD4E 80C202              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
   601 0000DD51 EE                  <1> 	out	dx, al			
   602 0000DD52 EB00                <1> 	JMP	$+2			; I/O DELAY
   603                              <1> 	; 29/10/2015
   604 0000DD54 FECA                <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
   605 0000DD56 30C0                <1> 	xor	al, al			; 0
   606 0000DD58 EE                  <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
   607 0000DD59 EB00                <1> 	JMP	$+2	
   608                              <1> sp_i4:
   609                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
   610                              <1> 	; 29/06/2015 (line status after modem status)
   611 0000DD5B 80C204              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
   612                              <1> sp_i4s:
   613 0000DD5E EC                  <1> 	in	al, dx			; GET MODEM CONTROL STATUS
   614 0000DD5F EB00                <1> 	JMP	$+2			; I/O DELAY
   615 0000DD61 88C4                <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
   616 0000DD63 FECA                <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
   617                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
   618 0000DD65 EC                  <1> 	in	al, dx			; GET LINE CONTROL STATUS
   619                              <1> 	; AL = Line status, AH = Modem status
   620 0000DD66 C3                  <1> 	retn
   621                              <1> 
   622                              <1> sp_status:
   623                              <1> 	; 29/06/2015
   624                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
   625                              <1> 	; Get serial port status
   626 0000DD67 66BAFE03            <1> 	mov	dx, 3FEh		; Modem status register (COM1)
   627 0000DD6B 28C6                <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
   628                              <1> 					; dx = 2FEh for COM2
   629 0000DD6D EBEF                <1> 	jmp	short sp_i4s
   630                              <1> 
   631                              <1> sp_setp: ; Set serial port communication parameters
   632                              <1> 	; 07/11/2015
   633                              <1> 	; 29/10/2015
   634                              <1> 	; 29/06/2015
   635                              <1> 	; Retro UNIX 386 v1 feature only !	
   636                              <1> 	;
   637                              <1> 	; INPUT:
   638                              <1> 	;	AL = 0 for COM1
   639                              <1> 	;	     1 for COM2
   640                              <1> 	;	AH = Communication parameters (*)
   641                              <1> 	; OUTPUT:
   642                              <1> 	;	CL = Line status
   643                              <1> 	;	CH = Modem status
   644                              <1> 	;   If cf = 1 -> Error code in [u.error]
   645                              <1> 	;		 'invalid parameter !' 
   646                              <1> 	;		 	 or
   647                              <1> 	;		 'device not ready !' error
   648                              <1> 	;	
   649                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   650                              <1> 	;	Bit	4	3	2	1	0
   651                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
   652                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   653                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   654                              <1> 	;		11 = even
   655                              <1> 	;  Baud rate setting bits: (29/06/2015)
   656                              <1> 	;		Retro UNIX 386 v1 feature only !
   657                              <1> 	;	Bit	7    6    5  | Baud rate
   658                              <1> 	;		------------------------
   659                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   660                              <1> 	;		0    0    1  | 9600 (12)
   661                              <1> 	;		0    1    0  | 19200 (6) 
   662                              <1> 	;		0    1	  1  | 38400 (3) 
   663                              <1> 	;		1    0	  0  | 14400 (8)
   664                              <1> 	;		1    0	  1  | 28800 (4)
   665                              <1> 	;		1    1    0  | 57600 (2)
   666                              <1> 	;		1    1    1  | 115200 (1) 
   667                              <1> 	;
   668                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   669                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   670                              <1> 	;
   671                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   672                              <1> 	;
   673 0000DD6F 66BAF803            <1> 	mov	dx, 3F8h
   674 0000DD73 BB[2E200100]        <1> 	mov	ebx, com1p ; COM1 control byte offset
   675 0000DD78 3C01                <1> 	cmp	al, 1
   676 0000DD7A 776B                <1> 	ja 	short sp_invp_err
   677 0000DD7C 7203                <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
   678 0000DD7E FECE                <1> 	dec	dh ; 2F8h
   679 0000DD80 43                  <1> 	inc	ebx ; COM2 control byte offset
   680                              <1> sp_setp1:
   681                              <1> 	; 29/10/2015
   682 0000DD81 8823                <1> 	mov	[ebx], ah
   683 0000DD83 0FB6CC              <1> 	movzx 	ecx, ah
   684 0000DD86 C0E905              <1> 	shr	cl, 5 ; -> baud rate index
   685 0000DD89 80E41F              <1> 	and	ah, 1Fh ; communication parameters except baud rate
   686 0000DD8C 8A81[F6DD0000]      <1> 	mov	al, [ecx+b_div_tbl]
   687 0000DD92 6689C1              <1> 	mov	cx, ax
   688 0000DD95 E896FFFFFF          <1> 	call	sp_i3
   689 0000DD9A 6689C1              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
   690 0000DD9D A880                <1> 	test	al, 80h
   691 0000DD9F 740F                <1> 	jz	short sp_setp2
   692 0000DDA1 C603E3              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
   693                              <1> stp_dnr_err:
   694 0000DDA4 C705[FD300100]0F00- <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
   694 0000DDAC 0000                <1>
   695                              <1> 	; CL = Line status, CH = Modem status
   696 0000DDAE F9                  <1> 	stc
   697 0000DDAF C3                  <1> 	retn
   698                              <1> sp_setp2:
   699 0000DDB0 80FE02              <1> 	cmp	dh, 2 ; COM2 (2F?h)
   700 0000DDB3 0F8649FFFFFF        <1>         jna     sp_i6 
   701                              <1> 		      ; COM1 (3F?h)
   702                              <1> sp_i5: 
   703                              <1> 	; 07/11/2015
   704                              <1> 	; 26/10/2015
   705                              <1> 	; 29/06/2015
   706                              <1> 	;
   707                              <1> 	;; COM1 - enabling IRQ 4
   708 0000DDB9 9C                  <1> 	pushf
   709 0000DDBA FA                  <1> 	cli
   710 0000DDBB 66BAFC03            <1> 	mov	dx, 3FCh   		; modem control register
   711 0000DDBF EC                  <1> 	in	al, dx 	   		; read register
   712 0000DDC0 EB00                <1> 	JMP	$+2			; I/O DELAY
   713 0000DDC2 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
   714 0000DDC4 EE                  <1> 	out	dx, al     		; write back to register
   715 0000DDC5 EB00                <1> 	JMP	$+2			; I/O DELAY
   716 0000DDC7 66BAF903            <1> 	mov	dx, 3F9h   		; interrupt enable register
   717 0000DDCB EC                  <1> 	in	al, dx     		; read register
   718 0000DDCC EB00                <1> 	JMP	$+2			; I/O DELAY
   719                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   720 0000DDCE 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
   721 0000DDD0 EE                  <1> 	out	dx, al 	   		; write back to register
   722 0000DDD1 EB00                <1> 	JMP	$+2        		; I/O DELAY
   723 0000DDD3 E421                <1> 	in	al, 21h    		; read interrupt mask register
   724 0000DDD5 EB00                <1> 	JMP	$+2			; I/O DELAY
   725 0000DDD7 24EF                <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
   726 0000DDD9 E621                <1> 	out	21h, al    		; write back to register
   727                              <1> 	;
   728                              <1> 	; 23/10/2015
   729 0000DDDB B8[EBDB0000]        <1> 	mov 	eax, com1_int
   730 0000DDE0 A3[FDDD0000]        <1> 	mov	[com1_irq4], eax
   731                              <1> 	; 26/10/2015
   732 0000DDE5 9D                  <1> 	popf
   733 0000DDE6 C3                  <1> 	retn
   734                              <1> 
   735                              <1> sp_invp_err:
   736 0000DDE7 C705[FD300100]1700- <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
   736 0000DDEF 0000                <1>
   737 0000DDF1 31C9                <1> 	xor	ecx, ecx
   738 0000DDF3 49                  <1> 	dec	ecx ; 0FFFFh
   739 0000DDF4 F9                  <1> 	stc
   740 0000DDF5 C3                  <1> 	retn
   741                              <1> 
   742                              <1> ; 29/10/2015
   743                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
   744 0000DDF6 010C0603080401      <1> 	db 1, 12, 6, 3, 8, 4, 1
   745                              <1> 
   746                              <1> 
   747                              <1> ; 23/10/2015
   748                              <1> com1_irq4:
   749 0000DDFD [05DE0000]          <1> 	dd dummy_retn
   750                              <1> com2_irq3:
   751 0000DE01 [05DE0000]          <1> 	dd dummy_retn
   752                              <1> 
   753                              <1> dummy_retn:
   754 0000DE05 C3                  <1> 	retn
   755                              <1> 
   756                              <1> wakeup:
   757                              <1> 	; 24/01/2016
   758 0000DE06 C3                  <1> 	retn
  1926                                  %include 'trdosk9.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - INITIALIZED DATA : trdosk9.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 08/08/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; ----------------------------------------------------------------------------
     9                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
    10                              <1> ; ----------------------------------------------------------------------------
    11                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    12                              <1> ; TRDOS2.ASM (09/11/2011)
    13                              <1> ; ****************************************************************************
    14                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
    15                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
    16                              <1> ; CMD_INTR.ASM [29/01/2005] Last Update: 09/11/2011
    17                              <1> ; FILE.ASM [29/10/2009] Last Update: 09/10/2011
    18                              <1> 
    19                              <1> ; 12/02/2016
    20                              <1> Last_DOS_DiskNo: 
    21 0000DE07 01                  <1> 		db 1 ; A: = 0 & B: = 1
    22                              <1> 
    23                              <1> Restore_CDIR:	
    24 0000DE08 FF                  <1> 		db 0FFh ; Initial value -> any number except 0
    25                              <1> 
    26                              <1> msg_CRLF_temp:  
    27 0000DE09 070D0A00            <1> 		db  07h, 0Dh, 0Ah, 0
    28                              <1> 
    29                              <1> Magic_Bytes:
    30 0000DE0D 04                  <1> 		db 4
    31 0000DE0E 01                  <1> 		db 1
    32                              <1> mainprog_Version:
    33 0000DE0F 07                  <1> 		db 7
    34 0000DE10 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.080816"
    34 0000DE19 61696E2050726F6772- <1>
    34 0000DE22 616D2076322E302E30- <1>
    34 0000DE2B 3830383136          <1>
    35 0000DE30 0D0A                <1> 		db 0Dh, 0Ah
    36 0000DE32 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2016"
    36 0000DE3B 616E2054616E203230- <1>
    36 0000DE44 30352D32303136      <1>
    37 0000DE4B 0D0A00              <1> 		db 0Dh, 0Ah, 0
    38                              <1> 
    39                              <1> MainProgCfgFile: ; 14/04/2016
    40 0000DE4E 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
    40 0000DE57 43464700            <1>
    41                              <1> 
    42                              <1> TRDOSPromptLabel:
    43 0000DE5B 5452444F53          <1> 		db "TRDOS"
    44 0000DE60 00                  <1> 		db 0
    45 0000DE61 00<rept>            <1>                 times 5 db 0
    46 0000DE66 00                  <1> 		db 0
    47                              <1> 
    48                              <1> ; INTERNAL COMMANDS
    49                              <1> Command_List:
    50 0000DE67 44495200            <1> Cmd_Dir:	db "DIR", 0
    51 0000DE6B 434400              <1> Cmd_Cd:		db "CD", 0
    52 0000DE6E 433A00              <1> Cmd_Drive:	db "C:", 0
    53 0000DE71 56455200            <1> Cmd_Ver:	db "VER", 0
    54 0000DE75 4558495400          <1> Cmd_Exit:	db "EXIT", 0
    55 0000DE7A 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
    56 0000DE81 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
    57 0000DE88 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
    58 0000DE91 4441544500          <1> Cmd_Date:	db "DATE", 0
    59 0000DE96 54494D4500          <1> Cmd_Time:	db "TIME", 0
    60 0000DE9B 52554E00            <1> Cmd_Run:	db "RUN", 0
    61 0000DE9F 53455400            <1> Cmd_Set:	db "SET", 0 
    62 0000DEA3 434C5300            <1> Cmd_Cls:	db "CLS", 0
    63 0000DEA7 53484F5700          <1> Cmd_Show:	db "SHOW", 0
    64 0000DEAC 44454C00            <1> Cmd_Del:	db "DEL", 0
    65 0000DEB0 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
    66 0000DEB7 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
    67 0000DEBE 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
    68 0000DEC4 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
    69 0000DECA 434F505900          <1> Cmd_Copy:	db "COPY", 0
    70 0000DECF 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
    71 0000DED4 5041544800          <1> Cmd_Path:	db "PATH", 0
    72 0000DED9 4D454D00            <1> Cmd_Mem:	db "MEM", 0
    73 0000DEDD 00                  <1> 		db 0
    74 0000DEDE 46494E4400          <1> Cmd_Find:	db "FIND", 0
    75 0000DEE3 5245414446494C4500  <1> Cmd_ReadFile:	db "READFILE", 0
    76 0000DEEC 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
    77 0000DEF1 2A00                <1> Cmd_Remark:	db "*", 0
    78 0000DEF3 3F00                <1> Cmd_Help:	db "?", 0
    79 0000DEF5 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
    80 0000DEFC 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
    81 0000DF04 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
    82 0000DF0A 4245455000          <1> Cmd_Beep:	db "BEEP", 0
    83                              <1> 		
    84 0000DF0F 00                  <1> 		db 0
    85                              <1> 
    86                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
    87                              <1> invalid_fname_chars:
    88 0000DF10 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
    89 0000DF18 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
    90 0000DF1F 5B5C5D5E60          <1> 		db 5Bh, 5Ch, 5Dh, 5Eh, 60h
    91                              <1> sizeInvFnChars  equ ($ - invalid_fname_chars)                
    92                              <1> ;
    93                              <1> 
    94                              <1> Msg_Enter_Date:
    95 0000DF24 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
    95 0000DF2D 206461746520286464- <1>
    95 0000DF36 2D6D6D2D7979293A20  <1>
    96 0000DF3F 00                  <1>                 db 0
    97                              <1> Msg_Show_Date:
    98 0000DF40 43757272656E742064- <1>                 db   'Current date is '
    98 0000DF49 61746520697320      <1>
    99 0000DF50 30                  <1> Day:            db   '0'
   100 0000DF51 30                  <1> 		db   '0'
   101 0000DF52 2F                  <1>                 db   '/'
   102 0000DF53 30                  <1> Month:          db   '0'
   103 0000DF54 30                  <1> 		db   '0'
   104 0000DF55 2F                  <1>                 db   '/'
   105 0000DF56 30                  <1> Century:        db   '0'
   106 0000DF57 30                  <1>                 db   '0'
   107 0000DF58 30                  <1> Year:           db   '0'
   108 0000DF59 30                  <1> 		db   '0'
   109 0000DF5A 0D0A00              <1>                 db   0Dh, 0Ah, 0
   110                              <1> 
   111                              <1> Msg_Enter_Time:
   112 0000DF5D 456E746572206E6577- <1> 		db 'Enter new time: '
   112 0000DF66 2074696D653A20      <1>
   113 0000DF6D 00                  <1> 		db 0
   114                              <1> Msg_Show_Time:
   115 0000DF6E 43757272656E742074- <1> 		db   'Current time is '
   115 0000DF77 696D6520697320      <1>
   116 0000DF7E 30                  <1> Hour:           db   '0'
   117 0000DF7F 30                  <1> 		db   '0'
   118 0000DF80 3A                  <1> 		db   ':'
   119 0000DF81 30                  <1> Minute:         db   '0'
   120 0000DF82 30                  <1> 		db   '0'
   121 0000DF83 3A                  <1> 		db   ':'
   122 0000DF84 30                  <1> Second:         db   '0'
   123 0000DF85 30                  <1> 		db   '0'
   124 0000DF86 0D0A00              <1> 		db   0Dh, 0Ah, 0
   125                              <1> 
   126                              <1> ;VolSize_Unit1:   dd 0
   127                              <1> ;VolSize_Unit2:   dd 0
   128                              <1> 
   129                              <1> VolSize_KiloBytes:
   130 0000DF89 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
   130 0000DF92 730D0A00            <1>
   131                              <1> VolSize_Bytes:
   132 0000DF96 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
   133                              <1> Volume_in_drive:
   134 0000DF9F 0D0A                <1> 		db 0Dh, 0Ah
   135                              <1> Vol_FS_Name:
   136 0000DFA1 54522046533120      <1> 		db "TR FS1 "
   137 0000DFA8 566F6C756D6520696E- <1> 		db "Volume in drive "
   137 0000DFB1 20647269766520      <1>
   138 0000DFB8 30                  <1> Vol_Drv_Name:   db 30h
   139 0000DFB9 3A                  <1> 		db ":"
   140 0000DFBA 20697320            <1> 		db " is "
   141 0000DFBE 0D0A00              <1> 		db 0Dh, 0Ah, 0
   142                              <1> Dir_Drive_Str:
   143 0000DFC1 54522D444F53204472- <1>                 db "TR-DOS Drive "
   143 0000DFCA 69766520            <1>
   144                              <1> Dir_Drive_Name:
   145 0000DFCE 303A                <1>                 db "0:"
   146 0000DFD0 0D0A                <1>                 db  0Dh, 0Ah
   147                              <1> Vol_Str_Header:
   148 0000DFD2 566F6C756D65204E61- <1>                 db "Volume Name: "
   148 0000DFDB 6D653A20            <1>
   149                              <1> Vol_Name:
   150 0000DFDF 00<rept>            <1> 		times 64 db 0
   151 0000E01F 00                  <1> 		db 0
   152                              <1> Vol_Serial_Header:
   153 0000E020 0D0A                <1> 		db 0Dh, 0Ah
   154 0000E022 566F6C756D65205365- <1> 		db "Volume Serial No: "
   154 0000E02B 7269616C204E6F3A20  <1>
   155                              <1> Vol_Serial1:
   156 0000E034 30303030            <1> 		db "0000"
   157 0000E038 2D                  <1> 		db "-"
   158                              <1> Vol_Serial2:
   159 0000E039 30303030            <1> 		db "0000"
   160 0000E03D 0D0A00              <1> 		db 0Dh, 0Ah, 0
   161                              <1> 
   162                              <1> ;Vol_Tot_Sec_Str_Start:
   163                              <1> ;		dd 0
   164                              <1> Vol_Total_Sector_Header:
   165 0000E040 0D0A                <1> 		db 0Dh, 0Ah
   166 0000E042 566F6C756D65205369- <1> 		db "Volume Size : ", 0
   166 0000E04B 7A65203A2000        <1>
   167                              <1> ;Vol_Tot_Sec_Str: 
   168                              <1> ;		db "0000000000"
   169                              <1> ;Vol_Tot_Sec_Str_End:
   170                              <1> ;		db 0
   171                              <1> ;Vol_Free_Sectors_Str_Start:
   172                              <1> ;		dd 0
   173                              <1> Vol_Free_Sectors_Header:
   174 0000E051 467265652053706163- <1> 		db "Free Space  : ", 0
   174 0000E05A 6520203A2000        <1>
   175                              <1> ;Vol_Free_Sectors_Str:
   176                              <1> ;		db "0000000000"
   177                              <1> ;Vol_Free_Sectors_Str_End:
   178                              <1> ;		db 0
   179                              <1> 
   180                              <1> Dir_Str_Header:
   181 0000E060 4469726563746F7279- <1>                 db "Directory: "
   181 0000E069 3A20                <1>
   182 0000E06B 2F                  <1> Dir_Str_Root:   db "/"
   183 0000E06C 00<rept>            <1> Dir_Str:        times 64 db 0
   184 0000E0AC 00000000            <1>                 dd 0
   185 0000E0B0 00                  <1>                 db 0
   186                              <1> 
   187                              <1> Msg_Bad_Command:
   188 0000E0B1 42616420636F6D6D61- <1>                 db "Bad command or file name!"
   188 0000E0BA 6E64206F722066696C- <1>
   188 0000E0C3 65206E616D6521      <1>
   189 0000E0CA 0D0A00              <1>                 db 0Dh, 0Ah, 0
   190                              <1> 
   191                              <1> msgl_drv_not_ready: 
   192 0000E0CD 070D0A              <1> 		db 07h, 0Dh, 0Ah
   193                              <1> 
   194                              <1> ; CMD_INTR.ASM - 09/11/2011 - Messages
   195                              <1> 
   196                              <1> Msg_Not_Ready_Read_Err:
   197 0000E0D0 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
   197 0000E0D9 207265616479206F72- <1>
   197 0000E0E2 207265616420657272- <1>
   197 0000E0EB 6F7221              <1>
   198 0000E0EE 0D0A00              <1>                 db 0Dh, 0Ah, 0
   199                              <1> 
   200                              <1> Msg_Not_Ready_Write_Err:
   201 0000E0F1 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
   201 0000E0FA 207265616479206F72- <1>
   201 0000E103 207772697465206572- <1>
   201 0000E10C 726F7221            <1>
   202 0000E110 0D0A00              <1>                 db 0Dh, 0Ah, 0
   203                              <1> 
   204                              <1> Msg_Dir_Not_Found:
   205 0000E113 4469726563746F7279- <1>                 db "Directory not found!"
   205 0000E11C 206E6F7420666F756E- <1>
   205 0000E125 6421                <1>
   206 0000E127 0D0A00              <1>                 db 0Dh, 0Ah, 0
   207                              <1> 
   208                              <1> Msg_File_Not_Found:
   209 0000E12A 46696C65206E6F7420- <1>                 db "File not found!"
   209 0000E133 666F756E6421        <1>
   210 0000E139 0D0A00              <1>                 db 0Dh, 0Ah, 0
   211                              <1> 
   212                              <1> Msg_File_Directory_Not_Found:
   213 0000E13C 46696C65206F722064- <1>                 db "File or directory not found!"
   213 0000E145 69726563746F727920- <1>
   213 0000E14E 6E6F7420666F756E64- <1>
   213 0000E157 21                  <1>
   214 0000E158 0D0A00              <1>                 db 0Dh, 0Ah, 0
   215                              <1> 
   216                              <1> Msg_LongName_Not_Found:
   217 0000E15B 4C6F6E67206E616D65- <1>                 db "Long name not found!"
   217 0000E164 206E6F7420666F756E- <1>
   217 0000E16D 6421                <1>
   218 0000E16F 0D0A00              <1>                 db 0Dh, 0Ah, 0
   219                              <1> 
   220                              <1> Msg_Insufficient_Memory:
   221 0000E172 496E73756666696369- <1>                 db "Insufficient memory!"
   221 0000E17B 656E74206D656D6F72- <1>
   221 0000E184 7921                <1>
   222 0000E186 0D0A00              <1>                 db 0Dh, 0Ah, 0
   223                              <1> 
   224                              <1> Msg_Error_Code:
   225 0000E189 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
   225 0000E192 61696C656421204572- <1>
   225 0000E19B 726F7220636F646520- <1>
   225 0000E1A4 3A20                <1>
   226 0000E1A6 303068              <1> error_code_hex: db '00h'
   227 0000E1A9 0A0A00              <1>                 db 0Ah, 0Ah, 0
   228                              <1> 
   229                              <1> align 2
   230                              <1> 
   231                              <1> ; 10/02/2016
   232                              <1> ; DIR.ASM - 09/10/2011
   233                              <1> 
   234 0000E1AC 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
   234 0000E1B5 20                  <1>
   235                              <1> 
   236                              <1> File_Name:
   237 0000E1B6 20<rept>            <1>                 times 12 db 20h
   238 0000E1C2 20                  <1> 		db 20h
   239                              <1> Dir_Or_FileSize:
   240 0000E1C3 20<rept>            <1>                 times 10 db 20h
   241 0000E1CD 20                  <1> 		db 20h
   242                              <1> File_Attribute:
   243 0000E1CE 20202020            <1> 		dd 20202020h
   244 0000E1D2 20                  <1> 		db 20h
   245                              <1> File_Day:
   246 0000E1D3 3030                <1>                 db '0','0'
   247 0000E1D5 2F                  <1> 		db '/'
   248                              <1> File_Month:
   249 0000E1D6 3030                <1>                 db '0','0'
   250 0000E1D8 2F                  <1> 		db '/'
   251                              <1> File_Year:
   252 0000E1D9 30303030            <1>                 db '0','0','0','0'
   253 0000E1DD 20                  <1> 		db 20h
   254                              <1> File_Hour:
   255 0000E1DE 3030                <1>                 db '0','0'
   256 0000E1E0 3A                  <1> 		db ':'
   257                              <1> File_Minute:
   258 0000E1E1 3030                <1>                 db '0','0'
   259 0000E1E3 00                  <1> 		db 0
   260                              <1> 
   261                              <1> Decimal_File_Count_Header:
   262 0000E1E4 0D0A                <1> 		db 0Dh, 0Ah
   263                              <1> Decimal_File_Count:
   264 0000E1E6 00<rept>            <1> 		times 6 db 0
   265                              <1> 
   266 0000E1EC 2066696C6528732920- <1> str_files:	db " file(s) & "
   266 0000E1F5 2620                <1>
   267                              <1> Decimal_Dir_Count: 
   268 0000E1F7 00<rept>            <1> 		times 6 db 0
   269                              <1> str_dirs:       
   270 0000E1FD 206469726563746F72- <1> 		db " directory(s) "
   270 0000E206 7928732920          <1>
   271 0000E20B 0D0A00              <1> 		db 0Dh, 0Ah, 0
   272                              <1> 
   273 0000E20E 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
   273 0000E217 696E2066696C652873- <1>
   273 0000E220 29                  <1>
   274 0000E221 0D0A00              <1> 		db 0Dh, 0Ah, 0
   275                              <1> 
   276                              <1> ; CMD_INTR.ASM - 09/11/2011
   277                              <1> ; 07/10/2010
   278                              <1> Msg_invalid_name_chars:
   279 0000E224 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
   279 0000E22D 696C65206F72206469- <1>
   279 0000E236 726563746F7279206E- <1>
   279 0000E23F 616D65206368617261- <1>
   279 0000E248 637465727321        <1>
   280 0000E24E 0D0A00              <1>         	db 0Dh, 0Ah, 0
   281                              <1> ; 21/02/2016
   282 0000E251 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
   282 0000E25A 69726563746F727920- <1>
   282 0000E263 6E616D652065786973- <1>
   282 0000E26C 747321              <1>
   283 0000E26F 0D0A00              <1>                 db 0Dh, 0Ah, 0
   284                              <1> Msg_DoYouWantMkdir:
   285 0000E272 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
   285 0000E27B 6E7420746F206D616B- <1>
   285 0000E284 65206469726563746F- <1>
   285 0000E28D 72792000            <1>
   286 0000E291 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
   286 0000E29A 00                  <1>
   287 0000E29B 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
   288 0000E29F 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
   289                              <1> 
   290                              <1> ; 27/02/2016
   291                              <1> Msg_DoYouWantRmDir:
   292 0000E2A5 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
   292 0000E2AE 6E7420746F2064656C- <1>
   292 0000E2B7 657465206469726563- <1>
   292 0000E2C0 746F72792000        <1>
   293                              <1> Msg_Dir_Not_Empty:
   294 0000E2C6 4469726563746F7279- <1>                 db "Directory not empty!"
   294 0000E2CF 206E6F7420656D7074- <1>
   294 0000E2D8 7921                <1>
   295 0000E2DA 0D0A00              <1>                 db 0Dh, 0Ah, 0
   296                              <1> 
   297                              <1> Msg_DoYouWantDelete:
   298 0000E2DD 446F20796F75207761- <1>                 db "Do you want to delete file ",0
   298 0000E2E6 6E7420746F2064656C- <1>
   298 0000E2EF 6574652066696C6520- <1>
   298 0000E2F8 00                  <1>
   299                              <1> 
   300 0000E2F9 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
   300 0000E302 2E0D0A00            <1>
   301                              <1> 
   302                              <1> Msg_Permission_Denied:
   303 0000E306 07                  <1>                 db 7
   304 0000E307 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
   304 0000E310 6E2064656E69656421- <1>
   304 0000E319 0D0A00              <1>
   305                              <1> 
   306                              <1> ; 04/03/2016
   307 0000E31C 4E657720            <1> Msg_New:        db "New "
   308 0000E320 00                  <1>                 db 0
   309                              <1> Str_Attributes:
   310 0000E321 417474726962757465- <1>                 db "Attributes : "
   310 0000E32A 73203A20            <1>
   311 0000E32E 4E4F524D414C        <1> Attr_Chars:     db "NORMAL"
   312 0000E334 00                  <1>                 db 0
   313                              <1> 
   314                              <1> ; 06/03/2016
   315                              <1> ; CMD_INTR.ASM - 16/11/2010 
   316                              <1> Msg_DoYouWantRename:
   317 0000E335 446F20796F75207761- <1>                 db "Do you want to rename ", 0
   317 0000E33E 6E7420746F2072656E- <1>
   317 0000E347 616D652000          <1>
   318 0000E34C 66696C652000        <1> Rename_File:    db "file ", 0
   319 0000E352 6469726563746F7279- <1> Rename_Directory: db "directory ", 0
   319 0000E35B 2000                <1>
   320 0000E35D 00<rept>            <1> Rename_OldName: times 13 db 0
   321 0000E36A 20617320            <1> Msg_File_rename_as: db " as "
   322 0000E36E 00<rept>            <1> Rename_NewName: times 13 db 0
   323                              <1> 
   324                              <1> ; 08/03/2016
   325                              <1> ; CMD_INTR.ASM - 01/08/2010 - 23/04/2011
   326                              <1> msg_not_same_drv:
   327 0000E37B 4E6F742073616D6520- <1>                 db "Not same drive!" 
   327 0000E384 647269766521        <1>
   328 0000E38A 0D0A00              <1>                 db 0Dh, 0Ah, 0 
   329                              <1> 
   330                              <1> Msg_DoYouWantMoveFile:
   331 0000E38D 446F20796F75207761- <1>                 db "Do you want to move file", 0
   331 0000E396 6E7420746F206D6F76- <1>
   331 0000E39F 652066696C6500      <1>
   332                              <1> 
   333                              <1> msg_insufficient_disk_space:
   334 0000E3A6 496E73756666696369- <1>                 db "Insufficient disk space!" 
   334 0000E3AF 656E74206469736B20- <1>
   334 0000E3B8 737061636521        <1>
   335 0000E3BE 0D0A00              <1>                 db 0Dh, 0Ah, 0
   336                              <1> 
   337                              <1> ; 01/08/2010
   338                              <1> msg_source_file: 
   339 0000E3C1 0D0A536F7572636520- <1> 		db 0Dh, 0Ah, "Source file name      :   "
   339 0000E3CA 66696C65206E616D65- <1>
   339 0000E3D3 2020202020203A2020- <1>
   339 0000E3DC 20                  <1>
   340                              <1> msg_source_file_drv: 
   341 0000E3DD 203A00              <1> 		db " :", 0
   342                              <1> msg_destination_file: 
   343 0000E3E0 0D0A44657374696E61- <1> 		db 0Dh, 0Ah, "Destination file name :   "
   343 0000E3E9 74696F6E2066696C65- <1>
   343 0000E3F2 206E616D65203A2020- <1>
   343 0000E3FB 20                  <1>
   344                              <1> msg_destination_file_drv: 
   345 0000E3FC 203A00              <1> 		db " :", 0
   346                              <1> msg_copy_nextline: 
   347 0000E3FF 0D0A00              <1> 		db 0Dh, 0Ah, 0
   348                              <1> 
   349                              <1> ; 15/03/2016
   350                              <1> ; CMD_INTR.ASM
   351                              <1> 
   352                              <1> Msg_DoYouWantOverWriteFile:
   353 0000E402 446F20796F75207761- <1>                 db "Do you want to overwrite file ",0
   353 0000E40B 6E7420746F206F7665- <1>
   353 0000E414 727772697465206669- <1>
   353 0000E41D 6C652000            <1>
   354                              <1>   
   355                              <1> Msg_DoYouWantCopyFile:
   356 0000E421 446F20796F75207761- <1>                 db "Do you want to copy file",0
   356 0000E42A 6E7420746F20636F70- <1>
   356 0000E433 792066696C6500      <1>
   357                              <1> 
   358                              <1> Msg_read_file_error_before_EOF:
   359 0000E43A 46696C652072656164- <1> 		db "File reading error! (before EOF)"
   359 0000E443 696E67206572726F72- <1>
   359 0000E44C 2120286265666F7265- <1>
   359 0000E455 20454F4629          <1>
   360 0000E45A 0A0A00              <1> 		db 0Ah, 0Ah, 0
   361                              <1> 
   362                              <1> ; 18/03/2016
   363                              <1> ; TRDOS 386 (v2.0) mainprog copy procedure
   364                              <1> msg_reading:
   365 0000E45D 52656164696E672E2E- <1> 		db "Reading... ", 0
   365 0000E466 2E2000              <1>
   366                              <1> msg_writing:
   367 0000E469 57726974696E672E2E- <1> 		db "Writing... ", 0
   367 0000E472 2E2000              <1>
   368                              <1> percentagestr:
   369 0000E475 2020202500          <1> 		db "   %", 0  ; "  0%" .. "100%"
   370                              <1> ; 11/04/2016
   371                              <1> Msg_No_Set_Space:
   372 0000E47A 496E73756666696369- <1>                 db "Insufficient environment space!"
   372 0000E483 656E7420656E766972- <1>
   372 0000E48C 6F6E6D656E74207370- <1>
   372 0000E495 61636521            <1>
   373 0000E499 0D0A00              <1>                 db 0Dh, 0Ah, 0
   374                              <1> ; 18/04/2016
   375                              <1> isc_msg:	
   376 0000E49C 0D0A                <1> 		db 0Dh, 0Ah
   377 0000E49E 494E56414C49442053- <1> 		db "INVALID SYSTEM CALL", 0
   377 0000E4A7 595354454D2043414C- <1>
   377 0000E4B0 4C00                <1>
   378                              <1> usi_msg:
   379 0000E4B2 0D0A                <1> 		db 0Dh, 0Ah
   380 0000E4B4 554E444546494E4544- <1> 		db "UNDEFINED SOFTWARE INTERRUPT", 0
   380 0000E4BD 20534F465457415245- <1>
   380 0000E4C6 20494E544552525550- <1>
   380 0000E4CF 5400                <1>
   381                              <1> ifc_msg:
   382 0000E4D1 0D0A                <1> 		db 0Dh, 0Ah
   383 0000E4D3 494E56414C49442046- <1> 		db "INVALID FUNCTION CALL"
   383 0000E4DC 554E4354494F4E2043- <1>
   383 0000E4E5 414C4C              <1>
   384                              <1> inv_msg_for_trdos_v2:
   385 0000E4E8 20                  <1> 		db 20h
   386 0000E4E9 666F72205452444F53- <1> 		db "for TRDOS v2!"
   386 0000E4F2 20763221            <1>
   387 0000E4F6 07                  <1> 		db 07h
   388 0000E4F7 0D0A                <1> 		db 0Dh, 0Ah
   389 0000E4F9 0D0A                <1> 		db 0Dh, 0Ah
   390 0000E4FB 494E5420            <1> 		db "INT "
   391 0000E4FF 303068              <1> int_num_str:	db "00h"
   392 0000E502 0D0A                <1> 		db 0Dh, 0Ah
   393 0000E504 454158203A20        <1> 		db "EAX : "
   394 0000E50A 303030303030303068- <1> eax_str:	db "00000000h", 0Dh, 0Ah
   394 0000E513 0D0A                <1>
   395 0000E515 454950203A20        <1> 		db "EIP : "
   396 0000E51B 303030303030303068- <1> eip_str:	db "00000000h", 0Dh, 0Ah, 0
   396 0000E524 0D0A00              <1>
   397                              <1> 		
  1927                                  
  1928                                  ; 15/04/2016
  1929                                  ; TRDOS 386 (TRDOS v2.0)
  1930                                  
  1931                                  ; 29/04/2016
  1932                                  int30h:
  1933                                  trdos_isc_routine:
  1934                                  	; 02/05/2016
  1935                                  	; 01/05/2016
  1936                                  	; 29/04/2016
  1937                                  	; 18/04/2016
  1938                                  	; 15/04/2016 (TRDOS 386 = TRDOS v2.0)
  1939                                  	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
  1940                                  	; 03/02/2011 ('trdos_ifc_routine')
  1941                                  	;
  1942 0000E527 8B1C24                  	mov	ebx, [esp] ; EIP (next)
  1943 0000E52A 83EB02                  	sub	ebx, 2 ; EIP (CD ##h)
  1944                                  
  1945 0000E52D 89C1                    	mov	ecx, eax
  1946 0000E52F 8A4301                  	mov	al, [ebx+1] ; CDh ##h
  1947                                  
  1948 0000E532 66BA1000                	mov	dx, KDATA
  1949 0000E536 8EDA                    	mov	ds, dx
  1950 0000E538 8EC2                    	mov	es, dx
  1951                                  
  1952 0000E53A FC                      	cld
  1953 0000E53B 8B15[C81F0100]          	mov	edx, [k_page_dir]
  1954 0000E541 0F22DA                  	mov	cr3, edx
  1955                                  
  1956 0000E544 E8EF47FFFF              	call	bytetohex
  1957 0000E549 66A3[FFE40000]          	mov	[int_num_str], ax
  1958                                  
  1959 0000E54F 89D8                    	mov	eax, ebx ; EIP
  1960 0000E551 E82248FFFF              	call	dwordtohex
  1961 0000E556 8915[1BE50000]          	mov	[eip_str], edx
  1962 0000E55C A3[1FE50000]            	mov	[eip_str+4], eax
  1963                                  
  1964 0000E561 89C8                    	mov	eax, ecx
  1965 0000E563 E81048FFFF              	call	dwordtohex
  1966 0000E568 8915[0AE50000]          	mov	[eax_str], edx
  1967 0000E56E A3[0EE50000]            	mov	[eax_str+4], eax 	
  1968                                  
  1969 0000E573 43                      	inc	ebx
  1970 0000E574 8A03                    	mov	al, [ebx] ; Interrupt number
  1971                                  
  1972                                  trdos_isc_handler:
  1973 0000E576 80FE30                  	cmp	dh, 30h ; Retro UNIX, SINGLIX System calls
  1974 0000E579 7507                    	jne	short trdos_usi_handler
  1975 0000E57B BE[9CE40000]            	mov	esi, isc_msg
  1976 0000E580 EB05                    	jmp	short loc_write_inv_system_call_msg
  1977                                  
  1978                                  trdos_usi_handler:
  1979 0000E582 BE[B2E40000]            	mov	esi, usi_msg
  1980                                  
  1981                                  loc_write_inv_system_call_msg:
  1982 0000E587 E8CA6FFFFF              	call	print_msg
  1983                                  	; 29/04/2016
  1984 0000E58C BE[E8E40000]            	mov	esi, inv_msg_for_trdos_v2
  1985 0000E591 E8C06FFFFF              	call	print_msg
  1986                                  
  1987                                  loc_ifc_terminate_process:
  1988                                  	; u.uno = process number
  1989                                  	; 29/04/2016
  1990                                  
  1991                                  	; 02/05/2016
  1992 0000E596 FE05[9F300100]          	inc	byte [sysflg] ; 0FFh -> 0
  1993                                  
  1994 0000E59C B801000000              	mov	eax, 1
  1995 0000E5A1 E987D1FFFF              	jmp	sysexit
  1996                                  
  1997                                  ; 07/03/2015
  1998                                  ; Temporary Code
  1999                                  display_disks:
  2000 0000E5A6 803D[18ED0000]00        	cmp 	byte [fd0_type], 0
  2001 0000E5AD 7605                    	jna 	short ddsks1
  2002 0000E5AF E87D000000              	call	pdskm
  2003                                  ddsks1:
  2004 0000E5B4 803D[19ED0000]00        	cmp	byte [fd1_type], 0
  2005 0000E5BB 760C                    	jna	short ddsks2
  2006 0000E5BD C605[9AEE0000]31        	mov	byte [dskx], '1'
  2007 0000E5C4 E868000000              	call	pdskm
  2008                                  ddsks2:
  2009 0000E5C9 803D[1AED0000]00        	cmp	byte [hd0_type], 0
  2010 0000E5D0 7654                    	jna	short ddsk6
  2011 0000E5D2 66C705[98EE0000]68-     	mov	word [dsktype], 'hd'
  2011 0000E5DA 64                 
  2012 0000E5DB C605[9AEE0000]30        	mov	byte [dskx], '0'
  2013 0000E5E2 E84A000000              	call	pdskm
  2014                                  ddsks3:
  2015 0000E5E7 803D[1BED0000]00        	cmp	byte [hd1_type], 0
  2016 0000E5EE 7636                    	jna	short ddsk6
  2017 0000E5F0 C605[9AEE0000]31        	mov	byte [dskx], '1'
  2018 0000E5F7 E835000000              	call	pdskm
  2019                                  ddsks4:
  2020 0000E5FC 803D[1CED0000]00        	cmp	byte [hd2_type], 0
  2021 0000E603 7621                    	jna	short ddsk6
  2022 0000E605 C605[9AEE0000]32        	mov	byte [dskx], '2'
  2023 0000E60C E820000000              	call	pdskm
  2024                                  ddsks5:
  2025 0000E611 803D[1DED0000]00        	cmp	byte [hd3_type], 0
  2026 0000E618 760C                    	jna	short ddsk6
  2027 0000E61A C605[9AEE0000]33        	mov	byte [dskx], '3'
  2028 0000E621 E80B000000              	call	pdskm
  2029                                  ddsk6:
  2030 0000E626 BE[ABEE0000]            	mov	esi, nextline
  2031 0000E62B E806000000              	call	pdskml
  2032                                  pdskm_ok:
  2033 0000E630 C3                      	retn
  2034                                  pdskm:
  2035 0000E631 BE[96EE0000]            	mov	esi, dsk_ready_msg
  2036                                  pdskml:	
  2037 0000E636 AC                      	lodsb
  2038 0000E637 08C0                    	or	al, al
  2039 0000E639 74F5                    	jz	short pdskm_ok
  2040 0000E63B 56                      	push	esi
  2041                                  	; 13/05/2016
  2042 0000E63C BB07000000                      mov     ebx, 7  ; Black background, 
  2043                                  			; light gray forecolor
  2044                                  			; Video page 0 (bh=0)
  2045 0000E641 E8DB34FFFF              	call	_write_tty
  2046 0000E646 5E                      	pop	esi
  2047 0000E647 EBED                    	jmp	short pdskml
  2048                                  
  2049 0000E649 90<rept>                align 16
  2050                                  
  2051                                  gdt:	; Global Descriptor Table
  2052                                  	; (30/07/2015, conforming cs)
  2053                                  	; (26/03/2015)
  2054                                  	; (24/03/2015, tss)
  2055                                  	; (19/03/2015)
  2056                                  	; (29/12/2013)
  2057                                  	;
  2058 0000E650 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
  2059                                  	; 18/08/2014
  2060                                  			; 8h kernel code segment, base = 00000000h		
  2061 0000E658 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
  2062                                  			; 10h kernel data segment, base = 00000000h	
  2063 0000E660 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
  2064                                  			; 1Bh user code segment, base address = 400000h ; CORE
  2065 0000E668 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE 
  2066                                  			; 23h user data segment, base address = 400000h ; CORE
  2067 0000E670 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
  2068                                  			; Task State Segment
  2069 0000E678 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
  2070                                  			       ;  no IO permission in ring 3)
  2071                                  gdt_tss0:
  2072 0000E67A 0000                    	dw 0  ; TSS base address, bits 0-15 
  2073                                  gdt_tss1:
  2074 0000E67C 00                      	db 0  ; TSS base address, bits 16-23 
  2075                                  	      		; 49h	
  2076 0000E67D E9                      	db 11101001b ; E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
  2077 0000E67E 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
  2078                                  gdt_tss2:
  2079 0000E67F 00                      	db 0  ; TSS base address, bits 24-31 
  2080                                  
  2081                                  gdt_end:
  2082                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  2083                                  					;; Type= 1 (code)/C=0/R=1/A=0
  2084                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  2085                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
  2086                                  
  2087                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  2088                                  					;; Type= 0 (data)/E=0/W=1/A=0
  2089                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  2090                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  2091                                  		; W= Writeable, A= Accessed
  2092                                  	
  2093                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
  2094                                  					;; Type= 1 (code)/C=0/R=1/A=0
  2095                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  2096                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
  2097                                  
  2098                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
  2099                                  					;; Type= 0 (data)/E=0/W=1/A=0
  2100                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  2101                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  2102                                  	
  2103                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
  2104                                  
  2105                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
  2106                                  		;	 = 100000h * 1000h (G=1) = 4GB
  2107                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
  2108                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
  2109                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
  2110                                  		; AVL= Available to programmers	
  2111                                  
  2112                                  gdtd:
  2113 0000E680 2F00                            dw gdt_end - gdt - 1    ; Limit (size)
  2114 0000E682 [50E60000]                      dd gdt			; Address of the GDT
  2115                                  
  2116                                  	; 20/08/2014
  2117                                  idtd:
  2118 0000E686 7F02                            dw idt_end - idt - 1    ; Limit (size)
  2119 0000E688 [E01C0100]                      dd idt			; Address of the IDT
  2120                                  
  2121                                  Align 4
  2122                                  	; 15/04/2016
  2123                                  	; TRDOS 386 (TRDOS v2.0)
  2124                                  
  2125                                  	; 21/08/2014
  2126                                  ilist:
  2127                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
  2128                                  	;
  2129                                  	; Exception list
  2130                                  	; 25/08/2014	
  2131 0000E68C [4B080000]              	dd	exc0	; 0h,  Divide-by-zero Error
  2132 0000E690 [52080000]              	dd	exc1	
  2133 0000E694 [59080000]              	dd 	exc2	
  2134 0000E698 [60080000]              	dd	exc3	
  2135 0000E69C [64080000]              	dd	exc4	
  2136 0000E6A0 [68080000]              	dd	exc5	
  2137 0000E6A4 [6C080000]              	dd 	exc6	; 06h,  Invalid Opcode
  2138 0000E6A8 [70080000]              	dd	exc7	
  2139 0000E6AC [74080000]              	dd	exc8	
  2140 0000E6B0 [78080000]              	dd	exc9	
  2141 0000E6B4 [7C080000]              	dd 	exc10	
  2142 0000E6B8 [80080000]              	dd	exc11
  2143 0000E6BC [84080000]              	dd	exc12
  2144 0000E6C0 [88080000]              	dd	exc13	; 0Dh, General Protection Fault
  2145 0000E6C4 [8C080000]              	dd 	exc14	; 0Eh, Page Fault
  2146 0000E6C8 [90080000]              	dd	exc15
  2147 0000E6CC [94080000]              	dd	exc16
  2148 0000E6D0 [98080000]              	dd	exc17
  2149 0000E6D4 [9C080000]              	dd 	exc18
  2150 0000E6D8 [A0080000]              	dd	exc19
  2151 0000E6DC [A4080000]              	dd 	exc20
  2152 0000E6E0 [A8080000]              	dd	exc21
  2153 0000E6E4 [AC080000]              	dd	exc22
  2154 0000E6E8 [B0080000]              	dd	exc23
  2155 0000E6EC [B4080000]              	dd 	exc24
  2156 0000E6F0 [B8080000]              	dd	exc25
  2157 0000E6F4 [BC080000]              	dd	exc26
  2158 0000E6F8 [C0080000]              	dd	exc27
  2159 0000E6FC [C4080000]              	dd 	exc28
  2160 0000E700 [C8080000]              	dd	exc29
  2161 0000E704 [CC080000]              	dd 	exc30
  2162 0000E708 [D0080000]              	dd	exc31
  2163                                  	; Interrupt list
  2164 0000E70C [40060000]              	dd	timer_int	; INT 20h
  2165                                  		;dd	irq0	
  2166 0000E710 [AC0C0000]              	dd	kb_int		; 24/01/2016
  2167                                  		;dd	irq1
  2168 0000E714 [A1070000]              	dd	irq2
  2169                                  		; COM2 int
  2170 0000E718 [A5070000]              	dd	irq3
  2171                                  		; COM1 int
  2172 0000E71C [B0070000]              	dd	irq4
  2173 0000E720 [BB070000]              	dd	irq5
  2174                                  ;DISKETTE_INT: ;06/02/2015
  2175 0000E724 [1F3C0000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
  2176                                  		;dd	irq6
  2177                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  2178                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  2179 0000E728 [AC0A0000]              	dd	default_irq7	; 25/02/2015
  2180                                  		;dd	irq7
  2181                                  ; Real Time Clock Interrupt
  2182 0000E72C [1D070000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
  2183                                  		;dd	irq8	; INT 28h
  2184 0000E730 [CB070000]              	dd	irq9
  2185 0000E734 [CF070000]              	dd	irq10
  2186 0000E738 [D3070000]              	dd	irq11
  2187 0000E73C [D7070000]              	dd	irq12
  2188 0000E740 [DB070000]              	dd	irq13
  2189                                  ;HDISK_INT1:  ;06/02/2015 	
  2190 0000E744 [99450000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
  2191                                  		;dd	irq14
  2192                                  ;HDISK_INT2:  ;06/02/2015
  2193 0000E748 [C0450000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
  2194                                  		;dd	irq15	; INT 2Fh
  2195                                  		; 14/08/2015
  2196                                  	;dd	sysent		; INT 30h (system calls)
  2197                                  
  2198                                  	; 15/04/2016
  2199                                  	; TRDOS 386(TRDOS v2.0) Software Interrupts
  2200                                  
  2201 0000E74C [27E50000]              	dd	int30h		; Reserved for
  2202                                  				; !!! Retro UNIX (RUNIX) !!!
  2203                                  				; !!! SINGLIX !!! System Calls
  2204 0000E750 [9F130000]              	dd	int31h		; Video BIOS (IBM PC/AT, Int 10h)
  2205 0000E754 [D40A0000]              	dd	int32h		; Keyboard Functions (IBM PC/AT, Int 16h)
  2206 0000E758 [D63C0000]              	dd	int33h		; DISK I/O (IBM PC/AT, Int 13h)
  2207 0000E75C [C8DB0000]              	dd	int34h		; #IOCTL# (I/O port access support for ring 3)
  2208 0000E760 [A0510000]              	dd	int35h		; Time/Date Functions (IBM PC/AT, Int 1Ah)
  2209 0000E764 [A1090000]              	dd	ignore_int	; INT 36h : Timer Functions	
  2210 0000E768 [A1090000]              	dd	ignore_int	; INT 37h	
  2211 0000E76C [A1090000]              	dd	ignore_int	; INT 38h
  2212 0000E770 [A1090000]              	dd	ignore_int	; INT 39h
  2213 0000E774 [A1090000]              	dd	ignore_int	; INT 3Ah	
  2214 0000E778 [A1090000]              	dd	ignore_int	; INT 3Bh
  2215 0000E77C [A1090000]              	dd	ignore_int	; INT 3Ch
  2216 0000E780 [A1090000]              	dd	ignore_int	; INT 3Dh	
  2217 0000E784 [A1090000]              	dd	ignore_int	; INT 3Eh
  2218 0000E788 [A1090000]              	dd	ignore_int	; INT 3Fh
  2219 0000E78C [1CB50000]              	dd	sysent		; INT 40h : !!! TRDOS 386 System Calls !!!
  2220                                  	;dd	ignore_int
  2221 0000E790 00000000                	dd	0
  2222                                  ;;;
  2223                                  ;;; 11/03/2015
  2224                                  %include 'kybdata.s'	; KEYBOARD (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - kybdata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 17/01/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; kybdata.inc (11/03/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - KYBDATA.INC
    20                              <1> ; Last Modification: 11/03/2015
    21                              <1> ;		 (Data Section for 'KEYBOARD.INC')	
    22                              <1> ;
    23                              <1> ; ///////// KEYBOARD DATA ///////////////
    24                              <1> 
    25                              <1> ; 05/12/2014
    26                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-) 
    27                              <1> ; 03/06/86  KEYBOARD BIOS
    28                              <1> 
    29                              <1> ;---------------------------------------------------------------------------------
    30                              <1> ;	KEY IDENTIFICATION SCAN TABLES
    31                              <1> ;---------------------------------------------------------------------------------
    32                              <1> 
    33                              <1> ;-----	TABLES FOR ALT CASE ------------
    34                              <1> ;-----	ALT-INPUT-TABLE 
    35 0000E794 524F50514B          <1> K30:	db	82,79,80,81,75
    36 0000E799 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
    37                              <1> ;-----	SUPER-SHIFT-TABLE 
    38 0000E79E 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
    39 0000E7A4 161718191E1F        <1> 	db	22,23,24,25,30,31
    40 0000E7AA 202122232425        <1> 	db	32,33,34,35,36,37
    41 0000E7B0 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
    42 0000E7B6 3132                <1> 	db	49,50
    43                              <1> 
    44                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
    45                              <1> ;-----	KEY_TABLE 
    46 0000E7B8 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
    47 0000E7B9 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
    48 0000E7BE 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
    49                              <1> _K6L    equ     $-_K6
    50                              <1> 
    51                              <1> ;-----	MASK_TABLE
    52 0000E7C0 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
    53 0000E7C1 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
    54 0000E7C6 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
    55                              <1> 
    56                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
    57 0000E7C8 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
    58 0000E7CE 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
    59 0000E7D4 FF7FFF111705        <1> 	db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
    60 0000E7DA 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
    61 0000E7E0 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
    62 0000E7E6 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
    63 0000E7EC 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
    64 0000E7F2 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
    65 0000E7F8 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
    66 0000E7FE 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
    67                              <1> 	;				;----- FUNCTIONS ------		
    68 0000E802 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
    69 0000E808 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
    70 0000E80E 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
    71 0000E814 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
    72 0000E81A 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
    73                              <1> 
    74                              <1> ;-----	TABLES FOR LOWER CASE ----------
    75 0000E820 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
    75 0000E829 39302D3D0809        <1>
    76 0000E82F 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
    76 0000E838 705B5D0DFF61736466- <1>
    76 0000E841 67686A6B6C3B27      <1>
    77 0000E848 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
    77 0000E851 6D2C2E2FFF2AFF20FF  <1>
    78                              <1> ;-----	LC TABLE SCAN
    79 0000E85A 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
    80 0000E85F 4041424344          <1> 	db	64,65,66,67,68
    81 0000E864 FFFF                <1> 	db	-1,-1			; NL, SL
    82                              <1> 
    83                              <1> ;-----	KEYPAD TABLE
    84 0000E866 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
    85 0000E86C 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
    86 0000E873 FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
    87                              <1> 
    88                              <1> ;-----	TABLES FOR UPPER CASE ----------
    89 0000E878 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
    89 0000E881 28295F2B0800        <1>
    90 0000E887 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
    90 0000E890 507B7D0DFF41534446- <1>
    90 0000E899 47484A4B4C3A22      <1>
    91 0000E8A0 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
    91 0000E8A9 4D3C3E3FFF2AFF20FF  <1>
    92                              <1> ;-----	UC TABLE SCAN
    93 0000E8B2 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
    94 0000E8B7 595A5B5C5D          <1> 	db	89,90,91,92,93
    95 0000E8BC FFFF                <1> 	db	-1,-1			; NL, SL
    96                              <1> 
    97                              <1> ;-----	NUM STATE TABLE
    98 0000E8BE 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
    98 0000E8C7 3233302E            <1>
    99                              <1> 	;
   100 0000E8CB FFFF7C8788          <1> 	db	-1,-1,124,135,136	; SysRq, Undef, WT, F11, F12
   101                              <1> 
   102                              <1> ; 26/08/2014
   103                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (03/03/2014)
   104                              <1> ; Derived from IBM "pc-at" 
   105                              <1> ; rombios source code (06/10/1985)
   106                              <1> ; 'dseg.inc'
   107                              <1> 
   108                              <1> ;---------------------------------------;
   109                              <1> ;	SYSTEM DATA AREA		;
   110                              <1> ;----------------------------------------
   111 0000E8D0 00                  <1> BIOS_BREAK	db	0		; BIT 7=1 IF BREAK KEY HAS BEEN PRESSED
   112                              <1> 
   113                              <1> ;----------------------------------------
   114                              <1> ;	KEYBOARD DATA AREAS		;
   115                              <1> ;----------------------------------------
   116                              <1> 
   117 0000E8D1 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
   118 0000E8D2 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
   119 0000E8D3 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
   120 0000E8D4 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
   121 0000E8D5 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
   122 0000E8D6 [E6E80000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
   123 0000E8DA [06E90000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
   124 0000E8DE [E6E80000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
   125 0000E8E2 [E6E80000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
   126                              <1> ; ------	HEAD = TAIL	INDICATES THAT THE BUFFER IS EMPTY
   127 0000E8E6 0000<rept>          <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
   128                              <1> 
   129                              <1> ; /// End Of KEYBOARD DATA ///
  2225                                  %include 'vidata.s'	; VIDEO (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vidata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 31/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; vidata.inc (11/03/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - VIDATA.S
    20                              <1> ; Last Modification: 11/03/2015
    21                              <1> ;		    (Data section for 'VIDEO.INC')	
    22                              <1> ;
    23                              <1> ; ///////// VIDEO DATA ///////////////
    24                              <1> 
    25                              <1> ;----------------------------------------
    26                              <1> ;	VIDEO DISPLAY DATA AREA		;
    27                              <1> ;----------------------------------------
    28 0000E906 03                  <1> CRT_MODE:	db	3	; CURRENT DISPLAY MODE (TYPE)
    29 0000E907 29                  <1> CRT_MODE_SET:	db	29h	; CURRENT SETTING OF THE 3X8 REGISTER
    30                              <1> 				; (29h default setting for video mode 3)
    31                              <1> 				; Mode Select register Bits
    32                              <1> 				;   BIT 0 - 80x25 (1), 40x25 (0)
    33                              <1> 				;   BIT 1 - ALPHA (0), 320x200 GRAPHICS (1)
    34                              <1> 				;   BIT 2 - COLOR (0), BW (1)
    35                              <1> 				;   BIT 3 - Video Sig. ENABLE (1), DISABLE (0)
    36                              <1> 				;   BIT 4 - 640x200 B&W Graphics Mode (1)
    37                              <1> 				;   BIT 5 - ALPHA mode BLINKING (1)
    38                              <1> 				;   BIT 6, 7 - Not Used
    39                              <1> 
    40                              <1> ; Mode 0 - 2Ch = 101100b	; 40x25 text, 16 gray colors
    41                              <1> ; Mode 1 - 28h = 101000b	; 40x25 text, 16 fore colors, 8 back colors
    42                              <1> ; Mode 2 - 2Dh = 101101b	; 80x25 text, 16 gray colors	
    43                              <1> ; Mode 3 - 29h = 101001b	; 80x25 text, 16 fore color, 8 back color
    44                              <1> ; Mode 4 - 2Ah = 101010b	; 320x200 graphics, 4 colors
    45                              <1> ; Mode 5 - 2Eh = 101110b	; 320x200 graphics, 4 gray colors
    46                              <1> ; Mode 6 - 1Eh = 011110b	; 640x200 graphics, 2 colors
    47                              <1> ; Mode 7 - 29h = 101001b	; 80x25 text, black & white colors
    48                              <1> ; Mode & 37h = Video signal OFF
    49                              <1> 
    50                              <1> ; 24/06/2016
    51 0000E908 50                  <1> CRT_COLS:	db	80	; Number of columns
    52                              <1> 
    53                              <1> ; 01/07/2016
    54 0000E909 00                  <1> CRT_PALETTE:	db 	0	; Current palette setting
    55                              <1> 
    56                              <1> ; 03/07/2016
    57 0000E90A 10                  <1> CHAR_HEIGHT:	db	16	; Default character height
    58 0000E90B 60                  <1> VGA_VIDEO_CTL:	db	60h	; ROM BIOS DATA AREA Offset 87h
    59 0000E90C F9                  <1> VGA_SWITCHES:	db 	0F9h	; Feature Bit Switches (the basic screen)
    60 0000E90D 51                  <1> VGA_MODESET_CTL: db	051h	; Basic mode set options (VGA video flags)
    61                              <1> 				; ROM BIOS DATA AREA Offset 89h
    62                              <1> 				; Bit 7, 4 : Mode
    63                              <1> 				;	  01 : 400-line mode
    64                              <1> 				; Bit 6	: Display switch enabled =  1			
    65                              <1> 				; Bit 5	: Reserved  = 0
    66                              <1> 				; Bit 3	: Default palette loading 
    67                              <1> 				;	  disabled = 0
    68                              <1> 				; Bit 2 : Color monitor = 0
    69                              <1> 				; Bit 1 = Gray scale summing 
    70                              <1> 				;	  disabled = 0
    71                              <1> 				; Bit 0 = VGA active = 1
    72 0000E90E 19                  <1> VGA_ROWS:	db	25
    73                              <1> 
    74                              <1> ; 16/01/2016
    75                              <1> chr_attrib:  ; Character color/attributes for viode pages (0 to 7)
    76 0000E90F 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
    77                              <1> ; 30/01/2016
    78                              <1> vmode:
    79 0000E917 0303030303030303    <1> 	db	3,3,3,3,3,3,3,3 ; video modes for pseudo screens 
    80                              <1> 
    81                              <1> CURSOR_MODE: ; cursor start (ch) = 14, cursor end (cl) = 15
    82 0000E91F 0F0E                <1> 	db	15, 14 ; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
    83                              <1> 
    84                              <1> ;align 4
    85                              <1> ;VGA_BASE: ; 26/07/2016
    86                              <1> ;	dd	 0B8000h  ; (Mode < 0Dh) or 0A0000h (mode >= 0Dh)
    87                              <1> 
    88 0000E921 90                  <1> align 2
    89                              <1> 
    90                              <1> vga_modes:
    91                              <1> 	; 25/07/2016
    92                              <1> 	; 09/07/2016
    93                              <1> 	; 03/07/2016
    94                              <1> 	; valid (implemented) video modes (>7, extension to IBM PC CGA modes)
    95 0000E922 0302010007040506    <1> 	db 	03h, 02h, 01h, 00h, 07h, 04h, 05h, 06h
    96                              <1> vga_g_modes: ; 31/07/2016
    97 0000E92A 13F0126A0D0E1011    <1> 	db	13h, 0F0h, 12h, 6Ah, 0Dh, 0Eh, 10h, 11h
    98                              <1> vga_mode_count equ $ - vga_modes
    99                              <1> vga_g_mode_count equ $ - vga_g_modes
   100                              <1> 
   101                              <1> vga_mode_tbl_ptr:
   102                              <1> 	; 25/07/2016
   103 0000E932 [92E90000]          <1> 	dd	vga_mode_03h
   104 0000E936 [92E90000]          <1> 	dd	vga_mode_03h ; mode 02h -> mode 03h 
   105 0000E93A [D2E90000]          <1> 	dd	vga_mode_01h
   106 0000E93E [D2E90000]          <1> 	dd	vga_mode_01h ; mode 00h -> mode 01h
   107                              <1> 	;dd	vga_mode_07h
   108 0000E942 [92E90000]          <1> 	dd	vga_mode_03h ; mode 07h -> mode 03h
   109 0000E946 [12EA0000]          <1> 	dd	vga_mode_04h
   110 0000E94A [12EA0000]          <1> 	dd	vga_mode_04h ; mode 05h -> mode 04h	
   111 0000E94E [52EA0000]          <1> 	dd	vga_mode_06h
   112 0000E952 [92EA0000]          <1> 	dd	vga_mode_13h
   113 0000E956 [D2EA0000]          <1> 	dd	vga_mode_F0h
   114 0000E95A [12EB0000]          <1> 	dd	vga_mode_12h
   115 0000E95E [52EB0000]          <1> 	dd	vga_mode_6Ah
   116 0000E962 [92EB0000]          <1> 	dd	vga_mode_0Dh
   117 0000E966 [D2EB0000]          <1> 	dd	vga_mode_0Eh
   118 0000E96A [12EC0000]          <1> 	dd	vga_mode_10h
   119 0000E96E [52EC0000]          <1> 	dd	vga_mode_11h	
   120                              <1> 
   121                              <1> vga_memmodel: 
   122                              <1> 	; 25/07/2016
   123                              <1> 	; 07/07/2016
   124                              <1> 	CTEXT	equ 0
   125                              <1> 	;MTEXT	equ 1
   126                              <1> 	MTEXT	equ 0 ; mode 07h -> mode 03h
   127                              <1> 	CGA	equ 2
   128                              <1> 	LINEAR8 equ 5
   129                              <1> 	PLANAR4	equ 4
   130                              <1> 	PLANAR1	equ 3
   131 0000E972 0000000000020202    <1> 	db	CTEXT, CTEXT, CTEXT, CTEXT, MTEXT, CGA, CGA, CGA
   132                              <1> vga_g_memmodel: ; 31/07/2016
   133 0000E97A 0504040404040403    <1> 	db	LINEAR8, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR4, PLANAR1
   134                              <1> ;vga_pixbits:
   135                              <1> ;	; 25/07/2016
   136                              <1> ;	; 08/07/2016
   137                              <1> ;	db 	4, 4, 4, 4, 4, 2, 2, 1, 8, 4, 4, 4, 4, 4, 4, 1
   138                              <1> vga_dac_s:
   139 0000E982 020202020001010103- <1> 	db	2, 2, 2, 2, 0, 1, 1, 1, 3, 3, 2, 2, 1, 1, 2, 2
   139 0000E98B 03020201010202      <1>
   140                              <1> 
   141                              <1> vga_params:
   142                              <1> 	; 25/07/2016 
   143                              <1> 	; 19/07/2016
   144                              <1> 	; 03/07/2016
   145                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   146                              <1> 	; vgabios-0.7a (2011)
   147                              <1> 	; by the LGPL VGABios Developers Team (2001-2008)
   148                              <1> 	; 'vgatables.h'
   149                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
   150                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
   151                              <1> 	;
   152                              <1> vga_mode_03h:  ; mode 03h, 80*25 text, CGA colors
   153 0000E992 5018100010          <1>  	db	80, 24, 16, 00h, 10h ; tw, th-1, ch, slength (5)
   154 0000E997 00030002            <1>  	db	00h, 03h, 00h, 02h ; sequ regs (4)
   155 0000E99B 67                  <1>  	db	67h	; misc reg (1)
   156 0000E99C 5F4F50825581BF1F    <1>  	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
   157 0000E9A4 004F                <1>  	db	00h, 4Fh
   158                              <1> vga_p_cm_pos equ $ - vga_mode_03h
   159 0000E9A6 0D0E00000000        <1> 	db	0Dh, 0Eh, 00h, 00h, 00h, 00h
   160 0000E9AC 9C8E8F281F96B9A3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 1Fh, 96h, 0B9h, 0A3h
   161 0000E9B4 FF                  <1> 	db	0FFh	; crtc_regs (25)
   162 0000E9B5 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   163 0000E9BD 38393A3B3C3D3E3F    <1>  	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   164 0000E9C5 0C000F08            <1>  	db	0Ch, 00h, 0Fh, 08h  ; actl regs (20)
   165 0000E9C9 0000000000100E0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs (9)
   166                              <1> vga_mode_01h:	; mode 01h, 40*25 text, CGA colors
   167 0000E9D2 2818100008          <1> 	db	40, 24, 16, 00h, 08h ; tw, th-1, ch, slength
   168 0000E9D7 08030002            <1> 	db	08h, 03h, 00h, 02h  ; sequ regs
   169 0000E9DB 67                  <1> 	db	67h	; misc reg
   170 0000E9DC 2D2728902BA0BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 0A0h, 0BFh, 1Fh
   171 0000E9E4 004F0D0E00000000    <1> 	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
   172 0000E9EC 9C8E8F141F96B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 1Fh, 96h, 0B9h, 0A3h
   173 0000E9F4 FF                  <1> 	db	0FFh	; crtc_regs
   174 0000E9F5 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   175 0000E9FD 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   176 0000EA05 0C000F08            <1> 	db	0Ch, 00h, 0Fh, 08h  ; actl regs
   177 0000EA09 0000000000100E0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs
   178                              <1> ;vga_mode_07h:	; mode 07h, 80*25 text, mono color
   179                              <1> ;	db	80, 24, 16, 00h, 10h  ; tw, th-1, ch, slength
   180                              <1> ;	db	00h, 03h, 00h, 02h ; sequ regs
   181                              <1> ;	db	66h	; misc reg
   182                              <1> ;	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
   183                              <1> ;	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
   184                              <1> ;	db	9Ch, 8Eh, 8Fh, 28h, 0Fh, 96h, 0B9h, 0A3h
   185                              <1> ;	db	0FFh	; crtc regs
   186                              <1> ;	db	00h, 08h, 08h, 08h, 08h, 08h, 08h, 08h
   187                              <1> ;	db	10h, 18h, 18h, 18h, 18h, 18h, 18h, 18h
   188                              <1> ;	db	0Eh, 00h, 0Fh, 08h  ; actl regs
   189                              <1> ;	db	00h, 00h, 00h, 00h, 00h, 10h, 0Ah, 0Fh, 0FFh ; grdc regs
   190                              <1> vga_mode_04h:	; 320*200 graphics, 4 colors, CGA
   191 0000EA12 2818080008          <1> 	db	40, 24, 8, 00h, 08h   ; tw, th-1, ch, slength
   192 0000EA17 09030002            <1> 	db	09h, 03h, 00h, 02h ; sequ regs
   193 0000EA1B 63                  <1> 	db	63h	; misc reg
   194 0000EA1C 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   195 0000EA24 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   196 0000EA2C 9C8E8F140096B9A2    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0A2h
   197 0000EA34 FF                  <1> 	db	0FFh	; crtc_regs
   198 0000EA35 0013151702040607    <1> 	db	00h, 13h, 15h, 17h, 02h, 04h, 06h, 07h
   199 0000EA3D 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   200 0000EA45 01000300            <1> 	db	01h, 00h, 03h, 00h ; actl regs
   201 0000EA49 0000000000300F0FFF  <1> 	db 	00h, 00h, 00h, 00h, 00h, 30h, 0Fh, 0Fh, 0FFh ; grdc regs
   202                              <1> vga_mode_06h:	; 640*200 graphics, 2 colors, CGA
   203 0000EA52 5018080010          <1> 	db	80, 24, 8, 00h, 10h   ;	tw, th-1, ch, slength
   204 0000EA57 01010006            <1> 	db	01h, 01h, 00h, 06h ; sequ regs
   205 0000EA5B 63                  <1> 	db	63h	; misc reg
   206 0000EA5C 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   207 0000EA64 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   208 0000EA6C 9C8E8F280096B9C2    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0C2h
   209 0000EA74 FF                  <1> 	db	0FFh	; crtc regs
   210 0000EA75 0017171717171717    <1> 	db	00h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   211 0000EA7D 1717171717171717    <1> 	db	17h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   212 0000EA85 01000100            <1> 	db	01h, 00h, 01, 00h  ; actl regs
   213 0000EA89 0000000000000D0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 0Dh, 0Fh, 0FFh ; grdc regs
   214                              <1> vga_mode_13h:  ; mode 13h, 300*200, 256 colors, linear
   215 0000EA92 2818080000          <1> 	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength (5)
   216 0000EA97 010F000E            <1> 	db	01h, 0Fh, 00h, 0Eh ; sequ regs (4)
   217 0000EA9B 63                  <1> 	db	63h	; misc reg (1)
   218 0000EA9C 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh 
   219 0000EAA4 0041000000000000    <1>  	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
   220 0000EAAC 9C8E8F284096B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 40h, 96h, 0B9h, 0A3h
   221 0000EAB4 FF                  <1> 	db	0FFh	; crtc regs (25)
   222 0000EAB5 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   223 0000EABD 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   224 0000EAC5 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs (20)
   225 0000EAC9 000000000040050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs (9)
   226                              <1> vga_mode_setl equ $ - vga_mode_13h  ; = 64
   227                              <1> vga_mode_F0h:  ; mode X ; 320*240, 256 colors, planar
   228 0000EAD2 2818080000          <1> 	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength
   229 0000EAD7 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   230 0000EADB E3                  <1> 	db	0E3h	; misc reg
   231 0000EADC 5F4F508254800D3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Dh, 3Eh 
   232 0000EAE4 0041000000000000    <1>  	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
   233 0000EAEC EAACDF2800E706E3    <1> 	db	0EAh, 0ACh, 0DFh, 28h, 00h, 0E7h, 06h, 0E3h
   234 0000EAF4 FF                  <1> 	db	0FFh	; crtc regs (25)
   235 0000EAF5 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   236 0000EAFD 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   237 0000EB05 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs
   238 0000EB09 000000000040050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs
   239                              <1> vga_mode_12h:  ; mode 12h, 640*480, 16 colors, planar
   240 0000EB12 501D100000          <1>  	db 	80, 29, 16, 0, 0 ; tw, th-1, ch, slength
   241 0000EB17 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   242 0000EB1B E3                  <1> 	db 	0E3h	; misc reg
   243 0000EB1C 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   244 0000EB24 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   245 0000EB2C EA8CDF2800E704E3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   246 0000EB34 FF                  <1> 	db	0FFh	; crtc regs
   247 0000EB35 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   248 0000EB3D 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   249 0000EB45 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   250 0000EB49 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   251                              <1> vga_mode_6Ah:  ; mode 6Ah, 800*600, 16 colors, planar
   252 0000EB52 6424100000          <1>  	db 	100, 36, 16, 0, 0 ; tw, th-1, ch, slength
   253 0000EB57 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   254 0000EB5B E3                  <1> 	db 	0E3h	; misc reg
   255 0000EB5C 7F6363836B1B72F0    <1> 	db	7Fh, 63h, 63h, 83h, 6Bh, 1Bh, 72h, 0F0h
   256 0000EB64 0060000000000000    <1> 	db	00h, 60h, 00h, 00h, 00h, 00h, 00h, 00h
   257 0000EB6C 598D5732005773E3    <1>  	db	59h, 8Dh, 57h, 32h, 00h, 57h, 73h, 0E3h
   258 0000EB74 FF                  <1> 	db	0FFh	; crtc regs
   259 0000EB75 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   260 0000EB7D 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   261 0000EB85 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   262 0000EB89 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   263                              <1> vga_mode_0Dh:  ; mode 0Dh, 320*200, 16 colors, planar
   264 0000EB92 2818080020          <1>  	db 	40, 24, 8, 0, 20h ; tw, th-1, ch, slength
   265 0000EB97 090F0006            <1> 	db	09h, 0Fh, 00h, 06h ; sequ regs
   266 0000EB9B 63                  <1> 	db 	63h	; misc reg
   267 0000EB9C 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   268 0000EBA4 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   269 0000EBAC 9C8E8F140096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0E3h
   270 0000EBB4 FF                  <1> 	db	0FFh	; crtc regs
   271 0000EBB5 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   272 0000EBBD 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   273 0000EBC5 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   274 0000EBC9 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   275                              <1> vga_mode_0Eh:  ; mode 0Eh, 640*200, 16 colors, planar
   276 0000EBD2 5018080040          <1>  	db 	80, 24, 8, 0, 40h ; tw, th-1, ch, slength
   277 0000EBD7 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   278 0000EBDB 63                  <1> 	db 	63h	; misc reg
   279 0000EBDC 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   280 0000EBE4 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   281 0000EBEC 9C8E8F280096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0E3h
   282 0000EBF4 FF                  <1> 	db	0FFh	; crtc regs
   283 0000EBF5 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   284 0000EBFD 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   285 0000EC05 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   286 0000EC09 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   287                              <1> vga_mode_10h: ; mode 10h, 640*350, 16 colors, planar
   288 0000EC12 50180E0080          <1>  	db 	80, 24, 14, 0, 80h ; tw, th-1, ch, slength
   289 0000EC17 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   290 0000EC1B A3                  <1> 	db 	0A3h	; misc reg
   291 0000EC1C 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   292 0000EC24 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   293 0000EC2C 83855D280F63BAE3    <1>  	db	83h, 85h, 5Dh, 28h, 0Fh, 63h, 0BAh, 0E3h
   294 0000EC34 FF                  <1> 	db	0FFh	; crtc regs
   295 0000EC35 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   296 0000EC3D 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   297 0000EC45 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   298 0000EC49 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   299                              <1> vga_mode_11h: ; mode 11h, 640*480, mono color, planar
   300 0000EC52 501D100000          <1>  	db 	80, 29, 16, 0, 0   ; tw, th-1, ch, slength
   301 0000EC57 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   302 0000EC5B E3                  <1> 	db 	0E3h	; misc reg
   303 0000EC5C 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   304 0000EC64 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   305 0000EC6C EA8CDF2800E704E3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   306 0000EC74 FF                  <1> 	db	0FFh	; crtc regs
   307 0000EC75 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   308 0000EC7D 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   309 0000EC85 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   310 0000EC89 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   311                              <1> end_of_vga_params:
   312                              <1> 
   313                              <1> ; /// End Of VIDEO DATA ///
  2226                                  %include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskdata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 24/01/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; diskdata.inc (11/03/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - DISKDATA.INC
    20                              <1> ; Last Modification: 11/03/2015
    21                              <1> ;	(Initialized Disk Parameters Data section for 'DISKIO.INC') 
    22                              <1> ;
    23                              <1> 
    24                              <1> ;----------------------------------------
    25                              <1> ;	80286 INTERRUPT LOCATIONS	:
    26                              <1> ;	REFERENCED BY POST & BIOS	:
    27                              <1> ;----------------------------------------
    28                              <1> 
    29 0000EC92 [F5EC0000]          <1> DISK_POINTER:	dd	MD_TBL6		; Pointer to Diskette Parameter Table
    30                              <1> 
    31                              <1> ; IBM PC-XT Model 286 source code ORGS.ASM (06/10/85) - 14/12/2014
    32                              <1> ;----------------------------------------------------------------
    33                              <1> ; DISK_BASE							:
    34                              <1> ;	THIS IS THE SET OF PARAMETERS REQUIRED FOR		:
    35                              <1> ;	DISKETTE OPERATION. THEY ARE POINTED AT BY THE		:
    36                              <1> ;	DATA VARIABLE @DISK_POINTER. TO MODIFY THE PARAMETERS,	:
    37                              <1> ;	BUILD ANOTHER PARAMETER BLOCK AND POINT AT IT		:
    38                              <1> ;----------------------------------------------------------------
    39                              <1> 
    40                              <1> ;DISK_BASE:	
    41                              <1> ;	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
    42                              <1> ;	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
    43                              <1> ;	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
    44                              <1> ;	DB	2		; 512 BYTES/SECTOR
    45                              <1> ;	;DB	15		; EOT (LAST SECTOR ON TRACK)
    46                              <1> ;	db	18		; (EOT for 1.44MB diskette)
    47                              <1> ;	DB	01BH		; GAP LENGTH
    48                              <1> ;	DB	0FFH		; DTL
    49                              <1> ;	;DB	054H		; GAP LENGTH FOR FORMAT
    50                              <1> ;	db	06ch		; (for 1.44MB dsikette)
    51                              <1> ;	DB	0F6H		; FILL BYTE FOR FORMAT
    52                              <1> ;	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
    53                              <1> ;	DB	8		; MOTOR START TIME (1/8 SECONDS)
    54                              <1> 
    55                              <1> ;----------------------------------------
    56                              <1> ;	ROM BIOS DATA AREAS		:
    57                              <1> ;----------------------------------------
    58                              <1> 
    59                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
    60                              <1> 
    61                              <1> ;@EQUIP_FLAG	DW	?		; INSTALLED HARDWARE FLAGS
    62                              <1> 
    63                              <1> ;----------------------------------------
    64                              <1> ;	DISKETTE DATA AREAS		:
    65                              <1> ;----------------------------------------
    66                              <1> 
    67                              <1> ;@SEEK_STATUS	DB	?		; DRIVE RECALIBRATION STATUS
    68                              <1> ;					; BIT 3-0 = DRIVE 3-0 RECALIBRATION
    69                              <1> ;					; BEFORE NEXT SEEK IF BIT IS = 0
    70                              <1> ;@MOTOR_STATUS	DB	?		; MOTOR STATUS
    71                              <1> ;					; BIT 3-0 = DRIVE 3-0 CURRENTLY RUNNING
    72                              <1> ;					; BIT 7 = CURRENT OPERATION IS A WRITE
    73                              <1> ;@MOTOR_COUNT	DB	?		; TIME OUT COUNTER FOR MOTOR(S) TURN OFF
    74                              <1> ;@DSKETTE_STATUS DB	?		; RETURN CODE STATUS BYTE
    75                              <1> ;					; CMD_BLOCK  IN STACK FOR DISK OPERATION
    76                              <1> ;@NEC_STATUS	DB	7 DUP(?)	; STATUS BYTES FROM DISKETTE OPERATION
    77                              <1> 
    78                              <1> ;----------------------------------------
    79                              <1> ;	POST AND BIOS WORK DATA AREA	:
    80                              <1> ;----------------------------------------
    81                              <1> 
    82                              <1> ;@INTR_FLAG	DB	?		; FLAG INDICATING AN INTERRUPT HAPPENED
    83                              <1> 
    84                              <1> ;----------------------------------------
    85                              <1> ;	TIMER DATA AREA 		:
    86                              <1> ;----------------------------------------
    87                              <1> 
    88                              <1> ; 17/12/2014  (IRQ 0 - INT 08H)
    89                              <1> ;TIMER_LOW	equ	46Ch		; Timer ticks (counter)  @ 40h:006Ch
    90                              <1> ;TIMER_HIGH	equ	46Eh		; (18.2 timer ticks per second)
    91                              <1> ;TIMER_OFL	equ	470h		; Timer - 24 hours flag  @ 40h:0070h
    92                              <1> 
    93                              <1> ;----------------------------------------
    94                              <1> ;	ADDITIONAL MEDIA DATA		:
    95                              <1> ;----------------------------------------
    96                              <1> 
    97                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
    98                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
    99                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
   100                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
   101                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
   102                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
   103                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
   104                              <1> 
   105                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
   106                              <1> 
   107                              <1> ;--------------------------------------------------------
   108                              <1> ;	DRIVE TYPE TABLE				:
   109                              <1> ;--------------------------------------------------------
   110                              <1> 		; 16/02/2015 (unix386.s, 32 bit modifications)
   111                              <1> DR_TYPE:
   112 0000EC96 01                  <1> 		DB	01		;DRIVE TYPE, MEDIA TABLE
   113                              <1>                 ;DW      MD_TBL1
   114 0000EC97 [B4EC0000]          <1> 		dd	MD_TBL1
   115 0000EC9B 82                  <1> 		DB	02+BIT7ON
   116                              <1> 		;DW      MD_TBL2
   117 0000EC9C [C1EC0000]          <1>                 dd      MD_TBL2
   118 0000ECA0 02                  <1> DR_DEFAULT:	DB	02
   119                              <1>                 ;DW      MD_TBL3
   120 0000ECA1 [CEEC0000]          <1> 		dd      MD_TBL3
   121 0000ECA5 03                  <1> 		DB	03
   122                              <1>                 ;DW      MD_TBL4
   123 0000ECA6 [DBEC0000]          <1> 		dd      MD_TBL4
   124 0000ECAA 84                  <1> 		DB	04+BIT7ON
   125                              <1>                 ;DW      MD_TBL5
   126 0000ECAB [E8EC0000]          <1> 		dd      MD_TBL5
   127 0000ECAF 04                  <1> 		DB	04
   128                              <1>                 ;DW      MD_TBL6
   129 0000ECB0 [F5EC0000]          <1> 		dd      MD_TBL6
   130                              <1> DR_TYPE_E       equ $                   ; END OF TABLE
   131                              <1> ;DR_CNT		EQU	(DR_TYPE_E-DR_TYPE)/3
   132                              <1> DR_CNT		equ	(DR_TYPE_E-DR_TYPE)/5
   133                              <1> ;--------------------------------------------------------
   134                              <1> ;	MEDIA/DRIVE PARAMETER TABLES			:
   135                              <1> ;--------------------------------------------------------
   136                              <1> ;--------------------------------------------------------
   137                              <1> ;	360 KB MEDIA IN 360 KB DRIVE			:
   138                              <1> ;--------------------------------------------------------
   139                              <1> MD_TBL1:        
   140 0000ECB4 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   141 0000ECB5 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   142 0000ECB6 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   143 0000ECB7 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   144 0000ECB8 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   145 0000ECB9 2A                  <1> 	DB	02AH		; GAP LENGTH
   146 0000ECBA FF                  <1> 	DB	0FFH		; DTL
   147 0000ECBB 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   148 0000ECBC F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   149 0000ECBD 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   150 0000ECBE 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   151 0000ECBF 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   152 0000ECC0 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
   153                              <1> ;--------------------------------------------------------
   154                              <1> ;	360 KB MEDIA IN 1.2 MB DRIVE			:
   155                              <1> ;--------------------------------------------------------
   156                              <1> MD_TBL2:        
   157 0000ECC1 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   158 0000ECC2 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   159 0000ECC3 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   160 0000ECC4 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   161 0000ECC5 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   162 0000ECC6 2A                  <1> 	DB	02AH		; GAP LENGTH
   163 0000ECC7 FF                  <1> 	DB	0FFH		; DTL
   164 0000ECC8 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   165 0000ECC9 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   166 0000ECCA 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   167 0000ECCB 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   168 0000ECCC 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   169 0000ECCD 40                  <1> 	DB	RATE_300	; DATA TRANSFER RATE
   170                              <1> ;--------------------------------------------------------
   171                              <1> ;	1.2 MB MEDIA IN 1.2 MB DRIVE			:
   172                              <1> ;--------------------------------------------------------
   173                              <1> MD_TBL3:
   174 0000ECCE DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   175 0000ECCF 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   176 0000ECD0 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   177 0000ECD1 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   178 0000ECD2 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
   179 0000ECD3 1B                  <1> 	DB	01BH		; GAP LENGTH
   180 0000ECD4 FF                  <1> 	DB	0FFH		; DTL
   181 0000ECD5 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
   182 0000ECD6 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   183 0000ECD7 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   184 0000ECD8 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   185 0000ECD9 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   186 0000ECDA 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
   187                              <1> ;--------------------------------------------------------
   188                              <1> ;	720 KB MEDIA IN 720 KB DRIVE			:
   189                              <1> ;--------------------------------------------------------
   190                              <1> MD_TBL4:
   191 0000ECDB DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   192 0000ECDC 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   193 0000ECDD 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   194 0000ECDE 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   195 0000ECDF 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   196 0000ECE0 2A                  <1> 	DB	02AH		; GAP LENGTH
   197 0000ECE1 FF                  <1> 	DB	0FFH		; DTL
   198 0000ECE2 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   199 0000ECE3 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   200 0000ECE4 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   201 0000ECE5 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   202 0000ECE6 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   203 0000ECE7 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
   204                              <1> ;--------------------------------------------------------
   205                              <1> ;	720 KB MEDIA IN 1.44 MB DRIVE			:
   206                              <1> ;--------------------------------------------------------
   207                              <1> MD_TBL5:
   208 0000ECE8 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   209 0000ECE9 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   210 0000ECEA 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   211 0000ECEB 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   212 0000ECEC 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   213 0000ECED 2A                  <1> 	DB	02AH		; GAP LENGTH
   214 0000ECEE FF                  <1> 	DB	0FFH		; DTL
   215 0000ECEF 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   216 0000ECF0 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   217 0000ECF1 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   218 0000ECF2 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   219 0000ECF3 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   220 0000ECF4 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
   221                              <1> ;--------------------------------------------------------
   222                              <1> ;	1.44 MB MEDIA IN 1.44 MB DRIVE			:
   223                              <1> ;--------------------------------------------------------
   224                              <1> MD_TBL6:
   225 0000ECF5 AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
   226 0000ECF6 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   227 0000ECF7 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   228 0000ECF8 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   229 0000ECF9 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
   230 0000ECFA 1B                  <1> 	DB	01BH		; GAP LENGTH
   231 0000ECFB FF                  <1> 	DB	0FFH		; DTL
   232 0000ECFC 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
   233 0000ECFD F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   234 0000ECFE 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   235 0000ECFF 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   236 0000ED00 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   237 0000ED01 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
   238                              <1> 
   239                              <1> 
   240                              <1> ; << diskette.inc >>
   241                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   242                              <1> ;
   243                              <1> ;----------------------------------------
   244                              <1> ;	ROM BIOS DATA AREAS		:
   245                              <1> ;----------------------------------------
   246                              <1> 
   247                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
   248                              <1> 
   249                              <1> ;----------------------------------------
   250                              <1> ;	FIXED DISK DATA AREAS		:
   251                              <1> ;----------------------------------------
   252                              <1> 
   253                              <1> ;DISK_STATUS1:	DB	0		; FIXED DISK STATUS
   254                              <1> ;HF_NUM:		DB	0		; COUNT OF FIXED DISK DRIVES
   255                              <1> ;CONTROL_BYTE:	DB	0		; HEAD CONTROL BYTE
   256                              <1> ;@PORT_OFF	DB	?		;  RESERVED (PORT OFFSET)
   257                              <1> 
   258                              <1> ;----------------------------------------
   259                              <1> ;	ADDITIONAL MEDIA DATA		:
   260                              <1> ;----------------------------------------
   261                              <1> 
   262                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
   263                              <1> ;HF_STATUS	DB	0		; STATUS REGISTER
   264                              <1> ;HF_ERROR	DB	0		; ERROR REGISTER
   265                              <1> ;HF_INT_FLAG	DB	0		; FIXED DISK INTERRUPT FLAG
   266                              <1> ;HF_CNTRL	DB	0		; COMBO FIXED DISK/DISKETTE CARD BIT 0=1
   267                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
   268                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
   269                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
   270                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
   271                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
   272                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
   273                              <1> 
   274                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
   275                              <1> ;
   276                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   277                              <1> 
   278                              <1> ERR_TBL:
   279 0000ED02 E0                  <1> 	db	NO_ERR
   280 0000ED03 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
   281 0000ED07 04BB100A            <1> 	db	RECORD_NOT_FND,UNDEF_ERR,BAD_ECC,BAD_SECTOR
   282                              <1> 
   283                              <1> ; 17/12/2014 (mov ax, [cfd])
   284                              <1> ; 11/12/2014
   285 0000ED0B 00                  <1> cfd:		db 0			; current floppy drive (for GET_PARM)
   286                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
   287 0000ED0C 01                  <1> pfd:		db 1			; previous floppy drive (for GET_PARM)
   288                              <1> 					; (initial value of 'pfd 
   289                              <1> 					; must be different then 'cfd' value
   290                              <1> 					; to force updating/initializing
   291                              <1> 					; current drive parameters) 
   292 0000ED0D 90                  <1> align 2
   293                              <1> 
   294 0000ED0E F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
   295                              <1> 			      ; (170h)
   296 0000ED10 F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
   297                              <1> 
   298                              <1> ; 05/01/2015 
   299 0000ED12 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
   300                              <1> 
   301                              <1> ; *****************************************************************************
  2227                                  ;;;
  2228                                  
  2229 0000ED13 90                      Align 2
  2230                                  
  2231                                  ; 12/11/2014 (Retro UNIX 386 v1)
  2232 0000ED14 00                      boot_drv:    db 0 ; boot drive number (physical)
  2233                                  ; 24/11/2014
  2234 0000ED15 00                      drv:	     db 0 
  2235 0000ED16 00                      last_drv:    db 0 ; last hdd
  2236 0000ED17 00                      hdc:         db 0  ; number of hard disk drives
  2237                                  		     ; (present/detected)
  2238                                  ;
  2239                                  ; 24/11/2014 (Retro UNIX 386 v1)
  2240                                  ; Physical drive type & flags
  2241 0000ED18 00                      fd0_type:    db 0  ; floppy drive type
  2242 0000ED19 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
  2243                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
  2244                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
  2245                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
  2246                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
  2247 0000ED1A 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
  2248 0000ED1B 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
  2249 0000ED1C 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
  2250 0000ED1D 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
  2251                                  		     ; bit 0 - Fixed disk access subset supported
  2252                                  		     ; bit 1 - Drive locking and ejecting
  2253                                  		     ; bit 2 - Enhanced disk drive support
  2254                                  		     ; bit 3 = Reserved (64 bit EDD support)
  2255                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
  2256                                  		     ; will interpret it as 'LBA ready'!)		
  2257                                  
  2258                                  ; 11/03/2015 - 10/07/2015
  2259 0000ED1E 000000000000000000-     drv.cylinders: dw 0,0,0,0,0,0,0
  2259 0000ED27 0000000000         
  2260 0000ED2C 000000000000000000-     drv.heads:     dw 0,0,0,0,0,0,0
  2260 0000ED35 0000000000         
  2261 0000ED3A 000000000000000000-     drv.spt:       dw 0,0,0,0,0,0,0
  2261 0000ED43 0000000000         
  2262 0000ED48 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
  2262 0000ED51 000000000000000000-
  2262 0000ED5A 000000000000000000-
  2262 0000ED63 00                 
  2263 0000ED64 00000000000000          drv.status:    db 0,0,0,0,0,0,0
  2264 0000ED6B 00000000000000          drv.error:     db 0,0,0,0,0,0,0		
  2265                                  ;
  2266                                  
  2267                                  ; 27/08/2014
  2268                                  scr_row:
  2269 0000ED72 E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
  2270                                  scr_col:
  2271 0000ED76 00000000                	dd 0
  2272                                  
  2273                                  ; 20/08/2014
  2274                                    ; /* This is the default interrupt "handler" :-) */ 
  2275                                    ; Linux v0.12 (head.s)
  2276                                  int_msg:
  2277 0000ED7A 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
  2277 0000ED83 6E7465727275707420-
  2277 0000ED8C 212000             
  2278                                  
  2279 0000ED8F 90                      Align 2
  2280                                  	; 21/08/2014
  2281                                  exc_msg:
  2282 0000ED90 435055206578636570-     	db "CPU exception ! "
  2282 0000ED99 74696F6E202120     
  2283                                  excnstr: 		; 25/08/2014
  2284 0000EDA0 3F3F68202045495020-     	db "??h", "  EIP : "
  2284 0000EDA9 3A20               
  2285                                  EIPstr: ; 29/08/2014
  2286 0000EDAB 00<rept>                	times 12 db 0
  2287                                  
  2288                                  	; 23/02/2015
  2289                                  	; 25/08/2014
  2290                                  ;scounter:
  2291                                  ;	db 5
  2292                                  ;	db 19
  2293                                  
  2294                                  ; 05/11/2014
  2295                                  msg_out_of_memory:
  2296 0000EDB7 070D0A                  	db 	07h, 0Dh, 0Ah
  2297 0000EDBA 496E73756666696369-             db      'Insufficient memory !'
  2297 0000EDC3 656E74206D656D6F72-
  2297 0000EDCC 792021             
  2298 0000EDCF 0D0A                    	db	0Dh, 0Ah
  2299                                  _int13h_48h_buffer: ; 07/07/2016
  2300 0000EDD1 284D696E696D756D20-     	db	'(Minimum 2MB memory is needed.)'
  2300 0000EDDA 324D42206D656D6F72-
  2300 0000EDE3 79206973206E656564-
  2300 0000EDEC 65642E29           
  2301 0000EDF0 0D0A00                   	db	0Dh, 0Ah, 0
  2302                                  	;
  2303                                  setup_error_msg:
  2304 0000EDF3 0D0A                    	db 0Dh, 0Ah
  2305 0000EDF5 4469736B2053657475-     	db 'Disk Setup Error !' 
  2305 0000EDFE 70204572726F722021 
  2306 0000EE07 0D0A00                  	db 0Dh, 0Ah,0
  2307                                  
  2308                                  ; 06/11/2014
  2309                                  ; Memory Information message
  2310                                  ; 14/08/2015
  2311                                  msg_memory_info:
  2312 0000EE0A 07                      	db	07h
  2313 0000EE0B 0D0A                    	db	0Dh, 0Ah
  2314                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
  2315 0000EE0D 546F74616C206D656D-     	db	"Total memory : "
  2315 0000EE16 6F7279203A20       
  2316                                  mem_total_b_str: ; 10 digits
  2317 0000EE1C 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
  2317 0000EE25 302062797465730D0A 
  2318 0000EE2E 202020202020202020-     	db	"               ", 20h, 20h, 20h
  2318 0000EE37 202020202020202020 
  2319                                  mem_total_p_str: ; 7 digits
  2320 0000EE40 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
  2320 0000EE49 616765730D0A       
  2321 0000EE4F 0D0A                    	db 	0Dh, 0Ah
  2322 0000EE51 46726565206D656D6F-     	db	"Free memory  : "
  2322 0000EE5A 727920203A20       
  2323                                  free_mem_b_str:  ; 10 digits
  2324 0000EE60 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
  2324 0000EE69 3F2062797465730D0A 
  2325 0000EE72 202020202020202020-     	db	"               ", 20h, 20h, 20h
  2325 0000EE7B 202020202020202020 
  2326                                  free_mem_p_str:  ; 7 digits
  2327 0000EE84 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
  2327 0000EE8D 616765730D0A       
  2328 0000EE93 0D0A00                  	db	0Dh, 0Ah, 0
  2329                                  
  2330                                  dsk_ready_msg:
  2331 0000EE96 0D0A                    	db 	0Dh, 0Ah
  2332                                  dsktype:
  2333 0000EE98 6664                    	db	'fd'
  2334                                  dskx:
  2335 0000EE9A 30                      	db	'0'
  2336 0000EE9B 20                      	db	20h
  2337 0000EE9C 697320524541445920-     	db 	'is READY ...'
  2337 0000EEA5 2E2E2E             
  2338 0000EEA8 00                      	db 	0
  2339                                  
  2340                                  next2line: ; 08/02/2016
  2341 0000EEA9 0D0A                    	db	0Dh, 0Ah
  2342                                  nextline:
  2343 0000EEAB 0D0A00                  	db 	0Dh, 0Ah, 0
  2344                                  
  2345                                  ; KERNEL - SYSINIT Messages
  2346                                  ; 24/08/2015
  2347                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
  2348                                  ; 14/07/2013
  2349                                  ;kernel_init_err_msg:
  2350                                  ;	db 0Dh, 0Ah
  2351                                  ;	db 07h
  2352                                  ;	db 'Kernel initialization ERROR !'
  2353                                  ;	db 0Dh, 0Ah, 0 
  2354                                  
  2355                                  ;welcome_msg: 
  2356                                  ;	db 0Dh, 0Ah
  2357                                  ;	db 07h
  2358                                  ;	db 'Welcome to TRDOS 386 Operating System !'
  2359                                  ;	db 0Dh, 0Ah
  2360                                  ;	db 'by Erdogan Tan - 08/08/2016 (v2.0.0)'
  2361                                  ;	db 0Dh, 0Ah, 0
  2362                                  
  2363                                  panic_msg:
  2364 0000EEAE 0D0A07                  	db 0Dh, 0Ah, 07h
  2365 0000EEB1 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
  2365 0000EEBA 726E656C2050616E69-
  2365 0000EEC3 632021             
  2366 0000EEC6 0D0A00                  	db 0Dh, 0Ah, 0
  2367                                  
  2368 0000EEC9 90                      align 2
  2369                                  
  2370                                  ; EPOCH Variables
  2371                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
  2372                                  ; 09/04/2013 epoch variables
  2373                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
  2374                                  ;
  2375 0000EECA B207                    year: 	dw 1970
  2376 0000EECC 0100                    month: 	dw 1
  2377 0000EECE 0100                    day: 	dw 1
  2378 0000EED0 0000                    hour: 	dw 0
  2379 0000EED2 0000                    minute: dw 0
  2380 0000EED4 0000                    second: dw 0
  2381                                  
  2382                                  DMonth:
  2383 0000EED6 0000                    	dw 0
  2384 0000EED8 1F00                    	dw 31
  2385 0000EEDA 3B00                    	dw 59
  2386 0000EEDC 5A00                    	dw 90
  2387 0000EEDE 7800                    	dw 120
  2388 0000EEE0 9700                    	dw 151
  2389 0000EEE2 B500                    	dw 181
  2390 0000EEE4 D400                    	dw 212
  2391 0000EEE6 F300                    	dw 243
  2392 0000EEE8 1101                    	dw 273
  2393 0000EEEA 3001                    	dw 304
  2394 0000EEEC 4E01                    	dw 334
  2395                                  
  2396                                  ; 04/11/2014 (Retro UNIX 386 v1)
  2397 0000EEEE 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
  2398                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
  2399 0000EEF0 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
  2400                                  		   ; between 16 MB and 4 GB.
  2401                                  
  2402                                  ;msgl_drv_not_ready: 
  2403                                  ;	db 07h, 0Dh, 0Ah
  2404                                  ;       db 'Drive not ready or read error !'
  2405                                  ;       db 0Dh, 0Ah, 0
  2406                                  
  2407                                  starting_msg:
  2408 0000EEF2 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [08/08/2016] ...", 0
  2408 0000EEFB 6174696F6E616C2044-
  2408 0000EF04 4F532076322E30205B-
  2408 0000EF0D 30382F30382F323031-
  2408 0000EF16 365D202E2E2E00     
  2409                                  NextLine:
  2410 0000EF1D 0D0A00                  	db 0Dh, 0Ah, 0
  2411                                  
  2412                                  align 4
  2413                                  
  2414                                  %include 'vgadata.s' ; 04/07/2016
     1                              <1> ; ****************************************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vgadata.s  (palette and fond data)
     3                              <1> ; -----------------------------------------------------------------------------
     4                              <1> ; Last Update: 04/07/2016
     5                              <1> ; -----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; -----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; -----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Plex86/Bochs VGABios' source code, vgabios-0.7a (2011)
    14                              <1> ; by the LGPL VGABios Developers Team (2001-2008), 'vgatables.h'
    15                              <1> ;
    16                              <1> ; Oracle VirtualBox 5.0.24 VGABios Source Code 
    17                              <1> ; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
    18                              <1> ;
    19                              <1> ; Palette and font data in assembly language format:
    20                              <1> ; 'VBoxVgaBiosAlternative.asm'
    21                              <1> 
    22                              <1> ; ****************************************************************************************************
    23                              <1> 
    24                              <1> ; 04/07/2016
    25                              <1> ; COLOR DATA
    26                              <1> 
    27                              <1> palette0:
    28 0000EF20 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    28 0000EF29 00000000000000      <1>
    29 0000EF30 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    29 0000EF39 2A2A2A2A2A2A2A      <1>
    30 0000EF40 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    30 0000EF49 2A2A2A2A2A2A2A      <1>
    31 0000EF50 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    31 0000EF59 2A2A2A2A2A2A2A      <1>
    32 0000EF60 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    32 0000EF69 3F3F3F3F3F3F3F      <1>
    33 0000EF70 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    33 0000EF79 3F3F3F3F3F3F3F      <1>
    34 0000EF80 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    34 0000EF89 00000000000000      <1>
    35 0000EF90 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    35 0000EF99 2A2A2A2A2A2A2A      <1>
    36 0000EFA0 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    36 0000EFA9 2A2A2A2A2A2A2A      <1>
    37 0000EFB0 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    37 0000EFB9 2A2A2A2A2A2A2A      <1>
    38 0000EFC0 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    38 0000EFC9 3F3F3F3F3F3F3F      <1>
    39 0000EFD0 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    39 0000EFD9 3F3F3F3F3F3F3F      <1>
    40                              <1> palette1:
    41 0000EFE0 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    41 0000EFE9 002A2A2A00002A      <1>
    42 0000EFF0 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    42 0000EFF9 000000002A002A      <1>
    43 0000F000 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    43 0000F009 2A2A15002A2A2A      <1>
    44 0000F010 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    44 0000F019 153F3F3F15153F      <1>
    45 0000F020 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    45 0000F029 151515153F153F      <1>
    46 0000F030 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    46 0000F039 3F3F3F153F3F3F      <1>
    47 0000F040 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    47 0000F049 002A2A2A00002A      <1>
    48 0000F050 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    48 0000F059 000000002A002A      <1>
    49 0000F060 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    49 0000F069 2A2A15002A2A2A      <1>
    50 0000F070 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    50 0000F079 153F3F3F15153F      <1>
    51 0000F080 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    51 0000F089 151515153F153F      <1>
    52 0000F090 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    52 0000F099 3F3F3F153F3F3F      <1>
    53                              <1> palette2:
    54 0000F0A0 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    54 0000F0A9 002A2A2A00002A      <1>
    55 0000F0B0 002A2A2A002A2A2A00- <1>     db  000h, 02ah, 02ah, 02ah, 000h, 02ah, 02ah, 02ah, 000h, 000h, 015h, 000h, 000h, 03fh, 000h, 02ah
    55 0000F0B9 001500003F002A      <1>
    56 0000F0C0 15002A3F2A00152A00- <1>     db  015h, 000h, 02ah, 03fh, 02ah, 000h, 015h, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 02ah, 02ah, 03fh
    56 0000F0C9 3F2A2A152A2A3F      <1>
    57 0000F0D0 00150000152A003F00- <1>     db  000h, 015h, 000h, 000h, 015h, 02ah, 000h, 03fh, 000h, 000h, 03fh, 02ah, 02ah, 015h, 000h, 02ah
    57 0000F0D9 003F2A2A15002A      <1>
    58 0000F0E0 152A2A3F002A3F2A00- <1>     db  015h, 02ah, 02ah, 03fh, 000h, 02ah, 03fh, 02ah, 000h, 015h, 015h, 000h, 015h, 03fh, 000h, 03fh
    58 0000F0E9 151500153F003F      <1>
    59 0000F0F0 15003F3F2A15152A15- <1>     db  015h, 000h, 03fh, 03fh, 02ah, 015h, 015h, 02ah, 015h, 03fh, 02ah, 03fh, 015h, 02ah, 03fh, 03fh
    59 0000F0F9 3F2A3F152A3F3F      <1>
    60 0000F100 15000015002A152A00- <1>     db  015h, 000h, 000h, 015h, 000h, 02ah, 015h, 02ah, 000h, 015h, 02ah, 02ah, 03fh, 000h, 000h, 03fh
    60 0000F109 152A2A3F00003F      <1>
    61 0000F110 002A3F2A003F2A2A15- <1>     db  000h, 02ah, 03fh, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 000h, 015h, 015h, 000h, 03fh, 015h, 02ah
    61 0000F119 001515003F152A      <1>
    62 0000F120 15152A3F3F00153F00- <1>     db  015h, 015h, 02ah, 03fh, 03fh, 000h, 015h, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 03fh, 02ah, 03fh
    62 0000F129 3F3F2A153F2A3F      <1>
    63 0000F130 15150015152A153F00- <1>     db  015h, 015h, 000h, 015h, 015h, 02ah, 015h, 03fh, 000h, 015h, 03fh, 02ah, 03fh, 015h, 000h, 03fh
    63 0000F139 153F2A3F15003F      <1>
    64 0000F140 152A3F3F003F3F2A15- <1>     db  015h, 02ah, 03fh, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    64 0000F149 151515153F153F      <1>
    65 0000F150 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    65 0000F159 3F3F3F153F3F3F      <1>
    66                              <1> palette3:
    67 0000F160 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    67 0000F169 002A2A2A00002A      <1>
    68 0000F170 002A2A15002A2A2A15- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    68 0000F179 151515153F153F      <1>
    69 0000F180 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    69 0000F189 3F3F3F153F3F3F      <1>
    70 0000F190 000000050505080808- <1>     db  000h, 000h, 000h, 005h, 005h, 005h, 008h, 008h, 008h, 00bh, 00bh, 00bh, 00eh, 00eh, 00eh, 011h
    70 0000F199 0B0B0B0E0E0E11      <1>
    71 0000F1A0 11111414141818181C- <1>     db  011h, 011h, 014h, 014h, 014h, 018h, 018h, 018h, 01ch, 01ch, 01ch, 020h, 020h, 020h, 024h, 024h
    71 0000F1A9 1C1C2020202424      <1>
    72 0000F1B0 242828282D2D2D3232- <1>     db  024h, 028h, 028h, 028h, 02dh, 02dh, 02dh, 032h, 032h, 032h, 038h, 038h, 038h, 03fh, 03fh, 03fh
    72 0000F1B9 323838383F3F3F      <1>
    73 0000F1C0 00003F10003F1F003F- <1>     db  000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 03fh, 03fh
    73 0000F1C9 2F003F3F003F3F      <1>
    74 0000F1D0 002F3F001F3F00103F- <1>     db  000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh
    74 0000F1D9 00003F10003F1F      <1>
    75 0000F1E0 003F2F003F3F002F3F- <1>     db  000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h
    75 0000F1E9 001F3F00103F00      <1>
    76 0000F1F0 003F00003F10003F1F- <1>     db  000h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h
    76 0000F1F9 003F2F003F3F00      <1>
    77 0000F200 2F3F001F3F00103F1F- <1>     db  02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh
    77 0000F209 1F3F271F3F2F1F      <1>
    78 0000F210 3F371F3F3F1F3F3F1F- <1>     db  03fh, 037h, 01fh, 03fh, 03fh, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h
    78 0000F219 373F1F2F3F1F27      <1>
    79 0000F220 3F1F1F3F271F3F2F1F- <1>     db  03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h
    79 0000F229 3F371F3F3F1F37      <1>
    80 0000F230 3F1F2F3F1F273F1F1F- <1>     db  03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh, 01fh, 01fh, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh
    80 0000F239 3F1F1F3F271F3F      <1>
    81 0000F240 2F1F3F371F3F3F1F37- <1>     db  02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh
    81 0000F249 3F1F2F3F1F273F      <1>
    82 0000F250 2D2D3F312D3F362D3F- <1>     db  02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03fh, 03fh
    82 0000F259 3A2D3F3F2D3F3F      <1>
    83 0000F260 2D3A3F2D363F2D313F- <1>     db  02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h
    83 0000F269 2D2D3F312D3F36      <1>
    84 0000F270 2D3F3A2D3F3F2D3A3F- <1>     db  02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh
    84 0000F279 2D363F2D313F2D      <1>
    85 0000F280 2D3F2D2D3F312D3F36- <1>     db  02dh, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh
    85 0000F289 2D3F3A2D3F3F2D      <1>
    86 0000F290 3A3F2D363F2D313F00- <1>     db  03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h
    86 0000F299 001C07001C0E00      <1>
    87 0000F2A0 1C15001C1C001C1C00- <1>     db  01ch, 015h, 000h, 01ch, 01ch, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h
    87 0000F2A9 151C000E1C0007      <1>
    88 0000F2B0 1C00001C07001C0E00- <1>     db  01ch, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h
    88 0000F2B9 1C15001C1C0015      <1>
    89 0000F2C0 1C000E1C00071C0000- <1>     db  01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch, 000h, 000h, 01ch, 000h, 000h, 01ch, 007h, 000h, 01ch
    89 0000F2C9 1C00001C07001C      <1>
    90 0000F2D0 0E001C15001C1C0015- <1>     db  00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch
    90 0000F2D9 1C000E1C00071C      <1>
    91 0000F2E0 0E0E1C110E1C150E1C- <1>     db  00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 01ch, 01ch
    91 0000F2E9 180E1C1C0E1C1C      <1>
    92 0000F2F0 0E181C0E151C0E111C- <1>     db  00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h
    92 0000F2F9 0E0E1C110E1C15      <1>
    93 0000F300 0E1C180E1C1C0E181C- <1>     db  00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh
    93 0000F309 0E151C0E111C0E      <1>
    94 0000F310 0E1C0E0E1C110E1C15- <1>     db  00eh, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh
    94 0000F319 0E1C180E1C1C0E      <1>
    95 0000F320 181C0E151C0E111C14- <1>     db  018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h
    95 0000F329 141C16141C1814      <1>
    96 0000F330 1C1A141C1C141C1C14- <1>     db  01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h
    96 0000F339 1A1C14181C1416      <1>
    97 0000F340 1C14141C16141C1814- <1>     db  01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah
    97 0000F349 1C1A141C1C141A      <1>
    98 0000F350 1C14181C14161C1414- <1>     db  01ch, 014h, 018h, 01ch, 014h, 016h, 01ch, 014h, 014h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch
    98 0000F359 1C14141C16141C      <1>
    99 0000F360 18141C1A141C1C141A- <1>     db  018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h, 01ch
    99 0000F369 1C14181C14161C      <1>
   100 0000F370 000010040010080010- <1>     db  000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h, 010h, 010h
   100 0000F379 0C001010001010      <1>
   101 0000F380 000C10000810000410- <1>     db  000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h
   101 0000F389 00001004001008      <1>
   102 0000F390 00100C001010000C10- <1>     db  000h, 010h, 00ch, 000h, 010h, 010h, 000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h
   102 0000F399 00081000041000      <1>
   103 0000F3A0 001000001004001008- <1>     db  000h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h
   103 0000F3A9 00100C00101000      <1>
   104 0000F3B0 0C1000081000041008- <1>     db  00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h
   104 0000F3B9 08100A08100C08      <1>
   105 0000F3C0 100E08101008101008- <1>     db  010h, 00eh, 008h, 010h, 010h, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah
   105 0000F3C9 0E10080C10080A      <1>
   106 0000F3D0 100808100A08100C08- <1>     db  010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh
   106 0000F3D9 100E081010080E      <1>
   107 0000F3E0 10080C10080A100808- <1>     db  010h, 008h, 00ch, 010h, 008h, 00ah, 010h, 008h, 008h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h
   107 0000F3E9 100808100A0810      <1>
   108 0000F3F0 0C08100E081010080E- <1>     db  00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah, 010h
   108 0000F3F9 10080C10080A10      <1>
   109 0000F400 0B0B100C0B100D0B10- <1>     db  00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 010h, 010h
   109 0000F409 0F0B10100B1010      <1>
   110 0000F410 0B0F100B0D100B0C10- <1>     db  00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh
   110 0000F419 0B0B100C0B100D      <1>
   111 0000F420 0B100F0B10100B0F10- <1>     db  00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh
   111 0000F429 0B0D100B0C100B      <1>
   112 0000F430 0B100B0B100C0B100D- <1>     db  00bh, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh
   112 0000F439 0B100F0B10100B      <1>
   113 0000F440 0F100B0D100B0C1000- <1>     db  00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   113 0000F449 00000000000000      <1>
   114 0000F450 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   114 0000F459 00000000000000      <1>
   115                              <1> 
   116                              <1> 
   117                              <1> ; 04/07/2016
   118                              <1> ; FONT DATA
   119                              <1> 
   120                              <1> CRT_CHAR_GEN:
   121                              <1> vgafont8: 
   122 0000F460 00000000000000007E- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 081h, 0a5h, 081h, 0bdh, 099h, 081h, 07eh
   122 0000F469 81A581BD99817E      <1>
   123 0000F470 7EFFDBFFC3E7FF7E6C- <1>     db  07eh, 0ffh, 0dbh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 06ch, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h
   123 0000F479 FEFEFE7C381000      <1>
   124 0000F480 10387CFE7C38100038- <1>     db  010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 038h, 07ch, 038h, 0feh, 0feh, 07ch, 038h, 07ch
   124 0000F489 7C38FEFE7C387C      <1>
   125 0000F490 1010387CFE7C387C00- <1>     db  010h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 07ch, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h
   125 0000F499 00183C3C180000      <1>
   126 0000F4A0 FFFFE7C3C3E7FFFF00- <1>     db  0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h
   126 0000F4A9 3C664242663C00      <1>
   127 0000F4B0 FFC399BDBD99C3FF0F- <1>     db  0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 00fh, 007h, 00fh, 07dh, 0cch, 0cch, 0cch, 078h
   127 0000F4B9 070F7DCCCCCC78      <1>
   128 0000F4C0 3C6666663C187E183F- <1>     db  03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 03fh, 033h, 03fh, 030h, 030h, 070h, 0f0h, 0e0h
   128 0000F4C9 333F303070F0E0      <1>
   129 0000F4D0 7F637F636367E6C099- <1>     db  07fh, 063h, 07fh, 063h, 063h, 067h, 0e6h, 0c0h, 099h, 05ah, 03ch, 0e7h, 0e7h, 03ch, 05ah, 099h
   129 0000F4D9 5A3CE7E73C5A99      <1>
   130 0000F4E0 80E0F8FEF8E0800002- <1>     db  080h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 080h, 000h, 002h, 00eh, 03eh, 0feh, 03eh, 00eh, 002h, 000h
   130 0000F4E9 0E3EFE3E0E0200      <1>
   131 0000F4F0 183C7E18187E3C1866- <1>     db  018h, 03ch, 07eh, 018h, 018h, 07eh, 03ch, 018h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 000h
   131 0000F4F9 66666666006600      <1>
   132 0000F500 7FDBDB7B1B1B1B003E- <1>     db  07fh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 000h, 03eh, 063h, 038h, 06ch, 06ch, 038h, 0cch, 078h
   132 0000F509 63386C6C38CC78      <1>
   133 0000F510 000000007E7E7E0018- <1>     db  000h, 000h, 000h, 000h, 07eh, 07eh, 07eh, 000h, 018h, 03ch, 07eh, 018h, 07eh, 03ch, 018h, 0ffh
   133 0000F519 3C7E187E3C18FF      <1>
   134 0000F520 183C7E181818180018- <1>     db  018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h
   134 0000F529 1818187E3C1800      <1>
   135 0000F530 00180CFE0C18000000- <1>     db  000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h
   135 0000F539 3060FE60300000      <1>
   136 0000F540 0000C0C0C0FE000000- <1>     db  000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h
   136 0000F549 2466FF66240000      <1>
   137 0000F550 00183C7EFFFF000000- <1>     db  000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 000h, 000h, 000h, 0ffh, 0ffh, 07eh, 03ch, 018h, 000h, 000h
   137 0000F559 FFFF7E3C180000      <1>
   138 0000F560 000000000000000030- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 078h, 078h, 030h, 030h, 000h, 030h, 000h
   138 0000F569 78783030003000      <1>
   139 0000F570 6C6C6C00000000006C- <1>     db  06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 0feh, 06ch, 06ch, 000h
   139 0000F579 6CFE6CFE6C6C00      <1>
   140 0000F580 307CC0780CF8300000- <1>     db  030h, 07ch, 0c0h, 078h, 00ch, 0f8h, 030h, 000h, 000h, 0c6h, 0cch, 018h, 030h, 066h, 0c6h, 000h
   140 0000F589 C6CC183066C600      <1>
   141 0000F590 386C3876DCCC760060- <1>     db  038h, 06ch, 038h, 076h, 0dch, 0cch, 076h, 000h, 060h, 060h, 0c0h, 000h, 000h, 000h, 000h, 000h
   141 0000F599 60C00000000000      <1>
   142 0000F5A0 183060606030180060- <1>     db  018h, 030h, 060h, 060h, 060h, 030h, 018h, 000h, 060h, 030h, 018h, 018h, 018h, 030h, 060h, 000h
   142 0000F5A9 30181818306000      <1>
   143 0000F5B0 00663CFF3C66000000- <1>     db  000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 000h
   143 0000F5B9 3030FC30300000      <1>
   144 0000F5C0 000000000030306000- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 060h, 000h, 000h, 000h, 0fch, 000h, 000h, 000h, 000h
   144 0000F5C9 0000FC00000000      <1>
   145 0000F5D0 000000000030300006- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 000h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h
   145 0000F5D9 0C183060C08000      <1>
   146 0000F5E0 7CC6CEDEF6E67C0030- <1>     db  07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 07ch, 000h, 030h, 070h, 030h, 030h, 030h, 030h, 0fch, 000h
   146 0000F5E9 7030303030FC00      <1>
   147 0000F5F0 78CC0C3860CCFC0078- <1>     db  078h, 0cch, 00ch, 038h, 060h, 0cch, 0fch, 000h, 078h, 0cch, 00ch, 038h, 00ch, 0cch, 078h, 000h
   147 0000F5F9 CC0C380CCC7800      <1>
   148 0000F600 1C3C6CCCFE0C1E00FC- <1>     db  01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 01eh, 000h, 0fch, 0c0h, 0f8h, 00ch, 00ch, 0cch, 078h, 000h
   148 0000F609 C0F80C0CCC7800      <1>
   149 0000F610 3860C0F8CCCC7800FC- <1>     db  038h, 060h, 0c0h, 0f8h, 0cch, 0cch, 078h, 000h, 0fch, 0cch, 00ch, 018h, 030h, 030h, 030h, 000h
   149 0000F619 CC0C1830303000      <1>
   150 0000F620 78CCCC78CCCC780078- <1>     db  078h, 0cch, 0cch, 078h, 0cch, 0cch, 078h, 000h, 078h, 0cch, 0cch, 07ch, 00ch, 018h, 070h, 000h
   150 0000F629 CCCC7C0C187000      <1>
   151 0000F630 003030000030300000- <1>     db  000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 060h
   151 0000F639 30300000303060      <1>
   152 0000F640 183060C06030180000- <1>     db  018h, 030h, 060h, 0c0h, 060h, 030h, 018h, 000h, 000h, 000h, 0fch, 000h, 000h, 0fch, 000h, 000h
   152 0000F649 00FC0000FC0000      <1>
   153 0000F650 6030180C1830600078- <1>     db  060h, 030h, 018h, 00ch, 018h, 030h, 060h, 000h, 078h, 0cch, 00ch, 018h, 030h, 000h, 030h, 000h
   153 0000F659 CC0C1830003000      <1>
   154 0000F660 7CC6DEDEDEC0780030- <1>     db  07ch, 0c6h, 0deh, 0deh, 0deh, 0c0h, 078h, 000h, 030h, 078h, 0cch, 0cch, 0fch, 0cch, 0cch, 000h
   154 0000F669 78CCCCFCCCCC00      <1>
   155 0000F670 FC66667C6666FC003C- <1>     db  0fch, 066h, 066h, 07ch, 066h, 066h, 0fch, 000h, 03ch, 066h, 0c0h, 0c0h, 0c0h, 066h, 03ch, 000h
   155 0000F679 66C0C0C0663C00      <1>
   156 0000F680 F86C6666666CF800FE- <1>     db  0f8h, 06ch, 066h, 066h, 066h, 06ch, 0f8h, 000h, 0feh, 062h, 068h, 078h, 068h, 062h, 0feh, 000h
   156 0000F689 6268786862FE00      <1>
   157 0000F690 FE6268786860F0003C- <1>     db  0feh, 062h, 068h, 078h, 068h, 060h, 0f0h, 000h, 03ch, 066h, 0c0h, 0c0h, 0ceh, 066h, 03eh, 000h
   157 0000F699 66C0C0CE663E00      <1>
   158 0000F6A0 CCCCCCFCCCCCCC0078- <1>     db  0cch, 0cch, 0cch, 0fch, 0cch, 0cch, 0cch, 000h, 078h, 030h, 030h, 030h, 030h, 030h, 078h, 000h
   158 0000F6A9 30303030307800      <1>
   159 0000F6B0 1E0C0C0CCCCC7800E6- <1>     db  01eh, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 0e6h, 066h, 06ch, 078h, 06ch, 066h, 0e6h, 000h
   159 0000F6B9 666C786C66E600      <1>
   160 0000F6C0 F06060606266FE00C6- <1>     db  0f0h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 000h
   160 0000F6C9 EEFEFED6C6C600      <1>
   161 0000F6D0 C6E6F6DECEC6C60038- <1>     db  0c6h, 0e6h, 0f6h, 0deh, 0ceh, 0c6h, 0c6h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h
   161 0000F6D9 6CC6C6C66C3800      <1>
   162 0000F6E0 FC66667C6060F00078- <1>     db  0fch, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 078h, 0cch, 0cch, 0cch, 0dch, 078h, 01ch, 000h
   162 0000F6E9 CCCCCCDC781C00      <1>
   163 0000F6F0 FC66667C6C66E60078- <1>     db  0fch, 066h, 066h, 07ch, 06ch, 066h, 0e6h, 000h, 078h, 0cch, 0e0h, 070h, 01ch, 0cch, 078h, 000h
   163 0000F6F9 CCE0701CCC7800      <1>
   164 0000F700 FCB4303030307800CC- <1>     db  0fch, 0b4h, 030h, 030h, 030h, 030h, 078h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 0fch, 000h
   164 0000F709 CCCCCCCCCCFC00      <1>
   165 0000F710 CCCCCCCCCC783000C6- <1>     db  0cch, 0cch, 0cch, 0cch, 0cch, 078h, 030h, 000h, 0c6h, 0c6h, 0c6h, 0d6h, 0feh, 0eeh, 0c6h, 000h
   165 0000F719 C6C6D6FEEEC600      <1>
   166 0000F720 C6C66C38386CC600CC- <1>     db  0c6h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 030h, 078h, 000h
   166 0000F729 CCCC7830307800      <1>
   167 0000F730 FEC68C183266FE0078- <1>     db  0feh, 0c6h, 08ch, 018h, 032h, 066h, 0feh, 000h, 078h, 060h, 060h, 060h, 060h, 060h, 078h, 000h
   167 0000F739 60606060607800      <1>
   168 0000F740 C06030180C06020078- <1>     db  0c0h, 060h, 030h, 018h, 00ch, 006h, 002h, 000h, 078h, 018h, 018h, 018h, 018h, 018h, 078h, 000h
   168 0000F749 18181818187800      <1>
   169 0000F750 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   169 0000F759 000000000000FF      <1>
   170 0000F760 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 076h, 000h
   170 0000F769 00780C7CCC7600      <1>
   171 0000F770 E060607C6666DC0000- <1>     db  0e0h, 060h, 060h, 07ch, 066h, 066h, 0dch, 000h, 000h, 000h, 078h, 0cch, 0c0h, 0cch, 078h, 000h
   171 0000F779 0078CCC0CC7800      <1>
   172 0000F780 1C0C0C7CCCCC760000- <1>     db  01ch, 00ch, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   172 0000F789 0078CCFCC07800      <1>
   173 0000F790 386C60F06060F00000- <1>     db  038h, 06ch, 060h, 0f0h, 060h, 060h, 0f0h, 000h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 0f8h
   173 0000F799 0076CCCC7C0CF8      <1>
   174 0000F7A0 E0606C766666E60030- <1>     db  0e0h, 060h, 06ch, 076h, 066h, 066h, 0e6h, 000h, 030h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   174 0000F7A9 00703030307800      <1>
   175 0000F7B0 0C000C0C0CCCCC78E0- <1>     db  00ch, 000h, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 0e0h, 060h, 066h, 06ch, 078h, 06ch, 0e6h, 000h
   175 0000F7B9 60666C786CE600      <1>
   176 0000F7C0 703030303030780000- <1>     db  070h, 030h, 030h, 030h, 030h, 030h, 078h, 000h, 000h, 000h, 0cch, 0feh, 0feh, 0d6h, 0c6h, 000h
   176 0000F7C9 00CCFEFED6C600      <1>
   177 0000F7D0 0000F8CCCCCCCC0000- <1>     db  000h, 000h, 0f8h, 0cch, 0cch, 0cch, 0cch, 000h, 000h, 000h, 078h, 0cch, 0cch, 0cch, 078h, 000h
   177 0000F7D9 0078CCCCCC7800      <1>
   178 0000F7E0 0000DC66667C60F000- <1>     db  000h, 000h, 0dch, 066h, 066h, 07ch, 060h, 0f0h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 01eh
   178 0000F7E9 0076CCCC7C0C1E      <1>
   179 0000F7F0 0000DC766660F00000- <1>     db  000h, 000h, 0dch, 076h, 066h, 060h, 0f0h, 000h, 000h, 000h, 07ch, 0c0h, 078h, 00ch, 0f8h, 000h
   179 0000F7F9 007CC0780CF800      <1>
   180 0000F800 10307C303034180000- <1>     db  010h, 030h, 07ch, 030h, 030h, 034h, 018h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   180 0000F809 00CCCCCCCC7600      <1>
   181 0000F810 0000CCCCCC78300000- <1>     db  000h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 000h, 000h, 000h, 0c6h, 0d6h, 0feh, 0feh, 06ch, 000h
   181 0000F819 00C6D6FEFE6C00      <1>
   182 0000F820 0000C66C386CC60000- <1>     db  000h, 000h, 0c6h, 06ch, 038h, 06ch, 0c6h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 07ch, 00ch, 0f8h
   182 0000F829 00CCCCCC7C0CF8      <1>
   183 0000F830 0000FC983064FC001C- <1>     db  000h, 000h, 0fch, 098h, 030h, 064h, 0fch, 000h, 01ch, 030h, 030h, 0e0h, 030h, 030h, 01ch, 000h
   183 0000F839 3030E030301C00      <1>
   184 0000F840 1818180018181800E0- <1>     db  018h, 018h, 018h, 000h, 018h, 018h, 018h, 000h, 0e0h, 030h, 030h, 01ch, 030h, 030h, 0e0h, 000h
   184 0000F849 30301C3030E000      <1>
   185 0000F850 76DC00000000000000- <1>     db  076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h
   185 0000F859 10386CC6C6FE00      <1>
   186 0000F860 78CCC0CC78180C7800- <1>     db  078h, 0cch, 0c0h, 0cch, 078h, 018h, 00ch, 078h, 000h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   186 0000F869 CC00CCCCCC7E00      <1>
   187 0000F870 1C0078CCFCC078007E- <1>     db  01ch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 07eh, 0c3h, 03ch, 006h, 03eh, 066h, 03fh, 000h
   187 0000F879 C33C063E663F00      <1>
   188 0000F880 CC00780C7CCC7E00E0- <1>     db  0cch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 0e0h, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h
   188 0000F889 00780C7CCC7E00      <1>
   189 0000F890 3030780C7CCC7E0000- <1>     db  030h, 030h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 000h, 000h, 078h, 0c0h, 0c0h, 078h, 00ch, 038h
   189 0000F899 0078C0C0780C38      <1>
   190 0000F8A0 7EC33C667E603C00CC- <1>     db  07eh, 0c3h, 03ch, 066h, 07eh, 060h, 03ch, 000h, 0cch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   190 0000F8A9 0078CCFCC07800      <1>
   191 0000F8B0 E00078CCFCC07800CC- <1>     db  0e0h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 0cch, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   191 0000F8B9 00703030307800      <1>
   192 0000F8C0 7CC6381818183C00E0- <1>     db  07ch, 0c6h, 038h, 018h, 018h, 018h, 03ch, 000h, 0e0h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   192 0000F8C9 00703030307800      <1>
   193 0000F8D0 C6386CC6FEC6C60030- <1>     db  0c6h, 038h, 06ch, 0c6h, 0feh, 0c6h, 0c6h, 000h, 030h, 030h, 000h, 078h, 0cch, 0fch, 0cch, 000h
   193 0000F8D9 300078CCFCCC00      <1>
   194 0000F8E0 1C00FC607860FC0000- <1>     db  01ch, 000h, 0fch, 060h, 078h, 060h, 0fch, 000h, 000h, 000h, 07fh, 00ch, 07fh, 0cch, 07fh, 000h
   194 0000F8E9 007F0C7FCC7F00      <1>
   195 0000F8F0 3E6CCCFECCCCCE0078- <1>     db  03eh, 06ch, 0cch, 0feh, 0cch, 0cch, 0ceh, 000h, 078h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h
   195 0000F8F9 CC0078CCCC7800      <1>
   196 0000F900 00CC0078CCCC780000- <1>     db  000h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 0e0h, 000h, 078h, 0cch, 0cch, 078h, 000h
   196 0000F909 E00078CCCC7800      <1>
   197 0000F910 78CC00CCCCCC7E0000- <1>     db  078h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h, 000h, 0e0h, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   197 0000F919 E000CCCCCC7E00      <1>
   198 0000F920 00CC00CCCC7C0CF8C3- <1>     db  000h, 0cch, 000h, 0cch, 0cch, 07ch, 00ch, 0f8h, 0c3h, 018h, 03ch, 066h, 066h, 03ch, 018h, 000h
   198 0000F929 183C66663C1800      <1>
   199 0000F930 CC00CCCCCCCC780018- <1>     db  0cch, 000h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 018h, 018h, 07eh, 0c0h, 0c0h, 07eh, 018h, 018h
   199 0000F939 187EC0C07E1818      <1>
   200 0000F940 386C64F060E6FC00CC- <1>     db  038h, 06ch, 064h, 0f0h, 060h, 0e6h, 0fch, 000h, 0cch, 0cch, 078h, 0fch, 030h, 0fch, 030h, 030h
   200 0000F949 CC78FC30FC3030      <1>
   201 0000F950 F8CCCCFAC6CFC6C70E- <1>     db  0f8h, 0cch, 0cch, 0fah, 0c6h, 0cfh, 0c6h, 0c7h, 00eh, 01bh, 018h, 03ch, 018h, 018h, 0d8h, 070h
   201 0000F959 1B183C1818D870      <1>
   202 0000F960 1C00780C7CCC7E0038- <1>     db  01ch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 038h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   202 0000F969 00703030307800      <1>
   203 0000F970 001C0078CCCC780000- <1>     db  000h, 01ch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 01ch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   203 0000F979 1C00CCCCCC7E00      <1>
   204 0000F980 00F800F8CCCCCC00FC- <1>     db  000h, 0f8h, 000h, 0f8h, 0cch, 0cch, 0cch, 000h, 0fch, 000h, 0cch, 0ech, 0fch, 0dch, 0cch, 000h
   204 0000F989 00CCECFCDCCC00      <1>
   205 0000F990 3C6C6C3E007E000038- <1>     db  03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h
   205 0000F999 6C6C38007C0000      <1>
   206 0000F9A0 30003060C0CC780000- <1>     db  030h, 000h, 030h, 060h, 0c0h, 0cch, 078h, 000h, 000h, 000h, 000h, 0fch, 0c0h, 0c0h, 000h, 000h
   206 0000F9A9 0000FCC0C00000      <1>
   207 0000F9B0 000000FC0C0C0000C3- <1>     db  000h, 000h, 000h, 0fch, 00ch, 00ch, 000h, 000h, 0c3h, 0c6h, 0cch, 0deh, 033h, 066h, 0cch, 00fh
   207 0000F9B9 C6CCDE3366CC0F      <1>
   208 0000F9C0 C3C6CCDB376FCF0318- <1>     db  0c3h, 0c6h, 0cch, 0dbh, 037h, 06fh, 0cfh, 003h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 000h
   208 0000F9C9 18001818181800      <1>
   209 0000F9D0 003366CC6633000000- <1>     db  000h, 033h, 066h, 0cch, 066h, 033h, 000h, 000h, 000h, 0cch, 066h, 033h, 066h, 0cch, 000h, 000h
   209 0000F9D9 CC663366CC0000      <1>
   210 0000F9E0 228822882288228855- <1>     db  022h, 088h, 022h, 088h, 022h, 088h, 022h, 088h, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   210 0000F9E9 AA55AA55AA55AA      <1>
   211 0000F9F0 DB77DBEEDB77DBEE18- <1>     db  0dbh, 077h, 0dbh, 0eeh, 0dbh, 077h, 0dbh, 0eeh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   211 0000F9F9 18181818181818      <1>
   212 0000FA00 18181818F818181818- <1>     db  018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h
   212 0000FA09 18F818F8181818      <1>
   213 0000FA10 36363636F636363600- <1>     db  036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h
   213 0000FA19 000000FE363636      <1>
   214 0000FA20 0000F818F818181836- <1>     db  000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h
   214 0000FA29 36F606F6363636      <1>
   215 0000FA30 363636363636363600- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h
   215 0000FA39 00FE06F6363636      <1>
   216 0000FA40 3636F606FE00000036- <1>     db  036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h
   216 0000FA49 363636FE000000      <1>
   217 0000FA50 1818F818F800000000- <1>     db  018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h
   217 0000FA59 000000F8181818      <1>
   218 0000FA60 181818181F00000018- <1>     db  018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h
   218 0000FA69 181818FF000000      <1>
   219 0000FA70 00000000FF18181818- <1>     db  000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h
   219 0000FA79 1818181F181818      <1>
   220 0000FA80 00000000FF00000018- <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h
   220 0000FA89 181818FF181818      <1>
   221 0000FA90 18181F181F18181836- <1>     db  018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h
   221 0000FA99 36363637363636      <1>
   222 0000FAA0 363637303F00000000- <1>     db  036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h
   222 0000FAA9 003F3037363636      <1>
   223 0000FAB0 3636F700FF00000000- <1>     db  036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h
   223 0000FAB9 00FF00F7363636      <1>
   224 0000FAC0 363637303736363600- <1>     db  036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   224 0000FAC9 00FF00FF000000      <1>
   225 0000FAD0 3636F700F736363618- <1>     db  036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   225 0000FAD9 18FF00FF000000      <1>
   226 0000FAE0 36363636FF00000000- <1>     db  036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h
   226 0000FAE9 00FF00FF181818      <1>
   227 0000FAF0 00000000FF36363636- <1>     db  000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h
   227 0000FAF9 3636363F000000      <1>
   228 0000FB00 18181F181F00000000- <1>     db  018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h
   228 0000FB09 001F181F181818      <1>
   229 0000FB10 000000003F36363636- <1>     db  000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h
   229 0000FB19 363636FF363636      <1>
   230 0000FB20 1818FF18FF18181818- <1>     db  018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h
   230 0000FB29 181818F8000000      <1>
   231 0000FB30 000000001F181818FF- <1>     db  000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   231 0000FB39 FFFFFFFFFFFFFF      <1>
   232 0000FB40 00000000FFFFFFFFF0- <1>     db  000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   232 0000FB49 F0F0F0F0F0F0F0      <1>
   233 0000FB50 0F0F0F0F0F0F0F0FFF- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h
   233 0000FB59 FFFFFF00000000      <1>
   234 0000FB60 000076DCC8DC760000- <1>     db  000h, 000h, 076h, 0dch, 0c8h, 0dch, 076h, 000h, 000h, 078h, 0cch, 0f8h, 0cch, 0f8h, 0c0h, 0c0h
   234 0000FB69 78CCF8CCF8C0C0      <1>
   235 0000FB70 00FCCCC0C0C0C00000- <1>     db  000h, 0fch, 0cch, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   235 0000FB79 FE6C6C6C6C6C00      <1>
   236 0000FB80 FCCC603060CCFC0000- <1>     db  0fch, 0cch, 060h, 030h, 060h, 0cch, 0fch, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 070h, 000h
   236 0000FB89 007ED8D8D87000      <1>
   237 0000FB90 00666666667C60C000- <1>     db  000h, 066h, 066h, 066h, 066h, 07ch, 060h, 0c0h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 000h
   237 0000FB99 76DC1818181800      <1>
   238 0000FBA0 FC3078CCCC7830FC38- <1>     db  0fch, 030h, 078h, 0cch, 0cch, 078h, 030h, 0fch, 038h, 06ch, 0c6h, 0feh, 0c6h, 06ch, 038h, 000h
   238 0000FBA9 6CC6FEC66C3800      <1>
   239 0000FBB0 386CC6C66C6CEE001C- <1>     db  038h, 06ch, 0c6h, 0c6h, 06ch, 06ch, 0eeh, 000h, 01ch, 030h, 018h, 07ch, 0cch, 0cch, 078h, 000h
   239 0000FBB9 30187CCCCC7800      <1>
   240 0000FBC0 00007EDBDB7E000006- <1>     db  000h, 000h, 07eh, 0dbh, 0dbh, 07eh, 000h, 000h, 006h, 00ch, 07eh, 0dbh, 0dbh, 07eh, 060h, 0c0h
   240 0000FBC9 0C7EDBDB7E60C0      <1>
   241 0000FBD0 3860C0F8C060380078- <1>     db  038h, 060h, 0c0h, 0f8h, 0c0h, 060h, 038h, 000h, 078h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 000h
   241 0000FBD9 CCCCCCCCCCCC00      <1>
   242 0000FBE0 00FC00FC00FC000030- <1>     db  000h, 0fch, 000h, 0fch, 000h, 0fch, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 0fch, 000h
   242 0000FBE9 30FC303000FC00      <1>
   243 0000FBF0 603018306000FC0018- <1>     db  060h, 030h, 018h, 030h, 060h, 000h, 0fch, 000h, 018h, 030h, 060h, 030h, 018h, 000h, 0fch, 000h
   243 0000FBF9 3060301800FC00      <1>
   244 0000FC00 0E1B1B181818181818- <1>     db  00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 070h
   244 0000FC09 18181818D8D870      <1>
   245 0000FC10 303000FC0030300000- <1>     db  030h, 030h, 000h, 0fch, 000h, 030h, 030h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h
   245 0000FC19 76DC0076DC0000      <1>
   246 0000FC20 386C6C380000000000- <1>     db  038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h
   246 0000FC29 00001818000000      <1>
   247 0000FC30 00000000180000000F- <1>     db  000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 0ech, 06ch, 03ch, 01ch
   247 0000FC39 0C0C0CEC6C3C1C      <1>
   248 0000FC40 786C6C6C6C00000070- <1>     db  078h, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 070h, 018h, 030h, 060h, 078h, 000h, 000h, 000h
   248 0000FC49 18306078000000      <1>
   249 0000FC50 00003C3C3C3C000000- <1>     db  000h, 000h, 03ch, 03ch, 03ch, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   249 0000FC59 00000000000000      <1>
   250                              <1> vgafont14:
   251 0000FC60 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   251 0000FC69 00000000000000      <1>
   252 0000FC70 7E81A58181BD99817E- <1>     db  07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 07eh, 000h, 000h, 000h, 000h, 000h, 07eh, 0ffh
   252 0000FC79 00000000007EFF      <1>
   253 0000FC80 DBFFFFC3E7FF7E0000- <1>     db  0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 0feh, 0feh
   253 0000FC89 000000006CFEFE      <1>
   254 0000FC90 FEFE7C381000000000- <1>     db  0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch
   254 0000FC99 000010387CFE7C      <1>
   255 0000FCA0 381000000000000018- <1>     db  038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h
   255 0000FCA9 3C3CE7E7E71818      <1>
   256 0000FCB0 3C0000000000183C7E- <1>     db  03ch, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h
   256 0000FCB9 FFFF7E18183C00      <1>
   257 0000FCC0 00000000000000183C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   257 0000FCC9 3C180000000000      <1>
   258 0000FCD0 FFFFFFFFFFE7C3C3E7- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h
   258 0000FCD9 FFFFFFFFFF0000      <1>
   259 0000FCE0 00003C664242663C00- <1>     db  000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh
   259 0000FCE9 000000FFFFFFFF      <1>
   260 0000FCF0 C399BDBD99C3FFFFFF- <1>     db  0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 01eh, 00eh, 01ah, 032h
   260 0000FCF9 FF00001E0E1A32      <1>
   261 0000FD00 78CCCCCC7800000000- <1>     db  078h, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 066h, 066h, 03ch, 018h
   261 0000FD09 003C6666663C18      <1>
   262 0000FD10 7E181800000000003F- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 070h, 0f0h
   262 0000FD19 333F30303070F0      <1>
   263 0000FD20 E000000000007F637F- <1>     db  0e0h, 000h, 000h, 000h, 000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h
   263 0000FD29 63636367E7E6C0      <1>
   264 0000FD30 000000001818DB3CE7- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h
   264 0000FD39 3CDB1818000000      <1>
   265 0000FD40 000080C0E0F8FEF8E0- <1>     db  000h, 000h, 080h, 0c0h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h, 000h
   265 0000FD49 C0800000000000      <1>
   266 0000FD50 02060E3EFE3E0E0602- <1>     db  002h, 006h, 00eh, 03eh, 0feh, 03eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch
   266 0000FD59 0000000000183C      <1>
   267 0000FD60 7E1818187E3C180000- <1>     db  07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h
   267 0000FD69 00000066666666      <1>
   268 0000FD70 666600666600000000- <1>     db  066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh
   268 0000FD79 007FDBDBDB7B1B      <1>
   269 0000FD80 1B1B1B000000007CC6- <1>     db  01bh, 01bh, 01bh, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h
   269 0000FD89 60386CC6C66C38      <1>
   270 0000FD90 0CC67C000000000000- <1>     db  00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 000h
   270 0000FD99 000000FEFEFE00      <1>
   271 0000FDA0 00000000183C7E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h
   271 0000FDA9 187E3C187E0000      <1>
   272 0000FDB0 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   272 0000FDB9 18180000000000      <1>
   273 0000FDC0 1818181818187E3C18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   273 0000FDC9 00000000000000      <1>
   274 0000FDD0 180CFE0C1800000000- <1>     db  018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 060h
   274 0000FDD9 00000000003060      <1>
   275 0000FDE0 FE6030000000000000- <1>     db  0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h
   275 0000FDE9 00000000C0C0C0      <1>
   276 0000FDF0 FE0000000000000000- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 028h, 06ch, 0feh, 06ch, 028h, 000h
   276 0000FDF9 00286CFE6C2800      <1>
   277 0000FE00 000000000000001038- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h
   277 0000FE09 387C7CFEFE0000      <1>
   278 0000FE10 0000000000FEFE7C7C- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h
   278 0000FE19 38381000000000      <1>
   279 0000FE20 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   279 0000FE29 00000000000000      <1>
   280 0000FE30 183C3C3C1818001818- <1>     db  018h, 03ch, 03ch, 03ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 066h, 066h, 066h
   280 0000FE39 00000000666666      <1>
   281 0000FE40 240000000000000000- <1>     db  024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch
   281 0000FE49 0000006C6CFE6C      <1>
   282 0000FE50 6C6CFE6C6C00000018- <1>     db  06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h
   282 0000FE59 187CC6C2C07C06      <1>
   283 0000FE60 86C67C181800000000- <1>     db  086h, 0c6h, 07ch, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 066h
   283 0000FE69 00C2C60C183066      <1>
   284 0000FE70 C60000000000386C6C- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 076h, 000h
   284 0000FE79 3876DCCCCC7600      <1>
   285 0000FE80 000000303030600000- <1>     db  000h, 000h, 000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   285 0000FE89 00000000000000      <1>
   286 0000FE90 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h, 000h
   286 0000FE99 180C0000000000      <1>
   287 0000FEA0 30180C0C0C0C0C1830- <1>     db  030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   287 0000FEA9 00000000000000      <1>
   288 0000FEB0 663CFF3C6600000000- <1>     db  066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   288 0000FEB9 00000000001818      <1>
   289 0000FEC0 7E1818000000000000- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   289 0000FEC9 00000000000000      <1>
   290 0000FED0 181818300000000000- <1>     db  018h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h
   290 0000FED9 000000FE000000      <1>
   291 0000FEE0 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   291 0000FEE9 00000000181800      <1>
   292 0000FEF0 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   292 0000FEF9 60C08000000000      <1>
   293 0000FF00 00007CC6CEDEF6E6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   293 0000FF09 C67C0000000000      <1>
   294 0000FF10 18387818181818187E- <1>     db  018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h
   294 0000FF19 00000000007CC6      <1>
   295 0000FF20 060C183060C6FE0000- <1>     db  006h, 00ch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 006h, 006h
   295 0000FF29 0000007CC60606      <1>
   296 0000FF30 3C0606C67C00000000- <1>     db  03ch, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh
   296 0000FF39 000C1C3C6CCCFE      <1>
   297 0000FF40 0C0C1E0000000000FE- <1>     db  00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 0c6h
   297 0000FF49 C0C0C0FC0606C6      <1>
   298 0000FF50 7C00000000003860C0- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 07ch, 000h
   298 0000FF59 C0FCC6C6C67C00      <1>
   299 0000FF60 00000000FEC6060C18- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c6h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h
   299 0000FF69 30303030000000      <1>
   300 0000FF70 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   300 0000FF79 C67C0000000000      <1>
   301 0000FF80 7CC6C6C67E06060C78- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h, 000h, 000h, 018h
   301 0000FF89 00000000000018      <1>
   302 0000FF90 180000001818000000- <1>     db  018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   302 0000FF99 00000000181800      <1>
   303 0000FFA0 000018183000000000- <1>     db  000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h
   303 0000FFA9 00060C18306030      <1>
   304 0000FFB0 180C06000000000000- <1>     db  018h, 00ch, 006h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h
   304 0000FFB9 00007E00007E00      <1>
   305 0000FFC0 000000000000603018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h
   305 0000FFC9 0C060C18306000      <1>
   306 0000FFD0 000000007CC6C60C18- <1>     db  000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h
   306 0000FFD9 18001818000000      <1>
   307 0000FFE0 00007CC6C6DEDEDEDC- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h, 000h
   307 0000FFE9 C07C0000000000      <1>
   308 0000FFF0 10386CC6C6FEC6C6C6- <1>     db  010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h, 0fch, 066h
   308 0000FFF9 0000000000FC66      <1>
   309 00010000 66667C666666FC0000- <1>     db  066h, 066h, 07ch, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h
   309 00010009 0000003C66C2C0      <1>
   310 00010010 C0C0C2663C00000000- <1>     db  0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h
   310 00010019 00F86C66666666      <1>
   311 00010020 666CF80000000000FE- <1>     db  066h, 06ch, 0f8h, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 062h, 066h
   311 00010029 66626878686266      <1>
   312 00010030 FE0000000000FE6662- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 0f0h, 000h
   312 00010039 6878686060F000      <1>
   313 00010040 000000003C66C2C0C0- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 066h, 03ah, 000h, 000h, 000h
   313 00010049 DEC6663A000000      <1>
   314 00010050 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   314 00010059 C6C60000000000      <1>
   315 00010060 3C181818181818183C- <1>     db  03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 01eh, 00ch
   315 00010069 00000000001E0C      <1>
   316 00010070 0C0C0C0CCCCC780000- <1>     db  00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 0e6h, 066h, 06ch, 06ch
   316 00010079 000000E6666C6C      <1>
   317 00010080 786C6C66E600000000- <1>     db  078h, 06ch, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h
   317 00010089 00F06060606060      <1>
   318 00010090 6266FE0000000000C6- <1>     db  062h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 0c6h
   318 00010099 EEFEFED6C6C6C6      <1>
   319 000100A0 C60000000000C6E6F6- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h
   319 000100A9 FEDECEC6C6C600      <1>
   320 000100B0 00000000386CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h
   320 000100B9 C6C66C38000000      <1>
   321 000100C0 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h
   321 000100C9 60F00000000000      <1>
   322 000100D0 7CC6C6C6C6D6DE7C0C- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h, 000h, 000h, 0fch, 066h
   322 000100D9 0E00000000FC66      <1>
   323 000100E0 66667C6C6666E60000- <1>     db  066h, 066h, 07ch, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 060h
   323 000100E9 0000007CC6C660      <1>
   324 000100F0 380CC6C67C00000000- <1>     db  038h, 00ch, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 07eh, 07eh, 05ah, 018h, 018h, 018h
   324 000100F9 007E7E5A181818      <1>
   325 00010100 18183C0000000000C6- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h
   325 00010109 C6C6C6C6C6C6C6      <1>
   326 00010110 7C0000000000C6C6C6- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 010h, 000h
   326 00010119 C6C6C66C381000      <1>
   327 00010120 00000000C6C6C6C6D6- <1>     db  000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 07ch, 06ch, 000h, 000h, 000h
   327 00010129 D6FE7C6C000000      <1>
   328 00010130 0000C6C66C3838386C- <1>     db  000h, 000h, 0c6h, 0c6h, 06ch, 038h, 038h, 038h, 06ch, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   328 00010139 C6C60000000000      <1>
   329 00010140 666666663C1818183C- <1>     db  066h, 066h, 066h, 066h, 03ch, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h
   329 00010149 0000000000FEC6      <1>
   330 00010150 8C183060C2C6FE0000- <1>     db  08ch, 018h, 030h, 060h, 0c2h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 03ch, 030h, 030h, 030h
   330 00010159 0000003C303030      <1>
   331 00010160 303030303C00000000- <1>     db  030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch
   331 00010169 0080C0E070381C      <1>
   332 00010170 0E060200000000003C- <1>     db  00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch
   332 00010179 0C0C0C0C0C0C0C      <1>
   333 00010180 3C00000010386CC600- <1>     db  03ch, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   333 00010189 00000000000000      <1>
   334 00010190 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h
   334 00010199 0000000000FF00      <1>
   335 000101A0 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   335 000101A9 00000000000000      <1>
   336 000101B0 000000780C7CCCCC76- <1>     db  000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0e0h, 060h
   336 000101B9 0000000000E060      <1>
   337 000101C0 60786C6666667C0000- <1>     db  060h, 078h, 06ch, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   337 000101C9 0000000000007C      <1>
   338 000101D0 C6C0C0C67C00000000- <1>     db  0c6h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch
   338 000101D9 001C0C0C3C6CCC      <1>
   339 000101E0 CCCC76000000000000- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h
   339 000101E9 00007CC6FEC0C6      <1>
   340 000101F0 7C0000000000386C64- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 0f0h, 000h
   340 000101F9 60F0606060F000      <1>
   341 00010200 0000000000000076CC- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   341 00010209 CCCC7C0CCC7800      <1>
   342 00010210 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h
   342 00010219 66E60000000000      <1>
   343 00010220 18180038181818183C- <1>     db  018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 006h, 006h
   343 00010229 00000000000606      <1>
   344 00010230 000E0606060666663C- <1>     db  000h, 00eh, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h, 000h, 000h, 0e0h, 060h, 060h, 066h
   344 00010239 000000E0606066      <1>
   345 00010240 6C786C66E600000000- <1>     db  06ch, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h
   345 00010249 00381818181818      <1>
   346 00010250 18183C000000000000- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ech, 0feh, 0d6h, 0d6h, 0d6h
   346 00010259 0000ECFED6D6D6      <1>
   347 00010260 C60000000000000000- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 000h
   347 00010269 DC666666666600      <1>
   348 00010270 000000000000007CC6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h
   348 00010279 C6C6C67C000000      <1>
   349 00010280 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 000h, 000h
   349 00010289 7C6060F0000000      <1>
   350 00010290 00000076CCCCCC7C0C- <1>     db  000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h
   350 00010299 0C1E0000000000      <1>
   351 000102A0 00DC76666060F00000- <1>     db  000h, 0dch, 076h, 066h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   351 000102A9 0000000000007C      <1>
   352 000102B0 C6701CC67C00000000- <1>     db  0c6h, 070h, 01ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h
   352 000102B9 00103030FC3030      <1>
   353 000102C0 30361C000000000000- <1>     db  030h, 036h, 01ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch
   353 000102C9 0000CCCCCCCCCC      <1>
   354 000102D0 760000000000000000- <1>     db  076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 03ch, 018h, 000h
   354 000102D9 666666663C1800      <1>
   355 000102E0 00000000000000C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 06ch, 000h, 000h, 000h
   355 000102E9 D6D6FE6C000000      <1>
   356 000102F0 0000000000C66C3838- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h
   356 000102F9 6CC60000000000      <1>
   357 00010300 000000C6C6C6C67E06- <1>     db  000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h, 000h, 000h, 000h, 000h
   357 00010309 0CF80000000000      <1>
   358 00010310 00FECC183066FE0000- <1>     db  000h, 0feh, 0cch, 018h, 030h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 00eh, 018h, 018h, 018h
   358 00010319 0000000E181818      <1>
   359 00010320 701818180E00000000- <1>     db  070h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h
   359 00010329 00181818180018      <1>
   360 00010330 181818000000000070- <1>     db  018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h
   360 00010339 1818180E181818      <1>
   361 00010340 70000000000076DC00- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   361 00010349 00000000000000      <1>
   362 00010350 00000000000010386C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   362 00010359 C6C6FE00000000      <1>
   363 00010360 00003C66C2C0C0C266- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h, 000h
   363 00010369 3C0C067C000000      <1>
   364 00010370 CCCC00CCCCCCCCCC76- <1>     db  0cch, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h
   364 00010379 000000000C1830      <1>
   365 00010380 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 078h
   365 00010389 000010386C0078      <1>
   366 00010390 0C7CCCCC7600000000- <1>     db  00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 000h, 078h, 00ch, 07ch
   366 00010399 00CCCC00780C7C      <1>
   367 000103A0 CCCC76000000006030- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch
   367 000103A9 1800780C7CCCCC      <1>
   368 000103B0 7600000000386C3800- <1>     db  076h, 000h, 000h, 000h, 000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h
   368 000103B9 780C7CCCCC7600      <1>
   369 000103C0 0000000000003C6660- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h
   369 000103C9 663C0C063C0000      <1>
   370 000103D0 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   370 000103D9 C67C0000000000      <1>
   371 000103E0 CCCC007CC6FEC0C67C- <1>     db  0cch, 0cch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h
   371 000103E9 00000000603018      <1>
   372 000103F0 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 000h, 038h
   372 000103F9 00000066660038      <1>
   373 00010400 181818183C00000000- <1>     db  018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h
   373 00010409 183C6600381818      <1>
   374 00010410 18183C000000006030- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h
   374 00010419 18003818181818      <1>
   375 00010420 3C00000000C6C61038- <1>     db  03ch, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h
   375 00010429 6CC6C6FEC6C600      <1>
   376 00010430 0000386C3800386CC6- <1>     db  000h, 000h, 038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h, 000h, 000h
   376 00010439 C6FEC6C6000000      <1>
   377 00010440 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h
   377 00010449 66FE0000000000      <1>
   378 00010450 0000CC76367ED8D86E- <1>     db  000h, 000h, 0cch, 076h, 036h, 07eh, 0d8h, 0d8h, 06eh, 000h, 000h, 000h, 000h, 000h, 03eh, 06ch
   378 00010459 00000000003E6C      <1>
   379 00010460 CCCCFECCCCCCCE0000- <1>     db  0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 07ch
   379 00010469 000010386C007C      <1>
   380 00010470 C6C6C6C67C00000000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h, 07ch, 0c6h, 0c6h
   380 00010479 00C6C6007CC6C6      <1>
   381 00010480 C6C67C000000006030- <1>     db  0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h
   381 00010489 18007CC6C6C6C6      <1>
   382 00010490 7C000000003078CC00- <1>     db  07ch, 000h, 000h, 000h, 000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   382 00010499 CCCCCCCCCC7600      <1>
   383 000104A0 00000060301800CCCC- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h
   383 000104A9 CCCCCC76000000      <1>
   384 000104B0 0000C6C600C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h, 000h, 0c6h
   384 000104B9 7E060C780000C6      <1>
   385 000104C0 C6386CC6C6C6C66C38- <1>     db  0c6h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h
   385 000104C9 00000000C6C600      <1>
   386 000104D0 C6C6C6C6C6C67C0000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 018h, 03ch, 066h, 060h
   386 000104D9 000018183C6660      <1>
   387 000104E0 60663C181800000000- <1>     db  060h, 066h, 03ch, 018h, 018h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h
   387 000104E9 386C6460F06060      <1>
   388 000104F0 60E6FC000000000066- <1>     db  060h, 0e6h, 0fch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 03ch, 018h, 07eh, 018h, 07eh, 018h
   388 000104F9 663C187E187E18      <1>
   389 00010500 1800000000F8CCCCF8- <1>     db  018h, 000h, 000h, 000h, 000h, 0f8h, 0cch, 0cch, 0f8h, 0c4h, 0cch, 0deh, 0cch, 0cch, 0c6h, 000h
   389 00010509 C4CCDECCCCC600      <1>
   390 00010510 0000000E1B1818187E- <1>     db  000h, 000h, 000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h
   390 00010519 18181818D87000      <1>
   391 00010520 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch
   391 00010529 CC76000000000C      <1>
   392 00010530 18300038181818183C- <1>     db  018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h
   392 00010539 00000000183060      <1>
   393 00010540 007CC6C6C6C67C0000- <1>     db  000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h, 000h, 0cch
   393 00010549 000018306000CC      <1>
   394 00010550 CCCCCCCC7600000000- <1>     db  0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h
   394 00010559 0076DC00DC6666      <1>
   395 00010560 66666600000076DC00- <1>     db  066h, 066h, 066h, 000h, 000h, 000h, 076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h
   395 00010569 C6E6F6FEDECEC6      <1>
   396 00010570 C6000000003C6C6C3E- <1>     db  0c6h, 000h, 000h, 000h, 000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h
   396 00010579 007E0000000000      <1>
   397 00010580 000000386C6C38007C- <1>     db  000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   397 00010589 00000000000000      <1>
   398 00010590 0000303000303060C6- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   398 00010599 C67C0000000000      <1>
   399 000105A0 00000000FEC0C0C000- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   399 000105A9 00000000000000      <1>
   400 000105B0 0000FE060606000000- <1>     db  000h, 000h, 0feh, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h
   400 000105B9 0000C0C0C6CCD8      <1>
   401 000105C0 3060DC860C183E0000- <1>     db  030h, 060h, 0dch, 086h, 00ch, 018h, 03eh, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h, 030h, 066h
   401 000105C9 C0C0C6CCD83066      <1>
   402 000105D0 CE9E3E060600000018- <1>     db  0ceh, 09eh, 03eh, 006h, 006h, 000h, 000h, 000h, 018h, 018h, 000h, 018h, 018h, 03ch, 03ch, 03ch
   402 000105D9 180018183C3C3C      <1>
   403 000105E0 180000000000000036- <1>     db  018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h
   403 000105E9 6CD86C36000000      <1>
   404 000105F0 000000000000D86C36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h
   404 000105F9 6CD80000000000      <1>
   405 00010600 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 055h, 0aah
   405 00010609 441144114455AA      <1>
   406 00010610 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 0ddh, 077h, 0ddh, 077h
   406 00010619 AA55AADD77DD77      <1>
   407 00010620 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 018h, 018h, 018h, 018h, 018h, 018h
   407 00010629 77181818181818      <1>
   408 00010630 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h
   408 00010639 181818181818F8      <1>
   409 00010640 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h
   409 00010649 1818F818F81818      <1>
   410 00010650 181818183636363636- <1>     db  018h, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h
   410 00010659 3636F636363636      <1>
   411 00010660 363600000000000000- <1>     db  036h, 036h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h
   411 00010669 FE363636363636      <1>
   412 00010670 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 036h, 036h
   412 00010679 18181818183636      <1>
   413 00010680 363636F606F6363636- <1>     db  036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   413 00010689 36363636363636      <1>
   414 00010690 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0feh
   414 00010699 360000000000FE      <1>
   415 000106A0 06F636363636363636- <1>     db  006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh
   415 000106A9 36363636F606FE      <1>
   416 000106B0 000000000000363636- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h
   416 000106B9 36363636FE0000      <1>
   417 000106C0 000000001818181818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h
   417 000106C9 F818F800000000      <1>
   418 000106D0 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h
   418 000106D9 F8181818181818      <1>
   419 000106E0 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   419 000106E9 00000000001818      <1>
   420 000106F0 1818181818FF000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   420 000106F9 00000000000000      <1>
   421 00010700 000000FF1818181818- <1>     db  000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   421 00010709 18181818181818      <1>
   422 00010710 181F18181818181800- <1>     db  018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   422 00010719 000000000000FF      <1>
   423 00010720 000000000000181818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h
   423 00010729 18181818FF1818      <1>
   424 00010730 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h
   424 00010739 1F181F18181818      <1>
   425 00010740 181836363636363636- <1>     db  018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h
   425 00010749 37363636363636      <1>
   426 00010750 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   426 00010759 00000000000000      <1>
   427 00010760 0000003F3037363636- <1>     db  000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   427 00010769 36363636363636      <1>
   428 00010770 36F700FF0000000000- <1>     db  036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   428 00010779 000000000000FF      <1>
   429 00010780 00F736363636363636- <1>     db  000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h
   429 00010789 36363636373037      <1>
   430 00010790 363636363636000000- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h
   430 00010799 0000FF00FF0000      <1>
   431 000107A0 000000003636363636- <1>     db  000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h
   431 000107A9 F700F736363636      <1>
   432 000107B0 36361818181818FF00- <1>     db  036h, 036h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h
   432 000107B9 FF000000000000      <1>
   433 000107C0 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   433 000107C9 00000000000000      <1>
   434 000107D0 000000FF00FF181818- <1>     db  000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   434 000107D9 18181800000000      <1>
   435 000107E0 000000FF3636363636- <1>     db  000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   435 000107E9 36363636363636      <1>
   436 000107F0 363F00000000000018- <1>     db  036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh
   436 000107F9 181818181F181F      <1>
   437 00010800 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h
   437 00010809 00001F181F1818      <1>
   438 00010810 181818180000000000- <1>     db  018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h
   438 00010819 00003F36363636      <1>
   439 00010820 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h
   439 00010829 FF363636363636      <1>
   440 00010830 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   440 00010839 18181818181818      <1>
   441 00010840 1818181818F8000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   441 00010849 00000000000000      <1>
   442 00010850 0000001F1818181818- <1>     db  000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   442 00010859 18FFFFFFFFFFFF      <1>
   443 00010860 FFFFFFFFFFFFFFFF00- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   443 00010869 000000000000FF      <1>
   444 00010870 FFFFFFFFFFFFF0F0F0- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   444 00010879 F0F0F0F0F0F0F0      <1>
   445 00010880 F0F0F0F00F0F0F0F0F- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   445 00010889 0F0F0F0F0F0F0F      <1>
   446 00010890 0F0FFFFFFFFFFFFFFF- <1>     db  00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   446 00010899 00000000000000      <1>
   447 000108A0 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h, 000h
   447 000108A9 DC760000000000      <1>
   448 000108B0 00007CC6FCC6C6FCC0- <1>     db  000h, 000h, 07ch, 0c6h, 0fch, 0c6h, 0c6h, 0fch, 0c0h, 0c0h, 040h, 000h, 000h, 000h, 0feh, 0c6h
   448 000108B9 C040000000FEC6      <1>
   449 000108C0 C6C0C0C0C0C0C00000- <1>     db  0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 06ch
   449 000108C9 0000000000FE6C      <1>
   450 000108D0 6C6C6C6C6C00000000- <1>     db  06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h
   450 000108D9 00FEC660301830      <1>
   451 000108E0 60C6FE000000000000- <1>     db  060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h
   451 000108E9 00007ED8D8D8D8      <1>
   452 000108F0 700000000000000066- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h
   452 000108F9 6666667C6060C0      <1>
   453 00010900 00000000000076DC18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h
   453 00010909 18181818000000      <1>
   454 00010910 00007E183C6666663C- <1>     db  000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h, 000h
   454 00010919 187E0000000000      <1>
   455 00010920 386CC6C6FEC6C66C38- <1>     db  038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch
   455 00010929 0000000000386C      <1>
   456 00010930 C6C6C66C6C6CEE0000- <1>     db  0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h, 000h, 01eh, 030h, 018h, 00ch
   456 00010939 0000001E30180C      <1>
   457 00010940 3E6666663C00000000- <1>     db  03eh, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh
   457 00010949 000000007EDBDB      <1>
   458 00010950 7E0000000000000003- <1>     db  07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h
   458 00010959 067EDBDBF37E60      <1>
   459 00010960 C000000000001C3060- <1>     db  0c0h, 000h, 000h, 000h, 000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 030h, 01ch, 000h
   459 00010969 607C6060301C00      <1>
   460 00010970 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h
   460 00010979 C6C6C6C6000000      <1>
   461 00010980 000000FE0000FE0000- <1>     db  000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   461 00010989 FE000000000000      <1>
   462 00010990 0018187E18180000FF- <1>     db  000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 030h, 018h
   462 00010999 00000000003018      <1>
   463 000109A0 0C060C1830007E0000- <1>     db  00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h, 060h
   463 000109A9 0000000C183060      <1>
   464 000109B0 30180C007E00000000- <1>     db  030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h
   464 000109B9 000E1B1B181818      <1>
   465 000109C0 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h
   465 000109C9 1818181818D8D8      <1>
   466 000109D0 700000000000001818- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h
   466 000109D9 007E0018180000      <1>
   467 000109E0 00000000000076DC00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h
   467 000109E9 76DC0000000000      <1>
   468 000109F0 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   468 000109F9 00000000000000      <1>
   469 00010A00 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   469 00010A09 00000000000000      <1>
   470 00010A10 000000180000000000- <1>     db  000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 00ch
   470 00010A19 00000F0C0C0C0C      <1>
   471 00010A20 0CEC6C3C1C00000000- <1>     db  00ch, 0ech, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   471 00010A29 D86C6C6C6C6C00      <1>
   472 00010A30 0000000000000070D8- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h
   472 00010A39 3060C8F8000000      <1>
   473 00010A40 00000000000000007C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h
   473 00010A49 7C7C7C7C7C0000      <1>
   474 00010A50 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   474 00010A59 00000000000000      <1>
   475                              <1> vgafont16:
   476 00010A60 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   476 00010A69 00000000000000      <1>
   477 00010A70 00007E81A58181BD99- <1>     db  000h, 000h, 07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 081h, 07eh, 000h, 000h, 000h, 000h
   477 00010A79 81817E00000000      <1>
   478 00010A80 00007EFFDBFFFFC3E7- <1>     db  000h, 000h, 07eh, 0ffh, 0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 0ffh, 07eh, 000h, 000h, 000h, 000h
   478 00010A89 FFFF7E00000000      <1>
   479 00010A90 000000006CFEFEFEFE- <1>     db  000h, 000h, 000h, 000h, 06ch, 0feh, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h
   479 00010A99 7C381000000000      <1>
   480 00010AA0 0000000010387CFE7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   480 00010AA9 38100000000000      <1>
   481 00010AB0 000000183C3CE7E7E7- <1>     db  000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   481 00010AB9 18183C00000000      <1>
   482 00010AC0 000000183C7EFFFF7E- <1>     db  000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   482 00010AC9 18183C00000000      <1>
   483 00010AD0 000000000000183C3C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   483 00010AD9 18000000000000      <1>
   484 00010AE0 FFFFFFFFFFFFE7C3C3- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   484 00010AE9 E7FFFFFFFFFFFF      <1>
   485 00010AF0 00000000003C664242- <1>     db  000h, 000h, 000h, 000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h
   485 00010AF9 663C0000000000      <1>
   486 00010B00 FFFFFFFFFFC399BDBD- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   486 00010B09 99C3FFFFFFFFFF      <1>
   487 00010B10 00001E0E1A3278CCCC- <1>     db  000h, 000h, 01eh, 00eh, 01ah, 032h, 078h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   487 00010B19 CCCC7800000000      <1>
   488 00010B20 00003C666666663C18- <1>     db  000h, 000h, 03ch, 066h, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   488 00010B29 7E181800000000      <1>
   489 00010B30 00003F333F30303030- <1>     db  000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 030h, 070h, 0f0h, 0e0h, 000h, 000h, 000h, 000h
   489 00010B39 70F0E000000000      <1>
   490 00010B40 00007F637F63636363- <1>     db  000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h, 000h, 000h, 000h
   490 00010B49 67E7E6C0000000      <1>
   491 00010B50 0000001818DB3CE73C- <1>     db  000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h, 000h
   491 00010B59 DB181800000000      <1>
   492 00010B60 0080C0E0F0F8FEF8F0- <1>     db  000h, 080h, 0c0h, 0e0h, 0f0h, 0f8h, 0feh, 0f8h, 0f0h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h
   492 00010B69 E0C08000000000      <1>
   493 00010B70 0002060E1E3EFE3E1E- <1>     db  000h, 002h, 006h, 00eh, 01eh, 03eh, 0feh, 03eh, 01eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   493 00010B79 0E060200000000      <1>
   494 00010B80 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   494 00010B89 3C180000000000      <1>
   495 00010B90 000066666666666666- <1>     db  000h, 000h, 066h, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h
   495 00010B99 00666600000000      <1>
   496 00010BA0 00007FDBDBDB7B1B1B- <1>     db  000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 01bh, 01bh, 000h, 000h, 000h, 000h
   496 00010BA9 1B1B1B00000000      <1>
   497 00010BB0 007CC660386CC6C66C- <1>     db  000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h
   497 00010BB9 380CC67C000000      <1>
   498 00010BC0 0000000000000000FE- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 0feh, 000h, 000h, 000h, 000h
   498 00010BC9 FEFEFE00000000      <1>
   499 00010BD0 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   499 00010BD9 3C187E00000000      <1>
   500 00010BE0 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   500 00010BE9 18181800000000      <1>
   501 00010BF0 000018181818181818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h
   501 00010BF9 7E3C1800000000      <1>
   502 00010C00 0000000000180CFE0C- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   502 00010C09 18000000000000      <1>
   503 00010C10 00000000003060FE60- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h
   503 00010C19 30000000000000      <1>
   504 00010C20 000000000000C0C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   504 00010C29 FE000000000000      <1>
   505 00010C30 00000000002466FF66- <1>     db  000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h
   505 00010C39 24000000000000      <1>
   506 00010C40 000000001038387C7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h, 000h, 000h, 000h
   506 00010C49 FEFE0000000000      <1>
   507 00010C50 00000000FEFE7C7C38- <1>     db  000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   507 00010C59 38100000000000      <1>
   508 00010C60 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   508 00010C69 00000000000000      <1>
   509 00010C70 0000183C3C3C181818- <1>     db  000h, 000h, 018h, 03ch, 03ch, 03ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   509 00010C79 00181800000000      <1>
   510 00010C80 006666662400000000- <1>     db  000h, 066h, 066h, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   510 00010C89 00000000000000      <1>
   511 00010C90 0000006C6CFE6C6C6C- <1>     db  000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 000h
   511 00010C99 FE6C6C00000000      <1>
   512 00010CA0 18187CC6C2C07C0606- <1>     db  018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h, 006h, 086h, 0c6h, 07ch, 018h, 018h, 000h, 000h
   512 00010CA9 86C67C18180000      <1>
   513 00010CB0 00000000C2C60C1830- <1>     db  000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 060h, 0c6h, 086h, 000h, 000h, 000h, 000h
   513 00010CB9 60C68600000000      <1>
   514 00010CC0 0000386C6C3876DCCC- <1>     db  000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   514 00010CC9 CCCC7600000000      <1>
   515 00010CD0 003030306000000000- <1>     db  000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   515 00010CD9 00000000000000      <1>
   516 00010CE0 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h
   516 00010CE9 30180C00000000      <1>
   517 00010CF0 000030180C0C0C0C0C- <1>     db  000h, 000h, 030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h
   517 00010CF9 0C183000000000      <1>
   518 00010D00 0000000000663CFF3C- <1>     db  000h, 000h, 000h, 000h, 000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h
   518 00010D09 66000000000000      <1>
   519 00010D10 000000000018187E18- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   519 00010D19 18000000000000      <1>
   520 00010D20 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 030h, 000h, 000h, 000h
   520 00010D29 18181830000000      <1>
   521 00010D30 00000000000000FE00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   521 00010D39 00000000000000      <1>
   522 00010D40 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   522 00010D49 00181800000000      <1>
   523 00010D50 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   523 00010D59 60C08000000000      <1>
   524 00010D60 00003C66C3C3DBDBC3- <1>     db  000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h, 000h, 000h
   524 00010D69 C3663C00000000      <1>
   525 00010D70 000018387818181818- <1>     db  000h, 000h, 018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h
   525 00010D79 18187E00000000      <1>
   526 00010D80 00007CC6060C183060- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   526 00010D89 C0C6FE00000000      <1>
   527 00010D90 00007CC606063C0606- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 006h, 03ch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   527 00010D99 06C67C00000000      <1>
   528 00010DA0 00000C1C3C6CCCFE0C- <1>     db  000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h
   528 00010DA9 0C0C1E00000000      <1>
   529 00010DB0 0000FEC0C0C0FC0606- <1>     db  000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   529 00010DB9 06C67C00000000      <1>
   530 00010DC0 00003860C0C0FCC6C6- <1>     db  000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   530 00010DC9 C6C67C00000000      <1>
   531 00010DD0 0000FEC606060C1830- <1>     db  000h, 000h, 0feh, 0c6h, 006h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h, 000h
   531 00010DD9 30303000000000      <1>
   532 00010DE0 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   532 00010DE9 C6C67C00000000      <1>
   533 00010DF0 00007CC6C6C67E0606- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h
   533 00010DF9 060C7800000000      <1>
   534 00010E00 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   534 00010E09 18180000000000      <1>
   535 00010E10 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h
   535 00010E19 18183000000000      <1>
   536 00010E20 000000060C18306030- <1>     db  000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 006h, 000h, 000h, 000h, 000h
   536 00010E29 180C0600000000      <1>
   537 00010E30 00000000007E00007E- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   537 00010E39 00000000000000      <1>
   538 00010E40 0000006030180C060C- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h, 000h, 000h, 000h
   538 00010E49 18306000000000      <1>
   539 00010E50 00007CC6C60C181818- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   539 00010E59 00181800000000      <1>
   540 00010E60 0000007CC6C6DEDEDE- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h
   540 00010E69 DCC07C00000000      <1>
   541 00010E70 000010386CC6C6FEC6- <1>     db  000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   541 00010E79 C6C6C600000000      <1>
   542 00010E80 0000FC6666667C6666- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 066h, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h
   542 00010E89 6666FC00000000      <1>
   543 00010E90 00003C66C2C0C0C0C0- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h
   543 00010E99 C2663C00000000      <1>
   544 00010EA0 0000F86C6666666666- <1>     db  000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h, 066h, 066h, 06ch, 0f8h, 000h, 000h, 000h, 000h
   544 00010EA9 666CF800000000      <1>
   545 00010EB0 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   545 00010EB9 6266FE00000000      <1>
   546 00010EC0 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   546 00010EC9 6060F000000000      <1>
   547 00010ED0 00003C66C2C0C0DEC6- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 0c6h, 066h, 03ah, 000h, 000h, 000h, 000h
   547 00010ED9 C6663A00000000      <1>
   548 00010EE0 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   548 00010EE9 C6C6C600000000      <1>
   549 00010EF0 00003C181818181818- <1>     db  000h, 000h, 03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   549 00010EF9 18183C00000000      <1>
   550 00010F00 00001E0C0C0C0C0CCC- <1>     db  000h, 000h, 01eh, 00ch, 00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   550 00010F09 CCCC7800000000      <1>
   551 00010F10 0000E666666C78786C- <1>     db  000h, 000h, 0e6h, 066h, 066h, 06ch, 078h, 078h, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   551 00010F19 6666E600000000      <1>
   552 00010F20 0000F0606060606060- <1>     db  000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   552 00010F29 6266FE00000000      <1>
   553 00010F30 0000C3E7FFFFDBC3C3- <1>     db  000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   553 00010F39 C3C3C300000000      <1>
   554 00010F40 0000C6E6F6FEDECEC6- <1>     db  000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   554 00010F49 C6C6C600000000      <1>
   555 00010F50 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   555 00010F59 C6C67C00000000      <1>
   556 00010F60 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   556 00010F69 6060F000000000      <1>
   557 00010F70 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h
   557 00010F79 D6DE7C0C0E0000      <1>
   558 00010F80 0000FC6666667C6C66- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 06ch, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   558 00010F89 6666E600000000      <1>
   559 00010F90 00007CC6C660380C06- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 060h, 038h, 00ch, 006h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   559 00010F99 C6C67C00000000      <1>
   560 00010FA0 0000FFDB9918181818- <1>     db  000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   560 00010FA9 18183C00000000      <1>
   561 00010FB0 0000C6C6C6C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   561 00010FB9 C6C67C00000000      <1>
   562 00010FC0 0000C3C3C3C3C3C3C3- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   562 00010FC9 663C1800000000      <1>
   563 00010FD0 0000C3C3C3C3C3DBDB- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 000h
   563 00010FD9 FF666600000000      <1>
   564 00010FE0 0000C3C3663C18183C- <1>     db  000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   564 00010FE9 66C3C300000000      <1>
   565 00010FF0 0000C3C3C3663C1818- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   565 00010FF9 18183C00000000      <1>
   566 00011000 0000FFC3860C183060- <1>     db  000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h
   566 00011009 C1C3FF00000000      <1>
   567 00011010 00003C303030303030- <1>     db  000h, 000h, 03ch, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h
   567 00011019 30303C00000000      <1>
   568 00011020 00000080C0E070381C- <1>     db  000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   568 00011029 0E060200000000      <1>
   569 00011030 00003C0C0C0C0C0C0C- <1>     db  000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 03ch, 000h, 000h, 000h, 000h
   569 00011039 0C0C3C00000000      <1>
   570 00011040 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   570 00011049 00000000000000      <1>
   571 00011050 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h
   571 00011059 00000000FF0000      <1>
   572 00011060 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   572 00011069 00000000000000      <1>
   573 00011070 0000000000780C7CCC- <1>     db  000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   573 00011079 CCCC7600000000      <1>
   574 00011080 0000E06060786C6666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 078h, 06ch, 066h, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h
   574 00011089 66667C00000000      <1>
   575 00011090 00000000007CC6C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c0h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   575 00011099 C0C67C00000000      <1>
   576 000110A0 00001C0C0C3C6CCCCC- <1>     db  000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   576 000110A9 CCCC7600000000      <1>
   577 000110B0 00000000007CC6FEC0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   577 000110B9 C0C67C00000000      <1>
   578 000110C0 0000386C6460F06060- <1>     db  000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   578 000110C9 6060F000000000      <1>
   579 000110D0 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   579 000110D9 CCCC7C0CCC7800      <1>
   580 000110E0 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   580 000110E9 6666E600000000      <1>
   581 000110F0 000018180038181818- <1>     db  000h, 000h, 018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   581 000110F9 18183C00000000      <1>
   582 00011100 00000606000E060606- <1>     db  000h, 000h, 006h, 006h, 000h, 00eh, 006h, 006h, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h
   582 00011109 06060666663C00      <1>
   583 00011110 0000E06060666C7878- <1>     db  000h, 000h, 0e0h, 060h, 060h, 066h, 06ch, 078h, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h
   583 00011119 6C66E600000000      <1>
   584 00011120 000038181818181818- <1>     db  000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   584 00011129 18183C00000000      <1>
   585 00011130 0000000000E6FFDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h
   585 00011139 DBDBDB00000000      <1>
   586 00011140 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   586 00011149 66666600000000      <1>
   587 00011150 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   587 00011159 C6C67C00000000      <1>
   588 00011160 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h
   588 00011169 66667C6060F000      <1>
   589 00011170 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h
   589 00011179 CCCC7C0C0C1E00      <1>
   590 00011180 0000000000DC766660- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 076h, 066h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   590 00011189 6060F000000000      <1>
   591 00011190 00000000007CC66038- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h
   591 00011199 0CC67C00000000      <1>
   592 000111A0 0000103030FC303030- <1>     db  000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h, 030h, 030h, 036h, 01ch, 000h, 000h, 000h, 000h
   592 000111A9 30361C00000000      <1>
   593 000111B0 0000000000CCCCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   593 000111B9 CCCC7600000000      <1>
   594 000111C0 0000000000C3C3C3C3- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   594 000111C9 663C1800000000      <1>
   595 000111D0 0000000000C3C3C3DB- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h
   595 000111D9 DBFF6600000000      <1>
   596 000111E0 0000000000C3663C18- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h
   596 000111E9 3C66C300000000      <1>
   597 000111F0 0000000000C6C6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h
   597 000111F9 C6C67E060CF800      <1>
   598 00011200 0000000000FECC1830- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0cch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   598 00011209 60C6FE00000000      <1>
   599 00011210 00000E181818701818- <1>     db  000h, 000h, 00eh, 018h, 018h, 018h, 070h, 018h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h
   599 00011219 18180E00000000      <1>
   600 00011220 000018181818001818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   600 00011229 18181800000000      <1>
   601 00011230 0000701818180E1818- <1>     db  000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h, 018h, 070h, 000h, 000h, 000h, 000h
   601 00011239 18187000000000      <1>
   602 00011240 000076DC0000000000- <1>     db  000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   602 00011249 00000000000000      <1>
   603 00011250 0000000010386CC6C6- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h
   603 00011259 C6FE0000000000      <1>
   604 00011260 00003C66C2C0C0C0C2- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h
   604 00011269 663C0C067C0000      <1>
   605 00011270 0000CC0000CCCCCCCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   605 00011279 CCCC7600000000      <1>
   606 00011280 000C1830007CC6FEC0- <1>     db  000h, 00ch, 018h, 030h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   606 00011289 C0C67C00000000      <1>
   607 00011290 0010386C00780C7CCC- <1>     db  000h, 010h, 038h, 06ch, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   607 00011299 CCCC7600000000      <1>
   608 000112A0 0000CC0000780C7CCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   608 000112A9 CCCC7600000000      <1>
   609 000112B0 0060301800780C7CCC- <1>     db  000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   609 000112B9 CCCC7600000000      <1>
   610 000112C0 00386C3800780C7CCC- <1>     db  000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   610 000112C9 CCCC7600000000      <1>
   611 000112D0 000000003C66606066- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 060h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h, 000h
   611 000112D9 3C0C063C000000      <1>
   612 000112E0 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   612 000112E9 C0C67C00000000      <1>
   613 000112F0 0000C600007CC6FEC0- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   613 000112F9 C0C67C00000000      <1>
   614 00011300 00603018007CC6FEC0- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   614 00011309 C0C67C00000000      <1>
   615 00011310 000066000038181818- <1>     db  000h, 000h, 066h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   615 00011319 18183C00000000      <1>
   616 00011320 00183C660038181818- <1>     db  000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   616 00011329 18183C00000000      <1>
   617 00011330 006030180038181818- <1>     db  000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   617 00011339 18183C00000000      <1>
   618 00011340 00C60010386CC6C6FE- <1>     db  000h, 0c6h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   618 00011349 C6C6C600000000      <1>
   619 00011350 386C3800386CC6C6FE- <1>     db  038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   619 00011359 C6C6C600000000      <1>
   620 00011360 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 060h, 066h, 0feh, 000h, 000h, 000h, 000h
   620 00011369 6066FE00000000      <1>
   621 00011370 00000000006E3B1B7E- <1>     db  000h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h
   621 00011379 D8DC7700000000      <1>
   622 00011380 00003E6CCCCCFECCCC- <1>     db  000h, 000h, 03eh, 06ch, 0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h
   622 00011389 CCCCCE00000000      <1>
   623 00011390 0010386C007CC6C6C6- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   623 00011399 C6C67C00000000      <1>
   624 000113A0 0000C600007CC6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   624 000113A9 C6C67C00000000      <1>
   625 000113B0 00603018007CC6C6C6- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   625 000113B9 C6C67C00000000      <1>
   626 000113C0 003078CC00CCCCCCCC- <1>     db  000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   626 000113C9 CCCC7600000000      <1>
   627 000113D0 0060301800CCCCCCCC- <1>     db  000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   627 000113D9 CCCC7600000000      <1>
   628 000113E0 0000C60000C6C6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h
   628 000113E9 C6C67E060C7800      <1>
   629 000113F0 00C6007CC6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   629 000113F9 C6C67C00000000      <1>
   630 00011400 00C600C6C6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   630 00011409 C6C67C00000000      <1>
   631 00011410 0018187EC3C0C0C0C3- <1>     db  000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   631 00011419 7E181800000000      <1>
   632 00011420 00386C6460F0606060- <1>     db  000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0e6h, 0fch, 000h, 000h, 000h, 000h
   632 00011429 60E6FC00000000      <1>
   633 00011430 0000C3663C18FF18FF- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   633 00011439 18181800000000      <1>
   634 00011440 00FC66667C62666F66- <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h, 000h
   634 00011449 6666F300000000      <1>
   635 00011450 000E1B1818187E1818- <1>     db  000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h, 000h
   635 00011459 181818D8700000      <1>
   636 00011460 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   636 00011469 CCCC7600000000      <1>
   637 00011470 000C18300038181818- <1>     db  000h, 00ch, 018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   637 00011479 18183C00000000      <1>
   638 00011480 00183060007CC6C6C6- <1>     db  000h, 018h, 030h, 060h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   638 00011489 C6C67C00000000      <1>
   639 00011490 0018306000CCCCCCCC- <1>     db  000h, 018h, 030h, 060h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   639 00011499 CCCC7600000000      <1>
   640 000114A0 000076DC00DC666666- <1>     db  000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   640 000114A9 66666600000000      <1>
   641 000114B0 76DC00C6E6F6FEDECE- <1>     db  076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   641 000114B9 C6C6C600000000      <1>
   642 000114C0 003C6C6C3E007E0000- <1>     db  000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   642 000114C9 00000000000000      <1>
   643 000114D0 00386C6C38007C0000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   643 000114D9 00000000000000      <1>
   644 000114E0 0000303000303060C0- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c0h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   644 000114E9 C6C67C00000000      <1>
   645 000114F0 000000000000FEC0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h
   645 000114F9 C0C00000000000      <1>
   646 00011500 000000000000FE0606- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 006h, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h
   646 00011509 06060000000000      <1>
   647 00011510 00C0C0C2C6CC183060- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh, 000h, 000h
   647 00011519 CE9B060C1F0000      <1>
   648 00011520 00C0C0C2C6CC183066- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h, 006h, 000h, 000h
   648 00011529 CE963E06060000      <1>
   649 00011530 00001818001818183C- <1>     db  000h, 000h, 018h, 018h, 000h, 018h, 018h, 018h, 03ch, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h
   649 00011539 3C3C1800000000      <1>
   650 00011540 0000000000366CD86C- <1>     db  000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h, 000h, 000h, 000h
   650 00011549 36000000000000      <1>
   651 00011550 0000000000D86C366C- <1>     db  000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h, 000h
   651 00011559 D8000000000000      <1>
   652 00011560 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h
   652 00011569 44114411441144      <1>
   653 00011570 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   653 00011579 AA55AA55AA55AA      <1>
   654 00011580 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h
   654 00011589 77DD77DD77DD77      <1>
   655 00011590 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   655 00011599 18181818181818      <1>
   656 000115A0 18181818181818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   656 000115A9 18181818181818      <1>
   657 000115B0 1818181818F818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   657 000115B9 18181818181818      <1>
   658 000115C0 36363636363636F636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   658 000115C9 36363636363636      <1>
   659 000115D0 00000000000000FE36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   659 000115D9 36363636363636      <1>
   660 000115E0 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   660 000115E9 18181818181818      <1>
   661 000115F0 3636363636F606F636- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   661 000115F9 36363636363636      <1>
   662 00011600 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   662 00011609 36363636363636      <1>
   663 00011610 0000000000FE06F636- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   663 00011619 36363636363636      <1>
   664 00011620 3636363636F606FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   664 00011629 00000000000000      <1>
   665 00011630 36363636363636FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   665 00011639 00000000000000      <1>
   666 00011640 1818181818F818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   666 00011649 00000000000000      <1>
   667 00011650 00000000000000F818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   667 00011659 18181818181818      <1>
   668 00011660 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   668 00011669 00000000000000      <1>
   669 00011670 18181818181818FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   669 00011679 00000000000000      <1>
   670 00011680 00000000000000FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   670 00011689 18181818181818      <1>
   671 00011690 181818181818181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   671 00011699 18181818181818      <1>
   672 000116A0 00000000000000FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   672 000116A9 00000000000000      <1>
   673 000116B0 18181818181818FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   673 000116B9 18181818181818      <1>
   674 000116C0 18181818181F181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   674 000116C9 18181818181818      <1>
   675 000116D0 363636363636363736- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   675 000116D9 36363636363636      <1>
   676 000116E0 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   676 000116E9 00000000000000      <1>
   677 000116F0 00000000003F303736- <1>     db  000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   677 000116F9 36363636363636      <1>
   678 00011700 3636363636F700FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   678 00011709 00000000000000      <1>
   679 00011710 0000000000FF00F736- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   679 00011719 36363636363636      <1>
   680 00011720 363636363637303736- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   680 00011729 36363636363636      <1>
   681 00011730 0000000000FF00FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   681 00011739 00000000000000      <1>
   682 00011740 3636363636F700F736- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   682 00011749 36363636363636      <1>
   683 00011750 1818181818FF00FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   683 00011759 00000000000000      <1>
   684 00011760 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   684 00011769 00000000000000      <1>
   685 00011770 0000000000FF00FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   685 00011779 18181818181818      <1>
   686 00011780 00000000000000FF36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   686 00011789 36363636363636      <1>
   687 00011790 363636363636363F00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   687 00011799 00000000000000      <1>
   688 000117A0 18181818181F181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   688 000117A9 00000000000000      <1>
   689 000117B0 00000000001F181F18- <1>     db  000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   689 000117B9 18181818181818      <1>
   690 000117C0 000000000000003F36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   690 000117C9 36363636363636      <1>
   691 000117D0 36363636363636FF36- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   691 000117D9 36363636363636      <1>
   692 000117E0 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   692 000117E9 18181818181818      <1>
   693 000117F0 18181818181818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   693 000117F9 00000000000000      <1>
   694 00011800 000000000000001F18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   694 00011809 18181818181818      <1>
   695 00011810 FFFFFFFFFFFFFFFFFF- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   695 00011819 FFFFFFFFFFFFFF      <1>
   696 00011820 00000000000000FFFF- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   696 00011829 FFFFFFFFFFFFFF      <1>
   697 00011830 F0F0F0F0F0F0F0F0F0- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   697 00011839 F0F0F0F0F0F0F0      <1>
   698 00011840 0F0F0F0F0F0F0F0F0F- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   698 00011849 0F0F0F0F0F0F0F      <1>
   699 00011850 FFFFFFFFFFFFFF0000- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   699 00011859 00000000000000      <1>
   700 00011860 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h
   700 00011869 D8DC7600000000      <1>
   701 00011870 000078CCCCCCD8CCC6- <1>     db  000h, 000h, 078h, 0cch, 0cch, 0cch, 0d8h, 0cch, 0c6h, 0c6h, 0c6h, 0cch, 000h, 000h, 000h, 000h
   701 00011879 C6C6CC00000000      <1>
   702 00011880 0000FEC6C6C0C0C0C0- <1>     db  000h, 000h, 0feh, 0c6h, 0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h
   702 00011889 C0C0C000000000      <1>
   703 00011890 00000000FE6C6C6C6C- <1>     db  000h, 000h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h
   703 00011899 6C6C6C00000000      <1>
   704 000118A0 000000FEC660301830- <1>     db  000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   704 000118A9 60C6FE00000000      <1>
   705 000118B0 00000000007ED8D8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   705 000118B9 D8D87000000000      <1>
   706 000118C0 000000006666666666- <1>     db  000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h, 000h, 000h, 000h
   706 000118C9 7C6060C0000000      <1>
   707 000118D0 0000000076DC181818- <1>     db  000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   707 000118D9 18181800000000      <1>
   708 000118E0 0000007E183C666666- <1>     db  000h, 000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   708 000118E9 3C187E00000000      <1>
   709 000118F0 000000386CC6C6FEC6- <1>     db  000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h
   709 000118F9 C66C3800000000      <1>
   710 00011900 0000386CC6C6C66C6C- <1>     db  000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h
   710 00011909 6C6CEE00000000      <1>
   711 00011910 00001E30180C3E6666- <1>     db  000h, 000h, 01eh, 030h, 018h, 00ch, 03eh, 066h, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h
   711 00011919 66663C00000000      <1>
   712 00011920 00000000007EDBDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh, 0dbh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h
   712 00011929 7E000000000000      <1>
   713 00011930 00000003067EDBDBF3- <1>     db  000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h, 0c0h, 000h, 000h, 000h, 000h
   713 00011939 7E60C000000000      <1>
   714 00011940 00001C3060607C6060- <1>     db  000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 060h, 030h, 01ch, 000h, 000h, 000h, 000h
   714 00011949 60301C00000000      <1>
   715 00011950 0000007CC6C6C6C6C6- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   715 00011959 C6C6C600000000      <1>
   716 00011960 00000000FE0000FE00- <1>     db  000h, 000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h
   716 00011969 00FE0000000000      <1>
   717 00011970 0000000018187E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h
   717 00011979 0000FF00000000      <1>
   718 00011980 00000030180C060C18- <1>     db  000h, 000h, 000h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h
   718 00011989 30007E00000000      <1>
   719 00011990 0000000C1830603018- <1>     db  000h, 000h, 000h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h
   719 00011999 0C007E00000000      <1>
   720 000119A0 00000E1B1B18181818- <1>     db  000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   720 000119A9 18181818181818      <1>
   721 000119B0 1818181818181818D8- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   721 000119B9 D8D87000000000      <1>
   722 000119C0 000000001818007E00- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   722 000119C9 18180000000000      <1>
   723 000119D0 000000000076DC0076- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h
   723 000119D9 DC000000000000      <1>
   724 000119E0 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   724 000119E9 00000000000000      <1>
   725 000119F0 000000000000001818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   725 000119F9 00000000000000      <1>
   726 00011A00 000000000000000018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   726 00011A09 00000000000000      <1>
   727 00011A10 000F0C0C0C0C0CEC6C- <1>     db  000h, 00fh, 00ch, 00ch, 00ch, 00ch, 00ch, 0ech, 06ch, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h
   727 00011A19 6C3C1C00000000      <1>
   728 00011A20 00D86C6C6C6C6C0000- <1>     db  000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   728 00011A29 00000000000000      <1>
   729 00011A30 0070D83060C8F80000- <1>     db  000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   729 00011A39 00000000000000      <1>
   730 00011A40 000000007C7C7C7C7C- <1>     db  000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h, 000h, 000h, 000h
   730 00011A49 7C7C0000000000      <1>
   731 00011A50 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   731 00011A59 00000000000000      <1>
   732                              <1> vgafont14alt:
   733 00011A60 1D000000002466FF66- <1>     db  01dh, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 022h
   733 00011A69 24000000000022      <1>
   734 00011A70 006363632200000000- <1>     db  000h, 063h, 063h, 063h, 022h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02bh, 000h
   734 00011A79 00000000002B00      <1>
   735 00011A80 0000181818FF181818- <1>     db  000h, 000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 02dh, 000h, 000h
   735 00011A89 000000002D0000      <1>
   736 00011A90 00000000FF00000000- <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 04dh, 000h, 000h, 0c3h
   736 00011A99 0000004D0000C3      <1>
   737 00011AA0 E7FFDBC3C3C3C3C300- <1>     db  0e7h, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh
   737 00011AA9 0000540000FFDB      <1>
   738 00011AB0 9918181818183C0000- <1>     db  099h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h
   738 00011AB9 00560000C3C3C3      <1>
   739 00011AC0 C3C3C3663C18000000- <1>     db  0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h
   739 00011AC9 570000C3C3C3C3      <1>
   740 00011AD0 DBDBFF666600000058- <1>     db  0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h
   740 00011AD9 0000C3C3663C18      <1>
   741 00011AE0 3C66C3C30000005900- <1>     db  03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   741 00011AE9 00C3C3C3663C18      <1>
   742 00011AF0 18183C0000005A0000- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 061h
   742 00011AF9 FFC3860C183061      <1>
   743 00011B00 C3FF0000006D000000- <1>     db  0c3h, 0ffh, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh
   743 00011B09 0000E6FFDBDBDB      <1>
   744 00011B10 DB0000007600000000- <1>     db  0dbh, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   744 00011B19 00C3C3C3663C18      <1>
   745 00011B20 000000770000000000- <1>     db  000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h
   745 00011B29 C3C3DBDBFF6600      <1>
   746 00011B30 000091000000006E3B- <1>     db  000h, 000h, 091h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h
   746 00011B39 1B7ED8DC770000      <1>
   747 00011B40 009B0018187EC3C0C0- <1>     db  000h, 09bh, 000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h
   747 00011B49 C37E1818000000      <1>
   748 00011B50 9D0000C3663C18FF18- <1>     db  09dh, 000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 000h, 000h, 000h, 09eh
   748 00011B59 FF18180000009E      <1>
   749 00011B60 00FC66667C62666F66- <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 0f3h, 000h, 000h, 000h, 0f1h, 000h
   749 00011B69 66F3000000F100      <1>
   750 00011B70 00181818FF18181800- <1>     db  000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 0ffh, 000h, 000h, 000h, 0f6h, 000h, 000h
   750 00011B79 FF000000F60000      <1>
   751 00011B80 18180000FF00001818- <1>     db  018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   751 00011B89 00000000            <1>
   752                              <1> vgafont16alt:
   753 00011B8D 1D00000000002466FF- <1>     db  01dh, 000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h
   753 00011B96 66240000000000      <1>
   754 00011B9D 003000003C66C3C3DB- <1>     db  000h, 030h, 000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h
   754 00011BA6 DBC3C3663C0000      <1>
   755 00011BAD 00004D0000C3E7FFFF- <1>     db  000h, 000h, 04dh, 000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h
   755 00011BB6 DBC3C3C3C3C300      <1>
   756 00011BBD 000000540000FFDB99- <1>     db  000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch
   756 00011BC6 1818181818183C      <1>
   757 00011BCD 00000000560000C3C3- <1>     db  000h, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch
   757 00011BD6 C3C3C3C3C3663C      <1>
   758 00011BDD 1800000000570000C3- <1>     db  018h, 000h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh
   758 00011BE6 C3C3C3C3DBDBFF      <1>
   759 00011BED 666600000000580000- <1>     db  066h, 066h, 000h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch
   759 00011BF6 C3C3663C18183C      <1>
   760 00011BFD 66C3C3000000005900- <1>     db  066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   760 00011C06 00C3C3C3663C18      <1>
   761 00011C0D 1818183C000000005A- <1>     db  018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h
   761 00011C16 0000FFC3860C18      <1>
   762 00011C1D 3060C1C3FF00000000- <1>     db  030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h
   762 00011C26 6D0000000000E6      <1>
   763 00011C2D FFDBDBDBDBDB000000- <1>     db  0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h
   763 00011C36 00760000000000      <1>
   764 00011C3D C3C3C3C3663C180000- <1>     db  0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h
   764 00011C46 00007700000000      <1>
   765 00011C4D 00C3C3C3DBDBFF6600- <1>     db  000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h, 078h, 000h, 000h, 000h
   765 00011C56 00000078000000      <1>
   766 00011C5D 0000C3663C183C66C3- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h, 091h, 000h, 000h
   766 00011C66 00000000910000      <1>
   767 00011C6D 0000006E3B1B7ED8DC- <1>     db  000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h, 09bh, 000h
   767 00011C76 77000000009B00      <1>
   768 00011C7D 18187EC3C0C0C0C37E- <1>     db  018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 09dh
   768 00011C86 1818000000009D      <1>
   769 00011C8D 0000C3663C18FF18FF- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   769 00011C96 18181800000000      <1>
   770 00011C9D 9E00FC66667C62666F- <1>     db  09eh, 000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h
   770 00011CA6 666666F3000000      <1>
   771 00011CAD 00AB00C0C0C2C6CC18- <1>     db  000h, 0abh, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh
   771 00011CB6 3060CE9B060C1F      <1>
   772 00011CBD 0000AC00C0C0C2C6CC- <1>     db  000h, 000h, 0ach, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h
   772 00011CC6 183066CE963E06      <1>
   773 00011CCD 06000000            <1>     db  006h, 000h, 000h, 000h
  2415                                  
  2416 00011CD1 90<rept>                align 16
  2417                                  
  2418                                  KERNELFSIZE  equ $  ; 04/07/2016
  2419                                  
  2420                                  
  2421                                  bss_start:
  2422                                  
  2423                                  ABSOLUTE bss_start
  2424                                  
  2425                                  	; 15/04/2016
  2426                                  	; TRDOS 386 (TRDOS v2.0)
  2427                                  	; 	80 interrupts 	
  2428                                  	; 11/03/2015
  2429                                  	; Interrupt Descriptor Table (20/08/2014)
  2430                                  idt:
  2431                                  	;resb	64*8 ; INT 0 to INT 3Fh
  2432                                  	; 15/04/2016
  2433 00011CE0 <res 00000280>          	resb	80*8 ; INT 0 to INT 4Fh
  2434                                  
  2435                                  idt_end:
  2436                                  
  2437                                  ;alignb 4
  2438                                  
  2439                                  task_state_segment:
  2440                                  	; 24/03/2015
  2441 00011F60 <res 00000002>          tss.link:   resw 1
  2442 00011F62 <res 00000002>          	    resw 1
  2443                                  ; tss offset 4	
  2444 00011F64 <res 00000004>          tss.esp0:   resd 1
  2445 00011F68 <res 00000002>          tss.ss0:    resw 1
  2446 00011F6A <res 00000002>          	    resw 1	
  2447 00011F6C <res 00000004>          tss.esp1:   resd 1
  2448 00011F70 <res 00000002>          tss.ss1:    resw 1
  2449 00011F72 <res 00000002>          	    resw 1 	
  2450 00011F74 <res 00000004>          tss.esp2:   resd 1
  2451 00011F78 <res 00000002>          tss.ss2:    resw 1
  2452 00011F7A <res 00000002>          	    resw 1
  2453                                  ; tss offset 28
  2454 00011F7C <res 00000004>          tss.CR3:    resd 1
  2455 00011F80 <res 00000004>          tss.eip:    resd 1
  2456 00011F84 <res 00000004>          tss.eflags: resd 1
  2457                                  ; tss offset 40
  2458 00011F88 <res 00000004>          tss.eax:    resd 1		 		
  2459 00011F8C <res 00000004>          tss.ecx:    resd 1
  2460 00011F90 <res 00000004>          tss.edx:    resd 1
  2461 00011F94 <res 00000004>          tss.ebx:    resd 1
  2462 00011F98 <res 00000004>          tss.esp:    resd 1
  2463 00011F9C <res 00000004>          tss.ebp:    resd 1
  2464 00011FA0 <res 00000004>          tss.esi:    resd 1
  2465 00011FA4 <res 00000004>          tss.edi:    resd 1
  2466                                  ; tss offset 72
  2467 00011FA8 <res 00000002>          tss.ES:     resw 1
  2468 00011FAA <res 00000002>          	    resw 1	
  2469 00011FAC <res 00000002>          tss.CS:	    resw 1
  2470 00011FAE <res 00000002>          	    resw 1
  2471 00011FB0 <res 00000002>          tss.SS:	    resw 1
  2472 00011FB2 <res 00000002>          	    resw 1
  2473 00011FB4 <res 00000002>          tss.DS:	    resw 1
  2474 00011FB6 <res 00000002>          	    resw 1
  2475 00011FB8 <res 00000002>          tss.FS:	    resw 1
  2476 00011FBA <res 00000002>          	    resw 1
  2477 00011FBC <res 00000002>          tss.GS:	    resw 1
  2478 00011FBE <res 00000002>          	    resw 1		
  2479 00011FC0 <res 00000002>          tss.LDTR:   resw 1
  2480 00011FC2 <res 00000002>          	    resw 1
  2481                                  ; tss offset 100		
  2482 00011FC4 <res 00000002>          	    resw 1		
  2483 00011FC6 <res 00000002>          tss.IOPB:   resw 1
  2484                                  ; tss offset 104 
  2485                                  tss_end:
  2486                                  
  2487 00011FC8 <res 00000004>          k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
  2488                                  		    ; (Physical address = Virtual address)	 	
  2489 00011FCC <res 00000004>          memory_size: resd 1 ; memory size in pages
  2490 00011FD0 <res 00000004>          free_pages:  resd 1 ; number of free pages		
  2491 00011FD4 <res 00000004>          next_page:   resd 1 ; offset value in M.A.T. for
  2492                                  		    ; first free page search
  2493 00011FD8 <res 00000004>          last_page:   resd 1 ; offset value in M.A.T. which
  2494                                  		    ; next free page search will be
  2495                                  		    ; stopped after it. (end of M.A.T.)
  2496 00011FDC <res 00000004>          first_page:  resd 1 ; offset value in M.A.T. which
  2497                                  		    ; first free page search
  2498                                  		    ; will be started on it. (for user)
  2499 00011FE0 <res 00000004>          mat_size:    resd 1 ; Memory Allocation Table size in pages		
  2500                                  
  2501                                  ; 02/09/2014 (Retro UNIX 386 v1)
  2502                                  ; 04/12/2013 (Retro UNIX 8086 v1)
  2503 00011FE4 <res 00000002>          CRT_START:   resw 1 	  ; starting address in regen buffer
  2504                                  			  ; NOTE: active page only	
  2505 00011FE6 <res 00000010>          CURSOR_POSN: resw 8 ; cursor positions for video pages
  2506                                  ACTIVE_PAGE: 
  2507 00011FF6 <res 00000001>          ptty: 	     resb 1 ; current tty
  2508                                  ; 01/07/2015 - 29/01/2016
  2509 00011FF7 <res 00000001>          ccolor:	     resb 1 ; current color attribute
  2510                                  ; 26/10/2015
  2511                                  ; 07/09/2014
  2512 00011FF8 <res 00000014>          ttychr:      resw ntty+2 ; Character buffer (multiscreen)
  2513                                  
  2514                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
  2515 0001200C <res 00000004>          p_time:      resd 1     ; present time (for systime & sysmdate)
  2516                                  
  2517                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
  2518                                  ; (open mode locks for pseudo TTYs)
  2519                                  ; [ major tty locks (return error in any conflicts) ]
  2520 00012010 <res 00000014>          ttyl:        resw ntty+2 ; opening locks for TTYs.
  2521                                  
  2522                                  ; 15/04/2015 (Retro UNIX 386 v1)
  2523                                  ; 22/09/2013 (Retro UNIX 8086 v1)
  2524 00012024 <res 0000000A>          wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
  2525                                  ; 15/04/2015 (Retro UNIX 386 v1)
  2526                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
  2527                                  ;; 0 means serial port is not available 
  2528                                  ;;comprm: ; 25/06/2014
  2529 0001202E <res 00000001>          com1p:       resb 1  ;;0E3h
  2530 0001202F <res 00000001>          com2p:       resb 1  ;;0E3h
  2531                                  
  2532                                  ; 17/11/2015
  2533                                  ; request for response (from the terminal)	
  2534 00012030 <res 00000002>          req_resp:    resw 1 			
  2535                                  ; 07/11/2015
  2536 00012032 <res 00000001>          ccomport:    resb 1 ; current COM (serial) port
  2537                                  		    ; (0= COM1, 1= COM2)
  2538                                  ; 09/11/2015
  2539 00012033 <res 00000001>          comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
  2540                                  ; 07/11/2015
  2541 00012034 <res 00000002>          rchar:	     resw 1 ; last received char for COM 1 and COM 2		
  2542 00012036 <res 00000002>          schar:	     resw 1 ; last sent char for COM 1 and COM 2
  2543                                  
  2544                                  ; 22/08/2014 (RTC)
  2545                                  ; (Packed BCD)
  2546 00012038 <res 00000001>          time_seconds: resb 1
  2547 00012039 <res 00000001>          time_minutes: resb 1
  2548 0001203A <res 00000001>          time_hours:   resb 1
  2549 0001203B <res 00000001>          date_wday:    resb 1
  2550 0001203C <res 00000001>          date_day:     resb 1
  2551 0001203D <res 00000001>          date_month:   resb 1			
  2552 0001203E <res 00000001>          date_year:    resb 1
  2553 0001203F <res 00000001>          date_century: resb 1
  2554                                  
  2555                                  ; 24/01/2016
  2556 00012040 <res 00000004>          RTC_LH:	       resd 1
  2557 00012044 <res 00000001>          RTC_WAIT_FLAG: resb 1
  2558 00012045 <res 00000001>          USER_FLAG:     resb 1
  2559                                  ; 19/05/2016
  2560                                  ;RTC_second:
  2561 00012046 <res 00000001>          RTC_2Hz:       resb 1 ;  from 2Hz interrupt to 1Hz timer event function	
  2562                                  
  2563                                  %include 'diskbss.s'	; UNINITIALIZED DISK (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskbss.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 24/01/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Turkish Rational DOS
    11                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                              <1> ;
    13                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                              <1> ; diskbss.inc (10/07/2015)
    15                              <1> ;
    16                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    17                              <1> ; ****************************************************************************
    18                              <1> 
    19                              <1> ; Retro UNIX 386 v1 Kernel - DISKBSS.INC
    20                              <1> ; Last Modification: 10/07/2015
    21                              <1> ;	(Unnitialized Disk Parameters Data section for 'DISKIO.INC') 
    22                              <1> 
    23 00012047 <res 00000001>      <1> alignb 2
    24                              <1> 
    25                              <1> ;----------------------------------------
    26                              <1> ;	TIMER DATA AREA 		:
    27                              <1> ;----------------------------------------
    28                              <1> 
    29                              <1> TIMER_LH:	; 16/02/205
    30 00012048 <res 00000002>      <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
    31 0001204A <res 00000002>      <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
    32 0001204C <res 00000001>      <1> TIMER_OFL:      resb 	1               ; TIMER HAS ROLLED OVER SINCE LAST READ
    33                              <1> 
    34                              <1> ;----------------------------------------
    35                              <1> ;	DISKETTE DATA AREAS		:
    36                              <1> ;----------------------------------------
    37                              <1> 
    38 0001204D <res 00000001>      <1> SEEK_STATUS:	resb	1
    39 0001204E <res 00000001>      <1> MOTOR_STATUS:	resb	1
    40 0001204F <res 00000001>      <1> MOTOR_COUNT:	resb	1
    41 00012050 <res 00000001>      <1> DSKETTE_STATUS:	resb	1
    42 00012051 <res 00000007>      <1> NEC_STATUS:	resb	7
    43                              <1> 
    44                              <1> ;----------------------------------------
    45                              <1> ;	ADDITIONAL MEDIA DATA		:
    46                              <1> ;----------------------------------------
    47                              <1> 
    48 00012058 <res 00000001>      <1> LASTRATE:	resb 	1
    49 00012059 <res 00000001>      <1> HF_STATUS:	resb 	1
    50 0001205A <res 00000001>      <1> HF_ERROR:	resb 	1
    51 0001205B <res 00000001>      <1> HF_INT_FLAG:	resb 	1
    52 0001205C <res 00000001>      <1> HF_CNTRL:	resb 	1
    53 0001205D <res 00000004>      <1> DSK_STATE:	resb 	4
    54 00012061 <res 00000002>      <1> DSK_TRK:	resb 	2
    55                              <1> 
    56                              <1> ;----------------------------------------
    57                              <1> ;	FIXED DISK DATA AREAS		:
    58                              <1> ;----------------------------------------
    59                              <1> 
    60 00012063 <res 00000001>      <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
    61 00012064 <res 00000001>      <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
    62 00012065 <res 00000001>      <1> CONTROL_BYTE:	resb 	1		; HEAD CONTROL BYTE
    63                              <1> ;@PORT_OFF	resb	1		; RESERVED (PORT OFFSET)
    64                              <1> ;port1_off	resb	1		; Hard disk controller 1 - port offset
    65                              <1> ;port2_off	resb	1		; Hard idsk controller 2 - port offset
    66                              <1> 
    67 00012066 <res 00000002>      <1> alignb 4
    68                              <1> 
    69                              <1> ;HF_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
    70                              <1> ;HF1_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
    71                              <1> HF_TBL_VEC: ; 22/12/2014	
    72 00012068 <res 00000004>      <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
    73 0001206C <res 00000004>      <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
    74 00012070 <res 00000004>      <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
    75 00012074 <res 00000004>      <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
    76                              <1> 
    77                              <1> ; 03/01/2015
    78 00012078 <res 00000001>      <1> LBAMode:     	resb	1
    79                              <1> 
    80                              <1> ; *****************************************************************************
  2564                                  
  2565                                  ;;; Real Mode Data (10/07/2015 - BSS)
  2566                                  
  2567                                  ;alignb 2
  2568                                  
  2569                                  ; 10/01/2016
  2570                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED DATA : trdoskx.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/07/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    11                              <1> ; TRDOS2.ASM (09/11/2011)
    12                              <1> ; ****************************************************************************
    13                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
    14                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
    15                              <1> ; DIR.ASM      [17/01/2004] Last Update: 09/10/2011
    16                              <1> ; CMD_INTR.ASM [29/01/2005] Last update: 09/11/2011
    17                              <1> ; DRV_FAT.ASM  [07/07/2009] Last update: 21/08/2011
    18                              <1> 
    19 00012079 <res 00000003>      <1> alignb 4
    20                              <1> 
    21                              <1> ; MAINPROG.ASM
    22 0001207C <res 00000004>      <1> MainProgCfg_FileSize:   resd 1 ; 14/04/2016
    23 00012080 <res 00000004>      <1> MainProgCfg_LineOffset: resd 1 ; 14/04/2016
    24                              <1> 
    25 00012084 <res 00000004>      <1> Current_VolSerial: resd 1
    26                              <1> 
    27 00012088 <res 00000004>      <1> Current_Dir_FCluster: resd 1
    28                              <1> 
    29 0001208C <res 00000001>      <1> Current_Dir_Level: resb 1
    30 0001208D <res 00000001>      <1> Current_FATType: resb 1
    31 0001208E <res 00000001>      <1> Current_Drv: resb 1
    32 0001208F <res 00000001>      <1> Current_Dir_Drv:   resb 1 ; '?'
    33 00012090 <res 00000001>      <1>                    resb 1 ; ':'
    34 00012091 <res 00000001>      <1> Current_Dir_Root:  resb 1 ; '/' 
    35 00012092 <res 0000005A>      <1> Current_Directory: resb 90
    36 000120EC <res 00000001>      <1> End_Of_Current_Dir_Str: resb 1
    37 000120ED <res 00000001>      <1> Current_Dir_StrLen: resb 1   
    38                              <1> 
    39 000120EE <res 00000001>      <1> CursorColumn: 	resb 1
    40 000120EF <res 00000001>      <1> CmdArgStart:    resb 1
    41                              <1> 
    42                              <1> ; 03/02/2016
    43 000120F0 <res 0000004E>      <1> Remark:		resb 78
    44                              <1> 
    45 0001213E <res 00000050>      <1> CommandBuffer: 	resb 80
    46                              <1> 
    47 0001218E <res 00000100>      <1> TextBuffer:	resb 256
    48                              <1> 
    49                              <1> MasterBootBuff:
    50 0001228E <res 000001BE>      <1> MasterBootCode: resb 1BEh
    51 0001244C <res 00000040>      <1> PartitionTable: resb 64
    52 0001248C <res 00000002>      <1> MBIDCode: resw 1
    53                              <1> 
    54                              <1> PTable_Buffer:
    55 0001248E <res 00000040>      <1> PTable_hd0: resb 64
    56 000124CE <res 00000040>      <1> PTable_hd1: resb 64
    57 0001250E <res 00000040>      <1> PTable_hd2: resb 64
    58 0001254E <res 00000040>      <1> PTable_hd3: resb 64
    59 0001258E <res 00000040>      <1> PTable_ep0: resb 64
    60 000125CE <res 00000040>      <1> PTable_ep1: resb 64
    61 0001260E <res 00000040>      <1> PTable_ep2: resb 64
    62 0001264E <res 00000040>      <1> PTable_ep3: resb 64
    63                              <1> 
    64 0001268E <res 00000001>      <1> scount:	resb 1 ; 16/05/2016 (diskio.s, 'int33h:')	
    65 0001268F <res 00000001>      <1> HD_LBA_yes: resb 1
    66 00012690 <res 00000001>      <1> PP_Counter: resb 1
    67 00012691 <res 00000001>      <1> EP_Counter: resb 1
    68                              <1> 
    69 00012692 <res 00000004>      <1> EP_StartSector: resd 1
    70 00012696 <res 00000004>      <1>                 resd 1
    71 0001269A <res 00000004>      <1>                 resd 1
    72 0001269E <res 00000004>      <1>                 resd 1
    73                              <1> 
    74 000126A2 <res 00000200>      <1> DOSBootSectorBuff: resb 512
    75                              <1> 
    76                              <1> FAT_BuffDescriptor:
    77 000128A2 <res 00000004>      <1> FAT_CurrentCluster: resd 1
    78 000128A6 <res 00000001>      <1> FAT_BuffValidData: resb 1
    79 000128A7 <res 00000001>      <1> FAT_BuffDrvName: resb 1
    80 000128A8 <res 00000002>      <1> FAT_BuffOffset: resw 1
    81 000128AA <res 00000004>      <1> FAT_BuffSector: resd 1
    82                              <1> 
    83 000128AE <res 00000004>      <1> FAT_ClusterCounter: resd 1
    84 000128B2 <res 00000004>      <1> LastCluster: resd 1
    85                              <1> 
    86                              <1> ; 16/05/2016
    87                              <1> ;; 18/03/2016 (TRDOS v2.0)
    88                              <1> ;ClusterBuffer_Valid: resb 1
    89                              <1> 
    90                              <1> Dir_BuffDescriptor:
    91 000128B6 <res 00000001>      <1> DirBuff_DRV: resb 1
    92 000128B7 <res 00000001>      <1> DirBuff_FATType: resb 1
    93 000128B8 <res 00000001>      <1> DirBuff_ValidData: resb 1
    94 000128B9 <res 00000002>      <1> DirBuff_CurrentEntry: resw 1
    95 000128BB <res 00000002>      <1> DirBuff_LastEntry: resw 1
    96 000128BD <res 00000004>      <1> DirBuff_Cluster: resd 1 
    97 000128C1 <res 00000002>      <1> DirBuffer_Size: resw 1
    98                              <1> ;DirBuff_EntryCounter: resw 1
    99                              <1> 
   100                              <1> ; 01/02/2016
   101                              <1> ; these are on (real mode) segment 8000h and later
   102                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
   103                              <1> ; Dir_Buffer:	resb 512*32
   104                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
   105                              <1> 
   106                              <1> ; 18/01/2016
   107                              <1> 
   108 000128C3 <res 00000004>      <1> FreeClusterCount: resd 1
   109                              <1> 
   110 000128C7 <res 00000004>      <1> VolSize_Unit1:   resd 1
   111 000128CB <res 00000004>      <1> VolSize_Unit2:   resd 1
   112                              <1> 
   113 000128CF <res 00000004>      <1> Vol_Tot_Sec_Str_Start:	    resd 1
   114 000128D3 <res 0000000A>      <1> Vol_Tot_Sec_Str: 	    resb 10
   115 000128DD <res 00000001>      <1> Vol_Tot_Sec_Str_End:	    resb 1
   116 000128DE <res 00000001>      <1> resb 1
   117 000128DF <res 00000004>      <1> Vol_Free_Sectors_Str_Start: resd 1
   118 000128E3 <res 0000000A>      <1> Vol_Free_Sectors_Str:	    resb 10				
   119 000128ED <res 00000001>      <1> Vol_Free_Sectors_Str_End:   resb 1
   120                              <1> 
   121                              <1> ; 10/02/2016
   122 000128EE <res 00000001>      <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   123                              <1> 
   124                              <1> ; 24/01/2016
   125 000128EF <res 00000080>      <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
   126                              <1> ; 06/02/2016
   127 0001296F <res 00000004>      <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
   128 00012973 <res 00000001>      <1> CCD_Level:	resb 1 ; DIR.ASM
   129 00012974 <res 00000001>      <1> Last_Dir_Level:	resb 1 ; DIR.ASM
   130                              <1> ;
   131 00012975 <res 00000002>      <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
   132 00012977 <res 00000004>      <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
   133 0001297B <res 00000002>      <1> CDLF_DEType:	resw 1 ; DIR.ASM
   134                              <1> ;
   135 0001297D <res 00000001>      <1> CD_COMMAND:	resb 1 ; DIR.ASM
   136                              <1> 
   137 0001297E <res 00000002>      <1> alignb 4
   138                              <1> 
   139                              <1> ; 29/01/2016
   140 00012980 <res 00000001>      <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   141                              <1> 
   142                              <1> ;alignb 4
   143                              <1> ; 23/02/2016
   144 00012981 <res 00000001>      <1> disk_rw_op:	resb 1 ;  0 = disk read, 1 = disk write
   145                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
   146                              <1> ; 31/01/2016
   147 00012982 <res 00000001>      <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
   148 00012983 <res 00000001>      <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
   149 00012984 <res 00000004>      <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
   150                              <1> 
   151                              <1> ; 06/02/2016 (long name)
   152 00012988 <res 00000002>      <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
   153 0001298A <res 00000002>      <1> AmbiguousFileName: resw 1 ; DIR.ASM
   154 0001298C <res 00000001>      <1> PreviousAttr:	   resb 1 ; DIR.ASM
   155                              <1> ;	
   156 0001298D <res 00000001>      <1> LongNameFound:   resb 1	  ; DIR.ASM
   157 0001298E <res 00000001>      <1> LFN_EntryLength: resb 1   ; DIR.ASM
   158 0001298F <res 00000001>      <1> LFN_CheckSum:    resb 1   ; DIR.ASM
   159 00012990 <res 00000084>      <1> LongFileName:    resb 132 ; DIR.ASM
   160                              <1> 
   161                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
   162 00012A14 <res 00000001>      <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
   163 00012A15 <res 00000001>      <1> PATH_Level:	 resb 1 ; DIR.ASM
   164                              <1> 
   165                              <1> ; 07/02/2016
   166 00012A16 <res 0000000D>      <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
   167                              <1> 
   168                              <1> ; 10/02/2016
   169 00012A23 <res 0000000D>      <1> Dir_Entry_Name:	resb 13 ; DIR.ASM
   170                              <1> 
   171                              <1> alignb 2
   172                              <1> 
   173 00012A30 <res 00000002>      <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
   174                              <1> 
   175                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
   176                              <1> ; 08/02/2016
   177                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
   178 00012A32 <res 00000001>      <1> FindFile_Drv:		  resb 1
   179 00012A33 <res 00000041>      <1> FindFile_Directory:	  resb 65
   180 00012A74 <res 0000000D>      <1> FindFile_Name:		  resb 13
   181                              <1> FindFile_LongNameEntryLength:
   182 00012A81 <res 00000001>      <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
   183                              <1> ;Above 80 bytes form
   184                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
   185 00012A82 <res 00000002>      <1> FindFile_AttributesMask:  resw 1
   186 00012A84 <res 00000020>      <1> FindFile_DirEntry:	  resb 32
   187 00012AA4 <res 00000004>      <1> FindFile_DirFirstCluster: resd 1
   188 00012AA8 <res 00000004>      <1> FindFile_DirCluster:	  resd 1
   189 00012AAC <res 00000002>      <1> FindFile_DirEntryNumber:  resw 1
   190 00012AAE <res 00000002>      <1> FindFile_MatchCounter:	  resw 1
   191 00012AB0 <res 00000002>      <1> FindFile_Reserved:	  resw 1 ; 06/03/2016
   192                              <1> 
   193 00012AB2 <res 00000004>      <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
   194 00012AB6 <res 00000004>      <1> Last_Slash_Pos: resd 1	; DIR.ASM 
   195                              <1> 
   196                              <1> ; 10/02/2016
   197 00012ABA <res 00000002>      <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
   198 00012ABC <res 00000002>      <1> Dir_Count:      resw 1
   199 00012ABE <res 00000004>      <1> Total_FSize:    resd 1
   200 00012AC2 <res 00000004>      <1> TFS_Dec_Begin:  resd 1
   201 00012AC6 <res 0000000A>      <1>                 resb 10
   202 00012AD0 <res 00000001>      <1> TFS_Dec_End:    resb 1
   203                              <1> 
   204 00012AD1 <res 00000001>      <1> PrintDir_RowCounter: resb 1
   205                              <1> 
   206 00012AD2 <res 00000002>      <1> alignb 4
   207                              <1> ; 15/02/2015 ('show' command variables)
   208 00012AD4 <res 00000004>      <1> Show_FDT:	resd 1
   209 00012AD8 <res 00000004>      <1> Show_LDDDT:	resd 1
   210 00012ADC <res 00000004>      <1> Show_Cluster:	resd 1
   211 00012AE0 <res 00000004>      <1> Show_FileSize:	resd 1
   212 00012AE4 <res 00000004>      <1> Show_FilePointer: resd 1
   213 00012AE8 <res 00000002>      <1> Show_ClusterPointer: resw 1
   214 00012AEA <res 00000002>      <1> Show_ClusterSize: resw 1
   215 00012AEC <res 00000001>      <1> Show_RowCount:	resb 1
   216                              <1> 
   217 00012AED <res 00000003>      <1> alignb 4
   218                              <1> ; 21/02/2016
   219 00012AF0 <res 00000004>      <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
   220                              <1> ; 27/02/2016
   221                              <1> ; DIR.ASM (09/10/2011)
   222 00012AF4 <res 00000004>      <1> DelFile_FCluster:	resd 1
   223 00012AF8 <res 00000002>      <1> DelFile_EntryCounter:	resw 1
   224 00012AFA <res 00000001>      <1> DelFile_LNEL:		resb 1
   225 00012AFB <res 00000001>      <1> resb 1
   226                              <1> 
   227                              <1> ; DIR.ASM
   228 00012AFC <res 00000004>      <1> mkdir_DirName_Offset: 	resd 1
   229 00012B00 <res 00000004>      <1> mkdir_FFCluster:	resd 1
   230 00012B04 <res 00000004>      <1> mkdir_LastDirCluster:	resd 1
   231 00012B08 <res 00000004>      <1> mkdir_FreeSectors:	resd 1
   232 00012B0C <res 00000002>      <1> mkdir_attrib:		resw 1 
   233 00012B0E <res 00000001>      <1> mkdir_SecPerClust:	resb 1
   234 00012B0F <res 00000001>      <1> mkdir_add_new_cluster:	resb 1
   235 00012B10 <res 0000000D>      <1> mkdir_Name:		resb 13
   236 00012B1D <res 00000002>      <1> resw 1 ; 01/03/2016
   237                              <1> ; 27/02/2016
   238 00012B1F <res 00000001>      <1> RmDir_MultiClusters:	resb 1  
   239 00012B20 <res 00000004>      <1> RmDir_DirEntryOffset:	resd 1 ; 01/03/2016 (word -> dword)
   240 00012B24 <res 00000004>      <1> RmDir_ParentDirCluster: resd 1
   241 00012B28 <res 00000004>      <1> RmDir_DirLastCluster:   resd 1
   242 00012B2C <res 00000004>      <1> RmDir_PreviousCluster:  resd 1
   243                              <1> ; 22/02/2016
   244 00012B30 <res 00000001>      <1> UPDLMDT_CDirLevel:	resb 1
   245 00012B31 <res 00000004>      <1> UPDLMDT_CDirFCluster:	resd 1
   246                              <1> 	
   247 00012B35 <res 00000003>      <1> alignb 4
   248                              <1> ; DRV_FAT.ASM ; 21/08/2011
   249 00012B38 <res 00000004>      <1> gffc_next_free_cluster:  resd 1
   250 00012B3C <res 00000004>      <1> gffc_first_free_cluster: resd 1
   251 00012B40 <res 00000004>      <1> gffc_last_free_cluster:  resd 1
   252                              <1> 
   253                              <1> ;29/04/2016
   254                              <1> Cluster_Index: ; resd 1
   255                              <1> ; 22/02/2016
   256 00012B44 <res 00000004>      <1> ClusterValue:	resd 1
   257                              <1> ; 04/03/2016
   258 00012B48 <res 00000001>      <1> Attributes:	resb 1 
   259                              <1> ;;CFS_error:  resb 1 ;; 01/03/2016
   260 00012B49 <res 00000001>      <1> resb 1
   261 00012B4A <res 00000001>      <1> CFS_OPType: resb 1
   262 00012B4B <res 00000001>      <1> CFS_Drv:    resb 1
   263 00012B4C <res 00000004>      <1> CFS_CC:	    resd 1
   264 00012B50 <res 00000004>      <1> CFS_FAT32FSINFOSEC: resd 1
   265 00012B54 <res 00000004>      <1> CFS_FAT32FC: resd 1
   266                              <1> 
   267                              <1> ; 27/02/2016
   268                              <1> ;alignb 4
   269 00012B58 <res 00000004>      <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
   270                              <1> 
   271                              <1> ; DIR.ASM
   272 00012B5C <res 00000002>      <1> DLN_EntryNumber: resw 1
   273 00012B5E <res 00000001>      <1> DLN_40h:	 resb 1
   274                              <1> ; 28/02/2016
   275 00012B5F <res 00000001>      <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
   276                              <1> 
   277                              <1> alignb 4
   278                              <1> ; DIR.ASM (09/10/2011)
   279 00012B60 <res 00000002>      <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
   280 00012B62 <res 00000002>      <1> LCDE_ClusterSN:  resw 1
   281 00012B64 <res 00000004>      <1> LCDE_Cluster: 	 resd 1
   282 00012B68 <res 00000004>      <1> LCDE_ByteOffset: resd 1
   283                              <1> 
   284                              <1> ;alignb4
   285                              <1> ; 06/03/2016 (word -> dword)
   286                              <1> ; CMD_INTR.ASM (01/08/2010)
   287 00012B6C <res 00000004>      <1> SourceFilePath:	     resd 1
   288 00012B70 <res 00000004>      <1> DestinationFilePath: resd 1
   289                              <1> 
   290                              <1> ;alignb 4
   291                              <1> ; 06/03/2016
   292                              <1> ; FILE.ASM (09/10/2011)
   293                              <1> ;Source File Structure (same with 'Find File' Structure)
   294 00012B74 <res 00000001>      <1> SourceFile_Drv:			resb 1
   295 00012B75 <res 00000041>      <1> SourceFile_Directory:		resb 65
   296 00012BB6 <res 0000000D>      <1> SourceFile_Name:		resb 13
   297                              <1> SourceFile_LongNameEntryLength: 
   298 00012BC3 <res 00000001>      <1> SourceFile_LongNameYes:		resb 1 ; Sign for longname procedures
   299                              <1> ;Above 80 bytes
   300                              <1> ;is TR-DOS Source File FullName Format/Structure
   301 00012BC4 <res 00000002>      <1> SourceFile_AttributesMask:	resw 1
   302 00012BC6 <res 00000020>      <1> SourceFile_DirEntry:		resb 32
   303 00012BE6 <res 00000004>      <1> SourceFile_DirFirstCluster:	resd 1
   304 00012BEA <res 00000004>      <1> SourceFile_DirCluster:		resd 1
   305 00012BEE <res 00000002>      <1> SourceFile_DirEntryNumber:	resw 1
   306 00012BF0 <res 00000002>      <1> SourceFile_MatchCounter:	resw 1
   307                              <1> ; 16/03/2016
   308 00012BF2 <res 00000001>      <1> SourceFile_SecPerClust:		resb 1
   309 00012BF3 <res 00000001>      <1> SourceFile_Reserved:		resb 1
   310                              <1> ; Above is 128 bytes
   311                              <1> 
   312                              <1> ;Destination File Structure (same with 'Find File' Structure)
   313 00012BF4 <res 00000001>      <1> DestinationFile_Drv:		resb 1
   314 00012BF5 <res 00000041>      <1> DestinationFile_Directory: 	resb 65
   315 00012C36 <res 0000000D>      <1> DestinationFile_Name:		resb 13
   316                              <1> DestinationFile_LongNameEntryLength:
   317 00012C43 <res 00000001>      <1> DestinationFile_LongNameYes:	resb 1 ; Sign for longname procedures
   318                              <1> ;Above 80 bytes
   319                              <1> ;is TR-DOS Destination File FullName Format/Structure
   320 00012C44 <res 00000002>      <1> DestinationFile_AttributesMask: resw 1
   321 00012C46 <res 00000020>      <1> DestinationFile_DirEntry:	resb 32
   322 00012C66 <res 00000004>      <1> DestinationFile_DirFirstCluster: resd 1
   323 00012C6A <res 00000004>      <1> DestinationFile_DirCluster:	resd 1
   324 00012C6E <res 00000002>      <1> DestinationFile_DirEntryNumber: resw 1
   325 00012C70 <res 00000002>      <1> DestinationFile_MatchCounter:	resw 1
   326                              <1> ; 16/03/2016
   327 00012C72 <res 00000001>      <1> DestinationFile_SecPerClust:	resb 1
   328 00012C73 <res 00000001>      <1> DestinationFile_Reserved:	resb 1
   329                              <1> ; Above is 128 bytes
   330                              <1> 
   331                              <1> ; 24/04/2016
   332 00012C74 <res 00000002>      <1> resw 1
   333                              <1> 
   334                              <1> ; 10/03/2016
   335                              <1> ; FILE.ASM
   336 00012C76 <res 00000001>      <1> move_cmd_phase:	   resb 1
   337 00012C77 <res 00000001>      <1> msftdf_sf_df_drv:  resb 1
   338 00012C78 <res 00000004>      <1> msftdf_drv_offset: resd 1
   339                              <1> 
   340                              <1> ; 11/03/2016
   341                              <1> ; DRV_FAT.ASM (21/08/2011)
   342 00012C7C <res 00000004>      <1> FAT_anc_LCluster:  resd 1
   343 00012C80 <res 00000004>      <1> FAT_anc_FFCluster: resd 1
   344                              <1> 
   345                              <1> ;alignb 4
   346                              <1> 
   347                              <1> ; 14/03/2016
   348                              <1> ; TRDOS 386 = TRDOS v2.0 feature only !
   349                              <1> ; 'allocate_memory_block' in 'memory.s'
   350 00012C84 <res 00000004>      <1> mem_ipg_count:	resd 1 ; page count (for contiguous allocation)
   351 00012C88 <res 00000004>      <1> mem_pg_count:	resd 1 ; page count (for count down)
   352 00012C8C <res 00000004>      <1> mem_aperture:	resd 1 ; contiguous free pages (current)
   353 00012C90 <res 00000004>      <1> mem_max_aperture: resd 1 ; maximum value of contiguous free pages
   354 00012C94 <res 00000004>      <1> mem_pg_pos:	resd 1 ; mem. position (page #) of current aperture
   355 00012C98 <res 00000004>      <1> mem_max_pg_pos: resd 1 ; mem. position (page #) of max. aperture
   356                              <1> 
   357                              <1> ; 15/03/2016
   358                              <1> ; FILE.ASM ('copy_source_file_to_destination_file')
   359 00012C9C <res 00000001>      <1> copy_cmd_phase:       resb 1
   360 00012C9D <res 00000001>      <1> csftdf_rw_err:	      resb 1
   361 00012C9E <res 00000001>      <1> DestinationFileFound: resb 1
   362 00012C9F <res 00000001>      <1> csftdf_cdrv: 	      resb 1
   363 00012CA0 <res 00000004>      <1> csftdf_filesize:      resd 1
   364                              <1> ; TRDOS386 (TRDOS v2.0)
   365 00012CA4 <res 00000004>      <1> csftdf_sf_mem_addr:   resd 1
   366 00012CA8 <res 00000004>      <1> csftdf_sf_mem_bsize:  resd 1
   367                              <1> ;
   368                              <1> 
   369 00012CAC <res 00000004>      <1> csftdf_sf_cluster:    resd 1 ; 16/03/2016
   370 00012CB0 <res 00000004>      <1> csftdf_df_cluster:    resd 1
   371                              <1> ; 16/03/2016
   372 00012CB4 <res 00000004>      <1> csftdf_r_size:        resd 1
   373 00012CB8 <res 00000004>      <1> csftdf_w_size:        resd 1
   374 00012CBC <res 00000004>      <1> csftdf_sf_rbytes:     resd 1
   375 00012CC0 <res 00000004>      <1> csftdf_df_wbytes:     resd 1
   376 00012CC4 <res 00000001>      <1> csftdf_percentage:    resb 1
   377                              <1> ; 17/03/2016
   378 00012CC5 <res 00000001>      <1> csftdf_videopage:     resb 1
   379 00012CC6 <res 00000002>      <1> csftdf_cursorpos:     resw 1
   380 00012CC8 <res 00000004>      <1> csftdf_sf_drv_dt:     resd 1
   381 00012CCC <res 00000004>      <1> csftdf_df_drv_dt:     resd 1
   382                              <1> 
   383                              <1> ; 21/03/2016
   384                              <1> ; 20/03/2016
   385                              <1> ; FILE.ASM
   386 00012CD0 <res 00000004>      <1> createfile_Name_Offset:  resd 1
   387 00012CD4 <res 00000004>      <1> createfile_FreeSectors:  resd 1 
   388 00012CD8 <res 00000004>      <1> createfile_size:         resd 1
   389 00012CDC <res 00000004>      <1> createfile_FFCluster:    resd 1 ; 11/03/2016
   390 00012CE0 <res 00000004>      <1> createfile_LastDirCluster: resd 1
   391 00012CE4 <res 00000004>      <1> createfile_Cluster:      resd 1
   392 00012CE8 <res 00000004>      <1> createfile_PCluster:     resd 1
   393 00012CEC <res 00000001>      <1> createfile_attrib:	 resb 1
   394 00012CED <res 00000001>      <1> createfile_SecPerClust:  resb 1
   395 00012CEE <res 00000002>      <1> createfile_DirIndex:     resw 1
   396 00012CF0 <res 00000004>      <1> createfile_CCount:	 resd 1
   397 00012CF4 <res 00000002>      <1> createfile_BytesPerSec:	 resw 1 ; 23/03/2016
   398 00012CF6 <res 00000001>      <1> createfile_wfc:	         resb 1
   399 00012CF7 <res 00000001>      <1> createfile_UpdatePDir:	 resb 1 ; 31/03/2016
   400                              <1> 
   401                              <1> ;alignb 4
   402                              <1> 
   403                              <1> ; 11/04/2016
   404 00012CF8 <res 00000002>      <1> env_var_length:	   resw 1
   405                              <1> 
   406 00012CFA <res 00000002>      <1> alignb 4
   407                              <1> 
   408                              <1> ; 25/04/2016
   409 00012CFC <res 00000001>      <1> readi.valid:	resb 1 ; valid data (>0 = valid for readi)
   410 00012CFD <res 00000001>      <1> readi.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   411 00012CFE <res 00000001>      <1> readi.spc:	resb 1 ; sectors per cluster for 'readi' drive
   412 00012CFF <res 00000001>      <1> readi.s_index:  resb 1 ; sector index in current cluster (buffer)
   413 00012D00 <res 00000004>      <1> readi.sector:	resd 1 ; current disk sector
   414 00012D04 <res 00000002>      <1> readi.bpc:	resw 1 ; bytes per cluster - 1
   415 00012D06 <res 00000002>      <1> readi.offset:	resw 1 ; byte offset in cluster buffer
   416 00012D08 <res 00000004>      <1> readi.cluster:  resd 1 ; current cluster number
   417 00012D0C <res 00000004>      <1> readi.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   418 00012D10 <res 00000004>      <1> readi.fclust:	resd 1 ; first cluster of the current cluster
   419 00012D14 <res 00000004>      <1> readi.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   420                              <1> ;readi.buffer:	resd 1 ; readi sector buffer address
   421                              <1> 
   422 00012D18 <res 00000001>      <1> writei.valid:	resb 1 ; valid data (>0 = valid for writei)
   423 00012D19 <res 00000001>      <1> writei.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   424 00012D1A <res 00000001>      <1> writei.spc:	resb 1 ; sectors per cluster for 'writei' drive
   425 00012D1B <res 00000001>      <1> writei.s_index: resb 1 ; sector index in current cluster (buffer)
   426 00012D1C <res 00000004>      <1> writei.sector:	resd 1 ; current disk sector
   427 00012D20 <res 00000002>      <1> writei.bpc:	resw 1 ; bytes per cluster - 1
   428 00012D22 <res 00000002>      <1> writei.offset:	resw 1 ; byte offset in cluster buffer
   429 00012D24 <res 00000004>      <1> writei.cluster: resd 1 ; current cluster number
   430 00012D28 <res 00000004>      <1> writei.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   431 00012D2C <res 00000004>      <1> writei.fclust:  resd 1 ; first cluster of the current cluster
   432 00012D30 <res 00000004>      <1> writei.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   433                              <1> ;writei.buffer:	resd 1 ; writei sector buffer address
   434                              <1> 
   435                              <1> ; 29/04/2016
   436 00012D34 <res 00000004>      <1> Run_CDirFC:	resd 1
   437 00012D38 <res 00000001>      <1> Run_Auto_Path:	resb 1
   438 00012D39 <res 00000001>      <1> Run_Manual_Path: resb 1 ; 0 -> auto path sequence needed
   439 00012D3A <res 00000001>      <1> EXE_ID:		resb 1	
   440 00012D3B <res 00000001>      <1> EXE_dot:	resb 1
   441                              <1> 
   442                              <1> ; 06/05/2016
   443 00012D3C <res 00000004>      <1> mainprog_return_addr: resd 1
   444 00012D40 <res 00000004>      <1> last_error:	resd 1  ; this will be used to return error code to MainProg
   445                              <1> 			; 'lasterror' keyword will be used later to get the
   446                              <1> 			; last error code/number/status.
   447                              <1> ; 12/05/2016
   448 00012D44 <res 00000004>      <1> video_eax:	resd 1  ; eax return value of video function
   449                              <1> 
   450                              <1> ; 01/06/2016
   451 00012D48 <res 00000004>      <1> user_buffer:	resd 1  ; 'diskio.s' (INT 33h, Function 08h, floppy disk type)
   452                              <1> 
   453                              <1> ; 21/05/2016 - TRDOS 386 ('swap/switch', 'rswap', [u.pri])
   454 00012D4C <res 00000001>      <1> priority:	resb 1  ; running priority level of process (0,1,2)
   455                              <1> 			; (run queue which is process comes from)
   456                              <1> ; 22/05/2016 - TRDOS 386 ('set_run_sequence', 'rtc_int', 'u_timer')
   457 00012D4D <res 00000001>      <1> p_change:	resb 1  ; process change status (for timer events)
   458                              <1> ; 23/05/2016 - TRDOS 386 ('clock')
   459 00012D4E <res 00000001>      <1> multi_tasking:	resb 1   ; Multi Tasking status (0 = disabled, >0 = enabled)
   460                              <1> 			; (EBX will return with user buffer addr or disk type)
   461                              <1> ; 07/06/2016
   462 00012D4F <res 00000001>      <1> timer_events:	resb 1  ; number of (active) timer events, <= 16		
   463                              <1> 
   464                              <1> ; 24/06/2016
   465 00012D50 <res 00000001>      <1> w_str_cmd:	resb 1	; WRITE_STRING command (0,1,2,3) ; video.s
   466 00012D51 <res 00000001>      <1> p_crt_mode:	resb 1  ; previous video mode (=3 or 0), backup mark/sign
   467                              <1> ; 26/06/2016
   468 00012D52 <res 00000001>      <1> p_crt_page:	resb 1  ; previous active page (for 'set_mode')
   469                              <1> ; 04/07/2016
   470 00012D53 <res 00000001>      <1> noclearmem:	resb 1  ; if set, 'SET MODE' (INT 31h) function (AH = 4)
   471                              <1> 			; will not clear the video memory
   472                              <1> 			; (usable for graphics modes only)
   473                              <1> alignb 2
   474 00012D54 <res 00000002>      <1> CRT_LEN:	resw 1  ; length of regen buffer in bytes
   475 00012D56 <res 00000010>      <1> cursor_pposn:	resw 8  ; cursor positions backup
   476                              <1> 
   477                              <1> ; 10/07/2016 ('VGA_FONT_SETUP', INT 43H address for x86 real mode bios)
   478 00012D66 <res 00000004>      <1> VGA_INT43H:	resd 1	; 0 = default (not configured by user)
   479                              <1> 			; 0FFFFFFFFh = user defined fonts
   480                              <1> 			; address:
   481                              <1> 			; 	vgafont8
   482                              <1> 			; 	vgafont16
   483                              <1> 			; 	vgafont14
   484                              <1> 
   485                              <1> ; 25/07/2016
   486 00012D6A <res 00000001>      <1> VGA_MTYPE:	resb 1  ; 0=CTEXT,1=MTEXT,2=CGA,3=PLANAR1,4=PLANAR4,5=LINEAR 
  2571                                  ; 24/01/2016
  2572                                  %include 'ubss.s'	; UNINITIALIZED KERNEL (USER) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED USER DATA : ubss.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 21/05/2016
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    11                              <1> ; ux.s (04/12/2015)
    12                              <1> ; ****************************************************************************
    13                              <1> 
    14                              <1> ; Retro UNIX 386 v1 Kernel - ux.s
    15                              <1> ; Last Modification: 04/12/2015
    16                              <1> ;
    17                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
    18                              <1> ; (Modified from 
    19                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
    20                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
    21                              <1> ; ----------------------------------------------------------------------------
    22                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
    23                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
    24                              <1> ; <Bell Laboratories (17/3/1972)>
    25                              <1> ; <Preliminary Release of UNIX Implementation Document>
    26                              <1> ; (Section E10 (17/3/1972) - ux.s)
    27                              <1> ; ****************************************************************************
    28                              <1> 
    29 00012D6B <res 00000001>      <1> alignb 2
    30                              <1> 
    31                              <1> inode:
    32                              <1> 	; 11/03/2013. 
    33                              <1> 	;Derived from UNIX v1 source code 'inode' structure (ux).
    34                              <1> 	;i.
    35                              <1> 
    36 00012D6C <res 00000002>      <1> 	i.flgs:	 resw 1
    37 00012D6E <res 00000001>      <1> 	i.nlks:	 resb 1
    38 00012D6F <res 00000001>      <1> 	i.uid:	 resb 1
    39                              <1>         ;i.size:  resw 1 ; size
    40 00012D70 <res 00000002>      <1> 	resw 1 ; 29/04/2016
    41 00012D72 <res 00000010>      <1> 	i.dskp:	 resw 8 ; 16 bytes
    42 00012D82 <res 00000004>      <1> 	i.ctim:	 resd 1
    43 00012D86 <res 00000004>      <1> 	i.mtim:	 resd 1
    44 00012D8A <res 00000002>      <1> 	i.rsvd:  resw 1 ; Reserved (ZERO/Undefined word for UNIX v1.)
    45                              <1> 
    46                              <1> I_SIZE	equ $ - inode 
    47                              <1> 
    48                              <1> process:
    49                              <1> 	; 21/05/2016
    50                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    51                              <1> 	; 06/05/2015 - Retro UNIX 386 v1
    52                              <1> 	; 11/03/2013 - 05/02/2014 (Retro UNIX 8086 v1)
    53                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
    54                              <1> 	;p.
    55                              <1> 	
    56 00012D8C <res 00000020>      <1>         p.pid:   resw nproc
    57 00012DAC <res 00000020>      <1>         p.ppid:  resw nproc
    58 00012DCC <res 00000020>      <1>         p.break: resw nproc
    59 00012DEC <res 00000010>      <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
    60 00012DFC <res 00000010>      <1> 	p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
    61 00012E0C <res 00000010>      <1> 	p.link:	 resb nproc
    62 00012E1C <res 00000010>      <1> 	p.stat:	 resb nproc
    63                              <1> 
    64                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 feature only !) 
    65 00012E2C <res 00000040>      <1> 	p.upage: resd nproc ; Physical address of the process's
    66                              <1> 			    ; 'user' structure
    67                              <1> 	; 21/05/2016	
    68                              <1> 	; 19/05/2016 (TRDOS 386 feature only!)
    69 00012E6C <res 00000010>      <1> 	p.timer: resb nproc ; number of timer events of the processs
    70                              <1> 			  		 			 	  
    71                              <1> P_SIZE	equ $ - process
    72                              <1> 
    73                              <1> 
    74                              <1> ; fsp table (original UNIX v1)
    75                              <1> ;
    76                              <1> ;Entry
    77                              <1> ;          15                                      0
    78                              <1> ;  1     |---|---------------------------------------|
    79                              <1> ;        |r/w|       i-number of open file           |
    80                              <1> ;        |---|---------------------------------------| 
    81                              <1> ;        |               device number               |
    82                              <1> ;        |-------------------------------------------|
    83                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
    84                              <1> ;        |-------------------------------------------| 
    85                              <1> ;        |  flag that says    | number of processes  |
    86                              <1> ;        |   file deleted     | that have file open  |
    87                              <1> ;        |-------------------------------------------| 
    88                              <1> ;  2     |                                           |
    89                              <1> ;        |-------------------------------------------| 
    90                              <1> ;        |                                           |
    91                              <1> ;        |-------------------------------------------|
    92                              <1> ;        |                                           |
    93                              <1> ;        |-------------------------------------------|
    94                              <1> ;        |                                           |
    95                              <1> ;        |-------------------------------------------| 
    96                              <1> ;  3     |                                           | 
    97                              <1> ;        |                                           |  
    98                              <1> ;
    99                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer 
   100                              <1> 
   101                              <1> 
   102                              <1> ; 15/04/2015
   103 00012E7C <res 000001F4>      <1> fsp:	 resb nfiles * 10 ; 11/05/2015 (8 -> 10)
   104 00013070 <res 00000018>      <1> bufp:	 resd (nbuf+2) ; will be initialized 
   105 00013088 <res 00000002>      <1> idev:	 resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   106 0001308A <res 00000002>      <1> cdev:    resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   107                              <1> ; 18/05/2015
   108                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
   109                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
   110                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
   111                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
   112                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
   113                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
   114                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
   115                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
   116                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
   117                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
   118                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
   119 0001308C <res 00000001>      <1> rdev:	 resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
   120                              <1> 	        ; as above, for physical drives numbers in following table
   121 0001308D <res 00000001>      <1> mdev:	 resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
   122                              <1> ; 15/04/2015
   123 0001308E <res 00000001>      <1> active:	 resb 1 
   124 0001308F <res 00000001>      <1> 	 resb 1 ; 09/06/2015
   125 00013090 <res 00000002>      <1> mnti:	 resw 1
   126 00013092 <res 00000002>      <1> mpid:	 resw 1
   127 00013094 <res 00000002>      <1> rootdir: resw 1
   128                              <1> 
   129                              <1> ; 21/05/2016 - TRDOS 386 (TRDOS v2.0) - priority levels, 3 run queues 
   130                              <1> runq:
   131 00013096 <res 00000002>      <1> runq_event:	 resw 1 ; high priority, 'run for event'            ; 2
   132 00013098 <res 00000002>      <1> runq_normal:	 resw 1 ; normal/regular priority, 'run as reqular' ; 1
   133 0001309A <res 00000002>      <1> runq_background: resw 1 ; low priority, 'run on background'         ; 0
   134                              <1> ;
   135 0001309C <res 00000001>      <1> imod:	 resb 1
   136 0001309D <res 00000001>      <1> smod:	 resb 1
   137 0001309E <res 00000001>      <1> mmod:	 resb 1
   138 0001309F <res 00000001>      <1> sysflg:	 resb 1
   139                              <1> 
   140                              <1> alignb 4
   141                              <1> 
   142                              <1> user:
   143                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0) 
   144                              <1> 	; 	       [u.pri] usage method modification
   145                              <1> 	; 04/12/2015 
   146                              <1> 	; 18/10/2015
   147                              <1> 	; 12/10/2015
   148                              <1> 	; 21/09/2015
   149                              <1> 	; 24/07/2015
   150                              <1> 	; 16/06/2015
   151                              <1> 	; 09/06/2015
   152                              <1> 	; 11/05/2015
   153                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
   154                              <1> 	; 10/10/2013
   155                              <1> 	; 11/03/2013. 
   156                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
   157                              <1> 	;u.
   158                              <1> 
   159 000130A0 <res 00000004>      <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
   160 000130A4 <res 00000004>      <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
   161 000130A8 <res 00000004>      <1> 	u.r0:	  resd 1 ; eax
   162 000130AC <res 00000002>      <1> 	u.cdir:	  resw 1
   163 000130AE <res 0000000A>      <1> 	u.fp:	  resb 10
   164 000130B8 <res 00000004>      <1> 	u.fofp:	  resd 1
   165 000130BC <res 00000004>      <1> 	u.dirp:	  resd 1
   166 000130C0 <res 00000004>      <1> 	u.namep:  resd 1
   167 000130C4 <res 00000004>      <1> 	u.off:	  resd 1
   168 000130C8 <res 00000004>      <1> 	u.base:	  resd 1
   169 000130CC <res 00000004>      <1> 	u.count:  resd 1
   170 000130D0 <res 00000004>      <1> 	u.nread:  resd 1
   171 000130D4 <res 00000004>      <1> 	u.break:  resd 1 ; break
   172 000130D8 <res 00000002>      <1> 	u.ttyp:	  resw 1 
   173 000130DA <res 00000010>      <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16) 
   174                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
   175 000130EA <res 00000001>      <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
   176 000130EB <res 00000001>      <1> 	u.pri:	  resb 1 ; Modification: 21/05/2016 (priority levels: 0, 1, 2)
   177 000130EC <res 00000002>      <1> 	u.intr:	  resw 1
   178 000130EE <res 00000002>      <1> 	u.quit:	  resw 1
   179                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
   180 000130F0 <res 00000002>      <1> 	u.ilgins: resw 1
   181 000130F2 <res 00000002>      <1> 	u.cdrv:	  resw 1 ; cdev
   182 000130F4 <res 00000001>      <1> 	u.uid:	  resb 1 ; uid
   183 000130F5 <res 00000001>      <1> 	u.ruid:	  resb 1
   184 000130F6 <res 00000001>      <1> 	u.bsys:	  resb 1
   185 000130F7 <res 00000001>      <1> 	u.uno:	  resb 1
   186 000130F8 <res 00000004>      <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
   187                              <1> 	; tty number (rtty, rcvt, wtty)
   188 000130FC <res 00000001>      <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
   189                              <1> 	; last error number
   190 000130FD <res 00000004>      <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
   191                              <1> 		        ; Retro UNIX 8086/386 v1 feature only!
   192 00013101 <res 00000004>      <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
   193 00013105 <res 00000004>      <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
   194 00013109 <res 00000004>      <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
   195 0001310D <res 00000002>      <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
   196                              <1> 	;u.pncount: resw 1 
   197                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
   198                              <1> 	;u.pnbase:  resd 1 
   199                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
   200                              <1> 			 ; 09/06/2015
   201 0001310F <res 00000001>      <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign		
   202 00013110 <res 00000001>      <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
   203                              <1> 			 ; 24/07/2015 - 24/06/2015
   204                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
   205                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
   206                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
   207                              <1>  			 ; 24/06/2015	  	
   208                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
   209                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
   210                              <1> 			 ; 21/09/2015 (debugging - page fault analyze)
   211 00013111 <res 00000004>      <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
   212                              <1> 
   213 00013115 <res 00000003>      <1> alignb 4
   214                              <1> 
   215                              <1> U_SIZE	equ $ - user
   216                              <1> 
   217                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
   218 00013118 <res 00000004>      <1> pcore:  resd 1 ; physical start address of user's memory space (for sys exec)
   219 0001311C <res 00000004>      <1> ecore:  resd 1 ; physical start address of user's memory space (for sys exec)
   220 00013120 <res 00000004>      <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
   221 00013124 <res 00000002>      <1> ncount: resw 1	; remain byte count in page for 'namei' & 'sysexec'
   222 00013126 <res 00000002>      <1> argc:	resw 1	; argument count for 'sysexec'
   223 00013128 <res 00000004>      <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
   224                              <1> 
   225                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
   226                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
   227 0001312C <res 00000001>      <1> rw: 	 resb 1 ;; Read/Write sign (iget)
   228                              <1> 
   229                              <1> ;alignb 4
   230                              <1> 
   231                              <1> ; 24/04/2016
   232 0001312D <res 00000004>      <1> ii:		resd 1 ; first cluster of the program file
   233 00013131 <res 00000004>      <1> i.size:		resd 1 ; size of the program file
   234                              <1> 
   235                              <1> ; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
   236                              <1> ; 22/08/2015 (Retro UNIX 386 v1)
   237                              <1> buffer: 
   238 00013135 <res 00000008>      <1> 	resb	8 
   239                              <1> readi_buffer:
   240 0001313D <res 00000200>      <1> 	resb 	512
   241 0001333D <res 00000008>      <1> 	resb	8
   242                              <1> writei_buffer:
   243 00013345 <res 00000200>      <1> 	resb	512	
   244 00013545 <res 00000410>      <1> 	resb (nbuf-2) * 520
   245                              <1> 
   246 00013955 <res 00000008>      <1> sb0:	resd 2
   247                              <1> ;s:
   248                              <1> ; (root disk) super block buffer
   249                              <1> systm:
   250                              <1> 	; 13/11/2015 (Retro UNIX 386 v1)	
   251                              <1> 	; 11/03/2013. 
   252                              <1> 	;Derived from UNIX v1 source code 'systm' structure (ux).
   253                              <1> 	;s.
   254                              <1> 
   255 0001395D <res 00000002>      <1> 	resw 1
   256 0001395F <res 00000168>      <1> 	resb 360 ; 2880 sectors ; original UNIX v1 value: 128
   257 00013AC7 <res 00000002>      <1> 	resw 1
   258 00013AC9 <res 00000020>      <1> 	resb 32	 ; 256+40 inodes ; original UNIX v1 value: 64
   259 00013AE9 <res 00000004>      <1> 	s.time:	 resd 1
   260 00013AED <res 00000004>      <1> 	s.syst:	 resd 1
   261 00013AF1 <res 00000004>      <1>         s.wait_: resd 1 ; wait
   262 00013AF5 <res 00000004>      <1> 	s.idlet: resd 1
   263 00013AF9 <res 00000004>      <1> 	s.chrgt: resd 1
   264 00013AFD <res 00000002>      <1> 	s.drerr: resw 1
   265                              <1> 
   266                              <1> S_SIZE	equ $ - systm
   267                              <1> 
   268 00013AFF <res 0000005E>      <1> 	resb 512-S_SIZE ; 03/06/2015	 
   269                              <1> 
   270 00013B5D <res 00000008>      <1> sb1:	resd 2
   271                              <1> ; (mounted disk) super block buffer
   272                              <1> mount:	
   273 00013B65 <res 00000200>      <1> 	resb 512  ; 03/06/2015
  2573                                  
  2574 00013D65 <res 00000003>          alignb 4
  2575                                  
  2576                                  ; 23/05/2016 (TRDOS 386)
  2577                                  ; 14/10/2015 (Retro UNIX 386 v1, 'unix386.s')
  2578 00013D68 <res 00000004>          cr3reg:	 resd 1  ; cr3 register content at the beginning of the timer
  2579                                  		 ; (or RTC) interrupt handler.
  2580                                  ; 10/06/2016
  2581                                  ; 19/05/2016
  2582                                  ; 18/05/2016 - TRDOS 386 feature only !
  2583 00013D6C <res 00000100>          timer_set: resd 16*4   ; 256 bytes memory space for 16 timer events
  2584                                  	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  2585                                  	;       Owner:	        resb 1 ; 0 = free
  2586                                  	;		  	       ;>0 = process number (p.pid)
  2587                                  	;	Reserved:	resb 1 ; = 0		
  2588                                  	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  2589                                  	;		   	       ; 1 = Real Time Clock interrupt 
  2590                                  	;	Response:       resb 1 ; 0 to 255, signal return value
  2591                                  	;	Count Limit:	resd 1 ; count of ticks (total/set)
  2592                                  	;	Current Count: 	resd 1 ; count of ticks (current)
  2593                                  	;	Response Addr:  resd 1 ; response byte (pointer) address
  2594                                  
  2595                                  ;; Memory (swap) Data (11/03/2015)
  2596                                  ; 09/03/2015
  2597 00013E6C <res 00000002>          swpq_count: resw 1 ; count of pages on the swap queue
  2598 00013E6E <res 00000004>          swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
  2599 00013E72 <res 00000004>          swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  2600 00013E76 <res 00000004>          swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  2601 00013E7A <res 00000004>          swpd_next:  resd 1 ; next free page block
  2602 00013E7E <res 00000004>          swpd_last:  resd 1 ; last swap page block	
  2603                                  
  2604 00013E82 <res 00000002>          alignb 4
  2605                                  
  2606                                  ; 10/07/2015
  2607                                  ; 28/08/2014
  2608 00013E84 <res 00000004>          error_code:	resd 1
  2609                                  ; 29/08/2014
  2610 00013E88 <res 00000004>          FaultOffset: 	resd 1
  2611                                  ; 21/09/2015
  2612 00013E8C <res 00000004>          PF_Count:	resd 1	; total page fault count
  2613                                  		       	; (for debugging - page fault analyze)
  2614                                  		 	; 'page_fault_handler' (memory.inc)
  2615                                  			; 'sysgeterr' (u9.s)
  2616                                  ;; 21/08/2015
  2617                                  ;;buffer: resb (nbuf*520) ;; sysdefs.inc, ux.s
  2618                                  ;; ((NOTE: nbuf = 6, buffer r/w problem/bug here !? when nbuf > 4))
  2619                                  
  2620                                  bss_end:
  2621                                  
  2622                                  ; 27/12/2013
  2623                                  _end:  ; end of kernel code
