     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.2
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 28/07/2020
     5                                  ; ----------------------------------------------------------------------------
     6                                  ; Beginning: 04/01/2016
     7                                  ; ----------------------------------------------------------------------------
     8                                  ; Assembler: NASM version 2.14 (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                                  ; nasm trdos386.s -l trdos386.txt -o TRDOS386.SYS
    22                                  
    23                                  
    24                                  KLOAD	equ 10000h ; Kernel loading address
    25                                  	; NOTE: Retro UNIX 8086 v1 /boot code loads kernel at 1000h:0000h 
    26                                  KCODE	equ 08h	; Code segment descriptor (ring 0)
    27                                  KDATA	equ 10h	; Data segment descriptor (ring 0)
    28                                  ; 19/03/2015
    29                                  UCODE	equ 1Bh ; 18h + 3h  (ring 3)
    30                                  UDATA	equ 23h ; 20h + 3h  (ring 3)
    31                                  ; 24/03/2015
    32                                  TSS	equ 28h	; Task state segment descriptor (ring 0)
    33                                  ; 19/03/2015
    34                                  CORE	equ 400000h  ; Start of USER's virtual/linear address space 
    35                                  		     ; (at the end of the 1st 4MB)
    36                                  ECORE	equ 0FFC00000h ; End of USER's virtual address space (4GB - 4MB)
    37                                  		     ; ULIMIT = (ECORE/4096) - 1 = 0FFBFFh (in GDT)
    38                                  
    39                                  ;; 27/12/2013
    40                                  ;KEND    equ KLOAD + 65536 ; (28/12/2013) (end of kernel space)
    41                                  ; 04/07/2016
    42                                  KEND    equ KERNELFSIZE + KLOAD
    43                                  
    44                                  
    45                                  ; IBM PC/AT BIOS ----- 10/06/85 (postequ.inc)
    46                                  ;--------- CMOS TABLE LOCATION ADDRESS'S -------------------------------------
    47                                  CMOS_SECONDS	EQU	00H		; SECONDS (BCD)
    48                                  CMOS_SEC_ALARM	EQU	01H		; SECONDS ALARM (BCD)
    49                                  CMOS_MINUTES	EQU	02H		; MINUTES (BCD)
    50                                  CMOS_MIN_ALARM	EQU	03H		; MINUTES ALARM (BCD) 	
    51                                  CMOS_HOURS	EQU	04H		; HOURS (BCD
    52                                  CMOS_HR_ALARM	EQU	005H		; HOURS ALARM   (BCD)
    53                                  CMOS_DAY_WEEK	EQU	06H		; DAY OF THE WEEK  (BCD)
    54                                  CMOS_DAY_MONTH	EQU	07H		; DAY OF THE MONTH (BCD) 
    55                                  CMOS_MONTH	EQU	08H		; MONTH (BCD)
    56                                  CMOS_YEAR	EQU	09H		; YEAR (TWO DIGITS) (BCD)
    57                                  CMOS_CENTURY	EQU	32H		; DATE CENTURY BYTE (BCD)
    58                                  CMOS_REG_A	EQU	0AH		; STATUS REGISTER A
    59                                  CMOS_REG_B	EQU	00BH		; STATUS REGISTER B  ALARM
    60                                  CMOS_REG_C	EQU	00CH		; STATUS REGISTER C  FLAGS
    61                                  CMOS_REG_D	EQU	0DH		; STATUS REGISTER D  BATTERY
    62                                  CMOS_SHUT_DOWN	EQU	0FH		; SHUTDOWN STATUS COMMAND BYTE
    63                                  ;----------------------------------------
    64                                  ;	CMOS EQUATES FOR THIS SYSTEM	;
    65                                  ;-----------------------------------------------------------------------------
    66                                  CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
    67                                  CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
    68                                  NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
    69                                  					; HIGH BIT OF CMOS LOCATION ADDRESS
    70                                  
    71                                  ; Memory Allocation Table Address
    72                                  ; 05/11/2014
    73                                  ; 31/10/2014
    74                                  MEM_ALLOC_TBL	equ	100000h		; Memory Allocation Table at the end of
    75                                  					; the 1st 1 MB memory space.
    76                                  					; (This address must be aligned
    77                                  					;  on 128 KB boundary, if it will be
    78                                  					;  changed later.)
    79                                  					; ((lower 17 bits of 32 bit M.A.T.
    80                                  					;   address must be ZERO)).
    81                                  					; ((((Reason: 32 bit allocation 
    82                                  					;     instructions, dword steps)))
    83                                  					; (((byte >> 12 --> page >> 5)))  
    84                                  ;04/11/2014	
    85                                  PDE_A_PRESENT	equ	1		; Present flag for PDE
    86                                  PDE_A_WRITE	equ 	2		; Writable (write permission) flag
    87                                  PDE_A_USER	equ	4		; User (non-system/kernel) page flag
    88                                  ;
    89                                  PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
    90                                  PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
    91                                  PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
    92                                  PTE_A_ACCESS    equ	32		; Accessed flag (bit 5) ; 09/03/2015
    93                                  
    94                                  ; 17/02/2015 (unix386.s)
    95                                  ; 10/12/2014 - 30/12/2014 (0B000h -> 9000h) (dsectrm2.s)
    96                                  DPT_SEGM equ 09000h  ; FDPT segment (EDD v1.1, EDD v3)
    97                                  ;
    98                                  HD0_DPT	 equ 0	    ; Disk parameter table address for hd0
    99                                  HD1_DPT	 equ 32	    ; Disk parameter table address for hd1
   100                                  HD2_DPT	 equ 64	    ; Disk parameter table address for hd2
   101                                  HD3_DPT	 equ 96	    ; Disk parameter table address for hd3
   102                                  
   103                                  
   104                                  ; FDPT (Phoenix, Enhanced Disk Drive Specification v1.1, v3.0)
   105                                  ;      (HDPT: Programmer's Guide to the AMIBIOS, 1993)
   106                                  ;
   107                                  FDPT_CYLS	equ 0 ; 1 word, number of cylinders
   108                                  FDPT_HDS	equ 2 ; 1 byte, number of heads
   109                                  FDPT_TT		equ 3 ; 1 byte, A0h = translated FDPT with logical values
   110                                  		      ; otherwise it is standard FDPT with physical values 	
   111                                  FDPT_PCMP	equ 5 ; 1 word, starting write precompensation cylinder
   112                                  		      ; (obsolete for IDE/ATA drives)
   113                                  FDPT_CB		equ 8 ; 1 byte, drive control byte
   114                                  			; Bits 7-6 : Enable or disable retries (00h = enable)
   115                                  			; Bit 5	: 1 = Defect map is located at last cyl. + 1
   116                                  			; Bit 4 : Reserved. Always 0
   117                                  			; Bit 3 : Set to 1 if more than 8 heads
   118                                  			; Bit 2-0 : Reserved. Alsways 0
   119                                  FDPT_LZ		equ 12 ; 1 word, landing zone (obsolete for IDE/ATA drives)
   120                                  FDPT_SPT	equ 14 ; 1 byte, sectors per track
   121                                  
   122                                  ; Floppy Drive Parameters Table (Programmer's Guide to the AMIBIOS, 1993)
   123                                  ; (11 bytes long) will be used by diskette handler/bios
   124                                  ; which is derived from IBM PC-AT BIOS (DISKETTE.ASM, 21/04/1986).
   125                                  
   126                                  ; 01/02/2016
   127                                  Logical_DOSDisks equ 90000h + 100h ; 26*256 = 6656 bytes
   128                                  Directory_Buffer equ 80000h ; max = 64K Bytes
   129                                  FAT_Buffer	 equ 91C00h ; 1536 bytes (3 sectors)
   130                                  ; 15/02/2016
   131                                  Cluster_Buffer	 equ 70000h ; max = 64K Bytes ; buffer for file read & write
   132                                  ; 11/04/2016
   133                                  Env_Page:	 equ 93000h ; 512 bytes (4096 bytes)
   134                                  Env_Page_Size	 equ 512    ; (4096 bytes)
   135                                  ; 30/07/2016
   136                                  Video_Pg_Backup	 equ 98000h ; Mode 3h, video page backup (32K, 8 pages)				 	  		 	  
   137                                  
   138                                  [BITS 16]       ; We need 16-bit intructions for Real mode
   139                                  
   140                                  [ORG 0] 
   141                                  	; 12/11/2014
   142                                  	; Save boot drive number (that is default root drive)
   143 00000000 8816[225D]              	mov	[boot_drv], dl ; physical drv number
   144                                  
   145                                  	; Determine installed memory
   146                                  	; 31/10/2014
   147                                  	;
   148 00000004 B801E8                  	mov	ax, 0E801h ; Get memory size 
   149 00000007 CD15                    	int	15h	   ; for large configurations
   150 00000009 7308                    	jnc	short chk_ms
   151 0000000B B488                    	mov	ah, 88h    ; Get extended memory size 
   152 0000000D CD15                    	int	15h
   153                                  	;	   
   154                                  	;mov	al, 17h	; Extended memory (1K blocks) low byte
   155                                  	;out	70h, al ; select CMOS register
   156                                  	;in	al, 71h ; read data (1 byte)
   157                                  	;mov	cl, al
   158                                  	;mov	al, 18h ; Extended memory (1K blocks) high byte
   159                                  	;out	70h, al ; select CMOS register
   160                                  	;in	al, 71h ; read data (1 byte)
   161                                  	;mov	ch, al
   162                                   	;      
   163 0000000F 89C1                    	mov	cx, ax
   164 00000011 31D2                    	xor	dx, dx
   165                                  chk_ms:
   166 00000013 890E[1E5D]              	mov	[mem_1m_1k], cx
   167 00000017 8916[205D]              	mov	[mem_16m_64k], dx
   168                                  	; 05/11/2014
   169                                  	;and	dx, dx
   170                                  	;jz	short L2
   171 0000001B 81F90004                        cmp     cx, 1024
   172 0000001F 7351                    	jnb	short L0
   173                                  		 ; insufficient memory_error	
   174                                  		 ; Minimum 2 MB memory is needed... 
   175                                  	; 05/11/2014
   176                                  	; (real mode error printing)
   177 00000021 FB                      	sti
   178 00000022 BE[3600]                	mov	si, msg_out_of_memory
   179 00000025 BB0700                  	mov	bx, 7
   180 00000028 B40E                    	mov	ah, 0Eh	; write tty
   181                                  oom_1:
   182 0000002A AC                      	lodsb
   183 0000002B 08C0                    	or	al, al
   184 0000002D 7404                    	jz	short oom_2
   185 0000002F CD10                    	int	10h
   186 00000031 EBF7                    	jmp	short oom_1
   187                                  oom_2:
   188 00000033 F4                              hlt
   189 00000034 EBFD                    	jmp	short oom_2
   190                                  
   191                                  ; 20/02/2017
   192                                  ; 05/11/2014
   193                                  msg_out_of_memory:
   194 00000036 070D0A                  	db 	07h, 0Dh, 0Ah
   195 00000039 496E73756666696369-             db      'Insufficient memory !'
   195 00000042 656E74206D656D6F72-
   195 0000004B 792021             
   196 0000004E 0D0A                    	db	0Dh, 0Ah
   197                                  _int13h_48h_buffer: ; 07/07/2016
   198 00000050 284D696E696D756D20-     	db	'(Minimum 2MB memory is needed.)'
   198 00000059 324D42206D656D6F72-
   198 00000062 79206973206E656564-
   198 0000006B 65642E29           
   199 0000006F 0D0A00                   	db	0Dh, 0Ah, 0
   200                                  	;
   201                                  
   202                                  L0:
   203                                  %include 'diskinit.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.2 - diskinit.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 17/07/2020
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.14 (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> 	; 17/07/2020
    27                              <1> 	; 14/07/2020 (TRDOS 386 v2.0.2)
    28                              <1> 	; 10/12/2014 - 02/02/2015 - dsectrm2.s
    29                              <1> ;L0:
    30                              <1> 	; 12/11/2014 (Retro UNIX 386 v1 - beginning)
    31                              <1> 	; Detecting disk drives... (by help of ROM-BIOS)
    32 00000072 BA7F00              <1> 	mov	dx, 7Fh
    33                              <1> L1:	
    34 00000075 FEC2                <1> 	inc	dl
    35 00000077 B441                <1> 	mov	ah, 41h ; Check extensions present
    36                              <1> 			; Phoenix EDD v1.1 - EDD v3
    37 00000079 BBAA55              <1> 	mov	bx, 55AAh
    38 0000007C CD13                <1> 	int 	13h
    39 0000007E 721A                <1> 	jc	short L2
    40                              <1> 
    41 00000080 81FB55AA            <1> 	cmp	bx, 0AA55h
    42 00000084 7514                <1> 	jne	short L2
    43 00000086 FE06[255D]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
    44 0000008A 8816[245D]          <1>         mov     [last_drv], dl  ; last hard disk number
    45 0000008E BB[A85C]            <1> 	mov	bx, hd0_type - 80h
    46 00000091 01D3                <1> 	add	bx, dx	 
    47 00000093 880F                <1> 	mov	[bx], cl ; Interface support bit map in CX
    48                              <1> 			 ; Bit 0 - 1, Fixed disk access subset ready
    49                              <1> 			 ; Bit 1 - 1, Drv locking and ejecting ready
    50                              <1> 			 ; Bit 2 - 1, Enhanced Disk Drive Support
    51                              <1>                          ;            (EDD) ready (DPTE ready)
    52                              <1> 			 ; Bit 3 - 1, 64bit extensions are present
    53                              <1>                          ;            (EDD-3)
    54                              <1> 			 ; Bit 4 to 15 - 0, Reserved
    55 00000095 80FA83              <1> 	cmp	dl, 83h	 ; drive number < 83h
    56 00000098 72DB                <1> 	jb	short L1
    57                              <1> L2:
    58                              <1> 	; 23/11/2014
    59                              <1> 	; 19/11/2014
    60 0000009A 30D2                <1> 	xor	dl, dl  ; 0
    61                              <1> 	; 04/02/2016 (esi -> si)
    62 0000009C BE[265D]            <1> 	mov	si, fd0_type
    63                              <1> L3:
    64                              <1> 	; 14/01/2015
    65 0000009F 8816[235D]          <1> 	mov	[drv], dl
    66                              <1> 	;
    67 000000A3 B408                <1> 	mov 	ah, 08h ; Return drive parameters
    68 000000A5 CD13                <1> 	int	13h	
    69 000000A7 7210                <1> 	jc	short L4
    70                              <1> 		; BL = drive type (for floppy drives)
    71                              <1> 		; DL = number of floppy drives
    72                              <1> 		;		
    73                              <1> 		; ES:DI = Address of DPT from BIOS
    74                              <1> 		;
    75 000000A9 881C                <1> 	mov	[si], bl ;  Drive type
    76                              <1> 			; 4 = 1.44 MB, 80 track, 3 1/2"
    77                              <1> 	; 14/01/2015
    78 000000AB E8EC01              <1> 	call	set_disk_parms
    79                              <1> 	; 10/12/2014
    80 000000AE 81FE[265D]          <1> 	cmp	si, fd0_type
    81 000000B2 7705                <1> 	ja	short L4
    82 000000B4 46                  <1> 	inc	si ; fd1_type
    83 000000B5 B201                <1> 	mov	dl, 1
    84 000000B7 EBE6                <1> 	jmp	short L3
    85                              <1> L4:
    86 000000B9 B27F                <1> 	mov	dl, 7Fh
    87                              <1> 	; 24/12/2014
    88 000000BB 803E[255D]00        <1> 	cmp	byte [hdc], 0 ; EDD present or not ?	
    89 000000C0 0F878700            <1>         ja      L10       ; yes, all fixed disk operations
    90                              <1> 			  ; will be performed according to
    91                              <1> 			  ; present EDD specification
    92                              <1> 
    93                              <1> 	; 17/07/2020
    94                              <1> 	; Note: Virtual CPU will not come here while 
    95                              <1> 	; running in QEMU, Bochs, VirtualBox emulators !!!
    96                              <1> 	
    97                              <1> 	; 17/07/2020
    98                              <1> 	; Older BIOS (INT 13h, AH = 48h is not available)
    99                              <1> L6:
   100 000000C4 FEC2                <1> 	inc 	dl
   101 000000C6 8816[235D]          <1>         mov     [drv], dl
   102 000000CA 8816[245D]          <1>         mov     [last_drv], dl ; 14/01/2015
   103 000000CE B408                <1> 	mov 	ah, 08h ; Return drive parameters
   104 000000D0 CD13                <1> 	int	13h	; (conventional function)
   105 000000D2 0F82B601            <1>         jc      L13	; fixed disk drive not ready
   106 000000D6 8816[255D]          <1>         mov     [hdc], dl ; number of drives
   107                              <1> 	;; 14/01/2013
   108                              <1> 	;;push	cx
   109 000000DA E8BD01              <1> 	call	set_disk_parms
   110                              <1> 	;;pop	cx
   111                              <1> 	;
   112                              <1> 	;;and	cl, 3Fh	 ; sectors per track (bits 0-6)
   113 000000DD 8A16[235D]          <1>         mov     dl, [drv]
   114 000000E1 BB0401              <1> 	mov	bx, 65*4 ; hd0 parameters table (INT 41h)	
   115 000000E4 80FA80              <1> 	cmp	dl, 80h
   116 000000E7 7603                <1> 	jna	short L7
   117 000000E9 83C314              <1> 	add	bx, 5*4	 ; hd1 parameters table (INT 46h)
   118                              <1> L7:	
   119 000000EC 31C0                <1> 	xor	ax, ax
   120 000000EE 8ED8                <1> 	mov	ds, ax
   121 000000F0 8B37                <1>         mov     si, [bx]
   122 000000F2 8B4702              <1>         mov     ax, [bx+2] 
   123 000000F5 8ED8                <1> 	mov	ds, ax
   124 000000F7 3A4C0E              <1>         cmp     cl, [si+FDPT_SPT] ; sectors per track 
   125 000000FA 0F858A01            <1>         jne     L12 ; invalid FDPT
   126 000000FE BF0000              <1> 	mov	di, HD0_DPT
   127 00000101 80FA80              <1> 	cmp	dl, 80h
   128 00000104 7603                <1> 	jna	short L8
   129 00000106 BF2000              <1> 	mov	di, HD1_DPT 
   130                              <1> L8:
   131                              <1> 	; 30/12/2014
   132 00000109 B80090              <1> 	mov	ax, DPT_SEGM
   133 0000010C 8EC0                <1> 	mov	es, ax
   134                              <1> 	; 24/12/2014
   135 0000010E B90800              <1> 	mov	cx, 8
   136 00000111 F3A5                <1> 	rep	movsw  ; copy 16 bytes to the kernel's DPT location
   137 00000113 8CC8                <1> 	mov	ax, cs
   138 00000115 8ED8                <1> 	mov	ds, ax
   139                              <1> 
   140                              <1> 	; 02/02/2015
   141                              <1> 	;mov	cl, [drv]
   142                              <1> 	;mov	bl, cl
   143                              <1> 	;mov	ax, 1F0h
   144                              <1> 	;and	bl, 1
   145                              <1> 	;jz	short L9
   146                              <1> 	;shl	bl, 4
   147                              <1> 	;sub	ax, 1F0h-170h
   148                              <1> 
   149                              <1> 	; 17/07/2020 
   150                              <1> 	; (Only 1F0h port address must be valid for old ROM BIOSes)
   151 00000117 B8F001              <1> 	mov	ax, 1F0h
   152 0000011A B3A0                <1> 	mov	bl, 0A0h
   153 0000011C 80FA80              <1> 	cmp	dl, 80h
   154 0000011F 7603                <1> 	jna	short L9
   155                              <1> 	; dl = 81h
   156 00000121 80C310              <1> 	add	bl, 10h  ; slave disk
   157                              <1> 	;sub	ax, 1F0h-170h
   158                              <1> L9:
   159 00000124 AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   160 00000125 050602              <1> 	add	ax, 206h
   161 00000128 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   162 00000129 88D8                <1> 	mov	al, bl  ; bit 4, master/slave disk bit
   163                              <1> 	;add	al, 0A0h ; 17/07/2020
   164 0000012B AA                  <1> 	stosb	; Device/Head Register upper nibble
   165                              <1> 	;
   166 0000012C FE06[235D]          <1> 	inc	byte [drv]
   167 00000130 BB[A85C]            <1> 	mov	bx, hd0_type - 80h
   168 00000133 01CB                <1> 	add	bx, cx
   169 00000135 800F80              <1>         or      byte [bx], 80h  ; present sign (when lower nibble is 0)
   170 00000138 A0[255D]            <1> 	mov	al, [hdc]
   171 0000013B FEC8                <1> 	dec	al
   172 0000013D 0F844B01            <1>         jz      L13
   173 00000141 80FA80              <1> 	cmp	dl, 80h
   174 00000144 0F867CFF            <1>         jna	L6 ; Max. 2 hard disks  ; 17/07/2020 
   175 00000148 E94101              <1>         jmp     L13
   176                              <1> L10:
   177 0000014B FEC2                <1> 	inc 	dl
   178                              <1> 	; 25/12/2014
   179 0000014D 8816[235D]          <1> 	mov	[drv], dl
   180 00000151 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   181 00000153 CD13                <1> 	int	13h	; (conventional function)
   182 00000155 0F823301            <1>         jc      L13
   183                              <1> 	; 14/01/2015
   184 00000159 8A16[235D]          <1> 	mov	dl, [drv]
   185 0000015D 52                  <1> 	push	dx
   186 0000015E 51                  <1> 	push	cx
   187 0000015F E83801              <1> 	call	set_disk_parms
   188 00000162 59                  <1> 	pop	cx
   189 00000163 5A                  <1> 	pop	dx
   190                              <1> 	; 06/07/2016 (BugFix for >64K kernel files)
   191                              <1> 	; 04/02/2016 (esi -> si)
   192                              <1> 	;mov	si, _end ; 30 byte temporary buffer address 	
   193                              <1> 	;		 ; at the '_end' of kernel.
   194                              <1> 	;mov	word [si], 30
   195                              <1> 	; 06/07/2016
   196 00000164 BE[5000]            <1> 	mov	si, _int13h_48h_buffer
   197                              <1> 	; 09/07/2016
   198 00000167 B81E00              <1> 	mov	ax, 001Eh
   199 0000016A 8824                <1> 	mov	[si], ah ; 0
   200 0000016C 46                  <1> 	inc	si
   201 0000016D 8904                <1> 	mov	word [si], ax
   202                              <1>  	; word [si] = 30
   203                              <1> 	;
   204 0000016F B448                <1> 	mov	ah, 48h	 ; Get drive parameters (EDD function)
   205 00000171 CD13                <1> 	int	13h
   206 00000173 0F821501            <1>         jc      L13
   207                              <1> 
   208                              <1> 	; 04/02/2016 (ebx -> bx)
   209                              <1> 	; 14/01/2015
   210 00000177 28FF                <1> 	sub	bh, bh
   211 00000179 88D3                <1> 	mov	bl, dl
   212 0000017B 80EB80              <1> 	sub	bl, 80h
   213 0000017E 81C3[285D]          <1> 	add	bx, hd0_type
   214 00000182 8A07                <1> 	mov 	al, [bx]
   215 00000184 0C80                <1> 	or	al, 80h
   216 00000186 8807                <1> 	mov 	[bx], al	
   217 00000188 81EB[265D]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   218 0000018C 81C3[725D]          <1> 	add	bx, drv.status
   219 00000190 8807                <1> 	mov	[bx], al
   220                              <1> 	; 04/02/2016 (eax -> ax)
   221 00000192 8B4410              <1> 	mov	ax, [si+16]
   222                              <1> 	; 14/07/2020
   223 00000195 8B7C12              <1> 	mov	di, [si+18] 
   224                              <1> 	;test	ax, [si+18]
   225 00000198 85F8                <1> 	test	ax, di ; 14/07/2020
   226 0000019A 7410                <1> 	jz	short L10_A0h ; (!) ; 17/07/2020
   227                              <1> 			; 'CHS only' disks on EDD system 
   228                              <1> 			;  are reported with ZERO disk size
   229                              <1> 			; (if so, we must not overwrite
   230                              <1> 			; calculated disk size in 'set_disk_parms')
   231 0000019C 81EB[725D]          <1> 	sub	bx, drv.status
   232 000001A0 C1E302              <1> 	shl	bx, 2
   233 000001A3 81C3[565D]          <1> 	add	bx, drv.size ; disk size (in sectors)
   234 000001A7 8907                <1> 	mov	[bx], ax
   235                              <1> 	;mov	ax, [si+18]
   236                              <1> 	;;mov	[bx], ax
   237                              <1> 	;mov	[bx+2], ax ; BugFix ; 15/07/2020
   238                              <1> 	; 14/07/2020
   239 000001A9 897F02              <1> 	mov	[bx+2], di ; 15/07/2020
   240                              <1> 
   241                              <1> L10_A0h: 
   242                              <1> 	; 17/07/2020
   243                              <1> 	; Note: Virtual CPU will jump here from above (!) test
   244                              <1> 	;	while running in QEMU
   245                              <1> 
   246                              <1> 	; Jump here to fix a ZERO (LBA) disk size problem 
   247                              <1> 	; for CHS disks (28/02/2015)
   248                              <1> 	
   249                              <1> 	; 30/12/2014
   250 000001AC BF0000              <1> 	mov	di, HD0_DPT
   251 000001AF 88D0                <1> 	mov	al, dl
   252 000001B1 83E003              <1> 	and 	ax, 3
   253 000001B4 C0E005              <1> 	shl	al, 5 ; * 32
   254 000001B7 01C7                <1> 	add 	di, ax
   255 000001B9 B80090              <1> 	mov	ax, DPT_SEGM
   256 000001BC 8EC0                <1> 	mov	es, ax
   257                              <1> 	;
   258 000001BE 88E8                <1> 	mov	al, ch	; max. cylinder number (bits 0-7)
   259 000001C0 88CC                <1> 	mov	ah, cl	
   260 000001C2 C0EC06              <1> 	shr	ah, 6	; max. cylinder number (bits 8-9)
   261 000001C5 40                  <1>  	inc	ax	; logical cylinders (limit 1024)
   262 000001C6 AB                  <1> 	stosw		
   263 000001C7 88F0                <1> 	mov	al, dh	; max. head number
   264 000001C9 FEC0                <1> 	inc	al
   265 000001CB AA                  <1> 	stosb		; logical heads (limits 256)
   266 000001CC B0A0                <1> 	mov	al, 0A0h ; Indicates translated table
   267 000001CE AA                  <1> 	stosb
   268 000001CF 8A440C              <1> 	mov	al, [si+12]
   269 000001D2 AA                  <1> 	stosb		 ; physical sectors per track
   270 000001D3 31C0                <1>  	xor	ax, ax
   271                              <1> 	;dec	ax	 ; 02/01/2015 
   272 000001D5 AB                  <1> 	stosw		 ; precompensation (obsolete)
   273                              <1> 	;xor	al, al	 ; 02/01/2015	
   274 000001D6 AA                  <1> 	stosb		 ; reserved
   275 000001D7 B008                <1> 	mov	al, 8	 ; drive control byte
   276                              <1> 		         ; (do not disable retries, 
   277                              <1> 			 ; more than 8 heads)
   278 000001D9 AA                  <1> 	stosb
   279 000001DA 8B4404              <1> 	mov	ax, [si+4]
   280 000001DD AB                  <1> 	stosw		 ; physical number of cylinders	
   281                              <1> 	;push	ax	 ; 02/01/2015
   282 000001DE 8A4408              <1> 	mov	al, [si+8]
   283 000001E1 AA                  <1> 	stosb		 ; physical num. of heads (limit 16)
   284 000001E2 29C0                <1> 	sub 	ax, ax
   285                              <1> 	;pop	ax	 ; 02/01/2015	
   286 000001E4 AB                  <1> 	stosw		 ; landing zone (obsolete)
   287 000001E5 88C8                <1> 	mov	al, cl	 ; logical sectors per track (limit 63)
   288 000001E7 243F                <1> 	and 	al, 3Fh	
   289 000001E9 AA                  <1> 	stosb
   290                              <1> 	;sub	al, al	 ; checksum
   291                              <1> 	;stosb
   292                              <1> 	;
   293 000001EA 83C61A              <1> 	add	si, 26   ; (BIOS) DPTE address pointer
   294 000001ED AD                  <1> 	lodsw
   295 000001EE 50                  <1> 	push	ax ; *	 ; (BIOS) DPTE offset
   296 000001EF AD                  <1> 	lodsw
   297 000001F0 50                  <1> 	push	ax ; **	 ; (BIOS) DPTE segment
   298                              <1> 	;
   299                              <1> 	; checksum calculation
   300 000001F1 89FE                <1> 	mov	si, di
   301 000001F3 06                  <1> 	push	es
   302 000001F4 1F                  <1> 	pop	ds
   303                              <1> 	;mov	cx, 16
   304 000001F5 B90F00              <1> 	mov 	cx, 15
   305 000001F8 29CE                <1> 	sub	si, cx
   306 000001FA 30E4                <1> 	xor	ah, ah
   307                              <1> 	;del	cl
   308                              <1> L11:		
   309 000001FC AC                  <1> 	lodsb
   310 000001FD 00C4                <1> 	add	ah, al
   311 000001FF E2FB                <1> 	loop	L11
   312                              <1> 	;
   313 00000201 88E0                <1> 	mov	al, ah
   314 00000203 F6D8                <1> 	neg	al	; -x+x = 0
   315 00000205 AA                  <1> 	stosb		; put checksum in byte 15 of the tbl
   316                              <1> 	;
   317 00000206 1F                  <1> 	pop	ds ; **	; (BIOS) DPTE segment
   318 00000207 5E                  <1> 	pop	si ; *	; (BIOS) DPTE offset	
   319                              <1> 	;
   320                              <1> 	; 14/07/2020
   321                              <1> 	; 0FFFFh:0FFFFh = invalid DPTE address
   322 00000208 8B0C                <1> 	mov	cx, [si]
   323 0000020A 8B4402              <1> 	mov	ax, [si+2]
   324 0000020D 21C1                <1> 	and	cx, ax
   325 0000020F 41                  <1> 	inc	cx 
   326 00000210 7404                <1> 	jz	short L11c ; 0FFFFh:0FFFFh
   327 00000212 0B04                <1> 	or	ax, [si]
   328 00000214 752A                <1> 	jnz	short L11e ; <> 0
   329                              <1> L11c:
   330                              <1> 	; 17/07/2020
   331                              <1> 	; TRDOS 386 v2 DRVINIT assumptions:
   332                              <1> 	; (also by regarding QEMU, Bochs and VirtualBox settings)
   333                              <1> 	;	Hard disk 0 port address: 1F0h
   334                              <1> 	;	Hard disk 1 port address: 1F0h
   335                              <1> 	;	Hard disk 2 port address: 170h
   336                              <1> 	;	Hard disk 3 port address: 170h
   337                              <1> 
   338                              <1> 	; in QEMU, hda=hd0 (1F0h) and hdb=hd1 (1F0h) -IRQ14-
   339                              <1> 	;      and hdc=hd2 (170h) and hdd=hd3 (170h) -IRQ15-
   340                              <1> 
   341 00000216 B8F001              <1> 	mov	ax, 1F0h
   342                              <1> 
   343                              <1> 	; 15/07/2020
   344                              <1> 	; 14/07/2020
   345                              <1> 	; Invalid DPTE address...
   346                              <1> 	; Default DPTE parms must be set for DISK_IO_CONT
   347                              <1> 	; (diskio.s)
   348                              <1> 	; 17/07/2020
   349                              <1> 
   350                              <1> 	;mov	bl, dl
   351                              <1> 	;and	bl, 1
   352                              <1> 	;jz	short L11d
   353                              <1> 
   354 00000219 B3A0                <1> 	mov	bl, 0A0h
   355                              <1> 
   356 0000021B F6C201              <1> 	test	dl, 1
   357 0000021E 7403                <1> 	jz	short L11g  ; Master (as default, for 80h & 82h))
   358                              <1> 	;shl	bl, 4 ; bl = 16 (bit 4 = 1 -> slave)
   359 00000220 80C310              <1> 	add	bl, 10h  ; Slave (as default, for 81h & 83h)
   360                              <1> L11g:
   361                              <1> 	; 17/07/2020
   362 00000223 80FA82              <1> 	cmp	dl, 82h	; Hard disk 3 or 4 ?
   363 00000226 7203                <1> 	jb	short L11d ; Primary ATA channel (hd0, hd1)
   364                              <1> 			   ; (port address = 1F0h)
   365                              <1> 	
   366                              <1> 	; Secondary ATA channel (hd2, hd3)
   367                              <1> 	; (port address = 170h)
   368                              <1> 
   369 00000228 2D8000              <1> 	sub	ax, 1F0h-170h
   370                              <1> L11d:
   371                              <1> 	; 14/07/2020
   372 0000022B AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   373 0000022C 050602              <1> 	add	ax, 206h
   374 0000022F AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   375 00000230 88D8                <1> 	mov	al, bl  ; Master/Slave bit (0 = Master)
   376                              <1> 	; 17/07/2020
   377                              <1> 	;or	al, 0A0h ; CHS (LBA enable bit = 0)
   378                              <1> 			 ; (Bits 5&7, reserved bits  =  1)
   379 00000232 30E4                <1> 	xor	ah, ah
   380                              <1> 	;stosb	; Device/Head Register upper nibble
   381 00000234 AB                  <1> 	stosw
   382 00000235 30C0                <1> 	xor	al, al
   383 00000237 B90500              <1> 	mov	cx, 5
   384 0000023A F3AB                <1> 	rep	stosw ; clear remain part of the (fake) DPTE
   385 0000023C 0E                  <1> 	push	cs
   386 0000023D 1F                  <1> 	pop	ds
   387 0000023E EB33                <1> 	jmp	short L11f
   388                              <1> L11e:
   389                              <1> 	; 23/02/2015
   390 00000240 57                  <1> 	push	di
   391                              <1> 	; ES:DI points to DPTE (FDPTE) location
   392                              <1> 	;;mov	cx, 8
   393                              <1> 	;mov	cl, 8
   394 00000241 B90800              <1> 	mov	cx, 8 ; 14/07/2020
   395 00000244 F3A5                <1> 	rep	movsw	
   396                              <1> 	;
   397                              <1> 	; 23/02/2015
   398                              <1> 	; (P)ATA drive and LBA validation
   399                              <1> 	; (invalidating SATA drives and setting
   400                              <1> 	; CHS type I/O for old type fixed disks)
   401 00000246 5B                  <1> 	pop	bx
   402 00000247 8CC8                <1> 	mov	ax, cs
   403 00000249 8ED8                <1> 	mov	ds, ax
   404 0000024B 268B07              <1> 	mov	ax, [es:bx]
   405 0000024E 3DF001              <1> 	cmp	ax, 1F0h
   406 00000251 7418                <1> 	je	short L11a
   407 00000253 3D7001              <1> 	cmp	ax, 170h
   408 00000256 7413                <1> 	je	short L11a
   409                              <1> 	; invalidation 
   410                              <1> 	; (because base port address is not 1F0h or 170h)
   411 00000258 30FF                <1> 	xor	bh, bh
   412 0000025A 88D3                <1> 	mov	bl, dl
   413 0000025C 80EB80              <1> 	sub	bl, 80h
   414 0000025F C687[285D]00        <1> 	mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   415 00000264 808F[745D]F0        <1>         or      byte [bx+drv.status+2], 0F0h ; (failure sign)
   416 00000269 EB14                <1> 	jmp	short L11b
   417                              <1> L11a:	
   418                              <1> 	; LBA validation
   419 0000026B 268A4704            <1> 	mov	al, [es:bx+4] ; Head register upper nibble
   420 0000026F A840                <1> 	test	al, 40h ; LBA bit (bit 6)
   421 00000271 750C                <1> 	jnz	short L11b ; LBA type I/O is OK! (E0h or F0h)
   422                              <1> L11f:
   423                              <1> 	; force CHS type I/O for this drive (A0h or B0h)
   424 00000273 28FF                <1> 	sub	bh, bh
   425 00000275 88D3                <1> 	mov	bl, dl
   426 00000277 80EB80              <1> 	sub	bl, 80h ; 26/02/2015
   427 0000027A 80A7[745D]FE        <1>         and     byte [bx+drv.status+2], 0FEh ; clear bit 0
   428                              <1> 				; bit 0 = LBA ready bit
   429                              <1> 	; 'diskio' procedure will check this bit !
   430                              <1> L11b:
   431 0000027F 3A16[245D]          <1> 	cmp	dl, [last_drv] ; 25/12/2014
   432 00000283 7307                <1>         jnb     short L13
   433 00000285 E9C3FE              <1>         jmp     L10
   434                              <1> 
   435                              <1> L12:
   436                              <1> 	; Restore data registers
   437 00000288 8CC8                <1> 	mov	ax, cs
   438 0000028A 8ED8                <1> 	mov	ds, ax	
   439                              <1> L13:
   440                              <1> 	; 13/12/2014
   441 0000028C 0E                  <1> 	push	cs
   442 0000028D 07                  <1> 	pop	es
   443                              <1> L14:
   444                              <1> 	; clear keyboard buffer
   445 0000028E B411                <1> 	mov 	ah, 11h
   446 00000290 CD16                <1> 	int 	16h
   447 00000292 7466                <1> 	jz 	short L16 ; no keys in keyboard buffer
   448 00000294 B010                <1> 	mov	al, 10h
   449 00000296 CD16                <1> 	int 	16h
   450 00000298 EBF4                <1> 	jmp 	short L14
   451                              <1> 
   452                              <1> set_disk_parms:
   453                              <1> 	; 04/02/2016 (ebx -> bx)
   454                              <1> 	; 10/07/2015
   455                              <1> 	; 14/01/2015
   456                              <1> 	;push	bx
   457 0000029A 28FF                <1> 	sub	bh, bh
   458 0000029C 8A1E[235D]          <1> 	mov	bl, [drv]
   459 000002A0 80FB80              <1> 	cmp	bl, 80h
   460 000002A3 7203                <1> 	jb	short sdp0
   461 000002A5 80EB7E              <1> 	sub	bl, 7Eh
   462                              <1> sdp0:	
   463 000002A8 81C3[725D]          <1> 	add	bx, drv.status
   464 000002AC C60780              <1>   	mov	byte [bx], 80h ; 'Present' flag
   465                              <1> 	;
   466 000002AF 88E8                <1> 	mov	al, ch ; last cylinder (bits 0-7)
   467 000002B1 88CC                <1> 	mov	ah, cl ; 
   468 000002B3 C0EC06              <1> 	shr	ah, 6  ; last cylinder (bits 8-9)
   469 000002B6 81EB[725D]          <1> 	sub	bx, drv.status
   470 000002BA D0E3                <1> 	shl	bl, 1
   471 000002BC 81C3[2C5D]          <1> 	add	bx, drv.cylinders
   472 000002C0 40                  <1> 	inc	ax  ; convert max. cyl number to cyl count		
   473 000002C1 8907                <1> 	mov	[bx], ax
   474 000002C3 50                  <1> 	push	ax ; ** cylinders
   475 000002C4 81EB[2C5D]          <1> 	sub	bx, drv.cylinders
   476 000002C8 81C3[3A5D]          <1> 	add	bx, drv.heads
   477 000002CC 30E4                <1> 	xor	ah, ah
   478 000002CE 88F0                <1> 	mov	al, dh ; heads
   479 000002D0 40                  <1> 	inc	ax
   480 000002D1 8907                <1> 	mov	[bx], ax
   481 000002D3 81EB[3A5D]          <1>         sub     bx, drv.heads
   482 000002D7 81C3[485D]          <1>         add     bx, drv.spt
   483 000002DB 30ED                <1> 	xor	ch, ch
   484 000002DD 80E13F              <1> 	and	cl, 3Fh	; sectors (bits 0-6)
   485 000002E0 890F                <1> 	mov	[bx], cx
   486 000002E2 81EB[485D]          <1>         sub     bx, drv.spt
   487 000002E6 D1E3                <1> 	shl	bx, 1
   488 000002E8 81C3[565D]          <1> 	add	bx, drv.size ; disk size (in sectors)
   489                              <1> 	; LBA size = cylinders * heads * secpertrack
   490 000002EC F7E1                <1> 	mul	cx 
   491 000002EE 89C2                <1> 	mov	dx, ax	; heads*spt					
   492 000002F0 58                  <1> 	pop	ax ; ** cylinders
   493 000002F1 48                  <1> 	dec	ax ; 1 cylinder reserved (!?)
   494 000002F2 F7E2                <1> 	mul	dx ; cylinders * (heads*spt)		
   495 000002F4 8907                <1> 	mov	[bx], ax
   496 000002F6 895702              <1> 	mov	[bx+2], dx
   497                              <1> 	;
   498                              <1> 	;pop	bx
   499 000002F9 C3                  <1> 	retn
   500                              <1> 
   501                              <1> L16:	; 28/05/2016
   204                                  
   205                                  	; 10/11/2014
   206 000002FA FA                           	cli	; Disable interrupts (clear interrupt flag)
   207                                  		; Reset Interrupt MASK Registers (Master&Slave)
   208                                  	;mov	al, 0FFh	; mask off all interrupts
   209                                  	;out	21h, al		; on master PIC (8259)
   210                                  	;jmp 	$+2  ; (delay)
   211                                  	;out	0A1h, al	; on slave PIC (8259)
   212                                  	;
   213                                  	; Disable NMI 
   214 000002FB B080                    	mov   	al, 80h 
   215 000002FD E670                    	out   	70h, al		; set bit 7 to 1 for disabling NMI
   216                                  	;23/02/2015
   217                                  	;nop			;
   218                                  	;in	al, 71h		; read in 71h just after writing out to 70h
   219                                  				; for preventing unknown state (!?)
   220                                  	;
   221                                   	; 20/08/2014
   222                                  	; Moving the kernel 64 KB back (to physical address 0)
   223                                  	; DS = CS = 1000h
   224                                  	; 05/11/2014
   225 000002FF 31C0                    	xor	ax, ax
   226 00000301 8EC0                    	mov	es, ax ; ES = 0
   227                                  	;
   228                                  	; 04/07/2016 -  TRDOS 386 (64K - 128K kernel)
   229 00000303 31F6                          	xor	si, si
   230 00000305 31FF                    	xor	di, di
   231 00000307 B90040                  	mov	cx, 16384
   232 0000030A F366A5                  	rep	movsd
   233                                  	;
   234 0000030D 06                      	push	es ; 0
   235 0000030E 68[1203]                	push	L17
   236 00000311 CB                      	retf
   237                                  L17:
   238 00000312 B90010                  	mov	cx, 1000h
   239 00000315 8EC1                    	mov	es, cx  ; 1000h 
   240 00000317 01C9                    	add	cx, cx
   241 00000319 8ED9                    	mov	ds, cx  ; 2000h
   242 0000031B 29F6                    	sub	si, si
   243 0000031D 29FF                    	sub	di, di
   244 0000031F B90040                  	mov	cx, 16384
   245 00000322 F366A5                  	rep	movsd
   246                                  	
   247                                  	; Turn off the floppy drive motor
   248 00000325 BAF203                          mov     dx, 3F2h
   249 00000328 EE                              out     dx, al ; 0 ; 31/12/2013
   250                                  
   251                                  	; Enable access to memory above one megabyte
   252                                  L18:
   253 00000329 E464                    	in	al, 64h
   254 0000032B A802                    	test	al, 2
   255 0000032D 75FA                            jnz     short L18
   256 0000032F B0D1                    	mov	al, 0D1h	; Write output port
   257 00000331 E664                    	out	64h, al
   258                                  L19:
   259 00000333 E464                    	in	al, 64h
   260 00000335 A802                    	test	al, 2
   261 00000337 75FA                            jnz     short L19
   262 00000339 B0DF                    	mov	al, 0DFh	; Enable A20 line
   263 0000033B E660                    	out	60h, al
   264                                  ;L20:
   265                                  	;
   266                                  	; Load global descriptor table register
   267                                  
   268                                          ;mov     ax, cs
   269                                          ;mov     ds, ax
   270                                  
   271 0000033D 2E0F0116[905C]                  lgdt    [cs:gdtd]
   272                                  
   273 00000343 0F20C0                          mov     eax, cr0
   274                                  	; or 	eax, 1
   275 00000346 40                      	inc     ax
   276 00000347 0F22C0                  	mov     cr0, eax
   277                                  
   278                                  	; Jump to 32 bit code
   279                                  	
   280 0000034A 66                      	db 66h 			; Prefix for 32-bit
   281 0000034B EA                      	db 0EAh 		; Opcode for far jump
   282 0000034C [52030000]              	dd StartPM 		; Offset to start, 32-bit
   283                                  				; (1000h:StartPM = StartPM + 10000h)
   284 00000350 0800                    	dw KCODE		; This is the selector for CODE32_DESCRIPTOR,
   285                                  				; assuming that StartPM resides in code32
   286                                  
   287                                  ; 20/02/2017
   288                                  
   289                                  
   290                                  [BITS 32] 
   291                                  
   292                                  StartPM:
   293                                  	; Kernel Base Address = 0 ; 30/12/2013
   294 00000352 66B81000                	mov ax, KDATA           ; Save data segment identifier
   295 00000356 8ED8                            mov ds, ax              ; Move a valid data segment into DS register
   296 00000358 8EC0                           	mov es, ax              ; Move data segment into ES register
   297 0000035A 8EE0                           	mov fs, ax              ; Move data segment into FS register
   298 0000035C 8EE8                          	mov gs, ax              ; Move data segment into GS register
   299 0000035E 8ED0                            mov ss, ax              ; Move data segment into SS register
   300 00000360 BC00000900                      mov esp, 90000h         ; Move the stack pointer to 090000h
   301                                  
   302                                  clear_bss: ; Clear uninitialized data area
   303                                  	; 11/03/2015
   304 00000365 31C0                    	xor  eax, eax ; 0
   305 00000367 B9F86E0000              	mov  ecx, (bss_end - bss_start)/4
   306                                  	;shr  ecx, 2 ; bss section is already aligned for double words
   307 0000036C BF[BA550100]            	mov  edi, bss_start	
   308 00000371 F3AB                    	rep  stosd  		
   309                                  
   310                                  memory_init:
   311                                  	; Initialize memory allocation table and page tables
   312                                  	; 16/11/2014
   313                                  	; 15/11/2014
   314                                  	; 07/11/2014
   315                                  	; 06/11/2014
   316                                  	; 05/11/2014
   317                                  	; 04/11/2014
   318                                  	; 31/10/2014 (Retro UNIX 386 v1 - Beginning) 
   319                                  	;
   320                                  ;	xor	eax, eax
   321                                  ;	xor 	ecx, ecx
   322 00000373 B108                    	mov	cl, 8
   323 00000375 BF00001000              	mov	edi, MEM_ALLOC_TBL	
   324 0000037A F3AB                    	rep	stosd		   ; clear Memory Allocation Table
   325                                  				   ; for the first 1 MB memory
   326                                  	;
   327 0000037C 668B0D[1E5D0000]        	mov	cx, [mem_1m_1k]	   ; Number of contiguous KB between
   328                                  				   ; 1 and 16 MB, max. 3C00h = 15 MB.
   329 00000383 66C1E902                	shr	cx, 2		   ; convert 1 KB count to 4 KB count
   330 00000387 890D[B0580100]          	mov	[free_pages], ecx
   331 0000038D 668B15[205D0000]        	mov	dx, [mem_16m_64k]  ; Number of contiguous 64 KB blocks
   332                                  				   ; between 16 MB and 4 GB.	
   333 00000394 6609D2                  	or	dx, dx
   334 00000397 7413                    	jz	short mi_0
   335                                  	;
   336 00000399 6689D0                  	mov	ax, dx
   337 0000039C C1E004                  	shl	eax, 4		   ; 64 KB -> 4 KB (page count)
   338 0000039F 0105[B0580100]          	add	[free_pages], eax
   339 000003A5 0500100000              	add	eax, 4096	   ; 16 MB = 4096 pages
   340 000003AA EB07                    	jmp	short mi_1
   341                                  mi_0:
   342 000003AC 6689C8                  	mov	ax, cx
   343 000003AF 66050001                	add	ax, 256		   ; add 256 pages for the first 1 MB		 
   344                                  mi_1:
   345 000003B3 A3[AC580100]            	mov	[memory_size], eax ; Total available memory in pages
   346                                  				   ; 1 alloc. tbl. bit = 1 memory page
   347                                  				   ; 32 allocation bits = 32 mem. pages   
   348                                  	;
   349 000003B8 05FF7F0000              	add	eax, 32767	   ; 32768 memory pages per 1 M.A.T. page 	
   350 000003BD C1E80F                  	shr	eax, 15		   ; ((32768 * x) + y) pages (y < 32768)
   351                                  				   ;  --> x + 1 M.A.T. pages, if y > 0
   352                                  				   ;  --> x M.A.T. pages, if y = 0
   353 000003C0 66A3[C0580100]          	mov	[mat_size], ax	   ; Memory Alloc. Table Size in pages		
   354 000003C6 C1E00C                  	shl	eax, 12		   ; 1 M.A.T. page = 4096 bytes
   355                                  	;			   ; Max. 32 M.A.T. pages (4 GB memory)
   356 000003C9 89C3                    	mov	ebx, eax	   ; M.A.T. size in bytes
   357                                  	; Set/Calculate Kernel's Page Directory Address
   358 000003CB 81C300001000            	add	ebx, MEM_ALLOC_TBL
   359 000003D1 891D[A8580100]          	mov	[k_page_dir], ebx  ; Kernel's Page Directory address
   360                                  				   ; just after the last M.A.T. page
   361                                  	;
   362 000003D7 83E804                  	sub	eax, 4		   ; convert M.A.T. size to offset value
   363 000003DA A3[B8580100]            	mov	[last_page], eax   ; last page ofset in the M.A.T.
   364                                  	;			   ; (allocation status search must be 
   365                                  				   ; stopped after here)	
   366 000003DF 31C0                    	xor	eax, eax
   367 000003E1 48                      	dec	eax		   ; FFFFFFFFh (set all bits to 1)	
   368 000003E2 6651                    	push	cx
   369 000003E4 C1E905                  	shr	ecx, 5		   ; convert 1 - 16 MB page count to 
   370                                  				   ; count of 32 allocation bits
   371 000003E7 F3AB                    	rep	stosd
   372 000003E9 6659                    	pop	cx
   373 000003EB 40                      	inc	eax		   ; 0	
   374 000003EC 80E11F                  	and	cl, 31		   ; remain bits
   375 000003EF 7412                    	jz	short mi_4
   376 000003F1 8907                    	mov	[edi], eax	   ; reset	
   377                                  mi_2:
   378 000003F3 0FAB07                  	bts	[edi], eax	   ; 06/11/2014		
   379 000003F6 FEC9                    	dec	cl
   380 000003F8 7404                    	jz	short mi_3
   381 000003FA FEC0                    	inc	al
   382 000003FC EBF5                    	jmp	short mi_2
   383                                  mi_3:
   384 000003FE 28C0                    	sub	al, al	   	   ; 0
   385 00000400 83C704                  	add	edi, 4		   ; 15/11/2014
   386                                  mi_4:
   387 00000403 6609D2                  	or	dx, dx		  ; check 16M to 4G memory space	
   388 00000406 7421                    	jz	short mi_6	  ; max. 16 MB memory, no more...
   389                                  	;	
   390 00000408 B900021000              	mov	ecx, MEM_ALLOC_TBL + 512 ; End of first 16 MB memory
   391                                  	;	
   392 0000040D 29F9                    	sub	ecx, edi	  ; displacement (to end of 16 MB)
   393 0000040F 7406                    	jz	short mi_5	  ; jump if EDI points to 
   394                                  				  ;         end of first 16 MB	
   395 00000411 D1E9                    	shr	ecx, 1		  ; convert to dword count
   396 00000413 D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   397 00000415 F3AB                    	rep 	stosd		  ; reset all bits for reserved pages
   398                                  				  ; (memory hole under 16 MB)
   399                                  mi_5:
   400 00000417 6689D1                  	mov	cx, dx		  ; count of 64 KB memory blocks
   401 0000041A D1E9                    	shr	ecx, 1		  ; 1 alloc. dword per 128 KB memory
   402 0000041C 9C                      	pushf			  ; 16/11/2014		
   403 0000041D 48                      	dec	eax		  ; FFFFFFFFh (set all bits to 1)
   404 0000041E F3AB                    	rep	stosd
   405 00000420 40                      	inc	eax		  ; 0
   406 00000421 9D                      	popf			  ; 16/11/2014
   407 00000422 7305                    	jnc	short mi_6
   408 00000424 6648                    	dec	ax		  ; eax = 0000FFFFh
   409 00000426 AB                      	stosd
   410 00000427 6640                    	inc	ax		  ; 0		
   411                                  mi_6:
   412 00000429 39DF                    	cmp	edi, ebx	  ; check if EDI points to 	
   413 0000042B 730A                    	jnb	short mi_7	  ; end of memory allocation table
   414                                  	;			  ; (>= MEM_ALLOC_TBL + 4906) 
   415 0000042D 89D9                    	mov	ecx, ebx	  ; end of memory allocation table
   416 0000042F 29F9                    	sub	ecx, edi	  ; convert displacement/offset
   417 00000431 D1E9                    	shr	ecx, 1		  ; to dword count 	 		
   418 00000433 D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   419 00000435 F3AB                    	rep 	stosd		  ; reset all remain M.A.T. bits
   420                                  mi_7:
   421                                  	; Reset M.A.T. bits in M.A.T. (allocate M.A.T. pages)
   422 00000437 BA00001000              	mov	edx, MEM_ALLOC_TBL
   423                                  	;sub	ebx, edx	  ; Mem. Alloc. Tbl. size in bytes
   424                                  	;shr	ebx, 12		  ; Mem. Alloc. Tbl. size in pages	
   425 0000043C 668B0D[C0580100]        	mov	cx, [mat_size]	  ; Mem. Alloc. Tbl. size in pages
   426 00000443 89D7                    	mov	edi, edx
   427 00000445 C1EF0F                  	shr	edi, 15		  ; convert M.A.T. address to
   428                                  				  ; byte offset in M.A.T.
   429                                  				  ; (1 M.A.T. byte points to 
   430                                  				  ;	      32768 bytes)
   431                                  				  ; Note: MEM_ALLOC_TBL address 
   432                                  				  ; must be aligned on 128 KB 
   433                                  				  ; boundary!
   434 00000448 01D7                    	add	edi, edx	  ; points to M.A.T.'s itself	
   435                                  	; eax = 0
   436 0000044A 290D[B0580100]          	sub	[free_pages], ecx ; 07/11/2014
   437                                  mi_8:
   438 00000450 0FB307                  	btr	[edi], eax	  ; clear bit 0 to bit x (1 to 31)
   439                                  	;dec	bl
   440 00000453 FEC9                    	dec	cl
   441 00000455 7404                    	jz	short mi_9
   442 00000457 FEC0                    	inc	al
   443 00000459 EBF5                    	jmp	short mi_8
   444                                  mi_9:
   445                                  	;
   446                                  	; Reset Kernel's Page Dir. and Page Table bits in M.A.T.
   447                                  	;		(allocate pages for system page tables)
   448                                  
   449                                  	; edx = MEM_ALLOC_TBL
   450 0000045B 8B0D[AC580100]          	mov	ecx, [memory_size] ; memory size in pages (PTEs)
   451 00000461 81C1FF030000            	add	ecx, 1023	 ; round up (1024 PTEs per table)	 	
   452 00000467 C1E90A                  	shr	ecx, 10		 ; convert memory page count to 
   453                                  				 ; page table count (PDE count)
   454                                  	;
   455 0000046A 51                      	push	ecx		 ; (**) PDE count (<= 1024)
   456                                  	;
   457 0000046B 41                      	inc	ecx		 ; +1 for kernel page directory	
   458                                  	;
   459 0000046C 290D[B0580100]          	sub	[free_pages], ecx ; 07/11/2014
   460                                  	;
   461 00000472 8B35[A8580100]          	mov	esi, [k_page_dir] ; Kernel's Page Directory address
   462 00000478 C1EE0C                  	shr	esi, 12		 ; convert to page number
   463                                  mi_10:
   464 0000047B 89F0                    	mov	eax, esi	 ; allocation bit offset		 
   465 0000047D 89C3                    	mov	ebx, eax
   466 0000047F C1EB03                  	shr	ebx, 3		 ; convert to alloc. byte offset
   467 00000482 80E3FC                  	and	bl,  0FCh	 ; clear bit 0 and bit 1
   468                                  				 ;   to align on dword boundary
   469 00000485 83E01F                  	and	eax, 31		 ; set allocation bit position 
   470                                  				 ;  (bit 0 to bit 31)
   471                                  	;
   472 00000488 01D3                    	add	ebx, edx	 ; offset in M.A.T. + M.A.T. address 
   473                                  	;
   474 0000048A 0FB303                  	btr 	[ebx], eax	 ; reset relevant bit (0 to 31)
   475                                  	;
   476 0000048D 46                      	inc	esi		 ; next page table
   477 0000048E E2EB                    	loop	mi_10		 ; allocate next kernel page table 
   478                                  				 ; (ecx = page table count + 1)		
   479                                  	;
   480 00000490 59                      	pop	ecx		 ; (**) PDE count (= pg. tbl. count)
   481                                  	;
   482                                  	; Initialize Kernel Page Directory and Kernel Page Tables
   483                                  	;
   484                                  	; Initialize Kernel's Page Directory
   485 00000491 8B3D[A8580100]          	mov	edi, [k_page_dir]
   486 00000497 89F8                    	mov	eax, edi
   487 00000499 0C03                    	or	al, PDE_A_PRESENT + PDE_A_WRITE
   488                                  		     	      ; supervisor + read&write + present
   489 0000049B 89CA                    	mov	edx, ecx 	; (**) PDE count (= pg. tbl. count)	
   490                                  mi_11:
   491 0000049D 0500100000              	add	eax, 4096	; Add page size (PGSZ)
   492                                  			        ; EAX points to next page table
   493 000004A2 AB                      	stosd
   494 000004A3 E2F8                    	loop	mi_11
   495 000004A5 29C0                    	sub	eax, eax	; Empty PDE
   496 000004A7 66B90004                	mov	cx, 1024	; Entry count (PGSZ/4)
   497 000004AB 29D1                    	sub	ecx, edx
   498 000004AD 7402                    	jz	short mi_12
   499 000004AF F3AB                    	rep	stosd 		; clear remain (empty) PDEs
   500                                  	;
   501                                  	; Initialization of Kernel's Page Directory is OK, here.
   502                                  mi_12:
   503                                  	; Initialize Kernel's Page Tables
   504                                  	;
   505                                  	; (EDI points to address of page table 0)
   506                                  	; eax = 0
   507 000004B1 8B0D[AC580100]          	mov	ecx, [memory_size] ; memory size in pages
   508 000004B7 89CA                    	mov	edx, ecx	; (***)
   509 000004B9 B003                    	mov	al, PTE_A_PRESENT + PTE_A_WRITE
   510                                  			     ; supervisor + read&write + present 	
   511                                  mi_13:
   512 000004BB AB                      	stosd
   513 000004BC 0500100000              	add	eax, 4096	
   514 000004C1 E2F8                    	loop	mi_13	
   515 000004C3 6681E2FF03              	and	dx, 1023	; (***)
   516 000004C8 740B                    	jz	short mi_14
   517 000004CA 66B90004                	mov	cx, 1024	
   518 000004CE 6629D1                  	sub	cx, dx		; from dx (<= 1023) to 1024
   519 000004D1 31C0                    	xor	eax, eax
   520 000004D3 F3AB                    	rep	stosd		; clear remain (empty) PTEs 
   521                                  				; of the last page table
   522                                  mi_14:
   523                                  	;  Initialization of Kernel's Page Tables is OK, here.
   524                                  	;
   525 000004D5 89F8                    	mov	eax, edi	; end of the last page table page
   526                                  			        ; (beginging of user space pages)
   527 000004D7 C1E80F                  	shr	eax, 15		; convert to M.A.T. byte offset
   528 000004DA 24FC                    	and	al, 0FCh	; clear bit 0 and bit 1 for
   529                                  				; aligning on dword boundary	
   530                                  	 
   531 000004DC A3[BC580100]            	mov	[first_page], eax
   532 000004E1 A3[B4580100]            	mov	[next_page], eax ; The first free page pointer
   533                                  				 ; for user programs
   534                                  				 ; (Offset in Mem. Alloc. Tbl.)	
   535                                  	;
   536                                  	; Linear/FLAT (1 to 1) memory paging for the kernel is OK, here.
   537                                  	;
   538                                  	
   539                                  	; Enable paging
   540                                  	;
   541 000004E6 A1[A8580100]                    mov     eax, [k_page_dir]
   542 000004EB 0F22D8                  	mov	cr3, eax
   543 000004EE 0F20C0                  	mov	eax, cr0
   544 000004F1 0D00000080              	or	eax, 80000000h	; set paging bit (bit 31)
   545 000004F6 0F22C0                  	mov	cr0, eax
   546                                          ;jmp    KCODE:StartPMP
   547                                  
   548 000004F9 EA                      	db 0EAh 		; Opcode for far jump
   549 000004FA [00050000]                      dd StartPMP		; 32 bit offset
   550 000004FE 0800                    	dw KCODE		; kernel code segment descriptor
   551                                  
   552                                  
   553                                  StartPMP:
   554                                  	; 06/11//2014
   555                                  	; Clear video page 0
   556                                  	;
   557                                  	; Temporary Code
   558                                  	;
   559 00000500 B9E8030000              	mov	ecx, 80*25/2
   560 00000505 BF00800B00              	mov	edi, 0B8000h
   561                                  	; 30/01/2016
   562                                  	;xor	eax, eax	; black background, black fore color
   563 0000050A B800070007              	mov	eax, 07000700h  ; black background, light gray fore color
   564 0000050F F3AB                    	rep	stosd
   565                                  	
   566                                  	; 19/08/2014
   567                                  	; Kernel Base Address = 0
   568                                  	; It is mapped to (physically) 0 in the page table.
   569                                  	; So, here is exactly 'StartPMP' address.
   570                                  
   571                                   	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
   572 00000511 BE[F5190100]            	mov	esi, starting_msg
   573                                  	;; 14/08/2015 (kernel version message will appear
   574                                  	;;	       when protected mode and paging is enabled)
   575 00000516 BF00800B00              	mov	edi, 0B8000h ; 27/08/2014
   576 0000051B B40A                    	mov	ah, 0Ah ; Black background, light green forecolor
   577                                  	; 20/08/2014
   578 0000051D E88F010000              	call	printk
   579                                  
   580                                  	; 'UNIX v7/x86' source code by Robert Nordier (1999)
   581                                  	; // Set IRQ offsets
   582                                  	;
   583                                  	;  Linux (v0.12) source code by Linus Torvalds (1991)
   584                                  	;
   585                                  					;; ICW1
   586 00000522 B011                    	mov	al, 11h			; Initialization sequence
   587 00000524 E620                    	out	20h, al			; 	8259A-1
   588                                  	; jmp 	$+2
   589 00000526 E6A0                    	out	0A0h, al		; 	8259A-2
   590                                  					;; ICW2
   591 00000528 B020                    	mov	al, 20h			; Start of hardware ints (20h)
   592 0000052A E621                    	out	21h, al			;	for 8259A-1
   593                                  	; jmp 	$+2
   594 0000052C B028                    	mov	al, 28h			; Start of hardware ints (28h)
   595 0000052E E6A1                    	out	0A1h, al		; 	for 8259A-2
   596                                  					;
   597 00000530 B004                    	mov	al, 04h			;; ICW3
   598 00000532 E621                    	out	21h, al			; 	IRQ2 of 8259A-1 (master)
   599                                  	; jmp 	$+2
   600 00000534 B002                    	mov	al, 02h			; 	is 8259A-2 (slave)
   601 00000536 E6A1                    	out	0A1h, al		;
   602                                  					;; ICW4
   603 00000538 B001                    	mov	al, 01h	 		;
   604 0000053A E621                    	out	21h, al			; 	8086 mode, normal EOI	
   605                                  	; jmp 	$+2
   606 0000053C E6A1                    	out	0A1h, al		;	for both chips.
   607                                  
   608                                  	;mov	al, 0FFh	; mask off all interrupts for now
   609                                  	;out	21h, al
   610                                  	;; jmp 	$+2
   611                                  	;out	0A1h, al
   612                                  
   613                                  	; 02/04/2015
   614                                  	; 26/03/2015 System call (INT 30h) modification
   615                                  	;  DPL = 3 (Interrupt service routine can be called from user mode)			
   616                                  	;
   617                                  	;; Linux (v0.12) source code by Linus Torvalds (1991)
   618                                  	;  setup_idt:
   619                                  	;
   620                                          ;; 16/02/2015
   621                                  	;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
   622                                  	; 21/08/2014 (timer_int)
   623 0000053E BE[B8160100]            	mov	esi, ilist
   624 00000543 8D3D[C0550100]          	lea	edi, [idt]
   625                                  	; 26/03/2015
   626 00000549 B930000000              	mov	ecx, 48		; 48 hardware interrupts (INT 0 to INT 2Fh)
   627                                  	; 02/04/2015
   628 0000054E BB00000800              	mov	ebx,  80000h
   629                                  rp_sidt1:
   630 00000553 AD                      	lodsd
   631 00000554 89C2                    	mov	edx, eax
   632 00000556 66BA008E                	mov	dx, 8E00h
   633 0000055A 6689C3                  	mov	bx, ax
   634 0000055D 89D8                    	mov	eax, ebx	; /* selector = 0x0008 = cs */
   635                                         			        ; /* interrupt gate - dpl=0, present */
   636 0000055F AB                      	stosd	; selector & offset bits 0-15 	
   637 00000560 89D0                    	mov	eax, edx
   638 00000562 AB                      	stosd	; attributes & offset bits 16-23
   639 00000563 E2EE                    	loop	rp_sidt1
   640                                  	; 15/04/2016
   641                                  	; TRDOS 386 (TRDOS v2.0) /// 32 sofware interrupts ///
   642                                  	;mov	cl, 16        ; 16 software interrupts (INT 30h to INT 3Fh)
   643 00000565 B120                    	mov	cl, 32	      ; 32 software interrupts (INT 30h to INT 4Fh)	
   644                                  rp_sidt2:
   645 00000567 AD                      	lodsd
   646 00000568 21C0                    	and	eax, eax
   647 0000056A 7413                    	jz	short rp_sidt3
   648 0000056C 89C2                    	mov	edx, eax
   649 0000056E 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   650 00000572 6689C3                  	mov	bx, ax
   651 00000575 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   652 00000577 AB                      	stosd
   653 00000578 89D0                    	mov	eax, edx
   654 0000057A AB                      	stosd
   655 0000057B E2EA                    	loop	rp_sidt2
   656 0000057D EB16                    	jmp	short sidt_OK
   657                                  rp_sidt3:
   658 0000057F B8[DA0A0000]            	mov	eax, ignore_int
   659 00000584 89C2                    	mov	edx, eax
   660 00000586 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   661 0000058A 6689C3                  	mov	bx, ax
   662 0000058D 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   663                                  rp_sidt4:
   664 0000058F AB                      	stosd
   665 00000590 92                      	xchg	eax, edx
   666 00000591 AB                      	stosd
   667 00000592 92                      	xchg	edx, eax
   668 00000593 E2FA                    	loop	rp_sidt4
   669                                  sidt_OK: 
   670 00000595 0F011D[965C0000]        	lidt 	[idtd]
   671                                  	;
   672                                  	; TSS descriptor setup ; 24/03/2015
   673 0000059C B8[40580100]            	mov	eax, task_state_segment
   674 000005A1 66A3[8A5C0000]          	mov	[gdt_tss0], ax
   675 000005A7 C1C010                  	rol	eax, 16
   676 000005AA A2[8C5C0000]            	mov	[gdt_tss1], al
   677 000005AF 8825[8F5C0000]          	mov	[gdt_tss2], ah
   678 000005B5 66C705[A6580100]68-     	mov	word [tss.IOPB], tss_end - task_state_segment
   678 000005BD 00                 
   679                                  		; 
   680                                  		; IO Map Base address (When this address points
   681                                  		; to end of the TSS, CPU does not use IO port 
   682                                  		; permission bit map for RING 3 IO permissions, 
   683                                  		; access to any IO ports in ring 3 will be forbidden.)
   684                                   		;
   685                                  	;mov	[tss.esp0], esp ; TSS offset 4
   686                                  	;mov	word [tss.ss0], KDATA ; TSS offset 8 (SS)
   687 000005BE 66B82800                   	mov	ax, TSS  ; It is needed when an interrupt 
   688                                  			 ; occurs (or a system call -software INT- is requested)
   689                                  			 ; while cpu running in ring 3 (in user mode).				
   690                                  			 ; (Kernel stack pointer and segment will be loaded
   691                                  			 ; from offset 4 and 8 of the TSS, by the CPU.)	 
   692 000005C2 0F00D8                  	ltr	ax  ; Load task register
   693                                  	;
   694                                  esp0_set0:
   695                                  	; 30/07/2015
   696 000005C5 8B0D[AC580100]          	mov 	ecx, [memory_size] ; memory size in pages
   697 000005CB C1E10C                  	shl 	ecx, 12 ; convert page count to byte count
   698 000005CE 81F900004000            	cmp	ecx, CORE ; beginning of user's memory space (400000h)
   699                                  			  ; (kernel mode virtual address)
   700 000005D4 7605                    	jna	short esp0_set1
   701                                  	;
   702                                  	; If available memory > CORE (end of the 1st 4 MB)
   703                                  	; set stack pointer to CORE
   704                                  	;(Because, PDE 0 is reserved for kernel space in user's page directory)
   705                                  	;(PDE 0 points to page table of the 1st 4 MB virtual address space)
   706 000005D6 B900004000              	mov	ecx, CORE
   707                                  esp0_set1:
   708 000005DB 89CC                    	mov	esp, ecx ; top of kernel stack (**tss.esp0**)
   709                                  esp0_set_ok:
   710                                  	; 30/07/2015 (**tss.esp0**) 
   711 000005DD 8925[44580100]          	mov	[tss.esp0], esp
   712 000005E3 66C705[48580100]10-             mov     word [tss.ss0], KDATA
   712 000005EB 00                 
   713                                  	; 14/08/2015
   714                                  	; 10/11/2014 (Retro UNIX 386 v1 - Erdogan Tan)
   715                                  	;
   716                                  	;cli	; Disable interrupts (for CPU)
   717                                  	;    (CPU will not handle hardware interrupts, except NMI!)
   718                                  	;
   719 000005EC 30C0                    	xor	al, al		; Enable all hardware interrupts!
   720 000005EE E621                    	out	21h, al		; (IBM PC-AT compatibility)
   721 000005F0 EB00                    	jmp 	$+2		; (All conventional PC-AT hardware
   722 000005F2 E6A1                    	out	0A1h, al	;  interrupts will be in use.)	
   723                                  				; (Even if related hardware component
   724                                  				;  does not exist!)
   725                                  	; Enable NMI 
   726 000005F4 B07F                    	mov	al, 7Fh		; Clear bit 7 to enable NMI (again)
   727 000005F6 E670                    	out  	70h, al
   728                                  	; 23/02/2015
   729 000005F8 90                      	nop
   730 000005F9 E471                    	in	al, 71h		; read in 71h just after writing out to 70h
   731                                  				; for preventing unknown state (!?)
   732                                  	;
   733                                  	; Only a NMI can occur here... (Before a 'STI' instruction)
   734                                  	;
   735                                  	; 02/09/2014
   736 000005FB 6631DB                  	xor	bx, bx
   737 000005FE 66BA0002                	mov	dx, 0200h	; Row 2, column 0  ; 07/03/2015
   738 00000602 E871170000              	call	_set_cpos	; 24/01/2016
   739                                  	;
   740                                  	; 06/11/2014
   741 00000607 E8782C0000              	call	memory_info
   742                                  	; 14/08/2015
   743                                  	;call getch ; 28/02/2015
   744                                  drv_init:
   745 0000060C FB                      	sti	; Enable Interrupts 
   746                                  	; 06/02/2015
   747 0000060D 8B15[285D0000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
   748 00000613 668B1D[265D0000]        	mov	bx, [fd0_type] ; fd0, fd1
   749                                  	; 22/02/2015
   750 0000061A 6621DB                  	and	bx, bx
   751 0000061D 751C                    	jnz	short di1
   752                                  	;
   753 0000061F 09D2                    	or 	edx, edx
   754 00000621 752A                    	jnz	short di2
   755                                  	;
   756                                  setup_error:
   757 00000623 BE[BE190100]            	mov 	esi, setup_error_msg
   758                                  psem:	
   759 00000628 AC                      	lodsb
   760 00000629 08C0                    	or	al, al
   761                                  	;jz	short haltx ; 22/02/2015
   762 0000062B 7427                    	jz	short di3
   763 0000062D 56                      	push	esi
   764                                  	; 13/05/2016
   765 0000062E BB07000000              	mov	ebx, 7	; Black background, 
   766                                  			; light gray forecolor
   767                                  			; Video page 0 (BH=0)
   768 00000633 E8AA160000              	call	_write_tty
   769 00000638 5E                      	pop	esi
   770 00000639 EBED                    	jmp	short psem
   771                                  
   772                                  di1:
   773                                  	; supress 'jmp short T6'
   774                                  	;  (activate fdc motor control code)
   775 0000063B 66C705[1B070000]90-     	mov	word [T5], 9090h ; nop
   775 00000643 90                 
   776                                  	;
   777                                  	;mov	ax, int_0Eh	; IRQ 6 handler
   778                                  	;mov	di, 0Eh*4	; IRQ 6 vector
   779                                  	;stosw
   780                                  	;mov 	ax, cs
   781                                  	;stosw
   782                                  	;; 16/02/2015
   783                                          ;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
   784                                  	;
   785 00000644 E8B03B0000              	CALL	DSKETTE_SETUP	; Initialize Floppy Disks
   786                                  	;
   787 00000649 09D2                    	or	edx, edx
   788 0000064B 7407                            jz      short di3
   789                                  di2:
   790 0000064D E8EE3B0000              	call   	DISK_SETUP	; Initialize Fixed Disks
   791 00000652 72CF                            jc      short setup_error
   792                                  di3:
   793 00000654 E8FF2B0000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
   794                                  	;
   795 00000659 E8F6110100              	call	display_disks ; 07/03/2015  (Temporary)
   796                                  ;haltx:
   797                                  	; 14/08/2015
   798                                  	;call	getch ; 22/02/2015
   799                                  	;sti	; Enable interrupts (for CPU)
   800                                  ;	; 29/01/2016
   801                                  ;	sub	ah, ah ;  read time count
   802                                  ;	call	int1Ah
   803                                  ;	mov	edx, ecx ; 18.2 * seconds
   804                                  ;md_info_msg_wait1:
   805                                  ;	; 29/01/2016
   806                                  ;	mov	ah, 1
   807                                  ;	call	int16h
   808                                  ;	jz	short md_info_msg_wait2
   809                                  ;	xor	ah, ah ; 0
   810                                  ;       call    int16h
   811                                  ;	jmp 	short md_info_msg_ok
   812                                  ;md_info_msg_wait2:
   813                                  ;	sub	ah, ah  ; read time count
   814                                  ;	call	int1Ah
   815                                  ;	cmp	edx, ecx ; ; 18.2 * seconds
   816                                  ;	jna	short md_info_msg_wait3
   817                                  ;	xchg 	edx, ecx	
   818                                  ;md_info_msg_wait3:
   819                                  ;	sub	ecx, edx
   820                                  ;	cmp	ecx, 127 ; 7 seconds (18.2 * 7)
   821                                  ;	jb	short md_info_msg_wait1		
   822                                  ;md_info_msg_ok:
   823                                  	; 08/09/2016
   824 0000065E 0F20C0                  	mov	eax, cr0
   825 00000661 A810                    	test	al, 10h  ; Bit 4, ET (Extension Type)
   826 00000663 7408                    	jz	short sysinit
   827                                  	; 27/02/2017
   828 00000665 FE05[5C650100]          	inc	byte [fpready]
   829                                  	; 80387 (FPU) is ready
   830 0000066B DBE3                    	fninit ; Initialize Floating-Point Unit
   831                                  sysinit:
   832                                  	; 30/06/2015
   833 0000066D E80C5C0000              	call	sys_init
   834                                  	;
   835                                  	;jmp 	cpu_reset ; 22/02/2015
   836                                  hang:  
   837                                  	; 23/02/2015
   838                                  	;sti			; Enable interrupts
   839 00000672 F4                      	hlt
   840                                  	;
   841                                  	;nop
   842                                  	;; 03/12/2014
   843                                  	;; 28/08/2014
   844                                  	;mov	ah, 11h
   845                                  	;call	getc
   846                                  	;jz      _c8
   847                                  	;
   848                                  	; 23/02/2015
   849                                  	; 06/02/2015
   850                                  	; 07/09/2014
   851 00000673 31DB                    	xor	ebx, ebx
   852 00000675 8A1D[D6580100]          	mov	bl, [ptty]	; active_page
   853 0000067B 89DE                    	mov	esi, ebx
   854 0000067D 66D1E6                  	shl 	si, 1
   855 00000680 81C6[D8580100]          	add	esi, ttychr
   856 00000686 668B06                  	mov	ax, [esi]
   857 00000689 6621C0                  	and	ax, ax
   858                                  	;jz	short _c8
   859 0000068C 74E4                    	jz	short hang
   860 0000068E 66C7060000              	mov	word [esi], 0
   861 00000693 80FB03                  	cmp	bl, 3		; Video page 3
   862                                  	;jb	short _c8
   863 00000696 72DA                    	jb	short hang
   864                                  	;	
   865                                  	; 13/05/2016
   866                                  	; 07/09/2014
   867                                  nxtl:
   868 00000698 6653                    	push	bx
   869 0000069A 66BB0E00                	mov	bx, 0Eh 	; Yellow character 
   870                                  				; on black background
   871                                  				; bh = 0 (video page 0)
   872                                  				; Retro UNIX 386 v1 - Video Mode 0
   873                                  				; (PC/AT Video Mode 3 - 80x25 Alpha.)
   874 0000069E 6650                    	push	ax
   875 000006A0 E83D160000              	call 	_write_tty
   876 000006A5 6658                    	pop	ax
   877 000006A7 665B                    	pop	bx
   878 000006A9 3C0D                    	cmp	al, 0Dh		; carriage return (enter)
   879                                  	;jne	short _c8
   880 000006AB 75C5                    	jne	short hang
   881 000006AD B00A                    	mov	al, 0Ah		; next line
   882 000006AF EBE7                    	jmp	short nxtl
   883                                  	
   884                                  ;_c8:
   885                                  ;	; 25/08/2014
   886                                  ;	cli				; Disable interrupts
   887                                  ;	mov	al, [scounter + 1]
   888                                  ;	and	al, al
   889                                  ;	jnz	hang
   890                                  ;	call	rtc_p
   891                                  ;	jmp     hang
   892                                  
   893                                  
   894                                  	; 27/08/2014
   895                                  	; 20/08/2014
   896                                  printk:
   897                                          ;mov    edi, [scr_row]
   898                                  pkl:
   899 000006B1 AC                      	lodsb
   900 000006B2 08C0                    	or 	al, al
   901 000006B4 7404                    	jz	short pkr
   902 000006B6 66AB                    	stosw
   903 000006B8 EBF7                    	jmp	short pkl
   904                                  pkr:
   905 000006BA C3                      	retn
   906                                  
   907                                  ; 28/02/2017
   908                                  ; 22/01/2017
   909                                  ; 15/01/2017
   910                                  ; 14/01/2017
   911                                  ; 02/01/2017
   912                                  ; 25/12/2016
   913                                  ; 19/12/2016
   914                                  ; 10/12/2016 (callback)
   915                                  ; 06/06/2016
   916                                  ; 23/05/2016
   917                                  ; 22/05/2016 - TRDOS 386 (TRDOS v2.0) Timer Event Modifications
   918                                  ; 25/07/2015
   919                                  ; 14/05/2015 (multi tasking -time sharing- 'clock', x_timer)
   920                                  ; 17/02/2015
   921                                  ; 06/02/2015 (unix386.s)
   922                                  ; 11/12/2014 - 22/12/2014 (dsectrm2.s) 
   923                                  ;
   924                                  ; IBM PC-XT Model 286 Source Code - BIOS2.ASM (06/10/85)
   925                                  ;
   926                                  ;-- HARDWARE INT  08 H - ( IRQ LEVEL 0 ) ---------------------------------------
   927                                  ;	THIS ROUTINE HANDLES THE TIMER INTERRUPT FROM FROM CHANNEL 0 OF        :
   928                                  ;	THE 8254 TIMER.  INPUT FREQUENCY IS 1.19318 MHZ AND THE DIVISOR        :
   929                                  ;	IS 65536, RESULTING IN APPROXIMATELY 18.2 INTERRUPTS EVERY SECOND.     :
   930                                  ;									       :
   931                                  ;	THE INTERRUPT HANDLER MAINTAINS A COUNT (40:6C) OF INTERRUPTS SINCE    :
   932                                  ;	POWER ON TIME, WHICH MAY BE USED TO ESTABLISH TIME OF DAY.	       :
   933                                  ;	THE INTERRUPT HANDLER ALSO DECREMENTS THE MOTOR CONTROL COUNT (40:40)  :
   934                                  ;	OF THE DISKETTE, AND WHEN IT EXPIRES, WILL TURN OFF THE 	       :
   935                                  ;	DISKETTE MOTOR(s), AND RESET THE MOTOR RUNNING FLAGS.		       :
   936                                  ;	THE INTERRUPT HANDLER WILL ALSO INVOKE A USER ROUTINE THROUGH	       :
   937                                  ;	INTERRUPT 1CH AT EVERY TIME TICK.  THE USER MUST CODE A 	       :
   938                                  ;	ROUTINE AND PLACE THE CORRECT ADDRESS IN THE VECTOR TABLE.	       :
   939                                  ;-------------------------------------------------------------------------------
   940                                  ;
   941                                  
   942                                  timer_int:	; IRQ 0
   943                                  ;int_08h:	; Timer
   944                                  	; 14/10/2015
   945                                  	; Here, we are simulating system call entry (for task switch)
   946                                  	; (If multitasking is enabled, 
   947                                  	; 'clock' procedure may jump to 'sysrelease')
   948                                  
   949 000006BB 1E                      	push	ds
   950 000006BC 06                      	push	es
   951 000006BD 0FA0                    	push	fs
   952 000006BF 0FA8                    	push	gs
   953                                  
   954 000006C1 60                      	pushad	; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
   955 000006C2 66B91000                	mov     cx, KDATA
   956 000006C6 8ED9                            mov     ds, cx
   957 000006C8 8EC1                            mov     es, cx
   958 000006CA 8EE1                            mov     fs, cx
   959 000006CC 8EE9                            mov     gs, cx
   960                                  
   961 000006CE 0F20D9                  	mov	ecx, cr3
   962 000006D1 890D[5C040300]          	mov	[cr3reg], ecx ; save current cr3 register value/content
   963                                  
   964                                  	; 14/01/2017
   965 000006D7 3B0D[A8580100]          	cmp 	ecx, [k_page_dir]
   966 000006DD 7409                    	je	short T3
   967                                  
   968 000006DF 8B0D[A8580100]          	mov	ecx, [k_page_dir]
   969 000006E5 0F22D9                  	mov	cr3, ecx
   970                                  T3:
   971                                  	;sti				; INTERRUPTS BACK ON
   972 000006E8 66FF05[28590100]        	INC	word [TIMER_LOW]	; INCREMENT TIME
   973 000006EF 7507                    	JNZ	short T4		; GO TO TEST_DAY
   974 000006F1 66FF05[2A590100]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
   975                                  T4:					; TEST_DAY
   976 000006F8 66833D[2A590100]18      	CMP	word [TIMER_HIGH],018H	; TEST FOR COUNT EQUALING 24 HOURS
   977 00000700 7519                    	JNZ	short T5		; GO TO DISKETTE_CTL
   978 00000702 66813D[28590100]B0-     	CMP	word [TIMER_LOW],0B0H
   978 0000070A 00                 
   979 0000070B 750E                    	JNZ	short T5		; GO TO DISKETTE_CTL
   980                                  
   981                                  ;-----	TIMER HAS GONE 24 HOURS
   982                                  	;;SUB	AX,AX
   983                                  	;MOV	[TIMER_HIGH],AX
   984                                  	;MOV	[TIMER_LOW],AX
   985 0000070D 29C0                    	sub	eax, eax
   986 0000070F A3[28590100]            	mov	[TIMER_LH], eax
   987                                  	;	
   988 00000714 C605[2C590100]01        	MOV	byte [TIMER_OFL],1
   989                                  
   990                                  ;-----	TEST FOR DISKETTE TIME OUT
   991                                  
   992                                  T5:
   993                                  	; 23/12/2014
   994 0000071B EB1D                    	jmp	short T6		; will be replaced with nop, nop
   995                                  					; (9090h) if a floppy disk
   996                                  					; is detected.
   997                                  	;mov	al,[CS:MOTOR_COUNT]
   998 0000071D A0[2F590100]            	mov	al, [MOTOR_COUNT]
   999 00000722 FEC8                    	dec	al
  1000                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
  1001 00000724 A2[2F590100]            	mov	[MOTOR_COUNT], al
  1002                                  	;mov	[ORG_MOTOR_COUNT], al
  1003 00000729 750F                    	JNZ	short T6		; RETURN IF COUNT NOT OUT
  1004 0000072B B0F0                    	mov 	al,0F0h
  1005                                  	;AND	[CS:MOTOR_STATUS],al 	; TURN OFF MOTOR RUNNING BITS
  1006 0000072D 2005[2E590100]          	and	[MOTOR_STATUS], al
  1007                                  	;and	[ORG_MOTOR_STATUS], al
  1008 00000733 B00C                    	MOV	AL,0CH			; bit 3 = enable IRQ & DMA, 
  1009                                  					; bit 2 = enable controller
  1010                                  					;	1 = normal operation
  1011                                  					;	0 = reset	
  1012                                  					; bit 0, 1 = drive select
  1013                                  					; bit 4-7 = motor running bits 
  1014 00000735 66BAF203                	MOV	DX,03F2H		; FDC CTL PORT
  1015 00000739 EE                      	OUT	DX,AL			; TURN OFF THE MOTOR
  1016                                  T6:	
  1017                                  	;inc	word [CS:wait_count]	; 22/12/2014 (byte -> word)
  1018                                  					; TIMER TICK INTERRUPT
  1019                                  	;;inc	word [wait_count] ;;27/02/2015
  1020                                  	;INT	1CH			; TRANSFER CONTROL TO A USER ROUTINE
  1021                                  	;cli
  1022 0000073A E857040000              	call 	u_timer			; TRANSFER CONTROL TO A USER ROUTINE
  1023                                  	; 23/05/2016
  1024 0000073F E84EF20000              	call	clock			; Multi Tasking control procedure
  1025                                  T7:
  1026                                  	; 14/10/2015
  1027 00000744 B020                    	MOV	AL,EOI			; GET END OF INTERRUPT MASK
  1028 00000746 FA                      	CLI				; DISABLE INTERRUPTS TILL STACK CLEARED
  1029 00000747 E620                    	OUT	INTA00,AL		; END OF INTERRUPT TO 8259 - 1	
  1030                                  	;
  1031                                  rtc_int_2:
  1032                                  	; 26/12/2016
  1033                                  	;mov	ecx, [cr3reg]
  1034                                  	; 13/01/2017
  1035 00000749 803D[D4030300]00        	cmp	byte [u.t_lock], 0  	; T_LOCK
  1036 00000750 7730                    	ja	short timer_int_return  ; Timer Lock : 'sysrele' is needed !
  1037                                  	; 28/02/2017
  1038                                  	; We need to exit if the user's IRQ callback service is in progress!
  1039                                  	; (To prevent a conflict!)
  1040 00000752 803D[D8030300]00        	cmp	byte [u.r_lock], 0	; R_LOCK, IRQ callback service lock !
  1041 00000759 7727                    	ja	short timer_int_return  ; Timer Lock : 'sysrele' is needed !	
  1042                                  	; 15/01/2017
  1043 0000075B 803D[30650100]02        	cmp	byte [priority], 2
  1044 00000762 733A                    	jnb	short T8  ; current process has a timer event (15/01/2017)
  1045                                  	; 22/05/2016
  1046 00000764 803D[31650100]00        	cmp	byte [p_change], 0 ; in 'set_run_sequence', in 'rtc_p'
  1047 0000076B 7615                    	jna	short timer_int_return ; 23/05/2016
  1048                                  
  1049                                  	; 15/01/2017
  1050                                  	
  1051                                  	; present process must be changed with high priority process	
  1052                                  	;xor	al, al
  1053 0000076D 31C0                    	xor	eax, eax ; 26/12/2016
  1054 0000076F A2[31650100]            	mov	[p_change], al ; 0
  1055                                  	;mov	byte [priority], 2 ; 15/01/2017 (there is a timer event)
  1056                                  
  1057 00000774 803D[5B030300]FF        	cmp     byte [sysflg], 0FFh ; user or system space ?
  1058 0000077B 7416                    	je	short rtc_int_3     ; user space ([sysflg]= 0FFh)
  1059                                  
  1060                                  	; system space, wait for 'sysret'
  1061                                  	; to change running process 	
  1062                                  	; with high priority (event) process
  1063                                  
  1064 0000077D A2[A8030300]            	mov	[u.quant], al ; 0
  1065                                  
  1066                                  timer_int_return: ; 23/05/2016 - jump from 'rtc_int' ('rtc_int_2')
  1067 00000782 8B0D[5C040300]          	mov 	ecx, [cr3reg] 	; previous value/content of cr3 register
  1068 00000788 0F22D9                   	mov	cr3, ecx	; restore cr3 register content
  1069                                  	;
  1070 0000078B 61                      	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
  1071                                  	;
  1072 0000078C 0FA9                    	pop	gs
  1073 0000078E 0FA1                    	pop	fs
  1074 00000790 07                      	pop	es
  1075 00000791 1F                      	pop	ds
  1076                                  	;
  1077 00000792 CF                      	iretd	; return from interrupt
  1078                                  
  1079                                  rtc_int_3:
  1080 00000793 FE05[5B030300]          	inc	byte [sysflg] 	; now, we are in system space
  1081                                  	;
  1082 00000799 E9BBBF0000                      jmp     sysrelease ; change running process immediatelly 
  1083                                  
  1084                                  T8:
  1085                                  	; 13/01/2017 (eax -> ebx)
  1086                                  	; callback checking... (19/12/2016)
  1087 0000079E 31DB                    	xor	ebx, ebx
  1088 000007A0 871D[D0030300]          	xchg	ebx, [u.tcb] ; callback address (0 = normal return)
  1089 000007A6 09DB                    	or	ebx, ebx
  1090 000007A8 74D8                    	jz	short timer_int_return
  1091                                  
  1092                                  	; Set user's callback routine as return address from this interrupt
  1093                                  	; and set normal return address as return address from callback
  1094                                  	; routine!!! (19/12/2016)
  1095                                  	
  1096                                  	; 14/01/2017
  1097                                  	; 13/01/2017 - Timer Lock (T_LOCK)
  1098 000007AA FE05[D4030300]          	inc	byte [u.t_lock]
  1099 000007B0 8A0D[5B030300]          	mov	cl, [sysflg]
  1100 000007B6 880D[D5030300]          	mov	[u.t_mode], cl 
  1101                                  
  1102 000007BC 8B2D[44580100]          	mov	ebp, [tss.esp0] ; kernel stack address (for ring 0)
  1103 000007C2 83ED14                  	sub	ebp, 20		; eip, cs, eflags, esp, ss
  1104 000007C5 892D[5C030300]           	mov	[u.sp], ebp
  1105 000007CB 8925[60030300]          	mov	[u.usp], esp
  1106                                  
  1107                                  	;or	word [ebp+8], 200h ; 22/01/2017, force enabling interrupts
  1108                                  
  1109 000007D1 8B44241C                	mov	eax, [esp+28] ; pushed eax
  1110 000007D5 A3[64030300]            	mov	[u.r0], eax
  1111                                  
  1112 000007DA E8A9DE0000              	call	wswap ; save user's registers & status
  1113                                  
  1114                                  	; software int is in ring 0 but timer int must return to ring 3
  1115                                  	; so, ring 3 return address and stack registers
  1116                                  	; (eip, cs, eflags, esp, ss) 
  1117                                  	; must be copied to timer int return
  1118                                  	; eip will be replaced by callback service routine address
  1119                                  
  1120 000007DF C605[5B030300]FF        	mov	byte [sysflg], 0FFh ; user mode
  1121                                  
  1122                                  	; system mode (system call)
  1123                                  	;mov	ebp, [u.sp] ; EIP (u), CS (UCODE), EFLAGS (u),
  1124                                  			    ; ESP (u), SS (UDATA)
  1125                                  
  1126 000007E6 8B4510                  	mov	eax, [ebp+16]	; SS (UDATA
  1127 000007E9 89E6                    	mov	esi, esp
  1128 000007EB 50                      	push	eax
  1129 000007EC 50                      	push	eax
  1130 000007ED 89E7                    	mov	edi, esp
  1131 000007EF 893D[60030300]          	mov	[u.usp], edi
  1132 000007F5 B908000000              	mov	ecx, ((ESPACE/4) - 4) ; except DS, ES, FS, GS
  1133 000007FA F3A5                    	rep	movsd
  1134 000007FC B104                    	mov	cl, 4	
  1135 000007FE F3AB                    	rep	stosd
  1136 00000800 893D[5C030300]          	mov	[u.sp], edi
  1137 00000806 89EE                    	mov	esi, ebp
  1138 00000808 B105                    	mov	cl, 5 ; EIP (u), CS (UCODE), EFLAGS (u), ESP (u), SS (UDATA)
  1139 0000080A F3A5                    	rep	movsd
  1140                                  
  1141 0000080C 8B0D[B8030300]          	mov	ecx, [u.pgdir]
  1142 00000812 890D[5C040300]          	mov	[cr3reg], ecx
  1143                                  
  1144                                  	; 13/01/207 (eax -> ebx)
  1145                                  	; EBX = callback routine address (virtual, not physical address!)
  1146                                  
  1147                                  	; 09/01/2017
  1148                                  	; !!! CALLBACK ROUTINE MUST BE ENDED/RETURNED WITH 'sysrele'
  1149                                  	;     system call !!!	
  1150                                  	; 25/12/2016
  1151                                  	; Callback Note: (19/12/2016)
  1152                                  	; !!! CALLBACK ROUTINE MUST BE ENDED/RETURNED WITH 'RETN' !!!
  1153                                  	;	pushf ; save flags	
  1154                                  	; 	<callback service code>
  1155                                  	; 	popf  ; restore flags
  1156                                  	; 	retn ; return to normal running address
  1157                                  	;
  1158                                  
  1159                                  	; 15/01/2017
  1160                                  	; 14/01/2017
  1161                                  	; 13/01/2017 (eax -> ebx)
  1162                                  	; 10/01/2017
  1163                                  set_callback_addr:
  1164                                  	; 09/01/2017 (**)
  1165                                  	; 02/01/2017 (*)
  1166                                  	; 25/12/2016 (*)
  1167                                  	; 19/12/2016 (TRDOS 386 feature only!)
  1168                                  	;
  1169                                  	; This routine sets return address
  1170                                  	; to start of user's interrupt
  1171                                  	; service (callback) address
  1172                                  	;; and sets callback 'retn' address to normal
  1173                                  	;; return address of user's running code! 
  1174                                  	;
  1175                                  	; INPUT:
  1176                                  	;	EBX = callback routine/service address
  1177                                  	;	      (virtual, not physical address!)	
  1178                                  	;	[u.sp] = kernel stack, points to
  1179                                  	;		 user's EIP,CS,EFLAGS,ESP,SS
  1180                                  	;		 registers.
  1181                                  	; OUTPUT:
  1182                                  	;	EIP (user) = callback (service) address
  1183                                  	;	CS (user) = UCODE
  1184                                  	;	EFLAGS (user) = flags before callback 	 
  1185                                  	;       ESP (user) = ESP-4 (user, before callback) 
  1186                                  	;	[ESP](user) = EIP (user) before callback
  1187                                  	;
  1188                                  	; Note: If CPU was in user mode while entering 
  1189                                  	;	the timer interrupt service routine,
  1190                                  	;	'IRET' will get return to callback routine
  1191                                  	;	immediately. If CPU was in system/kernel mode  
  1192                                  	;	'iret' will get return to system call and
  1193                                  	;	then, callback routine will be return address
  1194                                  	;	from system call. (User's callback/service code
  1195                                  	;	will be able to return to normal return address
  1196                                  	;	via an 'retn' at the end.) 
  1197                                  	;
  1198                                  	; Note(**): User's callback service code must be ended
  1199                                  	;	with a 'sysrele' sytstem call ! (09/01/2017)
  1200                                  	;
  1201                                  	;	For example:
  1202                                  	;
  1203                                  	;	timer_callback:
  1204                                  	;	    ...	 
  1205                                    	;	    inc	dword [time_counter]
  1206                                  	;	    ...
  1207                                  	;	    mov eax, 39 ; 'sysrele'
  1208                                  	;	    int 40h ; TRDOS 386 system call (interrupt)		
  1209                                  	;
  1210                                  	;
  1211                                  	;; Note(*): User's callback service code must preserve cpu 
  1212                                  	;;	flags if it has any instructions which changes
  1213                                  	;;	flags in the service code. (25/12/2016)
  1214                                  	;;
  1215                                  	;;	For example:
  1216                                  	;;
  1217                                  	;;	timer_callback:
  1218                                  	;;	    pushf ; save flags
  1219                                  	;;	    ; this instruction changes zero flag
  1220                                    	;;	    inc	dword [time_counter]
  1221                                  	;;	    popf ; restore flags
  1222                                  	;;	    retn ; return to normal user code
  1223                                  	;;		  (which is interrupted by the 
  1224                                  	;;		   timer interput) 	
  1225                                  	;;
  1226                                  
  1227                                  	; 15/01/2017
  1228 00000818 8B2D[5C030300]          	mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
  1229 0000081E 895D00                  	mov	[ebp], ebx
  1230 00000821 E95CFFFFFF              	jmp	timer_int_return
  1231                                  
  1232                                  	; 15/01/2017
  1233                                  	; 13/01/2017
  1234                                  	; 19/12/2016
  1235                                  	; 06/06/2016
  1236                                  	; 23/05/2016
  1237                                  	; 22/05/2016
  1238                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1239                                  	; 26/02/2015
  1240                                  	; 07/09/2014
  1241                                  	; 25/08/2014
  1242                                  rtc_int:       ; Real Time Clock Interrupt (IRQ 8)
  1243                                  	; 22/05/2016
  1244 00000826 1E                      	push	ds ; ** ; 23/05/2016
  1245 00000827 50                      	push	eax ; *
  1246 00000828 66B81000                	mov	ax, KDATA
  1247 0000082C 8ED8                    	mov	ds, ax
  1248                                  	;
  1249 0000082E 8A25[26590100]          	mov	ah, [RTC_2Hz] ;  2 Hz interrupt to 1 Hz function
  1250 00000834 80F401                  	xor	ah, 1
  1251 00000837 8825[26590100]          	mov	[RTC_2Hz], ah ; 1 = 0.5 second, 0 = 1 second
  1252 0000083D 753B                    	jnz	short rtc_int_return ; half second
  1253                                  	; 1 second
  1254                                  rtc_int_0:
  1255                                  	; 22/05/2016
  1256 0000083F 58                      	pop	eax ; *
  1257                                  	;
  1258                                  	; 14/10/2015 ('timer_int')
  1259                                  	; Here, we are simulating system call entry (for task switch)
  1260                                  	; (If multitasking is enabled, 
  1261                                  	; 'clock' procedure may jump to 'sysrelease')
  1262                                  	;push	ds ; ** ; 23/05/2016
  1263 00000840 06                      	push	es
  1264 00000841 0FA0                    	push	fs
  1265 00000843 0FA8                    	push	gs
  1266 00000845 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  1267 00000846 66B91000                	mov     cx, KDATA
  1268                                          ;mov    ds, cx ; 06/06/2016
  1269 0000084A 8EC1                            mov     es, cx
  1270 0000084C 8EE1                            mov     fs, cx
  1271 0000084E 8EE9                            mov     gs, cx
  1272                                  	;
  1273 00000850 0F20D9                  	mov	ecx, cr3
  1274 00000853 890D[5C040300]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  1275                                  	;
  1276 00000859 803D[D4030300]00        	cmp	byte [u.t_lock], 0 ; timer lock (callback) status ?
  1277 00000860 7711                    	ja	short rtc_int_1	   ; yes
  1278                                  
  1279                                  	; 15/01/2017
  1280 00000862 3B0D[A8580100]          	cmp 	ecx, [k_page_dir]
  1281 00000868 7409                    	je	short rtc_int_1
  1282                                  
  1283 0000086A 8B0D[A8580100]          	mov	ecx, [k_page_dir]
  1284 00000870 0F22D9                  	mov	cr3, ecx
  1285                                  rtc_int_1:
  1286                                  	; Timer event (kernel) functions must be performed with
  1287                                  	; 1 second intervals - TRDOS 386 (TRDOS v2.0) feature ! -
  1288                                   	;	
  1289                                  	; 25/08/2014
  1290 00000873 E81A030000              	call	rtc_p  ; 19/05/2016 - major modification 
  1291                                  	
  1292                                  	; 23/05/2016
  1293 00000878 28E4                    	sub	ah, ah ; 0
  1294                                  	; 22/05/2016 - TRDOS 386 timer event modifications
  1295                                  rtc_int_return: ; 19/05/2016
  1296                                  	; 22/02/2015 - dsectpm.s
  1297                                  	; [ source: http://wiki.osdev.org/RTC ]
  1298                                  	; read status register C to complete procedure
  1299                                  	;(it is needed to get a next IRQ 8) 
  1300 0000087A B00C                    	mov	al, 0Ch ; 
  1301 0000087C E670                    	out	70h, al ; select register C
  1302 0000087E 90                      	nop
  1303 0000087F E471                    	in	al, 71h ; just throw away contents
  1304                                  	; 22/02/2015
  1305 00000881 B020                    	MOV	AL,EOI		; END OF INTERRUPT
  1306                                  	;CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  1307 00000883 E6A0                    	OUT	INTB00,AL	; FOR CONTROLLER #2
  1308                                  
  1309                                  	; 23/05/2016
  1310 00000885 B020                    	MOV	AL,EOI		; GET END OF INTERRUPT MASK
  1311 00000887 FA                      	CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  1312 00000888 E620                    	OUT	INTA00,AL	; END OF INTERRUPT TO 8259 - 1	
  1313                                  	;
  1314                                  	; 23/05/2016
  1315 0000088A 20E4                    	and	ah, ah
  1316 0000088C 0F84B7FEFFFF                    jz      rtc_int_2
  1317                                  	
  1318                                  	; ah = 1 (half second)
  1319 00000892 58                      	pop	eax ; *
  1320 00000893 1F                      	pop	ds  ; **
  1321 00000894 CF                      	iretd
  1322                                  
  1323                                  ; ////////////////
  1324                                  
  1325                                  	; 28/08/2014
  1326                                  irq0:
  1327 00000895 6A00                            push 	dword 0
  1328 00000897 EB48                    	jmp	short which_irq
  1329                                  irq1:
  1330 00000899 6A01                            push 	dword 1
  1331 0000089B EB44                    	jmp	short which_irq
  1332                                  irq2:
  1333 0000089D 6A02                            push 	dword 2
  1334 0000089F EB40                    	jmp	short which_irq
  1335                                  irq3:
  1336                                  	; 20/11/2015
  1337                                  	; 24/10/2015
  1338 000008A1 2EFF15[50FC0000]        	call	dword [cs:com2_irq3]
  1339 000008A8 6A03                    	push 	dword 3
  1340 000008AA EB35                    	jmp	short which_irq
  1341                                  irq4:
  1342                                  	; 20/11/2015
  1343                                  	; 24/10/2015
  1344 000008AC 2EFF15[4CFC0000]        	call	dword [cs:com1_irq4]
  1345 000008B3 6A04                            push 	dword 4
  1346 000008B5 EB2A                    	jmp	short which_irq
  1347                                  irq5:
  1348 000008B7 6A05                            push 	dword 5
  1349 000008B9 EB26                    	jmp	short which_irq
  1350                                  irq6:
  1351 000008BB 6A06                            push 	dword 6
  1352 000008BD EB22                    	jmp	short which_irq
  1353                                  irq7:
  1354 000008BF 6A07                            push 	dword 7
  1355 000008C1 EB1E                    	jmp	short which_irq
  1356                                  irq8:
  1357 000008C3 6A08                            push 	dword 8
  1358 000008C5 EB1A                    	jmp	short which_irq
  1359                                  irq9:
  1360 000008C7 6A09                            push 	dword 9
  1361 000008C9 EB16                    	jmp	short which_irq
  1362                                  irq10:
  1363 000008CB 6A0A                            push 	dword 10
  1364 000008CD EB12                    	jmp	short which_irq
  1365                                  irq11:
  1366 000008CF 6A0B                            push 	dword 11
  1367 000008D1 EB0E                    	jmp	short which_irq
  1368                                  irq12:
  1369 000008D3 6A0C                            push 	dword 12
  1370 000008D5 EB0A                    	jmp	short which_irq
  1371                                  irq13:
  1372 000008D7 6A0D                            push 	dword 13
  1373 000008D9 EB06                    	jmp	short which_irq
  1374                                  irq14:
  1375 000008DB 6A0E                            push 	dword 14
  1376 000008DD EB02                    	jmp	short which_irq
  1377                                  irq15:
  1378 000008DF 6A0F                            push 	dword 15
  1379                                  	;jmp	short which_irq
  1380                                  
  1381                                  	; 22/01/2017
  1382                                  	; 19/10/2015
  1383                                  	; 29/08/2014
  1384                                  	; 21/08/2014
  1385                                  which_irq:
  1386 000008E1 870424                  	xchg	eax, [esp]  ; 28/08/2014
  1387 000008E4 53                      	push	ebx
  1388 000008E5 56                      	push	esi
  1389 000008E6 57                      	push	edi
  1390 000008E7 1E                      	push 	ds
  1391 000008E8 06                      	push 	es
  1392                                  	;
  1393 000008E9 88C3                    	mov	bl, al
  1394                                  	;
  1395 000008EB B810000000              	mov	eax, KDATA
  1396 000008F0 8ED8                    	mov	ds, ax
  1397 000008F2 8EC0                    	mov	es, ax
  1398                                  	; 19/10/2015
  1399 000008F4 FC                      	cld
  1400                                          ; 27/08/2014
  1401 000008F5 8105[B0160100]A000-             add     dword [scr_row], 0A0h
  1401 000008FD 0000               
  1402                                  	;
  1403 000008FF B417                    	mov	ah, 17h	; blue (1) background, 
  1404                                  			; light gray (7) forecolor
  1405 00000901 8B3D[B0160100]                  mov     edi, [scr_row]
  1406 00000907 B049                    	mov	al, 'I'
  1407 00000909 66AB                    	stosw
  1408 0000090B B052                    	mov	al, 'R'
  1409 0000090D 66AB                    	stosw
  1410 0000090F B051                    	mov	al, 'Q'
  1411 00000911 66AB                    	stosw
  1412 00000913 B020                    	mov	al, ' '
  1413 00000915 66AB                    	stosw
  1414 00000917 88D8                    	mov	al, bl
  1415 00000919 3C0A                    	cmp	al, 10
  1416 0000091B 7208                    	jb	short ii1
  1417 0000091D B031                    	mov	al, '1'
  1418 0000091F 66AB                    	stosw
  1419 00000921 88D8                    	mov	al, bl
  1420 00000923 2C0A                    	sub	al, 10
  1421                                  ii1:
  1422 00000925 0430                    	add	al, '0'
  1423 00000927 66AB                    	stosw
  1424 00000929 B020                    	mov	al, ' '
  1425 0000092B 66AB                    	stosw
  1426 0000092D B021                    	mov	al, '!'
  1427 0000092F 66AB                    	stosw
  1428 00000931 B020                    	mov	al, ' '
  1429 00000933 66AB                    	stosw
  1430                                  	; 23/02/2015
  1431 00000935 80FB07                  	cmp	bl, 7 ; check for IRQ 8 to IRQ 15 
  1432 00000938 7604                    	jna	ii2
  1433                                  	; 22/01/2017
  1434 0000093A B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1435 0000093C E6A0                    	out	0A0h, al ; the 2nd 8259
  1436                                  ii2:
  1437 0000093E B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1438 00000940 E620                    	out	20h, al ; the 2nd 8259
  1439 00000942 E9CD010000              	jmp     iiret
  1440                                  	;
  1441                                  	; 22/08/2014
  1442                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1443                                  	;out	20h, al	; 8259 PORT
  1444                                  	;
  1445                                  	;pop	es
  1446                                  	;pop	ds
  1447                                  	;pop	edi
  1448                                  	;pop	esi
  1449                                  	;pop	ebx
  1450                                  	;pop 	eax
  1451                                  	;iret
  1452                                  
  1453                                  	; 02/04/2015
  1454                                  	; 25/08/2014
  1455                                  exc0:
  1456 00000947 6A00                            push 	dword 0
  1457 00000949 E990000000                      jmp     cpu_except
  1458                                  exc1:
  1459 0000094E 6A01                            push 	dword 1
  1460 00000950 E989000000                      jmp     cpu_except
  1461                                  exc2:
  1462 00000955 6A02                            push 	dword 2
  1463 00000957 E982000000                      jmp     cpu_except
  1464                                  exc3:
  1465 0000095C 6A03                            push 	dword 3
  1466 0000095E EB7E                            jmp     cpu_except
  1467                                  exc4:
  1468 00000960 6A04                            push 	dword 4
  1469 00000962 EB7A                            jmp     cpu_except
  1470                                  exc5:
  1471 00000964 6A05                            push 	dword 5
  1472 00000966 EB76                            jmp     cpu_except
  1473                                  exc6:
  1474 00000968 6A06                            push 	dword 6
  1475 0000096A EB72                            jmp     cpu_except
  1476                                  exc7:
  1477 0000096C 6A07                            push 	dword 7
  1478 0000096E EB6E                            jmp     cpu_except
  1479                                  exc8:
  1480                                  	; [esp] = Error code
  1481 00000970 6A08                            push 	dword 8
  1482 00000972 EB5C                            jmp     cpu_except_en
  1483                                  exc9:
  1484 00000974 6A09                            push 	dword 9
  1485 00000976 EB66                            jmp     cpu_except
  1486                                  exc10:
  1487                                  	; [esp] = Error code
  1488 00000978 6A0A                            push 	dword 10
  1489 0000097A EB54                            jmp     cpu_except_en
  1490                                  exc11:
  1491                                  	; [esp] = Error code
  1492 0000097C 6A0B                            push 	dword 11
  1493 0000097E EB50                            jmp     cpu_except_en
  1494                                  exc12:
  1495                                  	; [esp] = Error code
  1496 00000980 6A0C                            push 	dword 12
  1497 00000982 EB4C                            jmp     cpu_except_en
  1498                                  exc13:
  1499                                  	; [esp] = Error code
  1500 00000984 6A0D                            push 	dword 13
  1501 00000986 EB48                            jmp     cpu_except_en
  1502                                  exc14:
  1503                                  	; [esp] = Error code
  1504 00000988 6A0E                            push 	dword 14
  1505 0000098A EB44                    	jmp	short cpu_except_en
  1506                                  exc15:
  1507 0000098C 6A0F                            push 	dword 15
  1508 0000098E EB4E                            jmp     cpu_except
  1509                                  exc16:
  1510 00000990 6A10                            push 	dword 16
  1511 00000992 EB4A                            jmp     cpu_except
  1512                                  exc17:
  1513                                  	; [esp] = Error code
  1514 00000994 6A11                            push 	dword 17
  1515 00000996 EB38                    	jmp	short cpu_except_en
  1516                                  exc18:
  1517 00000998 6A12                            push 	dword 18
  1518 0000099A EB42                    	jmp	short cpu_except
  1519                                  exc19:
  1520 0000099C 6A13                            push 	dword 19
  1521 0000099E EB3E                    	jmp	short cpu_except
  1522                                  exc20:
  1523 000009A0 6A14                            push 	dword 20
  1524 000009A2 EB3A                    	jmp	short cpu_except
  1525                                  exc21:
  1526 000009A4 6A15                            push 	dword 21
  1527 000009A6 EB36                    	jmp	short cpu_except
  1528                                  exc22:
  1529 000009A8 6A16                            push 	dword 22
  1530 000009AA EB32                    	jmp	short cpu_except
  1531                                  exc23:
  1532 000009AC 6A17                            push 	dword 23
  1533 000009AE EB2E                    	jmp	short cpu_except
  1534                                  exc24:
  1535 000009B0 6A18                            push 	dword 24
  1536 000009B2 EB2A                    	jmp	short cpu_except
  1537                                  exc25:
  1538 000009B4 6A19                            push 	dword 25
  1539 000009B6 EB26                    	jmp	short cpu_except
  1540                                  exc26:
  1541 000009B8 6A1A                            push 	dword 26
  1542 000009BA EB22                    	jmp	short cpu_except
  1543                                  exc27:
  1544 000009BC 6A1B                            push 	dword 27
  1545 000009BE EB1E                    	jmp	short cpu_except
  1546                                  exc28:
  1547 000009C0 6A1C                            push 	dword 28
  1548 000009C2 EB1A                    	jmp	short cpu_except
  1549                                  exc29:
  1550 000009C4 6A1D                            push 	dword 29
  1551 000009C6 EB16                    	jmp	short cpu_except
  1552                                  exc30:
  1553 000009C8 6A1E                            push 	dword 30
  1554 000009CA EB04                    	jmp	short cpu_except_en
  1555                                  exc31:
  1556 000009CC 6A1F                            push 	dword 31
  1557 000009CE EB0E                            jmp     short cpu_except
  1558                                  
  1559                                  	; 19/10/2015
  1560                                  	; 19/09/2015
  1561                                  	; 01/09/2015
  1562                                  	; 28/08/2015
  1563                                  	; 28/08/2014
  1564                                  cpu_except_en:
  1565 000009D0 87442404                	xchg	eax, [esp+4] ; Error code
  1566 000009D4 36A3[78050300]          	mov	[ss:error_code], eax
  1567 000009DA 58                      	pop	eax  ; Exception number
  1568 000009DB 870424                  	xchg	eax, [esp]
  1569                                  		; eax = eax before exception
  1570                                  		; [esp] -> exception number
  1571                                  		; [esp+4] -> EIP to return
  1572                                  	; 22/01/2017
  1573                                  	; 19/10/2015
  1574                                  	; 19/09/2015
  1575                                  	; 01/09/2015
  1576                                  	; 28/08/2015
  1577                                  	; 29/08/2014
  1578                                  	; 28/08/2014
  1579                                  	; 25/08/2014
  1580                                  	; 21/08/2014
  1581                                  cpu_except:	; CPU Exceptions
  1582 000009DE FC                      	cld
  1583 000009DF 870424                  	xchg	eax, [esp] 
  1584                                  		; eax = Exception number
  1585                                  		; [esp] = eax (before exception)	
  1586 000009E2 53                      	push	ebx
  1587 000009E3 56                      	push	esi
  1588 000009E4 57                      	push	edi
  1589 000009E5 1E                      	push 	ds
  1590 000009E6 06                      	push 	es
  1591                                  	; 28/08/2015
  1592 000009E7 66BB1000                	mov	bx, KDATA
  1593 000009EB 8EDB                    	mov	ds, bx
  1594 000009ED 8EC3                    	mov	es, bx
  1595 000009EF 0F20DB                  	mov	ebx, cr3
  1596 000009F2 53                      	push	ebx ; (*) page directory
  1597                                  	; 19/10/2015
  1598 000009F3 FC                      	cld
  1599                                  	; 25/03/2015
  1600 000009F4 8B1D[A8580100]          	mov	ebx, [k_page_dir]
  1601 000009FA 0F22DB                  	mov	cr3, ebx
  1602                                  	; 28/08/2015
  1603 000009FD 83F80E                  	cmp	eax, 0Eh ; 14, PAGE FAULT	
  1604 00000A00 750F                    	jne	short cpu_except_nfp
  1605 00000A02 E87D440000              	call	page_fault_handler
  1606 00000A07 21C0                    	and 	eax, eax
  1607 00000A09 0F8401010000                    jz	iiretp ; 01/09/2015
  1608 00000A0F B00E                    	mov	al, 0Eh ; 14
  1609                                  cpu_except_nfp:
  1610                                  	; 23/08/2016
  1611 00000A11 803D[F25E0000]03        	cmp	byte [CRT_MODE], 3
  1612 00000A18 7409                    	je	short cpu_except_mode_3
  1613 00000A1A 50                      	push	eax
  1614 00000A1B B003                    	mov	al, 3
  1615 00000A1D E8730B0000              	call	_set_mode
  1616 00000A22 58                      	pop	eax
  1617                                  cpu_except_mode_3:
  1618                                  	; 02/04/2015
  1619 00000A23 BB[72060000]            	mov	ebx, hang
  1620 00000A28 875C241C                	xchg	ebx, [esp+28]
  1621                                  		; EIP (points to instruction which faults)
  1622                                  	  	; New EIP (hang)
  1623 00000A2C 891D[7C050300]          	mov	[FaultOffset], ebx
  1624 00000A32 C744242008000000        	mov	dword [esp+32], KCODE ; kernel's code segment
  1625 00000A3A 814C242400020000        	or	dword [esp+36], 200h ; enable interrupts (set IF)
  1626                                  	;
  1627 00000A42 88C4                    	mov	ah, al
  1628 00000A44 240F                    	and	al, 0Fh
  1629 00000A46 3C09                    	cmp	al, 9
  1630 00000A48 7602                    	jna	short h1ok
  1631 00000A4A 0407                    	add	al, 'A'-':'
  1632                                  h1ok:
  1633 00000A4C C0EC04                  	shr	ah, 4
  1634 00000A4F 80FC09                  	cmp	ah, 9
  1635 00000A52 7603                    	jna	short h2ok
  1636 00000A54 80C407                  	add	ah, 'A'-':'
  1637                                  h2ok:	
  1638 00000A57 86E0                    	xchg 	ah, al	
  1639 00000A59 66053030                	add	ax, '00'
  1640 00000A5D 66A3[08190100]          	mov	[excnstr], ax
  1641                                  	;
  1642                                  	; 29/08/2014
  1643 00000A63 A1[7C050300]            	mov	eax, [FaultOffset]
  1644 00000A68 51                      	push	ecx
  1645 00000A69 52                      	push	edx
  1646 00000A6A 89E3                    	mov	ebx, esp
  1647                                  	; 28/08/2015
  1648 00000A6C B910000000              	mov	ecx, 16	  ; divisor value to convert binary number
  1649                                  			  ; to hexadecimal string
  1650                                  	;mov	ecx, 10	    ; divisor to convert	
  1651                                  			    ; binary number to decimal string
  1652                                  b2d1:
  1653 00000A71 31D2                    	xor	edx, edx
  1654 00000A73 F7F1                    	div	ecx
  1655 00000A75 6652                    	push	dx
  1656 00000A77 39C8                    	cmp	eax, ecx
  1657 00000A79 73F6                    	jnb	short b2d1
  1658 00000A7B BF[13190100]            	mov	edi, EIPstr ; EIP value
  1659                                  			    ; points to instruction which faults	
  1660                                  	; 28/08/2015
  1661 00000A80 89C2                    	mov	edx, eax
  1662                                  b2d2:
  1663                                  	;add	al, '0'
  1664 00000A82 8A82[4B330000]          	mov	al, [edx+hexchrs]
  1665 00000A88 AA                      	stosb		    ; write hexadecimal digit to its place	
  1666 00000A89 39E3                    	cmp	ebx, esp
  1667 00000A8B 7606                    	jna	short b2d3
  1668 00000A8D 6658                    	pop	ax
  1669 00000A8F 88C2                    	mov	dl, al
  1670 00000A91 EBEF                    	jmp	short b2d2
  1671                                  b2d3:
  1672 00000A93 B068                    	mov 	al, 'h' ; 28/08/2015
  1673 00000A95 AA                      	stosb
  1674 00000A96 B020                    	mov	al, 20h	    ; space
  1675 00000A98 AA                      	stosb
  1676 00000A99 30C0                    	xor	al, al	    ; to do it an ASCIIZ string	
  1677 00000A9B AA                      	stosb
  1678                                  	;
  1679 00000A9C 5A                      	pop	edx
  1680 00000A9D 59                      	pop	ecx
  1681                                  	;
  1682 00000A9E B44F                    	mov	ah, 4Fh	; red (4) background, 
  1683                                  			; white (F) forecolor
  1684 00000AA0 BE[F8180100]            	mov	esi, exc_msg ; message offset
  1685                                  	;
  1686                                  	; 20/01/2017 (!cpu exception!)
  1687                                  	;
  1688 00000AA5 8105[B0160100]A000-             add    dword [scr_row], 0A0h
  1688 00000AAD 0000               
  1689 00000AAF 8B3D[B0160100]                  mov    edi, [scr_row]
  1690                                  	;	
  1691 00000AB5 C605[5B030300]00        	mov	byte [sysflg], 0  ; system mode
  1692 00000ABC FB                              sti
  1693                                  	;
  1694 00000ABD E8EFFBFFFF              	call 	printk
  1695                                  	;
  1696 00000AC2 B410                    	mov	ah, 10h
  1697 00000AC4 E87D010000              	call	int16h ; getc
  1698                                  	;
  1699 00000AC9 B003                    	mov	al, 3
  1700 00000ACB E8C50A0000              	call	_set_mode
  1701                                  	;
  1702 00000AD0 B801000000              	mov	eax, 1
  1703 00000AD5 E9E6BD0000              	jmp	sysexit ; terminate process !!!
  1704                                  	
  1705                                  	; 22/01/2017
  1706                                  	; 18/04/2016
  1707                                  	; 28/08/2015
  1708                                  	; 23/02/2015
  1709                                  	; 20/08/2014
  1710                                  ignore_int:
  1711 00000ADA 50                      	push	eax
  1712 00000ADB 53                      	push	ebx ; 23/02/2015
  1713 00000ADC 56                      	push	esi
  1714 00000ADD 57                      	push	edi
  1715 00000ADE 1E                      	push 	ds
  1716 00000ADF 06                      	push 	es
  1717                                  	; 18/04/2016
  1718 00000AE0 66B81000                	mov	ax, KDATA
  1719 00000AE4 8ED8                    	mov	ds, ax
  1720 00000AE6 8EC0                    	mov	es, ax
  1721                                  	; 28/08/2015
  1722 00000AE8 0F20D8                  	mov	eax, cr3
  1723 00000AEB 50                      	push	eax ; (*) page directory
  1724                                  	;
  1725 00000AEC B467                    	mov	ah, 67h	; brown (6) background, 
  1726                                  			; light gray (7) forecolor
  1727 00000AEE BE[C0170100]            	mov	esi, int_msg ; message offset
  1728                                  piemsg:
  1729                                          ; 27/08/2014
  1730 00000AF3 8105[B0160100]A000-             add     dword [scr_row], 0A0h
  1730 00000AFB 0000               
  1731 00000AFD 8B3D[B0160100]                  mov     edi, [scr_row]
  1732                                          ;
  1733 00000B03 E8A9FBFFFF              	call 	printk
  1734                                  	;
  1735                                  	; 23/02/2015
  1736 00000B08 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1737 00000B0A E6A0                    	out	0A0h, al ; the 2nd 8259
  1738                                  	; 22/08/2014
  1739 00000B0C B020                    	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1740 00000B0E E620                    	out	20h, al	; 8259 PORT
  1741                                  iiretp: 
  1742                                  	; 22/01/2017
  1743                                  	; 01/09/2015
  1744                                  	; 28/08/2015
  1745 00000B10 58                      	pop	eax ; (*) page directory
  1746 00000B11 0F22D8                  	mov	cr3, eax
  1747                                  iiret:
  1748 00000B14 07                      	pop	es
  1749 00000B15 1F                      	pop	ds
  1750 00000B16 5F                      	pop	edi
  1751 00000B17 5E                      	pop	esi
  1752 00000B18 5B                      	pop	ebx ; 29/08/2014
  1753 00000B19 58                      	pop 	eax
  1754 00000B1A CF                      	iretd
  1755                                  
  1756                                  	; 23/05/2016
  1757                                  	; 22/08/2014
  1758                                  	; IBM PC/AT BIOS source code ----- 10/06/85 (bios.asm)
  1759                                  	; (INT 1Ah)
  1760                                  	;; Linux (v0.12) source code (main.c) by Linus Torvalds (1991)
  1761                                  time_of_day:
  1762 00000B1B E8F0500000              	call	UPD_IPR			; WAIT TILL UPDATE NOT IN PROGRESS
  1763 00000B20 726F                            jc      short time_of_day_retn ; 23/05/2016
  1764 00000B22 B000                    	mov	al, CMOS_SECONDS
  1765 00000B24 E802510000              	call	CMOS_READ
  1766 00000B29 A2[18590100]            	mov	[time_seconds], al 
  1767 00000B2E B002                    	mov	al, CMOS_MINUTES
  1768 00000B30 E8F6500000              	call	CMOS_READ
  1769 00000B35 A2[19590100]            	mov	[time_minutes], al 
  1770 00000B3A B004                    	mov	al, CMOS_HOURS
  1771 00000B3C E8EA500000              	call	CMOS_READ
  1772 00000B41 A2[1A590100]                    mov     [time_hours], al
  1773 00000B46 B006                    	mov	al, CMOS_DAY_WEEK 
  1774 00000B48 E8DE500000              	call	CMOS_READ
  1775 00000B4D A2[1B590100]            	mov	[date_wday], al
  1776 00000B52 B007                     	mov	al, CMOS_DAY_MONTH
  1777 00000B54 E8D2500000              	call	CMOS_READ
  1778 00000B59 A2[1C590100]            	mov	[date_day], al
  1779 00000B5E B008                    	mov	al, CMOS_MONTH
  1780 00000B60 E8C6500000              	call	CMOS_READ
  1781 00000B65 A2[1D590100]            	mov	[date_month], al
  1782 00000B6A B009                    	mov	al, CMOS_YEAR
  1783 00000B6C E8BA500000              	call	CMOS_READ
  1784 00000B71 A2[1E590100]            	mov	[date_year], al
  1785 00000B76 B032                    	mov	al, CMOS_CENTURY
  1786 00000B78 E8AE500000              	call	CMOS_READ
  1787 00000B7D A2[1F590100]            	mov	[date_century], al
  1788                                  	;
  1789 00000B82 B000                    	mov	al, CMOS_SECONDS
  1790 00000B84 E8A2500000              	call 	CMOS_READ
  1791 00000B89 3A05[18590100]          	cmp	al, [time_seconds]
  1792 00000B8F 758A                    	jne	short time_of_day
  1793                                  
  1794                                  time_of_day_retn:
  1795 00000B91 C3                      	retn
  1796                                  
  1797                                  	; 15/01/2017
  1798                                  	; 10/06/2016
  1799                                  	; 07/06/2016
  1800                                  	; 06/06/2016
  1801                                  	; 23/05/2016
  1802                                  rtc_p:
  1803 00000B92 B101                    	mov	cl, 1 ; 15/01/2017
  1804 00000B94 EB02                    	jmp	short rtc_p0
  1805                                  u_timer: 
  1806                                  	; Timer Events with 18.2 Hz Timer Ticks
  1807                                  	; (and also timer events with RTC seconds)
  1808 00000B96 28C9                    	sub	cl, cl ; mov cl, 0 ; 15/01/2017
  1809                                  rtc_p0:
  1810                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1811                                  	; Major Modification:
  1812                                  	; Check and Perform Timer Events (for RTC)
  1813                                  	; 25/08/2014 - 07/09/2014
  1814                                  	; Retro UNIX 386 v1:
  1815                                   	; Print Real Time Clock content
  1816                                  	
  1817                                  	; 15/01/2017
  1818 00000B98 880D[30650100]          	mov	byte [priority], cl ; 0 or 1 (not 2)
  1819 00000B9E 8A2D[33650100]          	mov	ch, [timer_events]
  1820 00000BA4 20ED                    	and	ch, ch
  1821 00000BA6 7420                    	jz	short rtc_p3
  1822                                  
  1823 00000BA8 BE[60040300]            	mov	esi, timer_set  ; beginning address of
  1824                                  				; timer events space
  1825                                  rtc_p1:
  1826 00000BAD 8B06                    	mov	eax, [esi]	
  1827 00000BAF 20C0                    	and	al, al ; 0 = free, >0 = process no.
  1828 00000BB1 7416                    	jz	short rtc_p4
  1829                                  	;
  1830 00000BB3 C1C810                  	ror	eax, 16
  1831                                  	; ah = response value, al = interrupt type
  1832                                  	; 15/01/2017
  1833                                  	; cl = interrupt source
  1834                                  	;       1 = RTC, 0 = PIT  	 	
  1835 00000BB6 38C8                    	cmp	al, cl 
  1836 00000BB8 750A                    	jne	short rtc_p2 ; not as requested or undefined !
  1837 00000BBA 3C01                    	cmp	al, 1 ; 1 ; RTC interrupt ?
  1838 00000BBC 7410                    	je	short rtc_p5 ; yes, check for response
  1839                                  	; 06/06/2016 - 18.2 Hz Timer Ticks
  1840 00000BBE 836E080A                	sub	dword [esi+8], 10 ; 1 tick = 10
  1841 00000BC2 7613                    	jna	short rtc_p6  ; continue for responding
  1842                                  rtc_p2:
  1843                                  	; 15/01/2017 (cl -> ch)
  1844                                  	; 07/06/2016
  1845 00000BC4 FECD                    	dec	ch    ; remain count of timer events	
  1846 00000BC6 7501                    	jnz	short rtc_p4
  1847                                  rtc_p3:	 
  1848 00000BC8 C3                      	retn
  1849                                  rtc_p4:	
  1850                                  	;cmp	esi, timer_set + 240 ; 15*16 (last event)
  1851                                  	;jnb	short rtc_p3 ; end of timer event space
  1852 00000BC9 83C610                  	add	esi, 16 ; next timer event
  1853 00000BCC EBDF                    	jmp	short rtc_p1
  1854                                  rtc_p5:	 
  1855                                  	; current timer count ; 06/06/2016 (182)
  1856 00000BCE 816E08B6000000          	sub	dword [esi+8], 182 ; 1 second (10*18.2)
  1857 00000BD5 77ED                    	ja	short rtc_p2  ; check for the next 
  1858                                  rtc_p6:	
  1859                                  	; it is the time of response! 
  1860 00000BD7 8B5E04                  	mov	ebx, [esi+4] ; set (count limit) value
  1861 00000BDA 895E08                  	mov	[esi+8], ebx ; reset count down value
  1862                                  			     ; to count limit
  1863                                  	; 19/12/2016
  1864                                  	; 10/12/2016 - timer callback modification
  1865 00000BDD 8B7E0C                  	mov	edi, [esi+12] ; response (or callback) address	
  1866 00000BE0 807E0100                	cmp	byte [esi+1], 0 ; >0 = callback
  1867 00000BE4 762A                    	jna	short rtc_p8
  1868                                  
  1869                                  	; timer callback !
  1870 00000BE6 0FB61E                  	movzx	ebx, byte [esi] ; process number (>0)
  1871 00000BE9 89D8                    	mov	eax, ebx
  1872 00000BEB C0E302                  	shl	bl, 2 ; *4
  1873 00000BEE 89BB[0C010300]          	mov	[ebx+p.tcb-4], edi ; user's callback service addr
  1874 00000BF4 3A05[B3030300]          	cmp	al, [u.uno]
  1875 00000BFA 7521                    	jne	short rtc_p9
  1876 00000BFC 893D[D0030300]          	mov	[u.tcb], edi
  1877                                  rtc_p7:
  1878                                  	; 15/01/2017
  1879 00000C02 B002                    	mov	al, 2
  1880 00000C04 A2[30650100]            	mov	[priority], al ; 2
  1881                                  	; 10/01/2017
  1882                                  	;mov	byte [u.pri], 2
  1883 00000C09 A2[A9030300]            	mov	[u.pri], al ; 2
  1884 00000C0E EBB4                    	jmp	short rtc_p2
  1885                                  rtc_p8:
  1886                                  	; response address is physical address of
  1887                                  	; the program's response (signal return) byte
  1888                                  	; 06/06/2016
  1889                                  	;mov	edi, [esi+12] ; response address
  1890 00000C10 8827                    	mov	[edi], ah     ; response value 
  1891                                  	;
  1892 00000C12 C1C010                  	rol	eax, 16
  1893                                  	; 15/01/2017
  1894 00000C15 3A05[B3030300]          	cmp	al, [u.uno] ; running process ?
  1895 00000C1B 74E5                    	je	short rtc_p7
  1896                                  rtc_p9:
  1897                                  	; al = process number  ; 10/06/2016
  1898 00000C1D B202                    	mov	dl, 2 ; priority, 2 = event (high)	
  1899 00000C1F E822ED0000              	call	set_run_sequence ; 19/05/2016
  1900 00000C24 EB9E                    	jmp	short rtc_p2 ; 10/06/2016
  1901                                  
  1902                                  
  1903                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  1904                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  1905                                  default_irq7:
  1906 00000C26 6650                    	push	ax
  1907 00000C28 B00B                    	mov	al, 0Bh  ; In-Service register
  1908 00000C2A E620                    	out	20h, al
  1909 00000C2C EB00                            jmp short $+2
  1910 00000C2E EB00                    	jmp short $+2
  1911 00000C30 E420                    	in	al, 20h
  1912 00000C32 2480                    	and 	al, 80h ; bit 7 (is it real IRQ 7 or fake?)
  1913 00000C34 7404                            jz      short irq7_iret ; Fake (spurious) IRQ, do not send EOI 
  1914 00000C36 B020                            mov     al, 20h ; EOI
  1915 00000C38 E620                    	out	20h, al 
  1916                                  irq7_iret:
  1917 00000C3A 6658                    	pop	ax
  1918 00000C3C CF                      	iretd
  1919                                  	
  1920                                  bcd_to_ascii:
  1921                                  	; 25/08/2014
  1922                                  	; INPUT ->
  1923                                  	;	al = Packed BCD number
  1924                                  	; OUTPUT ->
  1925                                  	;	ax  = ASCII word/number
  1926                                  	;
  1927                                  	; Erdogan Tan - 1998 (proc_hex) - TRDOS.ASM (2004-2011)
  1928                                  	;
  1929 00000C3D D410                    	db 0D4h,10h                     ; Undocumented inst. AAM
  1930                                  					; AH = AL / 10h
  1931                                  					; AL = AL MOD 10h
  1932 00000C3F 660D3030                	or ax,'00'                      ; Make it ASCII based
  1933                                  
  1934 00000C43 86E0                            xchg ah, al 
  1935                                  	
  1936 00000C45 C3                      	retn	
  1937                                  	
  1938                                  
  1939                                  %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: 15/01/2017
     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 00000C46 9C                  <1> 	pushfd	; 28/08/2014
    40 00000C47 0E                  <1> 	push 	cs
    41 00000C48 E801000000          <1> 	call 	KEYBOARD_IO_1 ; getc_int
    42 00000C4D 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> ; 15/01/2017
   136                              <1> ; 14/01/2017
   137                              <1> ; 02/01/2017
   138                              <1> ; 29/05/2016
   139                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   140                              <1> int32h:  ; Keyboard BIOS
   141                              <1> 
   142                              <1> KEYBOARD_IO_1:	
   143                              <1> 	;sti				; INTERRUPTS BACK ON
   144                              <1> 	; 29/05/2016
   145 00000C4E 80642408BE          <1>         and     byte [esp+8], 10111110b ; clear zero flag and cary flag
   146                              <1> 	;
   147 00000C53 1E                  <1> 	push	ds			; SAVE CURRENT DS
   148 00000C54 53                  <1> 	push	ebx			; SAVE BX TEMPORARILY
   149                              <1> 	;push	ecx			; SAVE CX TEMPORARILY
   150 00000C55 66BB1000            <1>         mov     bx, KDATA 
   151 00000C59 8EDB                <1> 	mov	ds, bx			; PUT SEGMENT VALUE OF DATA AREA INTO DS
   152                              <1> 
   153                              <1> 	; 14/01/2017
   154 00000C5B 8B1C24              <1> 	mov	ebx, [esp]
   155                              <1> 	;; 15/01/2017
   156                              <1> 	; 02/01/2017
   157                              <1> 	;;mov	byte [intflg], 32h	; keyboard interrupt 
   158 00000C5E FB                  <1> 	sti
   159                              <1> 	;
   160                              <1> 
   161 00000C5F 08E4                <1> 	or	ah, ah			; CHECK FOR (AH)= 00H
   162 00000C61 743A                <1> 	jz	short _K1		; ASCII_READ
   163 00000C63 FECC                <1> 	dec	ah                      ; CHECK FOR (AH)= 01H
   164 00000C65 7453                <1>         jz      short _K2               ; ASCII_STATUS
   165 00000C67 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 02H
   166 00000C69 0F8494000000        <1>         jz      _K3                     ; SHIFT STATUS
   167 00000C6F FECC                <1> 	dec	ah			; CHECK FOR (AH)= 03H	
   168 00000C71 0F8493000000        <1>         jz      _K300                   ; SET TYPAMATIC RATE/DELAY
   169 00000C77 80EC02              <1> 	sub	ah, 2			; CHECK FOR (AH)= 05H	
   170 00000C7A 0F84BC000000        <1>         jz      _K500                   ; KEYBOARD WRITE         
   171                              <1> _KIO1:	
   172 00000C80 80EC0B              <1> 	sub	ah, 11			; AH =  10H
   173 00000C83 740C                <1> 	jz	short _K1E		; EXTENDED ASCII READ
   174 00000C85 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 11H
   175 00000C87 7422                <1> 	jz	short _K2E		; EXTENDED_ASCII_STATUS
   176 00000C89 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 12H
   177 00000C8B 7458                <1> 	jz	short _K3E		; EXTENDED_SHIFT_STATUS
   178                              <1> _KIO_EXIT:
   179                              <1> 	; 02/01/2017
   180 00000C8D FA                  <1> 	cli
   181                              <1> 	;;mov	byte [intflg], 0 ;; 15/01/2017
   182                              <1> 	;
   183                              <1> 	;pop	ecx			; RECOVER REGISTER
   184 00000C8E 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   185 00000C8F 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   186 00000C90 CF                  <1> 	iretd				; INVALID COMMAND, EXIT
   187                              <1> 
   188                              <1> 	;-----	ASCII CHARACTER
   189                              <1> _K1E:	
   190 00000C91 E8D3000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER (EXTENDED)
   191 00000C96 E848010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   192 00000C9B EBF0                <1> 	jmp	short _KIO_EXIT         ; GIVE IT TO THE CALLER
   193                              <1> _K1:	
   194 00000C9D E8C7000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER
   195 00000CA2 E847010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   196 00000CA7 72F4                <1> 	jc	short _K1		; CARRY SET MEANS TROW CODE AWAY
   197                              <1> _K1A:
   198 00000CA9 EBE2                <1> 	jmp	short _KIO_EXIT         ; RETURN TO CALLER
   199                              <1> 
   200                              <1> 	;-----	ASCII STATUS
   201                              <1> _K2E:	
   202 00000CAB E804010000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER (EXTENDED)
   203 00000CB0 7420                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   204 00000CB2 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   205 00000CB3 E82B010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   206 00000CB8 EB17                <1> 	jmp	short _K2A	        ; GIVE IT TO THE CALLER
   207                              <1> _K2:	
   208 00000CBA E8F5000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER
   209 00000CBF 7411                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   210 00000CC1 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   211 00000CC2 E827010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   212 00000CC7 7308                <1> 	jnc	short _K2A	        ; CARRY CLEAR MEANS PASS VALID CODE
   213 00000CC9 9D                  <1> 	popf				; INVALID CODE FOR THIS TYPE OF CALL
   214 00000CCA E89A000000          <1> 	call	_K1S			; THROW THE CHARACTER AWAY
   215 00000CCF EBE9                <1> 	jmp	short _K2		; GO LOOK FOR NEXT CHAR, IF ANY
   216                              <1> _K2A:
   217 00000CD1 9D                  <1> 	popf				; RESTORE ZF FROM TEST
   218                              <1> _K2B:
   219                              <1> 	; 02/01/2017
   220 00000CD2 FA                  <1> 	cli
   221                              <1> 	;; mov	byte [intflg], 0 ;; 15/01/2017
   222                              <1> 	;
   223                              <1> 	;pop	ecx			; RECOVER REGISTER
   224 00000CD3 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   225 00000CD4 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   226                              <1> 	; (*) 29/05/2016
   227                              <1> 	; (*) retf 4			; THROW AWAY (e)FLAGS
   228 00000CD5 7208                <1> 	jc	short _k2d
   229 00000CD7 7505                <1> 	jnz	short _k2c
   230 00000CD9 804C240840          <1> 	or	byte [esp+8], 01000000b	; set zero flag bit of eflags register
   231                              <1> _k2c:
   232 00000CDE CF                  <1> 	iretd
   233                              <1> _k2d:
   234                              <1> 	; 29/05/2016 -set carry flag on stack-
   235                              <1> 	; [esp] = EIP
   236                              <1> 	; [esp+4] = CS
   237                              <1> 	; [esp+8] = E-FLAGS
   238 00000CDF 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
   239                              <1> 	; [esp+12] = ESP (user)
   240                              <1> 	; [esp+16] = SS (User)
   241 00000CE4 CF                  <1> 	iretd
   242                              <1> 
   243                              <1> 	
   244                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
   245                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   246                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   247                              <1> 	; // RETF instruction:
   248                              <1> 	;
   249                              <1> 	; IF OperandMode=32 THEN
   250                              <1>  	;    Load CS:EIP from stack;
   251                              <1>  	;    Set CS RPL to CPL;
   252                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
   253                              <1>  	;    Load SS:eSP from stack;
   254                              <1>  	; ELSE (* OperandMode=16 *)
   255                              <1>  	;    Load CS:IP from stack;
   256                              <1>  	;    Set CS RPL to CPL;
   257                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
   258                              <1> 	;    Load SS:eSP from stack;
   259                              <1>  	; FI;
   260                              <1> 	;
   261                              <1> 	; //
   262                              <1> 
   263                              <1> 	;-----	SHIFT STATUS
   264                              <1> _K3E:                                   ; GET THE EXTENDED SHIFT STATUS FLAGS
   265 00000CE5 8A25[BE5E0000]      <1> 	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
   266 00000CEB 80E404              <1> 	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
   267                              <1> 	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
   268                              <1> 	;shl	ah, cl			; BIT 7 POSITION
   269 00000CEE C0E405              <1>         shl	ah, 5
   270 00000CF1 A0[BE5E0000]        <1> 	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
   271 00000CF6 2473                <1> 	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
   272 00000CF8 08C4                <1> 	or	ah, al                  ; MERGE REMAINING BITS INTO AH
   273 00000CFA A0[C05E0000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
   274 00000CFF 240C                <1> 	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
   275 00000D01 08C4                <1> 	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
   276                              <1> _K3:
   277 00000D03 A0[BD5E0000]        <1> 	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
   278                              <1> 	;jmp	short _KIO_EXIT		; RETURN TO CALLER
   279 00000D08 EB83                <1> 	jmp	_KIO_EXIT
   280                              <1> 
   281                              <1> 	;-----	SET TYPAMATIC RATE AND DELAY
   282                              <1> _K300:
   283 00000D0A 3C05                <1> 	cmp	al, 5			; CORRECT FUNCTION CALL?
   284                              <1> 	;jne	short _KIO_EXIT		; NO, RETURN
   285 00000D0C 0F857BFFFFFF        <1>      	jne	_KIO_EXIT
   286 00000D12 F6C3E0              <1> 	test	bl, 0E0h		; TEST FOR OUT-OF-RANGE RATE
   287 00000D15 0F8572FFFFFF        <1>         jnz     _KIO_EXIT               ; RETURN IF SO
   288 00000D1B F6C7FC              <1> 	test	BH, 0FCh		; TEST FOR OUT-OF-RANGE DELAY
   289 00000D1E 0F8569FFFFFF        <1>         jnz     _KIO_EXIT               ; RETURN IF SO
   290 00000D24 B0F3                <1> 	mov	al, KB_TYPA_RD		; COMMAND FOR TYPAMATIC RATE/DELAY		
   291 00000D26 E8DA060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   292                              <1> 	;mov	cx, 5			; SHIFT COUNT
   293                              <1> 	;shl	bh, cl			; SHIFT DELAY OVER
   294 00000D2B C0E705              <1> 	shl	bh, 5
   295 00000D2E 88D8                <1> 	mov	al, bl			; PUT IN RATE
   296 00000D30 08F8                <1> 	or	al, bh			; AND DELAY
   297 00000D32 E8CE060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   298 00000D37 E951FFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER
   299                              <1> 
   300                              <1> 	;-----	WRITE TO KEYBOARD BUFFER
   301                              <1> _K500:
   302 00000D3C 56                  <1> 	push	esi			; SAVE SI (esi)
   303 00000D3D FA                  <1> 	cli				; 
   304 00000D3E 8B1D[CE5E0000]      <1>      	mov	ebx, [BUFFER_TAIL]	; GET THE 'IN TO' POINTER TO THE BUFFER
   305 00000D44 89DE                <1> 	mov	esi, ebx		; SAVE A COPY IN CASE BUFFER NOT FULL
   306 00000D46 E8D3000000          <1> 	call	_K4			; BUMP THE POINTER TO SEE IF BUFFER IS FULL
   307 00000D4B 3B1D[CA5E0000]      <1> 	cmp	ebx, [BUFFER_HEAD]	; WILL THE BUFFER OVERRUN IF WE STORE THIS?
   308 00000D51 740D                <1> 	je	short _K502		; YES - INFORM CALLER OF ERROR		
   309 00000D53 66890E              <1> 	mov	[esi], cx		; NO - PUT ASCII/SCAN CODE INTO BUFFER	
   310 00000D56 891D[CE5E0000]      <1> 	mov	[BUFFER_TAIL], ebx	; ADJUST 'IN TO' POINTER TO REFLECT CHANGE
   311 00000D5C 28C0                <1> 	sub	al, al			; TELL CALLER THAT OPERATION WAS SUCCESSFUL
   312 00000D5E EB02                <1> 	jmp	short _K504		; SUB INSTRUCTION ALSO RESETS CARRY FLAG
   313                              <1> _K502:
   314 00000D60 B001                <1> 	mov	al, 01h			; BUFFER FULL INDICATION
   315                              <1> _K504:
   316 00000D62 FB                  <1> 	sti				
   317 00000D63 5E                  <1> 	pop	esi			; RECOVER SI (esi)
   318 00000D64 E924FFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER WITH STATUS IN AL
   319                              <1> 
   320                              <1> 	;-----	READ THE KEY TO FIGURE OUT WHAT TO DO -----
   321                              <1> _K1S:
   322 00000D69 FA                  <1> 	cli	; 03/12/2014
   323 00000D6A 8B1D[CA5E0000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   324 00000D70 3B1D[CE5E0000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   325                              <1> 	;jne	short _K1U		; IF ANYTHING IN BUFFER SKIP INTERRUPT
   326 00000D76 750F                <1> 	jne	short _k1x ; 03/12/2014
   327                              <1> 	;
   328                              <1> 	; 03/12/2014
   329                              <1> 	; 28/08/2014
   330                              <1> 	; PERFORM OTHER FUNCTION ?? here !
   331                              <1> 	;; MOV	AX, 9002h		; MOVE IN WAIT CODE & TYPE
   332                              <1> 	;; INT 	15H			; PERFORM OTHER FUNCTION
   333                              <1> _K1T:                                   ; ASCII READ
   334 00000D78 FB                  <1> 	sti				; INTERRUPTS BACK ON DURING LOOP
   335 00000D79 90                  <1> 	nop				; ALLOW AN INTERRUPT TO OCCUR
   336                              <1> _K1U:	
   337 00000D7A FA                  <1> 	cli				; INTERRUPTS BACK OFF
   338 00000D7B 8B1D[CA5E0000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   339 00000D81 3B1D[CE5E0000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   340                              <1> _k1x:
   341 00000D87 53                  <1> 	push	ebx			; SAVE ADDRESS		
   342 00000D88 9C                  <1> 	pushf				; SAVE FLAGS
   343 00000D89 E82F070000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   344 00000D8E 8A1D[BF5E0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   345 00000D94 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   346 00000D96 80E307              <1> 	and	bl, 07h	; KB_LEDS	; ISOLATE INDICATOR BITS
   347 00000D99 7406                <1> 	jz	short _K1V		; IF NO CHANGE BYPASS UPDATE
   348 00000D9B E8C9060000          <1> 	call	SND_LED1
   349 00000DA0 FA                  <1> 	cli				; DISABLE INTERRUPTS
   350                              <1> _K1V:
   351 00000DA1 9D                  <1> 	popf				; RESTORE FLAGS
   352 00000DA2 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
   353 00000DA3 74D3                <1>         je      short _K1T              ; LOOP UNTIL SOMETHING IN BUFFER
   354                              <1> 	;
   355 00000DA5 668B03              <1> 	mov	ax, [ebx] 		; GET SCAN CODE AND ASCII CODE
   356 00000DA8 E871000000          <1>         call    _K4                     ; MOVE POINTER TO NEXT POSITION
   357 00000DAD 891D[CA5E0000]      <1>         mov     [BUFFER_HEAD], ebx      ; STORE VALUE IN VARIABLE
   358 00000DB3 C3                  <1> 	retn				; RETURN
   359                              <1> 
   360                              <1> 	;-----	READ THE KEY TO SEE IF ONE IS PRESENT -----
   361                              <1> _K2S:
   362 00000DB4 FA                  <1> 	cli				; INTERRUPTS OFF
   363 00000DB5 8B1D[CA5E0000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
   364 00000DBB 3B1D[CE5E0000]      <1>         cmp     ebx, [BUFFER_TAIL]      ; IF EQUAL (Z=1) THEN NOTHING THERE
   365 00000DC1 668B03              <1> 	mov	ax, [ebx]
   366 00000DC4 9C                  <1> 	pushf				; SAVE FLAGS
   367 00000DC5 6650                <1> 	push	ax			; SAVE CODE
   368 00000DC7 E8F1060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   369 00000DCC 8A1D[BF5E0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   370 00000DD2 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   371 00000DD4 80E307              <1> 	and	bl, 07h ; KB_LEDS	; ISOLATE INDICATOR BITS
   372 00000DD7 7405                <1> 	jz	short _K2T		; IF NO CHANGE BYPASS UPDATE
   373 00000DD9 E874060000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   374                              <1> _K2T:
   375 00000DDE 6658                <1> 	pop	ax			; RESTORE CODE
   376 00000DE0 9D                  <1> 	popf				; RESTORE FLAGS
   377 00000DE1 FB                  <1> 	sti				; INTERRUPTS BACK ON
   378 00000DE2 C3                  <1> 	retn				; RETURN
   379                              <1> 
   380                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR EXTENDED CALLS -----
   381                              <1> _KIO_E_XLAT:
   382 00000DE3 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   383 00000DE5 7506                <1> 	jne	short _KIO_E_RET	; NO, PASS IT ON
   384 00000DE7 08E4                <1>         or 	ah, ah			; AH = 0 IS SPECIAL CASE
   385 00000DE9 7402                <1>         jz	short _KIO_E_RET        ; PASS THIS ON UNCHANGED
   386 00000DEB 30C0                <1> 	xor	al, al			; OTHERWISE SET AL = 0
   387                              <1> _KIO_E_RET:				
   388 00000DED C3                  <1> 	retn				; GO BACK
   389                              <1> 
   390                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR STANDARD CALLS -----
   391                              <1> _KIO_S_XLAT:
   392 00000DEE 80FCE0              <1> 	cmp	ah, 0E0h		; IS IT KEYPAD ENTER OR / ?
   393 00000DF1 750F                <1> 	jne	short _KIO_S2		; NO, CONTINUE
   394 00000DF3 3C0D                <1> 	cmp	al, 0Dh			; KEYPAD ENTER CODE?
   395 00000DF5 7408                <1>         je	short _KIO_S1		; YES, MASSAGE A BIT
   396 00000DF7 3C0A                <1> 	cmp	al, 0Ah			; CTRL KEYPAD ENTER CODE?
   397 00000DF9 7404                <1>         je	short _KIO_S1		; YES, MASSAGE THE SAME
   398 00000DFB B435                <1> 	mov	ah, 35h			; NO, MUST BE KEYPAD /
   399                              <1> _kio_ret: ; 03/12/2014
   400 00000DFD F8                  <1> 	clc
   401 00000DFE C3                  <1> 	retn
   402                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   403                              <1> _KIO_S1:				
   404 00000DFF B41C                <1> 	mov	ah, 1Ch			; CONVERT TO COMPATIBLE OUTPUT
   405                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   406 00000E01 C3                  <1> 	retn
   407                              <1> _KIO_S2:		
   408 00000E02 80FC84              <1> 	cmp	ah, 84h			; IS IT ONE OF EXTENDED ONES?
   409 00000E05 7715                <1> 	ja	short _KIO_DIS		; YES, THROW AWAY AND GET ANOTHER CHAR
   410 00000E07 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   411 00000E09 7506                <1>         jne	short _KIO_S3		; NO, TRY LAST TEST
   412 00000E0B 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   413 00000E0D 740C                <1>         jz	short _KIO_USE		; PASS THIS ON UNCHANGED
   414 00000E0F EB0B                <1> 	jmp	short _KIO_DIS		; THROW AWAY THE REST
   415                              <1> _KIO_S3:
   416 00000E11 3CE0                <1> 	cmp	al, 0E0h		; IS IT AN EXTENSION OF A PREVIOUS ONE?
   417                              <1> 	;jne	short _KIO_USE		; NO, MUST BE A STANDARD CODE
   418 00000E13 75E8                <1> 	jne	short _kio_ret
   419 00000E15 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   420 00000E17 7402                <1>         jz	short _KIO_USE		; JUMP IF AH = 0
   421 00000E19 30C0                <1> 	xor	al, al			; CONVERT TO COMPATIBLE OUTPUT
   422                              <1> 	;jmp	short _KIO_USE		; PASS IT ON TO CALLER
   423                              <1> _KIO_USE:
   424                              <1> 	;clc				; CLEAR CARRY TO INDICATE GOOD CODE
   425 00000E1B C3                  <1> 	retn				; RETURN	
   426                              <1> _KIO_DIS:
   427 00000E1C F9                  <1> 	stc				; SET CARRY TO INDICATE DISCARD CODE
   428 00000E1D C3                  <1> 	retn				; RETURN
   429                              <1> 
   430                              <1> 	;-----	INCREMENT BUFFER POINTER ROUTINE -----
   431                              <1> _K4:    
   432 00000E1E 43                  <1> 	inc     ebx
   433 00000E1F 43                  <1> 	inc	ebx			; MOVE TO NEXT WORD IN LIST
   434 00000E20 3B1D[C65E0000]      <1>         cmp     ebx, [BUFFER_END] 	; AT END OF BUFFER?
   435                              <1>         ;jne    short _K5               ; NO, CONTINUE
   436 00000E26 7206                <1> 	jb	short _K5
   437 00000E28 8B1D[C25E0000]      <1>         mov     ebx, [BUFFER_START]     ; YES, RESET TO BUFFER BEGINNING
   438                              <1> _K5:
   439 00000E2E C3                  <1> 	retn
   440                              <1> 
   441                              <1> ; 20/02/2015
   442                              <1> ; 05/12/2014
   443                              <1> ; 26/08/2014
   444                              <1> ; KEYBOARD (HARDWARE) INTERRUPT -  IRQ LEVEL 1
   445                              <1> ; (INT_09h - Retro UNIX 8086 v1 - U9.ASM, 07/03/2014)
   446                              <1> ;
   447                              <1> ; Derived from "KB_INT_1" procedure of IBM "pc-at" 
   448                              <1> ; rombios source code (06/10/1985)
   449                              <1> ; 'keybd.asm', HARDWARE INT 09h - (IRQ Level 1)
   450                              <1> 
   451                              <1> ; EQUATES (IBM PC-XT-286 BIOS, 1986, 'POSQEQU.INC')
   452                              <1> 
   453                              <1> ;--------- 8042 COMMANDS -------------------------------------------------------
   454                              <1> ENA_KBD		equ	0AEh		; ENABLE KEYBOARD COMMAND
   455                              <1> DIS_KBD		equ	0ADh		; DISABLE KEYBOARD COMMAND
   456                              <1> SHUT_CMD	equ	0FEh		; CAUSE A SHUTDOWN COMMAND
   457                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   458                              <1> STATUS_PORT	equ	064h		; 8042 STATUS PORT
   459                              <1> INPT_BUF_FULL	equ	00000010b 	; 1 = +INPUT BUFFER FULL
   460                              <1> PORT_A		equ	060h		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   461                              <1> ;---------- 8042 KEYBOARD RESPONSE ---------------------------------------------
   462                              <1> KB_ACK		equ	0FAh		; ACKNOWLEDGE PROM TRANSMISSION
   463                              <1> KB_RESEND	equ	0FEh		; RESEND REQUEST
   464                              <1> KB_OVER_RUN	equ	0FFh		; OVER RUN SCAN CODE
   465                              <1> ;---------- KEYBOARD/LED COMMANDS ----------------------------------------------
   466                              <1> KB_ENABLE	equ	0F4h		; KEYBOARD ENABLE
   467                              <1> LED_CMD		equ	0EDh		; LED WRITE COMMAND
   468                              <1> KB_TYPA_RD	equ	0F3h		; TYPAMATIC RATE/DELAY COMMAND
   469                              <1> ;---------- KEYBOARD SCAN CODES ------------------------------------------------
   470                              <1> NUM_KEY		equ	69		; SCAN CODE FOR	 NUMBER LOCK KEY
   471                              <1> SCROLL_KEY	equ	70		; SCAN CODE FOR	 SCROLL LOCK KEY
   472                              <1> ALT_KEY		equ	56		; SCAN CODE FOR	 ALTERNATE SHIFT KEY
   473                              <1> CTL_KEY		equ	29		; SCAN CODE FOR	 CONTROL KEY
   474                              <1> CAPS_KEY	equ	58		; SCAN CODE FOR	 SHIFT LOCK KEY
   475                              <1> DEL_KEY		equ	83		; SCAN CODE FOR	 DELETE KEY
   476                              <1> INS_KEY		equ	82		; SCAN CODE FOR	 INSERT KEY
   477                              <1> LEFT_KEY	equ	42		; SCAN CODE FOR	 LEFT SHIFT
   478                              <1> RIGHT_KEY	equ	54		; SCAN CODE FOR	 RIGHT SHIFT
   479                              <1> SYS_KEY		equ	84		; SCAN CODE FOR	 SYSTEM KEY
   480                              <1> ;---------- ENHANCED KEYBOARD SCAN CODES ---------------------------------------
   481                              <1> ID_1		equ	0ABh		; 1ST ID CHARACTER FOR KBX
   482                              <1> ID_2		equ	041h		; 2ND ID CHARACTER FOR KBX
   483                              <1> ID_2A		equ	054h		; ALTERNATE 2ND ID CHARACTER FOR KBX
   484                              <1> F11_M		equ	87		; F11 KEY MAKE
   485                              <1> F12_M		equ	88		; F12 KEY MAKE
   486                              <1> MC_E0		equ	224		; GENERAL MARKER CODE
   487                              <1> MC_E1		equ	225		; PAUSE KEY MARKER CODE
   488                              <1> ;---------- FLAG EQUATES WITHIN @KB_FLAG----------------------------------------
   489                              <1> RIGHT_SHIFT	equ	00000001b	; RIGHT SHIFT KEY DEPRESSED
   490                              <1> LEFT_SHIFT	equ	00000010b	; LEFT SHIFT KEY DEPRESSED
   491                              <1> CTL_SHIFT	equ	00000100b	; CONTROL SHIFT KEY DEPRESSED
   492                              <1> ALT_SHIFT	equ	00001000b	; ALTERNATE SHIFT KEY DEPRESSED
   493                              <1> SCROLL_STATE	equ	00010000b	; SCROLL LOCK STATE IS ACTIVE
   494                              <1> NUM_STATE	equ	00100000b	; NUM LOCK STATE IS ACTIVE
   495                              <1> CAPS_STATE	equ	01000000b	; CAPS LOCK STATE IS ACTIVE
   496                              <1> INS_STATE	equ	10000000b	; INSERT STATE IS ACTIVE
   497                              <1> ;---------- FLAG EQUATES WITHIN	@KB_FLAG_1 -------------------------------------
   498                              <1> L_CTL_SHIFT	equ	00000001b	; LEFT CTL KEY DOWN
   499                              <1> L_ALT_SHIFT	equ	00000010b	; LEFT ALT KEY DOWN
   500                              <1> SYS_SHIFT	equ	00000100b	; SYSTEM KEY DEPRESSED AND HELD
   501                              <1> HOLD_STATE	equ	00001000b	; SUSPEND KEY HAS BEEN TOGGLED
   502                              <1> SCROLL_SHIFT	equ	00010000b	; SCROLL LOCK KEY IS DEPRESSED
   503                              <1> NUM_SHIFT	equ	00100000b	; NUM LOCK KEY IS DEPRESSED
   504                              <1> CAPS_SHIFT	equ	01000000b	; CAPS LOCK KEY IS DEPRE55ED
   505                              <1> INS_SHIFT	equ	10000000b	; INSERT KEY IS DEPRESSED
   506                              <1> ;---------- FLAGS EQUATES WITHIN @KB_FLAG_2 -----------------------------------
   507                              <1> KB_LEDS		equ	00000111b	; KEYBOARD LED STATE BITS
   508                              <1> ;		equ	00000001b	; SCROLL LOCK INDICATOR
   509                              <1> ;		equ	00000010b	; NUM LOCK INDICATOR
   510                              <1> ;		equ	00000100b	; CAPS LOCK INDICATOR
   511                              <1> ;		equ	00001000b	; RESERVED (MUST BE ZERO)
   512                              <1> KB_FA		equ	00010000b	; ACKNOWLEDGMENT RECEIVED
   513                              <1> KB_FE		equ	00100000b	; RESEND RECEIVED FLAG
   514                              <1> KB_PR_LED	equ	01000000b	; MODE INDICATOR UPDATE
   515                              <1> KB_ERR		equ	10000000b	; KEYBOARD TRANSMIT ERROR FLAG
   516                              <1> ;----------- FLAGS EQUATES WITHIN @KB_FLAG_3 -----------------------------------
   517                              <1> LC_E1		equ	00000001b	; LAST CODE WAS THE E1 HIDDEN CODE
   518                              <1> LC_E0		equ	00000010b	; LAST CODE WAS THE E0 HIDDEN CODE
   519                              <1> R_CTL_SHIFT	equ	00000100b	; RIGHT CTL KEY DOWN
   520                              <1> R_ALT_SHIFT	equ	00001000b	; RIGHT ALT KEY DOWN
   521                              <1> GRAPH_ON	equ	00001000b	; ALT GRAPHICS KEY DOWN (WT ONLY)	
   522                              <1> KBX		equ	00010000b	; ENHANCED KEYBOARD INSTALLED
   523                              <1> SET_NUM_LK	equ	00100000b	; FORCE NUM LOCK IF READ ID AND KBX
   524                              <1> LC_AB		equ	01000000b	; LAST CHARACTER WAS FIRST ID CHARACTER
   525                              <1> RD_ID		equ	10000000b	; DOING A READ ID (MUST BE BIT0)
   526                              <1> ;
   527                              <1> ;----------- INTERRUPT EQUATES -------------------------------------------------
   528                              <1> EOI		equ	020h		; END OF INTERRUPT COMMAND TO 8259
   529                              <1> INTA00		equ	020h		; 8259 PORT
   530                              <1> 
   531                              <1> 
   532                              <1> kb_int:
   533                              <1> 
   534                              <1> ; 17/10/2015 ('ctrlbrk') 
   535                              <1> ; 05/12/2014
   536                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-)
   537                              <1> ; 26/08/2014
   538                              <1> ;
   539                              <1> ; 03/06/86  KEYBOARD BIOS
   540                              <1> ;
   541                              <1> ;--- HARDWARE INT 09H -- (IRQ LEVEL 1) ------------------------------------------
   542                              <1> ;										;
   543                              <1> ;	KEYBOARD INTERRUPT ROUTINE						;
   544                              <1> ;										;
   545                              <1> ;--------------------------------------------------------------------------------
   546                              <1> 
   547                              <1> KB_INT_1:
   548 00000E2F FB                  <1> 	sti				; ENABLE INTERRUPTS
   549                              <1> 	;push	ebp
   550 00000E30 50                  <1> 	push	eax
   551 00000E31 53                  <1> 	push	ebx
   552 00000E32 51                  <1> 	push	ecx
   553 00000E33 52                  <1> 	push	edx
   554 00000E34 56                  <1> 	push	esi
   555 00000E35 57                  <1> 	push	edi
   556 00000E36 1E                  <1> 	push	ds
   557 00000E37 06                  <1> 	push	es
   558 00000E38 FC                  <1> 	cld				; FORWARD DIRECTION
   559 00000E39 66B81000            <1> 	mov	ax, KDATA
   560 00000E3D 8ED8                <1> 	mov	ds, ax
   561 00000E3F 8EC0                <1> 	mov	es, ax
   562                              <1> 	;
   563                              <1> 	;-----	WAIT FOR KEYBOARD DISABLE COMMAND TO BE ACCEPTED
   564 00000E41 B0AD                <1> 	mov	al, DIS_KBD		; DISABLE THE KEYBOARD COMMAND
   565 00000E43 E8A9050000          <1> 	call	SHIP_IT			; EXECUTE DISABLE
   566 00000E48 FA                  <1> 	cli				; DISABLE INTERRUPTS
   567 00000E49 B900000100          <1> 	mov	ecx, 10000h		; SET MAXIMUM TIMEOUT
   568                              <1> KB_INT_01:
   569 00000E4E E464                <1> 	in	al, STATUS_PORT		; READ ADAPTER STATUS
   570 00000E50 A802                <1> 	test	al, INPT_BUF_FULL	; CHECK INPUT BUFFER FULL STATUS BIT
   571 00000E52 E0FA                <1> 	loopnz	KB_INT_01		; WAIT FOR COMMAND TO BE ACCEPTED
   572                              <1> 	;
   573                              <1> 	;-----	READ CHARACTER FROM KEYBOARD INTERFACE
   574 00000E54 E460                <1> 	in	al, PORT_A		; READ IN THE CHARACTER
   575                              <1> 	;
   576                              <1> 	;-----	SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INT LEVEL 9H) 	
   577                              <1> 	;MOV	AH, 04FH		; SYSTEM INTERCEPT - KEY CODE FUNCTION
   578                              <1> 	;STC				; SET CY=1 (IN CASE OF IRET)
   579                              <1> 	;INT	15H			; CASETTE CALL (AL)=KEY SCAN CODE
   580                              <1> 	;				; RETURNS CY=1 FOR INVALID FUNCTION
   581                              <1> 	;JC	KB_INT_02		; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
   582                              <1> 	;JMP	K26			; EXIT IF SYSTEM HANDLES SCAN CODE
   583                              <1> 	;				; EXT HANDLES HARDWARE EOI AND ENABLE		
   584                              <1> 	;
   585                              <1> 	;-----	CHECK FOR A RESEND COMMAND TO KEYBOARD
   586                              <1> KB_INT_02:				; 	  (AL)= SCAN CODE
   587 00000E56 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
   588 00000E57 3CFE                <1> 	cmp	al, KB_RESEND		; IS THE INPUT A RESEND
   589 00000E59 7411                <1>         je      short KB_INT_4          ; GO IF RESEND
   590                              <1> 	;
   591                              <1> 	;-----	CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
   592 00000E5B 3CFA                <1> 	cmp	al, KB_ACK		; IS THE INPUT AN ACKNOWLEDGE
   593 00000E5D 751A                <1>         jne     short KB_INT_2          ; GO IF NOT
   594                              <1> 	;
   595                              <1> 	;-----	A COMMAND TO THE KEYBOARD WAS ISSUED
   596 00000E5F FA                  <1> 	cli				; DISABLE INTERRUPTS
   597 00000E60 800D[BF5E0000]10    <1> 	or	byte [KB_FLAG_2], KB_FA ; INDICATE ACK RECEIVED
   598 00000E67 E97A020000          <1>         jmp     K26                     ; RETURN IF NOT (ACK RETURNED FOR DATA)
   599                              <1> 	;
   600                              <1> 	;-----	RESEND THE LAST BYTE
   601                              <1> KB_INT_4:
   602 00000E6C FA                  <1> 	cli				; DISABLE INTERRUPTS
   603 00000E6D 800D[BF5E0000]20    <1> 	or	byte [KB_FLAG_2], KB_FE ; INDICATE RESEND RECEIVED
   604 00000E74 E96D020000          <1>         jmp     K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
   605                              <1> 	;
   606                              <1> ;-----	UPDATE MODE INDICATORS IF CHANGE IN STATE
   607                              <1> KB_INT_2:
   608 00000E79 6650                <1> 	push 	ax			; SAVE DATA IN
   609 00000E7B E83D060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   610 00000E80 8A1D[BF5E0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   611 00000E86 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   612 00000E88 80E307              <1> 	and	bl, KB_LEDS		; ISOLATE INDICATOR BITS
   613 00000E8B 7405                <1> 	jz	short UP0		; IF NO CHANGE BYPASS UPDATE
   614 00000E8D E8C0050000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   615                              <1> UP0:
   616 00000E92 6658                <1> 	pop	ax			; RESTORE DATA IN
   617                              <1> ;------------------------------------------------------------------------
   618                              <1> ;	START OF KEY PROCESSING						;
   619                              <1> ;------------------------------------------------------------------------
   620 00000E94 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE IN AH ALSO
   621                              <1> 	;
   622                              <1> 	;-----	TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
   623 00000E96 3CFF                <1> 	cmp	al, KB_OVER_RUN		; IS THIS AN OVERRUN CHAR
   624 00000E98 0F843F050000        <1>         je      K62			; BUFFER_FULL_BEEP
   625                              <1> 	;
   626                              <1> K16:	
   627 00000E9E 8A3D[C05E0000]      <1> 	mov	bh, [KB_FLAG_3]		; LOAD FLAGS FOR TESTING
   628                              <1> 	;
   629                              <1> 	;-----	TEST TO SEE IF A READ_ID IS IN PROGRESS
   630 00000EA4 F6C7C0              <1> 	test 	bh, RD_ID+LC_AB 	; ARE WE DOING A READ ID?
   631 00000EA7 7449                <1> 	jz	short NOT_ID		; CONTINUE IF NOT
   632 00000EA9 7917                <1> 	jns	short TST_ID_2		; IS THE RD_ID FLAG ON?
   633 00000EAB 3CAB                <1> 	cmp	al, ID_1		; IS THIS THE 1ST ID CHARACTER?
   634 00000EAD 7507                <1> 	jne	short RST_RD_ID
   635 00000EAF 800D[C05E0000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
   636                              <1> RST_RD_ID:
   637 00000EB6 8025[C05E0000]7F    <1> 	and	byte [KB_FLAG_3], ~RD_ID ; RESET THE READ ID FLAG
   638                              <1>         ;jmp    short ID_EX		; AND EXIT
   639 00000EBD E924020000          <1> 	jmp	K26
   640                              <1> 	;
   641                              <1> TST_ID_2:
   642 00000EC2 8025[C05E0000]BF    <1> 	and	byte [KB_FLAG_3], ~LC_AB ; RESET FLAG
   643 00000EC9 3C54                <1> 	cmp	al, ID_2A		; IS THIS THE 2ND ID CHARACTER?
   644 00000ECB 7419                <1>         je	short KX_BIT		; JUMP IF SO
   645 00000ECD 3C41                <1> 	cmp	al, ID_2		; IS THIS THE 2ND ID CHARACTER?
   646                              <1>         ;jne	short ID_EX		; LEAVE IF NOT
   647 00000ECF 0F8511020000        <1> 	jne	K26
   648                              <1> 	;
   649                              <1> 	;-----	A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
   650 00000ED5 F6C720              <1> 	test	bh, SET_NUM_LK 		; SHOULD WE SET NUM LOCK?
   651 00000ED8 740C                <1>         jz      short KX_BIT		; EXIT IF NOT
   652 00000EDA 800D[BD5E0000]20    <1> 	or	byte [KB_FLAG], NUM_STATE ; FORCE NUM LOCK ON
   653 00000EE1 E86C050000          <1> 	call	SND_LED			; GO SET THE NUM LOCK INDICATOR
   654                              <1> KX_BIT:
   655 00000EE6 800D[C05E0000]10    <1> 	or	byte [KB_FLAG_3], KBX	; INDICATE ENHANCED KEYBOARD WAS FOUND
   656 00000EED E9F4010000          <1> ID_EX:	jmp     K26			; EXIT
   657                              <1> 	;
   658                              <1> NOT_ID:
   659 00000EF2 3CE0                <1> 	cmp	al, MC_E0		; IS THIS THE GENERAL MARKER CODE?
   660 00000EF4 750C                <1> 	jne	short TEST_E1
   661 00000EF6 800D[C05E0000]12    <1> 	or	byte [KB_FLAG_3], LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
   662                              <1> 	;jmp	short EXIT		; THROW AWAY THIS CODE
   663 00000EFD E9EB010000          <1> 	jmp	K26A	
   664                              <1> TEST_E1:	
   665 00000F02 3CE1                <1> 	cmp	al, MC_E1		; IS THIS THE PAUSE KEY?
   666 00000F04 750C                <1> 	jne	short NOT_HC
   667 00000F06 800D[C05E0000]11    <1> 	or	byte [KB_FLAG_3], LC_E1+KBX ; SET FLAG BIT, SET KBX, AND
   668 00000F0D E9DB010000          <1> EXIT:	jmp	K26A			; THROW AWAY THIS CODE
   669                              <1> 	;
   670                              <1> NOT_HC:
   671 00000F12 247F                <1> 	and	al, 07Fh		; TURN OFF THE BREAK BIT
   672 00000F14 F6C702              <1> 	test	bh, LC_E0		; LAST CODE THE E0 MARKER CODE
   673 00000F17 7414                <1> 	jz	short NOT_LC_E0		; JUMP IF NOT
   674                              <1> 	;
   675 00000F19 BF[AA5D0000]        <1> 	mov	edi, _K6+6		; IS THIS A SHIFT KEY?
   676 00000F1E AE                  <1> 	scasb
   677 00000F1F 0F84C1010000        <1>         je      K26 ; K16B              ; YES, THROW AWAY & RESET FLAG
   678 00000F25 AE                  <1> 	scasb
   679 00000F26 757C                <1> 	jne	short K16A		; NO, CONTINUE KEY PROCESSING
   680                              <1> 	;jmp	short K16B		; YES, THROW AWAY & RESET FLAG
   681 00000F28 E9B9010000          <1> 	jmp	K26
   682                              <1> 	;
   683                              <1> NOT_LC_E0:
   684 00000F2D F6C701              <1> 	test	bh, LC_E1		; LAST CODE THE E1 MARKER CODE?
   685 00000F30 7435                <1> 	jz	short T_SYS_KEY		; JUMP IF NOT
   686 00000F32 B904000000          <1> 	mov	ecx, 4			; LENGHT OF SEARCH
   687 00000F37 BF[A85D0000]        <1> 	mov	edi, _K6+4		; IS THIS AN ALT, CTL, OR SHIFT?
   688 00000F3C F2AE                <1> 	repne	scasb			; CHECK IT
   689                              <1> 	;je	short EXIT		; THROW AWAY IF SO
   690 00000F3E 0F84A9010000        <1> 	je	K26A			
   691                              <1> 	;
   692 00000F44 3C45                <1> 	cmp	al, NUM_KEY		; IS IT THE PAUSE KEY?
   693                              <1> 	;jne	short K16B		; NO, THROW AWAY & RESET FLAG
   694 00000F46 0F859A010000        <1> 	jne	K26
   695 00000F4C F6C480              <1> 	test	ah, 80h			; YES, IS IT THE BREAK OF THE KEY?
   696                              <1> 	;jnz	short K16B		; YES, THROW THIS AWAY, TOO	
   697 00000F4F 0F8591010000        <1> 	jnz	K26
   698                              <1>         ; 20/02/2015 
   699 00000F55 F605[BE5E0000]08    <1> 	test	byte [KB_FLAG_1],HOLD_STATE ;  NO, ARE WE PAUSED ALREADY?
   700                              <1> 	;jnz	short K16B		;  YES, THROW AWAY
   701 00000F5C 0F8584010000        <1> 	jnz	K26
   702 00000F62 E9E1020000          <1> 	jmp     K39P                    ; NO, THIS IS THE REAL PAUSE STATE
   703                              <1> 	;
   704                              <1> 	;-----	TEST FOR SYSTEM KEY
   705                              <1> T_SYS_KEY:
   706 00000F67 3C54                <1> 	cmp	al, SYS_KEY		; IS IT THE SYSTEM KEY?
   707 00000F69 7539                <1> 	jnz	short K16A		; CONTINUE IF NOT
   708                              <1> 	;
   709 00000F6B F6C480              <1> 	test	ah, 80h			; CHECK IF THIS A BREAK CODE
   710 00000F6E 7524                <1> 	jnz	short K16C		; DO NOT TOUCH SYSTEM INDICATOR IF TRUE
   711                              <1> 	;
   712 00000F70 F605[BE5E0000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN 
   713                              <1>         ;jnz	short K16B		; IF YES, DO NOT PROCESS SYSTEM INDICATOR	
   714 00000F77 0F8569010000        <1> 	jnz     K26			
   715                              <1> 	;
   716 00000F7D 800D[BE5E0000]04    <1> 	or	byte [KB_FLAG_1], SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
   717 00000F84 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   718 00000F86 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   719                              <1> 					; INTERRUPT-RETURN-NO-EOI
   720 00000F88 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   721 00000F8A E862040000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   722                              <1> 	; !!! SYSREQ !!! function/system call (INTERRUPT) must be here !!!
   723                              <1> 	;MOV	AL, 8500H		; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
   724                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   725                              <1> 	;INT	15H			; USER INTERRUPT	
   726 00000F8F E965010000          <1>         jmp     K27A                    ; END PROCESSING
   727                              <1> 	;
   728                              <1> ;K16B:	jmp	K26			; IGNORE SYSTEM KEY
   729                              <1> 	;
   730                              <1> K16C:
   731 00000F94 8025[BE5E0000]FB    <1> 	and	byte [KB_FLAG_1], ~SYS_SHIFT ; TURN OFF SHIFT KEY HELD DOWN
   732 00000F9B B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   733 00000F9D E620                <1> 	out	20h, al ;out INTA00, al ; SEND COMMAND TO INTERRUPT CONTROL PORT
   734                              <1> 					; INTERRUPT-RETURN-NO-EOI
   735                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   736                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
   737                              <1> 	;
   738                              <1> 	;MOV	AX, 8501H		; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
   739                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   740                              <1> 	;INT	15H			; USER INTERRUPT
   741                              <1> 	;JMP	K27A			; INGONRE SYSTEM KEY				
   742                              <1> 	;
   743 00000F9F E94E010000          <1> 	jmp     K27			; IGNORE SYSTEM KEY
   744                              <1> 	;
   745                              <1> 	;-----	TEST FOR SHIFT KEYS
   746                              <1> K16A:
   747 00000FA4 8A1D[BD5E0000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
   748 00000FAA BF[A45D0000]        <1> 	mov	edi, _K6		; SHIFT KEY TABLE offset
   749 00000FAF B908000000          <1> 	mov	ecx, _K6L		; LENGTH
   750 00000FB4 F2AE                <1> 	repne	scasb			; LOOK THROUGH THE TABLE FOR A MATCH
   751 00000FB6 88E0                <1> 	mov	al, ah			; RECOVER SCAN CODE
   752 00000FB8 0F8510010000        <1>         jne     K25                     ; IF NO MATCH, THEN SHIFT NOT FOUND
   753                              <1> 	;
   754                              <1> 	;------	SHIFT KEY FOUND
   755                              <1> K17:
   756 00000FBE 81EF[A55D0000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
   757 00000FC4 8AA7[AC5D0000]      <1>        	mov     ah, [edi+_K7]       	; GET MASK INTO AH
   758 00000FCA B102                <1> 	mov	cl, 2			; SETUP COUNT FOR FLAG SHIFTS
   759 00000FCC A880                <1> 	test	al, 80h			; TEST FOR BREAK KEY
   760 00000FCE 0F8596000000        <1>         jnz     K23                     ; JUMP OF BREAK
   761                              <1> 	;
   762                              <1> 	;-----	SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
   763                              <1> K17C:
   764 00000FD4 80FC10              <1> 	cmp	ah, SCROLL_SHIFT
   765 00000FD7 732B                <1> 	jae	short K18		; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
   766                              <1> 	;
   767                              <1> 	;-----	PLAIN SHIFT KEY, SET SHIFT ON
   768 00000FD9 0825[BD5E0000]      <1> 	or	[KB_FLAG], ah		; TURN ON SHIFT BIT
   769 00000FDF A80C                <1>         test	al, CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
   770                              <1> 	;jnz	short K17D		; YES, MORE FLAGS TO SET
   771 00000FE1 0F84FF000000        <1> 	jz	K26			; NO, INTERRUPT RETURN
   772                              <1> K17D:
   773 00000FE7 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF NEW KEYS?
   774 00000FEA 740B                <1> 	jz 	short K17E		; NO, JUMP
   775 00000FEC 0825[C05E0000]      <1> 	or	[KB_FLAG_3], ah		; SET BITS FOR RIGHT CTRL, ALT
   776 00000FF2 E9EF000000          <1> 	jmp	K26			; INTERRUPT RETURN
   777                              <1> K17E:
   778 00000FF7 D2EC                <1> 	shr	ah, cl			; MOVE FLAG BITS TWO POSITIONS
   779 00000FF9 0825[BE5E0000]      <1> 	or	[KB_FLAG_1], ah		; SET BITS FOR LEFT CTRL, ALT
   780 00000FFF E9E2000000          <1> 	jmp	K26
   781                              <1> 	;
   782                              <1> 	;-----	TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
   783                              <1> K18:					; SHIFT-TOGGLE
   784 00001004 F6C304              <1> 	test	bl, CTL_SHIFT 		; CHECK CTL SHIFT STATE
   785                              <1>         ;jz    	short K18A              ; JUMP IF NOT CTL STATE
   786 00001007 0F85C1000000        <1>         jnz     K25                     ; JUMP IF CTL STATE
   787                              <1> K18A:
   788 0000100D 3C52                <1> 	cmp	al, INS_KEY		; CHECK FOR INSERT KEY
   789 0000100F 7524                <1> 	jne	short K22		; JUMP IF NOT INSERT KEY
   790 00001011 F6C308              <1> 	test	bl, ALT_SHIFT 		; CHECK FOR ALTERNATE SHIFT
   791                              <1>       	;jz	short K18B		; JUMP IF NOT ALTERNATE SHIFT	
   792 00001014 0F85B4000000        <1>         jnz     K25                     ; JUMP IF ALTERNATE SHIFT
   793                              <1> K18B:
   794 0000101A F6C702              <1> 	test	bh, LC_E0 ;20/02/2015	; IS THIS NEW INSERT KEY?
   795 0000101D 7516                <1> 	jnz	short K22		; YES, THIS ONE'S NEVER A '0'
   796                              <1> K19:	
   797 0000101F F6C320              <1> 	test	bl, NUM_STATE 		; CHECK FOR BASE STATE
   798 00001022 750C                <1> 	jnz	short K21		; JUMP IF NUM LOCK IS ON
   799 00001024 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
   800 00001027 740C                <1> 	jz	short K22		; JUMP IF BASE STATE
   801                              <1> K20:					; NUMERIC ZERO, NOT INSERT KEY
   802 00001029 88C4                <1> 	mov	ah, al			; PUT SCAN CODE BACK IN AH
   803 0000102B E99E000000          <1>         jmp     K25                     ; NUMERAL '0', STNDRD. PROCESSING
   804                              <1> K21:					; MIGHT BE NUMERIC
   805 00001030 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT
   806 00001033 74F4                <1> 	jz	short K20		; IS NUMERIC, STD. PROC.
   807                              <1> 	;
   808                              <1> K22:					; SHIFT TOGGLE KEY HIT; PROCESS IT
   809 00001035 8425[BE5E0000]      <1> 	test	ah, [KB_FLAG_1] 	; IS KEY ALREADY DEPRESSED
   810 0000103B 0F85A5000000        <1>         jnz     K26                     ; JUMP IF KEY ALREADY DEPRESSED
   811                              <1> K22A:
   812 00001041 0825[BE5E0000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
   813 00001047 3025[BD5E0000]      <1> 	xor	[KB_FLAG], ah		; TOGGLE THE SHIFT STATE
   814                              <1> 	;
   815                              <1> 	;-----	TOGGLE LED IF CAPS, NUM  OR SCROLL KEY DEPRESSED
   816 0000104D F6C470              <1> 	test	ah, CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
   817 00001050 7409                <1> 	jz	short K22B		; GO IF NOT
   818                              <1> 	;
   819 00001052 6650                <1> 	push	ax			; SAVE SCAN CODE AND SHIFT MASK
   820 00001054 E8F9030000          <1> 	call	SND_LED			; GO TURN MODE INDICATORS ON
   821 00001059 6658                <1> 	pop	ax			; RESTORE SCAN CODE
   822                              <1> K22B:
   823 0000105B 3C52                <1> 	cmp	al, INS_KEY		; TEST FOR 1ST MAKE OF INSERT KEY
   824 0000105D 0F8583000000        <1>         jne     K26                     ; JUMP IF NOT INSERT KEY
   825 00001063 88C4                <1> 	mov	ah, al		        ; SCAN CODE IN BOTH HALVES OF AX
   826 00001065 E999000000          <1>         jmp     K28                     ; FLAGS UPDATED, PROC. FOR BUFFER
   827                              <1> 	;
   828                              <1> 	;-----	BREAK SHIFT FOUND
   829                              <1> K23:					; BREAK-SHIFT-FOUND
   830 0000106A 80FC10              <1> 	cmp	ah, SCROLL_SHIFT	; IS THIS A TOGGLE KEY
   831 0000106D F6D4                <1> 	not	ah			; INVERT MASK
   832 0000106F 7355                <1> 	jae	short K24		; YES, HANDLE BREAK TOGGLE
   833 00001071 2025[BD5E0000]      <1> 	and	[KB_FLAG], ah		; TURN OFF SHIFT BIT
   834 00001077 80FCFB              <1> 	cmp	ah, ~CTL_SHIFT		; IS THIS ALT OR CTL?
   835 0000107A 7730                <1> 	ja	short K23D		; NO, ALL DONE
   836                              <1> 	;
   837 0000107C F6C702              <1> 	test	bh, LC_E0		; 2ND ALT OR CTL?
   838 0000107F 7408                <1> 	jz	short K23A		; NO, HANSLE NORMALLY
   839 00001081 2025[C05E0000]      <1> 	and 	[KB_FLAG_3], ah		; RESET BIT FOR RIGHT ALT OR CTL
   840 00001087 EB08                <1> 	jmp	short K23B		; CONTINUE
   841                              <1> K23A:
   842 00001089 D2FC                <1> 	sar	ah, cl			; MOVE THE MASK BIT TWO POSITIONS
   843 0000108B 2025[BE5E0000]      <1> 	and	[KB_FLAG_1], ah		; RESET BIT FOR LEFT ALT AND CTL
   844                              <1> K23B:
   845 00001091 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE
   846 00001093 A0[C05E0000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT ALT & CTRL FLAGS
   847 00001098 D2E8                <1> 	shr	al, cl			; MOVE TO BITS 1 & 0
   848 0000109A 0A05[BE5E0000]      <1> 	or	al, [KB_FLAG_1]		; PUT IN LEFT ALT & CTL FLAGS
   849 000010A0 D2E0                <1> 	shl	al, cl			; MOVE BACK TO BITS 3 & 2
   850 000010A2 240C                <1> 	and	al, ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
   851 000010A4 0805[BD5E0000]      <1> 	or	[KB_FLAG], al		; PUT RESULT IN THE REAL FLAGS	
   852 000010AA 88E0                <1> 	mov	al, ah
   853                              <1> K23D:
   854 000010AC 3CB8                <1> 	cmp	al, ALT_KEY+80h		; IS THIS ALTERNATE SHIFT RELEASE
   855 000010AE 7536                <1> 	jne	short K26		; INTERRUPT RETURN
   856                              <1> 	;	
   857                              <1> 	;-----	ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
   858 000010B0 A0[C15E0000]        <1> 	mov	al, [ALT_INPUT]
   859 000010B5 B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
   860 000010B7 8825[C15E0000]      <1> 	mov	[ALT_INPUT], ah 	; ZERO OUT THE FIELD
   861 000010BD 3C00                <1> 	cmp	al, 0			; WAS THE INPUT = 0?
   862 000010BF 7425                <1> 	je	short K26		; INTERRUPT_RETURN
   863                              <1>         ; 29/01/2016
   864                              <1> 	;jmp     K61                    ; IT WASN'T, SO PUT IN BUFFER
   865 000010C1 E9D0020000          <1> 	jmp	_K60
   866                              <1> 	;
   867                              <1> K24:					; BREAK-TOGGLE
   868 000010C6 2025[BE5E0000]      <1> 	and	[KB_FLAG_1], ah 	; INDICATE NO LONGER DEPRESSED
   869 000010CC EB18                <1> 	jmp	short K26		; INTERRUPT_RETURN
   870                              <1> 	;
   871                              <1> 	;-----	TEST FOR HOLD STATE
   872                              <1> 					; AL, AH = SCAN CODE
   873                              <1> K25:					; NO-SHIFT-FOUND
   874 000010CE 3C80                <1> 	cmp	al, 80h			; TEST FOR BREAK KEY
   875 000010D0 7314                <1> 	jae	short K26		; NOTHING FOR BREAK CHARS FROM HERE ON
   876 000010D2 F605[BE5E0000]08    <1> 	test	byte [KB_FLAG_1], HOLD_STATE ; ARE WE IN HOLD STATE
   877 000010D9 7428                <1> 	jz	short K28		; BRANCH AROUND TEST IF NOT
   878 000010DB 3C45                <1> 	cmp	al, NUM_KEY
   879 000010DD 7407                <1> 	je	short K26		; CAN'T END HOLD ON NUM_LOCK
   880 000010DF 8025[BE5E0000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
   881                              <1> 	;
   882                              <1> K26:
   883 000010E6 8025[C05E0000]FC    <1> 	and	byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
   884                              <1> K26A:					; INTERRUPT-RETURN
   885 000010ED FA                  <1> 	cli				; TURN OFF INTERRUPTS
   886 000010EE B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   887 000010F0 E620                <1> 	out	20h, al	;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   888                              <1> K27:					; INTERRUPT-RETURN-NO-EOI
   889 000010F2 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   890 000010F4 E8F8020000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   891                              <1> K27A:
   892 000010F9 FA                  <1> 	cli				; DISABLE INTERRUPTS
   893                              <1> 	;;mov	byte [intflg], 0 ; 07/01/2017 ;; 15/01/2017
   894 000010FA 07                  <1> 	pop	es			; RESTORE REGISTERS
   895 000010FB 1F                  <1> 	pop	ds
   896 000010FC 5F                  <1> 	pop	edi
   897 000010FD 5E                  <1> 	pop	esi
   898 000010FE 5A                  <1> 	pop	edx
   899 000010FF 59                  <1> 	pop	ecx
   900 00001100 5B                  <1> 	pop	ebx
   901 00001101 58                  <1> 	pop	eax
   902                              <1> 	;pop	ebp
   903 00001102 CF                  <1> 	iretd				; RETURN
   904                              <1> 
   905                              <1> 	;-----	NOT IN	HOLD STATE
   906                              <1> K28:					; NO-HOLD-STATE
   907 00001103 3C58                <1> 	cmp	al, 88			; TEST FOR OUT-OF-RANGE SCAN CODES
   908 00001105 77DF                <1> 	ja	short K26		; IGNORE IF OUT-OF-RANGE	
   909                              <1> 	;
   910 00001107 F6C308              <1> 	test	bl, ALT_SHIFT 		; ARE WE IN ALTERNATE SHIFT
   911                              <1>         ;jz	short K28A		; IF NOT ALTERNATE
   912 0000110A 0F84F1000000        <1>         jz      K38
   913                              <1> 	;
   914 00001110 F6C710              <1> 	test	bh, KBX			; IS THIS THE ENCHANCED KEYBOARD?
   915 00001113 740D                <1> 	jz	short K29		; NO, ALT STATE IS REAL
   916                              <1> 	 ;28/02/2015
   917 00001115 F605[BE5E0000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
   918                              <1> 	;jz	short K29		;  NO, ALT STATE IS REAL
   919 0000111C 0F85DF000000        <1> 	jnz	K38			; YES, THIS IS PHONY ALT STATE 
   920                              <1>         ;				; DUE TO PRESSING SYSREQ	
   921                              <1> ;K28A:	jmp	short K38
   922                              <1> 	;
   923                              <1> 	;-----	TEST FOR RESET KEY SEQUENCE (CTL ALT DEL)
   924                              <1> K29:					; TEST-RESET
   925 00001122 F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT ALSO?
   926 00001125 740B                <1> 	jz	short K31		; NO_RESET
   927 00001127 3C53                <1> 	cmp	al, DEL_KEY		; CTL-ALT STATE, TEST FOR DELETE KEY
   928 00001129 7507                <1> 	jne	short K31		; NO_RESET, IGNORE
   929                              <1> 	;
   930                              <1> 	;-----	CTL-ALT-DEL HAS BEEN FOUND
   931                              <1>  	; 26/08/2014
   932                              <1> cpu_reset:
   933                              <1> 	; IBM PC/AT ROM BIOS source code - 10/06/85 (TEST4.ASM - PROC_SHUTDOWN)
   934                              <1> 	; Send FEh (system reset command) to the keyboard controller.
   935 0000112B B0FE                <1> 	mov	al, SHUT_CMD		; SHUTDOWN COMMAND
   936 0000112D E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROL PORT
   937                              <1> khere:
   938 0000112F F4                  <1> 	hlt				; WAIT FOR 80286 RESET
   939 00001130 EBFD                <1> 	jmp 	short khere		; INSURE HALT
   940                              <1> 
   941                              <1> 	;
   942                              <1> 	;-----	IN ALTERNATE SHIFT, RESET NOT FOUND
   943                              <1> K31:					; NO-RESET
   944 00001132 3C39                <1> 	cmp	al, 57			; TEST FOR SPACE KEY
   945 00001134 7507                <1> 	jne	short K311		; NOT THERE
   946 00001136 B020                <1> 	mov	al, ' '			; SET SPACE CHAR
   947 00001138 E948020000          <1>         jmp     K57                     ; BUFFER_FILL
   948                              <1> K311:
   949 0000113D 3C0F                <1> 	cmp	al, 15			; TEST FOR TAB KEY
   950 0000113F 7509                <1> 	jne	short K312		; NOT THERE
   951 00001141 66B800A5            <1> 	mov	ax, 0A500h		; SET SPECIAL CODE FOR ALT-TAB
   952 00001145 E93B020000          <1>         jmp     K57                     ; BUFFER_FILL
   953                              <1> K312:
   954 0000114A 3C4A                <1> 	cmp	al, 74			; TEST FOR KEY PAD -
   955 0000114C 0F84A2000000        <1>         je      K37B                    ; GO PROCESS
   956 00001152 3C4E                <1> 	cmp	al, 78			; TEST FOR KEY PAD +
   957 00001154 0F849A000000        <1>         je      K37B                    ; GO PROCESS
   958                              <1> 	;
   959                              <1> 	;-----	LOOK FOR KEY PAD ENTRY
   960                              <1> K32:					; ALT-KEY-PAD
   961 0000115A BF[805D0000]        <1> 	mov	edi, K30		; ALT-INPUT-TABLE offset
   962 0000115F B90A000000          <1> 	mov	ecx, 10			; LOOK FOR ENTRY USING KEYPAD
   963 00001164 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH
   964 00001166 7525                <1> 	jne	short K33		; NO_ALT_KEYPAD
   965 00001168 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF THE NEW KEYS?
   966 0000116B 0F858A000000        <1>         jnz     K37C                    ; YES, JUMP, NOT NUMPAD KEY
   967 00001171 81EF[815D0000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
   968 00001177 A0[C15E0000]        <1> 	mov	al, [ALT_INPUT] 	; GET THE CURRENT BYTE
   969 0000117C B40A                <1> 	mov	ah, 10			; MULTIPLY BY 10
   970 0000117E F6E4                <1> 	mul	ah
   971 00001180 6601F8              <1> 	add	ax, di			; ADD IN THE LATEST ENTRY
   972 00001183 A2[C15E0000]        <1> 	mov	[ALT_INPUT], al 	; STORE IT AWAY
   973                              <1> ;K32A:
   974 00001188 E959FFFFFF          <1>         jmp     K26                     ; THROW AWAY THAT KEYSTROKE
   975                              <1> 	;
   976                              <1> 	;-----	LOOK FOR SUPERSHIFT ENTRY
   977                              <1> K33:					; NO-ALT-KEYPAD
   978 0000118D C605[C15E0000]00    <1>         mov     byte [ALT_INPUT], 0     ; ZERO ANY PREVIOUS ENTRY INTO INPUT
   979 00001194 B91A000000          <1> 	mov	ecx, 26			; (DI),(ES) ALREADY POINTING
   980 00001199 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH IN ALPHABET
   981 0000119B 7450                <1> 	je	short K37A		; MATCH FOUND, GO FILLL THE BUFFER
   982                              <1> 	;
   983                              <1> 	;-----	LOOK FOR TOP ROW OF ALTERNATE SHIFT
   984                              <1> K34:					; ALT-TOP-ROW
   985 0000119D 3C02                <1> 	cmp	al, 2			; KEY WITH '1' ON IT
   986 0000119F 7253                <1> 	jb	short K37B		; MUST BE ESCAPE
   987 000011A1 3C0D                <1> 	cmp	al, 13			; IS IT IN THE REGION
   988 000011A3 7705                <1> 	ja	short K35		; NO, ALT SOMETHING ELSE
   989 000011A5 80C476              <1> 	add	ah, 118			; CONVERT PSEUDO SCAN CODE TO RANGE
   990 000011A8 EB43                <1> 	jmp	short K37A		; GO FILL THE BUFFER
   991                              <1> 	;
   992                              <1> 	;-----	TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
   993                              <1> K35:					; ALT-FUNCTION
   994 000011AA 3C57                <1> 	cmp	al, F11_M		; IS IT F11?	
   995 000011AC 7209                <1> 	jb	short K35A ; 20/02/2015	; NO, BRANCH
   996 000011AE 3C58                <1> 	cmp	al, F12_M		; IS IT F12?
   997 000011B0 7705                <1> 	ja	short K35A ; 20/02/2015	; NO, BRANCH
   998 000011B2 80C434              <1> 	add	ah, 52			; CONVERT TO PSEUDO SCAN CODE
   999 000011B5 EB36                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  1000                              <1> K35A:
  1001 000011B7 F6C702              <1> 	test	bh, LC_E0		; DO WE HAVE ONE OF THE NEW KEYS?
  1002 000011BA 7422                <1> 	jz	short K37		; NO, JUMP
  1003 000011BC 3C1C                <1> 	cmp	al, 28			; TEST FOR KEYPAD ENTER
  1004 000011BE 7509                <1>         jne     short K35B              ; NOT THERE
  1005 000011C0 66B800A6            <1> 	mov	ax, 0A600h		; SPECIAL CODE
  1006 000011C4 E9BC010000          <1> 	jmp	K57			; BUFFER FILL
  1007                              <1> K35B:
  1008 000011C9 3C53                <1> 	cmp	al, 83			; TEST FOR DELETE KEY
  1009 000011CB 742E                <1> 	je	short K37C		; HANDLE WITH OTHER EDIT KEYS
  1010 000011CD 3C35                <1> 	cmp	al, 53			; TEST FOR KEYPAD /
  1011                              <1> 	;jne	short K32A		; NOT THERE, NO OTHER E0 SPECIALS	
  1012 000011CF 0F8511FFFFFF        <1>         jne     K26
  1013 000011D5 66B800A4            <1> 	mov	ax, 0A400h		; SPECIAL CODE
  1014 000011D9 E9A7010000          <1> 	jmp	K57			; BUFFER FILL
  1015                              <1> K37:
  1016 000011DE 3C3B                <1> 	cmp	al, 59			; TEST FOR FUNCTION KEYS (F1)
  1017 000011E0 7212                <1>         jb      short K37B		; NO FN, HANDLE W/OTHER EXTENDED
  1018 000011E2 3C44                <1> 	cmp	al, 68			; IN KEYPAD REGION?
  1019                              <1>         ;ja	short K32A		; IF SO, IGNORE
  1020 000011E4 0F87FCFEFFFF        <1>         ja      K26
  1021 000011EA 80C42D              <1> 	add	ah, 45			; CONVERT TO PSEUDO SCAN CODE
  1022                              <1> K37A:
  1023 000011ED B000                <1> 	mov	al, 0			; ASCII CODE OF ZERO
  1024 000011EF E991010000          <1>         jmp     K57                     ; PUT IT IN THE BUFFER
  1025                              <1> K37B:
  1026 000011F4 B0F0                <1> 	mov	al, 0F0h		; USE SPECIAL ASCII CODE
  1027 000011F6 E98A010000          <1> 	jmp     K57                     ; PUT IT IN THE BUFFER
  1028                              <1> K37C:
  1029 000011FB 0450                <1> 	add	al, 80			; CONVERT SCAN CODE (EDIT KEYS)
  1030 000011FD 88C4                <1> 	mov	ah, al			; (SCAN CODE NOT IN AH FOR INSERT)
  1031 000011FF EBEC                <1> 	jmp     short K37A              ; PUT IT IN THE BUFFER
  1032                              <1> 	;
  1033                              <1> 	;-----	NOT IN ALTERNATE SHIFT
  1034                              <1> K38:					; NOT-ALT-SHIFT
  1035                              <1> 					; BL STILL HAS SHIFT FLAGS
  1036 00001201 F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT?
  1037                              <1> 	;jnz	short K38A		; YES, START PROCESSING	
  1038 00001204 0F84B0000000        <1>         jz      K44                     ; NOT-CTL-SHIFT
  1039                              <1> 	;
  1040                              <1> 	;-----	CONTROL SHIFT, TEST SPECIAL CHARACTERS
  1041                              <1> 	;-----	TEST FOR BREAK
  1042                              <1> K38A:
  1043 0000120A 3C46                <1> 	cmp	al, SCROLL_KEY		; TEST FOR BREAK
  1044 0000120C 7531                <1> 	jne	short K39		; JUMP, NO-BREAK
  1045 0000120E F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1046 00001211 7405                <1> 	jz	short K38B		; NO, BREAK IS VALID	
  1047 00001213 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1048 00001216 7427                <1> 	jz	short K39		; NO-BREAK, TEST FOR PAUSE	
  1049                              <1> K38B:
  1050 00001218 8B1D[CA5E0000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  1051 0000121E 891D[CE5E0000]      <1> 	mov	[BUFFER_TAIL], ebx
  1052 00001224 C605[BC5E0000]80    <1> 	mov	byte [BIOS_BREAK], 80h  ; TURN ON BIOS_BREAK BIT
  1053                              <1> 	;
  1054                              <1> 	;-----	ENABLE KEYBOARD
  1055 0000122B B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1056 0000122D E8BF010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1057                              <1> 	;
  1058                              <1> 	; CTRL+BREAK code here !!!
  1059                              <1> 	;INT	1BH			; BREAK INTERRUPT VECTOR
  1060                              <1> 	; 17/10/2015	
  1061 00001232 E8DF510000          <1> 	call	ctrlbrk ; control+break subroutine
  1062                              <1> 	;
  1063 00001237 6629C0              <1> 	sub	ax, ax			; PUT OUT DUMMY CHARACTER
  1064 0000123A E946010000          <1>         jmp     K57                     ; BUFFER_FILL
  1065                              <1> 	;
  1066                              <1> 	;-----	TEST FOR PAUSE
  1067                              <1> K39:					; NO_BREAK
  1068 0000123F F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1069 00001242 7537                <1> 	jnz	short K41		; YES, THEN THIS CAN'T BE PAUSE	
  1070 00001244 3C45                <1> 	cmp	al, NUM_KEY		; LOOK FOR PAUSE KEY
  1071 00001246 7533                <1> 	jne	short K41		; NO-PAUSE
  1072                              <1> K39P:
  1073 00001248 800D[BE5E0000]08    <1> 	or	byte [KB_FLAG_1], HOLD_STATE ; TURN ON THE HOLD FLAG
  1074                              <1> 	;
  1075                              <1> 	;-----	ENABLE KEYBOARD
  1076 0000124F B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1077 00001251 E89B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1078                              <1> K39A:
  1079 00001256 B020                <1> 	mov	al, EOI			; END OF INTERRUPT TO CONTROL PORT
  1080 00001258 E620                <1> 	out	20h, al ;out INTA00, al	; ALLOW FURTHER KEYSTROKE INTERRUPTS
  1081                              <1> 	;
  1082                              <1> 	;-----	DURING PAUSE INTERVAL, TURN COLOR CRT BACK ON
  1083 0000125A 803D[F25E0000]07    <1>         cmp     byte [CRT_MODE], 7      ; IS THIS BLACK AND WHITE CARD
  1084 00001261 740A                <1>         je      short K40              	; YES, NOTHING TO DO
  1085 00001263 66BAD803            <1> 	mov	dx, 03D8h		; PORT FOR COLOR CARD
  1086 00001267 A0[F35E0000]        <1>         mov     al, [CRT_MODE_SET] 	; GET THE VALUE OF THE CURRENT MODE
  1087 0000126C EE                  <1> 	out	dx, al			; SET THE CRT MODE, SO THAT CRT IS ON
  1088                              <1> 	;
  1089                              <1> K40:					; PAUSE-LOOP
  1090 0000126D F605[BE5E0000]08    <1>         test    byte [KB_FLAG_1], HOLD_STATE ; CHECK HOLD STATE FLAG
  1091 00001274 75F7                <1> 	jnz	short K40		; LOOP UNTIL FLAG TURNED OFF
  1092                              <1> 	;
  1093 00001276 E977FEFFFF          <1>         jmp     K27                     ; INTERRUPT_RETURN_NO_EOI
  1094                              <1>         ;
  1095                              <1> 	;-----	TEST SPECIAL CASE KEY 55
  1096                              <1> K41:					; NO-PAUSE
  1097 0000127B 3C37                <1> 	cmp	al, 55			; TEST FOR */PRTSC KEY
  1098 0000127D 7513                <1> 	jne	short K42		; NOT-KEY-55
  1099 0000127F F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1100 00001282 7405                <1> 	jz	short K41A		; NO, CTL-PRTSC IS VALID	
  1101 00001284 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1102 00001287 7421                <1> 	jz	short K42B		; NO, TRANSLATE TO A FUNCTION
  1103                              <1> K41A:	
  1104 00001289 66B80072            <1> 	mov	ax, 114*256		; START/STOP PRINTING SWITCH
  1105 0000128D E9F3000000          <1>         jmp     K57                     ; BUFFER_FILL
  1106                              <1> 	;
  1107                              <1> 	;-----	SET UP TO TRANSLATE CONTROL SHIFT
  1108                              <1> K42:					; NOT-KEY-55
  1109 00001292 3C0F                <1> 	cmp	al, 15			; IS IT THE TAB KEY?
  1110 00001294 7414                <1> 	je	short K42B		; YES, XLATE TO FUNCTION CODE
  1111 00001296 3C35                <1> 	cmp	al, 53			; IS IT THE / KEY?
  1112 00001298 750E                <1> 	jne	short K42A		; NO, NO MORE SPECIAL CASES	
  1113 0000129A F6C702              <1> 	test	bh, LC_E0		; YES, IS IT FROM THE KEY PAD?
  1114 0000129D 7409                <1> 	jz	short K42A		; NO, JUST TRANSLATE
  1115 0000129F 66B80095            <1> 	mov	ax, 9500h		; YES, SPECIAL CODE FOR THIS ONE
  1116 000012A3 E9DD000000          <1> 	jmp	K57			; BUFFER FILL	
  1117                              <1> K42A: 
  1118                              <1> 	;;mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1119 000012A8 3C3B                <1> 	cmp	al, 59			; IS IT IN CHARACTER TABLE?
  1120                              <1>         ;jb	short K45F              ; YES, GO TRANSLATE CHAR
  1121                              <1> 	;;jb	K56 ; 20/02/2015
  1122                              <1> 	;;jmp	K64 ; 20/02/2015
  1123                              <1> K42B:
  1124 000012AA BB[B45D0000]        <1> 	mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1125 000012AF 0F82AE000000        <1> 	jb	K56 ;; 20/02/2015	
  1126 000012B5 E9B9000000          <1> 	jmp	K64	
  1127                              <1>         ;
  1128                              <1> 	;-----	NOT IN CONTROL SHIFT
  1129                              <1> K44:					; NOT-CTL-SHIFT
  1130 000012BA 3C37                <1> 	cmp	al, 55			; PRINT SCREEN KEY?
  1131 000012BC 7528                <1> 	jne	short K45		; NOT PRINT SCREEN
  1132 000012BE F6C710              <1> 	test	bh, KBX			; IS THIS ENHANCED KEYBOARD?
  1133 000012C1 7407                <1> 	jz	short K44A		; NO, TEST FOR SHIFT STATE	
  1134 000012C3 F6C702              <1> 	test	bh, LC_E0		; YES, LAST CODE A MARKER?
  1135 000012C6 7507                <1> 	jnz	short K44B		; YES, IS PRINT SCREEN
  1136 000012C8 EB41                <1> 	jmp	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1137                              <1> K44A:
  1138 000012CA F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; NOT 101 KBD, SHIFT KEY DOWN?
  1139 000012CD 743C                <1> 	jz	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1140                              <1> 	;
  1141                              <1> 	;-----	ISSUE INTERRUPT TO INDICATE PRINT SCREEN FUNCTION
  1142                              <1> K44B:
  1143 000012CF B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1144 000012D1 E81B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1145 000012D6 B020                <1> 	mov	al, EOI			; END OF CURRENT INTERRUPT
  1146 000012D8 E620                <1> 	out	20h, al ;out INTA00, al	; SO FURTHER THINGS CAN HAPPEN
  1147                              <1> 	; Print Screen !!!		; ISSUE PRINT SCREEN INTERRUPT (INT 05h)
  1148                              <1> 	;PUSH 	BP			; SAVE POINTER
  1149                              <1> 	;INT 	5H			; ISSUE PRINT SCREEN INTERRUPT
  1150                              <1> 	;POP	BP			; RESTORE POINTER
  1151 000012DA 8025[C05E0000]FC    <1>         and     byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; ZERO OUT THESE FLAGS
  1152 000012E1 E90CFEFFFF          <1>         jmp     K27                     ; GO BACK WITHOUT EOI OCCURRING
  1153                              <1> 	;
  1154                              <1> 	;-----	HANDLE IN-CORE KEYS
  1155                              <1> K45:					; NOT-PRINT-SCREEN
  1156 000012E6 3C3A                <1> 	cmp	al, 58			; TEST FOR IN-CORE AREA
  1157 000012E8 7734                <1> 	ja	short K46		; JUMP IF NOT
  1158 000012EA 3C35                <1> 	cmp	al, 53			; IS THIS THE '/' KEY?
  1159 000012EC 7505                <1> 	jne	short K45A		; NO, JUMP
  1160 000012EE F6C702              <1> 	test	bh, LC_E0		; WAS THE LAST CODE THE MARKER?
  1161 000012F1 7518                <1> 	jnz	short K45C		; YES, TRANSLATE TO CHARACTER
  1162                              <1> K45A:
  1163 000012F3 B91A000000          <1> 	mov	ecx, 26			; LENGHT OF SEARCH
  1164 000012F8 BF[8A5D0000]        <1> 	mov	edi, K30+10		; POINT TO TABLE OF A-Z CHARS
  1165 000012FD F2AE                <1> 	repne	scasb			; IS THIS A LETTER KEY?
  1166                              <1> 		; 20/02/2015
  1167 000012FF 7505                <1> 	jne	short K45B              ; NO, SYMBOL KEY
  1168                              <1> 	;
  1169 00001301 F6C340              <1> 	test	bl, CAPS_STATE		; ARE WE IN CAPS_LOCK?
  1170 00001304 750C                <1> 	jnz	short K45D		; TEST FOR SURE
  1171                              <1> K45B:
  1172 00001306 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1173 00001309 750C                <1> 	jnz	short K45E		; YES, UPPERCASE
  1174                              <1> 					; NO, LOWERCASE
  1175                              <1> K45C:
  1176 0000130B BB[0C5E0000]        <1> 	mov	ebx, K10		; TRANSLATE TO LOWERCASE LETTERS
  1177 00001310 EB51                <1> 	jmp	short K56	
  1178                              <1> K45D:					; ALMOST-CAPS-STATE
  1179 00001312 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  1180 00001315 75F4                <1> 	jnz	short K45C		; SHIFTED TEMP OUT OF CAPS STATE
  1181                              <1> K45E:
  1182 00001317 BB[645E0000]        <1> 	mov	ebx, K11		; TRANSLATE TO UPPER CASE LETTERS
  1183 0000131C EB45                <1> K45F:	jmp	short K56
  1184                              <1> 	;
  1185                              <1> 	;-----	TEST FOR KEYS F1 - F10
  1186                              <1> K46:					; NOT IN-CORE AREA
  1187 0000131E 3C44                <1> 	cmp	al, 68			; TEST FOR F1 - F10
  1188                              <1> 	;ja	short K47		; JUMP IF NOT
  1189                              <1> 	;jmp	short K53		; YES, GO DO FN KEY PROCESS			
  1190 00001320 7635                <1> 	jna	short K53		
  1191                              <1> 	;
  1192                              <1> 	;-----	HANDLE THE NUMERIC PAD KEYS
  1193                              <1> K47:					; NOT F1 - F10
  1194 00001322 3C53                <1> 	cmp	al, 83			; TEST NUMPAD KEYS
  1195 00001324 772D                <1> 	ja	short K52		; JUMP IF NOT
  1196                              <1> 	;
  1197                              <1> 	;-----	KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  1198                              <1> K48:
  1199 00001326 3C4A                <1> 	cmp	al , 74			; SPECIAL CASE FOR MINUS
  1200 00001328 74ED                <1> 	je	short K45E		; GO TRANSLATE
  1201 0000132A 3C4E                <1> 	cmp	al , 78			; SPECIAL CASE FOR PLUS
  1202 0000132C 74E9                <1> 	je	short K45E		; GO TRANSLATE
  1203 0000132E F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OFTHE NEW KEYS?
  1204 00001331 750A                <1> 	jnz	short K49		; YES, TRANSLATE TO BASE STATE
  1205                              <1> 	;		
  1206 00001333 F6C320              <1> 	test 	bl, NUM_STATE		; ARE WE IN NUM LOCK
  1207 00001336 7514                <1> 	jnz	short K50		; TEST FOR SURE
  1208 00001338 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1209                              <1> 	;jnz	short K51		; IF SHIFTED, REALLY NUM STATE
  1210 0000133B 75DA                <1> 	jnz	short K45E
  1211                              <1> 	;
  1212                              <1> 	;-----	BASE CASE FOR KEYPAD
  1213                              <1> K49:					
  1214 0000133D 3C4C                <1> 	cmp	al, 76			; SPECIAL CASE FOR BASE STATE 5
  1215 0000133F 7504                <1> 	jne	short K49A		; CONTINUE IF NOT KEYPAD 5
  1216 00001341 B0F0                <1> 	mov	al, 0F0h		; SPECIAL ASCII CODE	
  1217 00001343 EB40                <1> 	jmp	short K57		; BUFFER FILL
  1218                              <1> K49A:
  1219 00001345 BB[0C5E0000]        <1> 	mov	ebx, K10		; BASE CASE TABLE	
  1220 0000134A EB27                <1> 	jmp	short K64		; CONVERT TO PSEUDO SCAN
  1221                              <1> 	;
  1222                              <1> 	;-----	MIGHT BE NUM LOCK, TEST SHIFT STATUS
  1223                              <1> K50:					; ALMOST-NUM-STATE
  1224 0000134C F6C303              <1>         test    bl, LEFT_SHIFT+RIGHT_SHIFT
  1225 0000134F 75EC                <1> 	jnz 	short K49		; SHIFTED TEMP OUT OF NUM STATE
  1226 00001351 EBC4                <1> K51:	jmp	short K45E		; REALLY NUM STATE
  1227                              <1> 	;
  1228                              <1> 	;-----	TEST FOR THE NEW KEYS ON WT KEYBOARDS 
  1229                              <1> K52:					; NOT A NUMPAD KEY
  1230 00001353 3C56                <1> 	cmp	al, 86			; IS IT THE NEW WT KEY?
  1231                              <1> 	;jne	short K53		; JUMP IF NOT
  1232                              <1> 	;jmp	short K45B		; HANDLE WITH REST OF LETTER KEYS
  1233 00001355 74AF                <1> 	je	short K45B		
  1234                              <1> 	;
  1235                              <1> 	;-----	MUST BE F11 OR F12 
  1236                              <1> K53:					; F1 - F10 COME HERE, TOO
  1237 00001357 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST SHIFT STATE
  1238 0000135A 74E1                <1> 	jz	short K49		; JUMP, LOWER CASE PSEUDO SC'S
  1239                              <1> 		; 20/02/2015 
  1240 0000135C BB[645E0000]        <1> 	mov	ebx, K11		; UPPER CASE PSEUDO SCAN CODES
  1241 00001361 EB10                <1> 	jmp	short K64		; TRANSLATE SCAN
  1242                              <1> 	;
  1243                              <1> 	;-----	TRANSLATE THE CHARACTER
  1244                              <1> K56:					; TRANSLATE-CHAR
  1245 00001363 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1246 00001365 D7                  <1> 	xlat    			; CONVERT THE SCAN CODE TO ASCII
  1247 00001366 F605[C05E0000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1248 0000136D 7416                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1249 0000136F B4E0                <1> 	mov	ah, MC_E0		; YES, PUT SPECIAL MARKER IN AH
  1250 00001371 EB12                <1> 	jmp	short K57		; PUT IT INTO THE BUFFER	
  1251                              <1> 	;
  1252                              <1> 	;-----	TRANSLATE SCAN FOR PSEUDO SCAN CODES
  1253                              <1> K64:					; TRANSLATE-SCAN-ORGD
  1254 00001373 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1255 00001375 D7                  <1>        	xlat    	                ; CTL TABLE SCAN
  1256 00001376 88C4                <1> 	mov	ah, al			; PUT VALUE INTO AH
  1257 00001378 B000                <1> 	mov	al, 0			; ZERO ASCII CODE
  1258 0000137A F605[C05E0000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1259 00001381 7402                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1260 00001383 B0E0                <1> 	mov	al, MC_E0		; YES, PUT SPECIAL MARKER IN AL
  1261                              <1> 	;
  1262                              <1> 	;-----	PUT CHARACTER INTO BUFFER
  1263                              <1> K57:					; BUFFER_FILL
  1264 00001385 3CFF                <1> 	cmp	al, -1			; IS THIS AN IGNORE CHAR
  1265                              <1>         ;je	short K59		; YES, DO NOTHING WITH IT
  1266 00001387 0F8459FDFFFF        <1> 	je      K26			; YES, DO NOTHING WITH IT
  1267 0000138D 80FCFF              <1> 	cmp	ah, -1			; LOOK FOR -1 PSEUDO SCAN
  1268                              <1>         ;jne	short K61		; NEAR_INTERRUPT_RETURN
  1269 00001390 0F8450FDFFFF        <1> 	je      K26			; INTERRUPT_RETURN
  1270                              <1> ;K59:					; NEAR_INTERRUPT_RETURN
  1271                              <1> ;	jmp	K26			; INTERRUPT_RETURN
  1272                              <1> 
  1273                              <1> _K60: ; 29/01/2016
  1274 00001396 80FC68              <1> 	cmp	ah, 68h	; ALT + F1 key
  1275 00001399 721F                <1> 	jb	short K61
  1276 0000139B 80FC6F              <1> 	cmp	ah, 6Fh ; ALT + F8 key	
  1277 0000139E 771A                <1> 	ja	short K61
  1278                              <1> 	;
  1279 000013A0 8A1D[D6580100]      <1> 	mov	bl, [ACTIVE_PAGE]
  1280 000013A6 80C368              <1> 	add	bl, 68h
  1281 000013A9 38E3                <1> 	cmp	bl, ah
  1282 000013AB 740D                <1> 	je	short K61
  1283 000013AD 6650                <1> 	push	ax
  1284 000013AF 88E0                <1> 	mov	al, ah
  1285 000013B1 2C68                <1> 	sub	al, 68h
  1286 000013B3 E8F4050000          <1> 	call	set_active_page
  1287 000013B8 6658                <1> 	pop	ax
  1288                              <1> K61:					; NOT-CAPS-STATE
  1289 000013BA 8B1D[CE5E0000]      <1> 	mov	ebx, [BUFFER_TAIL] 	; GET THE END POINTER TO THE BUFFER
  1290 000013C0 89DE                <1> 	mov	esi, ebx		; SAVE THE VALUE
  1291 000013C2 E857FAFFFF          <1> 	call	_K4			; ADVANCE THE TAIL
  1292 000013C7 3B1D[CA5E0000]      <1> 	cmp	ebx, [BUFFER_HEAD] 	; HAS THE BUFFER WRAPPED AROUND
  1293 000013CD 740E                <1> 	je	short K62		; BUFFER_FULL_BEEP
  1294 000013CF 668906              <1> 	mov	[esi], ax		; STORE THE VALUE
  1295 000013D2 891D[CE5E0000]      <1> 	mov	[BUFFER_TAIL], ebx 	; MOVE THE POINTER UP
  1296 000013D8 E909FDFFFF          <1> 	jmp	K26
  1297                              <1> 	;;cli				; TURN OFF INTERRUPTS
  1298                              <1> 	;;mov	al, EOI			; END OF INTERRUPT COMMAND
  1299                              <1> 	;;out	INTA00, al		; SEND COMMAND TO INTERRUPT CONTROL PORT
  1300                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1301                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  1302                              <1> 	;MOV	AX, 9102H		; MOVE IN POST CODE & TYPE
  1303                              <1> 	;INT	15H			; PERFORM OTHER FUNCTION
  1304                              <1> 	;;and	byte [KB_FLAG_3],~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  1305                              <1> 	;JMP	K27A			; INTERRUPT_RETURN
  1306                              <1> 	;;jmp   K27                    
  1307                              <1> 	;
  1308                              <1> 	;-----	BUFFER IS FULL SOUND THE BEEPER
  1309                              <1> K62:
  1310 000013DD B020                <1> 	mov	al, EOI			; ENABLE INTERRUPT CONTROLLER CHIP
  1311 000013DF E620                <1> 	out	INTA00, al
  1312 000013E1 66B9A602            <1> 	mov	cx, 678			; DIVISOR FOR 1760 HZ
  1313 000013E5 B304                <1> 	mov	bl, 4			; SHORT BEEP COUNT (1/16 + 1/64 DELAY)
  1314 000013E7 E8E5090000          <1> 	call	beep			; GO TO COMMON BEEP HANDLER
  1315 000013EC E901FDFFFF          <1> 	jmp     K27			; EXIT   
  1316                              <1> 
  1317                              <1> SHIP_IT:
  1318                              <1> 	;---------------------------------------------------------------------------------
  1319                              <1> 	; SHIP_IT
  1320                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1321                              <1> 	;	TO THE KEYBOARD CONTROLLER.
  1322                              <1> 	;---------------------------------------------------------------------------------
  1323                              <1> 	;
  1324 000013F1 6650                <1> 	push	ax			; SAVE DATA TO SEND
  1325                              <1> 
  1326                              <1> 	;-----	WAIT FOR COMMAND TO ACCEPTED
  1327 000013F3 FA                  <1> 	cli				; DISABLE INTERRUPTS TILL DATA SENT
  1328                              <1> 	; xor	ecx, ecx		; CLEAR TIMEOUT COUNTER
  1329 000013F4 B900000100          <1> 	mov	ecx, 10000h			
  1330                              <1> S10:
  1331 000013F9 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD CONTROLLER STATUS
  1332 000013FB A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ITS INPUT BUFFER BUSY
  1333 000013FD E0FA                <1> 	loopnz	S10			; WAIT FOR COMMAND TO BE ACCEPTED
  1334                              <1> 
  1335 000013FF 6658                <1> 	pop	ax			; GET DATA TO SEND
  1336 00001401 E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROLLER
  1337 00001403 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  1338 00001404 C3                  <1> 	retn				; RETURN TO CALLER
  1339                              <1> 
  1340                              <1> SND_DATA:
  1341                              <1> 	; ---------------------------------------------------------------------------------
  1342                              <1> 	; SND_DATA
  1343                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1344                              <1> 	;	TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  1345                              <1> 	;	HANDLES ANY RETRIES IF REQUIRED
  1346                              <1> 	; ---------------------------------------------------------------------------------
  1347                              <1> 	;
  1348 00001405 6650                <1> 	push	ax			; SAVE REGISTERS
  1349 00001407 6653                <1> 	push	bx
  1350 00001409 51                  <1> 	push	ecx
  1351 0000140A 88C7                <1> 	mov	bh, al			; SAVE TRANSMITTED BYTE FOR RETRIES
  1352 0000140C B303                <1> 	mov	bl, 3			; LOAD RETRY COUNT
  1353                              <1> SD0:
  1354 0000140E FA                  <1> 	cli				; DISABLE INTERRUPTS
  1355 0000140F 8025[BF5E0000]CF    <1> 	and	byte [KB_FLAG_2], ~(KB_FE+KB_FA) ; CLEAR ACK AND RESEND FLAGS
  1356                              <1> 	;
  1357                              <1> 	;-----	WAIT FOR COMMAND TO BE ACCEPTED
  1358 00001416 B900000100          <1> 	mov	ecx, 10000h		; MAXIMUM WAIT COUNT
  1359                              <1> SD5:
  1360 0000141B E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD PROCESSOR STATUS PORT
  1361 0000141D A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ANY PENDING COMMAND
  1362 0000141F E0FA                <1> 	loopnz	SD5			; WAIT FOR COMMAND TO BE ACCEPTED
  1363                              <1> 	;
  1364 00001421 88F8                <1> 	mov	al, bh			; REESTABLISH BYTE TO TRANSMIT
  1365 00001423 E660                <1> 	out	PORT_A, al		; SEND BYTE
  1366 00001425 FB                  <1> 	sti				; ENABLE INTERRUPTS
  1367                              <1> 	;mov	cx, 01A00h		; LOAD COUNT FOR 10 ms+
  1368 00001426 B9FFFF0000          <1> 	mov	ecx, 0FFFFh
  1369                              <1> SD1:
  1370 0000142B F605[BF5E0000]30    <1> 	test	byte [KB_FLAG_2], KB_FE+KB_FA ; SEE IF EITHER BIT SET
  1371 00001432 750F                <1> 	jnz	short SD3		; IF SET, SOMETHING RECEIVED GO PROCESS
  1372 00001434 E2F5                <1> 	loop	SD1			; OTHERWISE WAIT
  1373                              <1> SD2:
  1374 00001436 FECB                <1> 	dec	bl			; DECREMENT RETRY COUNT
  1375 00001438 75D4                <1> 	jnz	short SD0		; RETRY TRANSMISSION
  1376 0000143A 800D[BF5E0000]80    <1> 	or	byte [KB_FLAG_2], KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  1377 00001441 EB09                <1> 	jmp	short SD4		; RETRIES EXHAUSTED FORGET TRANSMISSION
  1378                              <1> SD3:
  1379 00001443 F605[BF5E0000]10    <1> 	test	byte [KB_FLAG_2], KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  1380 0000144A 74EA                <1> 	jz	short SD2		; IF NOT, GO RESEND
  1381                              <1> SD4:	
  1382 0000144C 59                  <1> 	pop	ecx			; RESTORE REGISTERS
  1383 0000144D 665B                <1> 	pop	bx
  1384 0000144F 6658                <1> 	pop	ax
  1385 00001451 C3                  <1> 	retn				; RETURN, GOOD TRANSMISSION
  1386                              <1> 
  1387                              <1> SND_LED:
  1388                              <1> 	; ---------------------------------------------------------------------------------
  1389                              <1> 	; SND_LED
  1390                              <1> 	;	THIS ROUTINES TURNS ON THE MODE INDICATORS.
  1391                              <1> 	;
  1392                              <1> 	;----------------------------------------------------------------------------------
  1393                              <1> 	;
  1394 00001452 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1395 00001453 F605[BF5E0000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1396 0000145A 755F                <1> 	jnz 	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1397                              <1> 	;
  1398 0000145C 800D[BF5E0000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1399 00001463 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  1400 00001465 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  1401 00001467 EB11                <1> 	jmp	short SL0		; GO SEND MODE INDICATOR COMMAND
  1402                              <1> SND_LED1:
  1403 00001469 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1404 0000146A F605[BF5E0000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1405 00001471 7548                <1> 	jnz	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1406                              <1> 	;
  1407 00001473 800D[BF5E0000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1408                              <1> SL0:
  1409 0000147A B0ED                <1> 	mov	al, LED_CMD		; LED CMD BYTE
  1410 0000147C E884FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1411 00001481 FA                  <1> 	cli
  1412 00001482 E836000000          <1> 	call	MAKE_LED		; GO FORM INDICATOR DATA BYTE
  1413 00001487 8025[BF5E0000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  1414 0000148E 0805[BF5E0000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  1415 00001494 F605[BF5E0000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1416 0000149B 750F                <1> 	jnz	short SL2		; IF SO, BYPASS SECOND BYTE TRANSMISSION
  1417                              <1> 	;
  1418 0000149D E863FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1419 000014A2 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1420 000014A3 F605[BF5E0000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1421 000014AA 7408                <1> 	jz	short SL3		; IF NOT, DON'T SEND AN ENABLE COMMAND
  1422                              <1> SL2:
  1423 000014AC B0F4                <1> 	mov	al, KB_ENABLE		; GET KEYBOARD CSA ENABLE COMMAND
  1424 000014AE E852FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1425 000014B3 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1426                              <1> SL3:
  1427 000014B4 8025[BF5E0000]3F    <1> 	and	byte [KB_FLAG_2], ~(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  1428                              <1> SL1:					; UPDATE AND TRANSMIT ERROR FLAG
  1429 000014BB FB                  <1> 	sti				; ENABLE INTERRUPTS
  1430 000014BC C3                  <1> 	retn				; RETURN TO CALLER
  1431                              <1> 
  1432                              <1> MAKE_LED:
  1433                              <1> 	;---------------------------------------------------------------------------------
  1434                              <1> 	; MAKE_LED
  1435                              <1> 	;	THIS ROUTINES FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  1436                              <1> 	;	THE MODE INDICATORS.
  1437                              <1> 	;---------------------------------------------------------------------------------
  1438                              <1> 	;
  1439                              <1> 	;push 	cx			; SAVE CX
  1440 000014BD A0[BD5E0000]        <1> 	mov	al, [KB_FLAG]		; GET CAPS & NUM LOCK INDICATORS
  1441 000014C2 2470                <1> 	and	al, CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  1442                              <1> 	;mov	cl, 4			; SHIFT COUNT
  1443                              <1> 	;rol	al, cl			; SHIFT BITS OVER TO TURN ON INDICATORS
  1444 000014C4 C0C004              <1> 	rol	al, 4 ; 20/02/2015
  1445 000014C7 2407                <1> 	and	al, 07h			; MAKE SURE ONLY MODE BITS ON
  1446                              <1> 	;pop	cx
  1447 000014C9 C3                  <1> 	retn				; RETURN TO CALLER
  1448                              <1> 
  1449                              <1> ; % include 'kybdata.s'   ; KEYBOARD DATA
  1450                              <1> 
  1451                              <1> 
  1452                              <1> ; /// End Of KEYBOARD FUNCTIONS ///
  1940                                  
  1941                                  %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: 09/12/2017
     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 000014CA 9C                  <1> 	pushfd
    35 000014CB 0E                  <1> 	push 	cs
    36 000014CC E851000000          <1> 	call 	VIDEO_IO_1
    37 000014D1 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 000014D2 [7F150000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
   191 000014D6 [E7180000]          <1> 	dd	SET_CTYPE
   192 000014DA [1B190000]          <1> 	dd	SET_CPOS
   193 000014DE [43190000]          <1> 	dd	READ_CURSOR
   194                              <1> 	;dd	VIDEO_RETURN	; READ_LPEN
   195 000014E2 [68150000]          <1> 	dd	set_mode_ncm	; Set mode without clearing video memory
   196 000014E6 [89190000]          <1> 	dd	ACT_DISP_PAGE
   197 000014EA [201A0000]          <1> 	dd	SCROLL_UP
   198 000014EE [441B0000]          <1> 	dd	SCROLL_DOWN
   199 000014F2 [C51B0000]          <1> 	dd	READ_AC_CURRENT
   200 000014F6 [1D1C0000]          <1> 	dd	WRITE_AC_CURRENT
   201 000014FA [431C0000]          <1> 	dd	WRITE_C_CURRENT
   202 000014FE [69250000]          <1> 	dd	SET_COLOR
   203 00001502 [D4250000]          <1> 	dd	WRITE_DOT
   204 00001506 [9F250000]          <1> 	dd	READ_DOT
   205 0000150A [C51C0000]          <1> 	dd	WRITE_TTY
   206 0000150E [50150000]          <1> 	dd	VIDEO_STATE
   207 00001512 [1F2F0000]          <1> 	dd	vga_pal_funcs ; 10/08/2016 (TRDOS 386)
   208 00001516 [D52A0000]          <1> 	dd	font_setup    ; 10/07/2016 (TRDOS 386)
   209 0000151A [84150000]          <1> 	dd	VIDEO_RETURN	; RESERVED
   210 0000151E [321E0000]          <1> 	dd	WRITE_STRING  ; 23/06/2016 (TRDOS 386)
   211                              <1> M1L	EQU	$ - M1
   212                              <1> 
   213                              <1> ; 14/01/2017
   214                              <1> ; 02/01/2017
   215                              <1> ; 04/07/2016
   216                              <1> ; 12/05/2016
   217                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   218                              <1> int31h:  ; Video BIOS
   219                              <1> 
   220                              <1> ; BH = Video page number
   221                              <1> ; BL = Color/Attribute
   222                              <1> ; AH = Function number
   223                              <1> ; AL = Character
   224                              <1> 
   225                              <1> VIDEO_IO_1:
   226                              <1> 	;sti				; INTERRUPTS BACK ON
   227 00001522 FC                  <1> 	cld				; SET DIRECTION FORWARD
   228 00001523 80FC14              <1> 	cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
   229 00001526 7327                <1> 	jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
   230                              <1> 
   231 00001528 06                  <1> 	push	es
   232 00001529 1E                  <1> 	push	ds			; SAVE WORK AND PARAMETER REGISTERS
   233 0000152A 52                  <1> 	push	edx
   234 0000152B 51                  <1> 	push	ecx
   235 0000152C 53                  <1> 	push	ebx
   236 0000152D 56                  <1> 	push	esi
   237 0000152E 57                  <1> 	push	edi
   238 0000152F 55                  <1> 	push	ebp
   239                              <1> 
   240 00001530 66BE1000            <1> 	mov	si, KDATA 		; POINT DS: TO DATA SEGMENT
   241 00001534 8EDE                <1> 	mov	ds, si
   242 00001536 8EC6                <1> 	mov	es, si
   243 00001538 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
   244 0000153D A3[28650100]        <1> 	mov	[video_eax], eax ; 12/05/2016 
   245                              <1> 	; 23/03/2016
   246 00001542 C0E402              <1> 	shl	ah, 2  ; dword		; TIMES 2 FOR WORD TABLE LOOKUP
   247 00001545 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
   248                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
   249                              <1> 
   250                              <1> 	;;15/01/2017
   251                              <1> 	; 14/01/2017
   252                              <1> 	; 02/01/2017
   253                              <1> 	;;mov	byte [intflg], 31h  ; video interrupt
   254 00001548 FB                  <1> 	sti
   255                              <1> 	;
   256                              <1> 
   257 00001549 FFA6[D2140000]      <1> 	JMP	dword [esi+M1]		; GO TO SELECTED FUNCTION
   258                              <1> 
   259                              <1> M4:					; COMMAND NOT VALID
   260 0000154F CF                  <1> 	iretd				; DO NOTHING IF NOT IN VALID RANGE
   261                              <1> 
   262                              <1> VIDEO_STATE:
   263                              <1> 	; 26/06/2016
   264                              <1> 	; 12/05/2016
   265                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   266                              <1> 
   267                              <1> ;---------------------------------------------------
   268                              <1> ; VIDEO STATE
   269                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
   270                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
   271                              <1> ;  AL = CURRENT VIDEO MODE
   272                              <1> ;  BH = CURRENT ACTIVE PAGE
   273                              <1> ;---------------------------------------------------
   274                              <1> 
   275 00001550 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
   276 00001556 A0[F25E0000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
   277                              <1> 	;movzx	esi, al
   278                              <1> 	;mov	ah, [esi+M6] 
   279                              <1> 	; BH = active page
   280 0000155B 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
   281 00001561 FA                  <1> 	cli	; 02/01/2017
   282 00001562 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
   283 00001563 5F                  <1> 	pop	edi
   284 00001564 5E                  <1> 	pop	esi
   285 00001565 59                  <1> 	pop	ecx		; DISCARD SAVED BX
   286 00001566 EB26                <1> 	jmp	short M15	; RETURN TO CALLER
   287                              <1> 
   288                              <1> set_mode_ncm:
   289                              <1> 	; 04/07/2016 - TRDOS 386 (TRDOS v2.0)
   290                              <1> 	; set mode without clearing the video memory
   291                              <1> 	; (ony for graphics modes)
   292 00001568 3C07                <1> 	cmp	al, 7 ; IBM PC CGA modes
   293 0000156A 7613                <1> 	jna	short SET_MODE ; normal function (clear)
   294                              <1> 	; do not clear memory
   295 0000156C A2[37650100]        <1> 	mov	[noclearmem], al ; > 0
   296 00001571 E81F000000          <1> 	call	_set_mode
   297 00001576 C605[37650100]00    <1> 	mov	byte [noclearmem], 0
   298 0000157D EB05                <1>         jmp     short VIDEO_RETURN
   299                              <1> 
   300                              <1> 	; 10/08/2016
   301                              <1> 	; 08/08/2016
   302                              <1> 	; 30/07/2016
   303                              <1> 	; 29/07/2016
   304                              <1> 	; 27/07/2016
   305                              <1> 	; 26/07/2016
   306                              <1> 	; 25/07/2016
   307                              <1> 	; 23/07/2016
   308                              <1> 	; 18/07/2016
   309                              <1> 	; 02/07/2016
   310                              <1> 	; 26/06/2016
   311                              <1> 	; 24/06/2016
   312                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
   313                              <1> SET_MODE:
   314                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
   315                              <1> 	;	valid video mode: 03h only!
   316                              <1> 	;	(VGA modes will be selected with another routine)
   317                              <1> 	;
   318                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
   319                              <1> 
   320                              <1> ;------------------------------------------------------
   321                              <1> ; SET MODE					      :
   322                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
   323                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
   324                              <1> ; INPUT						      :
   325                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
   326                              <1> ; OUTPUT					      :
   327                              <1> ;	NONE					      :
   328                              <1> ;------------------------------------------------------
   329                              <1> 
   330 0000157F E811000000          <1> 	call	_set_mode ; 24/06/2016 (set_txt_mode)
   331                              <1> 
   332                              <1> ; 12/05/2016
   333                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   334                              <1> 
   335                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
   336                              <1> 
   337                              <1> VIDEO_RETURN:
   338 00001584 A1[28650100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
   339                              <1> _video_return:
   340 00001589 FA                  <1> 	cli ; 02/01/2017
   341 0000158A 5D                  <1> 	pop	ebp
   342 0000158B 5F                  <1> 	pop	edi
   343 0000158C 5E                  <1> 	pop	esi
   344 0000158D 5B                  <1> 	pop	ebx
   345                              <1> M15:	; VIDEO_RETURN_C
   346                              <1> 	;;15/01/2017
   347                              <1> 	; 02/01/2017
   348                              <1> 	;;mov	byte [intflg], 0
   349                              <1> 	;
   350 0000158E 59                  <1> 	pop	ecx
   351 0000158F 5A                  <1> 	pop	edx
   352 00001590 1F                  <1> 	pop	ds
   353 00001591 07                  <1> 	pop	es	; RECOVER SEGMENTS
   354 00001592 CF                  <1> 	iretd		; ALL DONE
   355                              <1> 
   356                              <1> set_txt_mode:
   357                              <1> 	; 29/07/2016
   358                              <1> 	; 27/06/2016
   359 00001593 B003                <1> 	mov	al, 3
   360                              <1> 
   361                              <1> ; 10/08/2016
   362                              <1> ; 08/08/2016
   363                              <1> ; 30/07/2016
   364                              <1> ; 29/07/2016
   365                              <1> ; 27/07/2016
   366                              <1> ; 26/07/2016
   367                              <1> ; 25/07/2016
   368                              <1> ; 23/07/2016
   369                              <1> ; 18/07/2016
   370                              <1> ; 07/07/2016
   371                              <1> ; 04/07/2016
   372                              <1> ; 03/07/2016
   373                              <1> ; 02/07/2016
   374                              <1> ; 26/06/2016
   375                              <1> ; 24/06/2016 (set_txt_mode -> _set_mode)
   376                              <1> ; 17/06/2016
   377                              <1> ; 29/05/2016
   378                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   379                              <1> _set_mode:
   380                              <1> 	; 24/06/2016
   381 00001595 3805[F25E0000]      <1> 	cmp	[CRT_MODE], al  ; current mode = requested mode ?
   382 0000159B 750D                <1> 	jne	short _sm_0
   383 0000159D 3C03                <1> 	cmp	al, 3		; text, 80*25 color, default mode
   384                              <1> 				; for TRDOS 386 MainProg
   385 0000159F 755F                <1>         jne     short _sm_2	;  multiscreen is only for mode 3
   386                              <1> 
   387                              <1> 	; If '_set_mode' procedure is called for video mode 3
   388                              <1> 	;     while video mode is 3, video page will be cleared
   389                              <1> 	;     and cursor position of video page will be reset.	  
   390                              <1> 	
   391                              <1> 	; 29/07/2016
   392 000015A1 800D[35650100]80    <1> 	or	byte [p_crt_mode], 80h ; clear page indicator
   393 000015A8 EB5B                <1>         jmp     short _sm_3
   394                              <1> _sm_0:  
   395 000015AA 803D[F25E0000]03    <1> 	cmp	byte [CRT_MODE], 3
   396 000015B1 7534                <1>         jne     short _sm_1
   397                              <1> 
   398                              <1> 	; If '_set_mode' procedure is called for a video mode
   399                              <1> 	;     except video mode 3, while current video mode
   400                              <1> 	;     is 3; all video pages of mode 3 will be copied 
   401                              <1> 	;     to 98000h address as backup, before mode change.	
   402                              <1> 
   403                              <1> _sm_save_pm:
   404                              <1> 	; 03/07/2016
   405                              <1> 	; save video pages
   406 000015B3 BE00800B00          <1> 	mov	esi, 0B8000h
   407 000015B8 BF00800900          <1> 	mov	edi, 98000h ; 30/07/2016
   408 000015BD B900200000          <1> 	mov	ecx, (0B8000h-0B0000h)/4
   409 000015C2 F3A5                <1> 	rep	movsd
   410                              <1> 
   411 000015C4 C605[35650100]03    <1> 	mov	byte [p_crt_mode], 3 ; previous mode, backup sign
   412                              <1> 	;mov	cl, [ACTIVE_PAGE]
   413                              <1> 	;mov	[p_crt_page], cl
   414                              <1> 
   415                              <1> 	; save cursor positions
   416 000015CB BE[C6580100]        <1> 	mov	esi, CURSOR_POSN
   417 000015D0 BF[3A650100]        <1> 	mov	edi, cursor_pposn    ; cursor positions backup
   418 000015D5 B104                <1> 	mov	cl, 4
   419 000015D7 F3A5                <1> 	rep	movsd
   420                              <1> 
   421                              <1> 	; 29/07/2016
   422                              <1> 	;mov	[ACTIVE_PAGE], cl ; 0
   423 000015D9 860D[D6580100]      <1> 	xchg	cl, [ACTIVE_PAGE]
   424 000015DF 880D[36650100]      <1> 	mov	[p_crt_page], cl     ; previous page (for mode 3)	
   425                              <1> 	; [ACTIVE_PAGE] = 0 
   426 000015E5 EB19                <1> 	jmp	short _sm_2
   427                              <1> 
   428                              <1> _sm_1:
   429 000015E7 3C03                <1> 	cmp	al, 3		; text, 80*25 color, default mode
   430                              <1> 				; for TRDOS 386 MainProg
   431 000015E9 7515                <1> 	jne	short _sm_2  ;  multiscreen is only for mode 3
   432                              <1> 
   433                              <1> 	; If '_set_mode' procedure is called for video mode 3
   434                              <1> 	;     while video mode is not 3 and if there is video
   435                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
   436                              <1> 	;     video pages will be restored from 98000h.
   437                              <1> 
   438 000015EB 803D[35650100]03    <1> 	cmp	byte [p_crt_mode], 3 ; previous mode, backup sign
   439 000015F2 750C                <1> 	jne	short _sm_2 ; there is no (multiscreen) video pages
   440                              <1> 			 ; to be restored
   441 000015F4 8A0D[36650100]      <1> 	mov	cl, [p_crt_page]
   442 000015FA 880D[D6580100]      <1> 	mov	[ACTIVE_PAGE], cl
   443                              <1> 
   444                              <1> _sm_2:
   445 00001600 A2[F25E0000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
   446                              <1> _sm_3:
   447                              <1> 	; 30/07/2016
   448                              <1> 	; 26/07/2016
   449                              <1> 	; 25/07/2016
   450                              <1> 	; set_mode_vga:
   451                              <1> 	; 18/07/2016
   452                              <1> 	; 14/07/2016
   453                              <1> 	; 09/07/2016
   454                              <1> 	; 04/07/2016
   455                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
   456                              <1> 	; /// video mode 13h ///
   457                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   458                              <1> 	; vgabios-0.7a (2011)
   459                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
   460                              <1> 	; 'vgabios.c', 'vgatables.h'
   461                              <1> 	;
   462                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
   463                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
   464                              <1> 	;
   465 00001605 88C4                <1> 	mov	ah, al
   466 00001607 B910000000          <1> 	mov	ecx, vga_mode_count 	
   467 0000160C BE[0E5F0000]        <1> 	mov	esi, vga_modes
   468 00001611 31DB                <1> 	xor	ebx, ebx
   469                              <1> _sm_4:
   470 00001613 AC                  <1> 	lodsb
   471 00001614 38C4                <1> 	cmp	ah, al
   472 00001616 740C                <1> 	je	short _sm_5
   473 00001618 FEC3                <1> 	inc	bl
   474 0000161A E2F7                <1> 	loop	_sm_4
   475                              <1> 
   476                              <1> 	; UNIMPLEMENTED VIDEO MODE !
   477 0000161C 31C0                <1> 	xor	eax, eax
   478 0000161E A3[28650100]        <1>         mov     [video_eax], eax ; 0 
   479 00001623 C3                  <1> 	retn
   480                              <1> 
   481                              <1> ;-----	eBX POINTS TO CORRECT ROW OF INITIALIZATION TABLE	
   482                              <1> 
   483                              <1> _sm_5: 	; 25/07/2016
   484 00001624 89DE                <1> 	mov	esi, ebx
   485 00001626 81C6[5E5F0000]      <1> 	add	esi, vga_memmodel
   486 0000162C 8A06                <1> 	mov	al, [esi]
   487 0000162E A2[4E650100]        <1> 	mov	[VGA_MTYPE], al
   488                              <1> 
   489 00001633 89DF                <1> 	mov	edi, ebx
   490 00001635 81C7[6E5F0000]      <1> 	add	edi, vga_dac_s 	
   491 0000163B C0E302              <1> 	shl	bl, 2 ; byte -> dword
   492 0000163E 81C3[1E5F0000]      <1> 	add	ebx, vga_mode_tbl_ptr
   493                              <1> 
   494                              <1> 	;mov	dword [VGA_BASE], 0B8000h
   495                              <1> 	;cmp	ah, 0Dh ; [CRT_MODE]
   496                              <1> 	;jb	short M9 
   497                              <1> 	;mov	dword [VGA_BASE], 0A0000h
   498                              <1> ;M9:
   499 00001644 8B33                <1> 	mov	esi, [ebx]
   500 00001646 89F3                <1> 	mov	ebx, esi
   501 00001648 83C614              <1> 	add	esi, vga_p_cm_pos ; ebx + 20
   502 0000164B 668B06              <1> 	mov	ax, [esi]       ; get the cursor mode from the table
   503 0000164E 66A3[0B5F0000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode (initial value)
   504                              <1> 	; al = 6, ah = 7
   505                              <1> 	; al = 0Dh, ah = 0Eh ; 25/07/2016
   506 00001654 E83B020000          <1> 	call	cursor_shape_fix
   507                              <1> 	; al = 14, ah = 15  (If [CHAR_HEIGHT] = 16)
   508 00001659 668906              <1> 	mov	[esi], ax
   509                              <1> 
   510 0000165C 56                  <1> 	push	esi ; *	
   511                              <1> 
   512 0000165D 8A25[F95E0000]      <1> 	mov	ah, [VGA_MODESET_CTL]
   513 00001663 80E408              <1> 	and	ah, 8 ; default palette loading ?
   514 00001666 7524                <1> 	jnz	short _sm_6
   515 00001668 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK (DAC mask register)
   516 0000166C B0FF                <1> 	mov	al, 0FFh ; PEL mask
   517 0000166E EE                  <1> 	out	dx, al
   518 0000166F 8A27                <1> 	mov	ah, [edi] ; DAC model (selection number)
   519 00001671 E8ED0F0000          <1> 	call	load_dac_palette
   520                              <1> 	; ecx = 0
   521 00001676 F605[F95E0000]02    <1> 	test	byte [VGA_MODESET_CTL], 2 ; gray scale summing
   522 0000167D 740D                <1> 	jz	short _sm_6
   523 0000167F 53                  <1> 	push	ebx
   524 00001680 29DB                <1> 	sub	ebx, ebx ; sub bl, bl
   525 00001682 66B90001            <1>         mov     cx, 256 
   526 00001686 E82B100000          <1> 	call	gray_scale_summing
   527 0000168B 5B                  <1> 	pop	ebx	
   528                              <1> _sm_6:
   529                              <1> 	; Reset Attribute Ctl flip-flop
   530 0000168C 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
   531 00001690 EC                  <1>  	in	al, dx
   532                              <1> 	; Set Attribute Ctl
   533 00001691 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   534 00001693 83C623              <1> 	add	esi, 35  ; actl regs
   535 00001696 30E4                <1> 	xor	ah, ah ; 0
   536 00001698 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
   537                              <1> _sm_7:
   538 0000169C 88E0                <1> 	mov	al, ah
   539 0000169E EE                  <1> 	out	dx, al ; index
   540 0000169F AC                  <1> 	lodsb
   541                              <1> 	; DX = 3C0h = VGAREG_ACTL_WRITE_DATA
   542 000016A0 EE                  <1> 	out	dx, al ; value
   543 000016A1 FEC4                <1> 	inc	ah
   544 000016A3 80FC14              <1> 	cmp	ah, 20 ; number of actl registers
   545 000016A6 72F4                <1> 	jb	short _sm_7
   546                              <1> 	;
   547 000016A8 88E0                <1> 	mov	al, ah ; 20
   548 000016AA EE                  <1> 	out	dx, al ; index
   549 000016AB 28C0                <1> 	sub	al, al ; 0
   550 000016AD EE                  <1> 	out	dx, al ; value
   551                              <1> 	;
   552                              <1> 	; Set Sequencer Ctl
   553 000016AE 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   554 000016B0 83C605              <1> 	add	esi, 5 ; sequ regs
   555                              <1> 	;
   556 000016B3 66BAC403            <1> 	mov	dx, 3C4h  ; VGAREG_SEQU_ADDRESS
   557 000016B7 EE                  <1> 	out	dx, al ; 0
   558 000016B8 6642                <1> 	inc	dx ; 3C5h ; VGAREG_SEQU_DATA
   559 000016BA B003                <1> 	mov	al, 3
   560 000016BC EE                  <1> 	out	dx, al
   561 000016BD B401                <1> 	mov	ah, 1	
   562                              <1> _sm_8:
   563 000016BF 88E0                <1> 	mov	al, ah
   564                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   565 000016C1 664A                <1> 	dec	dx
   566 000016C3 EE                  <1> 	out	dx, al ; index
   567 000016C4 AC                  <1> 	lodsb
   568 000016C5 6642                <1> 	inc	dx ; 3C5h ; VGAREG_SEQU_DATA
   569 000016C7 EE                  <1> 	out	dx, al
   570 000016C8 80FC04              <1> 	cmp	ah, 4 ; number of sequ regs
   571 000016CB 7304                <1> 	jnb	short _sm_9		
   572 000016CD FEC4                <1> 	inc	ah 
   573 000016CF EBEE                <1> 	jmp	short _sm_8
   574                              <1> _sm_9:
   575                              <1> 	; Set Grafx Ctl
   576 000016D1 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   577 000016D3 83C637              <1> 	add	esi, 55 ; grdc regs
   578 000016D6 30E4                <1> 	xor	ah, ah ; 0
   579                              <1> _sm_10:
   580 000016D8 88E0                <1> 	mov	al, ah
   581 000016DA 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
   582 000016DE EE                  <1> 	out	dx, al	
   583 000016DF AC                  <1> 	lodsb
   584 000016E0 6642                <1> 	inc	dx ; 3CFh ; VGAREG_GRDC_DATA
   585 000016E2 EE                  <1> 	out	dx, al
   586 000016E3 FEC4                <1> 	inc	ah
   587 000016E5 80FC09              <1> 	cmp	ah, 9 ; number of grdc regs
   588 000016E8 72EE                <1> 	jb	short _sm_10
   589                              <1> 	;
   590                              <1> 	; Disable CRTC write protection
   591 000016EA 66BAD403            <1> 	mov	dx, 3D4h  ; VGAREG_VGA_CRTC_ADDRESS
   592                              <1> 	;mov	al, 11h
   593                              <1> 	;our	dx, al
   594                              <1> 	;inc	dx
   595                              <1> 	;sub	al, al
   596                              <1> 	;out	dx, al
   597 000016EE 66B81100            <1> 	mov	ax, 11h
   598 000016F2 66EF                <1> 	out	dx, ax
   599 000016F4 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
   600 000016F6 83C60A              <1> 	add	esi, 10 ; crtc regs
   601                              <1> 	; ah = 0
   602                              <1> _sm_11:
   603 000016F9 88E0                <1> 	mov	al, ah
   604                              <1> 	; dx = 3D4h = VGAREG_VGA_CRTC_ADDRESS
   605 000016FB EE                  <1> 	out	dx, al ; index
   606 000016FC AC                  <1> 	lodsb
   607 000016FD 6642                <1> 	inc	dx  ; VGAREG_VGA_CRTC_ADDRESS + 1
   608 000016FF EE                  <1> 	out	dx, al ; value
   609 00001700 80FC18              <1> 	cmp	ah, 24 ; number of crtc registers - 1
   610 00001703 7306                <1> 	jnb	short _sm_12
   611 00001705 FEC4                <1> 	inc	ah
   612 00001707 664A                <1> 	dec	dx ; 3D4h
   613 00001709 EBEE                <1> 	jmp	short _sm_11
   614                              <1> _sm_12:
   615                              <1> 	; Set the misc register
   616 0000170B 66BACC03            <1> 	mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
   617 0000170F 8A4309              <1> 	mov	al, [ebx+9] ; misc reg
   618 00001712 EE                  <1> 	out	dx, al
   619                              <1> 	;
   620                              <1> 	; Enable video
   621 00001713 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
   622 00001717 B020                <1> 	mov	al, 20h  
   623 00001719 EE                  <1>         out     dx, al   ; set bit 5 to 1
   624 0000171A 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
   625 0000171E EC                  <1> 	in	al, dx
   626                              <1> 	;
   627 0000171F 803D[37650100]00    <1> 	cmp	byte [noclearmem], 0
   628 00001726 7740                <1>         ja      short _sm_15
   629                              <1> 
   630                              <1> 	; 29/07/2016
   631 00001728 31C0                <1> 	xor	eax, eax
   632 0000172A B900400000          <1> 	mov	ecx, 4000h ; 16K words (32K)
   633 0000172F 803D[4E650100]02    <1> 	cmp     byte [VGA_MTYPE], 2  ; CTEXT, MTEXT, CGA
   634 00001736 7715                <1> 	ja	short _sm_14    ; no ? (0A0000h)
   635 00001738 BF00800B00          <1> 	mov	edi, 0B8000h
   636 0000173D 7409                <1> 	je	short _sm_13	; CGA graphics mode
   637                              <1> 	; 08/08/2016
   638 0000173F A3[4A650100]        <1> 	mov	[VGA_INT43H], eax ; 0 ; default font 
   639 00001744 66B82007            <1> 	mov	ax, 0720h	; CGA text mode
   640                              <1> _sm_13:
   641 00001748 F366AB              <1> 	rep	stosw
   642 0000174B EB1B                <1> 	jmp	short _sm_15		
   643                              <1> 
   644                              <1> _sm_14:
   645 0000174D BF00000A00          <1> 	mov	edi, 0A0000h
   646                              <1> 	; ecx = 16384 dwords  (64K)
   647 00001752 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   648 00001756 B002                <1> 	mov	al, 2
   649 00001758 EE                  <1> 	out	dx, al
   650                              <1> 	;mov	dx, 3C5h ; VGAREG_SEQU_DATA
   651 00001759 6642                <1> 	inc	dx
   652 0000175B EC                  <1> 	in	al, dx ; mmask
   653 0000175C 6650                <1> 	push	ax
   654 0000175E B00F                <1> 	mov	al, 0Fh ; all planes
   655 00001760 EE                  <1> 	out	dx, al
   656 00001761 30C0                <1> 	xor	al, al ; 0
   657 00001763 F3AB                <1> 	rep	stosd	; ecx = 163684 (64K)
   658 00001765 6658                <1> 	pop	ax
   659 00001767 EE                  <1> 	out	dx, al  ; mmask
   660                              <1> _sm_15:
   661                              <1> 	; ebx = addr of params tbl for selected mode
   662                              <1> 	; 10/08/2016
   663 00001768 668B03              <1> 	mov	ax, [ebx] ; num of columns, 'twidth'
   664 0000176B A2[F45E0000]        <1> 	mov	[CRT_COLS], al
   665                              <1> 	;; 26/07/2016
   666                              <1> 	;; CRTC_ADDRESS = 3D4h (always)
   667                              <1> 	;mov	ah, [ebx+1] ; num of rows, 'theightm1'
   668 00001770 FEC4                <1> 	inc	ah ; 09/07/2016
   669 00001772 8825[FA5E0000]      <1> 	mov	[VGA_ROWS], ah
   670                              <1> 	; 10/08/2016
   671 00001778 8A4302              <1> 	mov	al, [ebx+2]
   672 0000177B A2[F65E0000]        <1> 	mov	[CHAR_HEIGHT], al 
   673                              <1> 	; 29/07/2016
   674                              <1> 	; length of regen buffer in bytes
   675 00001780 668B4B03            <1> 	mov	cx, [ebx+3] ; 'slength_l'
   676 00001784 66890D[38650100]    <1> 	mov	[CRT_LEN], cx
   677                              <1> 	;
   678                              <1> 	; 27/07/2016
   679 0000178B 30E4                <1> 	xor	ah, ah
   680 0000178D A0[D6580100]        <1> 	mov	al, [ACTIVE_PAGE] ; may be > 0 for mode 3
   681                              <1> 	;mul	word [CRT_LEN] ; 4096 for mode 3
   682 00001792 66F7E1              <1> 	mul	cx ; 29/07/2016
   683 00001795 66A3[C4580100]      <1> 	mov	[CRT_START], ax
   684                              <1> 	;
   685 0000179B B060                <1> 	mov	al, 60h
   686 0000179D 803D[37650100]00    <1> 	cmp	byte [noclearmem], 0
   687 000017A4 7602                <1> 	jna	short _sm_16
   688 000017A6 0480                <1> 	add	al, 80h
   689                              <1> _sm_16:
   690 000017A8 A2[F75E0000]        <1> 	mov	[VGA_VIDEO_CTL], al
   691 000017AD C605[F85E0000]F9    <1> 	mov	byte [VGA_SWITCHES], 0F9h
   692 000017B4 8025[F95E0000]7F    <1> 	and	byte [VGA_MODESET_CTL], 7Fh
   693                              <1> 
   694 000017BB 5E                  <1> 	pop	esi ; *
   695                              <1> 
   696                              <1> 	; 26/07/2016
   697                              <1> 	; 07/07/2016
   698 000017BC 668B0D[0B5F0000]    <1> 	mov	cx, [CURSOR_MODE] ; restore cursor mode (initial value)
   699 000017C3 66870E              <1> 	xchg	cx, [esi] ; cl = start line, ch = end line
   700                              <1> 			  ; reset to initial value
   701 000017C6 86E9                <1> 	xchg 	ch, cl  ; ch = start line, cl = end line  
   702 000017C8 66890D[0B5F0000]    <1> 	mov	[CURSOR_MODE], cx ; save (fixed) cursor mode
   703                              <1> 
   704                              <1> 	; 27/07/2016
   705 000017CF 803D[4E650100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
   706 000017D6 7317                <1> 	jnb	short _sm_17
   707                              <1> 
   708                              <1> 	; Set cursor shape
   709                              <1> 	;mov	cx, 0607h
   710                              <1> 	;call	_set_ctype
   711                              <1> 
   712                              <1> 	; 29/07/2016
   713 000017D8 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
   714 000017DA E8C4050000          <1> 	call	m16	; output cx register
   715                              <1> 	
   716                              <1> 	; 25/07/2016
   717 000017DF 803D[F25E0000]03    <1>         cmp     byte [CRT_MODE], 03h
   718 000017E6 7507                <1> 	jne	short _sm_17
   719                              <1> 	; 26/07/2016
   720                              <1> 
   721 000017E8 A0[D6580100]        <1> 	mov	al, [ACTIVE_PAGE]
   722 000017ED EB0C                <1> 	jmp	short _sm_18
   723                              <1> _sm_17:
   724                              <1> 	; Set cursor pos for page 0..7
   725 000017EF 6629C0              <1> 	sub	ax, ax ; eax = 0
   726 000017F2 BF[C6580100]        <1> 	mov	edi, CURSOR_POSN
   727 000017F7 AB                  <1> 	stosd	
   728 000017F8 AB                  <1> 	stosd
   729 000017F9 AB                  <1> 	stosd
   730 000017FA AB                  <1> 	stosd
   731                              <1> 	;; Set active page 0
   732                              <1> 	;mov	[ACTIVE_PAGE], al ; 0
   733                              <1> _sm_18:
   734                              <1> 	; 29/07/2016
   735 000017FB 803D[4E650100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
   736 00001802 0F8386000000        <1>         jnb	_sm_23
   737                              <1> 
   738                              <1> 	;cmp	byte [CHAR_HEIGHT], 16
   739                              <1> 	;je	short _sm_19
   740                              <1> 
   741                              <1>  	;; copy and activate 8x16 font
   742                              <1> 	
   743                              <1> 	; 26/07/2016
   744 00001808 B004                <1> 	mov	al, 04h
   745                              <1> 	;sub	bl, bl
   746                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set
   747                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
   748 0000180A E83A150000          <1> 	call	load_text_8_16_pat
   749                              <1> 
   750                              <1> 	; video_func_1103h:
   751                              <1> 	; biosfn_set_text_block_specifier:
   752                              <1> 	; BL = font block selector code	
   753                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
   754                              <1> 	; (It is as BL = 0 for TRDOS 386)
   755 0000180F 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
   756                              <1> 	;mov	ah, bl
   757 00001813 28E4                <1> 	sub	ah, ah ; 0
   758 00001815 B003                <1> 	mov	al, 03h
   759 00001817 66EF                <1> 	out	dx, ax
   760                              <1> _sm_19:
   761                              <1> 	; 29/07/2016
   762                              <1> 	; 26/07/2016
   763                              <1> 	; 24/06/2016
   764                              <1> 	;mov	edi, 0B8000h
   765                              <1> 	;mov	cx, 4000h ; 16K words (32K)
   766                              <1> 	;
   767 00001819 30C0                <1> 	xor	al, al
   768 0000181B 3805[35650100]      <1>         cmp     byte [p_crt_mode], al ; 0 
   769 00001821 7707                <1>         ja      short _sm_20 ; 3h, 80h or 83h
   770                              <1> 
   771                              <1> 	; 30/07/2016
   772                              <1> 	; 24/06/2016
   773                              <1> 	; TRDOS 386 (TRDOS v2) 'set mode' modification
   774                              <1> 	; (for multiscreen feature):
   775                              <1> 	; If '_set_mode' procedure is called for video mode 3
   776                              <1> 	;     while video mode is 3, video page will be cleared
   777                              <1> 	;     and cursor position of video page will be reset.	  
   778                              <1> 	; If '_set_mode' procedure is called for a video mode
   779                              <1> 	;     except video mode 3, while current video mode
   780                              <1> 	;     is 3; all video pages of mode 3 will be copied 
   781                              <1> 	;     to 98000h address as backup, before mode change.	 	
   782                              <1> 	; If '_set_mode' procedure is called for video mode 3
   783                              <1> 	;     while video mode is not 3 and if there is video
   784                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
   785                              <1> 	;     video pages will be restored from 98000h.
   786                              <1> 
   787 00001823 A2[D6580100]        <1> 	mov	[ACTIVE_PAGE], al ; 0
   788                              <1> 	;mov	ax, 0720h
   789                              <1> 	;;mov	cx, 4000h ; 16K words (32K)
   790                              <1> 	;;mov	edi, 0B8000h
   791                              <1> 	;rep	stosw
   792                              <1> 	;sub	al, al
   793 00001828 EB64                <1> 	jmp	short _sm_23
   794                              <1> _sm_20:
   795                              <1> 	; Previous video mode is 3
   796                              <1> 	; New video mode is 3 while current video mode is not 3
   797                              <1> 	; (multi screen) video pages will be restored from 0B0000h
   798                              <1> 
   799 0000182A 0FB61D[D6580100]    <1> 	movzx	ebx, byte [ACTIVE_PAGE]
   800 00001831 D0E3                <1> 	shl	bl, 1 ; * 2
   801 00001833 81C3[C6580100]      <1> 	add	ebx, CURSOR_POSN
   802                              <1> 
   803                              <1> 	; 29/07/2016
   804 00001839 F605[35650100]7F    <1> 	test    byte [p_crt_mode], 7Fh ; 83h or 3h
   805 00001840 7427                <1> 	jz	short _sm_21	; do not restore video pages
   806                              <1> 
   807                              <1> 	;; restore video pages
   808 00001842 BE00800900          <1> 	mov	esi, 98000h ; 30/07/2016 
   809 00001847 BF00800B00          <1> 	mov	edi, 0B8000h
   810 0000184C 66B90020            <1> 	mov	cx, 2000h ; 8K dwords (32K)
   811 00001850 F3A5                <1> 	rep	movsd
   812                              <1> 
   813                              <1> 	; restore cursor positions
   814 00001852 BE[3A650100]        <1> 	mov	esi, cursor_pposn
   815 00001857 BF[C6580100]        <1> 	mov	edi, CURSOR_POSN
   816                              <1> 	;mov	ecx, 4	; restore all cursor positions (16 bytes)
   817 0000185C B104                <1> 	mov	cl, 4
   818 0000185E F3A5                <1> 	rep 	movsd
   819                              <1> 
   820 00001860 F605[35650100]80    <1>         test    byte [p_crt_mode], 80h
   821 00001867 7420                <1> 	jz	short _sm_22 ; do not clear current video pages
   822                              <1> _sm_21:
   823                              <1> 	; clear video page
   824 00001869 668B0D[38650100]    <1> 	mov	cx, [CRT_LEN] ; 4096 
   825 00001870 66D1E9              <1> 	shr	cx, 1 ; 2072
   826 00001873 66B82007            <1> 	mov	ax, 0720h
   827 00001877 BF00800B00          <1> 	mov	edi, 0B8000h ; [crt_base]
   828 0000187C 66033D[C4580100]    <1> 	add	di, [CRT_START]
   829 00001883 F366AB              <1> 	rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
   830                              <1> 	;
   831 00001886 66890B              <1> 	mov	[ebx], cx ; reset cursor position
   832                              <1> _sm_22:
   833 00001889 A2[35650100]        <1> 	mov	[p_crt_mode], al ; 0
   834                              <1> _sm_23:
   835                              <1> 	; al = video page number
   836                              <1> 	; [CRT_LEN] = length of regen buffer in bytes
   837 0000188E E81E010000          <1> 	call	_set_active_page
   838                              <1> 
   839                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
   840 00001893 C3                  <1> 	retn
   841                              <1> 
   842                              <1> cursor_shape_fix:
   843                              <1> 	; 07/07/2016
   844                              <1> 	; (Cursor start and cursor end line values -6,7-
   845                              <1> 	; will be fixed depending on character height)
   846                              <1> 	;
   847                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   848                              <1> 	; vgabios-0.7a (2011)
   849                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
   850                              <1> 	; 'vgabios.c', ' biosfn_set_cursor_shape (CH,CL)'
   851                              <1> 	;
   852                              <1> 	; INPUT ->
   853                              <1> 	;	AL = cursor start line (=6)
   854                              <1> 	;	AH = cursor end line (=7)
   855                              <1> 	; OUTPUT ->
   856                              <1> 	;	AL = cursor start line (=14)
   857                              <1> 	;	AH = cursor end line (=15)
   858                              <1> 	;
   859                              <1> 	;; if((modeset_ctl&0x01)&&(cheight>8)&&(CL<8)&&(CH<0x20))
   860                              <1> 
   861                              <1> 	;test	byte [VGA_MODESET_CTL], 1 ; VGA active
   862                              <1> 	;jz	short csf_3
   863 00001894 803D[F65E0000]08    <1> 	cmp	byte [CHAR_HEIGHT], 8
   864 0000189B 7649                <1> 	jna	short csf_3
   865 0000189D 80FC08              <1> 	cmp	ah, 8
   866 000018A0 7344                <1> 	jnb	short csf_3
   867 000018A2 3C20                <1> 	cmp	al, 20h
   868 000018A4 7340                <1> 	jnb	short csf_3
   869                              <1> 	;
   870 000018A6 6650                <1> 	push	ax
   871                              <1> 	; {
   872                              <1>    	; if(CL!=(CH+1))	
   873 000018A8 FEC0                <1> 	inc	al
   874 000018AA 38C4                <1> 	cmp	ah, al   ; ah != al + 1
   875 000018AC 740F                <1>         je      short csf_1
   876                              <1> 	; CH = ((CH+1) * cheight / 8) -1;
   877 000018AE 8A25[F65E0000]      <1> 	mov	ah, [CHAR_HEIGHT]
   878 000018B4 F6E4                <1> 	mul	ah
   879 000018B6 C0E803              <1> 	shr	al, 3 ; / 8
   880 000018B9 FEC8                <1> 	dec	al ; - 1
   881 000018BB EB0E                <1> 	jmp	short csf_2 
   882                              <1> csf_1: 	
   883                              <1>  	; }
   884                              <1>    	; else		; ah = al + 1
   885                              <1>     	; {
   886 000018BD FEC4                <1> 	inc	ah	; ah = ah + 1   
   887                              <1> 	; CH = ((CL+1) * cheight / 8) - 2;
   888 000018BF A0[F65E0000]        <1> 	mov	al, [CHAR_HEIGHT]
   889 000018C4 F6E4                <1> 	mul	ah
   890 000018C6 C0E803              <1> 	shr	al, 3 ; / 8
   891 000018C9 2C02                <1> 	sub	al, 2 ; - 2
   892                              <1> 	; al = 14 (if [CHAR_HEIGHT] = 16)
   893                              <1> csf_2:
   894 000018CB 880424              <1> 	mov	[esp], al
   895 000018CE 8A642401            <1> 	mov	ah, [esp+1]
   896                              <1> 	; CL = ((CL+1) * cheight / 8) - 1;
   897 000018D2 FEC4                <1> 	inc	ah 
   898 000018D4 A0[F65E0000]        <1> 	mov	al, [CHAR_HEIGHT]
   899 000018D9 F6E4                <1> 	mul	ah
   900 000018DB C0E803              <1> 	shr	al, 3 ; / 8
   901 000018DE FEC8                <1> 	dec	al ; - 1
   902 000018E0 88442401            <1> 	mov	[esp+1], al
   903                              <1> 	; ah = 15 (if [CHAR_HEIGHT] = 16)
   904                              <1> 	;
   905 000018E4 6658                <1> 	pop	ax
   906                              <1> csf_3:
   907 000018E6 C3                  <1> 	retn
   908                              <1> 
   909                              <1> SET_CTYPE:
   910                              <1> 	; 12/09/2016
   911                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   912 000018E7 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7
   913 000018EE 0F8790FCFFFF        <1> 	ja	VIDEO_RETURN ; 12/09/2016
   914 000018F4 E805000000          <1> 	call	_set_ctype
   915 000018F9 E986FCFFFF          <1>         jmp     VIDEO_RETURN
   916                              <1> 
   917                              <1> _set_ctype:
   918                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
   919                              <1> 	;
   920                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
   921                              <1> 
   922                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
   923                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
   924                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
   925                              <1> 	;     OR NO CURSOR AT ALL
   926                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
   927                              <1> 
   928                              <1> ;------------------------------------------------
   929                              <1> ; SET_CTYPE
   930                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
   931                              <1> ; INPUT
   932                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
   933                              <1> ; OUTPUT	
   934                              <1> ;	NONE
   935                              <1> ;------------------------------------------------
   936                              <1> 
   937                              <1> 	; 07/07/2016
   938                              <1> 	; Fixing cursor start and stop line depending on
   939                              <1> 	; current character height (=16)
   940                              <1> 	; (Note: Default/initial values are 6 and 7.
   941                              <1> 	; If set values are 6 (start) & 7 (stop) and 
   942                              <1> 	; [CHAR_HEIGHT] = 16 :
   943                              <1> 	; After fixing, start line will be 14, stop line
   944                              <1> 	; will be 15.)
   945 000018FE 6689C8              <1> 	mov	ax, cx
   946 00001901 86C4                <1> 	xchg	al, ah
   947                              <1> 	; AL = start line, AH = stop line
   948 00001903 E88CFFFFFF          <1> 	call	cursor_shape_fix
   949                              <1> 	; AL = start line (fixed), AH = stop line (fixed)
   950 00001908 6689C1              <1> 	mov	cx, ax
   951 0000190B 86E9                <1> 	xchg	ch, cl
   952                              <1> 	; CH = start line (fixed), CL = stop line (fixed)
   953                              <1> 	;
   954 0000190D B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
   955 0000190F 66890D[0B5F0000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
   956                              <1> 	;call	m16	; output cx register
   957                              <1> 	;retn
   958 00001916 E988040000          <1>         jmp     m16
   959                              <1> 
   960                              <1> SET_CPOS:
   961                              <1> 	; 12/09/2016
   962                              <1> 	; 07/07/2016
   963                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   964 0000191B 80FF07              <1> 	cmp	bh, 7 ; video page > 7 ; 07/07/2016
   965 0000191E 0F8760FCFFFF        <1> 	ja	VIDEO_RETURN
   966                              <1> 	;
   967 00001924 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7
   968 0000192B 770A                <1> 	ja	short vga_set_cpos ; 12/09/2016	
   969 0000192D E846040000          <1> 	call	_set_cpos
   970 00001932 E94DFCFFFF          <1>         jmp     VIDEO_RETURN
   971                              <1> 
   972                              <1> vga_set_cpos:
   973                              <1> 	; 12/09/2016
   974                              <1> 	; 09/07/2016
   975                              <1> 	; set cursor position
   976                              <1> 	; NOTE: Hardware cursor position will not be set
   977                              <1> 	;   in any VGA modes (>7)
   978                              <1> 	;   But, cursor position will be saved into
   979                              <1> 	;   [CURSOR_POSN].
   980                              <1> 	;   TRDOS 386 (TRDOS v2.0) uses only one page
   981                              <1> 	;   (page 0) for all graphics modes.
   982                              <1> 
   983 00001937 668915[C6580100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
   984                              <1> 	; 04/08/2016
   985                              <1> 	;mov	bh, [ACTIVE_PAGE] ; = 0
   986                              <1> 	;call	_set_cpos
   987 0000193E E941FCFFFF          <1> 	jmp     VIDEO_RETURN
   988                              <1> 
   989                              <1> READ_CURSOR:
   990                              <1> 	; 12/09/2016
   991                              <1> 	; 07/07/2016
   992                              <1> 	; 12/05/2016
   993                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   994                              <1> 	;
   995                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
   996                              <1> 
   997                              <1> ;------------------------------------------------------
   998                              <1> ; READ_CURSOR
   999                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
  1000                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
  1001                              <1> ; INPUT
  1002                              <1> ;	BH - PAGE OF CURSOR
  1003                              <1> ; OUTPUT
  1004                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
  1005                              <1> ;	CX - CURRENT CURSOR MODE
  1006                              <1> ;------------------------------------------------------
  1007                              <1> 
  1008                              <1> 	; BH = Video page number (0 to 7)
  1009                              <1> 
  1010                              <1> 	; 07/07/2016
  1011 00001943 80FF07              <1> 	cmp	bh, 7 ; video page > 7 (invalid)
  1012 00001946 7606                <1> 	jna	short read_cursor_1
  1013                              <1> 	; invalid video page (input) 
  1014 00001948 31C9                <1> 	xor	ecx, ecx ; 0
  1015 0000194A 31D2                <1> 	xor	edx, edx ; 0
  1016 0000194C EB15                <1> 	jmp	short read_cursor_2
  1017                              <1> read_cursor_1:
  1018                              <1> 	; 12/09/2016
  1019 0000194E 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7 ; vga mode
  1020 00001955 7727                <1> 	ja	short vga_get_cpos
  1021                              <1> 	;
  1022 00001957 E815000000          <1> 	call	get_cpos
  1023 0000195C 0FB70D[0B5F0000]    <1> 	movzx	ecx, word [CURSOR_MODE]
  1024                              <1> read_cursor_2:
  1025 00001963 5D                  <1> 	pop	ebp
  1026 00001964 5F                  <1> 	pop	edi
  1027 00001965 5E                  <1> 	pop	esi
  1028 00001966 5B                  <1> 	pop	ebx
  1029 00001967 58                  <1> 	pop	eax  ; DISCARD SAVED CX AND DX
  1030 00001968 58                  <1> 	pop	eax
  1031 00001969 A1[28650100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
  1032                              <1> 	;;15/01/2017
  1033                              <1> 	;;mov	byte [intflg], 0 ; 07/01/2017
  1034 0000196E 1F                  <1> 	pop	ds
  1035 0000196F 07                  <1> 	pop	es
  1036 00001970 CF                  <1> 	iretd
  1037                              <1> 
  1038                              <1> get_cpos:
  1039                              <1> 	; 12/05/2016
  1040                              <1> 	; 16/01/2016
  1041                              <1> 	; BH = Video page number (0 to 7)
  1042                              <1> 	;
  1043 00001971 D0E7                <1> 	shl	bh, 1 ; WORD OFFSET
  1044 00001973 0FB6F7              <1> 	movzx	esi, bh 
  1045 00001976 0FB796[C6580100]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
  1046 0000197D C3                  <1> 	retn
  1047                              <1> 
  1048                              <1> vga_get_cpos:
  1049                              <1> 	; 12/09/2016
  1050                              <1> 	; get cursor position (vga)
  1051 0000197E 0FB715[C6580100]    <1> 	movzx	edx, word [CURSOR_POSN] ; cursor pos for pg 0
  1052 00001985 31C9                <1> 	xor	ecx, ecx ; Cursor Mode = 0 (invalid)
  1053 00001987 EBDA                <1> 	jmp     short read_cursor_2
  1054                              <1> 
  1055                              <1> ACT_DISP_PAGE:
  1056                              <1> 	; 07/07/2016
  1057                              <1> 	; 26/06/2016
  1058                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1059                              <1> 	;
  1060                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1061                              <1> 	;
  1062                              <1> ;-----------------------------------------------------
  1063                              <1> ; ACT_DISP_PAGE
  1064                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  1065                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  1066                              <1> ; INPUT
  1067                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  1068                              <1> ; OUTPUT
  1069                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  1070                              <1> ;-----------------------------------------------------
  1071                              <1> 	; 07/07/2016
  1072 00001989 3C07                <1> 	cmp	al, 7	; > 7 = invalid video page number
  1073 0000198B 0F87F3FBFFFF        <1> 	ja	VIDEO_RETURN
  1074 00001991 803D[F25E0000]03    <1>         cmp     byte [CRT_MODE], 3
  1075 00001998 7408                <1> 	je	short adp_1
  1076 0000199A 20C0                <1> 	and 	al, al
  1077 0000199C 0F85E2FBFFFF        <1>         jnz     VIDEO_RETURN
  1078                              <1> 	;sub	al, al ; 0 ; force to page 0
  1079                              <1> adp_1:	
  1080 000019A2 E805000000          <1> 	call	set_active_page
  1081 000019A7 E9D8FBFFFF          <1>         jmp     VIDEO_RETURN
  1082                              <1> 
  1083                              <1> set_active_page:   ; tty_sw
  1084                              <1> 	; 09/12/2017
  1085                              <1> 	; 26/07/2016
  1086                              <1> 	; 26/06/2016
  1087                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1088                              <1> 	; 30/06/2015
  1089                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  1090                              <1> 	; 10/12/2013
  1091                              <1> 	; 04/12/2013
  1092                              <1> 	;
  1093 000019AC A2[D6580100]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  1094                              <1> _set_active_page:
  1095                              <1> 	; 27/06/2015
  1096 000019B1 0FB6D8              <1> 	movzx	ebx, al
  1097                              <1> 	;
  1098                              <1> 	;cbw	; 07/09/2014 (ah=0)
  1099 000019B4 28E4                <1> 	sub	ah, ah ; 09/12/2017
  1100 000019B6 66F725[38650100]    <1> 	mul	word [CRT_LEN]  ; get saved length of regen buffer
  1101                              <1> 				; display page times regen length
  1102                              <1> 	; 10/12/2013
  1103 000019BD 66A3[C4580100]      <1> 	mov	[CRT_START], ax ; save start address for later
  1104 000019C3 6689C1              <1> 	mov	cx, ax ; start address to cx
  1105                              <1> _M16:
  1106                              <1> 	;sar	cx, 1
  1107 000019C6 66D1E9              <1> 	shr	cx, 1	; divide by 2 for 6845 handling
  1108 000019C9 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  1109 000019CB E8D3030000          <1> 	call	m16
  1110                              <1> 	;sal	bx, 1
  1111                              <1> 	; 01/09/2014
  1112 000019D0 D0E3                <1> 	shl	bl, 1	; *2 for word offset
  1113 000019D2 81C3[C6580100]      <1> 	add	ebx, CURSOR_POSN
  1114 000019D8 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  1115                              <1> 	; 16/01/2016
  1116                              <1> 	;call	m18
  1117                              <1> 	;retn
  1118 000019DB E9AF030000          <1> 	jmp	m18
  1119                              <1> 
  1120                              <1> position:
  1121                              <1> 	; 24/06/2016
  1122                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1123                              <1> 	; 27/06/2015
  1124                              <1> 	; 02/09/2014
  1125                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1126                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  1127                              <1> 	;
  1128                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1129                              <1> 	;
  1130                              <1> ;-----------------------------------------
  1131                              <1> ; POSITION
  1132                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  1133                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  1134                              <1> ; INPUT
  1135                              <1> ;	AX = ROW, COLUMN POSITION
  1136                              <1> ; OUTPUT
  1137                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  1138                              <1> ;-----------------------------------------
  1139                              <1> 
  1140                              <1> 	; DX = ROW, COLUMN POSITION
  1141 000019E0 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS] ; 24/06/2016
  1142 000019E7 F6E6                <1> 	mul	dh	 ; row value
  1143 000019E9 30F6                <1> 	xor	dh, dh   ; 0	
  1144 000019EB 6601D0              <1> 	add	ax, dx	 ; add column value to the result
  1145 000019EE 66D1E0              <1> 	shl	ax, 1	; * 2 for attribute bytes
  1146                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  1147 000019F1 C3                  <1> 	retn
  1148                              <1> 
  1149                              <1> find_position:
  1150                              <1> 	; 24/06/2016
  1151                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1152                              <1> 	; 27/06/2015
  1153                              <1> 	; 07/09/2014
  1154                              <1> 	; 02/09/2014
  1155                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1156                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1157                              <1> 
  1158 000019F2 0FB6CF              <1> 	movzx	ecx, bh ; video page number
  1159 000019F5 89CE                <1> 	mov	esi, ecx
  1160 000019F7 66D1E6              <1> 	shl	si, 1
  1161 000019FA 668B96[C6580100]    <1> 	mov	dx, [esi+CURSOR_POSN]
  1162 00001A01 740C                <1> 	jz	short p21
  1163 00001A03 6631F6              <1> 	xor	si, si
  1164                              <1> p20:
  1165 00001A06 660335[38650100]    <1> 	add	si, [CRT_LEN] ; 24/06/2016
  1166                              <1> 	;add	si, 80*25*2 ; add length of buffer for one page		
  1167 00001A0D E2F7                <1> 	loop	p20
  1168                              <1> p21:
  1169 00001A0F 6621D2              <1> 	and	dx, dx
  1170 00001A12 7407                <1> 	jz	short p22
  1171 00001A14 E8C7FFFFFF          <1> 	call 	position ; determine location in regen in page
  1172 00001A19 01C6                <1> 	add	esi, eax ; add location to start of regen page
  1173                              <1> p22:	
  1174                              <1> 	;mov	dx, [addr_6845] ; get base address of active display			
  1175                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  1176                              <1> 	;add	dx, 6	; point at status port
  1177 00001A1B 66BADA03            <1> 	mov	dx, 03DAh ; status port
  1178                              <1> 	; cx = 0
  1179 00001A1F C3                  <1> 	retn
  1180                              <1> 
  1181                              <1> SCROLL_UP:
  1182                              <1> 	; 07/07/2016
  1183                              <1> 	; 26/06/2016
  1184                              <1> 	; 12/05/2016
  1185                              <1> 	; 30/01/2016
  1186                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1187                              <1> 	; 07/09/2014
  1188                              <1> 	; 02/09/2014
  1189                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  1190                              <1> 	; 04/04/2014
  1191                              <1> 	; 04/12/2013
  1192                              <1> 	;
  1193                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1194                              <1> 	;
  1195                              <1> ;----------------------------------------------
  1196                              <1> ; SCROLL UP
  1197                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  1198                              <1> ;	ON THE SCREEN
  1199                              <1> ; INPUT
  1200                              <1> ;	(AH) = CURRENT CRT MODE
  1201                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  1202                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  1203                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  1204                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  1205                              <1> ;	(DS) = DATA SEGMENT
  1206                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  1207                              <1> ; OUTPUT
  1208                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  1209                              <1> ;--------------------------------------------
  1210                              <1> 
  1211                              <1> 	; 07/07/2016
  1212 00001A20 38F5                <1> 	cmp	ch, dh
  1213 00001A22 0F875CFBFFFF        <1> 	ja	VIDEO_RETURN
  1214 00001A28 38D1                <1> 	cmp	cl, dl
  1215 00001A2A 0F8754FBFFFF        <1> 	ja	VIDEO_RETURN
  1216                              <1> 	;
  1217 00001A30 E805000000          <1> 	call	_scroll_up
  1218 00001A35 E94AFBFFFF          <1>         jmp     VIDEO_RETURN
  1219                              <1> 
  1220                              <1> _scroll_up:  ; from 'write_tty'
  1221                              <1> 	;
  1222                              <1> 	; cl = left upper column
  1223                              <1> 	; ch = left upper row
  1224                              <1> 	; dl = right lower column
  1225                              <1> 	; dh = right lower row
  1226                              <1> 	;
  1227                              <1> 	; al = line count 
  1228                              <1> 	; bl = attribute to be used on blanked line	
  1229                              <1> 	; bh = video page number (0 to 7)
  1230                              <1> 
  1231 00001A3A E896000000          <1> 	call	test_line_count ; 16/01/2016
  1232                              <1> 
  1233 00001A3F 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  1234                              <1> 	;cmp	ah, 4
  1235                              <1>  	;jb	short n0
  1236                              <1> 	;cmp	byte [CRT_MODE], 4
  1237 00001A45 80FC04              <1>         cmp	ah, 4 ; 07/07/2016
  1238 00001A48 0F8320050000        <1> 	jnb     GRAPHICS_UP ; 26/06/2016
  1239                              <1> 
  1240                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1241                              <1> 	;jne	GRAPHICS_UP
  1242                              <1> n0:
  1243                              <1> 	; 07/07/2016
  1244 00001A4E 80FF07              <1> 	cmp	bh, 7 ; video page number
  1245 00001A51 7606                <1> 	jna	short n1
  1246 00001A53 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE]
  1247                              <1> n1:
  1248 00001A59 88DC                <1> 	mov	ah, bl ; attribute
  1249 00001A5B 6650                <1> 	push	ax ; *
  1250                              <1> 	;mov 	esi, [CRT_BASE]
  1251 00001A5D BE00800B00          <1>         mov     esi, 0B8000h  
  1252 00001A62 3A3D[D6580100]      <1>         cmp     bh, [ACTIVE_PAGE]
  1253 00001A68 750B                <1> 	jne	short n2
  1254                              <1> 	;
  1255 00001A6A 66A1[C4580100]      <1>         mov     ax, [CRT_START]
  1256 00001A70 6601C6              <1>         add     si, ax
  1257 00001A73 EB11                <1>         jmp     short n4
  1258                              <1> n2:
  1259 00001A75 20FF                <1>         and     bh, bh
  1260 00001A77 740D                <1> 	jz	short n4
  1261 00001A79 88F8                <1> 	mov	al, bh
  1262                              <1> n3:
  1263 00001A7B 660335[38650100]    <1>         add	si, [CRT_LEN]
  1264 00001A82 FEC8                <1>         dec	al
  1265 00001A84 75F5                <1> 	jnz	short n3
  1266                              <1> n4:	
  1267 00001A86 E85D000000          <1> 	call	scroll_position ; 16/01/2016
  1268 00001A8B 7420                <1>         jz      short n6 
  1269                              <1> 
  1270 00001A8D 01CE                <1>         add     esi, ecx ; from address for scroll
  1271 00001A8F 88F5                <1> 	mov	ch, dh  ; #rows in block
  1272 00001A91 28C5                <1> 	sub	ch, al	; #rows to be moved
  1273                              <1> n5:
  1274 00001A93 E894000000          <1> 	call	n10 ; 16/01/2016
  1275                              <1> 	
  1276 00001A98 51                  <1>         push	ecx
  1277 00001A99 0FB60D[F45E0000]    <1> 	movzx	ecx, byte [CRT_COLS] 
  1278 00001AA0 00C9                <1> 	add	cl, cl
  1279 00001AA2 01CE                <1>         add	esi, ecx  ; next line
  1280 00001AA4 01CF                <1>         add	edi, ecx
  1281 00001AA6 59                  <1> 	pop	ecx
  1282                              <1> 
  1283 00001AA7 FECD                <1> 	dec	ch	 ; count of lines to move
  1284 00001AA9 75E8                <1> 	jnz	short n5 ; row loop
  1285                              <1> 	; ch = 0
  1286 00001AAB 88C6                <1> 	mov	dh, al	 ; #rows	
  1287                              <1> n6:
  1288                              <1> 	; attribute in ah
  1289 00001AAD B020                <1> 	mov	al, ' '	 ; fill with blanks
  1290                              <1> n7:
  1291 00001AAF E885000000          <1> 	call	n11 ; 16/01/2016
  1292                              <1> 
  1293 00001AB4 8A0D[F45E0000]      <1> 	mov	cl, [CRT_COLS]
  1294 00001ABA 00C9                <1> 	add	cl, cl
  1295 00001ABC 01CF                <1>         add	edi, ecx
  1296                              <1> 
  1297 00001ABE FECE                <1> 	dec	dh
  1298 00001AC0 75ED                <1> 	jnz	short n7
  1299                              <1> n16:
  1300 00001AC2 3A3D[D6580100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  1301 00001AC8 750A                <1> 	jne	short n8
  1302                              <1> 	
  1303                              <1> 	;cmp	byte [CRT_MODE], 7	; is this the black and white card
  1304                              <1> 	;je	short n8		; if so, skip the mode reset
  1305                              <1> 
  1306 00001ACA A0[F35E0000]        <1> 	mov	al, [CRT_MODE_SET] ; get the value of mode set
  1307 00001ACF 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  1308 00001AD3 EE                  <1> 	out	dx, al
  1309                              <1> n8:
  1310 00001AD4 C3                  <1> 	retn
  1311                              <1> 
  1312                              <1> test_line_count:
  1313                              <1> 	; 12/05/2016
  1314                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1315                              <1> 	; 07/09/2014 (scroll_up)
  1316 00001AD5 08C0                <1> 	or	al, al
  1317 00001AD7 740E                <1> 	jz	short al_set2
  1318 00001AD9 6652                <1> 	push	dx
  1319 00001ADB 28EE                <1> 	sub	dh, ch  ; subtract upper row from lower row number
  1320 00001ADD FEC6                <1> 	inc	dh	; adjust difference by 1
  1321 00001ADF 38C6                <1> 	cmp	dh, al 	; line count = amount of rows in window?
  1322 00001AE1 7502                <1> 	jne	short al_set1 ; if not the we're all set
  1323 00001AE3 30C0                <1> 	xor	al, al	; otherwise set al to zero
  1324                              <1> al_set1:
  1325 00001AE5 665A                <1> 	pop	dx
  1326                              <1> al_set2:
  1327 00001AE7 C3                  <1> 	retn
  1328                              <1> 
  1329                              <1> scroll_position:
  1330                              <1> 	; 26/06/2016
  1331                              <1> 	; 30/01/2016
  1332                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1333                              <1> 	; 07/09/2014 (scroll_up)
  1334                              <1> 
  1335 00001AE8 6652                <1> 	push	dx
  1336 00001AEA 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  1337 00001AED E8EEFEFFFF          <1> 	call	position
  1338 00001AF2 01C6                <1> 	add	esi, eax
  1339 00001AF4 89F7                <1> 	mov	edi, esi
  1340 00001AF6 665A                <1> 	pop	dx	; lower right position in DX
  1341 00001AF8 6629CA              <1> 	sub	dx, cx
  1342 00001AFB FEC6                <1> 	inc	dh	; dh = #rows 
  1343 00001AFD FEC2                <1> 	inc	dl	; dl = #cols in block
  1344 00001AFF 59                  <1> 	pop	ecx 	; return address
  1345 00001B00 6658                <1> 	pop	ax	; * ; al = line count, ah = attribute
  1346 00001B02 51                  <1> 	push	ecx	; return address
  1347 00001B03 0FB7C8              <1> 	movzx	ecx, ax
  1348 00001B06 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS]
  1349 00001B0C F6E4                <1> 	mul	ah	; determine offset to from address
  1350 00001B0E 6601C0              <1> 	add	ax, ax  ; *2 for attribute byte
  1351                              <1> 	;
  1352 00001B11 6650                <1> 	push	ax	; offset 
  1353 00001B13 6652                <1> 	push	dx
  1354                              <1> 	;
  1355                              <1> 	; 04/04/2014
  1356 00001B15 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  1357                              <1> n9:                      ; wait_display_enable
  1358 00001B19 EC                  <1>         in      al, dx   ; get port
  1359 00001B1A A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  1360 00001B1C 74FB                <1> 	jz	short n9 ; wait_display_enable
  1361 00001B1E B025                <1> 	mov	al, 25h
  1362 00001B20 B2D8                <1> 	mov	dl, 0D8h ; address control port
  1363 00001B22 EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  1364 00001B23 665A                <1> 	pop	dx	; #rows, #cols
  1365 00001B25 6658                <1>        	pop	ax	; offset
  1366 00001B27 6691                <1> 	xchg	ax, cx	; 
  1367                              <1> 	; ecx = offset, al = line count, ah = attribute
  1368                              <1> 	;
  1369 00001B29 08C0                <1> 	or	al, al
  1370 00001B2B C3                  <1> 	retn
  1371                              <1> n10:
  1372                              <1> 	; Move rows
  1373 00001B2C 88D1                <1> 	mov	cl, dl	; get # of cols to move
  1374 00001B2E 56                  <1> 	push	esi
  1375 00001B2F 57                  <1> 	push	edi	; save start address
  1376                              <1> n10r:
  1377 00001B30 66A5                <1> 	movsw		; move that line on screen
  1378 00001B32 FEC9                <1> 	dec	cl
  1379 00001B34 75FA                <1>         jnz     short n10r
  1380 00001B36 5F                  <1> 	pop	edi
  1381 00001B37 5E                  <1> 	pop	esi	; recover addresses
  1382 00001B38 C3                  <1> 	retn
  1383                              <1> n11:
  1384                              <1> 	; Clear rows
  1385                              <1>                 	; dh =  #rows
  1386 00001B39 88D1                <1>         mov	cl, dl	; get # of cols to clear
  1387 00001B3B 57                  <1>         push    edi     ; save address
  1388                              <1> n11r:
  1389 00001B3C 66AB                <1>         stosw           ; store fill character
  1390 00001B3E FEC9                <1> 	dec	cl
  1391 00001B40 75FA                <1>         jnz     short n11r
  1392 00001B42 5F                  <1>         pop     edi     ; recover address
  1393 00001B43 C3                  <1> 	retn
  1394                              <1> 
  1395                              <1> SCROLL_DOWN:
  1396                              <1> 	; 07/07/2016
  1397                              <1> 	; 27/06/2016
  1398                              <1> 	; 26/06/2016
  1399                              <1> 	; 12/05/2016
  1400                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1401                              <1> 	;
  1402                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1403                              <1> 
  1404                              <1> ;------------------------------------------
  1405                              <1> ; SCROLL DOWN
  1406                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  1407                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  1408                              <1> ;	WITH A DEFINED CHARACTER
  1409                              <1> ; INPUT
  1410                              <1> ;	(AH) = CURRENT CRT MODE
  1411                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  1412                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  1413                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  1414                              <1> ;	(BH) = FILL CHARACTER
  1415                              <1> ;	(DS) = DATA SEGMENT
  1416                              <1> ;	(ES) = REGEN SEGMENT
  1417                              <1> ; OUTPUT
  1418                              <1> ;	NONE -- SCREEN IS SCROLLED
  1419                              <1> ;------------------------------------------
  1420                              <1> 
  1421                              <1> 	; 07/07/2016
  1422 00001B44 38F5                <1> 	cmp	ch, dh
  1423 00001B46 0F8738FAFFFF        <1> 	ja	VIDEO_RETURN
  1424 00001B4C 38D1                <1> 	cmp	cl, dl
  1425 00001B4E 0F8730FAFFFF        <1> 	ja	VIDEO_RETURN
  1426                              <1> 	;
  1427 00001B54 E805000000          <1> 	call	_scroll_down
  1428 00001B59 E926FAFFFF          <1>         jmp     VIDEO_RETURN
  1429                              <1> 
  1430                              <1> _scroll_down: ; 27/06/2016
  1431                              <1> 
  1432                              <1> 	; cl = left upper column
  1433                              <1> 	; ch = left upper row
  1434                              <1> 	; dl = right lower column
  1435                              <1> 	; dh = right lower row
  1436                              <1> 	;
  1437                              <1> 	; al = line count 
  1438                              <1> 	; bl = attribute to be used on blanked line	
  1439                              <1> 	; bh = video page number (0 to 7)
  1440                              <1> 
  1441                              <1> 	; !!!!
  1442 00001B5E FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  1443                              <1> 	; !!!!
  1444 00001B5F E871FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  1445                              <1> 	
  1446 00001B64 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  1447                              <1> 	;cmp	ah, 4
  1448                              <1>  	;jb	short _n0
  1449                              <1> 	;cmp	byte [CRT_MODE], 4
  1450 00001B6A 80FC04              <1>         cmp	ah, 4 ; 07/07/2016
  1451 00001B6D 0F83DF070000        <1> 	jnb     GRAPHICS_DOWN ; 26/06/2016
  1452                              <1> 
  1453                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1454                              <1> 	;jne	GRAPHICS_DOWN
  1455                              <1> _n0:
  1456                              <1> 	; 07/07/2016
  1457 00001B73 80FF07              <1> 	cmp	bh, 7 ; video page number
  1458 00001B76 7606                <1> 	jna	short n12
  1459 00001B78 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE]
  1460                              <1> 	;
  1461                              <1> n12:			; CONTINUE_DOWN
  1462 00001B7E 88DC                <1> 	mov	ah, bl
  1463 00001B80 6650                <1> 	push	ax	; * ; save attribute in ah
  1464 00001B82 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  1465 00001B85 E85EFFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  1466 00001B8A 741F                <1> 	jz	short n14
  1467 00001B8C 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  1468 00001B8E 88F5                <1> 	mov	ch, dh  ; #rows in block
  1469 00001B90 28C5                <1> 	sub	ch, al	; #rows to be moved
  1470                              <1> n13:
  1471 00001B92 E895FFFFFF          <1> 	call	n10	; MOVE ONE ROW
  1472                              <1> 
  1473 00001B97 51                  <1> 	push	ecx
  1474 00001B98 8A0D[F45E0000]      <1> 	mov	cl, [CRT_COLS] 
  1475 00001B9E 00C9                <1> 	add	cl, cl
  1476 00001BA0 29CE                <1>         sub	esi, ecx  ; next line
  1477 00001BA2 29CF                <1>         sub	edi, ecx
  1478 00001BA4 59                  <1>         pop	ecx
  1479                              <1> 	
  1480 00001BA5 FECD                <1> 	dec	ch	 ; count of lines to move
  1481 00001BA7 75E9                <1> 	jnz	short n13 ; row loop
  1482                              <1> 	; ch = 0
  1483 00001BA9 88C6                <1> 	mov	dh, al	 ; #rows
  1484                              <1> n14:
  1485                              <1> 	; attribute in ah
  1486 00001BAB B020                <1> 	mov	al, ' '	 ; fill with blanks
  1487                              <1> n15:
  1488 00001BAD E887FFFFFF          <1> 	call	n11 ; 16/01/2016
  1489                              <1> 
  1490 00001BB2 8A0D[F45E0000]      <1> 	mov	cl, [CRT_COLS]
  1491 00001BB8 00C9                <1> 	add	cl, cl
  1492 00001BBA 29CF                <1>         sub	edi, ecx
  1493                              <1>         
  1494 00001BBC FECE                <1> 	dec	dh
  1495 00001BBE 75ED                <1> 	jnz	short n15
  1496                              <1> 	;
  1497 00001BC0 E9FDFEFFFF          <1> 	jmp	n16 ; 27/06/2016
  1498                              <1> 
  1499                              <1> ;	cmp	bh, [ACTIVE_PAGE]
  1500                              <1> ;	jne	short n16
  1501                              <1> ;
  1502                              <1> ;	;cmp	byte [CRT_MODE], 7	; is this the black and white card
  1503                              <1> ;	;je	short n16		; if so, skip the mode reset
  1504                              <1> ;
  1505                              <1> ;	mov	al, [CRT_MODE_SET] ; get the value of mode set
  1506                              <1> ;	mov	dx, 03D8h ; always set color card port
  1507                              <1> ;	out	dx, al
  1508                              <1> ;n16:
  1509                              <1> ;	; !!!!
  1510                              <1> ;	cld		; Clear direction flag !
  1511                              <1> ;	; !!!!
  1512                              <1> ;	retn
  1513                              <1> 
  1514                              <1> READ_AC_CURRENT:
  1515                              <1> 	; 08/07/2016
  1516                              <1> 	; 26/06/2016
  1517                              <1> 	; 12/05/2016
  1518                              <1> 	; 18/01/2016
  1519                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1520                              <1> 	;
  1521                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1522                              <1> 	;
  1523                              <1> 	; 08/07/2016
  1524 00001BC5 803D[F25E0000]07    <1>         cmp     byte [CRT_MODE], 7 ; 6!?
  1525 00001BCC 7607                <1> 	jna	short read_ac_c
  1526 00001BCE 31C0                <1> 	xor	eax, eax
  1527 00001BD0 E9B4F9FFFF          <1>         jmp     _video_return 
  1528                              <1> read_ac_c:
  1529 00001BD5 E805000000          <1> 	call	_read_ac_current
  1530                              <1> 	; 12/05/2016
  1531                              <1>         ;jmp     VIDEO_RETURN
  1532 00001BDA E9AAF9FFFF          <1> 	jmp	_video_return
  1533                              <1> 
  1534                              <1> ;------------------------------------------------------------------------
  1535                              <1> ; READ_AC_CURRENT							:
  1536                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  1537                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  1538                              <1> ; INPUT									:
  1539                              <1> ;	(AH) = CURRENT CRT MODE						:
  1540                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  1541                              <1> ;	(DS) = DATA SEGMENT						:
  1542                              <1> ;	(ES) = REGEN SEGMENT						:
  1543                              <1> ; OUTPUT								:
  1544                              <1> ;	(AL) = CHARACTER READ						:
  1545                              <1> ;	(AH) = ATTRIBUTE READ						:
  1546                              <1> ;------------------------------------------------------------------------
  1547                              <1> 
  1548                              <1> _read_ac_current:
  1549                              <1> 	; 26/06/2016
  1550                              <1> 	; 12/05/2016 
  1551                              <1> 	; 18/01/2016
  1552                              <1> 
  1553                              <1> 	;mov	ah, [CRT_MODE] ; current video mode	
  1554                              <1> 	;cmp	ah, 4
  1555                              <1>  	;jb	short p10
  1556 00001BDF 803D[F25E0000]04    <1> 	cmp	byte [CRT_MODE], 4
  1557 00001BE6 0F83BB080000        <1> 	jnb     GRAPHICS_READ ; 26/06/2016
  1558                              <1> 
  1559                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1560                              <1> 	;jne	GRAPHICS_READ
  1561                              <1> p10:
  1562 00001BEC E801FEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  1563                              <1> 	;
  1564                              <1> 	; esi = regen location
  1565                              <1> 	; dx = status port
  1566                              <1> 	;
  1567 00001BF1 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE]	
  1568 00001BF7 80EC02              <1> 	sub	ah, 2
  1569 00001BFA D0EC                <1> 	shr	ah, 1
  1570 00001BFC 7515                <1> 	jnz	short p13
  1571                              <1> 
  1572                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  1573                              <1> p11:
  1574 00001BFE FB                  <1> 	sti		; enable interrupts first
  1575 00001BFF 3A3D[D6580100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  1576 00001C05 750C                <1> 	jne	short p13 
  1577 00001C07 FA                  <1> 	cli 		; block interrupts for single loop
  1578 00001C08 EC                  <1> 	in	al, dx	; get status from the adapter
  1579 00001C09 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  1580 00001C0B 75F1                <1> 	jnz	short p11 ; wait until it is
  1581                              <1> p12:			;  wait for either retrace high
  1582 00001C0D EC                  <1> 	in	al, dx ; get status again
  1583 00001C0E A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  1584 00001C10 74FB                <1> 	jz	short p12 ; wait until either retrace active
  1585 00001C12 FB                  <1> 	sti
  1586                              <1> p13:
  1587 00001C13 81C600800B00        <1> 	add	esi, 0B8000h 
  1588 00001C19 668B06              <1> 	mov	ax, [esi]
  1589                              <1> 
  1590 00001C1C C3                  <1> 	retn	; 18/01/2016
  1591                              <1> 
  1592                              <1> WRITE_AC_CURRENT:
  1593                              <1> 	; 08/07/2016
  1594                              <1> 	; 26/06/2016
  1595                              <1> 	; 24/06/2016
  1596                              <1> 	; 12/05/2016
  1597                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1598                              <1> 	;
  1599                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1600                              <1> 	;
  1601                              <1> ;----------------------------------------------------------------
  1602                              <1> ; WRITE_AC_CURRENT						:
  1603                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  1604                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  1605                              <1> ; INPUT								:
  1606                              <1> ;	(AH) = CURRENT CRT MODE					:
  1607                              <1> ;	(BH) = DISPLAY PAGE					:
  1608                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  1609                              <1> ;	(AL) = CHAR TO WRITE					:
  1610                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  1611                              <1> ;	(DS) = DATA SEGMENT					:
  1612                              <1> ;	(ES) = REGEN SEGMENT					:
  1613                              <1> ; OUTPUT							:
  1614                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  1615                              <1> ;----------------------------------------------------------------
  1616                              <1> 
  1617                              <1> 	; 08/07/2016
  1618 00001C1D 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  1619 00001C24 760A                <1> 	jna	short write_ac_c
  1620                              <1> 
  1621 00001C26 E8F20A0000          <1> 	call	vga_write_char_attr
  1622 00001C2B E954F9FFFF          <1> 	jmp     VIDEO_RETURN	
  1623                              <1> 
  1624                              <1> write_ac_c:
  1625 00001C30 E834000000          <1> 	call	_write_c_current
  1626                              <1> 
  1627 00001C35 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  1628 00001C38 889E[FB5E0000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  1629                              <1> 
  1630 00001C3E E941F9FFFF          <1>         jmp     VIDEO_RETURN
  1631                              <1> 
  1632                              <1> WRITE_C_CURRENT:
  1633                              <1> 	; 08/07/2016
  1634                              <1> 	; 26/06/2016
  1635                              <1> 	; 12/05/2016
  1636                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1637                              <1> 	;
  1638                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1639                              <1> 	;
  1640                              <1> ;----------------------------------------------------------------
  1641                              <1> ; WRITE_C_CURRENT						:
  1642                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  1643                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  1644                              <1> ; INPUT								:
  1645                              <1> ;	(AH) = CURRENT CRT MODE					:
  1646                              <1> ;	(BH) = DISPLAY PAGE					:
  1647                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  1648                              <1> ;	(AL) = CHAR TO WRITE					:
  1649                              <1> ;	(DS) = DATA SEGMENT					:
  1650                              <1> ;	(ES) = REGEN SEGMENT					:
  1651                              <1> ; OUTPUT							:
  1652                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  1653                              <1> ;----------------------------------------------------------------
  1654                              <1> 
  1655                              <1> 	; 08/07/2016
  1656 00001C43 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  1657 00001C4A 760A                <1> 	jna	short write_c_c
  1658                              <1> 
  1659 00001C4C E8CC0A0000          <1> 	call	vga_write_char_only
  1660 00001C51 E92EF9FFFF          <1> 	jmp     VIDEO_RETURN	
  1661                              <1> 
  1662                              <1> write_c_c:
  1663                              <1> 	;and	bh, 7 ; video page number (<= 7)
  1664 00001C56 0FB6F7              <1> 	movzx	esi, bh	
  1665 00001C59 8A9E[FB5E0000]      <1> 	mov	bl, [esi+chr_attrib]
  1666                              <1> 
  1667 00001C5F E805000000          <1> 	call	_write_c_current
  1668 00001C64 E91BF9FFFF          <1>         jmp     VIDEO_RETURN
  1669                              <1> 
  1670                              <1> _write_c_current:  ; from 'write_tty'
  1671                              <1> 	; 26/06/2016
  1672                              <1> 	; 24/06/2016
  1673                              <1> 	; 12/05/2016
  1674                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1675                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1676                              <1> 	; 18/01/2014
  1677                              <1> 	; 04/12/2013
  1678                              <1> 	;
  1679                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1680                              <1> 
  1681                              <1> 	;mov	ah, [CRT_MODE] ; current video mode	
  1682                              <1> 	;cmp	ah, 4
  1683                              <1>  	;jb	short p40
  1684 00001C69 803D[F25E0000]04    <1> 	cmp	byte [CRT_MODE], 4
  1685 00001C70 0F8381070000        <1>         jnb     GRAPHICS_WRITE ; 26/06/2016
  1686                              <1> 
  1687                              <1> 	;cmp	ah, 7 ; TEST FOR BW CARD
  1688                              <1> 	;jne	GRAPHICS_WRITE
  1689                              <1> p40:
  1690                              <1> 	; al = character
  1691                              <1> 	; bl = color/attribute
  1692                              <1> 	; bh = video page
  1693                              <1> 	; cx = count of characters to write
  1694 00001C76 6652                <1> 	push	dx
  1695 00001C78 88DC                <1> 	mov	ah, bl  ; color/attribute (12/05/2016)
  1696 00001C7A 6650                <1> 	push	ax	; save character & attribute/color
  1697 00001C7C 6651                <1> 	push	cx
  1698 00001C7E E86FFDFFFF          <1> 	call 	find_position  ; get regen location and port address
  1699 00001C83 6659                <1> 	pop	cx
  1700                              <1> 	; esi = regen location
  1701                              <1> 	; dx = status port
  1702                              <1> 	;
  1703 00001C85 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  1704                              <1> 	;
  1705 00001C8B 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE]	
  1706 00001C91 80EC02              <1> 	sub	ah, 2
  1707 00001C94 D0EC                <1> 	shr	ah, 1
  1708 00001C96 7519                <1> 	jnz	short p44    ; 26/06/2016
  1709                              <1> 
  1710                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  1711                              <1> p41:
  1712 00001C98 FB                  <1> 	sti		; enable interrupts first
  1713 00001C99 3A3D[D6580100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  1714 00001C9F 7510                <1> 	jne	short p44 
  1715 00001CA1 FA                  <1> 	cli 		; block interrupts for single loop
  1716 00001CA2 EC                  <1> 	in	al, dx	; get status from the adapter
  1717 00001CA3 A808                <1> 	test	al, RVRT ; check for vertical retrace first
  1718 00001CA5 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  1719 00001CA7 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  1720 00001CA9 75ED                <1> 	jnz	short p41 ; wait until it is
  1721                              <1> p42:			;  wait for either retrace high
  1722 00001CAB EC                  <1> 	in	al, dx ; get status again
  1723 00001CAC A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  1724 00001CAE 74FB                <1> 	jz	short p42 ; wait until either retrace active
  1725                              <1> p43:	
  1726 00001CB0 FB                  <1> 	sti
  1727                              <1> p44:
  1728 00001CB1 668B0424            <1> 	mov	ax, [esp] ; restore the character (al) & attribute (ah)
  1729 00001CB5 668906              <1> 	mov	[esi], ax
  1730                              <1> 
  1731 00001CB8 6649                <1> 	dec	cx
  1732 00001CBA 7404                <1> 	jz	short p45
  1733                              <1> 
  1734 00001CBC 46                  <1> 	inc	esi
  1735 00001CBD 46                  <1> 	inc	esi
  1736 00001CBE EBD8                <1> 	jmp	short p41
  1737                              <1> p45:	
  1738 00001CC0 6658                <1> 	pop	ax
  1739 00001CC2 665A                <1> 	pop	dx
  1740 00001CC4 C3                  <1> 	retn
  1741                              <1> 
  1742                              <1> ; 09/07/2016
  1743                              <1> ; 26/06/2016
  1744                              <1> ; 24/06/2016
  1745                              <1> ; 12/05/2016
  1746                              <1> ; 18/01/2016
  1747                              <1> ; 16/01/2016 - TRDOS 386 (TRDOS v2.0)
  1748                              <1> ; 30/06/2015
  1749                              <1> ; 27/06/2015
  1750                              <1> ; 11/03/2015
  1751                              <1> ; 02/09/2014
  1752                              <1> ; 30/08/2014
  1753                              <1> ; VIDEO FUNCTIONS
  1754                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  1755                              <1> 
  1756                              <1> WRITE_TTY:
  1757                              <1> 	; 09/12/2017
  1758                              <1> 	; 09/07/2016
  1759                              <1> 	; 01/07/2016
  1760                              <1> 	; 26/06/2016
  1761                              <1> 	; 24/06/2016
  1762                              <1> 	; 13/05/2016
  1763                              <1> 	; 12/05/2016
  1764                              <1> 	; 30/01/2016
  1765                              <1> 	; 18/01/2016
  1766                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1767                              <1> 	; 13/08/2015
  1768                              <1> 	; 02/09/2014
  1769                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  1770                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  1771                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  1772                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  1773                              <1> 	;
  1774                              <1> 	; INPUT -> AL = Character to be written
  1775                              <1> 	;	   BL = Color (Forecolor, Backcolor)
  1776                              <1> 	;	   BH = Video Page (0 to 7)
  1777                              <1> 
  1778                              <1> 	; 09/07/2016
  1779 00001CC5 803D[F25E0000]07    <1>         cmp     byte [CRT_MODE], 7
  1780 00001CCC 760A                <1> 	jna 	short write_tty_cga
  1781                              <1> 
  1782 00001CCE E8290D0000          <1> 	call	vga_write_teletype
  1783 00001CD3 E9ACF8FFFF          <1> 	jmp	VIDEO_RETURN
  1784                              <1> 
  1785                              <1> write_tty_cga:
  1786                              <1> 	; 13/05/2016
  1787                              <1> 	;call	_write_tty
  1788                              <1> 	; 01/07/2016
  1789 00001CD8 E818000000          <1> 	call	_write_tty_m3
  1790 00001CDD E9A2F8FFFF          <1> 	jmp	VIDEO_RETURN
  1791                              <1> 
  1792                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  1793                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  1794                              <1> 
  1795                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  1796                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  1797                              <1> ;
  1798                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  1799                              <1> ;
  1800                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  1801                              <1> ;										:
  1802                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  1803                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  1804                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  1805                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  1806                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  1807                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  1808                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  1809                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  1810                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  1811                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  1812                              <1> ;   THE 0 COLOR IS USED.							:
  1813                              <1> ;   ENTRY --									:
  1814                              <1> ;     (AH) = CURRENT CRT MODE							:
  1815                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  1816                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  1817                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  1818                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  1819                              <1> ;   EXIT -- 									:
  1820                              <1> ;     ALL REGISTERS SAVED							:
  1821                              <1> ;--------------------------------------------------------------------------------
  1822                              <1> 
  1823                              <1> ; 09/12/2017
  1824                              <1> ; 08/07/2016
  1825                              <1> ; 26/06/2016
  1826                              <1> ; 24/06/2016
  1827                              <1> _write_tty:	; 13/05/2016
  1828 00001CE2 FA                  <1> 	cli
  1829                              <1> 	;
  1830                              <1> 	; 01/09/2014
  1831 00001CE3 803D[F25E0000]03    <1> 	cmp	byte [CRT_MODE], 3
  1832 00001CEA 7409                <1> 	je	short _write_tty_m3
  1833                              <1> 	;
  1834                              <1> set_mode_3:
  1835 00001CEC 53                  <1> 	push	ebx
  1836 00001CED 50                  <1> 	push	eax
  1837 00001CEE E8A2F8FFFF          <1> 	call	_set_mode
  1838 00001CF3 58                  <1> 	pop	eax
  1839 00001CF4 5B                  <1> 	pop	ebx
  1840                              <1> 	;
  1841                              <1> _write_tty_m3: ; 24/06/2016 (m3 -> _write_tty_m3)
  1842 00001CF5 0FB6F7              <1> 	movzx 	esi, bh ; 12/05/2016
  1843 00001CF8 66D1E6              <1> 	shl	si, 1
  1844 00001CFB 81C6[C6580100]      <1> 	add	esi, CURSOR_POSN
  1845 00001D01 668B16              <1> 	mov	dx, [esi]
  1846                              <1> 	;
  1847                              <1> 	; dx now has the current cursor position
  1848                              <1> 	;
  1849 00001D04 3C0D                <1> 	cmp	al, 0Dh	; CR	; is it carriage return or control character
  1850 00001D06 7636                <1> 	jbe	short u8
  1851                              <1> 	;
  1852                              <1> 	; write the char to the screen
  1853                              <1> u0:	
  1854                              <1> 	; al = character
  1855                              <1> 	; bl = attribute/color
  1856                              <1> 	; bh = video page number (0 to 7)
  1857                              <1> 	;
  1858 00001D08 66B90100            <1> 	mov	cx, 1  ; 24/06/2016
  1859                              <1> 	; cx = count of characters to write
  1860                              <1> 	;
  1861 00001D0C E858FFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  1862                              <1> 	;
  1863                              <1> 	; position the cursor for next char
  1864 00001D11 FEC2                <1> 	inc	dl		; next column
  1865 00001D13 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS]  ; test for column overflow 
  1866 00001D19 755D                <1>         jne     _set_cpos
  1867 00001D1B B200                <1> 	mov	dl, 0		; column = 0
  1868                              <1> u10:				; (line feed found)
  1869 00001D1D 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  1870 00001D20 7218                <1> 	jb 	short u6
  1871                              <1> 	;
  1872                              <1> 	; scroll required
  1873                              <1> u1:	
  1874                              <1> 	; SET CURSOR POSITION (04/12/2013)
  1875 00001D22 E851000000          <1> 	call	_set_cpos
  1876                              <1> 	;
  1877                              <1> 	; determine value to fill with during scroll
  1878                              <1> u2:
  1879                              <1> 	; bh = video page number
  1880                              <1> 	;
  1881 00001D27 E8B3FEFFFF          <1> 	call	_read_ac_current ; 18/01/2016
  1882                              <1> 	;
  1883                              <1> 	; al = character, ah = attribute
  1884                              <1> 	; bh = video page number 	
  1885                              <1> u3:
  1886                              <1> 	;;mov	ax, 0601h 	; scroll one line
  1887                              <1> 	;;sub	cx, cx		; upper left corner
  1888                              <1> 	;;mov	dh, 25-1 	; lower right row
  1889                              <1> 	;;;mov	dl, [CRT_COLS]
  1890                              <1> 	;mov	dl, 80		; lower right column	
  1891                              <1> 	;;dec	dl
  1892                              <1> 	;;mov	dl, 79
  1893                              <1> 
  1894                              <1> 	;;call	scroll_up	; 04/12/2013
  1895                              <1> 	;;; 11/03/2015
  1896                              <1> 	; 02/09/2014
  1897                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  1898                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  1899                              <1> 	; 11/03/2015
  1900 00001D2C 6629C9              <1> 	sub	cx, cx
  1901 00001D2F 66BA4F18            <1> 	mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  1902                              <1> 	;
  1903 00001D33 B001                <1> 	mov	al, 1		; scroll 1 line up
  1904                              <1> 		; ah = attribute
  1905                              <1> 	;mov	bl, al ; 12/05/2016
  1906 00001D35 E900FDFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  1907                              <1> ;u4:
  1908                              <1> 	;;int	10h		; video-call return
  1909                              <1> 				; scroll up the screen
  1910                              <1> 				; tty return
  1911                              <1> ;u5:
  1912                              <1> 	;retn			; return to the caller
  1913                              <1> 
  1914                              <1> u6:				; set-cursor-inc
  1915 00001D3A FEC6                <1> 	inc	dh		; next row
  1916                              <1> 				; set cursor
  1917                              <1> ;u7:					
  1918                              <1> 	;;mov	ah, 02h
  1919                              <1> 	;;jmp	short u4 	; establish the new cursor
  1920                              <1> 	;call	_set_cpos
  1921                              <1> 	;jmp 	short u5
  1922 00001D3C EB3A                <1> 	jmp     _set_cpos
  1923                              <1> 
  1924                              <1> 	; check for control characters
  1925                              <1> u8:
  1926 00001D3E 7436                <1> 	je	short u9
  1927 00001D40 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  1928 00001D42 74D9                <1> 	je	short u10
  1929 00001D44 3C07                <1> 	cmp	al, 07h 	; is it a bell
  1930 00001D46 747A                <1> 	je	short u11
  1931 00001D48 3C08                <1> 	cmp	al, 08h		; is it a backspace
  1932                              <1> 	;jne	short u0
  1933 00001D4A 7422                <1> 	je	short bs	; 12/12/2013
  1934                              <1> 	; 12/12/2013 (tab stop)
  1935 00001D4C 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  1936 00001D4E 75B8                <1> 	jne	short u0
  1937 00001D50 88D0                <1> 	mov	al, dl
  1938                              <1> 	;cbw
  1939 00001D52 30E4                <1> 	xor	ah, ah ; 09/12/2017
  1940 00001D54 B108                <1> 	mov	cl, 8
  1941 00001D56 F6F1                <1> 	div	cl
  1942 00001D58 28E1                <1> 	sub	cl, ah
  1943                              <1> ts:
  1944                              <1> 	; 02/09/2014
  1945                              <1> 	; 01/09/2014
  1946 00001D5A B020                <1> 	mov	al, 20h
  1947                              <1> tsloop:
  1948 00001D5C 6651                <1> 	push	cx
  1949 00001D5E 6650                <1> 	push	ax
  1950                              <1> 	;mov	bh, [ACTIVE_PAGE]
  1951 00001D60 E890FFFFFF          <1> 	call	_write_tty_m3 ; 24/06/2016 (m3 -> _write_tty_m3)
  1952 00001D65 6658                <1> 	pop	ax  ; ah = attribute/color
  1953 00001D67 6659                <1> 	pop	cx
  1954 00001D69 FEC9                <1> 	dec	cl
  1955 00001D6B 75EF                <1> 	jnz	short tsloop
  1956 00001D6D C3                  <1> 	retn
  1957                              <1> bs:	
  1958                              <1> 	; back space found
  1959                              <1> 
  1960 00001D6E 08D2                <1> 	or	dl, dl 		; is it already at start of line
  1961                              <1> 	;je	short u7 	; set_cursor
  1962 00001D70 7406                <1> 	jz	short _set_cpos
  1963 00001D72 664A                <1> 	dec	dx     		; no -- just move it back
  1964                              <1> 	;jmp	short u7
  1965 00001D74 EB02                <1> 	jmp	short _set_cpos
  1966                              <1> 
  1967                              <1> 	; carriage return found
  1968                              <1> u9:
  1969 00001D76 B200                <1> 	mov	dl, 0 		; move to first column
  1970                              <1> 	;jmp	short u7
  1971                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  1972                              <1> 
  1973                              <1> 	; line feed found
  1974                              <1> ;u10:
  1975                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  1976                              <1> ;	jne	short u6 	; no, just set the cursor
  1977                              <1> ;       jmp     u1              ; yes, scroll the screen
  1978                              <1> 
  1979                              <1> _set_cpos:
  1980                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  1981                              <1> 	; 27/06/2015
  1982                              <1> 	; 01/09/2014
  1983                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  1984                              <1> 	;
  1985                              <1> 	; 04/12/2013 - 12/12/2013 (Retro UNIX 8086 v1) 
  1986                              <1> 	;
  1987                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  1988                              <1> 	;
  1989                              <1> ;----------------------------------------------
  1990                              <1> ; SET_CPOS
  1991                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  1992                              <1> ;	NEW X-Y VALUES PASSED
  1993                              <1> ; INPUT
  1994                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  1995                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  1996                              <1> ; OUTPUT
  1997                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  1998                              <1> ;----------------------------------------------
  1999                              <1> 	;
  2000 00001D78 BE[C6580100]        <1> 	mov	esi, CURSOR_POSN
  2001 00001D7D 0FB6C7              <1>         movzx   eax, bh	; BH = video page number
  2002                              <1> ;	or	al, al
  2003                              <1> ;	jz	short _set_cpos_0
  2004 00001D80 D0E0                <1>         shl     al, 1   ; word offset
  2005 00001D82 01C6                <1>         add     esi, eax
  2006                              <1> ;_set_cpos_0:
  2007 00001D84 668916              <1> 	mov	[esi], dx ; save the pointer
  2008 00001D87 383D[D6580100]      <1> 	cmp	[ACTIVE_PAGE], bh
  2009 00001D8D 7532                <1> 	jne	short m17
  2010                              <1> 	;call	m18	; CURSOR SET
  2011                              <1> ;m17:			; SET_CPOS_RETURN
  2012                              <1> 	; 01/09/2014
  2013                              <1> ;	retn
  2014                              <1> 		; DX  = row/column
  2015                              <1> m18:
  2016 00001D8F E84CFCFFFF          <1> 	call	position ; determine location in regen buffer	
  2017 00001D94 668B0D[C4580100]    <1> 	mov	cx, [CRT_START]
  2018 00001D9B 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  2019                              <1> 			; to the start address (offset) for this page
  2020 00001D9E 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  2021 00001DA1 B40E                <1> 	mov	ah, 14	; register number for cursor
  2022                              <1> 	;call	m16	; output value to the 6845	
  2023                              <1> 	;retn
  2024                              <1> 
  2025                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  2026                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  2027                              <1> m16:
  2028 00001DA3 FA                  <1> 	cli
  2029                              <1> 	;mov	dx, [addr_6845] ; address register
  2030 00001DA4 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  2031 00001DA8 88E0                <1> 	mov	al, ah	; get value
  2032 00001DAA EE                  <1> 	out	dx, al	; register set
  2033 00001DAB 6642                <1> 	inc	dx	; data register
  2034 00001DAD EB00                <1> 	jmp	$+2	; i/o delay
  2035 00001DAF 88E8                <1> 	mov	al, ch	; data
  2036 00001DB1 EE                  <1> 	out	dx, al	
  2037 00001DB2 664A                <1> 	dec	dx	
  2038 00001DB4 88E0                <1> 	mov	al, ah
  2039 00001DB6 FEC0                <1> 	inc	al	; point to other data register
  2040 00001DB8 EE                  <1> 	out	dx, al	; set for second register
  2041 00001DB9 6642                <1> 	inc	dx
  2042 00001DBB EB00                <1> 	jmp	$+2	; i/o delay
  2043 00001DBD 88C8                <1> 	mov	al, cl	; second data value
  2044 00001DBF EE                  <1> 	out	dx, al
  2045 00001DC0 FB                  <1> 	sti
  2046                              <1> m17:
  2047 00001DC1 C3                  <1> 	retn
  2048                              <1> 
  2049                              <1> beeper: 
  2050                              <1> 	; 04/08/2016
  2051                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  2052                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2053                              <1> 	; 18/01/2014
  2054                              <1> 	; 03/12/2013
  2055                              <1> 	; bell found
  2056                              <1> u11:
  2057 00001DC2 FB                  <1> 	sti
  2058 00001DC3 3A3D[D6580100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  2059 00001DC9 7551                <1> 	jne	short u12	; Do not sound the beep 
  2060                              <1> 				; if it is not written on the active page
  2061                              <1> beeper_gfx: ; 04/08/2016
  2062 00001DCB 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  2063 00001DCF B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  2064                              <1> 	;call	beep		; sound the pod bell
  2065                              <1> 	;jmp	short u5 	; tty_return
  2066                              <1> 	;retn
  2067                              <1> 	
  2068                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  2069                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  2070                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  2071                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  2072                              <1> 
  2073                              <1> beep:
  2074                              <1> 	; 07/02/2015
  2075                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2076                              <1> 	; 18/01/2014
  2077                              <1> 	; 03/12/2013
  2078                              <1> 	;
  2079                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  2080                              <1> 	;
  2081                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  2082                              <1> 	;
  2083                              <1> 	; ENTRY:
  2084                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  2085                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  2086                              <1> 	; EXIT:				:
  2087                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  2088                              <1> 
  2089 00001DD1 9C                  <1> 	pushf  ; 18/01/2014	; save interrupt status
  2090 00001DD2 FA                  <1> 	cli			; block interrupts during update
  2091 00001DD3 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  2092 00001DD5 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  2093 00001DD7 EB00                <1> 	jmp	$+2		; I/O delay
  2094 00001DD9 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  2095 00001DDB E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  2096 00001DDD EB00                <1> 	jmp	$+2		; I/O delay
  2097 00001DDF 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  2098 00001DE1 E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  2099 00001DE3 E461                <1> 	in	al, PORT_B	; get current setting of port
  2100 00001DE5 88C4                <1> 	mov	ah, al		; save that setting
  2101 00001DE7 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  2102 00001DE9 E661                <1> 	out	PORT_B, al	; and restore interrupt status
  2103                              <1> 	;popf	; 18/01/2014
  2104 00001DEB FB                  <1> 	sti
  2105                              <1> g7:				; 1/64 second per count (bl)
  2106 00001DEC B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second	
  2107 00001DF1 E827000000          <1> 	call	waitf		; go to beep delay 1/64 count
  2108 00001DF6 FECB                <1> 	dec	bl		; (bl) length count expired?
  2109 00001DF8 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  2110                              <1> 	;
  2111                              <1> 	;pushf			; save interrupt status
  2112 00001DFA FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  2113 00001DFB E461                <1> 	in	al, PORT_B	; get current port value
  2114                              <1>         ;or      al, not (GATE2+SPK2) ; isolate current speaker bits in case
  2115 00001DFD 0CFC                <1>         or      al, ~(GATE2+SPK2)
  2116 00001DFF 20C4                <1>         and	ah, al		; someone turned them off during beep
  2117 00001E01 88E0                <1> 	mov	al, ah		; recover value of port
  2118                              <1>         ;or      al, not (GATE2+SPK2) ; force speaker data off
  2119 00001E03 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  2120 00001E05 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  2121                              <1> 	;popf			; restore interrupt flag state
  2122 00001E07 FB                  <1> 	sti
  2123 00001E08 B90B040000          <1> 	mov	ecx, 1035	; force 1/64 second delay (short)
  2124 00001E0D E80B000000          <1> 	call	waitf		; minimum delay between all beeps
  2125                              <1> 	;pushf			; save interrupt status
  2126 00001E12 FA                  <1> 	cli			; block interrupts during update
  2127 00001E13 E461                <1> 	in	al, PORT_B	; get current port value in case	
  2128 00001E15 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  2129 00001E17 08E0                <1> 	or	al, ah		; recover value of port_b
  2130 00001E19 E661                <1> 	out	PORT_B, al	; restore speaker status
  2131 00001E1B 9D                  <1> 	popf			; restore interrupt flag state
  2132                              <1> u12:	
  2133 00001E1C C3                  <1> 	retn
  2134                              <1> 
  2135                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  2136                              <1> 
  2137                              <1> WAITF:
  2138                              <1> waitf:
  2139                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2140                              <1> 	; 03/12/2013
  2141                              <1> 	;
  2142                              <1> ;	push ax			; save work register (ah)	
  2143                              <1> ;waitf1:
  2144                              <1> 				; use timer 1 output bits
  2145                              <1> ;	in	al, PORT_B	; read current counter output status
  2146                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  2147                              <1> ;	cmp	al, ah		; did it just change
  2148                              <1> ;	je	short waitf1	; wait for a change in output line
  2149                              <1> ;	;
  2150                              <1> ;	mov	ah, al		; save new lflag state
  2151                              <1> ;	loop	waitf1		; decrement half cycles till count end		
  2152                              <1> ;	;
  2153                              <1> ;	pop	ax		; restore (ah)
  2154                              <1> ;	retn			; return (cx)=0
  2155                              <1> 
  2156                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  2157                              <1> ; 17/12/2014 (dsectrm2.s)
  2158                              <1> ; WAITF
  2159                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  2160                              <1> ;
  2161                              <1> ;---WAITF-----------------------------------------------------------------------
  2162                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  2163                              <1> ; ENTRY:
  2164                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  2165                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  2166                              <1> ; EXIT:
  2167                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  2168                              <1> ;	(CX) = 0	
  2169                              <1> ;-------------------------------------------------------------------------------
  2170                              <1> 
  2171                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  2172                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  2173                              <1> 
  2174                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  2175 00001E1D 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER (AH)
  2176                              <1> 	; 16/12/2014
  2177                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  2178 00001E1F D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  2179                              <1> ;17/12/2014	
  2180                              <1> ;WAITF1:
  2181                              <1> ;	IN	AL, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  2182                              <1> ;	AND	AL, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  2183                              <1> ;	CMP	AL, AH			; DID IT JUST CHANGE
  2184                              <1> ;	JE	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  2185                              <1> ;	MOV	AH, AL			; SAVE NEW FLAG STATE
  2186                              <1> ;	LOOP	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  2187                              <1> 	;
  2188                              <1> 	; 17/12/2014
  2189                              <1> 	;
  2190                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  2191                              <1> 	;
  2192                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  2193                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  2194                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  2195                              <1> WR_STATE_0:
  2196 00001E21 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  2197 00001E23 A810                <1> 	TEST	AL,010H
  2198 00001E25 74FA                <1> 	JZ	SHORT WR_STATE_0
  2199                              <1> WR_STATE_1:
  2200 00001E27 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  2201 00001E29 A810                <1> 	TEST	AL,010H
  2202 00001E2B 75FA                <1> 	JNZ	SHORT WR_STATE_1
  2203 00001E2D E2F2                <1>         LOOP    WR_STATE_0
  2204                              <1> 	;
  2205 00001E2F 6658                <1> 	POP	AX			; RESTORE (AH)
  2206 00001E31 C3                  <1> 	RETn				; (CX) = 0
  2207                              <1> 
  2208                              <1> ; 09/07/2016
  2209                              <1> ; 01/07/2016
  2210                              <1> ; 24/06/2016
  2211                              <1> ; 23/06/2016 - TRDOS 386 (TRDOS v2.0)
  2212                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  2213                              <1> ;-------------------------------------------------------------------------------
  2214                              <1> ; WRITE_STRING								       :
  2215                              <1> ;	THIS ROUTINE WRITES A STRING OF CHARACTERS TO THE CRT.		       :
  2216                              <1> ; INPUT 								       :
  2217                              <1> ;	(AL) = WRITE STRING COMMAND  0 - 3				       :
  2218                              <1> ;	(BH) = DISPLAY PAGE (ACTIVE PAGE)				       :
  2219                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE, IF (CX) = 0 THEN RETURN	       :
  2220                              <1> ;	(DX) = CURSOR POSITION FOR START OF STRING WRITE		       :
  2221                              <1> ;	(BL) = ATTRIBUTE OF CHARACTER TO WRITE IF (AL) = 0  OR	(AL) = 1       :
  2222                              <1> ;	(eBP) = SOURCE STRING OFFSET					       :
  2223                              <1> ; OUTPUT								       :
  2224                              <1> ;	NONE								       :
  2225                              <1> ;-------------------------------------------------------------------------------
  2226                              <1> 
  2227                              <1> ; AL = 00h: Assign all characters the attribute in BL; do not update cursor
  2228                              <1> ; AL = 01h: Assign all characters the attribute in BL; update cursor
  2229                              <1> ; AL = 02h: Use attributes in string; do not update cursor
  2230                              <1> ; AL = 03h: Use attributes in string; update cursor
  2231                              <1> 
  2232                              <1> WRITE_STRING:
  2233                              <1> 	; 12/09/2016
  2234                              <1> 	; 09/07/2016
  2235                              <1> 	;cmp	byte [CRT_MODE], 7 ; 6?!
  2236                              <1> 	;ja	VIDEO_RETURN		; not a valid function for VGA modes
  2237                              <1> 	;
  2238 00001E32 A2[34650100]        <1> 	mov	[w_str_cmd], al		; save (AL) command
  2239 00001E37 3C04                <1> 	CMP	AL, 4			; TEST FOR INVALID WRITE STRING OPTION
  2240 00001E39 0F8345F7FFFF        <1> 	JNB	VIDEO_RETURN		; IF OPTION INVALID THEN RETURN
  2241                              <1> 
  2242                              <1>         ;JCXZ   VIDEO_RETURN            ; IF ZERO LENGTH STRING THEN RETURN
  2243                              <1> 
  2244 00001E3F 67E35E              <1>         jcxz    P55			; 01/07/2016
  2245                              <1> 
  2246                              <1> 
  2247                              <1> 	; 01/07/2016
  2248                              <1> 	;and	ecx, 0FFFFh
  2249                              <1> 	; ECX = byte count
  2250                              <1> 	;push	ecx
  2251 00001E42 89EE                <1> 	mov	esi, ebp ; user buffer
  2252 00001E44 BF00000700          <1> 	mov	edi, Cluster_Buffer  ; system buffer
  2253 00001E49 E8D0C90000          <1> 	call	transfer_from_user_buffer
  2254                              <1> 	;pop	ecx
  2255 00001E4E 0F8230F7FFFF        <1> 	jc	VIDEO_RETURN
  2256                              <1> 	; ecx = transfer (byte) count = character count
  2257 00001E54 BD00000700          <1> 	mov	ebp, Cluster_Buffer
  2258                              <1> 	; 12/09/2016
  2259 00001E59 803D[F25E0000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6?!
  2260 00001E60 0F879F000000        <1> 	ja	vga_write_string
  2261                              <1> 	;
  2262 00001E66 0FB6F7              <1> 	movzx	esi, bh			; GET CURRENT CURSOR PAGE
  2263 00001E69 66D1E6              <1> 	SAL	SI,1			; CONVERT TO PAGE OFFSET  (SI= PAGE)
  2264                              <1> 	; *****
  2265 00001E6C 66FFB6[C6580100]    <1> 	PUSH	word [eSI+CURSOR_POSN]	; SAVE CURRENT CURSOR POSITION IN STACK
  2266                              <1> 
  2267                              <1> 	;MOV	AX,0200H		; SET NEW CURSOR POSITION
  2268                              <1> 	;INT	10H
  2269                              <1> P50next:	
  2270 00001E73 53                  <1> 	push	ebx ; ****
  2271 00001E74 51                  <1> 	push	ecx ; ***
  2272 00001E75 56                  <1> 	push	esi ; **
  2273 00001E76 52                  <1> 	push	edx ; *
  2274 00001E77 E8FCFEFFFF          <1> 	call	_set_cpos
  2275                              <1> P50:
  2276 00001E7C 8A4500              <1> 	MOV	AL, [eBP]		; GET CHARACTER FROM INPUT STRING
  2277 00001E7F 45                  <1> 	INC	eBP			; BUMP POINTER TO CHARACTER
  2278                              <1> 
  2279                              <1> ;-----	TEST FOR SPECIAL CHARACTER'S
  2280                              <1> 
  2281 00001E80 3C08                <1> 	CMP	AL, 08H			; IS IT A BACKSPACE
  2282 00001E82 740C                <1> 	JE	short P51		; BACK_SPACE
  2283 00001E84 3C0D                <1> 	CMP	AL, 0Dh ; CR		; IS IT CARRIAGE RETURN
  2284 00001E86 7408                <1> 	JE	short P51		; CAR_RET
  2285 00001E88 3C0A                <1> 	CMP	AL, 0Ah ; LF		; IS IT A LINE FEED
  2286 00001E8A 7404                <1> 	JE	short P51		; LINE_FEED
  2287 00001E8C 3C07                <1> 	CMP	AL, 07h			; IS IT A BELL
  2288 00001E8E 7515                <1> 	JNE	short P52		; IF NOT THEN DO WRITE CHARACTER
  2289                              <1> P51:
  2290                              <1> 	;MOV	AH,0EH			; TTY_CHARACTER_WRITE
  2291                              <1> 	;INT	10H			; WRITE TTY CHARACTER TO THE CRT
  2292                              <1> 	
  2293 00001E90 E860FEFFFF          <1> 	call	_write_tty_m3
  2294                              <1> 
  2295 00001E95 5A                  <1> 	pop	edx ; *
  2296 00001E96 5E                  <1> 	pop	esi ; **
  2297                              <1> 
  2298 00001E97 668B96[C6580100]    <1> 	MOV	DX, [eSI+CURSOR_POSN]	; GET CURRENT CURSOR POSITION
  2299 00001E9E EB46                <1> 	JMP	SHORT P54		; SET CURSOR POSITION AND CONTINUE
  2300                              <1> P55:
  2301 00001EA0 E9DFF6FFFF          <1> 	JMP	VIDEO_RETURN
  2302                              <1> P52:
  2303 00001EA5 66B90100            <1> 	MOV	CX, 1			; SET CHARACTER WRITE AMOUNT TO ONE
  2304 00001EA9 803D[34650100]02    <1> 	CMP	byte [w_str_cmd], 2	; IS THE ATTRIBUTE IN THE STRING
  2305 00001EB0 7204                <1> 	JB	short P53		; IF NOT THEN SKIP
  2306 00001EB2 8A5D00              <1> 	MOV	BL, [eBP]		; ELSE GET NEW ATTRIBUTE
  2307 00001EB5 45                  <1> 	INC	eBP			; BUMP STRING POINTER
  2308                              <1> P53:
  2309                              <1> 	;MOV	AH,09H			; GOT_CHARACTER
  2310                              <1> 	;INT	10H			; WRITE CHARACTER TO THE CRT
  2311                              <1> 
  2312 00001EB6 E8AEFDFFFF          <1> 	call	_write_c_current
  2313                              <1> 	
  2314 00001EBB 5A                  <1> 	pop	edx ; *	
  2315                              <1> 	
  2316 00001EBC 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  2317 00001EBF 889E[FB5E0000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  2318                              <1> 
  2319 00001EC5 FEC2                <1> 	INC	DL			; INCREMENT COLUMN COUNTER
  2320 00001EC7 3A15[F45E0000]      <1> 	CMP	DL, [CRT_COLS]		; IF COLS ARE WITHIN RANGE FOR THIS MODE
  2321 00001ECD 7217                <1> 	JB	short P54		;    THEN GO TO COLUMNS SET
  2322 00001ECF FEC6                <1> 	INC	DH			; BUMP ROW COUNTER BY ONE
  2323 00001ED1 28D2                <1> 	SUB	DL, DL			; SET COLUMN COUNTER TO ZERO
  2324 00001ED3 80FE19              <1> 	CMP	DH, 25			; IF ROWS ARE LESS THAN 25 THEN
  2325 00001ED6 720E                <1> 	JB	short P54		; GO TO ROWS_COLUMNS_SET
  2326                              <1> 
  2327 00001ED8 66B80A0E            <1> 	MOV	AX,0E0AH		; ELSE SCROLL SCREEN
  2328                              <1> 	;INT	10H			; RESET ROW COUNTER TO 24
  2329                              <1> 
  2330 00001EDC E814FEFFFF          <1> 	call	_write_tty_m3
  2331                              <1> 	
  2332 00001EE1 66BA0018            <1> 	mov	dx, 1800h		; Column = 0, Row = 24
  2333 00001EE5 5E                  <1> 	pop	esi ; **
  2334                              <1> P54:
  2335                              <1> 					; ROW_COLUMNS_SET
  2336                              <1> 	;MOV	AX,0200H		; SET NEW CURSOR POSITION COMMAND
  2337                              <1> 	;INT	10H			; ESTABLISH NEW CURSOR POSITION
  2338                              <1> 
  2339 00001EE6 59                  <1> 	pop	ecx ; ***
  2340 00001EE7 5B                  <1> 	pop	ebx ; ****
  2341                              <1> 
  2342                              <1> 	;LOOP	P50			; DO IT ONCE MORE UNTIL (CX) = ZERO
  2343 00001EE8 6649                <1> 	dec	cx
  2344 00001EEA 7587                <1> 	jnz	short P50next
  2345                              <1> 
  2346 00001EEC 665A                <1> 	POP	DX  ; *****		; RESTORE OLD CURSOR COORDINATES
  2347                              <1> 	
  2348 00001EEE F605[34650100]01    <1> 	test	byte [w_str_cmd], 1	; IF CURSOR WAS NOT TO BE MOVED
  2349 00001EF5 0F8589F6FFFF        <1> 	JNZ	VIDEO_RETURN		; THEN EXIT WITHOUT RESETTING OLD VALUE
  2350                              <1> 	
  2351                              <1> 	;MOV	AX,0200H		; ELSE RESTORE OLD CURSOR POSITION
  2352                              <1> 	;INT	10H
  2353                              <1> 					; DONE - EXIT WRITE STRING
  2354 00001EFB E878FEFFFF          <1> 	call	_set_cpos
  2355 00001F00 E97FF6FFFF          <1> 	JMP	VIDEO_RETURN		; RETURN TO CALLER
  2356                              <1> 
  2357                              <1> vga_write_string:
  2358                              <1> 	; 12/09/2016 - TRDOS 386 (TRDOS v2.0)
  2359                              <1> 	;
  2360                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2361                              <1> 	; vgabios-0.7a (2011)
  2362                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2363                              <1> 	; 'vgabios.c', ' biosfn_write_string'
  2364                              <1> 
  2365                              <1> 	; INPUT 								  :
  2366                              <1> 	;	(AL) = WRITE STRING COMMAND  0 - 3				  :
  2367                              <1> 	;	(BH) = DISPLAY PAGE (ACTIVE PAGE)				  :
  2368                              <1> 	;	(CX) = COUNT OF CHARACTERS TO WRITE, IF (CX) = 0 THEN RETURN	  :
  2369                              <1> 	;	(DX) = CURSOR POSITION FOR START OF STRING WRITE		  :
  2370                              <1> 	;	(BL) = ATTRIBUTE OF CHARACTER TO WRITE IF (AL) = 0  OR	(AL) = 1  :
  2371                              <1> 	;	(eBP) = SOURCE STRING OFFSET					  :
  2372                              <1> 	; OUTPUT								  :
  2373                              <1> 	;	NONE								  :
  2374                              <1> 	;-------------------------------------------------------------------------;
  2375                              <1> 
  2376                              <1> 	; AL = 00h: Assign all characters the attribute in BL; do not update cursor
  2377                              <1> 	; AL = 01h: Assign all characters the attribute in BL; update cursor
  2378                              <1> 	; AL = 02h: Use attributes in string; do not update cursor
  2379                              <1> 	; AL = 03h: Use attributes in string; update cursor
  2380                              <1> 	
  2381                              <1> 	; biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX,GET_DH(),GET_DL(),ES,BP);
  2382                              <1> 	; static void biosfn_write_string (flag,page,attr,count,row,col,seg,offset) 
  2383                              <1> 
  2384                              <1> 	; // Read curs info for the page
  2385                              <1>  	; biosfn_get_cursor_pos(page,&dummy,&oldcurs);
  2386                              <1> 	; bh = video page = 0
  2387                              <1> 	;movzx	esi, word [CURSOR_POSN] ; current cursor position for video page 0
  2388                              <1> 	
  2389                              <1> 	; // if row=0xff special case : use current cursor position
  2390                              <1> 	; if(row==0xff)
  2391                              <1> 	;  {col=oldcurs&0x00ff;
  2392                              <1> 	;   row=(oldcurs&0xff00)>>8;
  2393                              <1> 	;  }
  2394                              <1> 
  2395                              <1> 	;mov	al, [w_str_cmd]
  2396                              <1> 
  2397 00001F05 80FEFF              <1> 	cmp	dh, 0FFh
  2398 00001F08 7407                <1> 	je	short vga_wstr_1 ; user current cursor position
  2399                              <1> vga_wstr_0:
  2400                              <1> 	; set cursor position
  2401 00001F0A 668915[C6580100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  2402                              <1> vga_wstr_1:
  2403 00001F11 66FF35[C6580100]    <1> 	push	word [CURSOR_POSN] ; *
  2404                              <1> 
  2405                              <1> 	; ebp = string offset in system buffer (user buffer was copied to)	
  2406                              <1> 	
  2407                              <1> 	; while(count--!=0)
  2408                              <1> 	;  {
  2409                              <1> 	;   car=read_byte(seg,offset++);
  2410                              <1> 	;   if((flag&0x02)!=0)
  2411                              <1> 	;    attr=read_byte(seg,offset++);
  2412                              <1> 	;    biosfn_write_teletype(car,page,attr,WITH_ATTR);
  2413                              <1> 	;  }
  2414                              <1> 
  2415                              <1> 	;push	eax ; **
  2416                              <1> 	;test	al, 2
  2417 00001F18 F605[34650100]02    <1> 	test	byte [w_str_cmd], 2
  2418 00001F1F 751D                <1> 	jnz	short vga_wstr_3
  2419 00001F21 881D[D7580100]      <1> 	mov	[ccolor], bl
  2420                              <1> vga_wstr_2:
  2421 00001F27 51                  <1> 	push	ecx
  2422 00001F28 8A4500              <1> 	mov	al, [ebp]
  2423 00001F2B E8CC0A0000          <1> 	call	vga_write_teletype
  2424 00001F30 59                  <1> 	pop	ecx
  2425 00001F31 6649                <1> 	dec	cx
  2426 00001F33 741E                <1> 	jz	short vga_wstr_4
  2427 00001F35 45                  <1> 	inc	ebp
  2428 00001F36 8A1D[D7580100]      <1> 	mov	bl, [ccolor]
  2429 00001F3C EBE9                <1> 	jmp	short vga_wstr_2
  2430                              <1> vga_wstr_3:
  2431 00001F3E 51                  <1> 	push	ecx
  2432 00001F3F 8A4500              <1> 	mov	al, [ebp]
  2433 00001F42 45                  <1> 	inc	ebp
  2434 00001F43 8A5D00              <1> 	mov	bl, [ebp]
  2435 00001F46 E8B10A0000          <1> 	call	vga_write_teletype
  2436 00001F4B 59                  <1> 	pop	ecx
  2437 00001F4C 6649                <1> 	dec	cx
  2438 00001F4E 7403                <1> 	jz	short vga_wstr_4
  2439 00001F50 45                  <1> 	inc	ebp
  2440 00001F51 EBEB                <1> 	jmp	short vga_wstr_3
  2441                              <1> vga_wstr_4:
  2442                              <1> 	; // Set back curs pos 
  2443                              <1> 	; if((flag&0x01)==0)
  2444                              <1> 	;  biosfn_set_cursor_pos(page,oldcurs);
  2445                              <1> 	; }
  2446                              <1> 	;pop	eax ; **
  2447 00001F53 665A                <1> 	pop	dx ; word [CURSOR_POSN] ; *
  2448                              <1> 	;test	al, 1
  2449 00001F55 F605[34650100]01    <1> 	test	byte [w_str_cmd], 1
  2450 00001F5C 0F8522F6FFFF        <1> 	jnz	VIDEO_RETURN
  2451 00001F62 668915[C6580100]    <1> 	mov 	[CURSOR_POSN], dx
  2452 00001F69 E916F6FFFF          <1> 	JMP	VIDEO_RETURN
  2453                              <1> 
  2454                              <1> ; 07/07/2016
  2455                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  2456                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  2457                              <1> ;------------------------------------------------------
  2458                              <1> ;  SCROLL UP
  2459                              <1> ;   THIS ROUTINE SCROLLS UP THE INFORMATION ON THE CRT
  2460                              <1> ; ENTRY ---
  2461                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  2462                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  2463                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  2464                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  2465                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  2466                              <1> ;  DS = DATA SEGMENT
  2467                              <1> ;  ES = REGEN SEGMENT
  2468                              <1> ; EXIT --
  2469                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  2470                              <1> ;--------------------------------------------------------
  2471                              <1> 
  2472                              <1> 	; cl = upper left column
  2473                              <1> 	; ch = upper left row
  2474                              <1> 	; dl = lower rigth column
  2475                              <1> 	; dh = lower right row
  2476                              <1> 	;
  2477                              <1> 	; al = line count (AL=0 means blank entire fields)
  2478                              <1> 	; bl = fill value for blanked lines	
  2479                              <1> 	; bh = unused
  2480                              <1> 
  2481                              <1> GRAPHICS_UP:
  2482                              <1> 	; 07/07/2016
  2483                              <1> 	;AH = Current video mode, [CRT_MODE]
  2484 00001F6E 80FC07              <1> 	cmp	ah, 7
  2485 00001F71 7766                <1> 	ja	short vga_graphics_up
  2486                              <1> 	;je	n0
  2487                              <1> 
  2488 00001F73 88C7                <1> 	MOV	bh, al			; save line count in BH
  2489 00001F75 6689C8              <1> 	MOV	AX, CX			; GET UPPER LEFT POSITION INTO AX REG
  2490                              <1> 
  2491                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  2492                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  2493                              <1> 
  2494 00001F78 E8D9050000          <1> 	CALL	GRAPH_POSN
  2495 00001F7D 0FB7F8              <1> 	MOVzx	eDI, AX			; SAVE RESULT AS DESTINATION ADDRESS
  2496                              <1> 
  2497                              <1> ;-----	DETERMINE SIZE OF WINDOW
  2498                              <1> 
  2499 00001F80 6629CA              <1> 	SUB	DX, CX
  2500 00001F83 6681C20101          <1>         ADD     DX, 101h                ; ADJUST VALUES
  2501 00001F88 C0E602              <1> 	SAL	DH, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  2502                              <1> 					; AND EVEN/ODD ROWS
  2503                              <1> ;-----	DETERMINE CRT MODE
  2504                              <1> 
  2505 00001F8B 803D[F25E0000]06    <1> 	CMP	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  2506 00001F92 7305                <1>         JNC     short _R7_              ; FIND_SOURCE
  2507                              <1> 
  2508                              <1> ;-----	MEDIUM RES UP
  2509 00001F94 D0E2                <1> 	SAL	DL, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  2510 00001F96 66D1E7              <1> 	SAL	DI, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  2511                              <1> 
  2512                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  2513                              <1> _R7_:                                   ; FIND_SOURCE
  2514 00001F99 81C700800B00        <1> 	add	edi, 0B8000h
  2515 00001F9F C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  2516 00001FA2 7431                <1>         JZ      short _R11              ; IF ZERO, THEN BLANK ENTIRE FIELD
  2517 00001FA4 B050                <1> 	MOV	AL, 80			; 80 BYTES/ROW
  2518 00001FA6 F6E7                <1> 	mul	bh			; determine offset to source
  2519 00001FA8 0FB7F0              <1> 	movzx	esi, ax			; offset to source
  2520 00001FAB 01FE                <1> 	add	eSI, eDI		; SET UP SOURCE
  2521 00001FAD 88F4                <1> 	MOV	AH, DH			; NUMBER OF ROWS IN FIELD
  2522 00001FAF 28FC                <1> 	sub	ah, bh			; determine number to move
  2523                              <1> 
  2524                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  2525                              <1> _R8:                                    ; ROW_LOOP
  2526 00001FB1 E812040000          <1>         CALL    _R17                    ; MOVE ONE ROW
  2527 00001FB6 6681EEB01F          <1> 	SUB	SI, 2000h-80		; MOVE TO NEXT ROW
  2528 00001FBB 6681EFB01F          <1> 	SUB	DI, 2000h-80
  2529 00001FC0 FECC                <1> 	DEC	AH			; NUMBER OF ROWS TO MOVE
  2530 00001FC2 75ED                <1>         JNZ     short _R8               ; CONTINUE TILL ALL MOVED
  2531                              <1> 
  2532                              <1> ;-----	FILL IN THE VACATED LINE(S)
  2533                              <1> _R9:                                    ; CLEAR ENTRY
  2534 00001FC4 88D8                <1> 	mov	al, bl			; attribute to fill with
  2535                              <1> _R10_:
  2536 00001FC6 E819040000          <1>         CALL    _R18                    ; CLEAR THAT ROW
  2537 00001FCB 6681EFB01F          <1> 	SUB	DI, 2000h-80		; POINT TO NEXT LINE
  2538 00001FD0 FECF                <1> 	dec	bh			; number of lines to fill
  2539 00001FD2 75F2                <1>         JNZ     short _R10_             ; CLEAR LOOP
  2540 00001FD4 C3                  <1> 	retn				; EVERYYHING DONE
  2541                              <1> 
  2542                              <1> _R11:                                   ; BLANK_FIELD
  2543 00001FD5 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  2544 00001FD7 EBEB                <1>         JMP     short _R9               ; CLEAR THE FIELD
  2545                              <1> 
  2546                              <1> vga_graphics_up:
  2547                              <1> 	; 08/08/2016
  2548                              <1> 	; 07/08/2016
  2549                              <1> 	; 04/08/2016
  2550                              <1> 	; 01/08/2016
  2551                              <1> 	; 31/07/2016
  2552                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2553                              <1> 	;
  2554                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2555                              <1> 	; vgabios-0.7a (2011)
  2556                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2557                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  2558                              <1> 	;
  2559                              <1> 
  2560                              <1> 	; cl = upper left column
  2561                              <1> 	; ch = upper left row
  2562                              <1> 	; dl = lower rigth column
  2563                              <1> 	; dh = lower right row
  2564                              <1> 	;
  2565                              <1> 	; al = line count (AL=0 means blank entire fields)
  2566                              <1> 	; bl = fill value for blanked lines	
  2567                              <1> 	; bh = unused
  2568                              <1> 	;
  2569                              <1> 	; ah = [CRT_MODE], current video mode	
  2570                              <1> 
  2571 00001FD9 88C7                <1> 	mov	bh, al ; 31/07/2016
  2572 00001FDB BE[165F0000]        <1> 	mov	esi, vga_g_modes
  2573 00001FE0 89F7                <1> 	mov	edi, esi
  2574 00001FE2 83C708              <1> 	add	edi, vga_g_mode_count
  2575                              <1> vga_g_up_0:
  2576 00001FE5 AC                  <1> 	lodsb
  2577 00001FE6 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  2578 00001FE8 7405                <1> 	je	short vga_g_up_1
  2579 00001FEA 39FE                <1> 	cmp	esi, edi
  2580 00001FEC 72F7                <1> 	jb	short vga_g_up_0
  2581                              <1> 	;xor	bh, bh ; 31/07/2016)
  2582 00001FEE C3                  <1> 	retn	; nothing to do
  2583                              <1> vga_g_up_1:
  2584 00001FEF 88F8                <1> 	mov	al, bh ; 31/07/2016
  2585 00001FF1 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  2586                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  2587                              <1> 	
  2588                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  2589                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  2590                              <1>  	; if(nblines>nbrows)nblines=0;
  2591                              <1>  	; cols=clr-cul+1;
  2592                              <1> 
  2593 00001FF4 3A35[FA5E0000]      <1> 	cmp	dh, [VGA_ROWS]
  2594 00001FFA 7208                <1> 	jb	short vga_g_up_2
  2595 00001FFC 8A35[FA5E0000]      <1> 	mov	dh, [VGA_ROWS]
  2596 00002002 FECE                <1> 	dec	dh
  2597                              <1> vga_g_up_2:
  2598 00002004 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  2599 0000200A 7208                <1> 	jb	short vga_g_up_3
  2600 0000200C 8A15[F45E0000]      <1> 	mov	dl, [CRT_COLS]
  2601 00002012 FECA                <1> 	dec	dl
  2602                              <1> vga_g_up_3:	
  2603 00002014 3A05[FA5E0000]      <1> 	cmp	al, [VGA_ROWS]
  2604 0000201A 7602                <1> 	jna	short vga_g_up_4
  2605 0000201C 28C0                <1> 	sub	al, al ; 0
  2606                              <1> vga_g_up_4:
  2607 0000201E 88D7                <1> 	mov	bh, dl ; clr
  2608 00002020 28CF                <1> 	sub	bh, cl ; cul
  2609 00002022 FEC7                <1> 	inc	bh ; cols = clr-cul+1
  2610                              <1> 
  2611 00002024 20C0                <1> 	and	al, al ; nblines = 0
  2612 00002026 755D                <1> 	jnz	short vga_g_up_6
  2613 00002028 20ED                <1> 	and	ch, ch ; rul = 0
  2614 0000202A 7559                <1> 	jnz	short vga_g_up_6
  2615 0000202C 20C9                <1> 	and	cl, cl ; cul = 0
  2616 0000202E 7555                <1> 	jnz	short vga_g_up_6
  2617                              <1> 
  2618 00002030 6650                <1> 	push	ax
  2619 00002032 A0[FA5E0000]        <1> 	mov	al, [VGA_ROWS]
  2620 00002037 FEC8                <1> 	dec	al  
  2621 00002039 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  2622 0000203B 7546                <1> 	jne	short vga_g_up_5
  2623 0000203D A0[F45E0000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  2624 00002042 FEC8                <1> 	dec	al 
  2625 00002044 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  2626 00002046 753B                <1> 	jne	short vga_g_up_5
  2627 00002048 6658                <1> 	pop	ax
  2628                              <1> 
  2629 0000204A 66B80502            <1> 	mov	ax, 0205h
  2630 0000204E 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2631 00002052 66EF                <1> 	out	dx, ax
  2632 00002054 A0[FA5E0000]        <1> 	mov	al, [VGA_ROWS]
  2633 00002059 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  2634 0000205F F6E4                <1> 	mul	ah
  2635 00002061 0FB7D0              <1> 	movzx	edx, ax
  2636                              <1> 	; 08/08/2016
  2637 00002064 0FB605[F65E0000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2638 0000206B F7E2                <1> 	mul	edx
  2639                              <1> 	; eax = byte count	
  2640 0000206D 89C1                <1> 	mov	ecx, eax
  2641                              <1> 	;; 07/08/2016
  2642                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  2643                              <1> 	;mov	ecx, edx
  2644 0000206F 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  2645 00002071 BF00000A00          <1> 	mov	edi, 0A0000h
  2646 00002076 F3AA                <1> 	rep	stosb		
  2647                              <1> 	
  2648 00002078 66B80500            <1> 	mov	ax, 5
  2649 0000207C 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2650 00002080 66EF                <1> 	out	dx, ax ; 0005h	
  2651                              <1> 
  2652 00002082 C3                  <1> 	retn
  2653                              <1> 
  2654                              <1> vga_g_up_5:
  2655 00002083 6658                <1> 	pop	ax
  2656                              <1> 
  2657                              <1> vga_g_up_6:
  2658                              <1> 	; [ESI] = VGA memory model number for current video mode
  2659                              <1>         ;
  2660                              <1>         ; LINEAR8 equ 5
  2661                              <1>         ; PLANAR4 equ 4
  2662                              <1>         ; PLANAR1 equ 3
  2663                              <1> 
  2664 00002085 803E04              <1> 	cmp	byte [esi], PLANAR4
  2665 00002088 7424                <1> 	je	short vga_g_up_planar
  2666 0000208A 803E03              <1> 	cmp	byte [esi], PLANAR1
  2667 0000208D 741F                <1> 	je	short vga_g_up_planar
  2668                              <1> vga_g_up_linear8:
  2669                              <1> 	; 07/07/2016 (TEMPORARY)
  2670                              <1> 	;
  2671                              <1> 	; cl = upper left column ; cul
  2672                              <1> 	; ch = upper left row ; rul
  2673                              <1> 	; dl = lower rigth column ; clr
  2674                              <1> 	; dh = lower right row ; rlr
  2675                              <1> 
  2676                              <1> vga_g_up_l0:
  2677                              <1>  	;{for(i=rul;i<=rlr;i++)
  2678                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  2679 0000208F 08C0                <1> 	or	al, al
  2680 00002091 7414                <1> 	jz	short vga_g_up_l2
  2681 00002093 88C4                <1> 	mov	ah, al
  2682 00002095 00EC                <1> 	add	ah, ch ; i+nblines
  2683                              <1> 	;jc	short vga_g_up_l2	
  2684 00002097 38F4                <1> 	cmp	ah, dh
  2685 00002099 770C                <1> 	ja	short vga_g_up_l2
  2686                              <1> 	; else
  2687                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  2688 0000209B E8F2000000          <1> 	call	vgamem_copy_l8
  2689                              <1> vga_g_up_l1:
  2690 000020A0 FEC5                <1> 	inc	ch
  2691 000020A2 38F5                <1> 	cmp	ch, dh
  2692 000020A4 76E9                <1> 	jna	short vga_g_up_l0
  2693 000020A6 C3                  <1> 	retn
  2694                              <1> vga_g_up_l2:
  2695                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  2696 000020A7 E850010000          <1> 	call	vgamem_fill_l8
  2697 000020AC EBF2                <1> 	jmp	short vga_g_up_l1
  2698                              <1> 
  2699                              <1> vga_g_up_planar:
  2700                              <1> 	; cl = upper left column ; cul
  2701                              <1> 	; ch = upper left row ; rul
  2702                              <1> 	; dl = lower rigth column ; clr
  2703                              <1> 	; dh = lower right row ; rlr
  2704                              <1> vga_g_up_pl0:
  2705                              <1>  	;{for(i=rul;i<=rlr;i++)
  2706                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  2707 000020AE 20C0                <1> 	and	al, al
  2708 000020B0 7414                <1> 	jz	short vga_g_up_pl2	
  2709 000020B2 88C4                <1> 	mov	ah, al
  2710 000020B4 00EC                <1> 	add	ah, ch ; i+nblines
  2711                              <1> 	;jc	short vga_g_up_pl2
  2712 000020B6 38F4                <1> 	cmp	ah, dh
  2713 000020B8 770C                <1> 	ja	short vga_g_up_pl2
  2714                              <1> 	; else
  2715                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  2716 000020BA E80E000000          <1> 	call	vgamem_copy_pl4
  2717                              <1> vga_g_up_pl1:
  2718 000020BF FEC5                <1> 	inc	ch 
  2719 000020C1 38F5                <1> 	cmp	ch, dh
  2720 000020C3 76E9                <1> 	jna	short vga_g_up_pl0
  2721 000020C5 C3                  <1> 	retn
  2722                              <1> vga_g_up_pl2:
  2723                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  2724 000020C6 E870000000          <1> 	call	vgamem_fill_pl4
  2725 000020CB EBF2                <1> 	jmp	short vga_g_up_pl1
  2726                              <1> 
  2727                              <1> vgamem_copy_pl4:
  2728                              <1> 	; 08/08/2016
  2729                              <1> 	; 07/08/2016
  2730                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2731                              <1> 	;
  2732                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2733                              <1> 	; vgabios-0.7a (2011)
  2734                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2735                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  2736                              <1> 	;
  2737                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  2738                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  2739                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  2740                              <1> 
  2741                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  2742                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  2743                              <1> 
  2744 000020CD 52                  <1> 	push	edx
  2745 000020CE 50                  <1> 	push	eax
  2746                              <1> 
  2747                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  2748 000020CF 66B80501            <1> 	mov	ax, 0105h
  2749 000020D3 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2750 000020D7 66EF                <1> 	out	dx, ax
  2751                              <1> 
  2752                              <1> 	; 07/08/2016
  2753                              <1>  	;mov     ah, [esp+1]
  2754                              <1> 	;movzx	edx, ah ; ysrc
  2755 000020D9 0FB6542401          <1> 	movzx	edx, byte [esp+1]
  2756                              <1> 	; 08/08/2016
  2757 000020DE 0FB605[F65E0000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2758 000020E5 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  2759 000020EB F6E4                <1> 	mul	ah 
  2760                              <1> 	;; 07/08/2016
  2761                              <1> 	;movzx	eax, byte [CRT_COLS]
  2762                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2763 000020ED 50                  <1> 	push	eax ; cheight * nbcols
  2764 000020EE F7E2                <1> 	mul	edx ; * ysrc
  2765                              <1> 	; eax = ysrc * cheight * nbcols
  2766                              <1> 	; edx = 0
  2767 000020F0 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2768 000020F2 01D0                <1>  	add	eax, edx
  2769 000020F4 89C6                <1> 	mov	esi, eax ; src
  2770 000020F6 88EA                <1> 	mov	dl, ch ; ydest
  2771 000020F8 58                  <1> 	pop	eax ; cheight * nbcols
  2772 000020F9 F7E2                <1> 	mul	edx
  2773                              <1> 	; eax = ydest * cheight * nbcols
  2774 000020FB 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2775 000020FD 01D0                <1>  	add	eax, edx
  2776 000020FF 89C7                <1> 	mov	edi, eax ; dest
  2777                              <1> 	; esi = src
  2778                              <1> 	; edi = dest
  2779                              <1> 	; for(i=0;i<cheight;i++)
  2780                              <1>   	; {
  2781                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  2782                              <1>   	; }
  2783 00002101 51                  <1> 	push	ecx
  2784 00002102 B900000A00          <1> 	mov	ecx, 0A0000h
  2785 00002107 01CE                <1> 	add	esi, ecx
  2786 00002109 01CF                <1> 	add	edi, ecx
  2787                              <1> 	; 08/08/2016
  2788 0000210B 8A35[F65E0000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2789                              <1> 	;; 07/08/2016
  2790                              <1> 	;mov	dh, 8 ; 07/08/2016
  2791 00002111 28D2                <1> 	sub	dl, dl ; i
  2792                              <1> vgamem_copy_pl4_0:
  2793 00002113 56                  <1> 	push	esi
  2794 00002114 57                  <1> 	push	edi
  2795 00002115 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS]
  2796 0000211C F6E2                <1> 	mul	dl
  2797                              <1> 	; eax = i * nbcols
  2798 0000211E 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2799 00002120 01C6                <1> 	add	esi, eax
  2800 00002122 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2801 00002125 F3A4                <1> 	rep	movsb
  2802 00002127 5F                  <1> 	pop	edi
  2803 00002128 5E                  <1> 	pop	esi
  2804 00002129 FECE                <1> 	dec	dh
  2805 0000212B 75E6                <1> 	jnz	short vgamem_copy_pl4_0
  2806                              <1> vgamem_copy_pl4_1:
  2807 0000212D 59                  <1> 	pop	ecx
  2808                              <1> 
  2809                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2810 0000212E 66B80500            <1> 	mov	ax, 0005h
  2811 00002132 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2812 00002136 66EF                <1> 	out	dx, ax
  2813                              <1> 
  2814 00002138 58                  <1> 	pop	eax
  2815 00002139 5A                  <1> 	pop	edx
  2816                              <1> 
  2817 0000213A C3                  <1> 	retn	
  2818                              <1> 
  2819                              <1> vgamem_fill_pl4:
  2820                              <1> 	; 08/08/2016
  2821                              <1> 	; 07/08/2016
  2822                              <1> 	; 04/08/2016
  2823                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2824                              <1> 	;
  2825                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2826                              <1> 	; vgabios-0.7a (2011)
  2827                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2828                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  2829                              <1> 	;
  2830                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  2831                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  2832                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  2833                              <1> 
  2834                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  2835 0000213B 52                  <1> 	push	edx
  2836 0000213C 50                  <1> 	push	eax
  2837                              <1> 
  2838                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  2839 0000213D 66B80502            <1> 	mov	ax, 0205h
  2840 00002141 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2841 00002145 66EF                <1> 	out	dx, ax
  2842                              <1> 
  2843                              <1>       	; 08/08/2016
  2844 00002147 0FB605[F65E0000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  2845 0000214E F6E5                <1> 	mul	ch
  2846                              <1> 	;; 07/08/2016
  2847                              <1> 	;movzx	eax, ch
  2848                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2849 00002150 0FB615[F45E0000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  2850 00002157 F7E2                <1> 	mul	edx
  2851                              <1> 	; edx  = 0
  2852 00002159 88CA                <1> 	mov	dl, cl 
  2853 0000215B 01D0                <1> 	add	eax, edx
  2854 0000215D 89C7                <1> 	mov	edi, eax
  2855                              <1> 	; edi = dest
  2856                              <1> 	; for(i=0;i<cheight;i++)
  2857                              <1>   	; {
  2858                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  2859                              <1>   	; }
  2860 0000215F 81C700000A00        <1> 	add	edi, 0A0000h
  2861 00002165 51                  <1> 	push	ecx
  2862                              <1> 	; 08/08/2016
  2863 00002166 8A35[F65E0000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2864                              <1> 	;; 07/08/2016
  2865                              <1> 	;mov	dh, 8 ; 07/08/2016
  2866 0000216C 28D2                <1> 	sub	dl, dl ; i
  2867                              <1> vgamem_fill_pl4_0:
  2868 0000216E 57                  <1> 	push	edi
  2869 0000216F 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS]
  2870 00002176 F6E2                <1> 	mul	dl
  2871                              <1> 	; eax = i * nbcols
  2872 00002178 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2873 0000217A 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  2874 0000217C 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2875 0000217F F3AA                <1>  	rep	stosb
  2876 00002181 5F                  <1> 	pop	edi
  2877 00002182 75EA                <1> 	jnz	short vgamem_fill_pl4_0
  2878                              <1> vgamem_fill_pl4_1:
  2879 00002184 59                  <1> 	pop	ecx
  2880                              <1> 
  2881                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2882 00002185 66B80500            <1> 	mov	ax, 0005h
  2883 00002189 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2884 0000218D 66EF                <1> 	out	dx, ax
  2885                              <1> 
  2886 0000218F 58                  <1> 	pop	eax
  2887 00002190 5A                  <1> 	pop	edx 
  2888                              <1> 	
  2889 00002191 C3                  <1> 	retn
  2890                              <1> 
  2891                              <1> vgamem_copy_l8:
  2892                              <1> 	; 08/08/2016
  2893                              <1> 	; 07/08/2016
  2894                              <1> 	; 06/08/2016
  2895                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2896                              <1> 	;
  2897                              <1> 	; TEMPORARY
  2898                              <1> 	;
  2899                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2900                              <1> 	; vgabios-0.7a (2011)
  2901                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2902                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  2903                              <1> 	;
  2904                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  2905                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  2906                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  2907                              <1> 
  2908                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  2909                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  2910                              <1> 
  2911 00002192 52                  <1> 	push	edx
  2912 00002193 50                  <1> 	push	eax
  2913                              <1> 
  2914                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  2915                              <1> 	;mov	ax, 0105h
  2916                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2917                              <1> 	;out	dx, ax
  2918                              <1> 
  2919                              <1> 	;mov	ah, [esp+1]
  2920                              <1> 
  2921 00002194 0FB6D4              <1> 	movzx	edx, ah ; ysrc
  2922                              <1> 	; 08/08/2016
  2923 00002197 0FB605[F65E0000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  2924 0000219E 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  2925 000021A4 F6E4                <1> 	mul	ah 
  2926                              <1> 	;; 07/08/2016
  2927                              <1> 	;movzx	eax, byte [CRT_COLS]
  2928                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  2929 000021A6 50                  <1> 	push	eax ; cheight * nbcols
  2930 000021A7 F7E2                <1> 	mul	edx ; * ysrc
  2931                              <1> 	; eax = ysrc * cheight * nbcols
  2932                              <1> 	; edx = 0
  2933 000021A9 88CA                <1> 	mov	dl, cl ; edx = xstart
  2934 000021AB 01D0                <1>  	add	eax, edx
  2935 000021AD 89C6                <1> 	mov	esi, eax ; src
  2936 000021AF 66C1E603            <1> 	shl	si, 3 ; * 8 ; 06/08/2016
  2937 000021B3 88EA                <1> 	mov	dl, ch ; ydest
  2938 000021B5 58                  <1> 	pop	eax ; cheight * nbcols
  2939 000021B6 F7E2                <1> 	mul	edx
  2940                              <1> 	; eax = ydest * cheight * nbcols
  2941 000021B8 88CA                <1> 	mov	dl, cl ; edx = xstart	
  2942 000021BA 01D0                <1>  	add	eax, edx
  2943 000021BC 89C7                <1> 	mov	edi, eax ; dest
  2944 000021BE 66C1E703            <1> 	shl	di, 3 ; * 8 ; 06/08/2016
  2945                              <1> 	; esi = src
  2946                              <1> 	; edi = dest
  2947                              <1> 	; for(i=0;i<cheight;i++)
  2948                              <1>   	; {
  2949                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  2950                              <1>   	; }
  2951 000021C2 51                  <1> 	push	ecx
  2952 000021C3 B900000A00          <1> 	mov	ecx, 0A0000h
  2953 000021C8 01CE                <1> 	add	esi, ecx
  2954 000021CA 01CF                <1> 	add	edi, ecx
  2955                              <1> 	; 08/08/2016
  2956 000021CC 8A35[F65E0000]      <1> 	mov	dh, [CHAR_HEIGHT]
  2957                              <1> 	;; 07/08/2016
  2958                              <1> 	;mov	dh, 8 ; 07/08/2016
  2959 000021D2 28D2                <1> 	sub	dl, dl ; i
  2960                              <1> vgamem_copy_l8_0:
  2961 000021D4 56                  <1> 	push	esi
  2962 000021D5 57                  <1> 	push	edi
  2963 000021D6 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS]
  2964 000021DD F6E2                <1> 	mul	dl
  2965                              <1> 	; eax = i * nbcols
  2966 000021DF 66C1E003            <1> 	shl	ax, 3 ; * 8 ; 06/08/2016
  2967 000021E3 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  2968 000021E5 01C6                <1> 	add	esi, eax
  2969 000021E7 0FB6CF              <1> 	movzx	ecx, bh ; cols
  2970 000021EA 66C1E103            <1> 	shl	cx, 3 ; * 8 ; 06/08/2016
  2971 000021EE F3A4                <1> 	rep	movsb
  2972 000021F0 5F                  <1> 	pop	edi
  2973 000021F1 5E                  <1> 	pop	esi
  2974 000021F2 FEC2                <1> 	inc	dl ; 06/08/2016
  2975 000021F4 FECE                <1> 	dec	dh
  2976 000021F6 75DC                <1> 	jnz	short vgamem_copy_l8_0
  2977                              <1> vgamem_copy_l8_1:
  2978 000021F8 59                  <1> 	pop	ecx
  2979                              <1> 
  2980                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  2981                              <1> 	;mov	ax, 0005h
  2982                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  2983                              <1> 	;out	dx, ax
  2984                              <1> 
  2985 000021F9 58                  <1> 	pop	eax
  2986 000021FA 5A                  <1> 	pop	edx
  2987                              <1> 
  2988 000021FB C3                  <1> 	retn
  2989                              <1> 
  2990                              <1> vgamem_fill_l8:
  2991                              <1> 	; 08/08/2016
  2992                              <1> 	; 07/08/2016
  2993                              <1> 	; 06/08/2016
  2994                              <1> 	; 04/08/2016
  2995                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  2996                              <1> 	;
  2997                              <1> 	; TEMPORARY
  2998                              <1> 	;
  2999                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3000                              <1> 	; vgabios-0.7a (2011)
  3001                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3002                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  3003                              <1> 	;
  3004                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  3005                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  3006                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  3007                              <1> 
  3008                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  3009 000021FC 52                  <1> 	push	edx
  3010 000021FD 50                  <1> 	push	eax
  3011                              <1> 
  3012                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  3013                              <1> 	;mov	ax, 0205h
  3014                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  3015                              <1> 	;out	dx, ax
  3016                              <1> 
  3017                              <1>         ; 08/08/2016
  3018 000021FE 0FB605[F65E0000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  3019 00002205 F6E5                <1> 	mul	ch
  3020                              <1> 	;; 07/08/2016
  3021                              <1> 	;movzx	eax, ch
  3022                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  3023 00002207 0FB615[F45E0000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  3024 0000220E F7E2                <1> 	mul	edx
  3025                              <1> 	; edx  = 0
  3026 00002210 88CA                <1> 	mov	dl, cl 
  3027 00002212 01D0                <1> 	add	eax, edx
  3028 00002214 89C7                <1> 	mov	edi, eax
  3029 00002216 66C1E703            <1> 	shl	di, 3 ; * 8 ; 06/08/2016
  3030                              <1> 	; edi = dest
  3031                              <1> 	; for(i=0;i<cheight;i++)
  3032                              <1>   	; {
  3033                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  3034                              <1>   	; }
  3035 0000221A 81C700000A00        <1> 	add	edi, 0A0000h
  3036 00002220 51                  <1> 	push	ecx
  3037                              <1> 	; 08/08/2016
  3038 00002221 8A35[F65E0000]      <1> 	mov	dh, [CHAR_HEIGHT]
  3039                              <1> 	;; 07/08/2016
  3040                              <1> 	;mov	dh, 8 ; 07/08/2016
  3041 00002227 28D2                <1> 	sub	dl, dl ; i
  3042                              <1> vgamem_fill_l8_0:
  3043 00002229 57                  <1> 	push	edi
  3044 0000222A 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS]
  3045 00002231 F6E2                <1> 	mul	dl
  3046                              <1> 	; eax = i * nbcols
  3047 00002233 66C1E003            <1> 	shl	ax, 3 ; * 8 ; 06/08/2016
  3048 00002237 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  3049 00002239 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  3050 0000223B 0FB6CF              <1> 	movzx	ecx, bh ; cols
  3051 0000223E 66C1E103            <1> 	shl	cx, 3 ; * 8 ; 06/08/2016
  3052 00002242 F3AA                <1>  	rep	stosb
  3053 00002244 5F                  <1> 	pop	edi
  3054 00002245 FEC2                <1> 	inc	dl ; 06/08/2016
  3055 00002247 FECE                <1> 	dec	dh
  3056 00002249 75DE                <1> 	jnz	short vgamem_fill_l8_0
  3057                              <1> vgamem_fill_l8_1:
  3058 0000224B 59                  <1> 	pop	ecx
  3059                              <1> 
  3060                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  3061                              <1> 	;mov	ax, 0005h
  3062                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  3063                              <1> 	;out	dx, ax
  3064                              <1> 
  3065 0000224C 58                  <1> 	pop	eax
  3066 0000224D 5A                  <1> 	pop	edx 
  3067                              <1> 
  3068 0000224E C3                  <1> 	retn
  3069                              <1> 
  3070                              <1> vga_graphics_down:
  3071                              <1> 	; 08/08/2016
  3072                              <1> 	; 07/08/2016
  3073                              <1> 	; 31/07/2016
  3074                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  3075                              <1> 	;
  3076                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3077                              <1> 	; vgabios-0.7a (2011)
  3078                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3079                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  3080                              <1> 	;
  3081                              <1> 
  3082                              <1> 	; cl = upper left column
  3083                              <1> 	; ch = upper left row
  3084                              <1> 	; dl = lower rigth column
  3085                              <1> 	; dh = lower right row
  3086                              <1> 	;
  3087                              <1> 	; al = line count (AL=0 means blank entire fields)
  3088                              <1> 	; bl = fill value for blanked lines	
  3089                              <1> 	; bh = unused
  3090                              <1> 	;
  3091                              <1> 	; ah = [CRT_MODE], current video mode	
  3092                              <1> 
  3093 0000224F FC                  <1>         cld     ; !!! Clear direction flag !!! 
  3094                              <1> 
  3095 00002250 88C7                <1> 	mov	bh, al ; 31/07/2016
  3096                              <1> 
  3097 00002252 BE[0E5F0000]        <1> 	mov	esi, vga_modes
  3098 00002257 89F7                <1> 	mov	edi, esi
  3099 00002259 83C710              <1> 	add	edi, vga_mode_count
  3100                              <1> vga_g_down_0:
  3101 0000225C AC                  <1> 	lodsb
  3102 0000225D 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  3103 0000225F 7405                <1> 	je	short vga_g_down_1
  3104 00002261 39FE                <1> 	cmp	esi, edi
  3105 00002263 72F7                <1> 	jb	short vga_g_down_0
  3106                              <1> 	; xor 	bh, bh	; 31/07/2016
  3107 00002265 C3                  <1> 	retn	; nothing to do
  3108                              <1> vga_g_down_1:
  3109 00002266 88F8                <1> 	mov	al, bh ; 31/07/2016
  3110 00002268 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  3111                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  3112                              <1> 	
  3113                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  3114                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  3115                              <1>  	; if(nblines>nbrows)nblines=0;
  3116                              <1>  	; cols=clr-cul+1;
  3117                              <1> 
  3118 0000226B 3A35[FA5E0000]      <1> 	cmp	dh, [VGA_ROWS]
  3119 00002271 7208                <1> 	jb	short vga_g_down_2
  3120 00002273 8A35[FA5E0000]      <1> 	mov	dh, [VGA_ROWS]
  3121 00002279 FECE                <1> 	dec	dh
  3122                              <1> vga_g_down_2:
  3123 0000227B 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  3124 00002281 7208                <1> 	jb	short vga_g_down_3
  3125 00002283 8A15[F45E0000]      <1> 	mov	dl, [CRT_COLS]
  3126 00002289 FECA                <1> 	dec	dl
  3127                              <1> vga_g_down_3:	
  3128 0000228B 3A05[FA5E0000]      <1> 	cmp	al, [VGA_ROWS]
  3129 00002291 7602                <1> 	jna	short vga_g_down_4
  3130 00002293 28C0                <1> 	sub	al, al ; 0
  3131                              <1> vga_g_down_4:
  3132 00002295 88F7                <1> 	mov	bh, dh ; clr
  3133 00002297 28CF                <1> 	sub	bh, cl ; cul
  3134 00002299 FEC7                <1> 	inc	bh ; cols = clr-cul+1
  3135                              <1> 
  3136 0000229B 20C0                <1> 	and	al, al ; nblines = 0
  3137 0000229D 755B                <1> 	jnz	short vga_g_down_6
  3138 0000229F 20ED                <1> 	and	ch, ch ; rul = 0
  3139 000022A1 7557                <1> 	jnz	short vga_g_down_6
  3140 000022A3 20C9                <1> 	and	cl, cl ; cul = 0
  3141 000022A5 7553                <1> 	jnz	short vga_g_down_6
  3142                              <1> 
  3143 000022A7 6650                <1> 	push	ax
  3144 000022A9 A0[FA5E0000]        <1> 	mov	al, [VGA_ROWS]
  3145 000022AE FEC8                <1> 	dec	al  
  3146 000022B0 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  3147 000022B2 7544                <1> 	jne	short vga_g_down_5
  3148 000022B4 A0[F45E0000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  3149 000022B9 FEC8                <1> 	dec	al 
  3150 000022BB 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  3151 000022BD 7539                <1> 	jne	short vga_g_down_5
  3152 000022BF 6658                <1> 	pop	ax
  3153                              <1> 
  3154 000022C1 66B80502            <1> 	mov	ax, 0205h
  3155 000022C5 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  3156 000022C9 66EF                <1> 	out	dx, ax
  3157 000022CB A0[FA5E0000]        <1> 	mov	al, [VGA_ROWS]
  3158 000022D0 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  3159 000022D6 F6E4                <1> 	mul	ah
  3160 000022D8 0FB7D0              <1> 	movzx	edx, ax
  3161                              <1> 	; 08/08/2016
  3162 000022DB 0FB605[F65E0000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  3163 000022E2 F7E2                <1> 	mul	edx
  3164                              <1> 	; eax = byte count	
  3165 000022E4 89C1                <1> 	mov	ecx, eax
  3166                              <1> 	;; 07/08/2016
  3167                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  3168                              <1> 	;mov	ecx, edx
  3169 000022E6 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  3170 000022E8 BF00000A00          <1> 	mov	edi, 0A0000h
  3171 000022ED F3AA                <1> 	rep	stosb			
  3172                              <1> 	
  3173 000022EF B005                <1> 	mov	al, 5
  3174 000022F1 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  3175 000022F5 66EF                <1> 	out	dx, ax ; 0005h	
  3176                              <1> 
  3177 000022F7 C3                  <1> 	retn
  3178                              <1> 
  3179                              <1> vga_g_down_5:
  3180 000022F8 6658                <1> 	pop	ax
  3181                              <1> 
  3182                              <1> vga_g_down_6:
  3183                              <1> 	; [ESI] = VGA memory model number for current video mode
  3184                              <1>         ;
  3185                              <1>         ; LINEAR8 equ 5
  3186                              <1>         ; PLANAR4 equ 4
  3187                              <1>         ; PLANAR1 equ 3
  3188                              <1> 
  3189 000022FA 803E04              <1> 	cmp	byte [esi], PLANAR4
  3190 000022FD 742C                <1> 	je	short vga_g_down_planar
  3191 000022FF 803E03              <1> 	cmp	byte [esi], PLANAR1
  3192 00002302 7427                <1> 	je	short vga_g_down_planar
  3193                              <1> vga_g_down_linear8:
  3194                              <1> 	; 07/07/2016 (TEMPORARY)
  3195                              <1> 	;
  3196                              <1> 	; cl = upper left column ; cul
  3197                              <1> 	; ch = upper left row ; rul
  3198                              <1> 	; dl = lower rigth column ; clr
  3199                              <1> 	; dh = lower right row ; rlr
  3200                              <1> 
  3201                              <1> vga_g_down_l0:
  3202                              <1> 	;{for(i=rlr;i>=rul;i--)
  3203                              <1>         ; if((i<rul+nblines)||(nblines==0))
  3204 00002304 08C0                <1> 	or	al, al
  3205 00002306 741C                <1> 	jz	short vga_g_down_l2
  3206 00002308 88C4                <1> 	mov	ah, al
  3207 0000230A 00EC                <1> 	add	ah, ch
  3208                              <1> 	;jc	short vga_g_down_l2	
  3209 0000230C 86EE                <1> 	xchg	ch, dh
  3210 0000230E 38E5                <1> 	cmp	ch, ah
  3211 00002310 7212                <1> 	jb	short vga_g_down_l2
  3212 00002312 88EC                <1> 	mov	ah, ch
  3213 00002314 28C4                <1> 	sub	ah, al ; ah = i - nblines
  3214                              <1> 	; else
  3215                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  3216 00002316 E877FEFFFF          <1> 	call	vgamem_copy_l8
  3217                              <1> vga_g_down_l1:
  3218 0000231B 86F5                <1> 	xchg	dh, ch
  3219 0000231D FECE                <1> 	dec	dh 
  3220 0000231F 38EE                <1> 	cmp	dh, ch
  3221 00002321 73E1                <1> 	jnb	short vga_g_down_l0
  3222 00002323 C3                  <1> 	retn
  3223                              <1> 
  3224                              <1> vga_g_down_l2:
  3225                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  3226 00002324 E8D3FEFFFF          <1> 	call	vgamem_fill_l8
  3227 00002329 EBF0                <1> 	jmp	short vga_g_down_l1
  3228                              <1> 		 
  3229                              <1> vga_g_down_planar:
  3230                              <1> 	; cl = upper left column ; cul
  3231                              <1> 	; ch = upper left row ; rul
  3232                              <1> 	; dl = lower rigth column ; clr
  3233                              <1> 	; dh = lower right row ; rlr
  3234                              <1> vga_g_down_pl0:
  3235                              <1>  	;{for(i=rlr;i>=rul;i--)
  3236                              <1>         ; if((i<rul+nblines)||(nblines==0))
  3237 0000232B 08C0                <1> 	or	al, al
  3238 0000232D 741C                <1> 	jz	short vga_g_down_pl2
  3239 0000232F 88C4                <1> 	mov	ah, al
  3240 00002331 00EC                <1> 	add	ah, ch
  3241                              <1> 	;jc	short vga_g_down_pl2	
  3242 00002333 86EE                <1> 	xchg	ch, dh
  3243 00002335 38E5                <1> 	cmp	ch, ah
  3244 00002337 7212                <1> 	jb	short vga_g_down_pl2
  3245 00002339 88EC                <1> 	mov	ah, ch
  3246 0000233B 28C4                <1> 	sub	ah, al ; ah = i - nblines
  3247                              <1> 	; else
  3248                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  3249 0000233D E88BFDFFFF          <1> 	call	vgamem_copy_pl4
  3250                              <1> vga_g_down_pl1:
  3251 00002342 86F5                <1> 	xchg	dh, ch
  3252 00002344 FECE                <1> 	dec	dh 
  3253 00002346 38EE                <1> 	cmp	dh, ch
  3254 00002348 73E1                <1> 	jnb	short vga_g_down_pl0
  3255 0000234A C3                  <1> 	retn
  3256                              <1> 
  3257                              <1> vga_g_down_pl2:
  3258                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  3259 0000234B E8EBFDFFFF          <1> 	call	vgamem_fill_pl4
  3260 00002350 EBF0                <1> 	jmp	short vga_g_down_pl1
  3261                              <1> 
  3262                              <1> ; 07/07/2016
  3263                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  3264                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3265                              <1> ;------------------------------------------------------
  3266                              <1> ; SCROLL DOWN
  3267                              <1> ;  THIS ROUTINE SCROLLS DOWN THE INFORMATION ON THE CRT
  3268                              <1> ; ENTRY --
  3269                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  3270                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  3271                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  3272                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  3273                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  3274                              <1> ;  DS = DATA SEGMENT
  3275                              <1> ;  ES = REGEN SEGMENT
  3276                              <1> ; EXIT --
  3277                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  3278                              <1> ;--------------------------------------------------------
  3279                              <1> 
  3280                              <1> 	; cl = upper left column
  3281                              <1> 	; ch = upper left row
  3282                              <1> 	; dl = lower rigth column
  3283                              <1> 	; dh = lower right row
  3284                              <1> 	;
  3285                              <1> 	; al = line count (AL=0 means blank entire fields)
  3286                              <1> 	; bl = fill value for blanked lines	
  3287                              <1> 	; bh = unused
  3288                              <1> 
  3289                              <1> GRAPHICS_DOWN:
  3290                              <1> 	; 07/07/2016
  3291                              <1> 	;AH = Current video mode, [CRT_MODE]
  3292                              <1> 	;STD				; SET DIRECTION
  3293 00002352 80FC07              <1> 	cmp	ah, 7
  3294 00002355 0F87F4FEFFFF        <1>         ja      vga_graphics_down
  3295                              <1> 	;je	_n0
  3296                              <1> 
  3297 0000235B 88C7                <1> 	MOV	bh, al			; save line count in BH
  3298 0000235D 6689D0              <1> 	MOV	AX, DX			; GET LOWER RIGHT POSITION INTO AX REG
  3299                              <1> 
  3300                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  3301                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  3302                              <1> 
  3303 00002360 E8F1010000          <1> 	CALL	GRAPH_POSN
  3304 00002365 0FB7F8              <1> 	MOVzx	eDI, AX			; SAVE RESULT AS DESTINATION ADDRESS
  3305                              <1> 
  3306                              <1> ;-----	DETERMINE SIZE OF WINDOW
  3307                              <1> 
  3308 00002368 6629CA              <1> 	SUB	DX, CX
  3309 0000236B 6681C20101          <1>         ADD     DX, 101h                ; ADJUST VALUES
  3310 00002370 C0E602              <1> 	SAL	DH, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  3311                              <1> 					; AND EVEN/ODD ROWS
  3312                              <1> 
  3313                              <1> ;-----	DETERMINE CRT MODE
  3314                              <1> 
  3315 00002373 803D[F25E0000]06    <1> 	CMP	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  3316 0000237A 7307                <1>         JNC     short _R12              ; FIND_SOURCE_DOWN
  3317                              <1> 
  3318                              <1> ;-----	MEDIUM RES DOWN
  3319 0000237C D0E2                <1> 	SAL	DL, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  3320 0000237E 66D1E7              <1> 	SAL	DI, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  3321 00002381 6647                <1> 	INC	DI			; POINT TO LAST BYTE
  3322                              <1> 
  3323                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  3324                              <1> 
  3325                              <1> _R12:                                   ; FIND_SOURCE_DOWN
  3326 00002383 81C700800B00        <1> 	add	edi, 0B8000h		
  3327 00002389 6681C7F000          <1> 	ADD	DI, 240			; POINT TO LAST ROW OF PIXELS
  3328 0000238E C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  3329 00002391 74(06)              <1> 	JZ	short 6			; IF ZERO, THEN BLANK ENTIRE FIELD
  3330 00002393 B050                <1> 	MOV	AL, 80			; 80 BYTES/ROW
  3331 00002395 F6E7                <1> 	mul	bh			; determine offset to source
  3332 00002397 89FE                <1> 	MOV	eSI, eDI		; SET UP SOURCE
  3333 00002399 6629C6              <1> 	SUB	SI, AX			; SUBTRACT THE OFFSET
  3334 0000239C 88F4                <1> 	MOV	AH, DH			; NUMBER OF ROWS IN FIELD
  3335 0000239E 28FC                <1> 	sub	ah, bh			; determine number to move
  3336                              <1> 
  3337                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  3338                              <1> 
  3339                              <1> _R13:                                   ; ROW_LOOP_DOWN
  3340 000023A0 E823000000          <1>         CALL    _R17                    ; MOVE ONE ROW
  3341 000023A5 6681EE5020          <1> 	SUB	SI, 2000h+80		; MOVE TO NEXT ROW
  3342 000023AA 6681EF5020          <1> 	SUB	DI, 2000h+80
  3343 000023AF FECC                <1> 	DEC	AH			; NUMBER OF ROWS TO MOVE
  3344 000023B1 75ED                <1>         JNZ     short _R13              ; CONTINUE TILL ALL MOVED
  3345                              <1> 
  3346                              <1> ;-----	FILL IN THE VACATED LINE(S)
  3347                              <1> _R14:                                   ; CLEAR_ENTRY_DOWN
  3348 000023B3 88D8                <1> 	mov	al, bl			; attribute to fill with
  3349                              <1> _R15_:                                  ; CLEAR_LOOP_DOWN
  3350 000023B5 E82A000000          <1> 	CALL	_R18			; CLEAR A ROW
  3351 000023BA 6681EF5020          <1> 	SUB	DI, 2000h+80		; POINT TO NEXT LINE
  3352 000023BF FECF                <1> 	dec	bh			; number of lines to fill
  3353 000023C1 75F2                <1>         JNZ     short _R15_             ; CLEAR_LOOP_DOWN
  3354                              <1> 
  3355 000023C3 C3                  <1> 	retn				; EVERYYHING DONE
  3356                              <1> 
  3357                              <1> _R16:                                   ; BLANK_FIELD_DOWN
  3358 000023C4 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  3359 000023C6 EBEB                <1>         JMP     short _R14              ; CLEAR THE FIELD
  3360                              <1> 
  3361                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  3362                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3363                              <1> 
  3364                              <1> ;-----	ROUTINE TO MOVE ONE ROW OF INFORMATION
  3365                              <1> 
  3366                              <1> _R17:
  3367 000023C8 0FB6CA              <1> 	MOVzx	ecx, DL			; NUMBER OF BYTES IN THE ROW
  3368 000023CB 56                  <1> 	PUSH	eSI
  3369 000023CC 57                  <1> 	PUSH	eDI			; SAVE POINTERS
  3370 000023CD F3A4                <1> 	REP	MOVSB			; MOVE THE EVEN FIELD
  3371 000023CF 5F                  <1> 	POP	eDI
  3372 000023D0 5E                  <1> 	POP	eSI
  3373 000023D1 6681C60020          <1> 	ADD	SI, 2000h
  3374 000023D6 6681C70020          <1> 	ADD	DI, 2000h		; POINT TO THE ODD FIELD
  3375 000023DB 56                  <1> 	PUSH	eSI
  3376 000023DC 57                  <1> 	PUSH	eDI			; SAVE THE POINTERS
  3377 000023DD 88D1                <1> 	MOV	CL, DL			; COUNT BACK
  3378 000023DF F3A4                <1> 	REP	MOVSB			; MOVE THE ODD FIELD
  3379 000023E1 5F                  <1> 	POP	eDI
  3380 000023E2 5E                  <1> 	POP	eSI			; POINTERS BACK
  3381 000023E3 C3                  <1> 	RETn				; RETURN TO CALLER
  3382                              <1> 
  3383                              <1> ;-----	CLEAR A SINGLE ROW
  3384                              <1> 
  3385                              <1> _R18:
  3386 000023E4 0FB6CA              <1> 	MOVzx	ecx, DL			; NUMBER OF BYTES IN FIELD
  3387 000023E7 57                  <1> 	PUSH	eDI			; SAVE POINTER
  3388 000023E8 F3AA                <1> 	REP	STOSB			; STORE THE NEW VALUE
  3389 000023EA 5F                  <1> 	POP	eDI			; POINTER BACK
  3390 000023EB 6681C70020          <1> 	ADD	DI, 2000h		; POINT TO ODD FIELD
  3391 000023F0 57                  <1> 	PUSH	eDI
  3392 000023F1 88D1                <1> 	MOV	CL, DL
  3393 000023F3 F3AA                <1> 	REP	STOSB			; FILL THE ODD FIELD
  3394 000023F5 5F                  <1> 	POP	eDI
  3395 000023F6 C3                  <1> 	RETn				; RETURN TO CALLER
  3396                              <1> 
  3397                              <1> ; 04/07/2016
  3398                              <1> ; 01/07/2016
  3399                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3400                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3401                              <1> ;--------------------------------------------------
  3402                              <1> ; GRAPHICS WRITE
  3403                              <1> ;  THIS ROUTINE WRITES THE ASCII CHARACTER TO THE CURRENT
  3404                              <1> ;  POSITION ON THE SCREEN.
  3405                              <1> ; ENTRY --
  3406                              <1> ;  AL = CHARACTER TO WRITE
  3407                              <1> ;  BL = COLOR ATTRIBUTE TO BE USED FOR FOREGROUND COLOR
  3408                              <1> ;	IF BIT 7 IS SET, THE CHAR IS XOR'D INTO THE REGEN BUFFER
  3409                              <1> ;	(0 IS USED FOR THE BACKGROUND COLOR)
  3410                              <1> ;  CX = NUMBER OF CHARS TO WRITE
  3411                              <1> ;  DS = DATA SEGMENT
  3412                              <1> ;  ES = REGEN SEGMENT
  3413                              <1> ; EXIT --
  3414                              <1> ;  NOTHING IS RETURNED
  3415                              <1> ;
  3416                              <1> ; GRAPHICS READ
  3417                              <1> ;  THIS ROUTINE READS THE ASCII CHARACTER AT THE CURRENT CURSOR
  3418                              <1> ;  POSITION ON THE SCREEN BY MATCHING THE DOTS ON THE SCREEN TO THE
  3419                              <1> ;  CHARACTER GENERATOR CODE POINTS
  3420                              <1> ; ENTRY --
  3421                              <1> ;  NONE (0 IS ASSUMED AS THE BACKGROUND COLOR)
  3422                              <1> ; EXIT --
  3423                              <1> ;  AL = CHARACTER READ AT THAT POSITION (0 RETURNED IF NONE FOUND)
  3424                              <1> ;
  3425                              <1> ; FOR BOTH ROUTINES, THE IMAGES USED TO FORM CHARS ARE CONTAINED IN ROM
  3426                              <1> ;  FOR THE 1ST 128 CHARS.  TO ACCESS CHARS IN THE SECOND HALF, THE USER
  3427                              <1> ;  MUST INITIALIZE THE VECTOR AT INTERRUPT 1FH (LOCATION 0007CH) TO
  3428                              <1> ;  POINT TO THE USER SUPPLIED TABLE OF GRAPHIC IMAGES (8X8 BOXES).
  3429                              <1> ;  FAILURE TO DO SO WILL CAUSE IN STRANGE RESULTS
  3430                              <1> ;-----------------------------------------------------
  3431                              <1> 
  3432                              <1> GRAPHICS_WRITE:
  3433 000023F7 25FF000000          <1> 	and 	eax, 0FFh		; ZERO TO HIGH OF CODE POINT
  3434 000023FC 50                  <1> 	PUSH	eAX			; SAVE CODE POINT VALUE
  3435                              <1> 
  3436                              <1> ;-----	DETERMINE POSITION IN REGEN BUFFER TO PUT CODE POINTS
  3437                              <1> 
  3438 000023FD E84D010000          <1> 	CALL	S26			; FIND LOCATION IN REGEN BUFFER
  3439 00002402 89C7                <1> 	MOV	eDI, eAX		; REGEN POINTER IN DI
  3440                              <1> 
  3441                              <1> ;-----	DETERMINE REGION TO GET CODE POINTS FROM
  3442                              <1> 
  3443 00002404 58                  <1> 	POP	eAX			; RECOVER CODE POINT
  3444                              <1> 
  3445 00002405 BE[242D0100]        <1> 	MOV	eSI, CRT_CHAR_GEN	; OFFSET OF IMAGES
  3446                              <1> 
  3447                              <1> ;-----	DETERMINE GRAPHICS MODE IN OPERATION
  3448                              <1> 					; DETERMINE_MODE
  3449 0000240A 66C1E003            <1> 	SAL	AX, 3			; MULTIPLY CODE POINT VALUE BY 8
  3450 0000240E 01C6                <1> 	ADD	eSI, eAX		; SI HAS OFFSET OF DESIRED CODES
  3451                              <1> 	
  3452 00002410 803D[F25E0000]06    <1> 	CMP	byte [CRT_MODE], 6
  3453 00002417 7231                <1> 	JC	short S6		; TEST FOR MEDIUM RESOLUTION MODE
  3454                              <1> 
  3455                              <1> ;-----	HIGH RESOLUTION MODE
  3456                              <1> 
  3457 00002419 81C700800B00        <1> 	add	edi, 0B8000h
  3458                              <1> S1:					; HIGH_CHAR
  3459 0000241F 57                  <1> 	PUSH	eDI			; SAVE REGEN POINTER
  3460 00002420 56                  <1> 	PUSH	eSI			; SAVE CODE POINTER
  3461 00002421 B604                <1> 	MOV	DH, 4			; NUMBER OF TIMES THROUGH LOOP
  3462                              <1> S2:
  3463 00002423 AC                  <1> 	LODSB				; GET BYTE FROM CODE POINTS
  3464 00002424 F6C380              <1> 	TEST	BL, 80H			; SHOULD WE USE THE FUNCTION
  3465 00002427 7515                <1> 	JNZ	short S5		; TO PUT CHAR IN
  3466 00002429 AA                  <1> 	STOSB				; STORE IN REGEN BUFFER
  3467 0000242A AC                  <1> 	LODSB
  3468                              <1> S4:
  3469 0000242B 8887FF1F0000        <1> 	MOV	[eDI+2000H-1], AL ; STORE IN SECOND HALF
  3470 00002431 83C74F              <1> 	ADD	eDI, 79			; MOVE TO NEXT ROW IN REGEN
  3471 00002434 FECE                <1> 	DEC	DH			; DONE WITH LOOP
  3472 00002436 75EB                <1> 	JNZ	short S2
  3473 00002438 5E                  <1> 	POP	eSI
  3474 00002439 5F                  <1> 	POP	eDI			; RECOVER REGEN POINTER
  3475 0000243A 47                  <1> 	INC	eDI			; POINT TO NEXT CHAR POSITION
  3476 0000243B E2E2                <1> 	LOOP	S1			; MORE CHARS TO WRITE
  3477 0000243D C3                  <1> 	retn
  3478                              <1> 
  3479                              <1> S5:
  3480 0000243E 3207                <1> 	XOR	AL, [eDI]		; EXCLUSIVE OR WITH CURRENT
  3481 00002440 AA                  <1> 	STOSB				; STORE THE CODE POINT
  3482 00002441 AC                  <1> 	LODSB				; AGAIN FOR ODD FIELD
  3483 00002442 3287FF1F0000        <1> 	XOR	AL, [eDI+2000H-1]
  3484 00002448 EBE1                <1> 	JMP	short S4		; BACK TO MAINSTREAM
  3485                              <1> 
  3486                              <1> ;-----	MEDIUM RESOLUTION WRITE
  3487                              <1> S6:					; MED_RES_WRITE
  3488 0000244A 88DA                <1> 	MOV	DL, BL			; SAVE HIGH COLOR BIT
  3489 0000244C 66D1E7              <1> 	SAL	DI, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  3490                              <1> 					; EXPAND BL TO FULL WORD OF COLOR
  3491 0000244F 80E303              <1> 	AND	BL, 3			; ISOLATE THE COLOR BITS ( LOW 2 BITS )
  3492 00002452 B055                <1> 	MOV	AL, 055H 		; GET BIT CONVERSION MULTIPLIER
  3493 00002454 F6E3                <1> 	MUL	BL			; EXPAND 2 COLOR BITS TO 4 REPLICATIONS
  3494 00002456 88C3                <1> 	MOV	BL, AL			; PLACE BACK IN WORK REGISTER
  3495 00002458 88C7                <1> 	MOV	BH, AL			; EXPAND TO 8 REPLICATIONS OF COLOR BITS
  3496 0000245A 81C700800B00        <1> 	add	edi, 0B8000h
  3497                              <1> S7:                                     ; MED_CHAR
  3498 00002460 57                  <1> 	PUSH	eDI			; SAVE REGEN POINTER
  3499 00002461 56                  <1> 	PUSH	eSI			; SAVE THE CODE POINTER
  3500 00002462 B604                <1> 	MOV	DH, 4			; NUMBER OF LOOPS
  3501                              <1> S8:
  3502 00002464 AC                  <1> 	LODSB				; GET CODE POINT
  3503 00002465 E8B3000000          <1> 	CALL	S21			; DOUBLE UP ALL THE BITS
  3504 0000246A 6621D8              <1> 	AND	AX, BX			; CONVERT TO FOREGROUND COLOR ( 0 BACK )
  3505 0000246D 86E0                <1> 	XCHG	AH, AL			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  3506 0000246F F6C280              <1> 	TEST	DL, 80H			; IS THIS XOR FUNCTION
  3507 00002472 7403                <1> 	JZ	short S9		; NO, STORE IT IN AS IS
  3508 00002474 663307              <1> 	XOR	AX, [eDI]		; DO FUNCTION WITH LOW/HIGH
  3509                              <1> S9:
  3510 00002477 668907              <1> 	MOV	[eDI], AX		; STORE FIRST BYTE HIGH, SECOND LOW
  3511 0000247A AC                  <1> 	LODSB				; GET CODE POINT
  3512 0000247B E89D000000          <1> 	CALL	S21
  3513 00002480 6621D8              <1> 	AND	AX, BX			; CONVERT TO COLOR
  3514 00002483 86E0                <1> 	XCHG	AH, AL			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  3515 00002485 F6C280              <1> 	TEST	DL, 80H			; AGAIN, IS THIS XOR FUNCTION
  3516 00002488 7407                <1> 	JZ	short _S10		; NO, JUST STORE THE VALUES
  3517 0000248A 66338700200000      <1> 	XOR	AX, [eDI+2000H]		; FUNCTION WITH FIRST HALF LOW
  3518                              <1> _S10:
  3519 00002491 66898700200000      <1> 	MOV	[eDI+2000H], AX		; STORE SECOND PORTION HIGH
  3520 00002498 6683C750            <1> 	ADD	DI, 80			; POINT TO NEXT LOCATION
  3521 0000249C FECE                <1> 	DEC	DH
  3522 0000249E 75C4                <1> 	JNZ	short S8		; KEEP GOING
  3523 000024A0 5E                  <1> 	POP	eSI			; RECOVER CODE POINTER
  3524 000024A1 5F                  <1> 	POP	eDI			; RECOVER REGEN POINTER
  3525 000024A2 47                  <1> 	INC	eDI			; POINT TO NEXT CHAR POSITION
  3526 000024A3 47                  <1> 	INC	eDI
  3527 000024A4 E2BA                <1> 	LOOP	S7			; MORE TO WRITE
  3528 000024A6 C3                  <1> 	retn
  3529                              <1> 
  3530                              <1> ; 04/07/2016
  3531                              <1> ; 01/07/2016
  3532                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3533                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3534                              <1> ;----------------------------------------
  3535                              <1> ; GRAPHICS READ
  3536                              <1> ;----------------------------------------
  3537                              <1> GRAPHICS_READ:
  3538 000024A7 E8A3000000          <1> 	CALL	S26			; CONVERTED TO OFFSET IN REGEN
  3539 000024AC 89C6                <1> 	MOV	eSI, eAX		; SAVE IN SI
  3540 000024AE 81C600800B00        <1> 	add	esi, 0B8000h		; 01/07/2016
  3541 000024B4 83EC08              <1> 	SUB	eSP, 8			; ALLOCATE SPACE FOR THE READ CODE POINT
  3542 000024B7 89E5                <1> 	MOV	eBP, eSP		; POINTER TO SAVE AREA
  3543                              <1> 
  3544                              <1> ;-----	DETERMINE GRAPHICS MODES
  3545 000024B9 B604                <1> 	mov	dh, 4			; number of passes ; 01/07/2016
  3546 000024BB 803D[F25E0000]06    <1> 	CMP	byte [CRT_MODE], 6
  3547 000024C2 7219                <1> 	JC	short S12		; MEDIUM RESOLUTION
  3548                              <1> 
  3549                              <1> ;-----	HIGH RESOLUTION READ
  3550                              <1> ;-----	GET VALUES FROM REGEN BUFFER AND CONVERT TO CODE POINT
  3551                              <1> 	;MOV	DH,4			; NUMBER OF PASSES
  3552                              <1> S11:
  3553 000024C4 8A06                <1> 	MOV	AL, [eSI] 		; GET FIRST BYTE
  3554 000024C6 884500              <1> 	MOV	[eBP], AL 		; SAVE IN STORAGE AREA
  3555 000024C9 45                  <1> 	INC	eBP			; NEXT LOCATION
  3556 000024CA 8A8600200000        <1> 	MOV	AL, [eSI+2000H]		; GET LOWER REGION BYTE
  3557 000024D0 884500              <1> 	MOV	[eBP], AL 		; ADJUST AND STORE
  3558 000024D3 45                  <1> 	INC	eBP
  3559 000024D4 83C650              <1> 	ADD	eSI, 80			; POINTER INTO REGEN
  3560 000024D7 FECE                <1> 	DEC	DH			; LOOP CONTROL
  3561 000024D9 75E9                <1> 	JNZ	short S11		; DO IT SOME MORE
  3562 000024DB EB1D                <1> 	JMP	SHORT S14		; GO MATCH THE SAVED CODE POINTS
  3563                              <1> 
  3564                              <1> ;-----	MEDIUM RESOLUTION READ
  3565                              <1> S12:	
  3566 000024DD 66D1E6              <1> 	SAL	SI, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  3567                              <1> 	;MOV	DH, 4			; NUMBER OF PASSES
  3568                              <1> S13:
  3569 000024E0 E84D000000          <1> 	CALL	S23			; GET BYTES FROM REGEN INTO SINGLE SAVE
  3570 000024E5 81C6FE1F0000        <1> 	ADD	eSI, 2000H-2		; GO TO LOWER REGION
  3571 000024EB E842000000          <1> 	CALL	S23			; GET THIS PAIR INTO SAVE
  3572 000024F0 81EEB21F0000        <1> 	SUB	eSI, 2000H-80+2		; ADJUST POINTER BACK INTO UPPER
  3573 000024F6 FECE                <1> 	DEC	DH
  3574 000024F8 75E6                <1> 	JNZ	short S13		; KEEP GOING UNTIL ALL 8 DONE
  3575                              <1> 
  3576                              <1> ;-----	SAVE AREA HAS CHARACTER IN IT, MATCH IT
  3577                              <1> S14:					; FIND_CHAR
  3578 000024FA BF[242D0100]        <1> 	MOV	eDI, CRT_CHAR_GEN	; ESTABLISH ADDRESSING
  3579 000024FF 83ED08              <1> 	SUB	eBP, 8			; ADJUST POINTER TO START OF SAVE AREA
  3580 00002502 89EE                <1> 	MOV	eSI, eBP
  3581                              <1> S15:
  3582 00002504 66B80001            <1> 	mov	ax, 256			; NUMBER TO TEST AGAINST
  3583                              <1> S16:
  3584 00002508 56                  <1> 	PUSH	eSI			; SAVE SAVE AREA POINTER
  3585 00002509 57                  <1> 	PUSH	eDI			; SAVE CODE POINTER
  3586                              <1> 	;MOV	eCX, 4			; NUMBER OF WORDS TO MATCH
  3587                              <1> 	;REPE	CMPSW			; COMPARE THE 8 BYTES AS WORDS
  3588 0000250A A7                  <1> 	cmpsd				; compare first 4 bytes 
  3589 0000250B 7501                <1> 	jne	short S17		; 
  3590 0000250D A7                  <1> 	cmpsd				; compare last 4 bytes
  3591                              <1> S17:
  3592 0000250E 5F                  <1> 	POP	eDI			; RECOVER THE POINTERS
  3593 0000250F 5E                  <1> 	POP	eSI
  3594                              <1> 	;JZ	short S18		; IF ZERO FLAG SET, THEN MATCH OCCURRED
  3595 00002510 7407                <1> 	je	short S18
  3596                              <1> 	;				; NO MATCH, MOVE ON TO NEXT
  3597 00002512 83C708              <1> 	ADD	eDI, 8			; NEXT CODE POINT
  3598 00002515 6648                <1> 	dec	ax			; LOOP CONTROL
  3599 00002517 75EF                <1> 	JNZ	short S16		; DO ALL OF THEM
  3600                              <1> 
  3601                              <1> ;-----	CHARACTER IS FOUND ( AL=0 IF NOT FOUND )
  3602                              <1> S18:	
  3603 00002519 83C408              <1> 	ADD	eSP, 8			; READJUST THE STACK, THROW AWAY SAVE
  3604 0000251C C3                  <1> 	retn				; ALL DONE
  3605                              <1> 
  3606                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3607                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3608                              <1> ;--------------------------------------------
  3609                              <1> ; EXPAND BYTE
  3610                              <1> ;  THIS ROUTINE TAKES THE BYTE IN AL AND DOUBLES ALL
  3611                              <1> ;  OF THE BITS, TURNING THE 8 BITS INTO 16 BITS.
  3612                              <1> ;  THE RESULT IS LEFT IN AX
  3613                              <1> ;--------------------------------------------
  3614                              <1> S21:
  3615 0000251D 6651                <1> 	PUSH	CX			; SAVE REGISTER
  3616                              <1> 	;MOV	CX, 8			; SHIFT COUNT REGISTER FOR ONE BYTE
  3617 0000251F B108                <1> 	mov	cl, 8
  3618                              <1> S22:
  3619 00002521 D0C8                <1> 	ROR	AL,1			; SHIFT BITS, LOW BIT INTO CARRY FLAG
  3620 00002523 66D1DD              <1> 	RCR	BP,1			; MOVE CARRY FLAG (LOW BIT INTO RESULTS
  3621 00002526 66D1FD              <1> 	SAR	BP,1			; SIGN EXTEND HIGH BIT (DOUBLE IT)
  3622                              <1> 	;LOOP	S22			; REPEAT FOR ALL 8 BITS
  3623 00002529 FEC9                <1> 	dec	cl
  3624 0000252B 75F4                <1> 	jnz	short S22
  3625 0000252D 6695                <1> 	XCHG	AX, BP			; MOVE RESULTS TO PARAMETER REGISTER
  3626 0000252F 6659                <1> 	POP	CX			; RECOVER REGISTER
  3627 00002531 C3                  <1> 	RETn				; ALL DONE
  3628                              <1> 
  3629                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3630                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3631                              <1> ;--------------------------------------------------
  3632                              <1> ; MED_READ_BYTE
  3633                              <1> ; THIS ROUTINE WILL TAKE 2 BYTES FROM THE REGEN BUFFER,
  3634                              <1> ;  COMPARE AGAINST THE CURRENT FOREGROUND COLOR, AND PLACE
  3635                              <1> ;  THE CORRESPONDING ON/OFF BIT PATTERN INTO THE CURRENT
  3636                              <1> ;  POSITION IN THE SAVE AREA
  3637                              <1> ; ENTRY --
  3638                              <1> ;  SI,DS = POINTER TO REGEN AREA OF INTEREST
  3639                              <1> ;  BX = EXPANDED FOREGROUND COLOR
  3640                              <1> ;  BP = POINTER TO SAVE AREA
  3641                              <1> ; EXIT --
  3642                              <1> ;  SI AND BP ARE INCREMENTED
  3643                              <1> ;----------------------------------------------------
  3644                              <1> S23:
  3645 00002532 66AD                <1> 	LODSW				; GET FIRST BYTE AND SECOND BYTES
  3646 00002534 86C4                <1> 	XCHG	AL, AH			; SWAP FOR COMPARE
  3647 00002536 66B900C0            <1> 	MOV	CX, 0C000H		; 2 BIT MASK TO TEST THE ENTRIES
  3648 0000253A B200                <1> 	MOV	DL, 0			; RESULT REGISTER
  3649                              <1> S24:
  3650 0000253C 6685C8              <1> 	TEST	AX, CX			; IS THIS SECTION BACKCROUND?
  3651 0000253F 7401                <1>         JZ      short S25               ; IF ZERO, IT IS BACKGROUND (CARRY=0)
  3652 00002541 F9                  <1> 	STC				; WASN'T, SO SET CARRY
  3653                              <1> S25:
  3654 00002542 D0D2                <1> 	RCL	DL, 1			; MOVE THAT BIT INTO THE RESULT
  3655 00002544 66C1E902            <1> 	SHR	CX, 2			; MOVE THE MASK TO THE RIGHT BY 2 BITS
  3656 00002548 73F2                <1> 	JNC	short S24		; DO IT AGAIN IF MASK DIDN'T FALL OUT
  3657 0000254A 885500              <1> 	MOV	[eBP], DL 		; STORE RESULT IN SAVE AREA
  3658 0000254D 45                  <1> 	INC	eBP			; ADJUST POINTER
  3659 0000254E C3                  <1> 	RETn				; ALL DONE
  3660                              <1> 
  3661                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  3662                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3663                              <1> ;-----------------------------------------
  3664                              <1> ; V4_POSITION
  3665                              <1> ;  THIS ROUTINE TAKES THE CURSOR POSITION CONTAINED IN
  3666                              <1> ;  THE MEMORY LOCATION, AND CONVERTS IT INTO AN OFFSET
  3667                              <1> ;  INTO THE REGEN BUFFER, ASSUMING ONE BYTE/CHAR.
  3668                              <1> ;  FOR MEDIUM RESOLUTION GRAPHICS, THE NUMBER MUST
  3669                              <1> ;  BE DOUBLED.
  3670                              <1> ; ENTRY -- NO REGISTERS,MEMORY LOCATION @CURSOR_POSN IS USED
  3671                              <1> ; EXIT--
  3672                              <1> ;  AX CONTAINS OFFSET INTO REGEN BUFFER
  3673                              <1> ;-----------------------------------------
  3674                              <1> S26:
  3675 0000254F 0FB705[C6580100]    <1> 	movzx	eax, word [CURSOR_POSN]	; GET CURRENT CURSOR
  3676                              <1> GRAPH_POSN:
  3677 00002556 53                  <1> 	PUSH	eBX			; SAVE REGISTER
  3678 00002557 0FB6D8              <1> 	movzx	ebx, al			; SAVE A COPY OF CURRENT CURSOR
  3679 0000255A A0[F45E0000]        <1> 	MOV	AL, [CRT_COLS]		; GET BYTES PER COLUMN
  3680 0000255F F6E4                <1> 	MUL	AH			; MULTIPLY BY ROWS
  3681 00002561 66C1E002            <1> 	SHL	AX, 2			; MULTIPLY * 4 SINCE 4 ROWS/BYTE
  3682 00002565 01D8                <1> 	ADD	eAX, eBX		; DETERMINE OFFSET
  3683 00002567 5B                  <1> 	POP	eBX			; RECOVER POINTER
  3684 00002568 C3                  <1> 	RETn				; ALL DONE
  3685                              <1> 
  3686                              <1> ; 09/07/2016
  3687                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3688                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3689                              <1> ;---------------------------------------------
  3690                              <1> ; SET_COLOR
  3691                              <1> ;	THIS ROUTINE WILL ESTABLISH THE BACKGROUND COLOR, THE OVERSCAN COLOR,
  3692                              <1> ;	AND THE FOREGROUND COLOR SET FOR MEDIUM RESOLUTION GRAPHICS
  3693                              <1> ; INPUT
  3694                              <1> ;	(BH) HAS COLOR ID
  3695                              <1> ;		IF BH=0, THE BACKGROUND COLOR VALUE IS SET
  3696                              <1> ;			FROM THE LOW BITS OF BL (0-31)
  3697                              <1> ;		IF BH=1, THE PALETTE SELECTION IS MADE
  3698                              <1> ;			BASED ON THE LOW BIT OF BL:
  3699                              <1> ;				0 = GREEN, RED, YELLOW FOR COLORS 1,2,3
  3700                              <1> ;				1 = BLUE, CYAN, MAGENTA FOR COLORS 1,2,3
  3701                              <1> ;	(BL) HAS THE COLOR VALUE TO BE USED
  3702                              <1> ; OUTPUT
  3703                              <1> ;	THE COLOR SELECTION IS UPDATED
  3704                              <1> ;----------------------------------------------
  3705                              <1> SET_COLOR:
  3706 00002569 803D[F25E0000]07    <1>         cmp     byte [CRT_MODE], 7      ; 09/07/2016
  3707 00002570 0F870EF0FFFF        <1> 	ja	VIDEO_RETURN		; nothing to do for VGA modes	 
  3708                              <1> 
  3709                              <1> 	;MOV	DX, [ADDR_6845]		; I/O PORT FOR PALETTE
  3710                              <1> 	;mov	dx, 3D4h
  3711                              <1> 	;ADD	DX,5			; OVERSCAN PORT
  3712 00002576 66BAD903            <1> 	mov	dx, 3D9h
  3713 0000257A A0[F55E0000]        <1> 	MOV	AL, [CRT_PALETTE] 	; GET THE CURRENT PALETTE VALUE
  3714 0000257F 08FF                <1> 	OR	BH, BH			; IS THIS COLOR 0?
  3715 00002581 7512                <1> 	JNZ	short M20		; OUTPUT COLOR 1
  3716                              <1> 
  3717                              <1> ;-----	HANDLE COLOR 0 BY SETTING THE BACKGROUND COLOR
  3718                              <1> 
  3719 00002583 24E0                <1> 	AND	AL, 0E0H 		; TURN OFF LOW 5 BITS OF CURRENT
  3720 00002585 80E31F              <1> 	AND	BL, 01FH 		; TURN OFF HIGH 3 BITS OF INPUT VALUE
  3721 00002588 08D8                <1> 	OR	AL, BL			; PUT VALUE INTO REGISTER
  3722                              <1> M19:					; OUTPUT THE PALETTE
  3723 0000258A EE                  <1> 	OUT	DX, AL			; OUTPUT COLOR SELECTION TO 3D9 PORT
  3724 0000258B A2[F55E0000]        <1> 	MOV	[CRT_PALETTE], AL 	; SAVE THE COLOR VALUE
  3725 00002590 E9EFEFFFFF          <1> 	JMP	VIDEO_RETURN
  3726                              <1> 
  3727                              <1> ;-----	HANDLE COLOR 1 BY SELECTING THE PALETTE TO BE USED
  3728                              <1> 
  3729                              <1> M20:
  3730 00002595 24DF                <1> 	AND	AL, 0DFH 		; TURN OFF PALETTE SELECT BIT
  3731 00002597 D0EB                <1> 	SHR	BL, 1			; TEST THE LOW ORDER BIT OF BL
  3732 00002599 73EF                <1> 	JNC	short M19		; ALREADY DONE
  3733 0000259B 0C20                <1> 	OR	AL, 20H			; TURN ON PALETTE SELECT BIT
  3734 0000259D EBEB                <1> 	JMP	short M19		; GO DO IT
  3735                              <1> 
  3736                              <1> ; 09/07/2016
  3737                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3738                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3739                              <1> ;--------------------------------------------
  3740                              <1> ; READ DOT -- WRITE DOT
  3741                              <1> ; THESE ROUTINES WILL WRITE A DOT, OR READ THE
  3742                              <1> ;  DOT AT THE INDICATED LOCATION
  3743                              <1> ; ENTRY --
  3744                              <1> ;   DX = ROW (0-199)	(THE ACTUAL VALUE DEPENDS ON THE MODE)
  3745                              <1> ;   CX = COLUMN ( 0-639) ( THE VALUES ARE NOT RANGE CHECKED )
  3746                              <1> ;   AL = DOT VALUE TO WRITE (1,2 OR 4 BITS DEPENDING ON MODE,
  3747                              <1> ;	REQUIRED FOR WRITE DOT ONLY, RIGHT JUSTIFIED)
  3748                              <1> ;	BIT 7 OF AL = 1 INDICATES XOR THE VALUE INTO THE LOCATION
  3749                              <1> ;   DS = DATA SEGMENT
  3750                              <1> ;   ES = REGEN SEGMENT
  3751                              <1> ;
  3752                              <1> ; EXIT
  3753                              <1> ;	AL = DOT VALUE READ, RIGHT JUSTIFIED, READ ONLY
  3754                              <1> ;----------------------------------------------
  3755                              <1> 
  3756                              <1> READ_DOT:
  3757                              <1> 	; 09/07/2016
  3758 0000259F 8A25[F25E0000]      <1> 	mov	ah,  [CRT_MODE]
  3759 000025A5 80FC07              <1> 	cmp	ah, 7 ; 6!?
  3760 000025A8 760A                <1> 	jna	short read_dot_cga
  3761                              <1> 
  3762 000025AA E8CB030000          <1> 	call	vga_read_pixel
  3763                              <1> 	; al = pixel value
  3764 000025AF E9D5EFFFFF          <1> 	jmp	_video_return
  3765                              <1> 
  3766                              <1> read_dot_cga:
  3767                              <1> 	;je	VIDEO_RETURN ; 7	
  3768 000025B4 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  3769 000025B7 0F82C7EFFFFF        <1> 	jb	VIDEO_RETURN ; no, text mode, nothing to do
  3770                              <1> 
  3771 000025BD E855000000          <1> 	CALL	R3			; DETERMINE BYTE POSITION OF DOT
  3772 000025C2 8A06                <1> 	MOV	AL, [eSI]		; GET THE BYTE
  3773 000025C4 20E0                <1> 	AND	AL, AH			; MASK OFF THE OTHER BITS IN THE BYTE
  3774 000025C6 D2E0                <1> 	SHL	AL, CL			; LEFT JUSTIFY THE VALUE
  3775 000025C8 88F1                <1> 	MOV	CL, DH			; GET NUMBER OF BITS IN RESULT
  3776 000025CA D2C0                <1> 	ROL	AL, CL			; RIGHT JUSTIFY THE RESULT
  3777                              <1> 	;JMP	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  3778 000025CC 0FB6C0              <1> 	movzx	eax, al
  3779 000025CF E9B5EFFFFF          <1> 	jmp	_video_return
  3780                              <1> 
  3781                              <1> ; 09/07/2016
  3782                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3783                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3784                              <1> 
  3785                              <1> WRITE_DOT:
  3786                              <1> 	; 09/07/2016
  3787 000025D4 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE]
  3788 000025DA 80FC07              <1> 	cmp	ah, 7 ; 6!?
  3789 000025DD 760A                <1> 	jna	short write_dot_cga
  3790                              <1> 	
  3791 000025DF E805030000          <1> 	call	vga_write_pixel
  3792 000025E4 E99BEFFFFF          <1> 	jmp	VIDEO_RETURN
  3793                              <1> 
  3794                              <1> write_dot_cga:
  3795                              <1> 	;je	VIDEO_RETURN ; 7	
  3796 000025E9 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  3797 000025EC 0F8292EFFFFF        <1> 	jb	VIDEO_RETURN ; no, text mode, nothing to do
  3798                              <1> 
  3799                              <1> 	;PUSH	AX			; SAVE DOT VALUE
  3800 000025F2 6650                <1> 	PUSH	AX			; TWICE
  3801 000025F4 E81E000000          <1> 	CALL	R3			; DETERMINE BYTE POSITION OF THE DOT
  3802 000025F9 D2E8                <1> 	SHR	AL, CL			; SHIFT TO SET UP THE BITS FOR OUTPUT
  3803 000025FB 20E0                <1> 	AND	AL, AH			; STRIP OFF THE OTHER BITS
  3804 000025FD 8A0E                <1> 	MOV	CL, [eSI]		; GET THE CURRENT BYTE
  3805 000025FF 665B                <1> 	POP	BX			; RECOVER XOR FLAG
  3806 00002601 F6C380              <1> 	TEST	BL, 80H			; IS IT ON
  3807 00002604 750D                <1> 	JNZ	short R2		; YES, XOR THE DOT
  3808 00002606 F6D4                <1> 	NOT	AH			; SET MASK TO REMOVE THE INDICATED BITS
  3809 00002608 20E1                <1> 	AND	CL, AH
  3810 0000260A 08C8                <1> 	OR	AL, CL			; OR IN THE NEW VALUE OF THOSE BITS
  3811                              <1> R1:					; FINISH_DOT
  3812 0000260C 8806                <1> 	MOV	[eSI], AL		; RESTORE THE BYTE IN MEMORY
  3813                              <1> 	;POP	AX
  3814 0000260E E971EFFFFF          <1> 	JMP	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  3815                              <1> R2:					; XOR_DOT
  3816 00002613 30C8                <1> 	XOR	AL, CL			; EXCLUSIVE OR THE DOTS
  3817 00002615 EBF5                <1> 	JMP	short R1		; FINISH UP THE WRITING
  3818                              <1> 
  3819                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  3820                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3821                              <1> 
  3822                              <1> ;----------------------------------------------
  3823                              <1> ; THIS SUBROUTINE DETERMINES THE REGEN BYTE LOCATION OF THE
  3824                              <1> ; INDICATED ROW COLUMN VALUE IN GRAPHICS MODE.
  3825                              <1> ; ENTRY --
  3826                              <1> ;  DX = ROW VALUE (0-199)
  3827                              <1> ;  CX = COLUMN VALUE (0-639)
  3828                              <1> ; EXIT --
  3829                              <1> ;  SI = OFFSET INTO REGEN BUFFER FOR BYTE OF INTEREST
  3830                              <1> ;  AH = MASK TO STRIP OFF THE BITS OF INTEREST
  3831                              <1> ;  CL = BITS TO SHIFT TO RIGHT JUSTIFY THE MASK IN AH
  3832                              <1> ;  DH = # BITS IN RESULT
  3833                              <1> ;  BX = MODIFIED
  3834                              <1> ;-----------------------------------------------
  3835                              <1> R3:
  3836                              <1> 
  3837                              <1> ;-----	DETERMINE 1ST BYTE IN INDICATED ROW BY MULTIPLYING ROW VALUE BY 40
  3838                              <1> ;-----	 ( LOW BIT OF ROW DETERMINES EVEN/ODD, 80 BYTES/ROW )
  3839                              <1> 
  3840 00002617 0FB7F0              <1> 	movzx	esi, ax			; WILL SAVE AL AND AH DURING OPERATION
  3841 0000261A B028                <1> 	MOV	AL, 40
  3842 0000261C F6E2                <1> 	MUL	DL			; AX= ADDRESS OF START OF INDICATED ROW
  3843 0000261E A808                <1> 	TEST	AL, 08H 		; TEST FOR EVEN/ODD ROW CALCULATED
  3844 00002620 7404                <1> 	JZ	short R4		; JUMP IF EVEN ROW
  3845 00002622 6605D81F            <1> 	ADD	AX, 2000H-40		; OFFSET TO LOCATION OF ODD ROWS ADJUST
  3846                              <1> R4:					; EVEN_ROW
  3847 00002626 6696                <1> 	XCHG	SI, AX			; MOVE POINTER TO (SI) AND RECOVER (AX)
  3848 00002628 81C600800B00        <1> 	add	esi, 0B8000h
  3849 0000262E 6689CA              <1> 	MOV	DX, CX			; COLUMN VALUE TO DX
  3850                              <1> 
  3851                              <1> ;-----	DETERMINE GRAPHICS MODE CURRENTLY IN EFFECT
  3852                              <1> 
  3853                              <1> ; SET UP THE REGISTERS ACCORDING TO THE MODE
  3854                              <1> ; CH = MASK FOR LOW OF COLUMN ADDRESS ( 7/3 FOR HIGH/MED RES )
  3855                              <1> ; CL = # OF ADDRESS BITS IN COLUMN VALUE ( 3/2 FOR H/M )
  3856                              <1> ; BL = MASK TO SELECT BITS FROM POINTED BYTE ( 80H/C0H FOR H/M )
  3857                              <1> ; BH = NUMBER OF VALID BITS IN POINTED BYTE ( 1/2 FOR H/M )
  3858                              <1> 
  3859 00002631 66BBC002            <1> 	MOV	BX, 2C0H
  3860 00002635 66B90203            <1> 	MOV	CX, 302H 		; SET PARMS FOR MED RES
  3861 00002639 803D[F25E0000]06    <1> 	CMP	byte [CRT_MODE], 6
  3862 00002640 7208                <1> 	JC	short R5		; HANDLE IF MED RES
  3863 00002642 66BB8001            <1> 	MOV	BX, 180H
  3864 00002646 66B90307            <1> 	MOV	CX, 703H 		; SET PARMS FOR HIGH RES
  3865                              <1> 
  3866                              <1> ;-----	DETERMINE BIT OFFSET IN BYTE FROM COLUMN MASK
  3867                              <1> R5:
  3868 0000264A 20D5                <1> 	AND	CH, DL			; ADDRESS OF PEL WITHIN BYTE TO CH
  3869                              <1> 
  3870                              <1> ;-----	DETERMINE BYTE OFFSET FOR THIS LOCATION IN COLUMN
  3871                              <1> 
  3872 0000264C 66D3EA              <1> 	SHR	DX, CL			; SHIFT BY CORRECT AMOUNT
  3873 0000264F 6601D6              <1> 	ADD	SI, DX			; INCREMENT THE POINTER
  3874 00002652 88FE                <1> 	MOV	DH, BH			; GET THE # OF BITS IN RESULT TO DH
  3875                              <1> 
  3876                              <1> ;-----	MULTIPLY BH (VALID BITS IN BYTE) BY CH (BIT OFFSET)
  3877                              <1> 
  3878 00002654 28C9                <1> 	SUB	CL, CL			; ZERO INTO STORAGE LOCATION
  3879                              <1> R6:
  3880 00002656 D0C8                <1> 	ROR	AL, 1			; LEFT JUSTIFY VALUE IN AL (FOR WRITE)
  3881 00002658 00E9                <1> 	ADD	CL, CH			; ADD IN THE BIT OFFSET VALUE
  3882 0000265A FECF                <1> 	DEC	BH			; LOOP CONTROL
  3883 0000265C 75F8                <1> 	JNZ	short R6		; ON EXIT, CL HAS COUNT TO RESTORE BITS
  3884 0000265E 88DC                <1> 	MOV	AH, BL			;  GET MASK TO AH
  3885 00002660 D2EC                <1> 	SHR	AH, CL			;  MOVE THE MASK TO CORRECT LOCATION
  3886 00002662 C3                  <1> 	RETn				;  RETURN WITH EVERYTHING SET UP
  3887                              <1> 
  3888                              <1> load_dac_palette:
  3889                              <1> 	; 29/07/2016
  3890                              <1> 	; 23/07/2016
  3891                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  3892                              <1> 	; (set_mode_vga)
  3893                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3894                              <1> 	; vgabios-0.7a (2011)
  3895                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3896                              <1> 	; 'vgabios.c', 'load_dac_palette'
  3897                              <1> 	;
  3898                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  3899                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  3900                              <1> 	;
  3901                              <1> 	; INPUT -> AH = DAC selection number (3, 2 or 1)
  3902                              <1> 	; OUTPUT -> ECX = 0, AX = 0
  3903                              <1> 	; (Modifed registers: EAX, ECX, EDX, ESI)
  3904                              <1> 	;
  3905 00002663 66BAC803            <1> 	mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  3906 00002667 28C0                <1> 	sub	al, al ; 0
  3907 00002669 EE                  <1> 	out	dx, al ; 0 ; color index, always 0 at the beginning	
  3908 0000266A 6642                <1> 	inc	dx   ; 3C9h ; VGAREG_DAC_DATA
  3909 0000266C B900010000          <1> 	mov	ecx, 256   ; always 256*3 values
  3910                              <1> 	;push	esi
  3911 00002671 88E0                <1> 	mov	al, ah
  3912 00002673 B43F                <1> 	mov	ah, 3Fh	; 3Fh except DAC selection number 3
  3913 00002675 3C02                <1> 	cmp 	al, 2
  3914 00002677 7414                <1> 	je	short l_dac_p_2
  3915 00002679 7719                <1> 	ja	short l_dac_p_3
  3916 0000267B 20C0                <1> 	and	al, al
  3917 0000267D 7507                <1> 	jnz	short l_dac_p_1
  3918                              <1> l_dac_p_0:
  3919 0000267F BE[E4270100]        <1> 	mov	esi, palette0
  3920 00002684 EB15                <1> 	jmp	short l_dac_p_4	
  3921                              <1> l_dac_p_1:
  3922 00002686 BE[A4280100]        <1> 	mov	esi, palette1
  3923 0000268B EB0E                <1> 	jmp	short l_dac_p_4
  3924                              <1> l_dac_p_2:
  3925 0000268D BE[64290100]        <1> 	mov	esi, palette2
  3926 00002692 EB07                <1> 	jmp	short l_dac_p_4
  3927                              <1> l_dac_p_3:
  3928 00002694 B4FF                <1> 	mov	ah, 0FFh ; dac registers
  3929 00002696 BE[242A0100]        <1> 	mov	esi, palette3
  3930                              <1> l_dac_p_4:
  3931 0000269B AC                  <1> 	lodsb
  3932 0000269C EE                  <1> 	out	dx, al  ; Red
  3933 0000269D AC                  <1> 	lodsb
  3934 0000269E EE                  <1> 	out	dx, al	; Green
  3935 0000269F AC                  <1> 	lodsb
  3936 000026A0 EE                  <1> 	out	dx, al	; Blue
  3937 000026A1 20E4                <1> 	and	ah, ah
  3938 000026A3 7405                <1> 	jz	short l_dac_p_5	
  3939 000026A5 FECC                <1> 	dec	ah
  3940 000026A7 E2F2                <1> 	loop	l_dac_p_4
  3941                              <1> 	;pop	esi
  3942 000026A9 C3                  <1> 	retn
  3943                              <1> l_dac_p_5:
  3944                              <1> 	; 29/07/2016
  3945 000026AA FEC9                <1> 	dec	cl
  3946 000026AC 7407                <1> 	jz	short l_dac_p_7
  3947                              <1> 	;
  3948 000026AE 28C0                <1> 	sub	al, al ; 0
  3949                              <1> l_dac_p_6:
  3950 000026B0 EE                  <1> 	out	dx, al ; outb(VGAREG_DAC_DATA,0);
  3951 000026B1 EE                  <1> 	out	dx, al
  3952 000026B2 EE                  <1> 	out	dx, al
  3953 000026B3 E2FB                <1> 	loop	l_dac_p_6
  3954                              <1> l_dac_p_7:
  3955                              <1> 	;pop	esi
  3956 000026B5 C3                  <1> 	retn
  3957                              <1> 
  3958                              <1> gray_scale_summing:
  3959                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  3960                              <1> 	; (set_mode_vga)
  3961                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  3962                              <1> 	; vgabios-0.7a (2011)
  3963                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  3964                              <1> 	; 'vgabios.c', 'biosfn_perform_gray_scale_summing'
  3965                              <1> 	;
  3966                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  3967                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  3968                              <1> 	;
  3969                              <1> 
  3970                              <1> 	; INPUT -> EBX = Start address (color index <= 255)
  3971                              <1> 	;	   ECX = Count (<= 256)
  3972                              <1> 	; OUTPUT -> (E)CX = 0
  3973                              <1> 	; (Modifed registers: EAX, ECX, EDX, EBX)
  3974                              <1> 
  3975 000026B6 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  3976 000026BA EC                  <1> 	in	al, dx
  3977 000026BB 30C0                <1> 	xor	al, al ; 0
  3978 000026BD 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  3979 000026C1 EE                  <1> 	out	dx, al	; clear bit 5
  3980                              <1> 			; (while loading palette registers)
  3981                              <1> 	; set read address and switch to read mode
  3982                              <1> g_s_s_1:
  3983 000026C2 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  3984 000026C6 88D8                <1> 	mov	al, bl
  3985 000026C8 EE                  <1> 	out	dx, al
  3986                              <1> 	; get 6-bit wide RGB data values
  3987                              <1>  	; intensity = (0.3*Red)+(0.59*Green)+(0.11*Blue)
  3988                              <1> 	; i = ( ( 77*r + 151*g + 28*b ) + 0x80 ) >> 8;
  3989 000026C9 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  3990 000026CD EC                  <1> 	in	al, dx ; red
  3991 000026CE B44D                <1> 	mov	ah, 77 ; 0.3* Red
  3992 000026D0 F6E4                <1> 	mul	ah
  3993 000026D2 6650                <1> 	push	ax
  3994 000026D4 EC                  <1> 	in	al, dx ; green
  3995 000026D5 B497                <1> 	mov	ah, 151  ; 0.59 * Green
  3996 000026D7 F6E4                <1> 	mul	ah
  3997 000026D9 6650                <1> 	push	ax
  3998 000026DB EC                  <1> 	in	al, dx ; blue
  3999 000026DC B41C                <1> 	mov	ah, 28 ; 0.11 * Blue
  4000 000026DE F6E4                <1> 	mul	ah
  4001 000026E0 665A                <1> 	pop	dx
  4002 000026E2 6601D0              <1> 	add	ax, dx
  4003 000026E5 665A                <1> 	pop	dx
  4004 000026E7 6601D0              <1> 	add	ax, dx
  4005 000026EA 66058000            <1> 	add	ax, 80h  
  4006 000026EE B03F                <1> 	mov	al, 3Fh
  4007 000026F0 38C4                <1> 	cmp	ah, al
  4008 000026F2 7602                <1> 	jna	short g_s_s_2
  4009 000026F4 88C4                <1> 	mov	ah, al
  4010                              <1> g_s_s_2:
  4011 000026F6 66BAC803            <1> 	mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  4012 000026FA 88D8                <1> 	mov	al, bl ; color index
  4013 000026FC EE                  <1> 	out	dx, al
  4014 000026FD 88E0                <1> 	mov	al, ah ; intensity
  4015 000026FF 6642                <1> 	inc	dx ; 3C9h ; VGAREG_DAC_DATA
  4016 00002701 EE                  <1> 	out	dx, al ; R (R=G=B)
  4017 00002702 88E0                <1> 	mov	al, ah ; intensity
  4018 00002704 EE                  <1> 	out	dx, al ; G (R=G=B)
  4019 00002705 88E0                <1>  	mov	al, ah ; intensity
  4020 00002707 EE                  <1> 	out	dx, al ; B (R=G=B)
  4021 00002708 6649                <1> 	dec	cx
  4022 0000270A 7404                <1> 	jz	short g_s_s_3
  4023 0000270C FEC3                <1> 	inc	bl    ; next color index value
  4024 0000270E EBB2                <1> 	jmp	short g_s_s_1
  4025                              <1> g_s_s_3:
  4026 00002710 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  4027 00002714 EC                  <1> 	in	al, dx
  4028 00002715 B020                <1> 	mov	al, 20h
  4029 00002717 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  4030 0000271B EE                  <1> 	out	dx, al ; 20h -> set bit 5
  4031                              <1> 		        ; (after loading palette regs)	
  4032 0000271C C3                  <1> 	retn
  4033                              <1> 
  4034                              <1> vga_write_char_attr:
  4035                              <1> vga_write_char_only: 
  4036                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  4037                              <1> 	;
  4038                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4039                              <1> 	; vgabios-0.7a (2011)
  4040                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4041                              <1> 	; 'vgabios.c', 'biosfn_write_char_attr'
  4042                              <1> 	; 'biosfn_write_char_only'
  4043                              <1> 
  4044                              <1> 	; INPUT ->
  4045                              <1> 	; [CRT_MODE] = current video mode (>7)
  4046                              <1> 	; CX = Count of characters to write
  4047                              <1> 	; AL = Character to write
  4048                              <1> 	; BL = Color of character
  4049                              <1> 	; OUTPUT ->
  4050                              <1> 	; Regen buffer updated
  4051                              <1>  
  4052 0000271D 8A25[F25E0000]      <1> 	mov 	ah, [CRT_MODE]
  4053 00002723 668B15[C6580100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  4054                              <1> 
  4055 0000272A BE[0E5F0000]        <1> 	mov	esi, vga_modes
  4056 0000272F 89F7                <1> 	mov	edi, esi
  4057 00002731 83C710              <1> 	add	edi, vga_mode_count
  4058                              <1> vga_wca_0:
  4059 00002734 AC                  <1> 	lodsb
  4060 00002735 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4061 00002737 7405                <1> 	je	short vga_wca_2
  4062 00002739 39FE                <1> 	cmp	esi, edi
  4063 0000273B 72F7                <1> 	jb	short vga_wca_0
  4064                              <1> vga_wca_1:
  4065 0000273D C3                  <1> 	retn	; nothing to do
  4066                              <1> vga_wca_2:
  4067 0000273E 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  4068                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4069                              <1> 
  4070                              <1> 	; biosfn_write_char_attr (car,page,attr,count) 
  4071                              <1> 	; AL = car, page = 0, BL = attr, CX = count
  4072 00002741 803E04              <1> 	cmp	byte [esi], PLANAR4
  4073 00002744 741D                <1> 	je	short vga_wca_planar
  4074 00002746 803E03              <1> 	cmp	byte [esi], PLANAR1
  4075 00002749 7418                <1> 	je	short vga_wca_planar
  4076                              <1> vga_wca_linear8:
  4077                              <1> 	; while((count-->0) && (xcurs<nbcols))
  4078                              <1> 	; CX = count
  4079 0000274B 6621C9              <1> 	and	cx, cx
  4080 0000274E 74ED                <1> 	jz	short vga_wca_1
  4081 00002750 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS]
  4082 00002756 73E5                <1> 	jnb	short vga_wca_1
  4083                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  4084                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  4085                              <1> 	; [CRT_COLS] = nbcols
  4086 00002758 E81E000000          <1> 	call	write_gfx_char_lin	 
  4087 0000275D 6649                <1> 	dec	cx ; count
  4088 0000275F FEC2                <1> 	inc	dl ; xcurs
  4089 00002761 EBE8                <1> 	jmp	short vga_wca_linear8
  4090                              <1> vga_wca_planar:
  4091                              <1> 	; while((count-->0) && (xcurs<nbcols))
  4092                              <1> 	; CX = count
  4093 00002763 6621C9              <1> 	and	cx, cx
  4094 00002766 74D5                <1> 	jz	short vga_wca_1
  4095 00002768 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS]
  4096 0000276E 73CD                <1> 	jnb	short vga_wca_1
  4097                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  4098                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  4099                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  4100 00002770 E89D000000          <1> 	call	write_gfx_char_pl4
  4101 00002775 6649                <1> 	dec	cx ; count
  4102 00002777 FEC2                <1> 	inc	dl ; xcurs
  4103 00002779 EBE8                <1> 	jmp	short vga_wca_planar
  4104                              <1> 
  4105                              <1> write_gfx_char_lin:
  4106                              <1> 	; 08/08/2016
  4107                              <1> 	; 31/07/2016
  4108                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  4109                              <1> 	;
  4110                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4111                              <1> 	; vgabios-0.7a (2011)
  4112                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4113                              <1> 	; 'vgabios.c', 'write_gfx_char_lin'
  4114                              <1> 
  4115                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols)
  4116                              <1> 	; INPUT ->
  4117                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  4118                              <1> 	; [CRT_COLS] = nbcols
  4119                              <1> 	; OUTPUT ->
  4120                              <1> 	; Regen buffer updated
  4121                              <1> 
  4122 0000277B 51                  <1> 	push	ecx
  4123 0000277C 53                  <1> 	push	ebx
  4124 0000277D 52                  <1> 	push	edx
  4125 0000277E 50                  <1> 	push	eax
  4126                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  4127                              <1> 	; 08/08/2016
  4128 0000277F 0FB6F0              <1> 	movzx	esi, al ; car
  4129 00002782 0FB6C6              <1> 	movzx	eax, dh ; ycurs
  4130 00002785 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  4131 0000278B F6E4                <1> 	mul	ah
  4132                              <1> 	;shl	ax, 6 ; * 64
  4133 0000278D 66C1E003            <1>  	shl	ax, 3 ; * 8
  4134                              <1> 	;sub	dh, dh
  4135                              <1> 	;shl	dx, 3 ; xcurs * 8
  4136                              <1> 	;movzx	edi, dx
  4137 00002791 0FB6FA              <1> 	movzx	edi, dl
  4138 00002794 66C1E703            <1> 	shl	di, 3 ; xcurs * 8
  4139 00002798 30F6                <1> 	xor	dh, dh
  4140 0000279A 8A15[F65E0000]      <1> 	mov	dl, [CHAR_HEIGHT]
  4141 000027A0 66F7E2              <1> 	mul	dx
  4142                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  4143 000027A3 01C7                <1> 	add	edi, eax ; addr
  4144 000027A5 81C700000A00        <1> 	add	edi, 0A0000h
  4145                              <1> 	;shl	si, 3 ; car * 8
  4146 000027AB 30E4                <1> 	xor	ah, ah
  4147 000027AD A0[F65E0000]        <1> 	mov	al, [CHAR_HEIGHT]
  4148 000027B2 66F7E6              <1> 	mul	si
  4149 000027B5 6689C6              <1> 	mov	si, ax
  4150                              <1> 	;; esi = src = car * 8
  4151                              <1> 	; esi = src = car * [CHAR_HEIGHT]
  4152                              <1> 	; i = 0
  4153                              <1> 	;add	esi, vgafont8 ; fdata [src+i]
  4154                              <1> 	; 08/08/2016
  4155 000027B8 A1[4A650100]        <1> 	mov	eax, [VGA_INT43H]
  4156 000027BD 3D[24430100]        <1> 	cmp	eax, vgafont16
  4157 000027C2 740F                <1>         je      short wgfxl_0
  4158 000027C4 3D[24350100]        <1> 	cmp	eax, vgafont14
  4159 000027C9 7408                <1> 	je	short wgfxl_0
  4160 000027CB 81C6[242D0100]      <1> 	add	esi, vgafont8
  4161 000027D1 EB02                <1> 	jmp	short wgfxl_1
  4162                              <1> wgfxl_0:
  4163 000027D3 01C6                <1> 	add	esi, eax
  4164                              <1> wgfxl_1:
  4165 000027D5 28FF                <1> 	sub	bh, bh ; i = 0
  4166                              <1> wgfxl_2:
  4167                              <1> 	; for(i=0;i<8;i++)
  4168 000027D7 57                  <1> 	push	edi ; addr
  4169 000027D8 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  4170 000027DF F6E7                <1> 	mul	bh ; nbcols*i
  4171 000027E1 66C1E003            <1> 	shl	ax, 3 ; i*nbcols*8
  4172                              <1>  	; dest=addr+i*nbcols*8;
  4173 000027E5 01C7                <1> 	add	edi, eax ; dest + j ; j = 0
  4174 000027E7 B180                <1> 	mov	cl, 80h ; mask = 0x80;
  4175                              <1> 	; esi = fdata + src + i
  4176                              <1> 	; for(j=0;j<8;j++)
  4177 000027E9 29D2                <1> 	sub	edx, edx ; j = 0
  4178                              <1> wgfxl_3:
  4179 000027EB 8A06                <1> 	mov	al, [esi] ; al = fdata[src+i]
  4180 000027ED 20C8                <1> 	and	al, cl ; if (fdata[src+i] & mask)
  4181 000027EF 7402                <1> 	jz	short wgfxl_4  ; data = 0, zf = 1
  4182 000027F1 88D8                <1> 	mov	al, bl ; data = attr;
  4183                              <1> wgfxl_4:
  4184                              <1> 	; write_byte(0xa000,dest+j,data);		
  4185 000027F3 AA                  <1> 	stosb  ; dest + j (+ 0A0000h)
  4186                              <1> 	;inc	dl ; j++
  4187                              <1> 	;cmp	dl, 8
  4188 000027F4 80FA07              <1> 	cmp	dl, 7
  4189 000027F7 720E                <1> 	jb	short wgfxl_5
  4190 000027F9 5F                  <1> 	pop	edi
  4191                              <1> 	; 08/08/2016
  4192                              <1> 	;cmp	bh, 7
  4193                              <1> 	;jnb	short wgfxl_6
  4194 000027FA FEC7                <1> 	inc	bh ; i++
  4195 000027FC 3A3D[F65E0000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  4196 00002802 7309                <1> 	jnb	short wgfxl_6
  4197 00002804 46                  <1> 	inc	esi
  4198 00002805 EBD0                <1> 	jmp	short wgfxl_2
  4199                              <1> wgfxl_5:
  4200 00002807 D0E9                <1> 	shr	cl, 1 ; mask >>= 1;
  4201 00002809 FEC2                <1> 	inc	dl ; j++
  4202 0000280B EBDE                <1>         jmp     short wgfxl_3
  4203                              <1> wgfxl_6:
  4204 0000280D 58                  <1> 	pop	eax
  4205 0000280E 5A                  <1> 	pop	edx
  4206 0000280F 5B                  <1> 	pop	ebx
  4207 00002810 59                  <1> 	pop	ecx
  4208 00002811 C3                  <1> 	retn
  4209                              <1> 
  4210                              <1> write_gfx_char_pl4:
  4211                              <1> 	; 08/08/2016
  4212                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  4213                              <1> 	;
  4214                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4215                              <1> 	; vgabios-0.7a (2011)
  4216                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4217                              <1> 	; 'vgabios.c', 'write_gfx_char_pl4'
  4218                              <1> 
  4219                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight)
  4220                              <1> 	; INPUT ->
  4221                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  4222                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  4223                              <1> 	; OUTPUT ->
  4224                              <1> 	; Regen buffer updated
  4225                              <1> 
  4226 00002812 51                  <1> 	push	ecx
  4227 00002813 53                  <1> 	push	ebx
  4228 00002814 52                  <1> 	push	edx
  4229 00002815 50                  <1> 	push	eax
  4230                              <1> wgfxpl_f0:
  4231                              <1> 	; switch(cheight)
  4232 00002816 8A25[F65E0000]      <1> 	mov	ah, [CHAR_HEIGHT]
  4233 0000281C 80FC10              <1> 	cmp	ah, 16 ; case 16:
  4234 0000281F 7507                <1> 	jne	short wgfxpl_f1
  4235                              <1> 	; fdata = &vgafont16;
  4236 00002821 BE[24430100]        <1> 	mov	esi, vgafont16
  4237 00002826 EB13                <1> 	jmp	short wgfxpl_f3
  4238                              <1> wgfxpl_f1:
  4239 00002828 80FC0E              <1> 	cmp	ah, 14 ; case 14:
  4240 0000282B 7507                <1> 	jne	short wgfxpl_f2
  4241 0000282D BE[24350100]        <1> 	mov	esi, vgafont14
  4242 00002832 EB07                <1> 	jmp	short wgfxpl_f3
  4243                              <1> wgfxpl_f2:
  4244                              <1> 	; default:
  4245                              <1> 	;  fdata = &vgafont8;
  4246 00002834 BE[242D0100]        <1> 	mov	esi, vgafont8
  4247 00002839 B408                <1> 	mov	ah, 8	
  4248                              <1> wgfxpl_f3:
  4249                              <1> 	; al = car
  4250 0000283B F6E4                <1> 	mul	ah ; ah = cheight
  4251 0000283D 25FFFF0000          <1> 	and	eax, 0FFFFh ; car * cheight
  4252                              <1> 	; src = car * cheight;
  4253 00002842 01C6                <1> 	add	esi, eax ; esi = fdata[src+i]
  4254                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  4255 00002844 88F0                <1> 	mov	al, dh ; ycurs
  4256 00002846 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  4257 0000284C F6E4                <1> 	mul	ah
  4258                              <1> 	; 08/08/2016
  4259                              <1> 	;shl	ax, 6 ; * 64
  4260 0000284E 66C1E003            <1> 	shl	ax, 3 ; * 8
  4261                              <1> 	;sub	dh, dh ; 0
  4262                              <1> 	;shl	dx, 3 ; xcurs * 8
  4263                              <1> 	;movzx	edi, dx
  4264 00002852 0FB6FA              <1> 	movzx	edi, dl
  4265 00002855 66C1E703            <1> 	shl	di, 3 ; xcurs * 8
  4266 00002859 30F6                <1> 	xor	dh, dh
  4267 0000285B 8A15[F65E0000]      <1> 	mov	dl, [CHAR_HEIGHT]
  4268 00002861 66F7E2              <1> 	mul	dx
  4269                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  4270 00002864 01C7                <1> 	add	edi, eax ; addr
  4271 00002866 81C700000A00        <1> 	add	edi, 0A0000h
  4272                              <1> 	;
  4273                              <1> 	; outw(VGAREG_SEQU_ADDRESS, 0x0f02);
  4274                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  4275 0000286C 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4276 00002870 66B8020F            <1> 	mov	ax, 0F02h
  4277 00002874 66EF                <1> 	out	dx, ax
  4278 00002876 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4279 0000287A 66B80502            <1> 	mov	ax, 0205h
  4280 0000287E 66EF                <1> 	out	dx, ax
  4281                              <1> 	;
  4282 00002880 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4283 00002884 F6C380              <1> 	test	bl, 80h ; if(attr&0x80)
  4284 00002887 7406                <1> 	jz	short wgfxpl_f4 ; else
  4285                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x1803);
  4286 00002889 66B80318            <1> 	mov	ax, 1803h
  4287 0000288D EB04                <1> 	jmp	short wgfxpl_f5
  4288                              <1> wgfxpl_f4:
  4289                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0003);
  4290 0000288F 66B80300            <1> 	mov	ax, 0003h	
  4291                              <1> wgfxpl_f5:
  4292 00002893 66EF                <1> 	out	dx, ax
  4293                              <1> 	;	
  4294 00002895 28FF                <1> 	sub	bh, bh ; i = 0
  4295                              <1> wgfxpl_0:
  4296                              <1> 	; for(i=0;i<cheight;i++)
  4297 00002897 57                  <1> 	push	edi ; addr
  4298 00002898 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  4299 0000289F F6E7                <1> 	mul	bh ; nbcols*i
  4300                              <1> 	; dest=addr+i*nbcols
  4301 000028A1 01C7                <1> 	add	edi, eax ; dest
  4302 000028A3 B580                <1> 	mov	ch, 80h ; mask = 0x80;
  4303                              <1> 	; for(j=0;j<8;j++)
  4304 000028A5 28C9                <1> 	sub	cl, cl ; j = 0
  4305                              <1> wgfxpl_1:
  4306 000028A7 D2ED                <1> 	shr	ch, cl ; mask=0x80>>j;
  4307                              <1> 	;
  4308                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  4309                              <1>      	; read_byte(0xa000,dest);
  4310                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4311 000028A9 88EC                <1> 	mov	ah, ch
  4312 000028AB B008                <1> 	mov	al, 8
  4313 000028AD 66EF                <1> 	out	dx, ax
  4314 000028AF 8A07                <1> 	mov	al, [edi] ; ? (io delay?)
  4315                              <1> 	;
  4316 000028B1 28C0                <1> 	sub	al, al ; attr = 0
  4317                              <1> 	; if (fdata[src+i] & mask)
  4318 000028B3 842E                <1> 	test	byte [esi], ch
  4319 000028B5 7404                <1> 	jz	short wgfxpl_2  ; zf = 1
  4320                              <1> 	; write_byte(0xa000,dest,attr&0x0f);
  4321 000028B7 88D8                <1> 	mov	al, bl ; attr;
  4322 000028B9 240F                <1> 	and	al, 0Fh	; attr&0x0f
  4323                              <1> wgfxpl_2:
  4324                              <1> 	; write_byte(0xa000,dest,0x00);		
  4325 000028BB 8807                <1> 	mov	[edi], al ; dest (+ 0A0000h)
  4326 000028BD FEC1                <1> 	inc	cl ; j++
  4327 000028BF 80F908              <1> 	cmp	cl, 8
  4328 000028C2 72E3                <1> 	jb	short wgfxpl_1
  4329 000028C4 5F                  <1> 	pop	edi
  4330                              <1> 	; 08/08/2016
  4331                              <1> 	;cmp	bh, 7
  4332                              <1> 	;jnb	short wgfxpl_3
  4333 000028C5 FEC7                <1> 	inc	bh ; i++
  4334 000028C7 3A3D[F65E0000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  4335 000028CD 7303                <1> 	jnb	short wgfxpl_3
  4336 000028CF 46                  <1> 	inc	esi
  4337 000028D0 EBC5                <1> 	jmp	short wgfxpl_0
  4338                              <1> wgfxpl_3:
  4339                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4340 000028D2 66B808FF            <1>   	mov	ax, 0FF08h
  4341 000028D6 66EF                <1> 	out	dx, ax
  4342 000028D8 66B80500            <1> 	mov	ax, 0005h
  4343 000028DC 66EF                <1> 	out	dx, ax
  4344 000028DE 66B80300            <1> 	mov	ax, 0003h
  4345 000028E2 66EF                <1> 	out	dx, ax
  4346                              <1> 	;
  4347 000028E4 58                  <1> 	pop	eax
  4348 000028E5 5A                  <1> 	pop	edx
  4349 000028E6 5B                  <1> 	pop	ebx
  4350 000028E7 59                  <1> 	pop	ecx
  4351 000028E8 C3                  <1> 	retn
  4352                              <1> 
  4353                              <1> vga_write_pixel: 
  4354                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4355                              <1> 	;
  4356                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4357                              <1> 	; vgabios-0.7a (2011)
  4358                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4359                              <1> 	; 'vgabios.c', 'biosfn_write_pixel'
  4360                              <1> 
  4361                              <1> 	; INPUT ->
  4362                              <1> 	; 	DX = row (0-239)
  4363                              <1> 	; 	CX = column (0-799)
  4364                              <1> 	; 	AL = pixel value
  4365                              <1> 	;	(AH = [CRT_MODE])
  4366                              <1> 	; OUTPUT ->
  4367                              <1> 	; 	none
  4368                              <1>  
  4369 000028E9 88C3                <1> 	mov	bl, al ; pixel value
  4370                              <1> 	;mov 	ah, [CRT_MODE]
  4371 000028EB BE[0E5F0000]        <1> 	mov	esi, vga_modes
  4372 000028F0 89F7                <1> 	mov	edi, esi
  4373 000028F2 83C710              <1> 	add	edi, vga_mode_count
  4374                              <1> vga_wp_0:
  4375 000028F5 AC                  <1> 	lodsb
  4376 000028F6 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4377 000028F8 7405                <1> 	je	short vga_wp_1
  4378 000028FA 39FE                <1> 	cmp	esi, edi
  4379 000028FC 72F7                <1> 	jb	short vga_wp_0
  4380 000028FE C3                  <1> 	retn	; nothing to do
  4381                              <1> vga_wp_1:
  4382 000028FF 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  4383                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4384 00002902 BF00000A00          <1> 	mov	edi, 0A0000h
  4385                              <1> 	;
  4386 00002907 803E04              <1> 	cmp	byte [esi], PLANAR4
  4387 0000290A 741D                <1> 	je	short vga_wp_planar
  4388 0000290C 803E03              <1> 	cmp	byte [esi], PLANAR1
  4389 0000290F 7418                <1> 	je	short vga_wp_planar
  4390                              <1> vga_wp_linear8:
  4391                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  4392 00002911 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4393 00002918 66C1E003            <1>      	shl	ax, 3 ; * 8
  4394 0000291C 66F7E2              <1> 	mul	dx
  4395 0000291F 50                  <1> 	push	eax
  4396                              <1> 	;mov	edi, 0A0000h
  4397 00002920 6601CF              <1> 	add	di, cx
  4398 00002923 58                  <1> 	pop	eax
  4399 00002924 01C7                <1> 	add	edi, eax ; addr
  4400                              <1> 	; write_byte(0xa000,addr,AL);
  4401 00002926 881F                <1> 	mov	[edi], bl
  4402 00002928 C3                  <1> 	retn    
  4403                              <1> vga_wp_planar:
  4404                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  4405 00002929 0FB7C1              <1> 	movzx	eax, cx
  4406 0000292C 66C1E803            <1> 	shr	ax, 3 ; CX/8
  4407 00002930 50                  <1> 	push	eax
  4408 00002931 28E4                <1> 	sub	ah, ah ; 0
  4409 00002933 A0[F45E0000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4410 00002938 66F7E2              <1> 	mul	dx
  4411                              <1> 	;mov	edi, 0A0000h
  4412 0000293B 6601C7              <1>         add     di, ax
  4413 0000293E 58                  <1> 	pop	eax
  4414 0000293F 01C7                <1> 	add	edi, eax ; addr
  4415 00002941 80E107              <1> 	and	cl, 7
  4416 00002944 B580                <1> 	mov	ch, 80h ; mask
  4417 00002946 D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  4418                              <1> 	
  4419                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  4420 00002948 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4421 0000294C 88EC                <1> 	mov	ah, ch
  4422 0000294E B008                <1> 	mov	al, 8
  4423 00002950 66EF                <1> 	out	dx, ax
  4424                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  4425 00002952 66B80502            <1> 	mov	ax, 0205h
  4426 00002956 66EF                <1> 	out	dx, ax
  4427                              <1> 	; data = read_byte(0xa000,addr);
  4428 00002958 8A07                <1> 	mov	al, [edi] ; (delay?)	
  4429                              <1> 	; if (AL & 0x80)
  4430                              <1> 	; {
  4431                              <1> 	;  outw(VGAREG_GRDC_ADDRESS, 0x1803);
  4432                              <1> 	; }
  4433 0000295A F6C380              <1> 	test	bl, 80h
  4434 0000295D 7406                <1> 	jz	short vga_wp_2
  4435 0000295F 66B80318            <1> 	mov	ax, 1803h
  4436 00002963 66EF                <1> 	out	dx, ax
  4437                              <1> vga_wp_2:	
  4438                              <1> 	; write_byte(0xa000,addr,AL);
  4439 00002965 881F                <1> 	mov	[edi], bl
  4440                              <1> 	;
  4441                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4442 00002967 66B808FF            <1>   	mov	ax, 0FF08h
  4443 0000296B 66EF                <1> 	out	dx, ax
  4444 0000296D 66B80500            <1> 	mov	ax, 0005h
  4445 00002971 66EF                <1> 	out	dx, ax
  4446 00002973 66B80300            <1> 	mov	ax, 0003h
  4447 00002977 66EF                <1> 	out	dx, ax
  4448                              <1> 	;
  4449 00002979 C3                  <1> 	retn
  4450                              <1> 
  4451                              <1> vga_read_pixel: 
  4452                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4453                              <1> 	;
  4454                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4455                              <1> 	; vgabios-0.7a (2011)
  4456                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4457                              <1> 	; 'vgabios.c', 'biosfn_read_pixel'
  4458                              <1> 
  4459                              <1> 	; INPUT ->
  4460                              <1> 	; 	DX = row (0-239)
  4461                              <1> 	; 	CX = column (0-799)
  4462                              <1> 	;	(AH = [CRT_MODE])
  4463                              <1> 	; OUTPUT ->
  4464                              <1> 	; 	AL = pixel value
  4465                              <1> 	 
  4466                              <1> 	;mov 	ah, [CRT_MODE]
  4467 0000297A BE[0E5F0000]        <1> 	mov	esi, vga_modes
  4468 0000297F 89F7                <1> 	mov	edi, esi
  4469 00002981 83C710              <1> 	add	edi, vga_mode_count
  4470                              <1> vga_rp_0:
  4471 00002984 AC                  <1> 	lodsb
  4472 00002985 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4473 00002987 7405                <1> 	je	short vga_rp_1
  4474 00002989 39FE                <1> 	cmp	esi, edi
  4475 0000298B 72F7                <1> 	jb	short vga_rp_0
  4476 0000298D C3                  <1> 	retn	; nothing to do
  4477                              <1> vga_rp_1:
  4478 0000298E 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  4479                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4480 00002991 BF00000A00          <1> 	mov	edi, 0A0000h
  4481                              <1> 	;
  4482 00002996 803E04              <1> 	cmp	byte [esi], PLANAR4
  4483 00002999 741D                <1> 	je	short vga_rp_planar
  4484 0000299B 803E03              <1> 	cmp	byte [esi], PLANAR1
  4485 0000299E 7418                <1> 	je	short vga_rp_planar
  4486                              <1> vga_rp_linear8:
  4487                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  4488 000029A0 0FB605[F45E0000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4489 000029A7 66C1E003            <1>      	shl	ax, 3 ; * 8
  4490 000029AB 66F7E2              <1> 	mul	dx
  4491 000029AE 50                  <1> 	push	eax
  4492                              <1> 	;mov	edi, 0A0000h
  4493 000029AF 6601CF              <1> 	add	di, cx
  4494 000029B2 58                  <1> 	pop	eax
  4495 000029B3 01C7                <1> 	add	edi, eax ; addr
  4496                              <1> 	; attr=read_byte(0xa000,addr);
  4497 000029B5 8A07                <1> 	mov	al, [edi] ; pixel value
  4498 000029B7 C3                  <1> 	retn    
  4499                              <1> vga_rp_planar:
  4500                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  4501 000029B8 0FB7C1              <1> 	movzx	eax, cx
  4502 000029BB 66C1E803            <1> 	shr	ax, 3 ; CX/8
  4503 000029BF 50                  <1> 	push	eax
  4504 000029C0 28E4                <1> 	sub	ah, ah ; 0
  4505 000029C2 A0[F45E0000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  4506 000029C7 66F7E2              <1> 	mul	dx
  4507                              <1> 	;mov	edi, 0A0000h
  4508 000029CA 6601C7              <1>         add     di, ax
  4509 000029CD 58                  <1> 	pop	eax
  4510 000029CE 01C7                <1> 	add	edi, eax ; addr
  4511 000029D0 80E107              <1> 	and	cl, 7
  4512 000029D3 B580                <1> 	mov	ch, 80h ; mask
  4513 000029D5 D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  4514                              <1> 	; attr = 0x00;
  4515 000029D7 30DB                <1> 	xor	bl, bl ; attr = bl = 0, 
  4516 000029D9 30C9                <1> 	xor	cl, cl ; i = cl = 0
  4517                              <1> 	; for(i=0;i<4;i++)
  4518                              <1>       	; {
  4519                              <1>        	;  outw(VGAREG_GRDC_ADDRESS, (i << 8) | 0x04);
  4520                              <1>        	;  data = read_byte(0xa000,addr) & mask;
  4521                              <1>        	;  if (data > 0) attr |= (0x01 << i);
  4522                              <1>       	; }
  4523                              <1> vga_rp_2:
  4524 000029DB 88CC                <1> 	mov	ah, cl ; i << 8
  4525 000029DD B004                <1> 	mov	al, 4  ; | 0x04
  4526 000029DF 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4527 000029E3 66EF                <1> 	out	dx, ax
  4528                              <1> 	; data = read_byte(0xa000,addr) & mask;
  4529 000029E5 8A07                <1> 	mov	al, [edi]
  4530 000029E7 20E8                <1> 	and	al, ch ; & mask
  4531                              <1> 	; if (data > 0) attr |= (0x01 << i);
  4532 000029E9 08C0                <1> 	or	al, al
  4533 000029EB 7408                <1> 	jz	short vga_rp_3 ; al = 0 
  4534 000029ED B701                <1> 	mov	bh, 1
  4535 000029EF D2E7                <1> 	shl	bh, cl ; (0x01 << i)
  4536 000029F1 08FB                <1> 	or	bl, bh ; attr |= (0x01 << i)
  4537 000029F3 88D8                <1> 	mov	al, bl ; pixel value	
  4538                              <1> vga_rp_3:	
  4539 000029F5 C3                  <1> 	retn
  4540                              <1> 
  4541                              <1> vga_beeper:
  4542                              <1> 	; 04/08/2016  (TRDOS 386 = TRDOS v2.0)
  4543 000029F6 FB                  <1> 	sti
  4544                              <1> 	;mov	bh, [ACTIVE_PAGE]
  4545 000029F7 E9CFF3FFFF          <1>         jmp     beeper_gfx
  4546                              <1> 
  4547                              <1> vga_write_teletype:
  4548                              <1> 	; 09/12/2017
  4549                              <1> 	; 06/08/2016
  4550                              <1> 	; 04/08/2016
  4551                              <1> 	; 01/08/2016
  4552                              <1> 	; 31/07/2016
  4553                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  4554                              <1> 	;
  4555                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4556                              <1> 	; vgabios-0.7a (2011)
  4557                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4558                              <1> 	; 'vgabios.c', 'biosfn_write_teletype'
  4559                              <1> 	; 'biosfn_write_char_only'
  4560                              <1> 
  4561                              <1> 	; INPUT ->
  4562                              <1> 	; [CRT_MODE] = current video mode (>7)
  4563                              <1> 	; AL = Character to write
  4564                              <1> 	; BL = Color of character
  4565                              <1> 	; OUTPUT ->
  4566                              <1> 	; Regen buffer updated
  4567                              <1> 
  4568                              <1> 	; biosfn_write_teletype (car, page, attr, flag) 
  4569                              <1> 	; car = character (AL)
  4570                              <1> 	; page = 0
  4571                              <1> 	; attr = color (BL)
  4572                              <1> 	; 'flag' not used
  4573                              <1> 
  4574 000029FC 8A25[F25E0000]      <1> 	mov 	ah, [CRT_MODE]
  4575 00002A02 88C7                <1> 	mov	bh, al ; character
  4576 00002A04 668B15[C6580100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  4577                              <1> 
  4578 00002A0B BE[165F0000]        <1> 	mov	esi, vga_g_modes
  4579 00002A10 89F7                <1> 	mov	edi, esi
  4580 00002A12 83C708              <1> 	add	edi, vga_g_mode_count
  4581                              <1> vga_wtty_0:
  4582 00002A15 AC                  <1> 	lodsb
  4583 00002A16 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4584 00002A18 7405                <1> 	je	short vga_wtty_2
  4585 00002A1A 39FE                <1> 	cmp	esi, edi
  4586 00002A1C 72F7                <1> 	jb	short vga_wtty_0
  4587                              <1> vga_wtty_1:
  4588 00002A1E C3                  <1> 	retn	; nothing to do
  4589                              <1> vga_wtty_2:
  4590 00002A1F 80FF07              <1> 	cmp	bh, 07h ; bell (beep)
  4591 00002A22 74D2                <1> 	je	short vga_beeper  ; u11
  4592 00002A24 80FF08              <1> 	cmp	bh, 08h ; backspace
  4593 00002A27 7508                <1> 	jne	short vga_wtty_3
  4594                              <1> 	; if(xcurs>0)xcurs--;
  4595 00002A29 08D2                <1> 	or	dl, dl ; xcurs (column)
  4596 00002A2B 74F1                <1> 	jz	short vga_wtty_1
  4597 00002A2D FECA                <1> 	dec	dl ; xcurs--;
  4598 00002A2F EB59                <1>         jmp     short vga_wtty_12 
  4599                              <1> vga_wtty_3:			
  4600 00002A31 80FF0D              <1> 	cmp	bh, 0Dh ; carriage return (\r)
  4601 00002A34 7504                <1> 	jne	short vga_wtty_4
  4602                              <1> 	; xcurs=0;
  4603 00002A36 28D2                <1> 	sub	dl, dl ; 0
  4604 00002A38 EB50                <1>         jmp     short vga_wtty_12 
  4605                              <1> vga_wtty_4:	
  4606 00002A3A 80FF0A              <1> 	cmp	bh, 0Ah ; new line (\n)
  4607 00002A3D 7504                <1> 	jne	short vga_wtty_5
  4608                              <1> 	; ycurs++;
  4609 00002A3F FEC6                <1> 	inc	dh ; next row
  4610 00002A41 EB62                <1>         jmp     short vga_wtty_11
  4611                              <1> vga_wtty_5:
  4612 00002A43 80FF09              <1> 	cmp 	bh, 09h ; tab stop
  4613 00002A46 7527                <1> 	jne	short vga_wtty_8
  4614 00002A48 88D0                <1> 	mov	al, dl
  4615                              <1> 	;cbw
  4616 00002A4A 30E4                <1> 	xor	ah, ah ; 09/12/2017
  4617 00002A4C B108                <1> 	mov	cl, 8
  4618 00002A4E F6F1                <1> 	div	cl
  4619 00002A50 28E1                <1> 	sub	cl, ah
  4620                              <1> 	;
  4621 00002A52 B720                <1> 	mov	bh, 20h ; space
  4622                              <1> vga_wtty_6: ; tab stop loop
  4623 00002A54 6651                <1> 	push	cx
  4624 00002A56 6653                <1> 	push	bx
  4625 00002A58 E812000000          <1> 	call	vga_wtty_8
  4626 00002A5D 665B                <1> 	pop	bx  ; bh = character, bl = color
  4627 00002A5F 6659                <1> 	pop	cx
  4628 00002A61 FEC9                <1> 	dec	cl
  4629 00002A63 7409                <1> 	jz	short vga_wtty_7
  4630 00002A65 668B15[C6580100]    <1> 	mov	dx, [CURSOR_POSN] ; new cursor position (pg 0)
  4631 00002A6C EBE6                <1> 	jmp	short vga_wtty_6
  4632                              <1> vga_wtty_7:
  4633 00002A6E C3                  <1> 	retn
  4634                              <1> 	;
  4635                              <1> vga_wtty_8:
  4636 00002A6F 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  4637                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4638 00002A72 BF00000A00          <1> 	mov	edi, 0A0000h
  4639                              <1> 	;
  4640 00002A77 88F8                <1> 	mov	al, bh ; character
  4641                              <1> 	;
  4642 00002A79 803E04              <1> 	cmp	byte [esi], PLANAR4
  4643 00002A7C 7414                <1> 	je	short vga_wtty_planar
  4644 00002A7E 803E03              <1> 	cmp	byte [esi], PLANAR1
  4645 00002A81 740F                <1> 	je	short vga_wtty_planar
  4646                              <1> vga_wtty_linear8:
  4647                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  4648                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  4649                              <1> 	; [CRT_COLS] = nbcols
  4650 00002A83 E8F3FCFFFF          <1> 	call	write_gfx_char_lin
  4651 00002A88 EB0D                <1> 	jmp	short vga_wtty_9
  4652                              <1> 
  4653                              <1> vga_wtty_12:
  4654                              <1> 	; 09/07/2016
  4655                              <1> 	; set cursor position
  4656                              <1> 	; NOTE: Hardware cursor position will not be set
  4657                              <1> 	;   in any VGA modes (>7)
  4658                              <1> 	;   But, cursor position will be saved into
  4659                              <1> 	;   [CURSOR_POSN].
  4660                              <1> 	;   TRDOS 386 (TRDOS v2.0) uses only one page
  4661                              <1> 	;   (page 0) for all graphics modes.
  4662                              <1> 
  4663 00002A8A 668915[C6580100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  4664                              <1> 	; 04/08/2016
  4665                              <1> 	;mov	bh, [ACTIVE_PAGE] ; = 0
  4666                              <1> 	;call	_set_cpos
  4667 00002A91 C3                  <1> 	retn
  4668                              <1> 
  4669                              <1> vga_wtty_planar:
  4670                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  4671                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  4672                              <1> 	; [CRT_COLS]= nbcols, [CHAR_HEIGHT] = cheight
  4673 00002A92 E87BFDFFFF          <1> 	call	write_gfx_char_pl4
  4674                              <1> vga_wtty_9:
  4675 00002A97 FEC2                <1> 	inc	dl ; xcurs++;
  4676                              <1> vga_wtty_10:
  4677                              <1> 	; Do we need to wrap ?
  4678                              <1> 	; if(xcurs==nbcols)
  4679 00002A99 3A15[F45E0000]      <1> 	cmp	dl, [CRT_COLS] ; [VGA_COLS]
  4680 00002A9F 7204                <1> 	jb	short vga_wtty_11 ; no
  4681 00002AA1 28D2                <1> 	sub	dl, dl ; xcurs=0;
  4682 00002AA3 FEC6                <1> 	inc	dh ;  ycurs++;
  4683                              <1> vga_wtty_11:
  4684                              <1> 	; Do we need to scroll ?
  4685                              <1> 	; if(ycurs==nbrows)
  4686 00002AA5 3A35[FA5E0000]      <1> 	cmp	dh, [VGA_ROWS]
  4687 00002AAB 72DD                <1> 	jb	short vga_wtty_12 ; no
  4688                              <1> 	;
  4689                              <1> 	; biosfn_scroll (nblines,attr,rul,cul,rlr,clr,page,dir)
  4690                              <1> 	; al = nblines = 1, bl = attr (color) = 0
  4691                              <1> 	; ch = rul, cl = cul, dh = rlr, dl = clr, page = 0
  4692                              <1> 	; dir = SCROLL_UP
  4693                              <1> 	
  4694 00002AAD B001                <1> 	mov	al, 1
  4695 00002AAF 28DB                <1> 	sub	bl, bl ; 0 ; blank/black line (attr=0) will be used
  4696 00002AB1 6629C9              <1> 	sub	cx, cx ; 0,0
  4697                              <1> 
  4698                              <1> 	; 06/08/2016
  4699 00002AB4 8A35[FA5E0000]      <1> 	mov	dh, [VGA_ROWS]
  4700 00002ABA FECE                <1> 	dec	dh ; nbrows -1
  4701                              <1> 
  4702 00002ABC 6652                <1> 	push	dx 	; 04/08/2016
  4703 00002ABE 8A15[F45E0000]      <1> 	mov	dl, [CRT_COLS]
  4704 00002AC4 FECA                <1> 	dec	dl ; nbcols -1
  4705                              <1> 	
  4706 00002AC6 8A25[F25E0000]      <1> 	mov	ah, [CRT_MODE]
  4707                              <1> 	
  4708                              <1> 	; biosfn_scroll(0x01,0x00,0,0,nbrows-1,nbcols-1,page,SCROLL_UP);
  4709 00002ACC E808F5FFFF          <1> 	call	vga_graphics_up
  4710                              <1> 	; 04/08/2016
  4711 00002AD1 665A                <1> 	pop	dx
  4712                              <1> 	;dec	dh ; ycurs-=1
  4713 00002AD3 EBB5                <1> 	jmp	short vga_wtty_12 
  4714                              <1> 
  4715                              <1> font_setup:
  4716                              <1> 	; 09/07/2016
  4717                              <1> 	; character generator (font loading) functions
  4718                              <1> 	;
  4719                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4720                              <1> 	; vgabios-0.7a (2011)
  4721                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4722                              <1> 	; 'vgabios.c', 'int10_func'
  4723                              <1> 
  4724                              <1> 	; AX = 1100H ; Load User-Defined Font (EGA/VGA)
  4725                              <1> 	;
  4726                              <1>         ; BH    height of each character (bytes per character definition)
  4727                              <1>         ; (BL   font block to load (EGA: 0-3; VGA: 0-7))
  4728                              <1> 	; CX    number of characters to redefine (<=256)
  4729                              <1>         ; DX    ASCII code of the first character defined at ES:BP
  4730                              <1>         ; EBP	address of font-definition information
  4731                              <1> 	;	(in user's memory space)
  4732                              <1> 
  4733                              <1> 	; case 0x11:
  4734                              <1>      	; switch(GET_AL())
  4735                              <1>       	; {
  4736                              <1> 	; case 0x00:
  4737                              <1>         ; case 0x10:
  4738                              <1>         ; biosfn_load_text_user_pat(GET_AL(),ES,BP,CX,DX,GET_BL(),GET_BH());
  4739                              <1>         ; break;
  4740                              <1> 
  4741                              <1> 	; AX = 1110H ; Load and Activate User-Defined Font (EGA/VGA)
  4742 00002AD5 08C0                <1> 	or	al, al ; 0
  4743 00002AD7 7404                <1> 	jz	short font_setup_0
  4744 00002AD9 3C10                <1> 	cmp	al, 10h
  4745 00002ADB 7511                <1> 	jne	short font_setup_1	
  4746                              <1> font_setup_0:
  4747 00002ADD E8B7000000          <1> 	call	transfer_user_fonts
  4748 00002AE2 721C                <1> 	jc	short font_setup_error
  4749 00002AE4 E8C2000000          <1> 	call	load_text_user_pat
  4750 00002AE9 E996EAFFFF          <1>         jmp     VIDEO_RETURN 
  4751                              <1> font_setup_1:
  4752                              <1> 	; AX = 1101H ; Load ROM 8x14 Character Set (EGA/VGA)
  4753                              <1> 	; case 0x01:
  4754                              <1>         ; case 0x11:
  4755                              <1>         ; biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
  4756                              <1>         ; break;
  4757 00002AEE 3C01                <1> 	cmp	al, 1
  4758 00002AF0 7404                <1> 	je	short font_setup_2
  4759 00002AF2 3C11                <1> 	cmp	al, 11h
  4760 00002AF4 7511                <1> 	jne	short font_setup_3	
  4761                              <1> font_setup_2:
  4762                              <1> 	; AX = 1111H ; Load and Activate ROM 8x14 Character Set (EGA/VGA)
  4763                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4764 00002AF6 E8EE010000          <1> 	call	load_text_8_14_pat
  4765 00002AFB E984EAFFFF          <1>         jmp     VIDEO_RETURN
  4766                              <1> font_setup_error:
  4767 00002B00 29C0                <1> 	sub	eax, eax ; 0 -> fonts could not be loaded
  4768 00002B02 E982EAFFFF          <1> 	jmp	_video_return
  4769                              <1> font_setup_3:
  4770                              <1> 	; AX = 1102H ; Load ROM 8x8 Character Set (EGA/VGA)
  4771                              <1> 	; case 0x02:
  4772                              <1>         ; case 0x12:
  4773                              <1>         ; biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
  4774                              <1>         ; break;
  4775 00002B07 3C02                <1> 	cmp	al, 2
  4776 00002B09 7404                <1> 	je	short font_setup_4
  4777 00002B0B 3C12                <1> 	cmp	al, 12h
  4778 00002B0D 750A                <1> 	jne	short font_setup_5	
  4779                              <1> font_setup_4:
  4780                              <1> 	; AX = 1112H ; Load and Activate ROM 8x8 Character Set (EGA/VGA)
  4781                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4782 00002B0F E805020000          <1> 	call	load_text_8_8_pat
  4783 00002B14 E96BEAFFFF          <1>         jmp     VIDEO_RETURN
  4784                              <1> font_setup_5:
  4785                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set (EGA/VGA)
  4786                              <1> 	; case 0x04:
  4787                              <1>         ; case 0x14:
  4788                              <1>         ; biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
  4789                              <1>         ; break;
  4790 00002B19 3C04                <1> 	cmp	al, 4
  4791 00002B1B 7404                <1> 	je	short font_setup_6
  4792 00002B1D 3C14                <1> 	cmp	al, 14h
  4793 00002B1F 750A                <1> 	jne	short font_setup_7	
  4794                              <1> font_setup_6:
  4795                              <1> 	; AX = 1114H ; Load and Activate ROM 8x16 Character Set (EGA/VGA)
  4796                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  4797 00002B21 E823020000          <1> 	call	load_text_8_16_pat
  4798 00002B26 E959EAFFFF          <1>         jmp     VIDEO_RETURN
  4799                              <1> font_setup_7:
  4800                              <1> 	; Note: AX=1120h (Setup INT 1Fh, EXT_PTR) is not needed
  4801                              <1> 	; for TRDOS 386 (TRDIOS v2.0) video functionality;
  4802                              <1> 	; because, originally EXT_PTR (font address) was used for
  4803                              <1> 	; chars 80h to 0FFh (after the first 128 ASCII char fonts), for
  4804                              <1> 	; CGA graphics mode; currenty, 'vgafont8' address has 256 chars!
  4805                              <1> 	; 
  4806                              <1> 	; case 0x20:
  4807                              <1>         ; biosfn_load_gfx_8_8_chars(ES,BP);
  4808                              <1>         ; break; 
  4809                              <1> 	; case 0x21:
  4810                              <1>         ; biosfn_load_gfx_user_chars(ES,BP,CX,GET_BL(),GET_DL());
  4811                              <1>         ; break;
  4812                              <1> 	; AX = 1121H ; Setup User-Defined Font for Graphics Mode (VGA)
  4813                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  4814                              <1>         ;                        01H = 14 rows
  4815                              <1>         ;                        02H = 25 rows
  4816                              <1>         ;                        03H = 43 rows
  4817                              <1>         ; CX   bytes per character definition
  4818                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  4819                              <1>         ; EBP  address of font-definition information (user's mem space)
  4820                              <1> 
  4821 00002B2B 3C21                <1> 	cmp	al, 21h
  4822 00002B2D 751A                <1> 	jne	short font_setup_9
  4823                              <1> 
  4824                              <1> 	; TRDOS 386 modification !
  4825                              <1> 	; dh = 0 -> 256 characters
  4826                              <1> 	; dh = 80h -> 128 characters
  4827                              <1> 	; (If DH <> 0 and DH <> 80h -> invalid)     
  4828 00002B2F 20F6                <1> 	and	dh, dh
  4829 00002B31 7405                <1> 	jz	short font_setup_8 ; 256 characters
  4830 00002B33 80FE80              <1> 	cmp	dh, 80h ; 128 characters
  4831 00002B36 75C8                <1> 	jne	short font_setup_error ; invalid !
  4832                              <1> font_setup_8:
  4833 00002B38 E85C000000          <1> 	call	transfer_user_fonts
  4834 00002B3D 72C1                <1> 	jc	short font_setup_error
  4835                              <1> 	; ebp = user's font data address in system's memory space
  4836 00002B3F E836020000          <1> 	call	load_gfx_user_chars
  4837 00002B44 E93BEAFFFF          <1>         jmp     VIDEO_RETURN 
  4838                              <1> font_setup_9:
  4839                              <1> 	; case 0x22:
  4840                              <1>         ; biosfn_load_gfx_8_14_chars(GET_BL());
  4841                              <1>         ; break;
  4842 00002B49 3C22                <1> 	cmp	al, 22h
  4843 00002B4B 750A                <1> 	jne	short font_setup_10
  4844 00002B4D E866020000          <1> 	call	load_gfx_8_14_chars	
  4845 00002B52 E92DEAFFFF          <1>         jmp     VIDEO_RETURN 
  4846                              <1> font_setup_10:	
  4847                              <1> 	; case 0x23:
  4848                              <1>         ; biosfn_load_gfx_8_8_dd_chars(GET_BL());
  4849                              <1>         ; break;
  4850 00002B57 3C23                <1> 	cmp	al, 23h
  4851 00002B59 750A                <1> 	jne	short font_setup_11
  4852 00002B5B E899020000          <1> 	call	load_gfx_8_8_chars	
  4853 00002B60 E91FEAFFFF          <1>         jmp     VIDEO_RETURN 
  4854                              <1> font_setup_11:	
  4855                              <1> 	; case 0x24:
  4856                              <1>         ; biosfn_load_gfx_8_16_chars(GET_BL());
  4857                              <1>         ; break;
  4858 00002B65 3C24                <1> 	cmp	al, 24h
  4859 00002B67 750A                <1> 	jne	short font_setup_12
  4860 00002B69 E8CC020000          <1> 	call	load_gfx_8_16_chars	
  4861 00002B6E E911EAFFFF          <1>         jmp     VIDEO_RETURN 
  4862                              <1> font_setup_12:
  4863                              <1>  	; case 0x30:
  4864                              <1>         ; biosfn_get_font_info(GET_BH(),&ES,&BP,&CX,&DX);
  4865                              <1>         ; break;
  4866 00002B73 3C30                <1> 	cmp	al, 30h
  4867 00002B75 750A                <1> 	jne	short font_setup_13			
  4868 00002B77 E8FF020000          <1> 	call	get_font_info
  4869                              <1> 	; eax = return value (info: 4 bytes for 4 parms)
  4870                              <1> 	; eax = 0 -> invalid function (input)
  4871 00002B7C E908EAFFFF          <1>         jmp     _video_return
  4872                              <1> font_setup_13:
  4873 00002B81 3C03                <1> 	cmp	al, 03h ; AX = 1103h	
  4874 00002B83 750D                <1> 	jne	short font_setup_14
  4875                              <1> 	; biosfn_set_text_block_specifier:
  4876                              <1> 	; BL = font block selector code	
  4877                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
  4878                              <1> 	; (It is as BL = 0 for TRDOS 386)
  4879 00002B85 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4880                              <1> 	;mov	ah, bl
  4881 00002B89 28E4                <1> 	sub	ah, ah ; 0
  4882                              <1> 	;mov	al, 03h
  4883 00002B8B 66EF                <1> 	out	dx, ax
  4884 00002B8D E9F2E9FFFF          <1> 	jmp     VIDEO_RETURN 
  4885                              <1> 	
  4886                              <1> font_setup_14:
  4887 00002B92 29C0                <1> 	sub	eax, eax ; 0 = invalid function
  4888 00002B94 E9F0E9FFFF          <1>         jmp     _video_return
  4889                              <1> 
  4890                              <1> transfer_user_fonts:
  4891                              <1> 	; 09/07/2016
  4892                              <1> 	;and	ecx, 0FFFFh
  4893                              <1> 	; ECX = byte count
  4894                              <1> 	;push	ecx
  4895 00002B99 89EE                <1> 	mov	esi, ebp ; user buffer
  4896 00002B9B BF00000700          <1> 	mov	edi, Cluster_Buffer  ; system buffer
  4897 00002BA0 E879BC0000          <1> 	call	transfer_from_user_buffer
  4898                              <1> 	;pop	ecx
  4899                              <1> 	; ecx = transfer (byte) count = character count
  4900 00002BA5 BD00000700          <1> 	mov	ebp, Cluster_Buffer
  4901                              <1> 	; jc	VIDEO_RETURN -> failed
  4902 00002BAA C3                  <1> 	retn
  4903                              <1> 
  4904                              <1> load_text_user_pat:
  4905                              <1> 	; 26/07/2016
  4906                              <1> 	; 09/07/2016
  4907                              <1> 	; load user defined (EGA/VGA) text fonts
  4908                              <1> 	;
  4909                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4910                              <1> 	; vgabios-0.7a (2011)
  4911                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4912                              <1> 	; 'vgabios.c', 'biosfn_load_text_user_pat'
  4913                              <1> 
  4914                              <1> 	; biosfn_load_text_user_pat (AL,ES,BP,CX,DX,BL,BH)
  4915                              <1> 
  4916                              <1> 	; get_font_access();
  4917                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  4918                              <1> 	; for(i=0;i<CX;i++)
  4919                              <1> 	; {
  4920                              <1> 	;  src = BP + i * BH;
  4921                              <1> 	;  dest = blockaddr + (DX + i) * 32;
  4922                              <1> 	;  memcpyb(0xA000, dest, ES, src, BH);
  4923                              <1> 	; }
  4924                              <1> 	; release_font_access();
  4925                              <1> 	; if(AL>=0x10)
  4926                              <1> 	; {
  4927                              <1> 	; set_scan_lines(BH);
  4928                              <1> 	; }
  4929                              <1> 
  4930 00002BAB 50                  <1> 	push	eax
  4931 00002BAC E83C000000          <1> 	call	get_font_access
  4932 00002BB1 28DB                <1> 	sub	bl, bl ; i = 0	
  4933                              <1> ltup_1:
  4934 00002BB3 88D8                <1> 	mov	al, bl
  4935 00002BB5 F6E7                <1> 	mul	bh
  4936 00002BB7 0FB7F0              <1> 	movzx	esi, ax
  4937 00002BBA 01EE                <1> 	add	esi, ebp
  4938 00002BBC 88D8                <1> 	mov	al, bl
  4939 00002BBE 28E4                <1> 	sub	ah, ah
  4940 00002BC0 6601D0              <1> 	add	ax, dx ; (DX + i)
  4941 00002BC3 66C1E005            <1> 	shl	ax, 5  ; * 32
  4942 00002BC7 0FB7F8              <1> 	movzx	edi, ax
  4943 00002BCA 81C700000A00        <1> 	add	edi, 0A0000h
  4944 00002BD0 51                  <1> 	push	ecx
  4945 00002BD1 0FB6CF              <1> 	movzx	ecx, bh 		
  4946 00002BD4 F3A4                <1> 	rep	movsb
  4947 00002BD6 59                  <1> 	pop	ecx	
  4948 00002BD7 FEC3                <1> 	inc	bl
  4949 00002BD9 38CB                <1> 	cmp	bl, cl
  4950 00002BDB 75D6                <1> 	jne	short ltup_1	
  4951                              <1> 	;
  4952 00002BDD E840000000          <1> 	call	release_font_access
  4953                              <1> 	;
  4954 00002BE2 58                  <1> 	pop	eax
  4955                              <1> 	; if(AL>=0x10)
  4956 00002BE3 3C10                <1> 	cmp	al, 10h
  4957 00002BE5 7205                <1> 	jb	short ltup_2
  4958                              <1>    	; set_scan_lines(BH);
  4959 00002BE7 E875000000          <1> 	call	set_scan_lines
  4960                              <1> ltup_2:
  4961 00002BEC C3                  <1> 	retn
  4962                              <1> 
  4963                              <1> get_font_access:
  4964                              <1> 	; 09/07/2016
  4965                              <1> 	;
  4966                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4967                              <1> 	; vgabios-0.7a (2011)
  4968                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4969                              <1> 	; 'vgabios.c', 'get_font_access'
  4970                              <1> 
  4971                              <1> 	; get_font_access()
  4972 00002BED 52                  <1> 	push	edx
  4973 00002BEE 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  4974 00002BF2 66B80001            <1> 	mov	ax, 0100h
  4975 00002BF6 66EF                <1> 	out	dx, ax
  4976 00002BF8 66B80204            <1> 	mov	ax, 0402h
  4977 00002BFC 66EF                <1> 	out	dx, ax
  4978 00002BFE 66B80407            <1> 	mov	ax, 0704h
  4979 00002C02 66EF                <1> 	out	dx, ax
  4980 00002C04 66B80003            <1> 	mov	ax, 0300h
  4981 00002C08 66EF                <1> 	out	dx, ax
  4982 00002C0A 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4983 00002C0E 66B80402            <1> 	mov	ax, 0204h
  4984 00002C12 66EF                <1> 	out	dx, ax
  4985 00002C14 66B80500            <1> 	mov	ax, 0005h
  4986 00002C18 66EF                <1> 	out	dx, ax
  4987 00002C1A 66B80604            <1> 	mov	ax, 0406h
  4988 00002C1E 66EF                <1> 	out	dx, ax
  4989 00002C20 5A                  <1> 	pop	edx
  4990 00002C21 C3                  <1> 	retn
  4991                              <1> 
  4992                              <1> release_font_access:
  4993                              <1> 	; 29/07/2016
  4994                              <1> 	; 09/07/2016
  4995                              <1> 	;
  4996                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4997                              <1> 	; vgabios-0.7a (2011)
  4998                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4999                              <1> 	; 'vgabios.c', 'release_font_access'
  5000                              <1> 
  5001 00002C22 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  5002 00002C26 66B80001            <1> 	mov	ax, 0100h
  5003 00002C2A 66EF                <1> 	out	dx, ax
  5004 00002C2C 66B80203            <1> 	mov	ax, 0302h
  5005 00002C30 66EF                <1> 	out	dx, ax
  5006 00002C32 66B80403            <1> 	mov	ax, 0304h
  5007 00002C36 66EF                <1> 	out	dx, ax
  5008 00002C38 66B80003            <1> 	mov	ax, 0300h
  5009 00002C3C 66EF                <1> 	out	dx, ax
  5010 00002C3E 66BACC03            <1> 	mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
  5011 00002C42 EC                  <1>  	in	al, dx
  5012 00002C43 2401                <1> 	and	al, 01h
  5013 00002C45 C0E002              <1> 	shl	al, 2
  5014 00002C48 0C0A                <1> 	or	al, 0Ah
  5015 00002C4A 88C4                <1> 	mov	ah, al
  5016 00002C4C B006                <1> 	mov	al, 06h
  5017 00002C4E 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  5018 00002C52 66EF                <1> 	out	dx, ax
  5019 00002C54 66B80400            <1> 	mov	ax, 0004h
  5020 00002C58 66EF                <1> 	out	dx, ax
  5021 00002C5A 66B80510            <1> 	mov	ax, 1005h
  5022 00002C5E 66EF                <1> 	out	dx, ax
  5023 00002C60 C3                  <1> 	retn
  5024                              <1> 
  5025                              <1> set_scan_lines:
  5026                              <1> 	; 09/07/2016
  5027                              <1> 	;
  5028                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5029                              <1> 	; vgabios-0.7a (2011)
  5030                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5031                              <1> 	; 'vgabios.c', 'set_scan_lines'
  5032                              <1> 
  5033                              <1> 	; set_scan_lines(lines)
  5034                              <1> 	; BH = lines
  5035                              <1> 
  5036                              <1> 	; outb(crtc_addr, 0x09);
  5037 00002C61 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS = 3D4h (always)
  5038 00002C65 B009                <1> 	mov	al, 09h
  5039 00002C67 EE                  <1> 	out	dx, al
  5040                              <1> 	; crtc_r9 = inb(crtc_addr+1);
  5041 00002C68 6642                <1> 	inc	dx ; 3D5h
  5042 00002C6A EC                  <1> 	in	al, dx
  5043                              <1> 	; crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1);
  5044 00002C6B 24E0                <1> 	and	al, 0E0h
  5045 00002C6D FECF                <1> 	dec	bh ; lines - 1
  5046 00002C6F 08F8                <1> 	or	al, bh
  5047                              <1> 	; outb(crtc_addr+1, crtc_r9);
  5048 00002C71 EE                  <1> 	out	dx, al
  5049                              <1> 	;inc	bh 
  5050                              <1> 	; if(lines==8)
  5051                              <1> 	;cmp	bh, 8
  5052 00002C72 80FF07              <1> 	cmp	bh, 7
  5053 00002C75 7506                <1> 	jne	short ssl_1
  5054                              <1> 	; biosfn_set_cursor_shape(0x06,0x07);
  5055 00002C77 66B90706            <1> 	mov	cx, 0607h
  5056 00002C7B EB06                <1> 	jmp	short ssl_2
  5057                              <1> ssl_1:
  5058                              <1> 	; biosfn_set_cursor_shape(lines-4,lines-3);
  5059 00002C7D 88F9                <1> 	mov	cl, bh ; lines - 1
  5060 00002C7F 88CD                <1> 	mov	ch, cl ; lines - 1 (16 -> 15)
  5061 00002C81 FECD                <1> 	dec	ch  ; lines - 2 (16 -> 14)
  5062                              <1> ssl_2:
  5063                              <1> 	; CH = start line, CL = stop line
  5064 00002C83 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  5065 00002C85 66890D[0B5F0000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  5066 00002C8C E812F1FFFF          <1> 	call	m16	; output cx register
  5067                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, lines);
  5068 00002C91 FEC7                <1> 	inc	bh ; lines
  5069 00002C93 883D[F65E0000]      <1> 	mov	[CHAR_HEIGHT], bh
  5070                              <1> 	;  outb(crtc_addr, 0x12);
  5071 00002C99 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS
  5072 00002C9D B012                <1> 	mov	al, 12h
  5073 00002C9F EE                  <1> 	out	dx, al
  5074                              <1> 	; vde = inb(crtc_addr+1);
  5075 00002CA0 6642                <1> 	inc	dx
  5076 00002CA2 EC                  <1> 	in	al, dx
  5077 00002CA3 88C4                <1> 	mov	ah, al
  5078                              <1> 	; outb(crtc_addr, 0x07);
  5079 00002CA5 664A                <1> 	dec	dx
  5080 00002CA7 B007                <1> 	mov	al, 07h
  5081 00002CA9 EE                  <1> 	out	dx, al
  5082                              <1> 	; ovl = inb(crtc_addr+1);
  5083 00002CAA 6642                <1> 	inc	dx
  5084 00002CAC EC                  <1> 	in	al, dx
  5085                              <1> 	; vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1);
  5086 00002CAD 88E2                <1> 	mov	dl, ah ; vde
  5087 00002CAF 88C6                <1> 	mov	dh, al ; ovl
  5088 00002CB1 6683E002            <1> 	and	ax, 02h
  5089 00002CB5 66C1E007            <1> 	shl	ax, 7
  5090 00002CB9 6689C1              <1> 	mov	cx, ax ; (ovl & 0x02) << 7)	
  5091 00002CBC 88F0                <1> 	mov	al, dh ; ovl
  5092 00002CBE 6683E040            <1> 	and	ax, 40h			
  5093 00002CC2 66C1E003            <1> 	shl	ax, 3  ; (ovl & 0x40) << 3)
  5094 00002CC6 6640                <1> 	inc	ax ; + 1 
  5095 00002CC8 6601C8              <1> 	add	ax, cx
  5096 00002CCB 30F6                <1> 	xor	dh, dh
  5097 00002CCD 6601D0              <1> 	add	ax, dx ; + vde
  5098                              <1> 	; rows = vde / lines;
  5099 00002CD0 F6F7                <1> 	div	bh
  5100                              <1> 	;dec	al ; rows -1
  5101                              <1> 	; write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, rows-1);
  5102 00002CD2 A2[FA5E0000]        <1> 	mov	[VGA_ROWS], al ; rows (not 'rows-1' !)
  5103                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, rows * cols * 2);
  5104 00002CD7 8A25[F45E0000]      <1> 	mov	ah, [CRT_COLS]
  5105 00002CDD F6E4                <1> 	mul	ah
  5106 00002CDF 66D1E0              <1> 	shl	ax, 1
  5107 00002CE2 66A3[38650100]      <1> 	mov 	[CRT_LEN], ax	
  5108 00002CE8 C3                  <1> 	retn
  5109                              <1> 
  5110                              <1> load_text_8_14_pat:
  5111                              <1> 	; 26/07/2016
  5112                              <1> 	; 25/07/2016
  5113                              <1> 	; 23/07/2016
  5114                              <1> 	; 09/07/2016
  5115                              <1> 	; load user defined (EGA/VGA) text fonts
  5116                              <1> 	;
  5117                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5118                              <1> 	; vgabios-0.7a (2011)
  5119                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5120                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_14_pat'
  5121                              <1> 
  5122                              <1> 	; biosfn_load_text_8_14_pat (AL,BL)
  5123                              <1> 
  5124                              <1> 	; get_font_access();
  5125                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5126                              <1> 	; for(i=0;i<0x100;i++)
  5127                              <1> 	; {
  5128                              <1> 	;  src = i * 14;
  5129                              <1> 	;  dest = blockaddr + i * 32;
  5130                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont14+src, 14);
  5131                              <1> 	; }
  5132                              <1> 	; release_font_access();
  5133                              <1> 	; if(AL>=0x10)
  5134                              <1> 	; {
  5135                              <1> 	; set_scan_lines(14);
  5136                              <1> 	; }
  5137                              <1> 
  5138 00002CE9 50                  <1> 	push	eax
  5139 00002CEA E8FEFEFFFF          <1> 	call	get_font_access
  5140                              <1> 
  5141                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5142                              <1> 	;mov	dl, bl
  5143                              <1> 	;and	dl, 3
  5144                              <1> 	;shl	dx, 14
  5145                              <1> 	;xchg	dx, bx
  5146                              <1> 	;and	dl, 4
  5147                              <1> 	;shl	dx, 11
  5148                              <1> 	;add	dx, bx 	
  5149                              <1>  
  5150                              <1> 	;xor	dx, dx  ; blockaddr = 0
  5151                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  5152                              <1> 
  5153 00002CEF 28DB                <1> 	sub	bl, bl ; i = 0
  5154 00002CF1 B70E                <1> 	mov	bh, 14
  5155 00002CF3 BE[24350100]        <1> 	mov	esi, vgafont14
  5156 00002CF8 BF00000A00          <1> 	mov	edi, 0A0000h		
  5157                              <1> lt8_14_1:
  5158                              <1> 	;mov	al, bl
  5159                              <1> 	;mul	bh
  5160                              <1> 	;movzx	esi, ax
  5161                              <1> 	;add	esi, vgafont14
  5162                              <1> 	;mov	al, bl
  5163                              <1> 	;sub	ah, ah
  5164                              <1> 	;shl	ax, 5 ; * 32
  5165                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5166                              <1> 	;movzx	edi, ax ; dest
  5167                              <1> 	;add	edi, 0A0000h
  5168 00002CFD 0FB6CF              <1> 	movzx	ecx, bh 		
  5169 00002D00 F3A4                <1> 	rep	movsb
  5170 00002D02 83C712              <1> 	add	edi, 18 ; 32 - 14
  5171 00002D05 FEC3                <1> 	inc	bl
  5172 00002D07 75F4                <1> 	jnz	short lt8_14_1	
  5173                              <1> 	;
  5174 00002D09 E814FFFFFF          <1> 	call	release_font_access
  5175                              <1> 	;
  5176 00002D0E 58                  <1> 	pop	eax
  5177                              <1> 	; if(AL>=0x10)
  5178 00002D0F 3C10                <1> 	cmp	al, 10h
  5179 00002D11 7205                <1> 	jb	short lt8_14_4
  5180                              <1> 	; BH = 14
  5181                              <1>    	; set_scan_lines(14);
  5182 00002D13 E849FFFFFF          <1> 	call	set_scan_lines
  5183                              <1> lt8_14_4:
  5184 00002D18 C3                  <1> 	retn
  5185                              <1> 
  5186                              <1> load_text_8_8_pat:
  5187                              <1> 	; 26/07/2016
  5188                              <1> 	; 25/07/2016
  5189                              <1> 	; 23/07/2016
  5190                              <1> 	; 09/07/2016
  5191                              <1> 	; load user defined (EGA/VGA) text fonts
  5192                              <1> 	;
  5193                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5194                              <1> 	; vgabios-0.7a (2011)
  5195                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5196                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_8_pat'
  5197                              <1> 
  5198                              <1> 	; biosfn_load_text_8_8_pat (AL,BL)
  5199                              <1> 
  5200                              <1> 	; get_font_access();
  5201                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5202                              <1> 	; for(i=0;i<0x100;i++)
  5203                              <1> 	; {
  5204                              <1> 	;  src = i * 8;
  5205                              <1> 	;  dest = blockaddr + i * 32;
  5206                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont8+src, 8);
  5207                              <1> 	; }
  5208                              <1> 	; release_font_access();
  5209                              <1> 	; if(AL>=0x10)
  5210                              <1> 	; {
  5211                              <1> 	; set_scan_lines(8);
  5212                              <1> 	; }
  5213                              <1> 
  5214 00002D19 50                  <1> 	push	eax
  5215 00002D1A E8CEFEFFFF          <1> 	call	get_font_access
  5216                              <1> 
  5217                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5218                              <1> 	;mov	dl, bl
  5219                              <1> 	;and	dl, 3
  5220                              <1> 	;shl	dx, 14
  5221                              <1> 	;xchg	dx, bx
  5222                              <1> 	;and	dl, 4
  5223                              <1> 	;shl	dx, 11
  5224                              <1> 	;add	dx, bx 	
  5225                              <1>  
  5226                              <1> 	;xor	dx, dx  ; blockaddr = 0
  5227                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  5228                              <1> 
  5229 00002D1F 28DB                <1> 	sub	bl, bl ; i = 0
  5230 00002D21 B708                <1> 	mov	bh, 8
  5231 00002D23 BE[242D0100]        <1> 	mov	esi, vgafont8
  5232 00002D28 BF00000A00          <1> 	mov	edi, 0A0000h		
  5233                              <1> lt8_8_1:
  5234                              <1> 	;mov	al, bl
  5235                              <1> 	;mul	bh
  5236                              <1> 	;movzx	esi, ax
  5237                              <1> 	;add	esi, vgafont8
  5238                              <1> 	;mov	al, bl
  5239                              <1> 	;sub	ah, ah
  5240                              <1> 	;shl	ax, 5 ; * 32
  5241                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5242                              <1> 	;movzx	edi, ax ; dest
  5243                              <1> 	;add	edi, 0A0000h
  5244 00002D2D 0FB6CF              <1> 	movzx	ecx, bh 		
  5245 00002D30 F3A4                <1> 	rep	movsb
  5246 00002D32 83C718              <1> 	add	edi, 24 ; 32 - 8
  5247 00002D35 FEC3                <1> 	inc	bl
  5248 00002D37 75F4                <1> 	jnz	short lt8_8_1	
  5249                              <1> 	;
  5250 00002D39 E8E4FEFFFF          <1> 	call	release_font_access
  5251                              <1> 	;
  5252 00002D3E 58                  <1> 	pop	eax
  5253                              <1> 	; if(AL>=0x10)
  5254 00002D3F 3C10                <1> 	cmp	al, 10h
  5255 00002D41 7205                <1> 	jb	short lt8_8_2
  5256                              <1> 	; BH = 8
  5257                              <1>    	; set_scan_lines(8);
  5258 00002D43 E819FFFFFF          <1> 	call	set_scan_lines
  5259                              <1> lt8_8_2:
  5260 00002D48 C3                  <1> 	retn
  5261                              <1> 
  5262                              <1> load_text_8_16_pat:
  5263                              <1> 	; 26/07/2016
  5264                              <1> 	; 25/07/2016
  5265                              <1> 	; 23/07/2016
  5266                              <1> 	; 09/07/2016
  5267                              <1> 	; load user defined (EGA/VGA) text fonts
  5268                              <1> 	;
  5269                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5270                              <1> 	; vgabios-0.7a (2011)
  5271                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5272                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_16_pat'
  5273                              <1> 
  5274                              <1> 	; biosfn_load_text_8_16_pat (AL,BL)
  5275                              <1> 
  5276                              <1> 	; get_font_access();
  5277                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5278                              <1> 	; for(i=0;i<0x100;i++)
  5279                              <1> 	; {
  5280                              <1> 	;  src = i * 16;
  5281                              <1> 	;  dest = blockaddr + i * 32;
  5282                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont16+src, 16);
  5283                              <1> 	; }
  5284                              <1> 	; release_font_access();
  5285                              <1> 	; if(AL>=0x10)
  5286                              <1> 	; {
  5287                              <1> 	; set_scan_lines(16);
  5288                              <1> 	; }
  5289                              <1> 
  5290 00002D49 50                  <1> 	push	eax
  5291 00002D4A E89EFEFFFF          <1> 	call	get_font_access
  5292                              <1> 
  5293                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  5294                              <1> 	;mov	dl, bl
  5295                              <1> 	;and	dl, 3
  5296                              <1> 	;shl	dx, 14
  5297                              <1> 	;xchg	dx, bx
  5298                              <1> 	;and	dl, 4
  5299                              <1> 	;shl	dx, 11
  5300                              <1> 	;add	dx, bx 	
  5301                              <1>  
  5302                              <1> 	;xor	dx, dx  ; blockaddr = 0
  5303                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0(
  5304                              <1> 
  5305 00002D4F 28DB                <1> 	sub	bl, bl ; i = 0
  5306 00002D51 B710                <1> 	mov	bh, 16
  5307 00002D53 BE[24430100]        <1> 	mov	esi, vgafont16
  5308 00002D58 BF00000A00          <1> 	mov	edi, 0A0000h
  5309 00002D5D 0FB6C7              <1> 	movzx	eax, bh	
  5310                              <1> lt8_16_1:
  5311                              <1> 	;mov	al, bl
  5312                              <1> 	;mul	bh
  5313                              <1> 	;movzx	esi, ax
  5314                              <1> 	;add	esi, vgafont16
  5315                              <1> 	;mov	al, bl ; i
  5316                              <1> 	;sub	ah, ah
  5317                              <1> 	;shl	ax, 5 ; * 32
  5318                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  5319                              <1> 	;movzx	edi, ax ; dest
  5320                              <1> 	;add	edi, 0A0000h
  5321                              <1> 	;movzx	ecx, bh
  5322 00002D60 89C1                <1> 	mov	ecx, eax ; 16	
  5323 00002D62 F3A4                <1> 	rep	movsb
  5324 00002D64 01C7                <1> 	add	edi, eax ; add edi, 16
  5325 00002D66 FEC3                <1> 	inc	bl
  5326 00002D68 75F6                <1> 	jnz	short lt8_16_1
  5327                              <1> 	;
  5328 00002D6A E8B3FEFFFF          <1> 	call	release_font_access
  5329                              <1> 	;
  5330 00002D6F 58                  <1> 	pop	eax
  5331                              <1> 	; if(AL>=0x10)
  5332 00002D70 3C10                <1> 	cmp	al, 10h
  5333 00002D72 7205                <1> 	jb	short lt8_16_2
  5334                              <1> 	; BH = 16
  5335                              <1>    	; set_scan_lines(16);
  5336 00002D74 E8E8FEFFFF          <1> 	call	set_scan_lines
  5337                              <1> lt8_16_2:
  5338 00002D79 C3                  <1> 	retn
  5339                              <1> 
  5340                              <1> load_gfx_user_chars:
  5341                              <1> 	; 08/08/2016
  5342                              <1> 	; 10/07/2016
  5343                              <1> 	; Setup User-Defined Font for Graphics Mode (VGA)
  5344                              <1> 	;
  5345                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5346                              <1> 	; vgabios-0.7a (2011)
  5347                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5348                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_user_chars'
  5349                              <1> 
  5350                              <1> 	; biosfn_load_gfx_user_chars (ES,BP,CX,BL,DL)
  5351                              <1> 	; /* set 0x43 INT pointer */
  5352                              <1>     	; write_word(0x0, 0x43*4, BP);
  5353                              <1>     	; write_word(0x0, 0x43*4+2, ES);
  5354 00002D7A 31C0                <1> 	xor	eax, eax
  5355 00002D7C 48                  <1> 	dec	eax ; 0FFFFFFFFh (user defined fonts)
  5356 00002D7D A3[4A650100]        <1> 	mov	[VGA_INT43H], eax
  5357                              <1> 		
  5358                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  5359                              <1>         ;                        01H = 14 rows
  5360                              <1>         ;                        02H = 25 rows
  5361                              <1>         ;                        03H = 43 rows
  5362                              <1>         ; CX   bytes per character definition
  5363                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  5364                              <1> 	; dh = 0 -> 256 characters
  5365                              <1> 	; dh = 80h -> 128 characters
  5366                              <1> 	; (If DH <> 0 and DH <> 80h -> invalid)     	 
  5367                              <1>         ; EBP  address of font-definition information (user's mem space)
  5368                              <1> 
  5369                              <1> 	; switch (BL) {
  5370                              <1> 	; case 0:
  5371                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5372                              <1> 	;    break;
  5373 00002D82 20DB                <1> 	and	bl, bl
  5374 00002D84 7508                <1> 	jnz	short l_gfx_uc_1
  5375 00002D86 8815[FA5E0000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5376 00002D8C EB23                <1> 	jmp	short l_gfx_uc_4 	
  5377                              <1> l_gfx_uc_1:
  5378                              <1> 	; case 1:
  5379                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5380                              <1> 	;    break;
  5381 00002D8E FECB                <1> 	dec	bl
  5382 00002D90 7509                <1> 	jnz	short l_gfx_uc_2
  5383                              <1> 	; bl = 1
  5384 00002D92 C605[FA5E0000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5385 00002D99 EB16                <1> 	jmp	short l_gfx_uc_4 	
  5386                              <1> l_gfx_uc_2:
  5387 00002D9B FECB                <1> 	dec	bl
  5388 00002D9D 740B                <1> 	jz	short l_gfx_uc_3 ; bl = 2
  5389 00002D9F FECB                <1> 	dec	bl
  5390 00002DA1 750E                <1> 	jnz	short l_gfx_uc_4 ; bl > 3
  5391                              <1> 	; bl = 3
  5392                              <1> 	; case 3:
  5393                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5394                              <1> 	;    break;
  5395 00002DA3 C605[FA5E0000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5396                              <1> l_gfx_uc_3:
  5397                              <1>     	; case 2:
  5398                              <1>     	; default:
  5399                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5400                              <1> 	;    break;
  5401                              <1> 	; bl = 2 or bl > 3
  5402 00002DAA C605[FA5E0000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5403                              <1>     	; }
  5404                              <1> l_gfx_uc_4:
  5405                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, CX);
  5406 00002DB1 880D[F65E0000]      <1> 	mov	[CHAR_HEIGHT], cl
  5407                              <1> 	; }
  5408 00002DB7 C3                  <1> 	retn	
  5409                              <1> 
  5410                              <1> load_gfx_8_14_chars:
  5411                              <1> 	; 08/08/2016
  5412                              <1> 	; 10/07/2016
  5413                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5414                              <1> 	;
  5415                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5416                              <1> 	; vgabios-0.7a (2011)
  5417                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5418                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_14_chars'
  5419                              <1> 
  5420                              <1> 	; biosfn_load_gfx_8_14_chars (BL)
  5421                              <1> 	; /* set 0x43 INT pointer */
  5422                              <1>     	; write_word(0x0, 0x43*4, &vgafont14);
  5423                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5424 00002DB8 C705[4A650100]-     <1> 	mov	dword [VGA_INT43H], vgafont14
  5424 00002DBE [24350100]          <1>
  5425                              <1> 		
  5426                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5427                              <1>         ;                         01H = 14 rows
  5428                              <1>         ;                         02H = 25 rows
  5429                              <1>         ;                         03H = 43 rows
  5430                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5431                              <1> 
  5432                              <1> 	; switch (BL) {
  5433                              <1> 	; case 0:
  5434                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5435                              <1> 	;    break;
  5436 00002DC2 20DB                <1> 	and	bl, bl
  5437 00002DC4 7508                <1> 	jnz	short l_gfx_8_14c_1
  5438 00002DC6 8815[FA5E0000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5439 00002DCC EB23                <1> 	jmp	short l_gfx_8_14c_4 	
  5440                              <1> l_gfx_8_14c_1:
  5441                              <1> 	; case 1:
  5442                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5443                              <1> 	;    break;
  5444 00002DCE FECB                <1> 	dec	bl
  5445 00002DD0 7509                <1> 	jnz	short l_gfx_8_14c_2
  5446                              <1> 	; bl = 1
  5447 00002DD2 C605[FA5E0000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5448 00002DD9 EB16                <1> 	jmp	short l_gfx_8_14c_4 	
  5449                              <1> l_gfx_8_14c_2:
  5450 00002DDB FECB                <1> 	dec	bl
  5451 00002DDD 740B                <1> 	jz	short l_gfx_8_14c_3 ; bl = 2
  5452 00002DDF FECB                <1> 	dec	bl
  5453 00002DE1 750E                <1> 	jnz	short l_gfx_8_14c_4 ; bl > 3
  5454                              <1> 	; bl = 3
  5455                              <1> 	; case 3:
  5456                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5457                              <1> 	;    break;
  5458 00002DE3 C605[FA5E0000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5459                              <1> l_gfx_8_14c_3:
  5460                              <1>     	; case 2:
  5461                              <1>     	; default:
  5462                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5463                              <1> 	;    break;
  5464                              <1> 	; bl = 2 or bl > 3
  5465 00002DEA C605[FA5E0000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5466                              <1>     	; }
  5467                              <1> l_gfx_8_14c_4:
  5468                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 14);
  5469 00002DF1 C605[F65E0000]0E    <1>         mov     byte [CHAR_HEIGHT], 14
  5470                              <1> 	; }
  5471 00002DF8 C3                  <1> 	retn	
  5472                              <1> 
  5473                              <1> load_gfx_8_8_chars:
  5474                              <1> 	; 08/08/2016
  5475                              <1> 	; 10/07/2016
  5476                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5477                              <1> 	;
  5478                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5479                              <1> 	; vgabios-0.7a (2011)
  5480                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5481                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_8_dd_chars'
  5482                              <1> 
  5483                              <1> 	; biosfn_load_gfx_8_8_dd_chars (BL)
  5484                              <1> 	; /* set 0x43 INT pointer */
  5485                              <1>     	; write_word(0x0, 0x43*4, &vgafont8);
  5486                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5487 00002DF9 C705[4A650100]-     <1> 	mov	dword [VGA_INT43H], vgafont8
  5487 00002DFF [242D0100]          <1>
  5488                              <1> 		
  5489                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5490                              <1>         ;                         01H = 14 rows
  5491                              <1>         ;                         02H = 25 rows
  5492                              <1>         ;                         03H = 43 rows
  5493                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5494                              <1> 
  5495                              <1> 	; switch (BL) {
  5496                              <1> 	; case 0:
  5497                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5498                              <1> 	;    break;
  5499 00002E03 20DB                <1> 	and	bl, bl
  5500 00002E05 7508                <1> 	jnz	short l_gfx_8_8c_1
  5501 00002E07 8815[FA5E0000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5502 00002E0D EB23                <1> 	jmp	short l_gfx_8_8c_4 	
  5503                              <1> l_gfx_8_8c_1:
  5504                              <1> 	; case 1:
  5505                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5506                              <1> 	;    break;
  5507 00002E0F FECB                <1> 	dec	bl
  5508 00002E11 7509                <1> 	jnz	short l_gfx_8_8c_2
  5509                              <1> 	; bl = 1
  5510 00002E13 C605[FA5E0000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5511 00002E1A EB16                <1> 	jmp	short l_gfx_8_8c_4 	
  5512                              <1> l_gfx_8_8c_2:
  5513 00002E1C FECB                <1> 	dec	bl
  5514 00002E1E 740B                <1> 	jz	short l_gfx_8_8c_3 ; bl = 2
  5515 00002E20 FECB                <1> 	dec	bl
  5516 00002E22 750E                <1> 	jnz	short l_gfx_8_8c_4 ; bl > 3
  5517                              <1> 	; bl = 3
  5518                              <1> 	; case 3:
  5519                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5520                              <1> 	;    break;
  5521 00002E24 C605[FA5E0000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5522                              <1> l_gfx_8_8c_3:
  5523                              <1>     	; case 2:
  5524                              <1>     	; default:
  5525                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5526                              <1> 	;    break;
  5527                              <1> 	; bl = 2 or bl > 3
  5528 00002E2B C605[FA5E0000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5529                              <1>     	; }
  5530                              <1> l_gfx_8_8c_4:
  5531                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 8);
  5532 00002E32 C605[F65E0000]08    <1>         mov     byte [CHAR_HEIGHT], 8
  5533                              <1> 	; }
  5534 00002E39 C3                  <1> 	retn
  5535                              <1> 
  5536                              <1> load_gfx_8_16_chars:
  5537                              <1> 	; 08/08/2016
  5538                              <1> 	; 10/07/2016
  5539                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  5540                              <1> 	;
  5541                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5542                              <1> 	; vgabios-0.7a (2011)
  5543                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5544                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_16_chars'
  5545                              <1> 
  5546                              <1> 	; biosfn_load_gfx_8_16_chars (BL)
  5547                              <1> 	; /* set 0x43 INT pointer */
  5548                              <1>     	; write_word(0x0, 0x43*4, &vgafont16);
  5549                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  5550 00002E3A C705[4A650100]-     <1> 	mov	dword [VGA_INT43H], vgafont16
  5550 00002E40 [24430100]          <1>
  5551                              <1> 		
  5552                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  5553                              <1>         ;                         01H = 14 rows
  5554                              <1>         ;                         02H = 25 rows
  5555                              <1>         ;                         03H = 43 rows
  5556                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  5557                              <1> 
  5558                              <1> 	; switch (BL) {
  5559                              <1> 	; case 0:
  5560                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  5561                              <1> 	;    break;
  5562 00002E44 20DB                <1> 	and	bl, bl
  5563 00002E46 7508                <1> 	jnz	short l_gfx_8_16c_1
  5564 00002E48 8815[FA5E0000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  5565 00002E4E EB23                <1> 	jmp	short l_gfx_8_16c_4 	
  5566                              <1> l_gfx_8_16c_1:
  5567                              <1> 	; case 1:
  5568                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  5569                              <1> 	;    break;
  5570 00002E50 FECB                <1> 	dec	bl
  5571 00002E52 7509                <1> 	jnz	short l_gfx_8_16c_2
  5572                              <1> 	; bl = 1
  5573 00002E54 C605[FA5E0000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  5574 00002E5B EB16                <1> 	jmp	short l_gfx_8_16c_4 	
  5575                              <1> l_gfx_8_16c_2:
  5576 00002E5D FECB                <1> 	dec	bl
  5577 00002E5F 740B                <1> 	jz	short l_gfx_8_16c_3 ; bl = 2
  5578 00002E61 FECB                <1> 	dec	bl
  5579 00002E63 750E                <1> 	jnz	short l_gfx_8_16c_4 ; bl > 3
  5580                              <1> 	; bl = 3
  5581                              <1> 	; case 3:
  5582                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  5583                              <1> 	;    break;
  5584 00002E65 C605[FA5E0000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  5585                              <1> l_gfx_8_16c_3:
  5586                              <1>     	; case 2:
  5587                              <1>     	; default:
  5588                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  5589                              <1> 	;    break;
  5590                              <1> 	; bl = 2 or bl > 3
  5591 00002E6C C605[FA5E0000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  5592                              <1>     	; }
  5593                              <1> l_gfx_8_16c_4:
  5594                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 16);
  5595 00002E73 C605[F65E0000]10    <1>         mov     byte [CHAR_HEIGHT], 16
  5596                              <1> 	; }
  5597 00002E7A C3                  <1> 	retn
  5598                              <1> 			
  5599                              <1> get_font_info:
  5600                              <1> 	; 19/09/2016
  5601                              <1> 	; 08/08/2016
  5602                              <1> 	; 10/07/2016
  5603                              <1> 	; Get Current Character Generator Info (VGA)
  5604                              <1> 	;
  5605                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5606                              <1> 	; vgabios-0.7a (2011)
  5607                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5608                              <1> 	; 'vgabios.c', 'biosfn_get_font_info'
  5609                              <1> 
  5610                              <1> 	; Modified for TRDOS 386 !
  5611                              <1> 	;
  5612                              <1> 	; INPUT ->
  5613                              <1> 	;    AX = 1130h
  5614                              <1> 	;    BL = 0 -> Get info for current VGA font
  5615                              <1> 	;	       (BH = unused)
  5616                              <1> 	;    19/09/2016
  5617                              <1> 	;    BL > 0 -> Get requested character font data
  5618                              <1> 	;	 BL = 1 -> vgafont8
  5619                              <1> 	;        BL = 2 -> vgafont14
  5620                              <1> 	;	 BL = 3 -> vgafont16   
  5621                              <1> 	;	 BL > 3 -> Invalid function (for now!)
  5622                              <1> 	;	 BH = ASCII code of the first character
  5623                              <1> 	;	 ECX = Number of characters from the 1st char
  5624                              <1> 	;	 ECX >= 256 -> All (256-BH) characters
  5625                              <1> 	;	 ECX = 0 -> All characters (BH = unused)	
  5626                              <1> 	;        EDX = User's Buffer Address	
  5627                              <1> 	; OUTPUT ->
  5628                              <1> 	;    AL = height (scanlines), bytes per character
  5629                              <1> 	;    AH = screen rows
  5630                              <1> 	;    Byte 16-23 of EAX = number of columns
  5631                              <1> 	;    Byte 24-31 of EAX = 
  5632                              <1> 	;	  0 -> default font (not configured yet)
  5633                              <1> 	;	  0FFh -> user defined font
  5634                              <1> 	;	  14 = vgafont14
  5635                              <1> 	;	   8 = vgafont8
  5636                              <1> 	;	  16 = vgafont16
  5637                              <1> 	;   If BL input > 0 -> 
  5638                              <1> 	;       EAX = Actual transfer count
  5639                              <1> 	;
  5640 00002E7B 20DB                <1> 	and	bl, bl
  5641 00002E7D 7408                <1> 	jz	short gfi_0
  5642                              <1> 	; invalid function (input)
  5643 00002E7F 80FB03              <1> 	cmp	bl, 3
  5644 00002E82 7642                <1> 	jna	short gfi_4
  5645 00002E84 31C0                <1> 	xor	eax, eax ; 0
  5646 00002E86 C3                  <1> 	retn
  5647                              <1> gfi_0:
  5648 00002E87 A0[F65E0000]        <1> 	mov	al, [CHAR_HEIGHT]
  5649 00002E8C 8A25[FA5E0000]      <1> 	mov	ah, [VGA_ROWS]
  5650 00002E92 C1E010              <1> 	shl	eax, 16
  5651 00002E95 A0[F45E0000]        <1> 	mov	al, [CRT_COLS]
  5652 00002E9A 8B0D[4A650100]      <1> 	mov	ecx, [VGA_INT43H]
  5653 00002EA0 21C9                <1> 	and	ecx, ecx
  5654 00002EA2 741E                <1> 	jz	short gfi_2 ; 0 = default font
  5655 00002EA4 41                  <1> 	inc	ecx ; 0FFFFFFFFh -> 0 (user defined font)
  5656 00002EA5 7504                <1> 	jnz	short gfi_1
  5657 00002EA7 FECC                <1> 	dec	ah ; 0FFh
  5658 00002EA9 EB17                <1> 	jmp	short gfi_2
  5659                              <1> gfi_1:
  5660 00002EAB 49                  <1> 	dec	ecx ; 08/08/2016
  5661 00002EAC B40E                <1> 	mov	ah, 14
  5662 00002EAE 81F9[24350100]      <1> 	cmp	ecx, vgafont14
  5663 00002EB4 740C                <1> 	je	short gfi_2
  5664 00002EB6 B408                <1> 	mov	ah, 8
  5665 00002EB8 81F9[242D0100]      <1> 	cmp	ecx, vgafont8
  5666 00002EBE 7402                <1> 	je	short gfi_2
  5667                              <1> 	; vgafont16
  5668 00002EC0 D0E4                <1> 	shl	ah, 1 ; ah = 16
  5669                              <1> gfi_2:
  5670 00002EC2 C1C010              <1> 	rol	eax, 16
  5671                              <1> gfi_3:
  5672 00002EC5 C3                  <1> 	retn
  5673                              <1> gfi_4:
  5674 00002EC6 89D7                <1> 	mov	edi, edx ; **
  5675 00002EC8 80FB02              <1> 	cmp	bl, 2
  5676 00002ECB 720B                <1> 	jb	short gfi_5
  5677 00002ECD 772F                <1> 	ja	short gfi_7
  5678                              <1> 	;BL = 2 -> vgafont14
  5679 00002ECF BE[24350100]        <1> 	mov	esi, vgafont14 ; *
  5680 00002ED4 B30E                <1> 	mov	bl, 14
  5681 00002ED6 EB07                <1> 	jmp	short gfi_6 
  5682                              <1> gfi_5:
  5683                              <1> 	;BL = 1 -> vgafont8
  5684 00002ED8 BE[242D0100]        <1> 	mov	esi, vgafont8 ; *
  5685 00002EDD B308                <1> 	mov	bl, 8
  5686                              <1> gfi_6:
  5687 00002EDF 09C9                <1> 	or	ecx, ecx
  5688 00002EE1 7424                <1> 	jz	short gfi_8 ; all chars from the 00h
  5689 00002EE3 88F8                <1> 	mov	al, bh ; character index
  5690 00002EE5 F6E3                <1> 	mul	bl ; char index * char height/size
  5691 00002EE7 0FB7D0              <1> 	movzx	edx, ax
  5692 00002EEA 01D6                <1> 	add	esi, edx ; *
  5693 00002EEC 66BAFF00            <1> 	mov	dx, 255
  5694 00002EF0 28FA                <1> 	sub	dl, bh
  5695 00002EF2 6642                <1> 	inc	dx	
  5696 00002EF4 39D1                <1> 	cmp	ecx, edx
  5697 00002EF6 770F                <1> 	ja	short gfi_8
  5698 00002EF8 7412                <1> 	je	short gfi_9
  5699 00002EFA 89D1                <1> 	mov	ecx, edx
  5700 00002EFC EB0E                <1> 	jmp	short gfi_9
  5701                              <1> gfi_7:
  5702                              <1> 	;BL = 3 -> vgafont16
  5703 00002EFE BE[24430100]        <1> 	mov	esi, vgafont16 ; *
  5704 00002F03 B310                <1> 	mov	bl, 16
  5705 00002F05 EBD8                <1> 	jmp	short gfi_6
  5706                              <1> gfi_8:
  5707 00002F07 B900010000          <1> 	mov	ecx, 256
  5708                              <1> gfi_9:
  5709 00002F0C 6689C8              <1> 	mov	ax, cx ; character count
  5710 00002F0F 30FF                <1> 	xor	bh, bh
  5711 00002F11 66F7E3              <1> 	mul	bx ; char count * char height/size	
  5712 00002F14 6689C1              <1>  	mov	cx, ax
  5713                              <1> 
  5714                              <1> 	; ESI = source address in system space
  5715                              <1> 	; EDI = user's buffer address
  5716                              <1> 	; ECX = transfer (byte) count
  5717 00002F17 E8B8B80000          <1> 	call	transfer_to_user_buffer
  5718 00002F1C 89C8                <1> 	mov	eax, ecx ; actual transfer count
  5719 00002F1E C3                  <1> 	retn
  5720                              <1> 	
  5721                              <1> vga_pal_funcs:
  5722                              <1> 	; 10/08/2016
  5723                              <1> 	; VGA Palette functions
  5724                              <1> 	;
  5725                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5726                              <1> 	; vgabios-0.7a (2011)
  5727                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5728                              <1> 	; 'vgabios.c', 'vgarom.asm'
  5729                              <1> 
  5730 00002F1F 3C00                <1> 	cmp	al, 0
  5731 00002F21 0F848F000000        <1>         je      set_single_palette_reg
  5732                              <1> vga_palf_1001:
  5733 00002F27 3C01                <1> 	cmp	al, 1
  5734 00002F29 0F84B4000000        <1>         je      set_overscan_border_color
  5735                              <1> vga_palf_1002:
  5736 00002F2F 3C02                <1> 	cmp	al, 2
  5737 00002F31 0F84B0000000        <1>         je      set_all_palette_reg
  5738                              <1> vga_palf_1003:
  5739 00002F37 3C03                <1> 	cmp	al, 3
  5740 00002F39 0F84E8000000        <1>         je      toggle_intensity
  5741                              <1> vga_palf_1007:
  5742 00002F3F 3C07                <1> 	cmp	al, 7
  5743 00002F41 0F840D010000        <1>         je      get_single_palette_reg
  5744 00002F47 7266                <1> 	jb	short vga_palf_unknown
  5745                              <1> vga_palf_1008:
  5746 00002F49 3C08                <1> 	cmp	al, 8
  5747 00002F4B 0F8437010000        <1>         je      read_overscan_border_color
  5748                              <1> vga_palf_1009:
  5749 00002F51 3C09                <1> 	cmp	al, 9
  5750 00002F53 0F8433010000        <1> 	je	get_all_palette_reg
  5751                              <1> vga_palf_1010:
  5752 00002F59 3C10                <1> 	cmp	al, 10h
  5753 00002F5B 0F8487010000        <1> 	je 	set_single_dac_reg
  5754 00002F61 724C                <1> 	jb	short vga_palf_unknown
  5755                              <1> vga_palf_1012:
  5756 00002F63 3C12                <1> 	cmp	al, 12h
  5757 00002F65 0F8498010000        <1>         je      set_all_dac_reg
  5758 00002F6B 7242                <1> 	jb	short vga_palf_unknown
  5759                              <1> vga_palf_1013:
  5760 00002F6D 3C13                <1> 	cmp	al, 13h
  5761 00002F6F 0F84CC010000        <1>         je      select_video_dac_color_page
  5762                              <1> vga_palf_1015:
  5763 00002F75 3C15                <1> 	cmp	al, 15h
  5764 00002F77 0F8412020000        <1> 	je	read_single_dac_reg
  5765 00002F7D 7230                <1> 	jb	short vga_palf_unknown
  5766                              <1> vga_palf_1017:
  5767 00002F7F 3C17                <1> 	cmp	al, 17h
  5768 00002F81 0F8428020000        <1>         je      read_all_dac_reg
  5769 00002F87 7226                <1> 	jb	short vga_palf_unknown
  5770                              <1> vga_palf_1018:
  5771 00002F89 3C18                <1> 	cmp	al, 18h
  5772 00002F8B 0F845E020000        <1>         je      set_pel_mask
  5773                              <1> vga_palf_1019:
  5774 00002F91 3C19                <1> 	cmp	al, 19h
  5775 00002F93 0F8462020000        <1>         je      read_pel_mask
  5776                              <1> vga_palf_101A:
  5777 00002F99 3C1A                <1> 	cmp	al, 1Ah
  5778 00002F9B 0F8468020000        <1>         je      read_video_dac_state
  5779                              <1> vga_palf_101B:
  5780 00002FA1 3C1B                <1> 	cmp	al, 1Bh
  5781                              <1> 	;jne	short vga_palf_unknown
  5782 00002FA3 770A                <1> 	ja	short vga_palf_unknown
  5783                              <1>  
  5784 00002FA5 E80CF7FFFF          <1> 	call	gray_scale_summing
  5785 00002FAA E9D5E5FFFF          <1>         jmp     VIDEO_RETURN 	
  5786                              <1> 
  5787                              <1> vga_palf_unknown:
  5788 00002FAF 29C0                <1> 	sub	eax, eax ; 0 = invalid function
  5789 00002FB1 E9D3E5FFFF          <1>         jmp     _video_return
  5790                              <1> 
  5791                              <1> set_single_palette_reg:
  5792                              <1> 	; 10/08/2016
  5793                              <1> 	; Set One Palette Register
  5794                              <1> 	; BL = register number to set
  5795                              <1> 	;     (a 4-bit attribute nibble: 00h-0Fh)
  5796                              <1> 	; BH = 6-bit RGB color to display 
  5797                              <1> 	;      for that attribute
  5798                              <1> 
  5799 00002FB6 80FB14              <1> 	cmp	bl, 14h
  5800                              <1> 	;ja	short no_actl_reg1
  5801 00002FB9 0F87C5E5FFFF        <1> 	ja	VIDEO_RETURN
  5802 00002FBF 6650                <1> 	push	ax
  5803 00002FC1 6652                <1> 	push	dx
  5804 00002FC3 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5805 00002FC7 EC                  <1> 	in	al, dx
  5806 00002FC8 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5807 00002FCC 88D8                <1> 	mov	al, bl
  5808 00002FCE EE                  <1> 	out	dx, al
  5809 00002FCF 88F8                <1> 	mov	al, bh
  5810 00002FD1 EE                  <1> 	out	dx, al
  5811 00002FD2 B020                <1> 	mov	al, 20h
  5812 00002FD4 EE                  <1> 	out	dx, al
  5813                              <1> 	; ifdef VBOX
  5814 00002FD5 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5815 00002FD9 EC                  <1> 	in	al, dx
  5816                              <1> 	; endif ; VBOX
  5817 00002FDA 665A                <1> 	pop	dx
  5818 00002FDC 6658                <1> 	pop	ax
  5819                              <1> ;no_actl_reg1:
  5820 00002FDE E9A1E5FFFF          <1> 	jmp	VIDEO_RETURN
  5821                              <1> 
  5822                              <1> set_overscan_border_color:
  5823                              <1> 	; 10/08/2016
  5824                              <1> 	; Set Overscan/Border Color Register
  5825                              <1> 	; BH = 6-bit RGB color to display 
  5826                              <1> 	;      for that attribute
  5827                              <1> 	
  5828 00002FE3 B311                <1> 	mov	bl, 11h
  5829 00002FE5 EBCF                <1>   	jmp	short set_single_palette_reg
  5830                              <1> 
  5831                              <1> set_all_palette_reg:
  5832                              <1> 	; 10/08/2016
  5833                              <1> 	; Set All Palette Registers and Overscan
  5834                              <1> 	; EDX = Address of 17 bytes; 
  5835                              <1> 	; an rgbRGB value for each of 16 palette
  5836                              <1> 	; registers plus one for the border.
  5837                              <1> 
  5838 00002FE7 89D6                <1> 	mov	esi, edx ; user buffer
  5839 00002FE9 B911000000          <1> 	mov	ecx, 17
  5840 00002FEE 89E7                <1> 	mov	edi, esp
  5841 00002FF0 83EC14              <1> 	sub	esp, 20	 	 
  5842 00002FF3 E826B80000          <1> 	call	transfer_from_user_buffer
  5843                              <1> 	;jc	VIDEO_RETURN
  5844                              <1> 
  5845 00002FF8 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5846 00002FFC EC                  <1> 	in	al, dx
  5847 00002FFD B100                <1> 	mov	cl, 0
  5848 00002FFF 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5849                              <1> set_palette_loop:
  5850 00003003 88C8                <1> 	mov	al, cl
  5851 00003005 EE                  <1> 	out	dx, al
  5852 00003006 8A07                <1> 	mov	al, [edi]
  5853 00003008 EE                  <1> 	out	dx, al
  5854 00003009 47                  <1> 	inc	edi
  5855 0000300A FEC1                <1> 	inc	cl
  5856 0000300C 80F910              <1> 	cmp	cl, 10h
  5857 0000300F 75F2                <1> 	jne	short set_palette_loop
  5858 00003011 B011                <1> 	mov	al, 11h
  5859 00003013 EE                  <1> 	out	dx, al
  5860 00003014 8A07                <1> 	mov	al, [edi]
  5861 00003016 EE                  <1> 	out	dx, al
  5862 00003017 B020                <1> 	mov	al, 20h
  5863 00003019 EE                  <1> 	out	dx, al
  5864                              <1> 	; ifdef VBOX
  5865 0000301A 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5866 0000301E EC                  <1> 	in	al, dx
  5867                              <1> 	; endif ; VBOX
  5868 0000301F 83C414              <1> 	add	esp, 20
  5869 00003022 E95DE5FFFF          <1> 	jmp	VIDEO_RETURN
  5870                              <1> 
  5871                              <1> toggle_intensity:
  5872                              <1> 	; 10/08/2016
  5873                              <1> 	; Select Foreground Blink or Bold Background
  5874                              <1> 	; BL = 00h = enable bold backgrounds
  5875                              <1> 	;	    (16 background colors)
  5876                              <1>         ;      01h = enable blinking foreground
  5877                              <1> 	;	    (8 background colors)
  5878                              <1> 
  5879 00003027 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5880 0000302B EC                  <1> 	in	al, dx
  5881 0000302C 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5882 00003030 B010                <1> 	mov	al, 10h
  5883 00003032 EE                  <1> 	out	dx, al
  5884 00003033 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  5885 00003037 EC                  <1> 	in	al, dx
  5886 00003038 24F7                <1> 	and	al, 0F7h
  5887 0000303A 80E301              <1> 	and	bl, 01h
  5888 0000303D C0E303              <1> 	shl	bl, 3
  5889 00003040 08D8                <1> 	or	al, bl
  5890 00003042 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5891 00003046 EE                  <1> 	out	dx, al
  5892 00003047 B020                <1> 	mov	al, 20h
  5893 00003049 EE                  <1> 	out	dx, al
  5894                              <1> 	; ifdef VBOX
  5895 0000304A 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5896 0000304E EC                  <1> 	in	al, dx
  5897                              <1> 	; endif ; VBOX
  5898 0000304F E930E5FFFF          <1> 	jmp	VIDEO_RETURN
  5899                              <1> 
  5900                              <1> get_single_palette_reg:
  5901                              <1> 	; 10/08/2016
  5902                              <1> 	; Read One Palette Register
  5903                              <1>         ; INPUT:
  5904                              <1> 	; BL = Palette register to read (00h-0Fh)
  5905                              <1> 	; OUTPUT:
  5906                              <1> 	; BH = Current rgbRGB value of specified register
  5907                              <1> 	;      for that attribute
  5908                              <1> 
  5909 00003054 80FB14              <1> 	cmp	bl, 14h
  5910                              <1> 	;ja	short no_actl_reg2
  5911 00003057 0F8727E5FFFF        <1> 	ja	VIDEO_RETURN
  5912                              <1> 
  5913 0000305D 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5914 00003061 EC                  <1> 	in	al, dx
  5915 00003062 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5916 00003066 88D8                <1> 	mov	al, bl
  5917 00003068 EE                  <1> 	out	dx, al
  5918 00003069 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  5919 0000306D EC                  <1> 	in	al, dx
  5920 0000306E 8844240D            <1> 	mov	[esp+13], al ; bh
  5921 00003072 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5922 00003076 EC                  <1> 	in	al, dx
  5923 00003077 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5924 0000307B B020                <1> 	mov	al, 20h
  5925 0000307D EE                  <1> 	out	dx, al
  5926                              <1> 	; ifdef VBOX
  5927 0000307E 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5928 00003082 EC                  <1> 	in	al, dx
  5929                              <1> 	; endif ; VBOX
  5930 00003083 E9FCE4FFFF          <1> 	jmp	VIDEO_RETURN
  5931                              <1> 
  5932                              <1> read_overscan_border_color:
  5933                              <1> 	; 10/08/2016
  5934                              <1> 	; Read Overscan Register
  5935                              <1> 	; OUTPUT:
  5936                              <1> 	; BH = current rgbRGB value 
  5937                              <1> 	;      of the overscan/border register
  5938                              <1> 
  5939 00003088 B311                <1> 	mov	bl, 11h
  5940 0000308A EBC8                <1> 	jmp	short get_single_palette_reg
  5941                              <1> 
  5942                              <1> get_all_palette_reg:
  5943                              <1> 	; 10/08/2016
  5944                              <1> 	; Read All Palette Registers
  5945                              <1> 	; EDX = Address of 17-byte buffer 
  5946                              <1> 	;	to receive data
  5947                              <1> 	
  5948 0000308C 89D7                <1> 	mov	edi, edx
  5949 0000308E 89E3                <1> 	mov	ebx, esp
  5950 00003090 89DE                <1> 	mov	esi, ebx
  5951 00003092 83EC14              <1> 	sub	esp, 20	 
  5952                              <1> 
  5953 00003095 B100                <1> 	mov	cl, 0
  5954                              <1> get_palette_loop:
  5955 00003097 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5956 0000309B EC                  <1> 	in	al, dx
  5957 0000309C 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5958 000030A0 88C8                <1> 	mov	al, cl
  5959 000030A2 EE                  <1> 	out	dx, al
  5960 000030A3 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  5961 000030A7 EC                  <1> 	in	al, dx
  5962 000030A8 8803                <1> 	mov	[ebx], al
  5963 000030AA 43                  <1> 	inc	ebx
  5964 000030AB FEC1                <1> 	inc	cl
  5965 000030AD 80F910              <1> 	cmp	cl, 10h
  5966 000030B0 75E5                <1> 	jne	short get_palette_loop
  5967 000030B2 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5968 000030B6 EC                  <1> 	in	al, dx
  5969 000030B7 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5970 000030BB B011                <1> 	mov	al, 11h
  5971 000030BD EE                  <1> 	out	dx, al
  5972 000030BE 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  5973 000030C2 EC                  <1> 	in	al, dx
  5974 000030C3 8803                <1> 	mov	[ebx], al
  5975 000030C5 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5976 000030C9 EC                  <1> 	in	al, dx
  5977 000030CA 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5978 000030CE B020                <1> 	mov	al, 20h
  5979 000030D0 EE                  <1> 	out	dx, al
  5980                              <1> 	; ifdef VBOX
  5981 000030D1 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5982 000030D5 EC                  <1> 	in	al, dx
  5983                              <1> 	; endif ; VBOX
  5984                              <1> 
  5985 000030D6 B911000000          <1> 	mov	ecx, 17 ; transfer (byte) count
  5986                              <1> 	; ESI = source address in system space
  5987                              <1> 	; EDI = user's buffer address
  5988 000030DB E8F4B60000          <1> 	call	transfer_to_user_buffer
  5989                              <1> 
  5990 000030E0 83C414              <1> 	add	esp, 20
  5991 000030E3 E99CE4FFFF          <1> 	jmp	VIDEO_RETURN
  5992                              <1> 
  5993                              <1> set_single_dac_reg:
  5994                              <1> 	; 10/08/2016
  5995                              <1> 	; Set One DAC Color Register
  5996                              <1> 	; BX = color register to set (0-255)
  5997                              <1>         ; CH = green value (00h-3Fh)
  5998                              <1>         ; CL = blue value  (00h-3Fh)
  5999                              <1>         ; DH = red value   (00h-3Fh)
  6000                              <1> 
  6001 000030E8 6652                <1> 	push	dx
  6002 000030EA 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
  6003 000030EE 88D8                <1> 	mov	al, bl
  6004 000030F0 EE                  <1> 	out	dx, al
  6005                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
  6006 000030F1 6642                <1> 	inc	dx
  6007 000030F3 6658                <1> 	pop	ax
  6008 000030F5 88E0                <1> 	mov	al, ah
  6009 000030F7 EE                  <1> 	out	dx, al
  6010 000030F8 88E8                <1> 	mov	al, ch
  6011 000030FA EE                  <1> 	out	dx, al
  6012 000030FB 88C8                <1> 	mov	al, cl
  6013 000030FD EE                  <1> 	out	dx, al
  6014 000030FE E981E4FFFF          <1> 	jmp	VIDEO_RETURN
  6015                              <1> 
  6016                              <1> set_all_dac_reg:
  6017                              <1> 	; 12/08/2016
  6018                              <1> 	; 11/08/2016
  6019                              <1> 	; 10/08/2016
  6020                              <1> 	; Set a Block of DAC Color Register
  6021                              <1> 	; BX = first DAC register to set (0-00FFh)
  6022                              <1> 	; ECX = number of registers to set (0-00FFh)
  6023                              <1> 	; EDX = addr of a table of R,G,B values 
  6024                              <1> 	;	(it will be CX*3 bytes long)
  6025                              <1> 
  6026 00003103 89D6                <1> 	mov	esi, edx ; user buffer
  6027 00003105 89CA                <1> 	mov	edx, ecx
  6028 00003107 66D1E1              <1> 	shl	cx, 1 ; *2
  6029 0000310A 01D1                <1> 	add	ecx, edx ; ecx = 3*ecx
  6030 0000310C 89E5                <1> 	mov	ebp, esp
  6031 0000310E 89EF                <1> 	mov	edi, ebp
  6032 00003110 29CF                <1> 	sub	edi, ecx
  6033 00003112 6683E7FC            <1> 	and	di, 0FFFCh ; (dword alignment)
  6034 00003116 89FC                <1> 	mov	esp, edi
  6035 00003118 E801B70000          <1> 	call	transfer_from_user_buffer
  6036                              <1> 	;jc	VIDEO_RETURN
  6037                              <1> 
  6038 0000311D 89D1                <1> 	mov	ecx, edx
  6039 0000311F 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
  6040 00003123 88D8                <1> 	mov	al, bl
  6041 00003125 EE                  <1> 	out	dx, al
  6042 00003126 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  6043                              <1> set_dac_loop:
  6044 0000312A 8A07                <1> 	mov	al, [edi]
  6045 0000312C EE                  <1> 	out	dx, al
  6046 0000312D 47                  <1> 	inc	edi
  6047 0000312E 8A07                <1> 	mov	al, [edi]
  6048 00003130 EE                  <1> 	out	dx, al
  6049 00003131 47                  <1> 	inc	edi
  6050 00003132 8A07                <1> 	mov	al, [edi]
  6051 00003134 EE                  <1> 	out	dx, al
  6052 00003135 47                  <1> 	inc	edi
  6053 00003136 6649                <1> 	dec	cx
  6054 00003138 75F0                <1> 	jnz	short set_dac_loop
  6055 0000313A 89EC                <1> 	mov	esp, ebp
  6056 0000313C E943E4FFFF          <1> 	jmp	VIDEO_RETURN
  6057                              <1> 
  6058                              <1> select_video_dac_color_page:
  6059                              <1> 	; 10/08/2016
  6060                              <1> 	; DAC Color Paging Functions
  6061                              <1> 	; BL = 00H = select color paging mode
  6062                              <1>         ;       BH = paging mode
  6063                              <1>         ;            00h = 4 blocks of 64 registers
  6064                              <1>         ;            01h = 16 blocks of 16 registers
  6065                              <1> 	; BL = 01H = activate color page
  6066                              <1>         ;       BH = DAC color page number
  6067                              <1>         ;            00h-03h (4-page/64-reg mode)
  6068                              <1>         ;            00h-0Fh (16-page/16-reg mode)
  6069                              <1> 
  6070 00003141 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6071 00003145 EC                  <1> 	in	al, dx
  6072 00003146 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6073 0000314A B010                <1> 	mov	al, 10h
  6074 0000314C EE                  <1> 	out	dx, al
  6075 0000314D 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  6076 00003151 EC                  <1> 	in	al, dx
  6077 00003152 80E301              <1> 	and	bl, 01h
  6078 00003155 750E                <1> 	jnz	short set_dac_page
  6079 00003157 247F                <1> 	and	al, 07Fh
  6080 00003159 C0E707              <1> 	shl	bh, 7
  6081 0000315C 08F8                <1> 	or	al, bh
  6082 0000315E 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6083 00003162 EE                  <1> 	out	dx, al
  6084 00003163 EB1D                <1> 	jmp	short set_actl_normal
  6085                              <1> set_dac_page:
  6086 00003165 6650                <1> 	push	ax
  6087 00003167 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6088 0000316B EC                  <1> 	in	al, dx
  6089 0000316C 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6090 00003170 B014                <1> 	mov	al, 14h
  6091 00003172 EE                  <1> 	out	dx, al
  6092 00003173 6658                <1> 	pop	ax
  6093 00003175 2480                <1> 	and	al, 80h
  6094 00003177 7503                <1> 	jnz	short set_dac_16_page
  6095 00003179 C0E702              <1> 	shl	bh, 2
  6096                              <1> set_dac_16_page:
  6097 0000317C 80E70F              <1> 	and	bh, 0Fh
  6098 0000317F 88F8                <1> 	mov	al, bh
  6099 00003181 EE                  <1> 	out	dx, al
  6100                              <1> set_actl_normal:
  6101 00003182 B020                <1> 	mov	al, 20h
  6102 00003184 EE                  <1> 	out	dx, al
  6103                              <1> 	; ifdef VBOX
  6104 00003185 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6105 00003189 EC                  <1> 	in	al, dx
  6106                              <1> 	; endif ; VBOX
  6107 0000318A E9F5E3FFFF          <1> 	jmp	VIDEO_RETURN	
  6108                              <1> 
  6109                              <1> read_single_dac_reg:
  6110                              <1> 	; 10/08/2016
  6111                              <1> 	; Read One DAC Color Register
  6112                              <1> 	; INPUT:
  6113                              <1> 	; BX = color register to read (0-255)
  6114                              <1> 	; OUTPUT:
  6115                              <1> 	; CH = green value (00h-3Fh)
  6116                              <1>         ; CL = blue value  (00h-3Fh)
  6117                              <1>         ; DH = red value   (00h-3Fh)
  6118                              <1> 
  6119 0000318F 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  6120 00003193 88D8                <1> 	mov	al, bl
  6121 00003195 EE                  <1> 	out	dx, al
  6122 00003196 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  6123 0000319A EC                  <1> 	in	al, dx
  6124 0000319B 88442415            <1> 	mov	[esp+21], al ; dh
  6125 0000319F EC                  <1> 	in	al, dx
  6126 000031A0 88C5                <1> 	mov	ch, al
  6127 000031A2 EC                  <1> 	in	al, dx
  6128 000031A3 88C1                <1> 	mov	cl, al
  6129 000031A5 66894C2410          <1> 	mov	[esp+16], cx ; cx
  6130 000031AA E9D5E3FFFF          <1> 	jmp	VIDEO_RETURN	
  6131                              <1> 
  6132                              <1> read_all_dac_reg:
  6133                              <1> 	; 12/08/2016
  6134                              <1> 	; 11/08/2016
  6135                              <1> 	; 10/08/2016
  6136                              <1> 	; Read a Block of DAC Color Registers
  6137                              <1>         ; BX = first DAC register to read (0-00FFh)
  6138                              <1>         ; ECX = number of registers to read (0-00FFh)
  6139                              <1>         ; EDX = addr of a buffer to hold R,G,B values
  6140                              <1> 	;	(CX*3 bytes long)
  6141                              <1> 
  6142 000031AF 89D7                <1> 	mov	edi, edx ; user buffer
  6143 000031B1 89CA                <1> 	mov	edx, ecx
  6144 000031B3 66D1E2              <1> 	shl	dx, 1 ; *2
  6145 000031B6 01CA                <1> 	add	edx, ecx ; edx = 3*ecx
  6146 000031B8 89E5                <1> 	mov	ebp, esp
  6147 000031BA 89EE                <1> 	mov	esi, ebp
  6148 000031BC 29D6                <1> 	sub	esi, edx
  6149 000031BE 6683E6FC            <1> 	and	si, 0FFFCh ; (dword alignment)
  6150 000031C2 89F4                <1> 	mov	esp, esi
  6151 000031C4 52                  <1> 	push	edx ; 3*ecx
  6152 000031C5 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  6153 000031C9 88D8                <1> 	mov	al, bl
  6154 000031CB EE                  <1> 	out	dx, al
  6155 000031CC 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  6156 000031D0 89F3                <1> 	mov	ebx, esi
  6157                              <1> read_dac_loop:
  6158 000031D2 EC                  <1> 	in	al, dx
  6159 000031D3 8803                <1> 	mov	[ebx], al
  6160 000031D5 43                  <1> 	inc	ebx
  6161 000031D6 EC                  <1> 	in	al, dx
  6162 000031D7 8803                <1> 	mov	[ebx], al
  6163 000031D9 43                  <1> 	inc	ebx
  6164 000031DA EC                  <1> 	in	al, dx
  6165 000031DB 8803                <1> 	mov	[ebx], al
  6166 000031DD 43                  <1> 	inc	ebx
  6167 000031DE 6649                <1> 	dec	cx
  6168 000031E0 75F0                <1> 	jnz	short read_dac_loop
  6169 000031E2 59                  <1> 	pop	ecx ; 3*ecx
  6170                              <1> 	; ECX = transfer (byte) count
  6171                              <1> 	; ESI = source address in system space
  6172                              <1> 	; EDI = user's buffer address
  6173 000031E3 E8ECB50000          <1> 	call	transfer_to_user_buffer
  6174 000031E8 89EC                <1> 	mov	esp, ebp
  6175 000031EA E995E3FFFF          <1> 	jmp	VIDEO_RETURN
  6176                              <1> 
  6177                              <1> set_pel_mask:
  6178                              <1> 	; 10/08/2016
  6179                              <1> 	; BL = mask value
  6180 000031EF 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK
  6181 000031F3 88D8                <1> 	mov	al, bl
  6182 000031F5 EE                  <1> 	out	dx, al
  6183 000031F6 E989E3FFFF          <1> 	jmp	VIDEO_RETURN
  6184                              <1> 
  6185                              <1> read_pel_mask:
  6186                              <1> 	; 10/08/2016
  6187                              <1> 	; Output: BL = mask value 
  6188 000031FB 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK
  6189 000031FF EC                  <1> 	in	al, dx
  6190 00003200 8844240C            <1> 	mov	[esp+12], al ; bl
  6191 00003204 E97BE3FFFF          <1> 	jmp	VIDEO_RETURN
  6192                              <1> 
  6193                              <1> read_video_dac_state:
  6194                              <1> 	; 10/08/2016
  6195                              <1> 	; Query DAC Color Paging State
  6196                              <1> 	; Output:
  6197                              <1> 	; BH = current active DAC color page
  6198                              <1>         ; BL = current active DAC paging mode
  6199                              <1> 
  6200 00003209 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6201 0000320D EC                  <1> 	in	al, dx
  6202 0000320E 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6203 00003212 B010                <1> 	mov	al, 10h
  6204 00003214 EE                  <1> 	out	dx, al
  6205 00003215 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  6206 00003219 EC                  <1> 	in	al, dx
  6207 0000321A 88C3                <1> 	mov	bl, al
  6208 0000321C C0EB07              <1> 	shr	bl, 7
  6209 0000321F 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6210 00003223 EC                  <1> 	in	al, dx
  6211 00003224 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6212 00003228 B014                <1> 	mov	al, 14h
  6213 0000322A EE                  <1> 	out	dx, al
  6214 0000322B 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  6215 0000322F EC                  <1> 	in	al, dx
  6216 00003230 88C7                <1> 	mov	bh, al
  6217 00003232 80E70F              <1> 	and	bh, 0Fh
  6218 00003235 F6C301              <1> 	test	bl, 01
  6219 00003238 7503                <1> 	jnz	short get_dac_16_page
  6220 0000323A C0EF02              <1> 	shr	bh, 2
  6221                              <1> get_dac_16_page:
  6222 0000323D 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6223 00003241 EC                  <1> 	in	al, dx
  6224 00003242 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  6225 00003246 B020                <1> 	mov	al, 20h
  6226 00003248 EE                  <1> 	out	dx, al
  6227                              <1> 	; ifdef VBOX
  6228 00003249 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  6229 0000324D EC                  <1> 	in	al, dx
  6230                              <1> 	; endif ; VBOX 
  6231 0000324E 66895C240C          <1> 	mov	[esp+12], bx ; bx
  6232 00003253 E92CE3FFFF          <1> 	jmp	VIDEO_RETURN
  6233                              <1> 
  6234                              <1> ; % include 'vidata.s' ; VIDEO DATA
  6235                              <1> 
  6236                              <1> ; /// End Of VIDEO FUNCTIONS ///
  1942                                  
  1943                                  setup_rtc_int:
  1944                                  ; source: http://wiki.osdev.org/RTC
  1945 00003258 FA                      	cli		; disable interrupts
  1946                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  1947                                  	; in order to change this ...
  1948                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  1949                                  	; (rate must be above 2 and not over 15)
  1950                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  1951 00003259 B08A                    	mov	al, 8Ah 
  1952 0000325B E670                    	out	70h, al ; set index to register A, disable NMI
  1953 0000325D 90                      	nop
  1954 0000325E E471                    	in	al, 71h ; get initial value of register A
  1955 00003260 88C4                    	mov 	ah, al
  1956 00003262 80E4F0                  	and	ah, 0F0h
  1957 00003265 B08A                    	mov	al, 8Ah 
  1958 00003267 E670                    	out	70h, al ; reset index to register A
  1959 00003269 88E0                    	mov	al, ah
  1960 0000326B 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  1961 0000326D E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  1962                                  	; enable RTC interrupt
  1963 0000326F B08B                    	mov	al, 8Bh ;
  1964 00003271 E670                    	out	70h, al ; select register B and disable NMI
  1965 00003273 90                      	nop
  1966 00003274 E471                    	in	al, 71h ; read the current value of register B
  1967 00003276 88C4                    	mov	ah, al  ;
  1968 00003278 B08B                    	mov 	al, 8Bh ;
  1969 0000327A E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  1970 0000327C 88E0                    	mov	al, ah  ;
  1971 0000327E 0C40                    	or	al, 40h ;
  1972 00003280 E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  1973 00003282 FB                      	sti
  1974 00003283 C3                      	retn
  1975                                  
  1976                                  ; Write memory information
  1977                                  ; 29/01/2016
  1978                                  ; 06/11/2014
  1979                                  ; 14/08/2015 
  1980                                  memory_info:	
  1981 00003284 A1[AC580100]            	mov	eax, [memory_size] ; in pages
  1982 00003289 50                      	push	eax
  1983 0000328A C1E00C                  	shl	eax, 12		   ; in bytes
  1984 0000328D BB0A000000              	mov	ebx, 10
  1985 00003292 89D9                    	mov	ecx, ebx	   ; 10
  1986 00003294 BE[31190100]            	mov	esi, mem_total_b_str	
  1987 00003299 E8BD000000              	call	bintdstr
  1988 0000329E 58                      	pop	eax
  1989 0000329F B107                    	mov	cl, 7
  1990 000032A1 BE[55190100]            	mov	esi, mem_total_p_str
  1991 000032A6 E8B0000000              	call	bintdstr	
  1992                                  	; 14/08/2015
  1993 000032AB E8C8000000              	call	calc_free_mem
  1994                                  	; edx = calculated free pages
  1995                                  	; ecx = 0
  1996 000032B0 A1[B0580100]            	mov 	eax, [free_pages]
  1997 000032B5 39D0                    	cmp	eax, edx ; calculated free mem value 
  1998                                  		; and initial free mem value are same or not?
  1999 000032B7 751D                    	jne 	short pmim ; print mem info with '?' if not
  2000 000032B9 52                      	push 	edx ; free memory in pages	
  2001                                  	;mov 	eax, edx
  2002 000032BA C1E00C                  	shl	eax, 12 ; convert page count
  2003                                  			; to byte count
  2004 000032BD B10A                    	mov	cl, 10
  2005 000032BF BE[75190100]            	mov	esi, free_mem_b_str
  2006 000032C4 E892000000              	call	bintdstr
  2007 000032C9 58                      	pop	eax
  2008 000032CA B107                    	mov	cl, 7
  2009 000032CC BE[99190100]            	mov	esi, free_mem_p_str
  2010 000032D1 E885000000              	call	bintdstr
  2011                                  pmim:
  2012 000032D6 BE[1F190100]            	mov	esi, msg_memory_info
  2013                                  	;
  2014 000032DB B407                    	mov	ah, 07h ; Black background, 
  2015                                  			; light gray forecolor
  2016                                  print_kmsg: ; 29/01/2016
  2017 000032DD 8825[D7580100]          	mov	[ccolor], ah
  2018                                  pkmsg_loop:
  2019 000032E3 AC                      	lodsb
  2020 000032E4 08C0                    	or	al, al
  2021 000032E6 7410                    	jz	short pkmsg_ok
  2022 000032E8 56                      	push	esi
  2023                                  	; 13/05/2016
  2024 000032E9 0FB61D[D7580100]        	movzx	ebx, byte [ccolor]
  2025                                  			; Video page 0 (bh=0)
  2026 000032F0 E8EDE9FFFF              	call	_write_tty
  2027 000032F5 5E                      	pop	esi
  2028 000032F6 EBEB                    	jmp	short pkmsg_loop
  2029                                  pkmsg_ok:
  2030 000032F8 C3                      	retn
  2031                                  
  2032                                  ; Convert binary number to hexadecimal string
  2033                                  ; 10/05/2015  
  2034                                  ; dsectpm.s (28/02/2015)
  2035                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  2036                                  ; 01/12/2014
  2037                                  ; 25/11/2014
  2038                                  ;
  2039                                  bytetohex:
  2040                                  	; INPUT ->
  2041                                  	; 	AL = byte (binary number)
  2042                                  	; OUTPUT ->
  2043                                  	;	AX = hexadecimal string
  2044                                  	;
  2045 000032F9 53                      	push	ebx
  2046 000032FA 31DB                    	xor	ebx, ebx
  2047 000032FC 88C3                    	mov	bl, al
  2048 000032FE C0EB04                  	shr	bl, 4
  2049 00003301 8A9B[4B330000]          	mov	bl, [ebx+hexchrs] 	 	
  2050 00003307 86D8                    	xchg	bl, al
  2051 00003309 80E30F                  	and	bl, 0Fh
  2052 0000330C 8AA3[4B330000]          	mov	ah, [ebx+hexchrs] 
  2053 00003312 5B                      	pop	ebx	
  2054 00003313 C3                      	retn
  2055                                  
  2056                                  wordtohex:
  2057                                  	; INPUT ->
  2058                                  	; 	AX = word (binary number)
  2059                                  	; OUTPUT ->
  2060                                  	;	EAX = hexadecimal string
  2061                                  	;
  2062 00003314 53                      	push	ebx
  2063 00003315 31DB                    	xor	ebx, ebx
  2064 00003317 86E0                    	xchg	ah, al
  2065 00003319 6650                    	push	ax
  2066 0000331B 88E3                    	mov	bl, ah
  2067 0000331D C0EB04                  	shr	bl, 4
  2068 00003320 8A83[4B330000]          	mov	al, [ebx+hexchrs] 	 	
  2069 00003326 88E3                    	mov	bl, ah
  2070 00003328 80E30F                  	and	bl, 0Fh
  2071 0000332B 8AA3[4B330000]          	mov	ah, [ebx+hexchrs]
  2072 00003331 C1E010                  	shl	eax, 16
  2073 00003334 6658                    	pop	ax
  2074 00003336 5B                      	pop	ebx
  2075 00003337 EBC0                    	jmp	short bytetohex
  2076                                  	;mov	bl, al
  2077                                  	;shr	bl, 4
  2078                                  	;mov	bl, [ebx+hexchrs] 	 	
  2079                                  	;xchg	bl, al	 	
  2080                                  	;and	bl, 0Fh
  2081                                  	;mov	ah, [ebx+hexchrs] 
  2082                                  	;pop	ebx	
  2083                                  	;retn
  2084                                  
  2085                                  dwordtohex:
  2086                                  	; INPUT ->
  2087                                  	; 	EAX = dword (binary number)
  2088                                  	; OUTPUT ->
  2089                                  	;	EDX:EAX = hexadecimal string
  2090                                  	;
  2091 00003339 50                      	push	eax
  2092 0000333A C1E810                  	shr	eax, 16
  2093 0000333D E8D2FFFFFF              	call	wordtohex
  2094 00003342 89C2                    	mov	edx, eax
  2095 00003344 58                      	pop	eax
  2096 00003345 E8CAFFFFFF              	call	wordtohex
  2097 0000334A C3                      	retn
  2098                                  
  2099                                  ; 10/05/2015
  2100                                  hex_digits:
  2101                                  hexchrs:
  2102 0000334B 303132333435363738-     	db '0123456789ABCDEF'
  2102 00003354 39414243444546     
  2103                                  
  2104                                  ; Convert binary number to decimal/numeric string
  2105                                  ; 06/11/2014
  2106                                  ; Temporary Code
  2107                                  ;
  2108                                  
  2109                                  bintdstr:
  2110                                  	; EAX = binary number
  2111                                  	; ESI = decimal/numeric string address
  2112                                  	; EBX = divisor (10)
  2113                                  	; ECX = string length (<=10)
  2114 0000335B 01CE                    	add	esi, ecx
  2115                                  btdstr0:
  2116 0000335D 4E                      	dec	esi
  2117 0000335E 31D2                    	xor	edx, edx
  2118 00003360 F7F3                    	div	ebx
  2119 00003362 80C230                  	add	dl, 30h
  2120 00003365 8816                    	mov	[esi], dl
  2121 00003367 FEC9                    	dec	cl
  2122 00003369 740C                    	jz	short btdstr2 ; 08/09/2016
  2123 0000336B 09C0                    	or	eax, eax
  2124 0000336D 75EE                    	jnz	short btdstr0
  2125                                  btdstr1:
  2126 0000336F 4E                      	dec	esi
  2127 00003370 C60620                          mov     byte [esi], 20h ; blank space
  2128 00003373 FEC9                    	dec	cl
  2129 00003375 75F8                    	jnz	short btdstr1
  2130                                  btdstr2:
  2131 00003377 C3                      	retn
  2132                                  
  2133                                  ; Calculate free memory pages on M.A.T.
  2134                                  ; 06/11/2014
  2135                                  ; Temporary Code
  2136                                  ;
  2137                                  
  2138                                  calc_free_mem:
  2139 00003378 31D2                    	xor	edx, edx
  2140                                  	;xor	ecx, ecx
  2141 0000337A 668B0D[C0580100]        	mov	cx, [mat_size] ; in pages
  2142 00003381 C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  2143 00003384 BE00001000              	mov	esi, MEM_ALLOC_TBL
  2144                                  cfm0:
  2145 00003389 AD                      	lodsd
  2146 0000338A 51                      	push	ecx
  2147 0000338B B920000000              	mov	ecx, 32
  2148                                  cfm1:
  2149 00003390 D1E8                    	shr	eax, 1
  2150 00003392 7301                    	jnc	short cfm2
  2151 00003394 42                      	inc	edx
  2152                                  cfm2:
  2153 00003395 E2F9                    	loop	cfm1
  2154 00003397 59                      	pop	ecx
  2155 00003398 E2EF                    	loop	cfm0
  2156 0000339A C3                      	retn
  2157                                  
  2158                                  %include 'diskio.s'  ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.2 - diskio.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/07/2020
     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 0000339B F8                  <1> 	clc ; 20/07/2020
    31 0000339C 9C                  <1> 	pushfd
    32 0000339D 0E                  <1> 	push 	cs
    33 0000339E E809000000          <1> 	call 	DISKETTE_IO_1
    34 000033A3 C3                  <1> 	retn
    35                              <1> 	
    36                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
    37                              <1> ;//////////////////////////////////////////////////////
    38                              <1> 
    39                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
    40                              <1> ; 20/02/2015
    41                              <1> ; 06/02/2015 (unix386.s)
    42                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
    43                              <1> ;
    44                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
    45                              <1> ;
    46                              <1> ; ADISK.EQU
    47                              <1> 
    48                              <1> ;----- Wait control constants 
    49                              <1> 
    50                              <1> ;amount of time to wait while RESET is active.
    51                              <1> 
    52                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
    53                              <1> 						;at 250 KBS xfer rate.
    54                              <1> 						;see INTEL MCS, 1985, pg. 5-456
    55                              <1> 
    56                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
    57                              <1> 						;status register to become valid
    58                              <1> 						;before re-reading.
    59                              <1> 
    60                              <1> ;After sending a byte to NEC, status register may remain
    61                              <1> ;incorrectly set for 24 us.
    62                              <1> 
    63                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
    64                              <1> 						;RQM low.
    65                              <1> 
    66                              <1> ; COMMON.MAC
    67                              <1> ;
    68                              <1> ;	Timing macros
    69                              <1> ;
    70                              <1> 
    71                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
    72                              <1> 		jmp short $+2
    73                              <1> %endmacro		
    74                              <1> 
    75                              <1> %macro		IODELAY  0			; NORMAL IODELAY
    76                              <1> 		jmp short $+2
    77                              <1> 		jmp short $+2
    78                              <1> %endmacro
    79                              <1> 
    80                              <1> %macro		NEWIODELAY 0
    81                              <1> 		out	0ebh,al
    82                              <1> %endmacro 
    83                              <1> 
    84                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
    85                              <1> ;;; WAIT_FOR_MEM
    86                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
    87                              <1> ;WAIT_FDU_INT_HI	equ	1
    88                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
    89                              <1> ;;; WAIT_FOR_PORT
    90                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
    91                              <1> ;WAIT_FDU_SEND_HI	equ	0
    92                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
    93                              <1> ;Time to wait while waiting for each byte of NEC results = .5
    94                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
    95                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
    96                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
    97                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
    98                              <1> ;;; WAIT_REFRESH
    99                              <1> ;amount of time to wait for head settle, per unit in parameter
   100                              <1> ;table = 1 ms.
   101                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
   102                              <1> 
   103                              <1> 
   104                              <1> ; //////////////// DISKETTE I/O ////////////////
   105                              <1> 
   106                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
   107                              <1> 
   108                              <1> ;----------------------------------------
   109                              <1> ;	EQUATES USED BY POST AND BIOS	:
   110                              <1> ;----------------------------------------
   111                              <1> 
   112                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   113                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   114                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
   115                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
   116                              <1> 
   117                              <1> ;----------------------------------------
   118                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
   119                              <1> ;-------------------------------------------------------------------------------
   120                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
   121                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
   122                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
   123                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
   124                              <1> 
   125                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
   126                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
   127                              <1> ;		EQU	011H		; - RESERVED			      ;C
   128                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
   129                              <1> ;		EQU	013H		; - RESERVED			      ;E
   130                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
   131                              <1> 
   132                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
   133                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
   134                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
   135                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
   136                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
   137                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
   138                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
   139                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
   140                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
   141                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
   142                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
   143                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
   144                              <1> 
   145                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
   146                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
   147                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
   148                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
   149                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
   150                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
   151                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
   152                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
   153                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
   154                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
   155                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
   156                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
   157                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
   158                              <1> 
   159                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
   160                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
   161                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
   162                              <1> 
   163                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
   164                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
   165                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
   166                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
   167                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
   168                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
   169                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
   170                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
   171                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
   172                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
   173                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
   174                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
   175                              <1> 
   176                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
   177                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
   178                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
   179                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
   180                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
   181                              <1> 
   182                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
   183                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
   184                              <1> ;INTA00		EQU	020H		; 8259 PORT
   185                              <1> INTA01		EQU	021H		; 8259 PORT
   186                              <1> INTB00		EQU	0A0H		; 2ND 8259
   187                              <1> INTB01		EQU	0A1H		;
   188                              <1> 
   189                              <1> ;-------------------------------------------------------------------------------
   190                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
   191                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
   192                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
   193                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
   194                              <1> ;-------------------------------------------------------------------------------
   195                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
   196                              <1> 
   197                              <1> ;-------------------------------------------------------------------------------
   198                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
   199                              <1> 
   200                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
   201                              <1> ; (unix386.s <-- dsectrm2.s)
   202                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
   203                              <1> 
   204                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
   205                              <1> ; 10/12/2014
   206                              <1> ;
   207                              <1> ;int40h:
   208                              <1> ;	pushf
   209                              <1> ;	push 	cs
   210                              <1> ;	;cli
   211                              <1> ;	call 	DISKETTE_IO_1
   212                              <1> ;	retn
   213                              <1> 
   214                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
   215                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
   216                              <1> ;
   217                              <1> 
   218                              <1> ;-- INT13H ---------------------------------------------------------------------
   219                              <1> ; DISKETTE I/O
   220                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
   221                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
   222                              <1> ; INPUT
   223                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
   224                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
   225                              <1> ;		ON ALL DRIVES
   226                              <1> ;------------------------------------------------------------------------------- 
   227                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
   228                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
   229                              <1> ;-------------------------------------------------------------------------------
   230                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
   231                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   232                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
   233                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
   234                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
   235                              <1> ;		320/360	320/360	    0-39
   236                              <1> ;		320/360	1.2M	    0-39
   237                              <1> ;		1.2M	1.2M	    0-79
   238                              <1> ;		720K	720K	    0-79
   239                              <1> ;		1.44M	1.44M	    0-79	
   240                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
   241                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
   242                              <1> ;		320/360	320/360	     1-8/9
   243                              <1> ;		320/360	1.2M	     1-8/9
   244                              <1> ;		1.2M	1.2M	     1-15
   245                              <1> ;		720K	720K	     1-9
   246                              <1> ;		1.44M	1.44M	     1-18		
   247                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
   248                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
   249                              <1> ;		320/360	320/360	        8/9
   250                              <1> ;		320/360	1.2M	        8/9
   251                              <1> ;		1.2M	1.2M		15
   252                              <1> ;		720K	720K		9
   253                              <1> ;		1.44M	1.44M		18
   254                              <1> ;
   255                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
   256                              <1> ;
   257                              <1> ;-------------------------------------------------------------------------------
   258                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
   259                              <1> ;-------------------------------------------------------------------------------
   260                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
   261                              <1> ;-------------------------------------------------------------------------------
   262                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
   263                              <1> ;-------------------------------------------------------------------------------
   264                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
   265                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
   266                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
   267                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
   268                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
   269                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
   270                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
   271                              <1> ;		READ/WRITE ACCESS.
   272                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
   273                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
   274                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
   275                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
   276                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
   277                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
   278                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
   279                              <1> ;
   280                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
   281                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
   282                              <1> ;		---------------------------------------------
   283                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
   284                              <1> ;		---------------------------------------------
   285                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
   286                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
   287                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
   288                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
   289                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
   290                              <1> ;		---------------------------------------------
   291                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
   292                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
   293                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
   294                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
   295                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
   296                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
   297                              <1> ;-------------------------------------------------------------------------------
   298                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
   299                              <1> ;	REGISTERS
   300                              <1> ;	  INPUT
   301                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   302                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
   303                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
   304                              <1> ;	  OUTPUT
   305                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
   306                              <1> ; 	    *** TRDOS 386 note: floppy disk parameter table (16 bytes)
   307                              <1> ;	    will be returned to user in EBX, buffer address *** 27/05/2016 ***		
   308                              <1> ;					
   309                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
   310                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   311                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   312                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
   313                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
   314                              <1> ;	    (BH) - 0
   315                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
   316                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
   317                              <1> ;	    (AX) - 0
   318                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
   319                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
   320                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
   321                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
   322                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
   323                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
   324                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
   325                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
   326                              <1> ;-------------------------------------------------------------------------------
   327                              <1> ;	(AH)= 15H  READ DASD TYPE
   328                              <1> ;	OUTPUT REGISTERS
   329                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
   330                              <1> ;		00 - DRIVE NOT PRESENT	
   331                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
   332                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
   333                              <1> ;		03 - RESERVED (FIXED DISK)
   334                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   335                              <1> ;-------------------------------------------------------------------------------
   336                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
   337                              <1> ;	OUTPUT REGISTERS
   338                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
   339                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
   340                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   341                              <1> ;-------------------------------------------------------------------------------
   342                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
   343                              <1> ;	INPUT REGISTERS
   344                              <1> ;	(AL) -	00 - NOT USED	
   345                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
   346                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
   347                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
   348                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
   349                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
   350                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
   351                              <1> ;-------------------------------------------------------------------------------
   352                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
   353                              <1> ;	INPUT REGISTERS
   354                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
   355                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   356                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   357                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
   358                              <1> ;	OUTPUT REGISTERS:
   359                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
   360                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
   361                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
   362                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
   363                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
   364                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
   365                              <1> ;-------------------------------------------------------------------------------
   366                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
   367                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
   368                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
   369                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
   370                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
   371                              <1> ;		CHANGE ERROR CODE
   372                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
   373                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
   374                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
   375                              <1> ;
   376                              <1> ; DATA VARIABLE -- @DISK_POINTER
   377                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
   378                              <1> ;-------------------------------------------------------------------------------
   379                              <1> ; OUTPUT FOR ALL FUNCTIONS
   380                              <1> ;	AH = STATUS OF OPERATION
   381                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
   382                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
   383                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
   384                              <1> ;		TYPE AH=(15)).
   385                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
   386                              <1> ;	FOR READ/WRITE/VERIFY
   387                              <1> ;		DS,BX,DX,CX PRESERVED
   388                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
   389                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
   390                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
   391                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
   392                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
   393                              <1> ;-------------------------------------------------------------------------------
   394                              <1> ;
   395                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
   396                              <1> ;
   397                              <1> ;   -----------------------------------------------------------------
   398                              <1> ;   |       |       |       |       |       |       |       |       |
   399                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
   400                              <1> ;   |       |       |       |       |       |       |       |       |
   401                              <1> ;   -----------------------------------------------------------------
   402                              <1> ;	|	|	|	|	|	|	|	|
   403                              <1> ;	|	|	|	|	|	-----------------
   404                              <1> ;	|	|	|	|	|		|
   405                              <1> ;	|	|	|	|    RESERVED		|
   406                              <1> ;	|	|	|	|		  PRESENT STATE
   407                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
   408                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
   409                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
   410                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
   411                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
   412                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
   413                              <1> ;	|	|	|	|	110: RESERVED
   414                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
   415                              <1> ;	|	|	|	|
   416                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
   417                              <1> ;	|	|	|
   418                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
   419                              <1> ;	|	|			DRIVE)
   420                              <1> ;	|	|
   421                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
   422                              <1> ;
   423                              <1> ;						00: 500 KBS
   424                              <1> ;						01: 300 KBS
   425                              <1> ;						10: 250 KBS
   426                              <1> ;						11: RESERVED
   427                              <1> ;
   428                              <1> ;
   429                              <1> ;-------------------------------------------------------------------------------
   430                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
   431                              <1> ;-------------------------------------------------------------------------------
   432                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
   433                              <1> ;-------------------------------------------------------------------------------
   434                              <1> 
   435                              <1> struc MD
   436 00000000 <res 00000001>      <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   437 00000001 <res 00000001>      <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   438 00000002 <res 00000001>      <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   439 00000003 <res 00000001>      <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
   440 00000004 <res 00000001>      <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
   441 00000005 <res 00000001>      <1> 	.GAP		resb	1	; GAP LENGTH
   442 00000006 <res 00000001>      <1> 	.DTL		resb	1	; DTL
   443 00000007 <res 00000001>      <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
   444 00000008 <res 00000001>      <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
   445 00000009 <res 00000001>      <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
   446 0000000A <res 00000001>      <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
   447 0000000B <res 00000001>      <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
   448 0000000C <res 00000001>      <1> 	.RATE		resb	1	; DATA TRANSFER RATE
   449                              <1> endstruc
   450                              <1> 
   451                              <1> BIT7OFF	EQU	7FH
   452                              <1> BIT7ON	EQU	80H
   453                              <1> 
   454                              <1> ;;int13h: ; 16/02/2015
   455                              <1> ;; 16/02/2015 - 21/02/2015
   456                              <1> int40h:
   457 000033A4 9C                  <1> 	pushfd
   458 000033A5 0E                  <1> 	push 	cs
   459 000033A6 E801000000          <1> 	call 	DISKETTE_IO_1
   460 000033AB C3                  <1> 	retn	
   461                              <1> 
   462                              <1> DISKETTE_IO_1:
   463                              <1> 
   464 000033AC FB                  <1> 	STI				; INTERRUPTS BACK ON
   465 000033AD 55                  <1> 	PUSH	eBP			; USER REGISTER
   466 000033AE 57                  <1> 	PUSH	eDI			; USER REGISTER
   467 000033AF 52                  <1> 	PUSH	eDX			; HEAD #, DRIVE # OR USER REGISTER
   468 000033B0 53                  <1> 	PUSH	eBX			; BUFFER OFFSET PARAMETER OR REGISTER
   469 000033B1 51                  <1> 	PUSH	eCX			; TRACK #-SECTOR # OR USER REGISTER
   470 000033B2 89E5                <1> 	MOV	eBP,eSP			; BP     => PARAMETER LIST DEP. ON AH
   471                              <1> 					; [BP]   = SECTOR #
   472                              <1> 					; [BP+1] = TRACK #
   473                              <1> 					; [BP+2] = BUFFER OFFSET
   474                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
   475                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
   476                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
   477                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
   478                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
   479                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
   480                              <1> 					; BH/[BP+3] = 0
   481                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
   482                              <1> 					; DH/[BP+5] = MAX HEAD #
   483                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
   484 000033B4 06                  <1> 	push	es ; 06/02/2015	
   485 000033B5 1E                  <1> 	PUSH	DS			; BUFFER SEGMENT PARM OR USER REGISTER
   486 000033B6 56                  <1> 	PUSH	eSI			; USER REGISTERS
   487                              <1> 	;CALL	DDS			; SEGMENT OF BIOS DATA AREA TO DS
   488                              <1> 	;mov	cx, cs
   489                              <1> 	;mov	ds, cx
   490 000033B7 66B91000            <1> 	mov	cx, KDATA
   491 000033BB 8ED9                <1>         mov     ds, cx
   492 000033BD 8EC1                <1>         mov     es, cx
   493                              <1> 
   494                              <1> 	;CMP	AH,(FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
   495 000033BF 80FC19              <1> 	cmp	ah,(FNC_TAE-FNC_TAB)/4  ; 18/02/2015
   496 000033C2 7202                <1> 	JB	short OK_FUNC		; FUNCTION OK
   497 000033C4 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
   498                              <1> OK_FUNC:
   499 000033C6 80FC01              <1> 	CMP	AH,1			; RESET OR STATUS ?
   500 000033C9 760C                <1> 	JBE	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
   501 000033CB 80FC08              <1> 	CMP	AH,8			; READ DRIVE PARMS ?
   502 000033CE 7407                <1> 	JZ	short OK_DRV		; IF SO DRIVE CHECKED LATER
   503 000033D0 80FA01              <1> 	CMP	DL,1			; DRIVES 0 AND 1 OK
   504 000033D3 7602                <1> 	JBE	short OK_DRV		; IF 0 OR 1 THEN JUMP
   505 000033D5 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
   506                              <1> OK_DRV:
   507 000033D7 31C9                <1> 	xor	ecx, ecx
   508                              <1> 	;mov	esi, ecx ; 08/02/2015
   509 000033D9 89CF                <1> 	mov	edi, ecx ; 08/02/2015
   510 000033DB 88E1                <1> 	MOV	CL,AH			; CL = FUNCTION
   511                              <1> 	;XOR	CH,CH			; CX = FUNCTION
   512                              <1> 	;SHL	CL, 1			; FUNCTION TIMES 2
   513 000033DD C0E102              <1> 	SHL	CL, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
   514 000033E0 BB[18340000]        <1> 	MOV	eBX,FNC_TAB		; LOAD START OF FUNCTION TABLE
   515 000033E5 01CB                <1> 	ADD	eBX,eCX			; ADD OFFSET INTO TABLE => ROUTINE
   516 000033E7 88F4                <1> 	MOV	AH,DH			; AX = HEAD #,# OF SECTORS OR DASD TYPE
   517 000033E9 30F6                <1> 	XOR	DH,DH			; DX = DRIVE #
   518 000033EB 6689C6              <1> 	MOV	SI,AX			; SI = HEAD #,# OF SECTORS OR DASD TYPE
   519 000033EE 6689D7              <1> 	MOV     DI,DX                   ; DI = DRIVE #
   520                              <1> 	;
   521                              <1> 	; 11/12/2014
   522 000033F1 8815[155D0000]      <1>         mov     [cfd], dl               ; current floppy drive (for 'GET_PARM')        
   523                              <1> 	;
   524 000033F7 8A25[30590100]      <1> 	MOV	AH, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
   525 000033FD C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; INITIALIZE FOR ALL OTHERS
   526                              <1> 
   527                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
   528                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
   529                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
   530                              <1> ;
   531                              <1> ;		DI	: DRIVE #
   532                              <1> ;		SI-HI	: HEAD #
   533                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
   534                              <1> ;		ES	: BUFFER SEGMENT
   535                              <1> ;		[BP]	: SECTOR #
   536                              <1> ;		[BP+1]	: TRACK #
   537                              <1> ;		[BP+2]	: BUFFER OFFSET
   538                              <1> ;
   539                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
   540                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
   541                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
   542                              <1> ;	SPECIFIC ERROR CODE.
   543                              <1> ;
   544                              <1> 					; (AH) = @DSKETTE_STATUS
   545 00003404 FF13                <1> 	CALL	dWORD [eBX]		; CALL THE REQUESTED FUNCTION
   546 00003406 5E                  <1> 	POP	eSI			; RESTORE ALL REGISTERS
   547 00003407 1F                  <1> 	POP	DS
   548 00003408 07                  <1> 	pop	es	; 06/02/2015
   549 00003409 59                  <1> 	POP	eCX
   550 0000340A 5B                  <1> 	POP	eBX
   551 0000340B 5A                  <1> 	POP	eDX
   552 0000340C 5F                  <1> 	POP	eDI
   553 0000340D 89E5                <1> 	MOV	eBP, eSP
   554 0000340F 50                  <1> 	PUSH	eAX
   555 00003410 9C                  <1> 	PUSHFd
   556 00003411 58                  <1> 	POP	eAX
   557                              <1> 	;MOV	[BP+6], AX
   558 00003412 89450C              <1> 	mov	[ebp+12], eax  ; 18/02/2015, flags
   559 00003415 58                  <1> 	POP	eAX
   560 00003416 5D                  <1> 	POP	eBP
   561 00003417 CF                  <1> 	IRETd
   562                              <1> 
   563                              <1> ;-------------------------------------------------------------------------------
   564                              <1> ; DW --> dd (06/02/2015)
   565 00003418 [7C340000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
   566 0000341C [F5340000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
   567 00003420 [06350000]          <1> 	dd	DSK_READ		; AH = 02H; READ
   568 00003424 [17350000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
   569 00003428 [28350000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
   570 0000342C [39350000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
   571 00003430 [BE350000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
   572 00003434 [BE350000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
   573 00003438 [CB350000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
   574 0000343C [BE350000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
   575 00003440 [BE350000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
   576 00003444 [BE350000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
   577 00003448 [BE350000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
   578 0000344C [BE350000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
   579 00003450 [BE350000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
   580 00003454 [BE350000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
   581 00003458 [BE350000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
   582 0000345C [BE350000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
   583 00003460 [BE350000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
   584 00003464 [BE350000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
   585 00003468 [BE350000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
   586 0000346C [A3360000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
   587 00003470 [CE360000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
   588 00003474 [08370000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
   589 00003478 [8B370000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
   590                              <1> FNC_TAE EQU     $                       ; END
   591                              <1> 
   592                              <1> ;-------------------------------------------------------------------------------
   593                              <1> ; DISK_RESET	(AH = 00H)	
   594                              <1> ;		RESET THE DISKETTE SYSTEM.
   595                              <1> ;
   596                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   597                              <1> ;-------------------------------------------------------------------------------
   598                              <1> DSK_RESET:
   599 0000347C 66BAF203            <1> 	MOV	DX,03F2H		; ADAPTER CONTROL PORT
   600 00003480 FA                  <1> 	CLI				; NO INTERRUPTS
   601 00003481 A0[2E590100]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
   602 00003486 243F                <1> 	AND	AL,00111111B		; KEEP SELECTED AND MOTOR ON BITS
   603 00003488 C0C004              <1> 	ROL	AL,4			; MOTOR VALUE TO HIGH NIBBLE
   604                              <1> 					; DRIVE SELECT TO LOW NIBBLE
   605 0000348B 0C08                <1> 	OR	AL,00001000B		; TURN ON INTERRUPT ENABLE
   606 0000348D EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
   607 0000348E C605[2D590100]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
   608                              <1> 	;JMP	$+2			; WAIT FOR I/O
   609                              <1> 	;JMP	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
   610                              <1> 					;      PULSE WIDTH)
   611                              <1> 	; 19/12/2014
   612                              <1> 	NEWIODELAY
   612 00003495 E6EB                <2>  out 0ebh,al
   613                              <1> 
   614                              <1> 	; 17/12/2014 
   615                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
   616 00003497 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
   617                              <1> wdw1:
   618                              <1> 	NEWIODELAY   ; 27/02/2015
   618 0000349C E6EB                <2>  out 0ebh,al
   619 0000349E E2FC                <1> 	loop	wdw1
   620                              <1> 	;
   621 000034A0 0C04                <1> 	OR	AL,00000100B		; TURN OFF RESET BIT
   622 000034A2 EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
   623                              <1> 	; 16/12/2014
   624                              <1> 	IODELAY
   624 000034A3 EB00                <2>  jmp short $+2
   624 000034A5 EB00                <2>  jmp short $+2
   625                              <1> 	;
   626                              <1> 	;STI				; ENABLE THE INTERRUPTS
   627 000034A7 E83C0C0000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
   628 000034AC 723E                <1> 	JC	short DR_ERR		; IF ERROR, RETURN IT
   629 000034AE 66B9C000            <1> 	MOV	CX,11000000B		; CL = EXPECTED @NEC_STATUS
   630                              <1> NXT_DRV:
   631 000034B2 6651                <1> 	PUSH	CX			; SAVE FOR CALL
   632 000034B4 B8[EA340000]        <1> 	MOV	eAX, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
   633 000034B9 50                  <1> 	PUSH	eAX			; "
   634 000034BA B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
   635 000034BC E81A0B0000          <1> 	CALL	NEC_OUTPUT
   636 000034C1 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
   637 000034C2 E8510C0000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
   638 000034C7 6659                <1> 	POP	CX			; RESTORE AFTER CALL
   639 000034C9 7221                <1> 	JC	short DR_ERR		; ERROR RETURN
   640 000034CB 3A0D[31590100]      <1> 	CMP	CL, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
   641 000034D1 7519                <1> 	JNZ	short DR_ERR		; EVERYTHING OK
   642 000034D3 FEC1                <1> 	INC	CL			; NEXT EXPECTED @NEC_STATUS
   643 000034D5 80F9C3              <1> 	CMP	CL,11000011B		; ALL POSSIBLE DRIVES CLEARED
   644 000034D8 76D8                <1> 	JBE	short NXT_DRV		; FALL THRU IF 11000100B OR >
   645                              <1> 	;
   646 000034DA E869030000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
   647                              <1> RESBAC:
   648 000034DF E81D090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   649 000034E4 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   650 000034E7 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   651 000034E9 C3                  <1> 	RETn		
   652                              <1> DR_POP_ERR:
   653 000034EA 6659                <1> 	POP	CX			; CLEAR STACK
   654                              <1> DR_ERR:
   655 000034EC 800D[30590100]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; SET ERROR CODE
   656 000034F3 EBEA                <1> 	JMP	SHORT RESBAC		; RETURN FROM RESET
   657                              <1> 
   658                              <1> ;-------------------------------------------------------------------------------
   659                              <1> ; DISK_STATUS	(AH = 01H)
   660                              <1> ;	DISKETTE STATUS.
   661                              <1> ;
   662                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
   663                              <1> ;
   664                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
   665                              <1> ;-------------------------------------------------------------------------------
   666                              <1> DSK_STATUS:
   667 000034F5 8825[30590100]      <1> 	MOV	[DSKETTE_STATUS],AH	; PUT BACK FOR SETUP END
   668 000034FB E801090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   669 00003500 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   670 00003503 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   671 00003505 C3                  <1> 	RETn		
   672                              <1> 
   673                              <1> ;-------------------------------------------------------------------------------
   674                              <1> ; DISK_READ	(AH = 02H)	
   675                              <1> ;	DISKETTE READ.
   676                              <1> ;
   677                              <1> ; ON ENTRY:	DI	: DRIVE #
   678                              <1> ;		SI-HI	: HEAD #
   679                              <1> ;		SI-LOW	: # OF SECTORS
   680                              <1> ;		ES	: BUFFER SEGMENT
   681                              <1> ;		[BP]	: SECTOR #
   682                              <1> ;		[BP+1]	: TRACK #
   683                              <1> ;		[BP+2]	: BUFFER OFFSET
   684                              <1> ;
   685                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   686                              <1> ;-------------------------------------------------------------------------------
   687                              <1> 
   688                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   689                              <1> 
   690                              <1> DSK_READ:
   691 00003506 8025[2E590100]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
   692 0000350D 66B846E6            <1> 	MOV	AX,0E646H		; AX = NEC COMMAND, DMA COMMAND
   693 00003511 E83C040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   694 00003516 C3                  <1> 	RETn
   695                              <1> 
   696                              <1> ;-------------------------------------------------------------------------------
   697                              <1> ; DISK_WRITE	(AH = 03H)
   698                              <1> ;	DISKETTE WRITE.
   699                              <1> ;
   700                              <1> ; ON ENTRY:	DI	: DRIVE #
   701                              <1> ;		SI-HI	: HEAD #
   702                              <1> ;		SI-LOW	: # OF SECTORS
   703                              <1> ;		ES	: BUFFER SEGMENT
   704                              <1> ;		[BP]	: SECTOR #
   705                              <1> ;		[BP+1]	: TRACK #
   706                              <1> ;		[BP+2]	: BUFFER OFFSET
   707                              <1> ;
   708                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   709                              <1> ;-------------------------------------------------------------------------------
   710                              <1> 
   711                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   712                              <1> 
   713                              <1> DSK_WRITE:
   714 00003517 66B84AC5            <1> 	MOV	AX,0C54AH		; AX = NEC COMMAND, DMA COMMAND
   715 0000351B 800D[2E590100]80    <1>         OR      byte [MOTOR_STATUS],10000000B ; INDICATE WRITE OPERATION
   716 00003522 E82B040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   717 00003527 C3                  <1> 	RETn
   718                              <1> 
   719                              <1> ;-------------------------------------------------------------------------------
   720                              <1> ; DISK_VERF	(AH = 04H)
   721                              <1> ;	DISKETTE VERIFY.
   722                              <1> ;
   723                              <1> ; ON ENTRY:	DI	: DRIVE #
   724                              <1> ;		SI-HI	: HEAD #
   725                              <1> ;		SI-LOW	: # OF SECTORS
   726                              <1> ;		ES	: BUFFER SEGMENT
   727                              <1> ;		[BP]	: SECTOR #
   728                              <1> ;		[BP+1]	: TRACK #
   729                              <1> ;		[BP+2]	: BUFFER OFFSET
   730                              <1> ;
   731                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   732                              <1> ;-------------------------------------------------------------------------------
   733                              <1> DSK_VERF:
   734 00003528 8025[2E590100]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
   735 0000352F 66B842E6            <1> 	MOV	AX,0E642H		; AX = NEC COMMAND, DMA COMMAND
   736 00003533 E81A040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   737 00003538 C3                  <1> 	RETn
   738                              <1> 
   739                              <1> ;-------------------------------------------------------------------------------
   740                              <1> ; DISK_FORMAT	(AH = 05H)
   741                              <1> ;	DISKETTE FORMAT.
   742                              <1> ;
   743                              <1> ; ON ENTRY:	DI	: DRIVE #
   744                              <1> ;		SI-HI	: HEAD #
   745                              <1> ;		SI-LOW	: # OF SECTORS
   746                              <1> ;		ES	: BUFFER SEGMENT
   747                              <1> ;		[BP]	: SECTOR #
   748                              <1> ;		[BP+1]	: TRACK #
   749                              <1> ;		[BP+2]	: BUFFER OFFSET
   750                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
   751                              <1> ;
   752                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   753                              <1> ;-------------------------------------------------------------------------------
   754                              <1> DSK_FORMAT:
   755 00003539 E853030000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
   756 0000353E E84F050000          <1> 	CALL	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
   757 00003543 800D[2E590100]80    <1>         OR      byte [MOTOR_STATUS], 10000000B ; INDICATE WRITE OPERATION
   758 0000354A E897050000          <1> 	CALL	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
   759 0000354F 725D                <1>         JC      short FM_DON            ; MEDIA CHANGED, SKIP
   760 00003551 E8F2020000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
   761 00003556 E8FD050000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
   762 0000355B 7405                <1>         JZ      short FM_WR             ; YES, SKIP SPECIFY COMMAND
   763 0000355D E8D4050000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO CONTROLLER
   764                              <1> FM_WR:
   765 00003562 E88A060000          <1> 	CALL	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
   766 00003567 7245                <1>         JC      short FM_DON            ; RETURN WITH ERROR
   767 00003569 B44D                <1> 	MOV	AH,04DH			; ESTABLISH THE FORMAT COMMAND
   768 0000356B E8E7060000          <1> 	CALL	NEC_INIT		; INITIALIZE THE NEC
   769 00003570 723C                <1>         JC      short FM_DON            ; ERROR - EXIT
   770 00003572 B8[AE350000]        <1>         MOV     eAX, FM_DON             ; LOAD ERROR ADDRESS
   771 00003577 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
   772 00003578 B203                <1> 	MOV	DL,3			; BYTES/SECTOR VALUE TO NEC
   773 0000357A E856090000          <1> 	CALL	GET_PARM
   774 0000357F E8570A0000          <1> 	CALL	NEC_OUTPUT
   775 00003584 B204                <1> 	MOV	DL,4			; SECTORS/TRACK VALUE TO NEC
   776 00003586 E84A090000          <1> 	CALL	GET_PARM
   777 0000358B E84B0A0000          <1> 	CALL	NEC_OUTPUT
   778 00003590 B207                <1> 	MOV	DL,7			; GAP LENGTH VALUE TO NEC
   779 00003592 E83E090000          <1> 	CALL	GET_PARM
   780 00003597 E83F0A0000          <1> 	CALL	NEC_OUTPUT
   781 0000359C B208                <1> 	MOV	DL,8			; FILLER BYTE TO NEC
   782 0000359E E832090000          <1> 	CALL	GET_PARM
   783 000035A3 E8330A0000          <1> 	CALL	NEC_OUTPUT
   784 000035A8 58                  <1> 	POP	eAX			; THROW AWAY ERROR
   785 000035A9 E827070000          <1> 	CALL	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
   786                              <1> FM_DON:
   787 000035AE E80F030000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   788 000035B3 E849080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
   789 000035B8 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   790 000035BB 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   791 000035BD C3                  <1> 	RETn
   792                              <1> 
   793                              <1> ;-------------------------------------------------------------------------------
   794                              <1> ; FNC_ERR
   795                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
   796                              <1> ;	SET BAD COMMAND IN STATUS.
   797                              <1> ;
   798                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   799                              <1> ;-------------------------------------------------------------------------------
   800                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
   801 000035BE 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
   802 000035C1 B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
   803 000035C3 8825[30590100]      <1> 	MOV	[DSKETTE_STATUS],AH	; STORE IN DATA AREA
   804 000035C9 F9                  <1> 	STC				; SET CARRY INDICATING ERROR
   805 000035CA C3                  <1> 	RETn
   806                              <1> 
   807                              <1> ; 01/06/2016
   808                              <1> ; 28/05/2016
   809                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v.2.0)
   810                              <1> ;-------------------------------------------------------------------------------
   811                              <1> ; DISK_PARMS	(AH = 08H)	
   812                              <1> ;	READ DRIVE PARAMETERS.
   813                              <1> ;
   814                              <1> ; ON ENTRY:	DI : DRIVE #
   815                              <1> ;		; 27/05/2016
   816                              <1> ;		EBX = Buffer Address for floppy disk parameters table (16 bytes)
   817                              <1> ;
   818                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
   819                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
   820                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
   821                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
   822                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
   823                              <1> ;		BH/[BP+3] = 0
   824                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
   825                              <1> ;		DH/[BP+5] = MAX HEAD #
   826                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
   827                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
   828                              <1> ;		;DI/[BP+6] = OFFSET TO DISK_BASE
   829                              <1> ;		;ES        = SEGMENT OF DISK_BASE
   830                              <1> ;
   831                              <1> ;		AX        = 0
   832                              <1> ;
   833                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
   834                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
   835                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
   836                              <1> ;		       CALLER.
   837                              <1> ;-------------------------------------------------------------------------------
   838                              <1> DSK_PARMS:
   839 000035CB E8C1020000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
   840                              <1>      ;	MOV	WORD [BP+2],0		; DRIVE TYPE = 0
   841                              <1>      ;  MOV     AX, [EQUIP_FLAG]        ; LOAD EQUIPMENT FLAG FOR # DISKETTES
   842                              <1>      ;  AND     AL,11000001B            ; KEEP DISKETTE DRIVE BITS
   843                              <1>      ;  MOV     DL,2                    ; DISKETTE DRIVES = 2
   844                              <1>      ;  CMP     AL,01000001B            ; 2 DRIVES INSTALLED ?
   845                              <1>      ;  JZ      short STO_DL            ; IF YES JUMP
   846                              <1>      ;  DEC     DL                      ; DISKETTE DRIVES = 1
   847                              <1>      ;  CMP     AL,00000001B            ; 1 DRIVE INSTALLED ?
   848                              <1>      ;  JNZ     short NON_DRV           ; IF NO JUMP
   849 000035D0 29D2                <1> 	sub	edx, edx
   850 000035D2 66A1[265D0000]      <1> 	mov     ax, [fd0_type]
   851 000035D8 6621C0              <1> 	and     ax, ax
   852 000035DB 0F848A000000        <1>         jz      NON_DRV
   853 000035E1 FEC2                <1> 	inc     dl
   854 000035E3 20E4                <1> 	and     ah, ah
   855 000035E5 7402                <1> 	jz      short STO_DL
   856 000035E7 FEC2                <1> 	inc     dl
   857                              <1> STO_DL:
   858                              <1> 	;MOV	[BP+4],DL		; STORE NUMBER OF DRIVES
   859 000035E9 895508              <1> 	mov	[ebp+8], edx ; 20/02/2015	 	
   860 000035EC 6683FF01            <1> 	CMP	DI,1			; CHECK FOR VALID DRIVE
   861 000035F0 777C                <1> 	JA	short NON_DRV1		; DRIVE INVALID
   862                              <1> 	;MOV	BYTE [BP+5],1		; MAXIMUM HEAD NUMBER =	1
   863 000035F2 C6450901            <1> 	mov	byte [ebp+9], 1  ; 20/02/2015	
   864 000035F6 E8D1080000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
   865                              <1> 	;;20/02/2015
   866                              <1> 	;;JC	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
   867                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE TYPE
   868 000035FB 740F                <1> 	JZ	short CHK_EST		; JUMP IF SO
   869 000035FD E81B020000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   870 00003602 7208                <1> 	JC	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
   871                              <1> 	;MOV	[BP+2],AL		; STORE VALID CMOS DRIVE TYPE
   872                              <1>         ;mov	[ebp+4], al ; 06/02/2015
   873 00003604 8A4B04              <1> 	MOV     CL, [eBX+MD.SEC_TRK]     ; GET SECTOR/TRACK
   874 00003607 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]     ; GET MAX. TRACK NUMBER
   875 0000360A EB36                <1> 	JMP	SHORT STO_CX		; CMOS GOOD, USE CMOS
   876                              <1> CHK_EST:
   877 0000360C 8AA7[3D590100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; LOAD STATE FOR THIS DRIVE
   878 00003612 F6C410              <1> 	TEST	AH,MED_DET		; CHECK FOR ESTABLISHED STATE
   879 00003615 7457                <1> 	JZ	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
   880                              <1> USE_EST:
   881 00003617 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE STATE
   882 0000361A 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
   883 0000361D 7570                <1> 	JNE	short USE_EST2		; NO, GO CHECK OTHER RATE
   884                              <1> 
   885                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
   886                              <1> 
   887 0000361F B001                <1> 	MOV	AL,01			; DRIVE TYPE 1 (360KB)
   888 00003621 E8F7010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   889 00003626 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   890 00003629 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   891 0000362C F687[3D590100]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; 80 TRACK ?
   892 00003633 740D                <1> 	JZ	short STO_CX		; MUST BE 360KB DRIVE 
   893                              <1> 
   894                              <1> ;-----	IT IS 1.44 MB DRIVE
   895                              <1> 
   896                              <1> PARM144:
   897 00003635 B004                <1> 	MOV	AL,04			; DRIVE TYPE 4 (1.44MB)
   898 00003637 E8E1010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   899 0000363C 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   900 0000363F 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   901                              <1> STO_CX:
   902 00003642 894D00              <1> 	MOV	[eBP],eCX		; SAVE POINTER IN STACK FOR RETURN
   903                              <1> ES_DI:
   904                              <1> 	;MOV	[BP+6],BX		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
   905                              <1> 	;mov	[ebp+12], ebx ; 06/02/2015
   906                              <1> 	;MOV	AX,CS			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
   907                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
   908                              <1> 	;
   909                              <1> 	; 28/05/2016
   910                              <1> 	; 27/05/2016
   911                              <1> 	; return floppy disk parameters table to user
   912                              <1> 	; in user's buffer, which is pointed by EBX
   913                              <1> 	;
   914 00003645 57                  <1> 	push	edi
   915 00003646 8B7D04              <1> 	mov	edi, [ebp+4]  		; ebx (input), user's buffer address
   916 00003649 0FB6C0              <1> 	movzx	eax, al
   917 0000364C 894504              <1>         mov	[ebp+4], eax   ; ebx	; drive type (for floppy drives)
   918                              <1> 	; 01/06/2016 (INT 33h, disk type return for floppy disks, in BL)
   919 0000364F A3[2C650100]        <1> 	mov	[user_buffer], eax	; 01/06/2016 (overwrite ebx return value)
   920                              <1> 	;(INT 33h, Function 08h will replace user's buffer addr with disk type!)
   921                              <1> 	;
   922 00003654 89DE                <1> 	mov	esi, ebx 		; floppy disk parameter table (16 bytes)
   923 00003656 B910000000          <1> 	mov	ecx, 16 ; 16 bytes
   924 0000365B E874B10000          <1>         call    transfer_to_user_buffer ; trdosk6.s (16/05/2016)
   925 00003660 5F                  <1> 	pop	edi	
   926                              <1> DP_OUT:
   927 00003661 E85C020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   928 00003666 6631C0              <1> 	XOR	AX,AX			; CLEAR
   929 00003669 F8                  <1> 	CLC
   930 0000366A C3                  <1> 	RETn
   931                              <1> 
   932                              <1> ;-----	NO DRIYE PRESENT HANDLER
   933                              <1> 
   934                              <1> NON_DRV:
   935                              <1> 	;MOV	BYTE [BP+4],0		; CLEAR NUMBER OF DRIVES
   936 0000366B 895508              <1> 	mov	[ebp+8], edx ; 0 ; 20/02/2015
   937                              <1> NON_DRV1:
   938 0000366E 6681FF8000          <1> 	CMP	DI,80H			; CHECK FOR FIXED MEDIA TYPE REQUEST
   939 00003673 720C                <1> 	JB	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
   940                              <1> 
   941                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
   942                              <1> 	
   943 00003675 E848020000          <1> 	CALL	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
   944 0000367A 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
   945 0000367D B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
   946 0000367F F9                  <1> 	STC
   947 00003680 C3                  <1> 	RETn
   948                              <1> 
   949                              <1> NON_DRV2:
   950                              <1> 	;XOR	AX,AX			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
   951 00003681 31C0                <1> 	xor	eax, eax	
   952 00003683 66894500            <1> 	MOV	[eBP],AX		; TRACKS, SECTORS/TRACK = 0
   953                              <1> 	;MOV	[BP+5],AH		; HEAD = 0
   954 00003687 886509              <1> 	mov	[ebp+9], ah ; 06/02/2015
   955                              <1> 	;MOV	[BP+6],AX		; OFFSET TO DISK_BASE = 0
   956 0000368A 89450C              <1> 	mov	[ebp+12], eax
   957                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
   958 0000368D EBD2                <1> 	JMP	SHORT DP_OUT
   959                              <1> 
   960                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
   961                              <1> 
   962                              <1> USE_EST2:
   963 0000368F B002                <1> 	MOV	AL,02			; DRIVE TYPE 2 (1.2MB)
   964 00003691 E887010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
   965 00003696 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
   966 00003699 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
   967 0000369C 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
   968 0000369F 74A1                <1> 	JZ	short STO_CX		; MUST BE 1.2MB DRIVE
   969 000036A1 EB92                <1> 	JMP	SHORT PARM144		; ELSE, IT IS 1.44MB DRIVE 
   970                              <1> 
   971                              <1> ;-------------------------------------------------------------------------------
   972                              <1> ; DISK_TYPE (AH = 15H)	
   973                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
   974                              <1> ;
   975                              <1> ;  ON ENTRY:	DI = DRIVE #
   976                              <1> ;
   977                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
   978                              <1> ;-------------------------------------------------------------------------------
   979                              <1> DSK_TYPE:
   980 000036A3 E8E9010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
   981 000036A8 8A87[3D590100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET PRESENT STATE INFORMATION
   982 000036AE 08C0                <1> 	OR	AL,AL			; CHECK FOR NO DRIVE
   983 000036B0 7418                <1> 	JZ	short NO_DRV
   984 000036B2 B401                <1> 	MOV	AH,NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
   985 000036B4 A801                <1> 	TEST	AL,TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
   986 000036B6 7402                <1> 	JZ	short DT_BACK			; IF NO JUMP
   987 000036B8 B402                <1> 	MOV	AH,CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
   988                              <1> DT_BACK:
   989 000036BA 6650                <1> 	PUSH	AX			; SAVE RETURN VALUE
   990 000036BC E801020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   991 000036C1 6658                <1> 	POP	AX			; RESTORE RETURN VALUE
   992 000036C3 F8                  <1> 	CLC				; NO ERROR
   993 000036C4 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
   994 000036C7 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
   995 000036C9 C3                  <1> 	RETn
   996                              <1> NO_DRV:	
   997 000036CA 30E4                <1> 	XOR	AH,AH			; NO DRIVE PRESENT OR UNKNOWN
   998 000036CC EBEC                <1> 	JMP	SHORT DT_BACK
   999                              <1> 
  1000                              <1> ;-------------------------------------------------------------------------------
  1001                              <1> ; DISK_CHANGE	(AH = 16H)
  1002                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  1003                              <1> ;
  1004                              <1> ; ON ENTRY:	DI = DRIVE #
  1005                              <1> ;
  1006                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  1007                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  1008                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  1009                              <1> ;-------------------------------------------------------------------------------
  1010                              <1> DSK_CHANGE:
  1011 000036CE E8BE010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1012 000036D3 8A87[3D590100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET MEDIA STATE INFORMATION
  1013 000036D9 08C0                <1> 	OR	AL,AL			; DRIVE PRESENT ?
  1014 000036DB 7422                <1> 	JZ	short DC_NON		; JUMP IF NO DRIVE
  1015 000036DD A801                <1> 	TEST	AL,TRK_CAPA		; 80 TRACK DRIVE ?
  1016 000036DF 7407                <1> 	JZ	short SETIT		; IF SO , CHECK CHANGE LINE
  1017                              <1> DC0:
  1018 000036E1 E88D0A0000          <1>         CALL    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  1019 000036E6 7407                <1> 	JZ	short FINIS		; CHANGE LINE NOT ACTIVE
  1020                              <1> 
  1021 000036E8 C605[30590100]06    <1> SETIT:	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  1022                              <1> 
  1023 000036EF E8CE010000          <1> FINIS:	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1024 000036F4 E808070000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1025 000036F9 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  1026 000036FC 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  1027 000036FE C3                  <1> 	RETn
  1028                              <1> DC_NON:
  1029 000036FF 800D[30590100]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  1030 00003706 EBE7                <1> 	JMP	SHORT FINIS
  1031                              <1> 
  1032                              <1> ;-------------------------------------------------------------------------------
  1033                              <1> ; FORMAT_SET	(AH = 17H)
  1034                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  1035                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  1036                              <1> ;
  1037                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  1038                              <1> ;		DI     = DRIVE #
  1039                              <1> ;
  1040                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  1041                              <1> ;		AH = @DSKETTE_STATUS
  1042                              <1> ;		CY = 1 IF ERROR
  1043                              <1> ;-------------------------------------------------------------------------------
  1044                              <1> FORMAT_SET:
  1045 00003708 E884010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1046 0000370D 6656                <1> 	PUSH	SI			; SAVE DASD TYPE
  1047 0000370F 6689F0              <1> 	MOV	AX,SI			; AH = ? , AL , DASD TYPE
  1048 00003712 30E4                <1> 	XOR	AH,AH			; AH , 0 , AL , DASD TYPE
  1049 00003714 6689C6              <1> 	MOV	SI,AX			; SI = DASD TYPE
  1050 00003717 80A7[3D590100]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1051 0000371E 664E                <1> 	DEC	SI			; CHECK FOR 320/360K MEDIA & DRIVE
  1052 00003720 7509                <1> 	JNZ	short NOT_320		; BYPASS IF NOT
  1053 00003722 808F[3D590100]90    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_250 ; SET TO 320/360
  1054 00003729 EB48                <1> 	JMP	SHORT S0
  1055                              <1> 
  1056                              <1> NOT_320:
  1057 0000372B E8B6030000          <1> 	CALL	MED_CHANGE		; CHECK FOR TIME_OUT
  1058 00003730 803D[30590100]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT
  1059 00003737 743A                <1> 	JZ	short S0		; IF TIME OUT TELL CALLER
  1060                              <1> S3:
  1061 00003739 664E                <1> 	DEC	SI			; CHECK FOR 320/360K IN 1.2M DRIVE
  1062 0000373B 7509                <1> 	JNZ	short NOT_320_12	; BYPASS IF NOT
  1063 0000373D 808F[3D590100]70    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  1064 00003744 EB2D                <1> 	JMP	SHORT S0
  1065                              <1> 
  1066                              <1> NOT_320_12:
  1067 00003746 664E                <1> 	DEC	SI			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  1068 00003748 7509                <1> 	JNZ	short NOT_12		; BYPASS IF NOT
  1069 0000374A 808F[3D590100]10    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_500 ; SET STATE VARIABLE
  1070 00003751 EB20                <1> 	JMP	SHORT S0		; RETURN TO CALLER
  1071                              <1> 
  1072                              <1> NOT_12:	
  1073 00003753 664E                <1> 	DEC	SI			; CHECK FOR SET DASD TYPE 04
  1074 00003755 752B                <1> 	JNZ	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  1075                              <1> 
  1076 00003757 F687[3D590100]04    <1> 	TEST	byte [DSK_STATE+eDI], DRV_DET ; DRIVE DETERMINED ?
  1077 0000375E 740B                <1> 	JZ	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  1078 00003760 B050                <1> 	MOV	AL,MED_DET+RATE_300
  1079 00003762 F687[3D590100]02    <1>         TEST    byte [DSK_STATE+eDI], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  1080 00003769 7502                <1> 	JNZ	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  1081                              <1> 
  1082                              <1> ASSUME:
  1083 0000376B B090                <1> 	MOV	AL,MED_DET+RATE_250	; SET UP
  1084                              <1> 
  1085                              <1> OR_IT_IN:
  1086 0000376D 0887[3D590100]      <1> 	OR	[DSK_STATE+eDI], AL	; OR IN THE CORRECT STATE
  1087                              <1> S0:
  1088 00003773 E84A010000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1089 00003778 E884060000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1090 0000377D 665B                <1> 	POP	BX			; GET SAVED AL TO BL
  1091 0000377F 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  1092 00003781 C3                  <1> 	RETn
  1093                              <1> 
  1094                              <1> FS_ERR:
  1095 00003782 C605[30590100]01    <1> 	MOV	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  1096 00003789 EBE8                <1> 	JMP	SHORT S0
  1097                              <1> 
  1098                              <1> ;-------------------------------------------------------------------------------
  1099                              <1> ; SET_MEDIA	(AH = 18H)
  1100                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  1101                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  1102                              <1> ;
  1103                              <1> ; ON ENTRY:
  1104                              <1> ;	[BP]	= SECTOR PER TRACK
  1105                              <1> ;	[BP+1]	= TRACK #
  1106                              <1> ;	DI	= DRIVE #
  1107                              <1> ;
  1108                              <1> ; ON EXIT:
  1109                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  1110                              <1> ;	IF NO ERROR:
  1111                              <1> ;		AH = 0
  1112                              <1> ;		CY = 0
  1113                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1114                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  1115                              <1> ;	IF ERROR:	
  1116                              <1> ;		AH = @DSKETTE_STATUS
  1117                              <1> ;		CY = 1
  1118                              <1> ;-------------------------------------------------------------------------------
  1119                              <1> SET_MEDIA:
  1120 0000378B E801010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1121 00003790 F687[3D590100]01    <1>         TEST    byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  1122 00003797 7415                <1> 	JZ	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  1123 00003799 E848030000          <1> 	CALL	MED_CHANGE		; RESET CHANGE LINE
  1124 0000379E 803D[30590100]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  1125 000037A5 746B                <1> 	JE	short SM_RTN
  1126 000037A7 C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  1127                              <1> SM_CMOS:
  1128 000037AE E819070000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1129                              <1> 	;;20/02/2015
  1130                              <1> 	;;JC	short MD_NOT_FND	; ERROR IN CMOS
  1131                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE
  1132 000037B3 745D                <1> 	JZ	short SM_RTN		; RETURN IF SO
  1133 000037B5 E863000000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1134 000037BA 7231                <1> 	JC	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  1135 000037BC 57                  <1> 	PUSH	eDI			; SAVE REG.
  1136 000037BD 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR. TYPE TABLE
  1137 000037BF B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1138                              <1> DR_SEARCH:
  1139 000037C4 8AA3[A05C0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  1140 000037CA 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  1141 000037CD 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH ?
  1142 000037CF 7516                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  1143                              <1> DR_FND:
  1144 000037D1 8BBB[A15C0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  1145                              <1> MD_SEARCH:
  1146 000037D7 8A6704              <1>         MOV     AH, [eDI+MD.SEC_TRK]    ; GET SECTOR/TRACK
  1147 000037DA 386500              <1> 	CMP	[eBP],AH		; MATCH?
  1148 000037DD 7508                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT MEDIA
  1149 000037DF 8A670B              <1>         MOV     AH, [eDI+MD.MAX_TRK]    ; GET MAX. TRACK #
  1150 000037E2 386501              <1> 	CMP 	[eBP+1],AH		; MATCH?
  1151 000037E5 740F                <1> 	JE	short MD_FND		; YES, GO GET RATE
  1152                              <1> NXT_MD:
  1153                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1154 000037E7 83C305              <1>         add	ebx, 5 ; 18/02/2015
  1155 000037EA E2D8                <1> 	LOOP    DR_SEARCH
  1156 000037EC 5F                  <1> 	POP	eDI			; RESTORE REG.
  1157                              <1> MD_NOT_FND:
  1158 000037ED C605[30590100]0C    <1> 	MOV	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  1159 000037F4 EB1C                <1> 	JMP	SHORT SM_RTN		; RETURN
  1160                              <1> MD_FND:
  1161 000037F6 8A470C              <1>         MOV     AL, [eDI+MD.RATE]       ; GET RATE
  1162 000037F9 3C40                <1> 	CMP	AL,RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  1163 000037FB 7502                <1> 	JNE	short MD_SET
  1164 000037FD 0C20                <1> 	OR	AL,DBL_STEP
  1165                              <1> MD_SET:
  1166                              <1> 	;MOV	[BP+6],DI		; SAVE TABLE POINTER IN STACK
  1167 000037FF 897D0C              <1> 	mov	[ebp+12], edi ; 18/02/2015
  1168 00003802 0C10                <1> 	OR	AL,MED_DET		; SET MEDIA ESTABLISHED
  1169 00003804 5F                  <1> 	POP	eDI
  1170 00003805 80A7[3D590100]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1171 0000380C 0887[3D590100]      <1> 	OR	[DSK_STATE+eDI], AL
  1172                              <1> 	;MOV	AX, CS			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1173                              <1> 	;MOV	ES, AX			; ES IS SEGMENT OF TABLE
  1174                              <1> SM_RTN:
  1175 00003812 E8AB000000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1176 00003817 E8E5050000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1177 0000381C C3                  <1> 	RETn
  1178                              <1> 
  1179                              <1> ;----------------------------------------------------------------
  1180                              <1> ; DR_TYPE_CHECK							:
  1181                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  1182                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  1183                              <1> ; ON ENTRY:							:
  1184                              <1> ;	AL = DRIVE TYPE						:
  1185                              <1> ; ON EXIT:							:
  1186                              <1> ;	CS = SEGMENT MEDIA/DRIVE PARAMETER TABLE (CODE)		:
  1187                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  1188                              <1> ;	     BX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE		:
  1189                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  1190                              <1> ; REGISTERS ALTERED: eBX						:
  1191                              <1> ;----------------------------------------------------------------		
  1192                              <1> DR_TYPE_CHECK:
  1193 0000381D 6650                <1> 	PUSH	AX			
  1194 0000381F 51                  <1> 	PUSH	eCX
  1195 00003820 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  1196 00003822 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1197                              <1> TYPE_CHK:	
  1198 00003827 8AA3[A05C0000]      <1> 	MOV	AH,[DR_TYPE+eBX]	; GET DRIVE TYPE
  1199 0000382D 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  1200 0000382F 740D                <1> 	JE	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  1201                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1202 00003831 83C305              <1>         add	ebx, 5	; 16/02/2015 (32 bit address modification)
  1203 00003834 E2F1                <1> 	LOOP    TYPE_CHK
  1204                              <1> 	;
  1205 00003836 BB[FF5C0000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  1206                              <1> 					; Default for GET_PARM (11/12/2014)
  1207                              <1> 	;
  1208 0000383B F9                  <1> 	STC				; DRIVE TYPE NOT FOUND IN TABLE
  1209 0000383C EB06                <1> 	JMP	SHORT TYPE_RTN
  1210                              <1> DR_TYPE_VALID:
  1211 0000383E 8B9B[A15C0000]      <1> 	MOV	eBX,[DR_TYPE+eBX+1] 	; BX = MEDIA TABLE
  1212                              <1> TYPE_RTN:
  1213 00003844 59                  <1> 	POP	eCX
  1214 00003845 6658                <1> 	POP	AX
  1215 00003847 C3                  <1> 	RETn	
  1216                              <1> 		
  1217                              <1> ;----------------------------------------------------------------
  1218                              <1> ; SEND_SPEC							:
  1219                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1220                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  1221                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  1222                              <1> ; ON EXIT:	NONE						:	
  1223                              <1> ; REGISTERS ALTERED: CX, DX					:
  1224                              <1> ;----------------------------------------------------------------		
  1225                              <1> SEND_SPEC:
  1226 00003848 50                  <1> 	PUSH	eAX			; SAVE AX
  1227 00003849 B8[6F380000]        <1> 	MOV	eAX, SPECBAC		; LOAD ERROR ADDRESS
  1228 0000384E 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1229 0000384F B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  1230 00003851 E885070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1231 00003856 28D2                <1> 	SUB	DL,DL			; FIRST SPECIFY BYTE
  1232 00003858 E878060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  1233 0000385D E879070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1234 00003862 B201                <1> 	MOV	DL,1			; SECOND SPECIFY BYTE
  1235 00003864 E86C060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  1236 00003869 E86D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1237 0000386E 58                  <1> 	POP	eAX			; POP ERROR RETURN
  1238                              <1> SPECBAC:
  1239 0000386F 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  1240 00003870 C3                  <1> 	RETn
  1241                              <1> 
  1242                              <1> ;----------------------------------------------------------------
  1243                              <1> ; SEND_SPEC_MD							:
  1244                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1245                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  1246                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  1247                              <1> ; ON EXIT:	NONE						:	
  1248                              <1> ; REGISTERS ALTERED: AX						:
  1249                              <1> ;----------------------------------------------------------------		
  1250                              <1> SEND_SPEC_MD:
  1251 00003871 50                  <1> 	PUSH	eAX			; SAVE RATE DATA
  1252 00003872 B8[8F380000]        <1> 	MOV	eAX, SPEC_ESBAC		; LOAD ERROR ADDRESS
  1253 00003877 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1254 00003878 B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  1255 0000387A E85C070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1256 0000387F 8A23                <1>         MOV     AH, [eBX+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  1257 00003881 E855070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1258 00003886 8A6301              <1>         MOV     AH, [eBX+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  1259 00003889 E84D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  1260 0000388E 58                  <1> 	POP	eAX			; POP ERROR RETURN
  1261                              <1> SPEC_ESBAC:
  1262 0000388F 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  1263 00003890 C3                  <1> 	RETn
  1264                              <1> 
  1265                              <1> ;-------------------------------------------------------------------------------
  1266                              <1> ; XLAT_NEW  
  1267                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  1268                              <1> ;	MODE TO NEW ARCHITECTURE.
  1269                              <1> ;
  1270                              <1> ; ON ENTRY:	DI = DRIVE #
  1271                              <1> ;-------------------------------------------------------------------------------
  1272                              <1> XLAT_NEW:
  1273 00003891 83FF01              <1> 	CMP	eDI,1				; VALID DRIVE
  1274 00003894 7725                <1> 	JA	short XN_OUT			; IF INVALID BACK
  1275 00003896 80BF[3D590100]00    <1> 	CMP	byte [DSK_STATE+eDI], 0		; NO DRIVE ?
  1276 0000389D 741D                <1> 	JZ	short DO_DET			; IF NO DRIVE ATTEMPT DETERMINE
  1277 0000389F 6689F9              <1> 	MOV	CX,DI				; CX = DRIVE NUMBER
  1278 000038A2 C0E102              <1> 	SHL	CL,2				; CL = SHIFT COUNT, A=0, B=4
  1279 000038A5 A0[3C590100]        <1> 	MOV	AL, [HF_CNTRL]			; DRIVE INFORMATION
  1280 000038AA D2C8                <1> 	ROR	AL,CL				; TO LOW NIBBLE
  1281 000038AC 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA	; KEEP DRIVE BITS
  1282 000038AE 80A7[3D590100]F8    <1>         AND     byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  1283 000038B5 0887[3D590100]      <1> 	OR	[DSK_STATE+eDI], AL		; UPDATE DRIVE STATE
  1284                              <1> XN_OUT:
  1285 000038BB C3                  <1> 	RETn
  1286                              <1> DO_DET:
  1287 000038BC E8BF080000          <1> 	CALL	DRIVE_DET			; TRY TO DETERMINE
  1288 000038C1 C3                  <1> 	RETn
  1289                              <1> 
  1290                              <1> ;-------------------------------------------------------------------------------
  1291                              <1> ; XLAT_OLD 
  1292                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  1293                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  1294                              <1> ;
  1295                              <1> ; ON ENTRY:	DI = DRIVE
  1296                              <1> ;-------------------------------------------------------------------------------
  1297                              <1> XLAT_OLD:
  1298 000038C2 83FF01              <1> 	CMP	eDI,1			; VALID DRIVE ?
  1299                              <1>         ;JA     short XO_OUT            ; IF INVALID BACK
  1300 000038C5 0F8786000000        <1>         ja      XO_OUT
  1301 000038CB 80BF[3D590100]00    <1>         CMP	byte [DSK_STATE+eDI],0	; NO DRIVE ?
  1302 000038D2 747D                <1> 	JZ	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  1303                              <1> 
  1304                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  1305                              <1> 
  1306 000038D4 6689F9              <1> 	MOV	CX,DI			; CX = DRIVE NUMBER
  1307 000038D7 C0E102              <1> 	SHL	CL,2			; CL = SHIFT COUNT, A=0, B=4
  1308 000038DA B402                <1> 	MOV	AH,FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  1309 000038DC D2CC                <1> 	ROR	AH,CL			; ROTATE BY MASK
  1310 000038DE 8425[3C590100]      <1> 	TEST	[HF_CNTRL], AH		; MULTIPLE-DATA RATE DETERMINED ?
  1311 000038E4 751C                <1> 	JNZ	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  1312                              <1> 
  1313                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  1314                              <1> 
  1315 000038E6 B407                <1> 	MOV	AH,DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  1316 000038E8 D2CC                <1> 	ROR	AH,CL			; FIX MASK TO KEEP
  1317 000038EA F6D4                <1> 	NOT	AH			; TRANSLATE MASK
  1318 000038EC 2025[3C590100]      <1> 	AND	[HF_CNTRL], AH		; KEEP BITS FROM OTHER DRIVE INTACT
  1319                              <1> 
  1320                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  1321                              <1> 
  1322 000038F2 8A87[3D590100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; ACCESS STATE
  1323 000038F8 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  1324 000038FA D2C8                <1> 	ROR	AL,CL			; FIX FOR THIS DRIVE
  1325 000038FC 0805[3C590100]      <1> 	OR	[HF_CNTRL], AL		; UPDATE SAVED DRIVE STATE
  1326                              <1> 
  1327                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  1328                              <1> 
  1329                              <1> SAVE_SET:
  1330 00003902 8AA7[3D590100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  1331 00003908 88E7                <1> 	MOV	BH,AH			; TO BH FOR LATER
  1332 0000390A 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE
  1333 0000390D 80FC00              <1> 	CMP	AH,RATE_500		; RATE 500 ?
  1334 00003910 7410                <1> 	JZ	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  1335 00003912 B001                <1> 	MOV	AL,M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  1336 00003914 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  1337 00003917 7518                <1> 	JNZ	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  1338 00003919 F6C720              <1> 	TEST	BH,DBL_STEP		; CHECK FOR DOUBLE STEP
  1339 0000391C 751F                <1> 	JNZ	short TST_DET		; MUST BE 360 IN 1.2
  1340                              <1> UNKNO:
  1341 0000391E B007                <1> 	MOV	AL,MED_UNK		; NONE OF THE ABOVE
  1342 00003920 EB22                <1> 	JMP	SHORT AL_SET		; PROCESS COMPLETE
  1343                              <1> CHK_144:
  1344 00003922 E8A5050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1345                              <1> 	;;20/02/2015
  1346                              <1> 	;;JC	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  1347 00003927 74F5                <1> 	jz	short UNKNO ;; 20/02/2015
  1348 00003929 3C02                <1> 	CMP	AL,2			; 1.2MB DRIVE ?
  1349 0000392B 75F1                <1> 	JNE	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  1350 0000392D B002                <1> 	MOV	AL,M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  1351 0000392F EB0C                <1> 	JMP	SHORT TST_DET
  1352                              <1> CHK_250:
  1353 00003931 B000                <1> 	MOV	AL,M3D3U		; AL = 360 IN 360 UNESTABLISHED
  1354 00003933 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  1355 00003936 75E6                <1> 	JNZ	short UNKNO		; IF SO FALL IHRU
  1356 00003938 F6C701              <1> 	TEST	BH,TRK_CAPA		; 80 TRACK CAPABILITY ?
  1357 0000393B 75E1                <1> 	JNZ	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  1358                              <1> TST_DET:
  1359 0000393D F6C710              <1> 	TEST	BH,MED_DET		; DETERMINED ?
  1360 00003940 7402                <1> 	JZ	short AL_SET		; IF NOT THEN SET
  1361 00003942 0403                <1> 	ADD	AL,3			; MAKE DETERMINED/ESTABLISHED
  1362                              <1> AL_SET:
  1363 00003944 80A7[3D590100]F8    <1> 	AND	byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  1364 0000394B 0887[3D590100]      <1> 	OR	[DSK_STATE+eDI], AL	; REPLACE WITH COMPATIBLE MODE
  1365                              <1> XO_OUT:
  1366 00003951 C3                  <1> 	RETn
  1367                              <1> 
  1368                              <1> ;-------------------------------------------------------------------------------
  1369                              <1> ; RD_WR_VF
  1370                              <1> ;	COMMON READ, WRITE AND VERIFY: 
  1371                              <1> ;	MAIN LOOP FOR STATE RETRIES.
  1372                              <1> ;
  1373                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
  1374                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
  1375                              <1> ;
  1376                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1377                              <1> ;-------------------------------------------------------------------------------
  1378                              <1> RD_WR_VF:
  1379 00003952 6650                <1> 	PUSH	AX			; SAVE DMA, NEC PARAMETERS
  1380 00003954 E838FFFFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1381 00003959 E8F3000000          <1> 	CALL	SETUP_STATE		; INITIALIZE START AND END RATE
  1382 0000395E 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  1383                              <1> DO_AGAIN:
  1384 00003960 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  1385 00003962 E87F010000          <1> 	CALL	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
  1386 00003967 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  1387 00003969 0F82C9000000        <1>         JC      RWV_END                 ; MEDIA CHANGE ERROR OR TIME-OUT
  1388                              <1> RWV:
  1389 0000396F 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  1390 00003971 8AB7[3D590100]      <1> 	MOV	DH, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1391 00003977 80E6C0              <1> 	AND	DH,RATE_MSK		; KEEP ONLY RATE
  1392 0000397A E84D050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
  1393                              <1> 	;;20/02/2015
  1394                              <1> 	;;JC	short RWV_ASSUME	; ERROR IN CMOS
  1395 0000397F 7451                <1> 	jz	short RWV_ASSUME ; 20/02/2015
  1396 00003981 3C01                <1> 	CMP	AL,1			; 40 TRACK DRIVE?
  1397 00003983 750D                <1> 	JNE	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
  1398 00003985 F687[3D590100]01    <1> 	TEST	byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
  1399 0000398C 7413                <1> 	JZ	short RWV_2		; YES, CMOS IS CORRECT
  1400 0000398E B002                <1> 	MOV	AL,2			; CHANGE TO 1.2M
  1401 00003990 EB0F                <1> 	JMP	SHORT RWV_2
  1402                              <1> RWV_1:
  1403 00003992 720D                <1> 	JB	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
  1404 00003994 F687[3D590100]01    <1> 	TEST    byte [DSK_STATE+eDI], TRK_CAPA ; IS IT REALLY 40 TRACK?
  1405 0000399B 7504                <1> 	JNZ	short RWV_2		; NO, 80 TRACK
  1406 0000399D B001                <1> 	MOV	AL,1			; IT IS 40 TRACK, FIX CMOS VALUE
  1407 0000399F EB04                <1> 	jmp	short rwv_3
  1408                              <1> RWV_2:
  1409 000039A1 08C0                <1> 	OR	AL,AL			; TEST FOR NO DRIVE
  1410 000039A3 742D                <1> 	JZ	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
  1411                              <1> rwv_3:
  1412 000039A5 E873FEFFFF          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
  1413 000039AA 7226                <1> 	JC	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
  1414                              <1> 
  1415                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
  1416                              <1> 
  1417 000039AC 57                  <1> 	PUSH	eDI			; SAVE DRIVE #
  1418 000039AD 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  1419 000039AF B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  1420                              <1> RWV_DR_SEARCH:
  1421 000039B4 8AA3[A05C0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  1422 000039BA 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  1423 000039BD 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  1424 000039BF 750B                <1> 	JNE	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
  1425                              <1> RWV_DR_FND:
  1426 000039C1 8BBB[A15C0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAMETER TABLE
  1427                              <1> RWV_MD_SEARH:
  1428 000039C7 3A770C              <1>         CMP     DH, [eDI+MD.RATE]       ; MATCH?
  1429 000039CA 741B                <1> 	JE	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
  1430                              <1> RWV_NXT_MD:
  1431                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  1432 000039CC 83C305              <1> 	add	eBX, 5
  1433 000039CF E2E3                <1> 	LOOP	RWV_DR_SEARCH
  1434 000039D1 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  1435                              <1> 
  1436                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
  1437                              <1> 
  1438                              <1> RWV_ASSUME:
  1439 000039D2 BB[BE5C0000]        <1> 	MOV	eBX, MD_TBL1		; POINT TO 40 TRACK 250 KBS
  1440 000039D7 F687[3D590100]01    <1> 	TEST 	byte [DSK_STATE+eDI], TRK_CAPA ; TEST FOR 80 TRACK
  1441 000039DE 740A                <1> 	JZ	short RWV_MD_FND1	; MUST BE 40 TRACK
  1442 000039E0 BB[D85C0000]        <1> 	MOV	eBX, MD_TBL3		; POINT TO 80 TRACK 500 KBS
  1443 000039E5 EB03                <1> 	JMP	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
  1444                              <1> 
  1445                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
  1446                              <1> 	 			
  1447                              <1> RWV_MD_FND:
  1448 000039E7 89FB                <1> 	MOV	eBX,eDI			; BX = MEDIA/DRIVE PARAMETER TABLE
  1449 000039E9 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  1450                              <1> 	
  1451                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
  1452                              <1> 
  1453                              <1> RWV_MD_FND1:
  1454 000039EA E882FEFFFF          <1> 	CALL	SEND_SPEC_MD
  1455 000039EF E864010000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
  1456 000039F4 7405                <1> 	JZ	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
  1457 000039F6 E83B010000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO NEC
  1458                              <1> RWV_DBL:
  1459 000039FB 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1460 000039FC E822040000          <1> 	CALL	SETUP_DBL		; CHECK FOR DOUBLE STEP
  1461 00003A01 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  1462 00003A02 7226                <1> 	JC	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
  1463 00003A04 6658                <1> 	POP	AX			; RESTORE NEC, DMA COMMAND
  1464 00003A06 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1465 00003A08 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1466 00003A09 E861010000          <1> 	CALL	DMA_SETUP		; SET UP THE DMA
  1467 00003A0E 5B                  <1> 	POP	eBX 
  1468 00003A0F 6658                <1> 	POP	AX			; RESTORE NEC COMMAND
  1469 00003A11 722F                <1> 	JC	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
  1470 00003A13 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1471 00003A15 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  1472 00003A16 E83C020000          <1> 	CALL	NEC_INIT		; INITIALIZE NEC
  1473 00003A1B 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  1474 00003A1C 720C                <1> 	JC	short CHK_RET		; ERROR - EXIT
  1475 00003A1E E866020000          <1> 	CALL	RWV_COM			; OP CODE COMMON TO READ/WRITE/VERIFY
  1476 00003A23 7205                <1> 	JC	short CHK_RET		; ERROR - EXIT
  1477 00003A25 E8AB020000          <1> 	CALL	NEC_TERM		; TERMINATE, GET STATUS, ETC.
  1478                              <1> CHK_RET:
  1479 00003A2A E84A030000          <1> 	CALL	RETRY			; CHECK FOR, SETUP RETRY
  1480 00003A2F 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY PARAMETER
  1481 00003A31 7305                <1> 	JNC	short RWV_END		; CY = 0 NO RETRY
  1482 00003A33 E928FFFFFF          <1>         JMP     DO_AGAIN                ; CY = 1 MEANS RETRY
  1483                              <1> RWV_END:
  1484 00003A38 E8F4020000          <1> 	CALL	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
  1485 00003A3D E887030000          <1> 	CALL	NUM_TRANS		; AL = NUMBER TRANSFERRED
  1486                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
  1487 00003A42 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  1488 00003A44 E879FEFFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1489 00003A49 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  1490 00003A4B E8B1030000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  1491 00003A50 C3                  <1> 	RETn
  1492                              <1> 
  1493                              <1> ;-------------------------------------------------------------------------------
  1494                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  1495                              <1> ;-------------------------------------------------------------------------------
  1496                              <1> SETUP_STATE:
  1497 00003A51 F687[3D590100]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; MEDIA DETERMINED ?
  1498 00003A58 7537                <1> 	JNZ	short J1C		; NO STATES IF DETERMINED
  1499 00003A5A 66B84000            <1>         MOV     AX,(RATE_500*256)+RATE_300  ; AH = START RATE, AL = END RATE
  1500 00003A5E F687[3D590100]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE ?
  1501 00003A65 740D                <1> 	JZ	short AX_SET		; DO NOT KNOW DRIVE
  1502 00003A67 F687[3D590100]02    <1> 	TEST	byte [DSK_STATE+eDI], FMT_CAPA ; MULTI-RATE?
  1503 00003A6E 7504                <1> 	JNZ	short AX_SET		; JUMP IF YES
  1504 00003A70 66B88080            <1>         MOV     AX,RATE_250*257         ; START A END RATE 250 FOR 360 DRIVE
  1505                              <1> AX_SET:	
  1506 00003A74 80A7[3D590100]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  1507 00003A7B 08A7[3D590100]      <1> 	OR	[DSK_STATE+eDI], AH	; RATE FIRST TO TRY
  1508 00003A81 8025[38590100]F3    <1> 	AND	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  1509 00003A88 C0C804              <1> 	ROR	AL,4			; TO OPERATION LAST RATE LOCATION
  1510 00003A8B 0805[38590100]      <1> 	OR	[LASTRATE], AL		; LAST RATE
  1511                              <1> J1C:	
  1512 00003A91 C3                  <1> 	RETn
  1513                              <1> 
  1514                              <1> ;-------------------------------------------------------------------------------
  1515                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  1516                              <1> ;-------------------------------------------------------------------------------
  1517                              <1> FMT_INIT:
  1518 00003A92 F687[3D590100]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; IS MEDIA ESTABLISHED
  1519 00003A99 7546                <1> 	JNZ	short F1_OUT		; IF SO RETURN
  1520 00003A9B E82C040000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  1521                              <1> 	;; 20/02/2015
  1522                              <1> 	;;JC	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  1523 00003AA0 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  1524 00003AA2 FEC8                <1> 	DEC	AL			; MAKE ZERO ORIGIN
  1525                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  1526 00003AA4 8AA7[3D590100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; AH = CURRENT STATE
  1527 00003AAA 80E40F              <1> 	AND	AH, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  1528 00003AAD 08C0                <1> 	OR	AL,AL			; CHECK FOR 360
  1529 00003AAF 7505                <1> 	JNZ	short N_360		; IF 360 WILL BE 0
  1530 00003AB1 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; ESTABLISH MEDIA
  1531 00003AB4 EB25                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  1532                              <1> N_360:	
  1533 00003AB6 FEC8                <1> 	DEC	AL			; 1.2 M DRIVE
  1534 00003AB8 7505                <1> 	JNZ	short N_12		; JUMP IF NOT
  1535                              <1> F1_RATE:
  1536 00003ABA 80CC10              <1> 	OR	AH,MED_DET+RATE_500	; SET FORMAT RATE
  1537 00003ABD EB1C                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  1538                              <1> N_12:	
  1539 00003ABF FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 3
  1540 00003AC1 750F                <1> 	JNZ	short N_720		; JUMP IF NOT
  1541 00003AC3 F6C404              <1> 	TEST	AH,DRV_DET		; IS DRIVE DETERMINED
  1542 00003AC6 7410                <1> 	JZ	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  1543 00003AC8 F6C402              <1> 	TEST	AH,FMT_CAPA		; IS 1.2M
  1544 00003ACB 740B                <1> 	JZ	short ISNT_12		; JUMP IF NOT
  1545 00003ACD 80CC50              <1> 	OR	AH,MED_DET+RATE_300	; RATE 300
  1546 00003AD0 EB09                <1> 	JMP	SHORT SKP_STATE		; CONTINUE
  1547                              <1> N_720:
  1548 00003AD2 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 4
  1549 00003AD4 750C                <1> 	JNZ	short CL_DRV		; NO DRIVE, CMOS BAD
  1550 00003AD6 EBE2                <1> 	JMP	SHORT F1_RATE
  1551                              <1> ISNT_12: 
  1552 00003AD8 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; MUST BE RATE 250
  1553                              <1> 
  1554                              <1> SKP_STATE:
  1555 00003ADB 88A7[3D590100]      <1> 	MOV	[DSK_STATE+eDI], AH	; STORE AWAY
  1556                              <1> F1_OUT:
  1557 00003AE1 C3                  <1> 	RETn
  1558                              <1> CL_DRV:	
  1559 00003AE2 30E4                <1> 	XOR	AH,AH			; CLEAR STATE
  1560 00003AE4 EBF5                <1> 	JMP	SHORT SKP_STATE		; SAVE IT
  1561                              <1> 
  1562                              <1> ;-------------------------------------------------------------------------------
  1563                              <1> ; MED_CHANGE	
  1564                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  1565                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  1566                              <1> ;
  1567                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  1568                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  1569                              <1> ;-------------------------------------------------------------------------------
  1570                              <1> MED_CHANGE:
  1571 00003AE6 E888060000          <1> 	CALL	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  1572 00003AEB 7447                <1> 	JZ	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  1573 00003AED 80A7[3D590100]EF    <1> 	AND	byte [DSK_STATE+eDI], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  1574                              <1> 
  1575                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  1576                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  1577                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  1578                              <1> 
  1579 00003AF4 6689F9              <1> 	MOV	CX,DI			; CL = DRIVE 0
  1580 00003AF7 B001                <1> 	MOV	AL,1			; MOTOR ON BIT MASK
  1581 00003AF9 D2E0                <1> 	SHL	AL,CL			; TO APPROPRIATE POSITION
  1582 00003AFB F6D0                <1> 	NOT	AL			; KEEP ALL BUT MOTOR ON
  1583 00003AFD FA                  <1> 	CLI				; NO INTERRUPTS
  1584 00003AFE 2005[2E590100]      <1> 	AND	[MOTOR_STATUS], AL	; TURN MOTOR OFF INDICATOR
  1585 00003B04 FB                  <1> 	STI				; INTERRUPTS ENABLED
  1586 00003B05 E810040000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON
  1587                              <1> 
  1588                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  1589                              <1> 
  1590 00003B0A E86DF9FFFF          <1> 	CALL	DSK_RESET		; RESET NEC
  1591 00003B0F B501                <1> 	MOV	CH,01H			; MOVE TO CYLINDER 1
  1592 00003B11 E8FF040000          <1> 	CALL	SEEK			; ISSUE SEEK
  1593 00003B16 30ED                <1> 	XOR	CH,CH			; MOVE TO CYLINDER 0
  1594 00003B18 E8F8040000          <1> 	CALL	SEEK			; ISSUE SEEK
  1595 00003B1D C605[30590100]06    <1> 	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  1596                              <1> OK1:
  1597 00003B24 E84A060000          <1> 	CALL	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  1598 00003B29 7407                <1> 	JZ	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  1599                              <1> OK4:
  1600 00003B2B C605[30590100]80    <1> 	MOV	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  1601                              <1> OK2:		
  1602 00003B32 F9                  <1> 	STC				; MEDIA CHANGED, SET CY
  1603 00003B33 C3                  <1> 	RETn
  1604                              <1> MC_OUT:
  1605 00003B34 F8                  <1> 	CLC				; NO MEDIA CHANGED, CLEAR CY
  1606 00003B35 C3                  <1> 	RETn
  1607                              <1> 
  1608                              <1> ;-------------------------------------------------------------------------------
  1609                              <1> ; SEND_RATE
  1610                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  1611                              <1> ; ON ENTRY:	DI = DRIVE #
  1612                              <1> ; ON EXIT:	NONE
  1613                              <1> ; REGISTERS ALTERED: DX
  1614                              <1> ;-------------------------------------------------------------------------------
  1615                              <1> SEND_RATE:
  1616 00003B36 6650                <1> 	PUSH	AX			; SAVE REG.
  1617 00003B38 8025[38590100]3F    <1> 	AND	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  1618 00003B3F 8A87[3D590100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1619 00003B45 24C0                <1> 	AND	AL,SEND_MSK		; KEEP ONLY RATE BITS
  1620 00003B47 0805[38590100]      <1> 	OR	[LASTRATE], AL		; SAVE NEW RATE FOR NEXT CHECK
  1621 00003B4D C0C002              <1> 	ROL	AL,2			; MOVE TO BIT OUTPUT POSITIONS
  1622 00003B50 66BAF703            <1> 	MOV	DX,03F7H		; OUTPUT NEW DATA RATE
  1623 00003B54 EE                  <1> 	OUT	DX,AL
  1624 00003B55 6658                <1> 	POP	AX			; RESTORE REG.
  1625 00003B57 C3                  <1> 	RETn
  1626                              <1> 
  1627                              <1> ;-------------------------------------------------------------------------------
  1628                              <1> ; CHK_LASTRATE
  1629                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  1630                              <1> ; ON ENTRY:
  1631                              <1> ;	DI = DRIVE #
  1632                              <1> ; ON EXIT:
  1633                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  1634                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  1635                              <1> ; REGISTERS ALTERED: DX
  1636                              <1> ;-------------------------------------------------------------------------------
  1637                              <1> CHK_LASTRATE:
  1638 00003B58 6650                <1> 	PUSH	AX			; SAVE REG
  1639 00003B5A 2225[38590100]      <1> 	AND	AH, [LASTRATE]		; GET LAST DATA RATE SELECTED
  1640 00003B60 8A87[3D590100]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  1641 00003B66 6625C0C0            <1>         AND     AX, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  1642 00003B6A 38E0                <1> 	CMP	AL, AH			; COMPARE TO PREVIOUSLY TRIED
  1643                              <1> 					; ZF = 1 RATE IS THE SAME
  1644 00003B6C 6658                <1> 	POP	AX			; RESTORE REG.
  1645 00003B6E C3                  <1> 	RETn
  1646                              <1> 
  1647                              <1> ;-------------------------------------------------------------------------------
  1648                              <1> ; DMA_SETUP
  1649                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  1650                              <1> ;
  1651                              <1> ; ON ENTRY:	AL = DMA COMMAND
  1652                              <1> ;
  1653                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1654                              <1> ;-------------------------------------------------------------------------------
  1655                              <1> 
  1656                              <1> ; SI = Head #, # of Sectors or DASD Type
  1657                              <1> 
  1658                              <1> ; 22/08/2015
  1659                              <1> ; 08/02/2015 - Protected Mode Modification
  1660                              <1> ; 06/02/2015 - 07/02/2015
  1661                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  1662                              <1> ; (DMA Addres = Physical Address)
  1663                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  1664                              <1> ;
  1665                              <1> 
  1666                              <1> 
  1667                              <1> ; 04/02/2016 (clc)
  1668                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  1669                              <1> ; 16/12/2014 (IODELAY)
  1670                              <1> 
  1671                              <1> DMA_SETUP:
  1672                              <1> 
  1673                              <1> ;; 20/02/2015
  1674 00003B6F 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  1675 00003B72 F7C2000000FF        <1> 	test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  1676 00003B78 756E                <1> 	jnz	short dma_bnd_err_stc
  1677                              <1> 	;
  1678 00003B7A 6650                <1> 	push	ax			; DMA command
  1679 00003B7C 52                  <1> 	push	edx			; *
  1680 00003B7D B203                <1> 	mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  1681 00003B7F E851030000          <1> 	call	GET_PARM		; 
  1682 00003B84 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  1683 00003B86 6689F0              <1> 	mov	ax, si			; Sector count
  1684 00003B89 88C4                <1> 	mov	ah, al			; AH =  # OF SECTORS
  1685 00003B8B 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  1686 00003B8D 66D1E8              <1> 	shr	ax, 1			; AX = # SECTORS * 128
  1687 00003B90 66D3E0              <1> 	shl	ax, cl			; SHIFT BY PARAMETER VALUE
  1688 00003B93 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  1689 00003B95 6689C1              <1> 	mov	cx, ax
  1690 00003B98 5A                  <1> 	pop	edx			; *
  1691 00003B99 6658                <1> 	pop	ax
  1692 00003B9B 3C42                <1> 	cmp	al, 42h
  1693 00003B9D 7507                <1>         jne     short NOT_VERF
  1694 00003B9F BA0000FF00          <1> 	mov	edx, 0FF0000h
  1695 00003BA4 EB08                <1> 	jmp	short J33
  1696                              <1> NOT_VERF:
  1697 00003BA6 6601CA              <1> 	add	dx, cx			; check for overflow
  1698 00003BA9 723E                <1> 	jc	short dma_bnd_err
  1699                              <1> 	;
  1700 00003BAB 6629CA              <1> 	sub	dx, cx			; Restore start address
  1701                              <1> J33:
  1702 00003BAE FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1703 00003BAF E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1704                              <1> 	IODELAY				; WAIT FOR I/O
  1704 00003BB1 EB00                <2>  jmp short $+2
  1704 00003BB3 EB00                <2>  jmp short $+2
  1705 00003BB5 E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1706 00003BB7 89D0                <1> 	mov	eax, edx		; Buffer address
  1707 00003BB9 E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1708                              <1> 	IODELAY				; WAIT FOR I/O
  1708 00003BBB EB00                <2>  jmp short $+2
  1708 00003BBD EB00                <2>  jmp short $+2
  1709 00003BBF 88E0                <1> 	MOV	AL,AH
  1710 00003BC1 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1711 00003BC3 C1E810              <1> 	shr	eax, 16
  1712                              <1> 	IODELAY				; I/O WAIT STATE
  1712 00003BC6 EB00                <2>  jmp short $+2
  1712 00003BC8 EB00                <2>  jmp short $+2
  1713 00003BCA E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  1714                              <1> 	IODELAY
  1714 00003BCC EB00                <2>  jmp short $+2
  1714 00003BCE EB00                <2>  jmp short $+2
  1715 00003BD0 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  1716 00003BD3 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1717                              <1> 	IODELAY				; WAIT FOR I/O
  1717 00003BD5 EB00                <2>  jmp short $+2
  1717 00003BD7 EB00                <2>  jmp short $+2
  1718 00003BD9 88E0                <1> 	MOV	AL, AH
  1719 00003BDB E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1720                              <1> 	IODELAY
  1720 00003BDD EB00                <2>  jmp short $+2
  1720 00003BDF EB00                <2>  jmp short $+2
  1721 00003BE1 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  1722 00003BE2 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  1723 00003BE4 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1724                              <1> 
  1725 00003BE6 F8                  <1> 	clc	; 04/02/2016
  1726 00003BE7 C3                  <1> 	retn
  1727                              <1> 
  1728                              <1> dma_bnd_err_stc:
  1729 00003BE8 F9                  <1> 	stc
  1730                              <1> dma_bnd_err:
  1731 00003BE9 C605[30590100]09    <1> 	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1732 00003BF0 C3                  <1> 	RETn				; CY SET BY ABOVE IF ERROR
  1733                              <1> 
  1734                              <1> ;; 16/12/2014
  1735                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1736                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1737                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1738                              <1> ;;	IODELAY
  1739                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1740                              <1> ;;	;SIODELAY
  1741                              <1> ;;      ;CMP	AL, 42H			; DMA VERIFY COMMAND
  1742                              <1> ;;      ;JNE	short NOT_VERF		; NO
  1743                              <1> ;;      ;XOR	AX, AX			; START ADDRESS
  1744                              <1> ;;      ;JMP	SHORT J33
  1745                              <1> ;;;NOT_VERF:	
  1746                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  1747                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  1748                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  1749                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  1750                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  1751                              <1> ;;	mov	eax, [ebp+4] ; 06/02/2015	
  1752                              <1> ;;	;JNC	short J33
  1753                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  1754                              <1> ;;;J33:
  1755                              <1> ;;	PUSH	eAX			; SAVE START ADDRESS
  1756                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1757                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1758                              <1> ;;	IODELAY
  1759                              <1> ;;	MOV	AL,AH
  1760                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1761                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  1762                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  1763                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  1764                              <1> ;;	IODELAY
  1765                              <1> ;;	;AND	AL,00001111B
  1766                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  1767                              <1> ;;	;SIODELAY
  1768                              <1> ;;
  1769                              <1> ;;;----- DETERMINE COUNT
  1770                              <1> ;;	sub	eax, eax ; 08/02/2015
  1771                              <1> ;;	MOV	AX, SI			; AL =  # OF SECTORS
  1772                              <1> ;;	XCHG	AL, AH			; AH =  # OF SECTORS
  1773                              <1> ;;	SUB	AL, AL			; AL = 0, AX = # SECTORS * 256
  1774                              <1> ;;	SHR	AX, 1			; AX = # SECTORS * 128
  1775                              <1> ;;	PUSH	AX			; SAVE # OF SECTORS * 128
  1776                              <1> ;;	MOV	DL, 3			; GET BYTES/SECTOR PARAMETER
  1777                              <1> ;;	CALL	GET_PARM		; "
  1778                              <1> ;;	MOV	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  1779                              <1> ;;	POP	AX			; AX = # SECTORS * 128
  1780                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  1781                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  1782                              <1> ;;	PUSH	eAX  ; 08/02/2015	; SAVE COUNT VALUE
  1783                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1784                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1785                              <1> ;;	IODELAY
  1786                              <1> ;;	MOV	AL, AH
  1787                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1788                              <1> ;;	;IODELAY
  1789                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  1790                              <1> ;;	POP	eCX  ; 08/02/2015 	; RECOVER COUNT VALUE
  1791                              <1> ;;	POP	eAX  ; 08/02/2015	; RECOVER ADDRESS VALUE
  1792                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  1793                              <1> ;;	add	ecx, eax ; 08/02/2015
  1794                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  1795                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1796                              <1> ;;	SIODELAY
  1797                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1798                              <1> ;;	;JNC	short NO_BAD		; CHECK FOR ERROR
  1799                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  1800                              <1> ;;	and	ecx, 0FFF00000h ; 16 MB limit
  1801                              <1> ;;	jz	short NO_BAD
  1802                              <1> ;;dma_bnd_err:
  1803                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1804                              <1> ;;NO_BAD:
  1805                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  1806                              <1> 
  1807                              <1> ;-------------------------------------------------------------------------------
  1808                              <1> ; FMTDMA_SET
  1809                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  1810                              <1> ;
  1811                              <1> ; ON ENTRY:	NOTHING REQUIRED
  1812                              <1> ;
  1813                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1814                              <1> ;-------------------------------------------------------------------------------
  1815                              <1> 
  1816                              <1> FMTDMA_SET:
  1817                              <1> ;; 20/02/2015 modification	
  1818 00003BF1 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  1819 00003BF4 F7C20000F0FF        <1> 	test	edx, 0FFF00000h		; 16 MB limit
  1820 00003BFA 75EC                <1> 	jnz	short dma_bnd_err_stc
  1821                              <1> 	;
  1822 00003BFC 6652                <1> 	push	dx			; *
  1823 00003BFE B204                <1> 	mov	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  1824 00003C00 E8D0020000          <1> 	call	GET_PARM		; "
  1825 00003C05 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  1826 00003C07 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  1827 00003C09 66C1E002            <1> 	shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  1828 00003C0D 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  1829 00003C0F 6689C1              <1> 	mov	cx, ax
  1830 00003C12 665A                <1> 	pop	dx			; *
  1831 00003C14 6601CA              <1> 	add	dx, cx			; check for overflow
  1832 00003C17 72D0                <1> 	jc	short dma_bnd_err
  1833                              <1> 	;
  1834 00003C19 6629CA              <1> 	sub	dx, cx			; Restore start address
  1835                              <1> 	;
  1836 00003C1C B04A                <1> 	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  1837 00003C1E FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1838 00003C1F E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1839                              <1> 	IODELAY				; WAIT FOR I/O
  1839 00003C21 EB00                <2>  jmp short $+2
  1839 00003C23 EB00                <2>  jmp short $+2
  1840 00003C25 E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1841 00003C27 89D0                <1> 	mov	eax, edx		; Buffer address
  1842 00003C29 E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1843                              <1> 	IODELAY				; WAIT FOR I/O
  1843 00003C2B EB00                <2>  jmp short $+2
  1843 00003C2D EB00                <2>  jmp short $+2
  1844 00003C2F 88E0                <1> 	MOV	AL,AH
  1845 00003C31 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1846 00003C33 C1E810              <1> 	shr	eax, 16
  1847                              <1> 	IODELAY				; I/O WAIT STATE
  1847 00003C36 EB00                <2>  jmp short $+2
  1847 00003C38 EB00                <2>  jmp short $+2
  1848 00003C3A E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  1849                              <1> 	IODELAY
  1849 00003C3C EB00                <2>  jmp short $+2
  1849 00003C3E EB00                <2>  jmp short $+2
  1850 00003C40 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  1851 00003C43 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1852                              <1> 	IODELAY				; WAIT FOR I/O
  1852 00003C45 EB00                <2>  jmp short $+2
  1852 00003C47 EB00                <2>  jmp short $+2
  1853 00003C49 88E0                <1> 	MOV	AL, AH
  1854 00003C4B E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1855                              <1> 	IODELAY
  1855 00003C4D EB00                <2>  jmp short $+2
  1855 00003C4F EB00                <2>  jmp short $+2
  1856 00003C51 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  1857 00003C52 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  1858 00003C54 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1859 00003C56 C3                  <1> 	retn
  1860                              <1> 
  1861                              <1> ;; 08/02/2015 - Protected Mode Modification
  1862                              <1> ;;	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  1863                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  1864                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  1865                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1866                              <1> ;;	IODELAY
  1867                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  1868                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  1869                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  1870                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  1871                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  1872                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  1873                              <1> ;;	;JNC	short J33A
  1874                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  1875                              <1> ;;	mov	eax, [ebp+4] ; 08/02/2015
  1876                              <1> ;;;J33A:
  1877                              <1> ;;	PUSH	eAX ; 08/02/2015	; SAVE START ADDRESS
  1878                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  1879                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1880                              <1> ;;	IODELAY
  1881                              <1> ;;	MOV	AL,AH
  1882                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  1883                              <1> ;;	shr 	eax, 16 ; 08/02/2015
  1884                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  1885                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  1886                              <1> ;;	IODELAY
  1887                              <1> ;;	;AND	AL,00001111B
  1888                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  1889                              <1> ;;
  1890                              <1> ;;;----- DETERMINE COUNT
  1891                              <1> ;;	sub	eax, eax ; 08/02/2015
  1892                              <1> ;;	MOV	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  1893                              <1> ;;	CALL	GET_PARM		; "
  1894                              <1> ;;	XCHG	AL, AH			; AL = SECTORS/TRACK VALUE
  1895                              <1> ;;	SUB	AH, AH			; AX = SECTORS/TRACK VALUE
  1896                              <1> ;;	SHL	AX, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  1897                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  1898                              <1> ;;	PUSH	eAX 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  1899                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  1900                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1901                              <1> ;;	IODELAY
  1902                              <1> ;;	MOV	AL, AH
  1903                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  1904                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  1905                              <1> ;;	POP	eCX	; 08/02/2015	; RECOVER COUNT VALUE
  1906                              <1> ;;	POP	eAX	; 08/02/2015	; RECOVER ADDRESS VALUE
  1907                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  1908                              <1> ;;	add	ecx, eax ; 08/02/2015
  1909                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  1910                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  1911                              <1> ;;	SIODELAY
  1912                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  1913                              <1> ;;	;JNC	short FMTDMA_OK		; CHECK FOR ERROR
  1914                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  1915                              <1> ;;	and	ecx, 0FFF00000h  ; 16 MB limit
  1916                              <1> ;;	jz	short FMTDMA_OK
  1917                              <1> ;;	stc	; 20/02/2015
  1918                              <1> ;;fmtdma_bnd_err:
  1919                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  1920                              <1> ;;FMTDMA_OK:
  1921                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  1922                              <1> 
  1923                              <1> ;-------------------------------------------------------------------------------
  1924                              <1> ; NEC_INIT	
  1925                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  1926                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  1927                              <1> ;
  1928                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  1929                              <1> ;
  1930                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1931                              <1> ;-------------------------------------------------------------------------------
  1932                              <1> NEC_INIT:
  1933 00003C57 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  1934 00003C59 E8BC020000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  1935                              <1> 
  1936                              <1> ;-----	DO THE SEEK OPERATION
  1937                              <1> 
  1938 00003C5E 8A6D01              <1> 	MOV	CH,[eBP+1]		; CH = TRACK #
  1939 00003C61 E8AF030000          <1> 	CALL	SEEK			; MOVE TO CORRECT TRACK
  1940 00003C66 6658                <1> 	POP	AX			; RECOVER COMMAND
  1941 00003C68 721E                <1> 	JC	short ER_1		; ERROR ON SEEK
  1942 00003C6A BB[883C0000]        <1> 	MOV	eBX, ER_1		; LOAD ERROR ADDRESS
  1943 00003C6F 53                  <1> 	PUSH	eBX			; PUSH NEC_OUT ERROR RETURN
  1944                              <1> 
  1945                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  1946                              <1> 
  1947 00003C70 E866030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  1948 00003C75 6689F0              <1> 	MOV	AX,SI			; AH = HEAD #
  1949 00003C78 89FB                <1> 	MOV	eBX,eDI			; BL = DRIVE #
  1950 00003C7A C0E402              <1> 	SAL	AH,2			; MOVE IT TO BIT 2
  1951 00003C7D 80E404              <1> 	AND	AH,00000100B		; ISOLATE THAT BIT
  1952 00003C80 08DC                <1> 	OR	AH,BL			; OR IN THE DRIVE NUMBER
  1953 00003C82 E854030000          <1> 	CALL	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  1954 00003C87 5B                  <1> 	POP	eBX			; THROW AWAY ERROR RETURN
  1955                              <1> ER_1:
  1956 00003C88 C3                  <1> 	RETn
  1957                              <1> 
  1958                              <1> ;-------------------------------------------------------------------------------
  1959                              <1> ; RWV_COM
  1960                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  1961                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  1962                              <1> ;
  1963                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  1964                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1965                              <1> ;-------------------------------------------------------------------------------
  1966                              <1> RWV_COM:
  1967 00003C89 B8[D43C0000]        <1> 	MOV	eAX, ER_2		; LOAD ERROR ADDRESS
  1968 00003C8E 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  1969 00003C8F 8A6501              <1> 	MOV	AH,[eBP+1]		; OUTPUT TRACK #
  1970 00003C92 E844030000          <1> 	CALL	NEC_OUTPUT
  1971 00003C97 6689F0              <1> 	MOV	AX,SI			; OUTPUT HEAD #
  1972 00003C9A E83C030000          <1> 	CALL	NEC_OUTPUT
  1973 00003C9F 8A6500              <1>         MOV     AH,[eBP]                ; OUTPUT SECTOR #
  1974 00003CA2 E834030000          <1> 	CALL	NEC_OUTPUT
  1975 00003CA7 B203                <1> 	MOV	DL,3			; BYTES/SECTOR PARAMETER FROM BLOCK
  1976 00003CA9 E827020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  1977 00003CAE E828030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1978 00003CB3 B204                <1> 	MOV	DL,4			; EOT PARAMETER FROM BLOCK
  1979 00003CB5 E81B020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  1980 00003CBA E81C030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1981 00003CBF 8A6305              <1>         MOV     AH, [eBX+MD.GAP]        ; GET GAP LENGTH
  1982                              <1> _R15:
  1983 00003CC2 E814030000          <1> 	CALL	NEC_OUTPUT
  1984 00003CC7 B206                <1> 	MOV	DL,6			; DTL PARAMETER PROM BLOCK
  1985 00003CC9 E807020000          <1> 	CALL	GET_PARM		;  TO THE NEC
  1986 00003CCE E808030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  1987 00003CD3 58                  <1> 	POP	eAX			; THROW AWAY ERROR EXIT
  1988                              <1> ER_2:
  1989 00003CD4 C3                  <1> 	RETn
  1990                              <1> 
  1991                              <1> ;-------------------------------------------------------------------------------
  1992                              <1> ; NEC_TERM
  1993                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  1994                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  1995                              <1> ;
  1996                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1997                              <1> ;-------------------------------------------------------------------------------
  1998                              <1> NEC_TERM:
  1999                              <1> 
  2000                              <1> ;-----	LET THE OPERATION HAPPEN
  2001                              <1> 
  2002 00003CD5 56                  <1> 	PUSH	eSI			; SAVE HEAD #, # OF SECTORS
  2003 00003CD6 E80D040000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  2004 00003CDB 9C                  <1> 	PUSHF
  2005 00003CDC E837040000          <1> 	CALL	RESULTS			; GET THE NEC STATUS
  2006 00003CE1 724B                <1> 	JC	short SET_END_POP
  2007 00003CE3 9D                  <1> 	POPF
  2008 00003CE4 723E                <1> 	JC	short SET_END		; LOOK FOR ERROR
  2009                              <1> 
  2010                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  2011                              <1> 
  2012 00003CE6 FC                  <1> 	CLD				; SET THE CORRECT DIRECTION
  2013 00003CE7 BE[31590100]        <1> 	MOV	eSI, NEC_STATUS		; POINT TO STATUS FIELD
  2014 00003CEC AC                  <1> 	lodsb				; GET ST0
  2015 00003CED 24C0                <1> 	AND	AL,11000000B		; TEST FOR NORMAL TERMINATION
  2016 00003CEF 7433                <1> 	JZ	short SET_END
  2017 00003CF1 3C40                <1> 	CMP	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  2018 00003CF3 7527                <1> 	JNZ	short J18		; NOT ABNORMAL, BAD NEC
  2019                              <1> 
  2020                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  2021                              <1> 
  2022 00003CF5 AC                  <1> 	lodsb				; GET ST1
  2023 00003CF6 D0E0                <1> 	SAL	AL,1			; TEST FOR EDT FOUND
  2024 00003CF8 B404                <1> 	MOV	AH,RECORD_NOT_FND
  2025 00003CFA 7222                <1> 	JC	short J19
  2026 00003CFC C0E002              <1> 	SAL	AL,2
  2027 00003CFF B410                <1> 	MOV	AH,BAD_CRC
  2028 00003D01 721B                <1> 	JC	short J19
  2029 00003D03 D0E0                <1> 	SAL	AL,1			; TEST FOR DMA OVERRUN
  2030 00003D05 B408                <1> 	MOV	AH,BAD_DMA
  2031 00003D07 7215                <1> 	JC	short J19
  2032 00003D09 C0E002              <1> 	SAL	AL,2			; TEST FOR RECORD NOT FOUND
  2033 00003D0C B404                <1> 	MOV	AH,RECORD_NOT_FND
  2034 00003D0E 720E                <1> 	JC	short J19
  2035 00003D10 D0E0                <1> 	SAL	AL,1
  2036 00003D12 B403                <1> 	MOV	AH,WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  2037 00003D14 7208                <1> 	JC	short J19
  2038 00003D16 D0E0                <1> 	SAL	AL,1			; TEST MISSING ADDRESS MARK
  2039 00003D18 B402                <1> 	MOV	AH,BAD_ADDR_MARK
  2040 00003D1A 7202                <1> 	JC	short J19
  2041                              <1> 
  2042                              <1> ;----- 	NEC MUST HAVE FAILED
  2043                              <1> J18:
  2044 00003D1C B420                <1> 	MOV	AH,BAD_NEC
  2045                              <1> J19:
  2046 00003D1E 0825[30590100]      <1> 	OR	[DSKETTE_STATUS], AH
  2047                              <1> SET_END:
  2048 00003D24 803D[30590100]01    <1> 	CMP	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  2049 00003D2B F5                  <1> 	CMC
  2050 00003D2C 5E                  <1> 	POP	eSI
  2051 00003D2D C3                  <1> 	RETn				; RESTORE HEAD #, # OF SECTORS
  2052                              <1> 
  2053                              <1> SET_END_POP:
  2054 00003D2E 9D                  <1> 	POPF
  2055 00003D2F EBF3                <1> 	JMP	SHORT SET_END
  2056                              <1> 
  2057                              <1> ;-------------------------------------------------------------------------------
  2058                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  2059                              <1> ;-------------------------------------------------------------------------------
  2060                              <1> DSTATE:
  2061 00003D31 803D[30590100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  2062 00003D38 753E                <1> 	JNZ	short SETBAC		    ; IF ERROR JUMP
  2063 00003D3A 808F[3D590100]10    <1> 	OR	byte [DSK_STATE+eDI],MED_DET ; NO ERROR, MARK MEDIA AS DETERMINED
  2064 00003D41 F687[3D590100]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE DETERMINED ?
  2065 00003D48 752E                <1> 	JNZ	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  2066 00003D4A 8A87[3D590100]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  2067 00003D50 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  2068 00003D52 3C80                <1> 	CMP	AL,RATE_250		; RATE 250 ?
  2069 00003D54 751B                <1> 	JNE	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  2070                              <1> 
  2071                              <1> ;----- 	CHECK IF IT IS 1.44M
  2072                              <1> 
  2073 00003D56 E871010000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  2074                              <1> 	;;20/02/2015
  2075                              <1> 	;;JC	short M_12		; CMOS BAD
  2076 00003D5B 7414                <1> 	jz	short M_12 ;; 20/02/2015
  2077 00003D5D 3C04                <1> 	CMP	AL, 4			; 1.44MB DRIVE ?
  2078 00003D5F 7410                <1> 	JE	short M_12		; YES
  2079                              <1> M_720:
  2080 00003D61 80A7[3D590100]FD    <1> 	AND	byte [DSK_STATE+eDI], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  2081 00003D68 808F[3D590100]04    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET  ; MARK DRIVE DETERMINED
  2082 00003D6F EB07                <1> 	JMP	SHORT SETBAC		; BACK
  2083                              <1> M_12:	
  2084 00003D71 808F[3D590100]06    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET+FMT_CAPA 
  2085                              <1> 					; TURN ON DETERMINED & FMT CAPA
  2086                              <1> SETBAC:
  2087 00003D78 C3                  <1> 	RETn
  2088                              <1> 
  2089                              <1> ;-------------------------------------------------------------------------------
  2090                              <1> ; RETRY	
  2091                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  2092                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  2093                              <1> ;
  2094                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  2095                              <1> ;-------------------------------------------------------------------------------
  2096                              <1> RETRY:
  2097 00003D79 803D[30590100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; GET STATUS OF OPERATION
  2098 00003D80 7445                <1> 	JZ	short NO_RETRY		; SUCCESSFUL OPERATION
  2099 00003D82 803D[30590100]80    <1> 	CMP	byte [DSKETTE_STATUS],TIME_OUT ; IF TIME OUT NO RETRY
  2100 00003D89 743C                <1> 	JZ	short NO_RETRY
  2101 00003D8B 8AA7[3D590100]      <1> 	MOV	AH,[DSK_STATE+eDI]	; GET MEDIA STATE OF DRIVE
  2102 00003D91 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED/DETERMINED ?
  2103 00003D94 7531                <1> 	JNZ	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  2104 00003D96 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE RATE
  2105 00003D99 8A2D[38590100]      <1> 	MOV	CH,[LASTRATE]		; GET START OPERATION STATE
  2106 00003D9F C0C504              <1> 	ROL	CH,4			; TO CORRESPONDING BITS
  2107 00003DA2 80E5C0              <1> 	AND	CH,RATE_MSK		; ISOLATE RATE BITS
  2108 00003DA5 38E5                <1> 	CMP	CH,AH			; ALL RATES TRIED
  2109 00003DA7 741E                <1> 	JE	short NO_RETRY		; IF YES, THEN TRUE ERROR
  2110                              <1> 
  2111                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  2112                              <1> ;	 00000000B (500) -> 10000000B	(250)
  2113                              <1> ;	 10000000B (250) -> 01000000B	(300)
  2114                              <1> ;	 01000000B (300) -> 00000000B	(500)
  2115                              <1> 
  2116 00003DA9 80FC01              <1> 	CMP	AH,RATE_500+1		; SET CY FOR RATE 500
  2117 00003DAC D0DC                <1> 	RCR	AH,1			; TO NEXT STATE
  2118 00003DAE 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE BITS
  2119 00003DB1 80A7[3D590100]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP)
  2120                              <1> 					; RATE, DBL STEP OFF
  2121 00003DB8 08A7[3D590100]      <1> 	OR	[DSK_STATE+eDI],AH	; TURN ON NEW RATE
  2122 00003DBE C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; RESET STATUS FOR RETRY
  2123 00003DC5 F9                  <1> 	STC				; SET CARRY FOR RETRY
  2124 00003DC6 C3                  <1> 	RETn				; RETRY RETURN
  2125                              <1> 
  2126                              <1> NO_RETRY:
  2127 00003DC7 F8                  <1> 	CLC				; CLEAR CARRY NO RETRY
  2128 00003DC8 C3                  <1> 	RETn				; NO RETRY RETURN
  2129                              <1> 
  2130                              <1> ;-------------------------------------------------------------------------------
  2131                              <1> ; NUM_TRANS
  2132                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  2133                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  2134                              <1> ;
  2135                              <1> ; ON ENTRY:	[BP+1] = TRACK
  2136                              <1> ;		SI-HI  = HEAD
  2137                              <1> ;		[BP]   = START SECTOR
  2138                              <1> ;
  2139                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  2140                              <1> ;-------------------------------------------------------------------------------
  2141                              <1> NUM_TRANS:
  2142 00003DC9 30C0                <1> 	XOR	AL,AL			; CLEAR FOR ERROR
  2143 00003DCB 803D[30590100]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  2144 00003DD2 752C                <1> 	JNZ	NT_OUT			; IF ERROR 0 TRANSFERRED
  2145 00003DD4 B204                <1> 	MOV	DL,4			; SECTORS/TRACK OFFSET TO DL
  2146 00003DD6 E8FA000000          <1> 	CALL	GET_PARM		; AH = SECTORS/TRACK
  2147 00003DDB 8A1D[36590100]      <1> 	MOV	BL, [NEC_STATUS+5]	; GET ENDING SECTOR
  2148 00003DE1 6689F1              <1> 	MOV	CX,SI			; CH = HEAD # STARTED
  2149 00003DE4 3A2D[35590100]      <1> 	CMP	CH, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  2150 00003DEA 750D                <1> 	JNZ	DIF_HD			; IF ON SAME HEAD, THEN NO ADJUST
  2151 00003DEC 8A2D[34590100]      <1> 	MOV	CH, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  2152 00003DF2 3A6D01              <1> 	CMP	CH,[eBP+1]		; IS IT ASKED FOR TRACK
  2153 00003DF5 7404                <1> 	JZ	short SAME_TRK		; IF SAME TRACK NO INCREASE
  2154 00003DF7 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  2155                              <1> DIF_HD:
  2156 00003DF9 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  2157                              <1> SAME_TRK:
  2158 00003DFB 2A5D00              <1> 	SUB	BL,[eBP]		; SUBTRACT START FROM END
  2159 00003DFE 88D8                <1> 	MOV	AL,BL			; TO AL
  2160                              <1> NT_OUT:
  2161 00003E00 C3                  <1> 	RETn
  2162                              <1> 
  2163                              <1> ;-------------------------------------------------------------------------------
  2164                              <1> ; SETUP_END
  2165                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
  2166                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
  2167                              <1> ;
  2168                              <1> ; ON EXIT:
  2169                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2170                              <1> ;-------------------------------------------------------------------------------
  2171                              <1> SETUP_END:
  2172 00003E01 B202                <1> 	MOV	DL,2			; GET THE MOTOR WAIT PARAMETER
  2173 00003E03 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  2174 00003E05 E8CB000000          <1> 	CALL	GET_PARM
  2175 00003E0A 8825[2F590100]      <1> 	MOV	[MOTOR_COUNT],AH	; STORE UPON RETURN
  2176 00003E10 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  2177 00003E12 8A25[30590100]      <1> 	MOV	AH, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  2178 00003E18 08E4                <1> 	OR	AH,AH			; CHECK FOR ERROR
  2179 00003E1A 7402                <1> 	JZ	short NUN_ERR		; NO ERROR
  2180 00003E1C 30C0                <1> 	XOR	AL,AL			; CLEAR NUMBER RETURNED
  2181                              <1> NUN_ERR: 
  2182 00003E1E 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  2183 00003E21 F5                  <1> 	CMC				; SUCCESS OR FAILURE
  2184 00003E22 C3                  <1> 	RETn
  2185                              <1> 
  2186                              <1> ;-------------------------------------------------------------------------------
  2187                              <1> ; SETUP_DBL
  2188                              <1> ;	CHECK DOUBLE STEP.
  2189                              <1> ;
  2190                              <1> ; ON ENTRY :	DI = DRIVE
  2191                              <1> ;
  2192                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  2193                              <1> ;-------------------------------------------------------------------------------
  2194                              <1> SETUP_DBL:
  2195 00003E23 8AA7[3D590100]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  2196 00003E29 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED STATE ?
  2197 00003E2C 757E                <1> 	JNZ	short NO_DBL			; IF ESTABLISHED THEN DOUBLE DONE
  2198                              <1> 
  2199                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  2200                              <1> 
  2201 00003E2E C605[2D590100]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  2202 00003E35 E8E0000000          <1> 	CALL	MOTOR_ON		; ENSURE MOTOR STAY ON
  2203 00003E3A B500                <1> 	MOV	CH,0			; LOAD TRACK 0
  2204 00003E3C E8D4010000          <1> 	CALL	SEEK			; SEEK TO TRACK 0
  2205 00003E41 E868000000          <1> 	CALL	READ_ID			; READ ID FUNCTION
  2206 00003E46 7249                <1> 	JC	short SD_ERR		; IF ERROR NO TRACK 0
  2207                              <1> 
  2208                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  2209                              <1> 
  2210 00003E48 66B95004            <1> 	MOV	CX,0450H 		; START, MAX TRACKS
  2211 00003E4C F687[3D590100]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  2212 00003E53 7402                <1> 	JZ	short CNT_OK		; IF NOT COUNT IS SETUP
  2213 00003E55 B1A0                <1> 	MOV	CL,0A0H			; MAXIMUM TRACK 1.2 MB
  2214                              <1> 
  2215                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  2216                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  2217                              <1> ;	THEN SET DOUBLE STEP ON.
  2218                              <1> 
  2219                              <1> CNT_OK:
  2220 00003E57 C605[2F590100]FF    <1>         MOV     byte [MOTOR_COUNT], 0FFH ; ENSURE MOTOR STAYS ON FOR OPERATION 
  2221 00003E5E 6651                <1> 	PUSH	CX			; SAVE TRACK, COUNT
  2222 00003E60 C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR STATUS, EXPECT ERRORS
  2223 00003E67 6631C0              <1> 	XOR	AX,AX			; CLEAR AX
  2224 00003E6A D0ED                <1> 	SHR	CH,1			; HALVE TRACK, CY = HEAD
  2225 00003E6C C0D003              <1> 	RCL	AL,3			; AX = HEAD IN CORRECT BIT
  2226 00003E6F 6650                <1> 	PUSH	AX			; SAVE HEAD
  2227 00003E71 E89F010000          <1> 	CALL	SEEK			; SEEK TO TRACK
  2228 00003E76 6658                <1> 	POP	AX			; RESTORE HEAD
  2229 00003E78 6609C7              <1> 	OR	DI,AX			; DI = HEAD OR'ED DRIVE
  2230 00003E7B E82E000000          <1> 	CALL	READ_ID			; READ ID HEAD 0
  2231 00003E80 9C                  <1> 	PUSHF				; SAVE RETURN FROM READ_ID
  2232 00003E81 6681E7FB00          <1> 	AND	DI,11111011B		; TURN OFF HEAD 1 BIT
  2233 00003E86 9D                  <1> 	POPF				; RESTORE ERROR RETURN
  2234 00003E87 6659                <1> 	POP	CX			; RESTORE COUNT
  2235 00003E89 7308                <1> 	JNC	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  2236 00003E8B FEC5                <1> 	INC	CH			; INC FOR NEXT TRACK
  2237 00003E8D 38CD                <1> 	CMP	CH,CL			; REACHED MAXIMUM YET
  2238 00003E8F 75C6                <1> 	JNZ	short CNT_OK		; CONTINUE TILL ALL TRIED
  2239                              <1> 
  2240                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  2241                              <1> 
  2242                              <1> SD_ERR:	
  2243 00003E91 F9                  <1> 	STC				; SET CARRY FOR ERROR
  2244 00003E92 C3                  <1> 	RETn				; SETUP_DBL ERROR EXIT
  2245                              <1> 
  2246                              <1> DO_CHK:
  2247 00003E93 8A0D[34590100]      <1> 	MOV	CL, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  2248 00003E99 888F[41590100]      <1> 	MOV	[DSK_TRK+eDI], CL	; STORE TRACK NUMBER
  2249 00003E9F D0ED                <1> 	SHR	CH,1			; HALVE TRACK
  2250 00003EA1 38CD                <1> 	CMP	CH,CL			; IS IT THE SAME AS ASKED FOR TRACK
  2251 00003EA3 7407                <1> 	JZ	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  2252 00003EA5 808F[3D590100]20    <1> 	OR	byte [DSK_STATE+eDI],DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  2253                              <1> NO_DBL:
  2254 00003EAC F8                  <1> 	CLC				; CLEAR ERROR FLAG
  2255 00003EAD C3                  <1> 	RETn
  2256                              <1> 
  2257                              <1> ;-------------------------------------------------------------------------------
  2258                              <1> ; READ_ID
  2259                              <1> ;	READ ID FUNCTION.
  2260                              <1> ;
  2261                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  2262                              <1> ;
  2263                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  2264                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2265                              <1> ;-------------------------------------------------------------------------------
  2266                              <1> READ_ID:
  2267 00003EAE B8[CB3E0000]        <1> 	MOV	eAX, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  2268 00003EB3 50                  <1> 	PUSH	eAX
  2269 00003EB4 B44A                <1> 	MOV	AH,4AH			; READ ID COMMAND
  2270 00003EB6 E820010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  2271 00003EBB 6689F8              <1> 	MOV	AX,DI			; DRIVE # TO AH, HEAD 0
  2272 00003EBE 88C4                <1> 	MOV	AH,AL
  2273 00003EC0 E816010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  2274 00003EC5 E80BFEFFFF          <1> 	CALL	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  2275 00003ECA 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  2276                              <1> ER_3:
  2277 00003ECB C3                  <1> 	RETn
  2278                              <1> 
  2279                              <1> ;-------------------------------------------------------------------------------
  2280                              <1> ; CMOS_TYPE
  2281                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  2282                              <1> ;
  2283                              <1> ; ON ENTRY:	DI = DRIVE #
  2284                              <1> ;
  2285                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  2286                              <1> ;-------------------------------------------------------------------------------
  2287                              <1> 
  2288                              <1> CMOS_TYPE: ; 11/12/2014
  2289 00003ECC 8A87[265D0000]      <1> mov	al, [eDI+fd0_type]
  2290 00003ED2 20C0                <1> and 	al, al ; 18/12/2014
  2291 00003ED4 C3                  <1> retn
  2292                              <1> 
  2293                              <1> ;CMOS_TYPE:
  2294                              <1> ;	MOV	AL, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  2295                              <1> ;	CALL	CMOS_READ		; GET CMOS STATUS
  2296                              <1> ;	TEST	AL,BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  2297                              <1> ;	STC				; SET CY = 1 INDICATING ERROR FOR RETURN
  2298                              <1> ;	JNZ	short BAD_CM		; ERROR IF EITHER BIT ON
  2299                              <1> ;	MOV	AL,CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  2300                              <1> ;	CALL	CMOS_READ		; GET DISKETTE BYTE
  2301                              <1> ;	OR	DI,DI			; SEE WHICH DRIVE IN QUESTION
  2302                              <1> ;	JNZ	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  2303                              <1> ;	ROR	AL,4			; EXCHANGE NIBBLES IF SECOND DRIVE
  2304                              <1> ;TB:
  2305                              <1> ;	AND	AL,0FH			; KEEP ONLY DRIVE DATA, RESET CY, 0
  2306                              <1> ;BAD_CM:
  2307                              <1> ;	RETn				; CY, STATUS OF READ
  2308                              <1> 
  2309                              <1> ;-------------------------------------------------------------------------------
  2310                              <1> ; GET_PARM
  2311                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  2312                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  2313                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  2314                              <1> ;	THE PARAMETER IN DL.
  2315                              <1> ;
  2316                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  2317                              <1> ;
  2318                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  2319                              <1> ;		AL,DH DESTROYED
  2320                              <1> ;-------------------------------------------------------------------------------
  2321                              <1> GET_PARM:
  2322                              <1> 	;PUSH	DS
  2323 00003ED5 56                  <1> 	PUSH	eSI
  2324                              <1>     	;SUB	AX,AX			; DS = 0, BIOS DATA AREA
  2325                              <1>     	;MOV	DS,AX
  2326                              <1> 	;;mov	ax, cs
  2327                              <1> 	;;mov	ds, ax
  2328                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  2329 00003ED6 87D3                <1> 	XCHG	eDX,eBX			; BL = INDEX
  2330                              <1> 	;SUB	BH,BH			; BX = INDEX
  2331 00003ED8 81E3FF000000        <1> 	and	ebx, 0FFh
  2332                              <1>     	;LDS	SI, [DISK_POINTER]	; POINT TO BLOCK
  2333                              <1> 	;
  2334                              <1> 	; 17/12/2014
  2335 00003EDE 66A1[155D0000]      <1> 	mov	ax, [cfd] ; current (AL) and previous fd (AH)
  2336 00003EE4 38E0                <1> 	cmp	al, ah
  2337 00003EE6 7425                <1> 	je	short gpndc
  2338 00003EE8 A2[165D0000]        <1> 	mov	[pfd], al ; current drive -> previous drive
  2339 00003EED 53                  <1> 	push	ebx ; 08/02/2015
  2340 00003EEE 88C3                <1> 	mov	bl, al 
  2341                              <1> 	; 11/12/2014
  2342 00003EF0 8A83[265D0000]      <1> 	mov	al, [eBX+fd0_type]	; Drive type (0,1,2,3,4)
  2343                              <1> 	; 18/12/2014
  2344 00003EF6 20C0                <1> 	and	al, al
  2345 00003EF8 7507                <1> 	jnz	short gpdtc
  2346 00003EFA BB[FF5C0000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  2347 00003EFF EB05                <1>         jmp     short gpdpu
  2348                              <1> gpdtc:	
  2349 00003F01 E817F9FFFF          <1> 	call	DR_TYPE_CHECK
  2350                              <1> 	; cf = 1 -> eBX points to 1.44MB fd parameter table (default)
  2351                              <1> gpdpu:
  2352 00003F06 891D[9C5C0000]      <1> 	mov	[DISK_POINTER], ebx
  2353 00003F0C 5B                  <1> 	pop	ebx
  2354                              <1> gpndc:
  2355 00003F0D 8B35[9C5C0000]      <1> 	mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  2356 00003F13 8A241E              <1> 	MOV	AH, [eSI+eBX]		; GET THE WORD
  2357 00003F16 87D3                <1> 	XCHG	eDX,eBX			; RESTORE BX
  2358 00003F18 5E                  <1> 	POP	eSI
  2359                              <1> 	;POP	DS
  2360 00003F19 C3                  <1> 	RETn
  2361                              <1> 
  2362                              <1> ;-------------------------------------------------------------------------------
  2363                              <1> ; MOTOR_ON
  2364                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  2365                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  2366                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  2367                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  2368                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  2369                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  2370                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  2371                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  2372                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  2373                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  2374                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  2375                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  2376                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  2377                              <1> ;
  2378                              <1> ; ON ENTRY:	DI = DRIVE #
  2379                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  2380                              <1> ;-------------------------------------------------------------------------------
  2381                              <1> MOTOR_ON:
  2382 00003F1A 53                  <1> 	PUSH	eBX			; SAVE REG.
  2383 00003F1B E82A000000          <1> 	CALL	TURN_ON			; TURN ON MOTOR
  2384 00003F20 7226                <1> 	JC	short MOT_IS_ON		; IF CY=1 NO WAIT
  2385 00003F22 E89BF9FFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  2386 00003F27 E865F9FFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  2387                              <1> 	;CALL	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  2388                              <1> 	;JC	MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  2389                              <1> M_WAIT:
  2390 00003F2C B20A                <1> 	MOV	DL,10			; GET THE MOTOR WAIT PARAMETER
  2391 00003F2E E8A2FFFFFF          <1> 	CALL	GET_PARM
  2392                              <1> 	;MOV	AL,AH			; AL = MOTOR WAIT PARAMETER
  2393                              <1> 	;XOR	AH,AH			; AX = MOTOR WAIT PARAMETER
  2394                              <1> 	;CMP	AL,8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  2395 00003F33 80FC08              <1> 	cmp	ah, 8
  2396                              <1> 	;JAE	short GP2		; IF YES, CONTINUE
  2397 00003F36 7702                <1> 	ja	short J13
  2398                              <1> 	;MOV	AL,8			; ONE SECOND WAIT FOR MOTOR START UP
  2399 00003F38 B408                <1> 	mov	ah, 8
  2400                              <1> 
  2401                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  2402                              <1> GP2:	
  2403                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  2404                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  2405 00003F3A B95E200000          <1> 	MOV	eCX,8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  2406 00003F3F E8D9DEFFFF          <1> 	CALL	WAITF			; GO TO FIXED WAIT ROUTINE
  2407                              <1> 	;DEC	AL			; DECREMENT TIME VALUE
  2408 00003F44 FECC                <1> 	dec	ah
  2409 00003F46 75F2                <1> 	JNZ	short J13		; ARE WE DONE YET
  2410                              <1> MOT_IS_ON:
  2411 00003F48 5B                  <1> 	POP	eBX			; RESTORE REG.
  2412 00003F49 C3                  <1> 	RETn
  2413                              <1> 
  2414                              <1> ;-------------------------------------------------------------------------------
  2415                              <1> ; TURN_ON
  2416                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  2417                              <1> ;
  2418                              <1> ; ON ENTRY:	DI = DRIVE #
  2419                              <1> ;
  2420                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  2421                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  2422                              <1> ;		AX,BX,CX,DX DESTROYED
  2423                              <1> ;-------------------------------------------------------------------------------
  2424                              <1> TURN_ON:
  2425 00003F4A 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2426 00003F4C 88D9                <1> 	MOV	CL,BL			; CL = DRIVE #
  2427 00003F4E C0C304              <1> 	ROL	BL,4			; BL = DRIVE SELECT
  2428 00003F51 FA                  <1> 	CLI				; NO INTERRUPTS WHILE DETERMINING STATUS
  2429 00003F52 C605[2F590100]FF    <1> 	MOV	byte [MOTOR_COUNT],0FFH	; ENSURE MOTOR STAYS ON FOR OPERATION
  2430 00003F59 A0[2E590100]        <1> 	MOV	AL, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  2431 00003F5E 2430                <1> 	AND	AL,00110000B		; KEEP ONLY DRIVE SELECT BITS
  2432 00003F60 B401                <1> 	MOV	AH,1			; MASK FOR DETERMINING MOTOR BIT
  2433 00003F62 D2E4                <1> 	SHL	AH,CL			; AH = MOTOR ON, A=00000001, B=00000010
  2434                              <1> 
  2435                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  2436                              <1> ;  BL = DRIVE SELECT DESIRED
  2437                              <1> ;  AH = MOTOR ON MASK DESIRED
  2438                              <1> 
  2439 00003F64 38D8                <1> 	CMP	AL,BL			; REQUESTED DRIVE ALREADY SELECTED ?
  2440 00003F66 7508                <1> 	JNZ	short TURN_IT_ON	; IF NOT SELECTED JUMP
  2441 00003F68 8425[2E590100]      <1> 	TEST	AH, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  2442 00003F6E 7535                <1> 	JNZ	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  2443                              <1> 
  2444                              <1> TURN_IT_ON:
  2445 00003F70 08DC                <1> 	OR	AH,BL			; AH = DRIVE SELECT AND MOTOR ON
  2446 00003F72 8A3D[2E590100]      <1> 	MOV	BH,[MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  2447 00003F78 80E70F              <1> 	AND	BH,00001111B		; KEEP ONLY MOTOR BITS
  2448 00003F7B 8025[2E590100]CF    <1> 	AND	byte [MOTOR_STATUS],11001111B ; CLEAR OUT DRIVE SELECT
  2449 00003F82 0825[2E590100]      <1> 	OR	[MOTOR_STATUS],AH	; OR IN DRIVE SELECTED AND MOTOR ON
  2450 00003F88 A0[2E590100]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  2451 00003F8D 88C3                <1> 	MOV	BL,AL			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  2452 00003F8F 80E30F              <1> 	AND	BL,00001111B		; KEEP ONLY MOTOR BITS
  2453 00003F92 FB                  <1> 	STI				; ENABLE INTERRUPTS AGAIN
  2454 00003F93 243F                <1> 	AND	AL,00111111B		; STRIP AWAY UNWANTED BITS
  2455 00003F95 C0C004              <1> 	ROL	AL,4			; PUT BITS IN DESIRED POSITIONS
  2456 00003F98 0C0C                <1> 	OR	AL,00001100B		; NO RESET, ENABLE DMA/INTERRUPT
  2457 00003F9A 66BAF203            <1> 	MOV	DX,03F2H		; SELECT DRIVE AND TURN ON MOTOR
  2458 00003F9E EE                  <1> 	OUT	DX,AL
  2459 00003F9F 38FB                <1> 	CMP	BL,BH			; NEW MOTOR TURNED ON ?
  2460                              <1> 	;JZ	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  2461 00003FA1 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  2462 00003FA3 F8                  <1> 	CLC				; (re)SET CARRY MEANING WAIT
  2463 00003FA4 C3                  <1> 	RETn
  2464                              <1> 
  2465                              <1> NO_MOT_WAIT:
  2466 00003FA5 FB                  <1> 	sti
  2467                              <1> no_mot_w1: ; 27/02/2015
  2468 00003FA6 F9                  <1> 	STC				; SET NO WAIT REQUIRED
  2469                              <1> 	;STI				; INTERRUPTS BACK ON
  2470 00003FA7 C3                  <1> 	RETn
  2471                              <1> 
  2472                              <1> ;-------------------------------------------------------------------------------
  2473                              <1> ; HD_WAIT
  2474                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  2475                              <1> ;
  2476                              <1> ; ON ENTRY:	DI = DRIVE #
  2477                              <1> ;
  2478                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  2479                              <1> ;-------------------------------------------------------------------------------
  2480                              <1> HD_WAIT:
  2481 00003FA8 B209                <1> 	MOV	DL,9			; GET HEAD SETTLE PARAMETER
  2482 00003FAA E826FFFFFF          <1> 	CALL	GET_PARM
  2483 00003FAF 08E4                <1> 	or	ah, ah	; 17/12/2014
  2484 00003FB1 7519                <1> 	jnz	short DO_WAT
  2485 00003FB3 F605[2E590100]80    <1>         TEST    byte [MOTOR_STATUS],10000000B ; SEE IF A WRITE OPERATION
  2486                              <1> 	;JZ	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  2487                              <1> 	;OR	AH,AH			; CHECK FOR ANY WAIT?
  2488                              <1> 	;JNZ	short DO_WAT		; IF THERE DO NOT ENFORCE
  2489 00003FBA 741E                <1> 	jz	short HW_DONE
  2490 00003FBC B40F                <1> 	MOV	AH,HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  2491 00003FBE 8A87[3D590100]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  2492 00003FC4 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  2493 00003FC6 3C80                <1> 	CMP	AL,RATE_250		; 1.2 M DRIVE ?
  2494 00003FC8 7502                <1> 	JNZ	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  2495                              <1> ;GP3:
  2496 00003FCA B414                <1> 	MOV	AH,HD320_SETTLE		; USE 320/360 HEAD SETTLE
  2497                              <1> ;	JMP	SHORT DO_WAT
  2498                              <1> 
  2499                              <1> ;ISNT_WRITE:
  2500                              <1> ;	OR	AH,AH			; CHECK FOR NO WAIT
  2501                              <1> ;	JZ	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  2502                              <1> 
  2503                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  2504                              <1> DO_WAT:
  2505                              <1> ;	MOV	AL,AH			; AL = # MILLISECONDS
  2506                              <1> ;	;XOR	AH,AH			; AX = # MILLISECONDS
  2507                              <1> J29:					; 	1 MILLISECOND LOOP
  2508                              <1> 	;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  2509 00003FCC B942000000          <1> 	MOV	eCX,66			; COUNT AT 15.085737 US PER COUNT
  2510 00003FD1 E847DEFFFF          <1> 	CALL	WAITF			; DELAY FOR 1 MILLISECOND
  2511                              <1> 	;DEC	AL			; DECREMENT THE COUNT
  2512 00003FD6 FECC                <1> 	dec	ah
  2513 00003FD8 75F2                <1> 	JNZ	short J29		; DO AL MILLISECOND # OF TIMES
  2514                              <1> HW_DONE:
  2515 00003FDA C3                  <1> 	RETn
  2516                              <1> 
  2517                              <1> ;-------------------------------------------------------------------------------
  2518                              <1> ; NEC_OUTPUT
  2519                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  2520                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  2521                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  2522                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  2523                              <1> ; 
  2524                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  2525                              <1> ;
  2526                              <1> ; ON EXIT:	CY = 0  SUCCESS
  2527                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  2528                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  2529                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  2530                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  2531                              <1> ;		AX,CX,DX DESTROYED
  2532                              <1> ;-------------------------------------------------------------------------------
  2533                              <1> 
  2534                              <1> ; 09/12/2014 [Erdogan Tan] 
  2535                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  2536                              <1> ; Diskette Drive Controller Status Register (3F4h)
  2537                              <1> ;	This read only register facilitates the transfer of data between
  2538                              <1> ;	the system microprocessor and the controller.
  2539                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  2540                              <1> ;	  with the system micrprocessor.
  2541                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  2542                              <1> ;	  the transfer is to the controller.
  2543                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  2544                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  2545                              <1> ; Bit 3 - Reserved.
  2546                              <1> ; Bit 2 - Reserved.
  2547                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  2548                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  2549                              <1> 
  2550                              <1> ; Data Register (3F5h)
  2551                              <1> ; This read/write register passes data, commands and parameters, and provides
  2552                              <1> ; diskette status information.
  2553                              <1>   		
  2554                              <1> NEC_OUTPUT:
  2555                              <1> 	;PUSH	BX			; SAVE REG.
  2556 00003FDB 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  2557                              <1> 	;MOV	BL,2			; HIGH ORDER COUNTER
  2558                              <1> 	;XOR	CX,CX			; COUNT FOR TIME OUT
  2559                              <1> 	; 16/12/2014
  2560                              <1> 	; waiting for (max.) 0.5 seconds
  2561                              <1>         ;;mov     byte [wait_count], 0 ;; 27/02/2015
  2562                              <1> 	;
  2563                              <1> 	; 17/12/2014
  2564                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  2565                              <1> 	;
  2566                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  2567                              <1> 	;		go on.
  2568                              <1> 	;INPUT:
  2569                              <1> 	;	AH=Mask for isolation bits.
  2570                              <1> 	;	AL=pattern to look for.
  2571                              <1> 	;	DX=Port to test for
  2572                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  2573                              <1> 	;	     (normally 30 microseconds per period.)
  2574                              <1> 	;
  2575                              <1> 	;WFP_SHORT:  
  2576                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  2577                              <1> 	;
  2578                              <1> 
  2579                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  2580                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  2581 00003FDF B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  2582                              <1> ;
  2583                              <1> ;WFPS_OUTER_LP:
  2584                              <1> ;	;
  2585                              <1> ;WFPS_CHECK_PORT:
  2586                              <1> J23:
  2587 00003FE4 EC                  <1> 	IN	AL,DX			; GET STATUS
  2588 00003FE5 24C0                <1> 	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  2589 00003FE7 3C80                <1> 	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  2590 00003FE9 7418                <1> 	JZ	short J27		; STATUS AND DIRECTION OK
  2591                              <1> WFPS_HI:
  2592 00003FEB E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  2593 00003FED A810                <1> 	TEST	AL,010H			; transition on memory
  2594 00003FEF 75FA                <1> 	JNZ	SHORT WFPS_HI		; refresh.
  2595                              <1> WFPS_LO:
  2596 00003FF1 E461                <1> 	IN	AL, PORT_B		; SYS1
  2597 00003FF3 A810                <1> 	TEST	AL,010H
  2598 00003FF5 74FA                <1> 	JZ	SHORT WFPS_LO
  2599                              <1> 	;LOOP	SHORT WFPS_CHECK_PORT
  2600 00003FF7 E2EB                <1> 	loop	J23	; 27/02/2015
  2601                              <1> ;	;
  2602                              <1> ;	dec	bl
  2603                              <1> ;	jnz	short WFPS_OUTER_LP
  2604                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  2605                              <1> ;J23:
  2606                              <1> ;	IN	AL,DX			; GET STATUS
  2607                              <1> ;	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  2608                              <1> ;	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  2609                              <1> ;	JZ	short J27		; STATUS AND DIRECTION OK
  2610                              <1> 	;LOOP	J23			; CONTINUE TILL CX EXHAUSTED
  2611                              <1> 	;DEC	BL			; DECREMENT COUNTER
  2612                              <1> 	;JNZ	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  2613                              <1>    
  2614                              <1> 	;;27/02/2015
  2615                              <1> 	;16/12/2014
  2616                              <1>         ;;cmp     byte [wait_count], 10   ; (10/18.2 seconds)
  2617                              <1> 	;;jb	short J23
  2618                              <1> 
  2619                              <1> ;WFPS_TIMEOUT:
  2620                              <1> 
  2621                              <1> ;-----	FALL THRU TO ERROR RETURN
  2622                              <1> 
  2623 00003FF9 800D[30590100]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  2624                              <1> 	;POP	BX			; RESTORE REG.
  2625 00004000 58                  <1> 	POP	eAX ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  2626 00004001 F9                  <1> 	STC				; INDICATE ERROR TO CALLER
  2627 00004002 C3                  <1> 	RETn
  2628                              <1> 
  2629                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  2630                              <1> 
  2631                              <1> J27:	
  2632 00004003 88E0                <1> 	MOV	AL,AH			; GET BYTE TO OUTPUT
  2633 00004005 6642                <1> 	INC	DX			; DATA PORT = STATUS PORT + 1
  2634 00004007 EE                  <1> 	OUT	DX,AL			; OUTPUT THE BYTE
  2635                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  2636                              <1> 	; 27/02/2015
  2637 00004008 9C                  <1> 	PUSHF				; SAVE FLAGS
  2638 00004009 B903000000          <1> 	MOV	eCX, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  2639 0000400E E80ADEFFFF          <1> 	CALL 	WAITF			; NEC FLAGS UPDATE CYCLE
  2640 00004013 9D                  <1> 	POPF				; RESTORE FLAGS FOR EXIT
  2641                              <1> 	;POP	BX			; RESTORE REG
  2642 00004014 C3                  <1> 	RETn				; CY = 0 FROM TEST INSTRUCTION
  2643                              <1> 
  2644                              <1> ;-------------------------------------------------------------------------------
  2645                              <1> ; SEEK
  2646                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  2647                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  2648                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  2649                              <1> ;
  2650                              <1> ; ON ENTRY:	DI = DRIVE #
  2651                              <1> ;		CH = TRACK #
  2652                              <1> ;
  2653                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2654                              <1> ;		AX,BX,CX DX DESTROYED
  2655                              <1> ;-------------------------------------------------------------------------------
  2656                              <1> SEEK:
  2657 00004015 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2658 00004017 B001                <1> 	MOV	AL,1			; ESTABLISH MASK FOR RECALIBRATE TEST
  2659 00004019 86CB                <1> 	XCHG	CL,BL			; SET DRIVE VALULE INTO CL
  2660 0000401B D2C0                <1> 	ROL	AL,CL			; SHIFT MASK BY THE DRIVE VALUE
  2661 0000401D 86CB                <1> 	XCHG	CL,BL			; RECOVER TRACK VALUE
  2662 0000401F 8405[2D590100]      <1> 	TEST	AL,[SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  2663 00004025 7526                <1> 	JNZ	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  2664                              <1> 
  2665 00004027 0805[2D590100]      <1> 	OR	[SEEK_STATUS],AL	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  2666 0000402D E862000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2667 00004032 730E                <1> 	JNC	short AFT_RECAL		; RECALIBRATE DONE
  2668                              <1> 
  2669                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  2670                              <1> 
  2671 00004034 C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR OUT INVALID STATUS
  2672 0000403B E854000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2673 00004040 7251                <1> 	JC	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  2674                              <1> 
  2675                              <1> AFT_RECAL:
  2676 00004042 C687[41590100]00    <1>         MOV     byte [DSK_TRK+eDI],0    ; SAVE NEW CYLINDER AS PRESENT POSITION
  2677 00004049 08ED                <1> 	OR	CH,CH			; CHECK FOR SEEK TO TRACK 0
  2678 0000404B 743F                <1> 	JZ	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  2679                              <1> 
  2680                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  2681                              <1> 
  2682 0000404D F687[3D590100]20    <1> J28A:	TEST	byte [DSK_STATE+eDI],DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  2683 00004054 7402                <1> 	JZ	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  2684 00004056 D0E5                <1> 	SHL	CH,1			; DOUBLE NUMBER OF STEP TO TAKE
  2685                              <1> 
  2686 00004058 3AAF[41590100]      <1> _R7:	CMP	CH, [DSK_TRK+eDI]	; SEE IF ALREADY AT THE DESIRED TRACK
  2687 0000405E 7433                <1> 	JE	short RB		; IF YES, DO NOT NEED TO SEEK
  2688                              <1> 
  2689 00004060 BA[93400000]        <1> 	MOV	eDX, NEC_ERR		; LOAD RETURN ADDRESS
  2690 00004065 52                  <1> 	PUSH	eDX ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  2691 00004066 88AF[41590100]      <1> 	MOV	[DSK_TRK+eDI],CH	; SAVE NEW CYLINDER AS PRESENT POSITION
  2692 0000406C B40F                <1> 	MOV	AH,0FH			; SEEK COMMAND TO NEC
  2693 0000406E E868FFFFFF          <1> 	CALL	NEC_OUTPUT
  2694 00004073 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2695 00004075 88DC                <1> 	MOV	AH,BL			; OUTPUT DRIVE NUMBER
  2696 00004077 E85FFFFFFF          <1> 	CALL	NEC_OUTPUT
  2697 0000407C 8AA7[41590100]      <1> 	MOV	AH, [DSK_TRK+eDI]	; GET CYLINDER NUMBER
  2698 00004082 E854FFFFFF          <1> 	CALL	NEC_OUTPUT
  2699 00004087 E829000000          <1> 	CALL	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  2700                              <1> 
  2701                              <1> ;-----	WAIT FOR HEAD SETTLE
  2702                              <1> 
  2703                              <1> DO_WAIT:
  2704 0000408C 9C                  <1> 	PUSHF				; SAVE STATUS
  2705 0000408D E816FFFFFF          <1> 	CALL	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  2706 00004092 9D                  <1> 	POPF				; RESTORE STATUS
  2707                              <1> RB:
  2708                              <1> NEC_ERR:
  2709                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  2710                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  2711 00004093 C3                  <1> 	RETn				; RETURN TO CALLER
  2712                              <1> 
  2713                              <1> ;-------------------------------------------------------------------------------
  2714                              <1> ; RECAL
  2715                              <1> ;	RECALIBRATE DRIVE
  2716                              <1> ;
  2717                              <1> ; ON ENTRY:	DI = DRIVE #
  2718                              <1> ;
  2719                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  2720                              <1> ;-------------------------------------------------------------------------------
  2721                              <1> RECAL:
  2722 00004094 6651                <1> 	PUSH	CX
  2723 00004096 B8[B2400000]        <1> 	MOV	eAX, RC_BACK		; LOAD NEC_OUTPUT ERROR
  2724 0000409B 50                  <1> 	PUSH	eAX
  2725 0000409C B407                <1> 	MOV	AH,07H			; RECALIBRATE COMMAND
  2726 0000409E E838FFFFFF          <1> 	CALL	NEC_OUTPUT
  2727 000040A3 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  2728 000040A5 88DC                <1> 	MOV	AH,BL
  2729 000040A7 E82FFFFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  2730 000040AC E804000000          <1> 	CALL	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  2731 000040B1 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  2732                              <1> RC_BACK:
  2733 000040B2 6659                <1> 	POP	CX
  2734 000040B4 C3                  <1> 	RETn
  2735                              <1> 
  2736                              <1> ;-------------------------------------------------------------------------------
  2737                              <1> ; CHK_STAT_2
  2738                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  2739                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  2740                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  2741                              <1> ;
  2742                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2743                              <1> ;-------------------------------------------------------------------------------
  2744                              <1> CHK_STAT_2:
  2745 000040B5 B8[DD400000]        <1>         MOV     eAX, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  2746 000040BA 50                  <1> 	PUSH	eAX
  2747 000040BB E828000000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  2748 000040C0 721A                <1> 	JC	short J34		; IF ERROR, RETURN IT
  2749 000040C2 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  2750 000040C4 E812FFFFFF          <1> 	CALL	NEC_OUTPUT
  2751 000040C9 E84A000000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  2752 000040CE 720C                <1> 	JC	short J34
  2753 000040D0 A0[31590100]        <1> 	MOV	AL,[NEC_STATUS]		; GET THE FIRST STATUS BYTE
  2754 000040D5 2460                <1> 	AND	AL,01100000B		; ISOLATE THE BITS
  2755 000040D7 3C60                <1> 	CMP	AL,01100000B		; TEST FOR CORRECT VALUE
  2756 000040D9 7403                <1> 	JZ	short J35		; IF ERROR, GO MARK IT
  2757 000040DB F8                  <1> 	CLC				; GOOD RETURN
  2758                              <1> J34:
  2759 000040DC 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  2760                              <1> CS_BACK:
  2761 000040DD C3                  <1> 	RETn
  2762                              <1> J35:
  2763 000040DE 800D[30590100]40    <1> 	OR	byte [DSKETTE_STATUS], BAD_SEEK
  2764 000040E5 F9                  <1> 	STC				; ERROR RETURN CODE
  2765 000040E6 EBF4                <1> 	JMP	SHORT J34
  2766                              <1> 
  2767                              <1> ;-------------------------------------------------------------------------------
  2768                              <1> ; WAIT_INT
  2769                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  2770                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  2771                              <1> ;	IF THE DRIVE IS NOT READY.
  2772                              <1> ;
  2773                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2774                              <1> ;-------------------------------------------------------------------------------
  2775                              <1> 
  2776                              <1> ; 17/12/2014
  2777                              <1> ; 2.5 seconds waiting !
  2778                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  2779                              <1> ; amount of time to wait for completion interrupt from NEC.
  2780                              <1> 
  2781                              <1> 
  2782                              <1> WAIT_INT:
  2783 000040E8 FB                  <1> 	STI				; TURN ON INTERRUPTS, JUST IN CASE
  2784 000040E9 F8                  <1> 	CLC				; CLEAR TIMEOUT INDICATOR
  2785                              <1>        ;MOV	BL,10			; CLEAR THE COUNTERS
  2786                              <1>        ;XOR	CX,CX			; FOR 2 SECOND WAIT
  2787                              <1> 
  2788                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  2789                              <1> 	;
  2790                              <1> 	;WAIT_FOR_MEM:	
  2791                              <1> 	;	Waits for a bit at a specified memory location pointed
  2792                              <1> 	;	to by ES:[DI] to become set.
  2793                              <1> 	;INPUT:
  2794                              <1> 	;	AH=Mask to test with.
  2795                              <1> 	;	ES:[DI] = memory location to watch.
  2796                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  2797                              <1> 	;	     (normally 30 microseconds per period.)
  2798                              <1> 
  2799                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  2800                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  2801                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  2802                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  2803                              <1> 	; 27/02/2015
  2804 000040EA B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  2805                              <1> WFMS_CHECK_MEM:
  2806 000040EF F605[2D590100]80    <1> 	test	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  2807 000040F6 7516                <1>         jnz     short J37
  2808                              <1> WFMS_HI:
  2809 000040F8 E461                <1> 	IN	AL,PORT_B  ; 061h	; SYS1, wait for lo to hi
  2810 000040FA A810                <1> 	TEST	AL,010H			; transition on memory
  2811 000040FC 75FA                <1> 	JNZ	SHORT WFMS_HI		; refresh.
  2812                              <1> WFMS_LO:
  2813 000040FE E461                <1> 	IN	AL,PORT_B		;SYS1
  2814 00004100 A810                <1> 	TEST	AL,010H
  2815 00004102 74FA                <1> 	JZ	SHORT WFMS_LO
  2816 00004104 E2E9                <1>         LOOP    WFMS_CHECK_MEM
  2817                              <1> ;WFMS_OUTER_LP:
  2818                              <1> ;;	or	bl, bl			; check outer counter
  2819                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  2820                              <1> ;	dec	bl
  2821                              <1> ;	jz	short J36A	
  2822                              <1> ;	jmp	short WFMS_CHECK_MEM
  2823                              <1> 
  2824                              <1> 	;17/12/2014
  2825                              <1> 	;16/12/2014
  2826                              <1> ;        mov     byte [wait_count], 0    ; Reset (INT 08H) counter
  2827                              <1> ;J36:
  2828                              <1> ;	TEST	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  2829                              <1> ;	JNZ	short J37
  2830                              <1> 	;16/12/2014
  2831                              <1> 	;LOOP	J36			; COUNT DOWN WHILE WAITING
  2832                              <1> 	;DEC	BL			; SECOND LEVEL COUNTER
  2833                              <1> 	;JNZ	short J36
  2834                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  2835                              <1> ;	jb	short J36
  2836                              <1> 
  2837                              <1> ;WFMS_TIMEOUT:
  2838                              <1> ;J36A:
  2839 00004106 800D[30590100]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  2840 0000410D F9                  <1> 	STC				; ERROR RETURN
  2841                              <1> J37:
  2842 0000410E 9C                  <1> 	PUSHF				; SAVE CURRENT CARRY
  2843 0000410F 8025[2D590100]7F    <1> 	AND	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  2844 00004116 9D                  <1> 	POPF				; RECOVER CARRY
  2845 00004117 C3                  <1> 	RETn				; GOOD RETURN CODE
  2846                              <1> 
  2847                              <1> ;-------------------------------------------------------------------------------
  2848                              <1> ; RESULTS
  2849                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  2850                              <1> ;	FOLLOWING AN INTERRUPT.
  2851                              <1> ;
  2852                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  2853                              <1> ;		AX,BX,CX,DX DESTROYED
  2854                              <1> ;-------------------------------------------------------------------------------
  2855                              <1> RESULTS:
  2856 00004118 57                  <1> 	PUSH	eDI
  2857 00004119 BF[31590100]        <1> 	MOV	eDI, NEC_STATUS		; POINTER TO DATA AREA
  2858 0000411E B307                <1> 	MOV	BL,7			; MAX STATUS BYTES
  2859 00004120 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  2860                              <1> 
  2861                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  2862                              <1> 
  2863                              <1> _R10: 
  2864                              <1> 	; 16/12/2014
  2865                              <1> 	; wait for (max) 0.5 seconds
  2866                              <1> 	;MOV	BH,2			; HIGH ORDER COUNTER
  2867                              <1> 	;XOR	CX,CX			; COUNTER
  2868                              <1> 
  2869                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  2870                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  2871                              <1> 	; 27/02/2015
  2872 00004124 B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  2873                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  2874                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  2875                              <1> 
  2876                              <1> WFPSR_OUTER_LP:
  2877                              <1> 	;
  2878                              <1> WFPSR_CHECK_PORT:
  2879                              <1> J39:					; WAIT FOR MASTER
  2880 00004129 EC                  <1> 	IN	AL,DX			; GET STATUS
  2881 0000412A 24C0                <1> 	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  2882 0000412C 3CC0                <1> 	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  2883 0000412E 7418                <1> 	JZ	short J42		; STATUS AND DIRECTION OK
  2884                              <1> WFPSR_HI:
  2885 00004130 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  2886 00004132 A810                <1> 	TEST	AL,010H			; transition on memory
  2887 00004134 75FA                <1> 	JNZ	SHORT WFPSR_HI		; refresh.
  2888                              <1> WFPSR_LO:
  2889 00004136 E461                <1> 	IN	AL, PORT_B		; SYS1
  2890 00004138 A810                <1> 	TEST	AL,010H
  2891 0000413A 74FA                <1> 	JZ	SHORT WFPSR_LO
  2892 0000413C E2EB                <1>         LOOP    WFPSR_CHECK_PORT
  2893                              <1> 	;; 27/02/2015
  2894                              <1> 	;;dec	bh
  2895                              <1> 	;;jnz	short WFPSR_OUTER_LP
  2896                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  2897                              <1> 
  2898                              <1> 	;;mov	byte [wait_count], 0
  2899                              <1> ;J39:					; WAIT FOR MASTER
  2900                              <1> ;	IN	AL,DX			; GET STATUS
  2901                              <1> ;	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  2902                              <1> ;	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  2903                              <1> ;	JZ	short J42		; STATUS AND DIRECTION OK
  2904                              <1> 	;LOOP	J39			; LOOP TILL TIMEOUT
  2905                              <1> 	;DEC	BH			; DECREMENT HIGH ORDER COUNTER
  2906                              <1> 	;JNZ	short J39		; REPEAT TILL DELAY DONE
  2907                              <1> 	;
  2908                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  2909                              <1> 	;;jb	short J39	
  2910                              <1> 
  2911                              <1> ;WFPSR_TIMEOUT:
  2912 0000413E 800D[30590100]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  2913 00004145 F9                  <1> 	STC				; SET ERROR RETURN
  2914 00004146 EB29                <1> 	JMP	SHORT POPRES		; POP REGISTERS AND RETURN
  2915                              <1> 
  2916                              <1> ;-----	READ IN THE STATUS
  2917                              <1> 
  2918                              <1> J42:
  2919 00004148 EB00                <1> 	JMP	$+2			; I/O DELAY
  2920 0000414A 6642                <1> 	INC	DX			; POINT AT DATA PORT
  2921 0000414C EC                  <1> 	IN	AL,DX			; GET THE DATA
  2922                              <1> 	; 16/12/2014
  2923                              <1> 	NEWIODELAY
  2923 0000414D E6EB                <2>  out 0ebh,al
  2924 0000414F 8807                <1>         MOV     [eDI],AL                ; STORE THE BYTE
  2925 00004151 47                  <1> 	INC	eDI			; INCREMENT THE POINTER
  2926                              <1> 	; 16/12/2014
  2927                              <1> ;	push	cx
  2928                              <1> ;	mov	cx, 30
  2929                              <1> ;wdw2:
  2930                              <1> ;	NEWIODELAY
  2931                              <1> ;	loop	wdw2
  2932                              <1> ;	pop	cx
  2933                              <1> 
  2934 00004152 B903000000          <1> 	MOV	eCX,3			; MINIMUM 24 MICROSECONDS FOR NEC
  2935 00004157 E8C1DCFFFF          <1> 	CALL	WAITF			; WAIT 30 TO 45 MICROSECONDS
  2936 0000415C 664A                <1> 	DEC	DX			; POINT AT STATUS PORT
  2937 0000415E EC                  <1> 	IN	AL,DX			; GET STATUS
  2938                              <1> 	; 16/12/2014
  2939                              <1> 	NEWIODELAY
  2939 0000415F E6EB                <2>  out 0ebh,al
  2940                              <1> 	;
  2941 00004161 A810                <1> 	TEST	AL,00010000B		; TEST FOR NEC STILL BUSY
  2942 00004163 740C                <1> 	JZ	short POPRES		; RESULTS DONE ?
  2943                              <1> 
  2944 00004165 FECB                <1> 	DEC	BL			; DECREMENT THE STATUS COUNTER
  2945 00004167 75BB                <1>         JNZ     short _R10              ; GO BACK FOR MORE
  2946 00004169 800D[30590100]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; TOO MANY STATUS BYTES
  2947 00004170 F9                  <1> 	STC				; SET ERROR FLAG
  2948                              <1> 
  2949                              <1> ;-----	RESULT OPERATION IS DONE
  2950                              <1> POPRES:
  2951 00004171 5F                  <1> 	POP	eDI
  2952 00004172 C3                  <1> 	RETn				; RETURN WITH CARRY SET
  2953                              <1> 
  2954                              <1> ;-------------------------------------------------------------------------------
  2955                              <1> ; READ_DSKCHNG
  2956                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  2957                              <1> ;
  2958                              <1> ; ON ENTRY:	DI = DRIVE #
  2959                              <1> ;
  2960                              <1> ; ON EXIT:	DI = DRIVE #
  2961                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  2962                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  2963                              <1> ;		AX,CX,DX DESTROYED
  2964                              <1> ;-------------------------------------------------------------------------------
  2965                              <1> READ_DSKCHNG:
  2966 00004173 E8A2FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  2967 00004178 66BAF703            <1> 	MOV	DX,03F7H		; ADDRESS DIGITAL INPUT REGISTER
  2968 0000417C EC                  <1> 	IN	AL,DX			; INPUT DIGITAL INPUT REGISTER
  2969 0000417D A880                <1> 	TEST	AL,DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  2970 0000417F C3                  <1> 	RETn				; RETURN TO CALLER WITH ZERO FLAG SET
  2971                              <1> 
  2972                              <1> ;-------------------------------------------------------------------------------
  2973                              <1> ; DRIVE_DET
  2974                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  2975                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  2976                              <1> ; ON ENTRY:	DI = DRIVE #
  2977                              <1> ;-------------------------------------------------------------------------------
  2978                              <1> DRIVE_DET:
  2979 00004180 E895FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  2980 00004185 E80AFFFFFF          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  2981 0000418A 7251                <1> 	JC	short DD_BAC		; ASSUME NO DRIVE PRESENT
  2982 0000418C B530                <1> 	MOV	CH,TRK_SLAP		; SEEK TO TRACK 48
  2983 0000418E E882FEFFFF          <1> 	CALL	SEEK
  2984 00004193 7248                <1> 	JC	short DD_BAC		; ERROR NO DRIVE
  2985 00004195 B50B                <1> 	MOV	CH,QUIET_SEEK+1		; SEEK TO TRACK 10
  2986                              <1> SK_GIN:
  2987 00004197 FECD                <1> 	DEC	CH			; DECREMENT TO NEXT TRACK
  2988 00004199 6651                <1> 	PUSH	CX			; SAVE TRACK
  2989 0000419B E875FEFFFF          <1> 	CALL	SEEK
  2990 000041A0 723C                <1> 	JC	short POP_BAC		; POP AND RETURN
  2991 000041A2 B8[DE410000]        <1> 	MOV	eAX, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  2992 000041A7 50                  <1> 	PUSH	eAX
  2993 000041A8 B404                <1> 	MOV	AH,SENSE_DRV_ST		; SENSE DRIVE STATUS COMMAND BYTE
  2994 000041AA E82CFEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  2995 000041AF 6689F8              <1> 	MOV	AX,DI			; AL = DRIVE
  2996 000041B2 88C4                <1> 	MOV	AH,AL			; AH = DRIVE
  2997 000041B4 E822FEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  2998 000041B9 E85AFFFFFF          <1> 	CALL	RESULTS			; GO GET STATUS
  2999 000041BE 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  3000 000041BF 6659                <1> 	POP	CX			; RESTORE TRACK
  3001 000041C1 F605[31590100]10    <1> 	TEST	byte [NEC_STATUS], HOME	; TRACK 0 ?
  3002 000041C8 74CD                <1> 	JZ	short SK_GIN		; GO TILL TRACK 0
  3003 000041CA 08ED                <1> 	OR	CH,CH			; IS HOME AT TRACK 0
  3004 000041CC 7408                <1> 	JZ	short IS_80		; MUST BE 80 TRACK DRIVE
  3005                              <1> 
  3006                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  3007                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  3008                              <1> 
  3009 000041CE 808F[3D590100]94    <1> 	OR	byte [DSK_STATE+eDI], DRV_DET+MED_DET+RATE_250
  3010 000041D5 C3                  <1> 	RETn				; ALL INFORMATION SET
  3011                              <1> IS_80:
  3012 000041D6 808F[3D590100]01    <1> 	OR	byte [DSK_STATE+eDI], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  3013                              <1> DD_BAC:
  3014 000041DD C3                  <1> 	RETn
  3015                              <1> POP_BAC:
  3016 000041DE 6659                <1> 	POP	CX			; THROW AWAY
  3017 000041E0 C3                  <1> 	RETn
  3018                              <1> 
  3019                              <1> fdc_int:  
  3020                              <1> 	  ; 30/07/2015	
  3021                              <1> 	  ; 16/02/2015
  3022                              <1> ;int_0Eh: ; 11/12/2014
  3023                              <1> 
  3024                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL  6 ) --------------------------------------
  3025                              <1> ; DISK_INT
  3026                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  3027                              <1> ;
  3028                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  3029                              <1> ;-------------------------------------------------------------------------------
  3030                              <1> DISK_INT_1:
  3031                              <1> 
  3032 000041E1 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER
  3033 000041E3 1E                  <1> 	push	ds
  3034 000041E4 66B81000            <1> 	mov	ax, KDATA
  3035 000041E8 8ED8                <1> 	mov 	ds, ax
  3036 000041EA 800D[2D590100]80    <1>         OR      byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  3037 000041F1 B020                <1> 	MOV     AL,EOI                  ; END OF INTERRUPT MARKER
  3038 000041F3 E620                <1> 	OUT	INTA00,AL		; INTERRUPT CONTROL PORT
  3039 000041F5 1F                  <1> 	pop	ds
  3040 000041F6 6658                <1> 	POP	AX			; RECOVER REGISTER
  3041 000041F8 CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
  3042                              <1> 
  3043                              <1> ;-------------------------------------------------------------------------------
  3044                              <1> ; DSKETTE_SETUP
  3045                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  3046                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  3047                              <1> ;-------------------------------------------------------------------------------
  3048                              <1> 
  3049                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  3050                              <1> 
  3051                              <1> DSKETTE_SETUP:
  3052                              <1> 	;PUSH	AX			; SAVE REGISTERS
  3053                              <1> 	;PUSH	BX
  3054                              <1> 	;PUSH	CX
  3055 000041F9 52                  <1> 	PUSH	eDX
  3056                              <1> 	;PUSH	DI
  3057                              <1> 	;;PUSH	DS
  3058                              <1> 	; 14/12/2014
  3059                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  3060                              <1> 	;mov	[DISK_POINTER+2], cs
  3061                              <1> 	;
  3062                              <1> 	;OR	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  3063 000041FA 31FF                <1> 	XOR	eDI,eDI			; INITIALIZE DRIVE POINTER
  3064 000041FC 66C705[3D590100]00- <1> 	MOV	WORD [DSK_STATE],0	; INITIALIZE STATES
  3064 00004204 00                  <1>
  3065 00004205 8025[38590100]33    <1> 	AND	byte [LASTRATE],~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  3066 0000420C 800D[38590100]C0    <1> 	OR	byte [LASTRATE],SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  3067 00004213 C605[2D590100]00    <1> 	MOV	byte [SEEK_STATUS],0	; INDICATE RECALIBRATE NEEDED
  3068 0000421A C605[2F590100]00    <1> 	MOV	byte [MOTOR_COUNT],0	; INITIALIZE MOTOR COUNT
  3069 00004221 C605[2E590100]00    <1> 	MOV	byte [MOTOR_STATUS],0	; INITIALIZE DRIVES TO OFF STATE
  3070 00004228 C605[30590100]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; NO ERRORS
  3071                              <1> 	;
  3072                              <1> 	; 28/02/2015
  3073                              <1> 	;mov	word [cfd], 100h 
  3074 0000422F E848F2FFFF          <1> 	call	DSK_RESET
  3075 00004234 5A                  <1> 	pop	edx
  3076 00004235 F8                  <1> 	clc	; 29/05/2016
  3077 00004236 C3                  <1> 	retn
  3078                              <1> 
  3079                              <1> ;SUP0:
  3080                              <1> ;	CALL	DRIVE_DET		; DETERMINE DRIVE
  3081                              <1> ;	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  3082                              <1> ;	; 02/01/2015
  3083                              <1> ;	;INC	DI			; POINT TO NEXT DRIVE
  3084                              <1> ;	;CMP	DI,MAX_DRV		; SEE IF DONE
  3085                              <1> ;	;JNZ	short SUP0		; REPEAT FOR EACH ORIVE
  3086                              <1> ;       cmp     byte [fd1_type], 0	
  3087                              <1> ;	jna	short sup1
  3088                              <1> ;	or	di, di
  3089                              <1> ;	jnz	short sup1
  3090                              <1> ;	inc	di
  3091                              <1> ;       jmp     short SUP0
  3092                              <1> ;sup1:
  3093                              <1> ;	MOV	byte [SEEK_STATUS],0	; FORCE RECALIBRATE
  3094                              <1> ;	;AND	byte [RTC_WAIT_FLAG],0FEH ; ALLOW FOR RTC WAIT
  3095                              <1> ;	CALL	SETUP_END		; VARIOUS CLEANUPS
  3096                              <1> ;	;;POP	DS			; RESTORE CALLERS REGISTERS
  3097                              <1> ;	;POP	DI
  3098                              <1> ;	POP	eDX
  3099                              <1> ;	;POP	CX
  3100                              <1> ;	;POP	BX
  3101                              <1> ;	;POP	AX
  3102                              <1> ;	RETn
  3103                              <1> 
  3104                              <1> ;//////////////////////////////////////////////////////
  3105                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3106                              <1> ;
  3107                              <1> 
  3108                              <1> int13h: ; 21/02/2015
  3109 00004237 F8                  <1> 	clc ; 20/07/2020
  3110 00004238 9C                  <1> 	pushfd
  3111 00004239 0E                  <1> 	push 	cs
  3112 0000423A E843010000          <1> 	call 	DISK_IO
  3113 0000423F C3                  <1> 	retn
  3114                              <1> 
  3115                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  3116                              <1> ;/////////////////////////////////////////////////////////////////////
  3117                              <1> 
  3118                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  3119                              <1> ; 18/02/2016
  3120                              <1> ; 17/02/2016
  3121                              <1> ; 23/02/2015
  3122                              <1> ; 21/02/2015 (unix386.s)
  3123                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  3124                              <1> ;
  3125                              <1> ; Original Source Code:
  3126                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  3127                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  3128                              <1> ;
  3129                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  3130                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  3131                              <1> ;
  3132                              <1> 
  3133                              <1> 
  3134                              <1> ;The wait for controller to be not busy is 10 seconds.
  3135                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  3136                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ	1615h		
  3137                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ	  05h
  3138                              <1> WAIT_HDU_CTRL_BUSY_LH	equ	51615h	 ;21/02/2015		
  3139                              <1> 
  3140                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  3141                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  3142                              <1> ;;WAIT_HDU_INT_LO	equ	1615h
  3143                              <1> ;;WAIT_HDU_INT_HI	equ	  05h
  3144                              <1> WAIT_HDU_INT_LH		equ	51615h	; 21/02/2015
  3145                              <1> 
  3146                              <1> ;The wait for Data request on read and write longs is
  3147                              <1> ;2000 us. (?)
  3148                              <1> ;;WAIT_HDU_DRQ_LO	equ	1000	; 03E8h
  3149                              <1> ;;WAIT_HDU_DRQ_HI	equ	0
  3150                              <1> WAIT_HDU_DRQ_LH		equ	1000	; 21/02/2015
  3151                              <1> 
  3152                              <1> ; Port 61h (PORT_B)
  3153                              <1> SYS1		equ	61h	; PORT_B  (diskette.inc)
  3154                              <1> 
  3155                              <1> ; 23/12/2014
  3156                              <1> %define CMD_BLOCK       eBP-8  ; 21/02/2015
  3157                              <1> 
  3158                              <1> 
  3159                              <1> ;--- INT 13H -------------------------------------------------------------------
  3160                              <1> ;									       :
  3161                              <1> ; FIXED DISK I/O INTERFACE						       :
  3162                              <1> ;									       :
  3163                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  3164                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  3165                              <1> ;									       :
  3166                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  3167                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  3168                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  3169                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  3170                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  3171                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  3172                              <1> ;									       :
  3173                              <1> ;------------------------------------------------------------------------------:
  3174                              <1> ;									       :
  3175                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  3176                              <1> ;									       :
  3177                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  3178                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  3179                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  3180                              <1> ;			  DL > 80H - DISK				       :
  3181                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  3182                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  3183                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  3184                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  3185                              <1> ;	(AH)= 06H  UNUSED						       :
  3186                              <1> ;	(AH)= 07H  UNUSED						       :
  3187                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  3188                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  3189                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  3190                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  3191                              <1> ;	(AH)= 0AH  READ LONG						       :
  3192                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  3193                              <1> ;	(AH)= 0CH  SEEK 						       :
  3194                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  3195                              <1> ;	(AH)= 0EH  UNUSED						       :
  3196                              <1> ;	(AH)= 0FH  UNUSED						       :
  3197                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  3198                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  3199                              <1> ;	(AH)= 12H  UNUSED						       :
  3200                              <1> ;	(AH)= 13H  UNUSED						       :
  3201                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  3202                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  3203                              <1> ;									       :
  3204                              <1> ;-------------------------------------------------------------------------------
  3205                              <1> ;									       :
  3206                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  3207                              <1> ;									       :
  3208                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  3209                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  3210                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  3211                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  3212                              <1> ;									       :
  3213                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  3214                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  3215                              <1> ;				 (10 BITS TOTAL)			       :
  3216                              <1> ;									       :
  3217                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  3218                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  3219                              <1> ;									       :
  3220                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  3221                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  3222                              <1> ;									       :
  3223                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  3224                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  3225                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  3226                              <1> ;			       80H FOR A BAD SECTOR			       :
  3227                              <1> ;			   N = SECTOR NUMBER				       :
  3228                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  3229                              <1> ;			   THE TABLE SHOULD BE: 			       :
  3230                              <1> ;									       :
  3231                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  3232                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  3233                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  3234                              <1> ;									       :
  3235                              <1> ;-------------------------------------------------------------------------------
  3236                              <1> 
  3237                              <1> ;-------------------------------------------------------------------------------
  3238                              <1> ; OUTPUT								       :
  3239                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  3240                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  3241                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  3242                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  3243                              <1> ;									       :
  3244                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  3245                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  3246                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  3247                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  3248                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  3249                              <1> ;		REWRITTEN.						       :
  3250                              <1> ;									       :
  3251                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  3252                              <1> ;	   INPUT:							       :
  3253                              <1> ;	     (DL) = DRIVE NUMBER					       :	
  3254                              <1> ;	     ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)						       :	 	
  3255                              <1> ;	     EBX = Buffer address for fixed disk parameters table (32 bytes)   :
  3256                              <1> ;	   OUTPUT:							       :
  3257                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  3258                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  3259                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  3260                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  3261                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  3262                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  3263                              <1> ;									       :
  3264                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  3265                              <1> ;									       :
  3266                              <1> ;	AH = 0 - NOT PRESENT						       :
  3267                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  3268                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  3269                              <1> ;	     3 - FIXED DISK						       :
  3270                              <1> ;									       :
  3271                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  3272                              <1> ;									       :
  3273                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  3274                              <1> ;	INFORMATION.							       :
  3275                              <1> ;									       :
  3276                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  3277                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  3278                              <1> ;									       :
  3279                              <1> ;-------------------------------------------------------------------------------
  3280                              <1> 
  3281                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  3282                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  3283                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  3284                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  3285                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  3286                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  3287                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  3288                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  3289                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  3290                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  3291                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  3292                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  3293                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  3294                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  3295                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  3296                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  3297                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  3298                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  3299                              <1> 
  3300                              <1> ;--------------------------------------------------------
  3301                              <1> ;							:
  3302                              <1> ; FIXED DISK PARAMETER TABLE				:
  3303                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  3304                              <1> ;							:
  3305                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  3306                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  3307                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  3308                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  3309                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  3310                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  3311                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  3312                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  3313                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  3314                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  3315                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  3316                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  3317                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  3318                              <1> ;							:
  3319                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  3320                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  3321                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  3322                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  3323                              <1> ;							:
  3324                              <1> ;--------------------------------------------------------
  3325                              <1> 
  3326                              <1> ;--------------------------------------------------------
  3327                              <1> ;							:
  3328                              <1> ; HARDWARE SPECIFIC VALUES				:
  3329                              <1> ;							:
  3330                              <1> ;  -  CONTROLLER I/O PORT				:
  3331                              <1> ;							:
  3332                              <1> ;     > WHEN READ FROM: 				:
  3333                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  3334                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  3335                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  3336                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  3337                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  3338                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  3339                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  3340                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  3341                              <1> ;							:
  3342                              <1> ;     > WHEN WRITTEN TO:				:
  3343                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  3344                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  3345                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  3346                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  3347                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  3348                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  3349                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  3350                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  3351                              <1> ;							:
  3352                              <1> ;--------------------------------------------------------
  3353                              <1> 
  3354                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  3355                              <1> ;HF1_PORT	equ	0170h	
  3356                              <1> ;HF_REG_PORT	EQU	03F6H
  3357                              <1> ;HF1_REG_PORT	equ	0376h
  3358                              <1> 
  3359                              <1> HDC1_BASEPORT	equ	1F0h
  3360                              <1> HDC2_BASEPORT	equ	170h		
  3361                              <1> 
  3362                              <1> align 2
  3363                              <1> 
  3364                              <1> ;-----		STATUS REGISTER
  3365                              <1> 
  3366                              <1> ST_ERROR	EQU	00000001B	;
  3367                              <1> ST_INDEX	EQU	00000010B	;
  3368                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  3369                              <1> ST_DRQ		EQU	00001000B	;
  3370                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  3371                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  3372                              <1> ST_READY	EQU	01000000B	;
  3373                              <1> ST_BUSY 	EQU	10000000B	;
  3374                              <1> 
  3375                              <1> ;-----		ERROR REGISTER
  3376                              <1> 
  3377                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  3378                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  3379                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  3380                              <1> ;		EQU	00001000B	; NOT USED
  3381                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  3382                              <1> ;		EQU	00100000B	; NOT USED
  3383                              <1> ERR_DATA_ECC	EQU	01000000B
  3384                              <1> ERR_BAD_BLOCK	EQU	10000000B
  3385                              <1> 
  3386                              <1> 
  3387                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  3388                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  3389                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  3390                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  3391                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  3392                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  3393                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  3394                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  3395                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  3396                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  3397                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  3398                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  3399                              <1> 
  3400                              <1> ;MAX_FILE	EQU	2
  3401                              <1> ;S_MAX_FILE	EQU	2
  3402                              <1> MAX_FILE	equ	4		; 22/12/2014
  3403                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  3404                              <1> 
  3405                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  3406                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  3407                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  3408                              <1> 
  3409                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  3410                              <1> 
  3411                              <1> ;-----		COMMAND BLOCK REFERENCE
  3412                              <1> 
  3413                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  3414                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  3415                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  3416                              <1> ; 19/12/2014
  3417                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  3418                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  3419                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3420                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3421                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  3422                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  3423                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  3424                              <1> 
  3425                              <1> align 2
  3426                              <1> 
  3427                              <1> ;----------------------------------------------------------------
  3428                              <1> ; FIXED DISK I/O SETUP						:
  3429                              <1> ;								:
  3430                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  3431                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  3432                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  3433                              <1> ;								:
  3434                              <1> ;----------------------------------------------------------------
  3435                              <1> 
  3436                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  3437                              <1> 
  3438                              <1> DISK_SETUP:
  3439                              <1> 	;CLI
  3440                              <1> 	;;MOV	AX,ABS0 			; GET ABSOLUTE SEGMENT
  3441                              <1> 	;xor	ax,ax
  3442                              <1> 	;MOV	DS,AX				; SET SEGMENT REGISTER
  3443                              <1> 	;MOV	AX, [ORG_VECTOR] 		; GET DISKETTE VECTOR
  3444                              <1> 	;MOV	[DISK_VECTOR],AX		;  INTO INT 40H
  3445                              <1> 	;MOV	AX, [ORG_VECTOR+2]
  3446                              <1> 	;MOV	[DISK_VECTOR+2],AX
  3447                              <1> 	;MOV	word [ORG_VECTOR],DISK_IO	; FIXED DISK HANDLER
  3448                              <1> 	;MOV	[ORG_VECTOR+2],CS
  3449                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  3450                              <1> 	;;MOV	word [HDISK_INT],HD_INT		; FIXED DISK INTERRUPT
  3451                              <1> 	;mov	word [HDISK_INT1],HD_INT	;
  3452                              <1> 	;;MOV	[HDISK_INT+2],CS
  3453                              <1> 	;mov	[HDISK_INT1+2],CS
  3454                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  3455                              <1> 	;mov	word [HDISK_INT2],HD1_INT	;
  3456                              <1> 	;mov	[HDISK_INT2+2],CS
  3457                              <1> 	;
  3458                              <1> 	;;MOV	word [HF_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80
  3459                              <1> 	;;MOV	word [HF_TBL_VEC+2],DPT_SEGM
  3460                              <1> 	;;MOV	word [HF1_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81
  3461                              <1> 	;;MOV	word [HF1_TBL_VEC+2],DPT_SEGM
  3462                              <1> 	;push	cs
  3463                              <1> 	;pop	ds
  3464                              <1> 	;mov	word [HDPM_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80h
  3465                              <1> 	;mov	word [HDPM_TBL_VEC+2],DPT_SEGM
  3466 00004240 C705[48590100]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  3466 00004248 0900                <1>
  3467                              <1> 	;mov	word [HDPS_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81h
  3468                              <1> 	;mov	word [HDPS_TBL_VEC+2],DPT_SEGM
  3469 0000424A C705[4C590100]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  3469 00004252 0900                <1>
  3470                              <1> 	;mov	word [HDSM_TBL_VEC],HD2_DPT	; PARM TABLE DRIVE 82h
  3471                              <1> 	;mov	word [HDSM_TBL_VEC+2],DPT_SEGM
  3472 00004254 C705[50590100]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  3472 0000425C 0900                <1>
  3473                              <1> 	;mov	word [HDSS_TBL_VEC],HD3_DPT	; PARM TABLE DRIVE 83h
  3474                              <1> 	;mov	word [HDSS_TBL_VEC+2],DPT_SEGM
  3475 0000425E C705[54590100]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  3475 00004266 0900                <1>
  3476                              <1> 	;
  3477                              <1> 	;;IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  3478                              <1> 	;;;AND	AL,0BFH
  3479                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  3480                              <1> 	;;;JMP	$+2
  3481                              <1> 	;;IODELAY
  3482                              <1> 	;;OUT	INTB01,AL
  3483                              <1> 	;;IODELAY
  3484                              <1> 	;;IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  3485                              <1> 	;;AND	AL,0FBH 		;  SECOND CHIP
  3486                              <1> 	;;;JMP	$+2
  3487                              <1> 	;;IODELAY
  3488                              <1> 	;;OUT	INTA01,AL
  3489                              <1> 	;
  3490                              <1> 	;STI
  3491                              <1> 	;;PUSH	DS			; MOVE ABS0 POINTER TO
  3492                              <1> 	;;POP	ES			; EXTRA SEGMENT POINTER
  3493                              <1> 	;;;CALL	DDS			; ESTABLISH DATA SEGMENT
  3494                              <1> 	;;MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  3495                              <1> 	;;MOV	byte [HF_NUM],0		; ZERO NUMBER OF FIXED DISKS
  3496                              <1> 	;;MOV	byte [CONTROL_BYTE],0
  3497                              <1> 	;;MOV	byte [PORT_OFF],0	; ZERO CARD OFFSET
  3498                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  3499                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  3500                              <1> 	;mov	si, hd0_type
  3501 00004268 BE[285D0000]        <1> 	mov	esi, hd0_type
  3502                              <1> 	;mov	cx, 4
  3503 0000426D B904000000          <1> 	mov	ecx, 4
  3504                              <1> hde_l:
  3505 00004272 AC                  <1> 	lodsb
  3506 00004273 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  3507 00004275 7206                <1> 	jb	short _L4
  3508 00004277 FE05[44590100]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  3509                              <1> _L4: ; 26/02/2015
  3510 0000427D E2F3                <1> 	loop	hde_l	
  3511                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  3512                              <1> ;L4:
  3513                              <1> 	; 
  3514                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  3515                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  3516                              <1> 	;;mov 	cl, 3
  3517                              <1> 	;;
  3518                              <1> 	;;MOV	DL,80H			; CHECK THE CONTROLLER
  3519                              <1> ;;hdc_dl:
  3520                              <1> 	;;MOV	AH,14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  3521                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  3522                              <1> 	;;;JC	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  3523                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  3524                              <1> 	;;jnc	short hdc_reset0
  3525                              <1> 	;;loop	hdc_dl
  3526                              <1> 	;;; 27/12/2014
  3527                              <1> 	;;stc
  3528                              <1> 	;;retn
  3529                              <1> 	;
  3530                              <1> ;;hdc_reset0:
  3531                              <1> 	; 18/01/2015
  3532 0000427F 8A0D[44590100]      <1> 	mov	cl, [HF_NUM]
  3533 00004285 20C9                <1> 	and	cl, cl
  3534 00004287 740E                <1> 	jz	short POD_DONE
  3535                              <1> 	;
  3536 00004289 B27F                <1> 	mov	dl, 7Fh
  3537                              <1> hdc_reset1:
  3538 0000428B FEC2                <1> 	inc	dl
  3539                              <1> 	;; 31/12/2015
  3540                              <1> 	;;push	dx
  3541                              <1> 	;;push	cx
  3542                              <1> 	;;push	ds
  3543                              <1> 	;;sub	ax, ax
  3544                              <1> 	;;mov	ds, ax
  3545                              <1> 	;;MOV	AX, [TIMER_LOW]		; GET START TIMER COUNTS
  3546                              <1> 	;;pop	ds
  3547                              <1> 	;;MOV	BX,AX
  3548                              <1> 	;;ADD	AX,6*182		; 60 SECONDS* 18.2
  3549                              <1> 	;;MOV	CX,AX
  3550                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  3551                              <1> 	;;
  3552                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  3553                              <1> 	;;CALL	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  3554                              <1> 	;;pop	cx
  3555                              <1> 	;;pop	dx
  3556                              <1> 	;;
  3557                              <1> 	; 18/01/2015
  3558 0000428D B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  3559                              <1> 	;int	13h
  3560 0000428F E8A3FFFFFF          <1> 	call	int13h
  3561 00004294 E2F5                <1> 	loop	hdc_reset1
  3562 00004296 F8                  <1> 	clc 	; 29/05/2016
  3563                              <1> POD_DONE:
  3564 00004297 C3                  <1> 	RETn
  3565                              <1> 
  3566                              <1> ;;-----	POD_ERROR
  3567                              <1> 
  3568                              <1> ;;CTL_ERRX:
  3569                              <1> ;	;MOV	SI,OFFSET F1782 	; CONTROLLER ERROR
  3570                              <1> ;	;CALL	SET_FAIL		; DO NOT IPL FROM DISK
  3571                              <1> ;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  3572                              <1> ;	;JMP	short POD_DONE
  3573                              <1> 
  3574                              <1> ;;HD_RESET_1:
  3575                              <1> ;;	;PUSH	BX			; SAVE TIMER LIMITS
  3576                              <1> ;;	;PUSH	CX
  3577                              <1> ;;RES_1: MOV	AH,09H			; SET DRIVE PARAMETERS
  3578                              <1> ;;	INT	13H
  3579                              <1> ;;	JC	short RES_2
  3580                              <1> ;;	MOV	AH,11H			; RECALIBRATE DRIVE
  3581                              <1> ;;	INT	13H
  3582                              <1> ;;	JNC	short RES_CK		; DRIVE OK
  3583                              <1> ;;RES_2: ;CALL	POD_TCHK		; CHECK TIME OUT
  3584                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  3585                              <1> ;;					; (30 seconds)		
  3586                              <1> ;;	;cmc
  3587                              <1> ;;	;JNC	short RES_1
  3588                              <1> ;;	jb	short RES_1
  3589                              <1> ;;;RES_FL: ;MOV	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  3590                              <1> ;;	;TEST	DL,1
  3591                              <1> ;;	;JNZ	RES_E1
  3592                              <1> ;;	;MOV	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  3593                              <1> ;;	;CALL	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  3594                              <1> ;;	;JMP	SHORT RES_E1
  3595                              <1> ;;RES_ER: ; 22/12/2014
  3596                              <1> ;;RES_OK:
  3597                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  3598                              <1> ;;	;POP	BX
  3599                              <1> ;;	RETn
  3600                              <1> ;;
  3601                              <1> ;;RES_RS: MOV	AH,00H			; RESET THE DRIVE
  3602                              <1> ;;	INT	13H
  3603                              <1> ;;RES_CK: MOV	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  3604                              <1> ;;	MOV	BL,DL			; SAVE DRIVE CODE
  3605                              <1> ;;	INT	13H
  3606                              <1> ;;	JC	short RES_ER
  3607                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  3608                              <1> ;;	MOV	DL,BL			; RESTORE DRIVE CODE
  3609                              <1> ;;RES_3: MOV	AX,0401H		; VERIFY THE LAST SECTOR
  3610                              <1> ;;	INT	13H
  3611                              <1> ;;	JNC	short RES_OK		; VERIFY OK
  3612                              <1> ;;	CMP	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  3613                              <1> ;;	JE	short RES_OK
  3614                              <1> ;;	CMP	AH,DATA_CORRECTED
  3615                              <1> ;;	JE	short RES_OK
  3616                              <1> ;;	CMP	AH,BAD_ECC
  3617                              <1> ;;	JE	short RES_OK
  3618                              <1> ;;	;CALL	POD_TCHK		; CHECK FOR TIME OUT
  3619                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  3620                              <1> ;;					; (60 seconds)		
  3621                              <1> ;;	cmc
  3622                              <1> ;;	JC	short RES_ER		; FAILED
  3623                              <1> ;;	MOV	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  3624                              <1> ;;	MOV	AL,CL			; SEPARATE OUT SECTOR NUMBER
  3625                              <1> ;;	AND	AL,3FH
  3626                              <1> ;;	DEC	AL			; TRY PREVIOUS ONE
  3627                              <1> ;;	JZ	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  3628                              <1> ;;	AND	CL,0C0H 		; KEEP CYLINDER BITS
  3629                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  3630                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  3631                              <1> ;;	JMP	short RES_3		; TRY AGAIN
  3632                              <1> ;;;RES_ER: MOV	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  3633                              <1> ;;	;TEST	DL,1
  3634                              <1> ;;	;JNZ	short RES_E1
  3635                              <1> ;;	;MOV	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  3636                              <1> ;;;RES_E1:
  3637                              <1> ;;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  3638                              <1> ;;;RES_OK:
  3639                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  3640                              <1> ;;	;POP	BX
  3641                              <1> ;;	;RETn
  3642                              <1> ;
  3643                              <1> ;;SET_FAIL:
  3644                              <1> ;	;MOV	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  3645                              <1> ;	;CALL	CMOS_READ
  3646                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  3647                              <1> ;	;XCHG	AH,AL			; SAVE IT
  3648                              <1> ;	;CALL	CMOS_WRITE		; PUT IT OUT
  3649                              <1> ;	;RETn
  3650                              <1> ;
  3651                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  3652                              <1> ;	;POP	AX			; SAVE RETURN
  3653                              <1> ;	;POP	CX			; GET TIME OUT LIMITS
  3654                              <1> ;	;POP	BX
  3655                              <1> ;	;PUSH	BX			; AND SAVE THEM AGAIN
  3656                              <1> ;	;PUSH	CX
  3657                              <1> ;	;PUSH	AX
  3658                              <1> ;	;push	ds
  3659                              <1> ;	;xor	ax, ax
  3660                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  3661                              <1> ;	;MOV	AX, [TIMER_LOW]		; AX = CURRENT TIME
  3662                              <1> ;	;				; BX = START TIME
  3663                              <1> ;	;				; CX = END TIME
  3664                              <1> ;	;pop	ds
  3665                              <1> ;	;CMP	BX,CX
  3666                              <1> ;	;JB	short TCHK1		; START < END
  3667                              <1> ;	;CMP	BX,AX
  3668                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  3669                              <1> ;	;JMP	SHORT TCHK2		; END, CURRENT < START
  3670                              <1> ;;TCHK1: CMP	AX,BX
  3671                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  3672                              <1> ;;TCHK2: CMP	AX,CX
  3673                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  3674                              <1> ;;					; OR CURRENT < END < START
  3675                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  3676                              <1> ;;	RETn
  3677                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  3678                              <1> ;;	RETn
  3679                              <1> ;;
  3680                              <1> ;;int_13h:
  3681                              <1> 
  3682                              <1> ;----------------------------------------
  3683                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  3684                              <1> ;----------------------------------------
  3685                              <1> 
  3686                              <1> ; 15/01/2017
  3687                              <1> ; 14/01/2017
  3688                              <1> ; 07/01/2017
  3689                              <1> ; 02/01/2017
  3690                              <1> ; 01/06/2016
  3691                              <1> ; 16/05/2016, 27/05/2016, 28/05/2016, 29/05/2016
  3692                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  3693                              <1> int33h:  ; DISK I/O
  3694                              <1> 	; 29/05/2016
  3695 00004298 80642408FE          <1> 	and	byte [esp+8], 11111110b  ; clear carry bit of eflags register
  3696                              <1> 	; 16/05/2016
  3697 0000429D 1E                  <1> 	push	ds
  3698 0000429E 53                  <1> 	push	ebx ; user's buffer address (virtual)
  3699 0000429F 66BB1000            <1> 	mov	bx, KDATA ; System (Kernel's) data segment
  3700 000042A3 8EDB                <1> 	mov	ds, bx
  3701                              <1> 
  3702                              <1> 	;;15/01/2017
  3703                              <1> 	; 14/01/2017
  3704                              <1> 	; 02/01/2017
  3705                              <1> 	;;mov	byte [intflg], 33h	; disk io interrupt 
  3706                              <1> 	;pop	ebx
  3707                              <1> 	;mov	[user_buffer], ebx		
  3708                              <1> 
  3709 000042A5 8F05[2C650100]      <1> 	pop	dword [user_buffer] ; 01/06/2016
  3710                              <1> 
  3711 000042AB C605[6E5E0100]00    <1> 	mov	byte [scount], 0 ; sector count for transfer
  3712 000042B2 80FC03              <1> 	cmp	ah, 03h ; chs write
  3713 000042B5 7744                <1> 	ja	short int33h_2
  3714 000042B7 7407                <1> 	je	short int33h_0
  3715 000042B9 80FC02              <1> 	cmp	ah, 02h ; chs read
  3716 000042BC 726A                <1> 	jb	short int33h_5
  3717 000042BE EB63                <1> 	jmp	short int33h_4
  3718                              <1> int33h_0:
  3719                              <1> 	; transfer user's buffer content to sector buffer
  3720 000042C0 51                  <1> 	push	ecx
  3721 000042C1 0FB6C8              <1> 	movzx	ecx, al
  3722                              <1> int33h_1:
  3723 000042C4 56                  <1> 	push	esi
  3724 000042C5 8B35[2C650100]      <1> 	mov	esi, [user_buffer]
  3725                              <1> 	; esi = user's buffer address (virtual, ebx)
  3726 000042CB 57                  <1> 	push	edi
  3727 000042CC 06                  <1> 	push	es
  3728 000042CD 50                  <1> 	push	eax
  3729 000042CE 66B81000            <1> 	mov	ax, KDATA
  3730 000042D2 8EC0                <1> 	mov	es, ax
  3731 000042D4 BF00000700          <1> 	mov	edi, Cluster_Buffer
  3732 000042D9 C1E109              <1> 	shl	ecx, 9 ; * 512
  3733 000042DC E83DA50000          <1> 	call	transfer_from_user_buffer
  3734 000042E1 58                  <1> 	pop	eax
  3735 000042E2 07                  <1> 	pop	es
  3736 000042E3 5F                  <1> 	pop	edi
  3737 000042E4 5E                  <1> 	pop	esi
  3738 000042E5 59                  <1> 	pop	ecx
  3739 000042E6 7340                <1> 	jnc	short int33h_5
  3740 000042E8 8B1D[2C650100]      <1> 	mov	ebx, [user_buffer] ; 01/06/2016
  3741 000042EE 1F                  <1> 	pop	ds
  3742                              <1> 
  3743                              <1> 	;;15/01/2017
  3744                              <1> 	; 02/01/2017
  3745                              <1> 	;cli
  3746                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
  3747                              <1> 	;
  3748                              <1> 	; (*) 29/05/2016
  3749                              <1> 	; (*) retf 4 ; skip eflags on stack
  3750                              <1> 
  3751                              <1> 	; 29/05/2016 -set carry flag on stack-
  3752                              <1> 	; [esp] = EIP
  3753                              <1> 	; [esp+4] = CS
  3754                              <1> 	; [esp+8] = E-FLAGS
  3755 000042EF 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
  3756                              <1> 	; [esp+12] = ESP (user)
  3757                              <1> 	; [esp+16] = SS (User)
  3758 000042F4 B8FF000000          <1> 	mov	eax, 0FFh ; Unknown error !?
  3759                              <1> 	;iretd
  3760 000042F9 EB79                <1> 	jmp	short int33h_7  ; 07/01/2017	
  3761                              <1> 
  3762                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
  3763                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
  3764                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
  3765                              <1> 	; // RETF instruction:
  3766                              <1> 	;
  3767                              <1> 	; IF OperandMode=32 THEN
  3768                              <1>  	;    Load CS:EIP from stack;
  3769                              <1>  	;    Set CS RPL to CPL;
  3770                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
  3771                              <1>  	;    Load SS:eSP from stack;
  3772                              <1>  	; ELSE (* OperandMode=16 *)
  3773                              <1>  	;    Load CS:IP from stack;
  3774                              <1>  	;    Set CS RPL to CPL;
  3775                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
  3776                              <1> 	;    Load SS:eSP from stack;
  3777                              <1>  	; FI;
  3778                              <1> 	;
  3779                              <1> 	; //
  3780                              <1> 
  3781                              <1> int33h_2:
  3782 000042FB 80FC05              <1> 	cmp	ah, 05h ; format track
  3783 000042FE 770A                <1> 	ja	short int33h_3
  3784 00004300 7226                <1> 	jb	short int33h_5
  3785 00004302 51                  <1> 	push	ecx
  3786 00004303 B901000000          <1> 	mov	ecx, 1
  3787 00004308 EBBA                <1> 	jmp	short int33h_1
  3788                              <1> int33h_3:
  3789 0000430A 80FC1C              <1> 	cmp	ah, 1Ch ; LBA write
  3790 0000430D 7719                <1> 	ja	short int33h_5
  3791 0000430F 74AF                <1> 	je	short int33h_0
  3792 00004311 80FC1B              <1> 	cmp	ah, 1Bh ; LBA read
  3793 00004314 740D                <1> 	je	short int33h_4
  3794 00004316 80FC08              <1> 	cmp	ah, 08h ; get disk parameters
  3795 00004319 750D                <1> 	jne	short int33h_5
  3796                              <1> 	; 01/06/2016
  3797 0000431B 8B1D[2C650100]      <1> 	mov	ebx, [user_buffer] ; user's buffer address
  3798 00004321 EB0A                <1> 	jmp	short int33h_6
  3799                              <1> int33h_4:
  3800 00004323 A2[6E5E0100]        <1> 	mov	byte [scount], al ; <= 128 sectors
  3801                              <1> int33h_5:
  3802 00004328 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; max. 65536 bytes
  3803                              <1> 				    ; buf. addr: 70000h	
  3804                              <1> 	;mov	byte [ClusterBuffer_Valid], 0
  3805                              <1> int33h_6:
  3806 0000432D 1F                  <1> 	pop	ds
  3807 0000432E 9C                  <1> 	pushfd
  3808 0000432F 0E                  <1> 	push 	cs
  3809 00004330 E84D000000          <1> 	call 	DISK_IO
  3810 00004335 2E8B1D[2C650100]    <1> 	mov	ebx, [CS:user_buffer] ; 01/06/2016
  3811 0000433C 723D                <1> 	jc	short int33h_9
  3812                              <1> 	;
  3813 0000433E 2E803D[6E5E0100]00  <1> 	cmp	byte [CS:scount], 0
  3814 00004346 762C                <1> 	jna	short int33h_7
  3815                              <1> 	; transfer sector buffer content to user's buffer
  3816 00004348 06                  <1> 	push	es
  3817 00004349 1E                  <1> 	push	ds
  3818 0000434A 50                  <1> 	push	eax
  3819 0000434B 66B81000            <1> 	mov	ax, KDATA
  3820 0000434F 8ED8                <1> 	mov	ds, ax
  3821 00004351 8EC0                <1> 	mov	es, ax
  3822 00004353 51                  <1> 	push	ecx
  3823 00004354 56                  <1> 	push	esi
  3824 00004355 57                  <1> 	push	edi
  3825 00004356 0FB60D[6E5E0100]    <1> 	movzx	ecx, byte [scount]
  3826 0000435D C1E109              <1> 	shl	ecx, 9 ; * 512 bytes
  3827 00004360 89DF                <1> 	mov	edi, ebx ; user's buffer address
  3828 00004362 BE00000700          <1> 	mov	esi, Cluster_Buffer
  3829 00004367 E868A40000          <1> 	call	transfer_to_user_buffer
  3830 0000436C 5F                  <1> 	pop	edi
  3831 0000436D 5E                  <1> 	pop	esi
  3832 0000436E 59                  <1> 	pop	ecx
  3833 0000436F 58                  <1> 	pop	eax
  3834 00004370 1F                  <1> 	pop	ds
  3835 00004371 07                  <1> 	pop	es
  3836 00004372 7202                <1> 	jc	short int33h_8
  3837                              <1> int33h_7:
  3838 00004374 FA                  <1> 	cli
  3839                              <1> 	;;15/01/2017
  3840                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
  3841                              <1> 	; cf = 0  ; use eflags which is in stack
  3842 00004375 CF                  <1> 	iretd	
  3843                              <1> int33h_8:
  3844 00004376 B8FF000000          <1> 	mov	eax, 0FFh ; Unknown error !?
  3845                              <1> int33h_9:
  3846                              <1> 	; cf = 1
  3847                              <1> 
  3848                              <1> 	; (*) 29/05/2016	
  3849                              <1> 	; (*) retf 4 ; skip eflags on stack
  3850                              <1> 	; Note: This 'retf 4' was wrong, -it was causing
  3851                              <1> 	;       to stack errors in ring 3-
  3852                              <1> 	;	POP sequence of 'retf 4' is as
  3853                              <1> 	;       "eip, cs, eflags, esp, ss, +4 bytes" 
  3854                              <1>         ;       it is not as "eip, cs, +4 bytes, esp, ss" ! 
  3855                              <1> 
  3856                              <1> 	; 29/05/2016 -set carry flag on stack-
  3857 0000437B 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
  3858                              <1> 	;iretd
  3859 00004380 EBF2                <1> 	jmp	short int33h_7 ; 07/01/2017
  3860                              <1> 
  3861                              <1> ; 09/12/2017
  3862                              <1> ; 29/05/2016
  3863                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  3864                              <1> 
  3865                              <1> DISK_IO:
  3866 00004382 80FA80              <1> 	CMP	DL,80H			; TEST FOR FIXED DISK DRIVE
  3867                              <1> 	;JAE	short A1		; YES, HANDLE HERE
  3868                              <1> 	;;;INT	40H			; DISKETTE HANDLER
  3869                              <1> 	;;call	int40h
  3870 00004385 0F8221F0FFFF        <1> 	jb	DISKETTE_IO_1
  3871                              <1> ;RET_2:
  3872                              <1> 	;RETf	2			; BACK TO CALLER
  3873                              <1> ;	retf	4
  3874                              <1> A1:
  3875 0000438B FB                  <1> 	STI				; ENABLE INTERRUPTS
  3876                              <1> 	;; 04/01/2015
  3877                              <1> 	;;OR	AH,AH
  3878                              <1> 	;;JNZ	short A2
  3879                              <1> 	;;INT	40H			; RESET NEC WHEN AH=0
  3880                              <1> 	;;SUB	AH,AH
  3881 0000438C 80FA83              <1> 	CMP	DL,(80H + S_MAX_FILE - 1)
  3882                              <1> 	;JA	short RET_2
  3883 0000438F 7616                <1> 	jna	short _A0
  3884                              <1> 	; 29/05/2016
  3885 00004391 1E                  <1> 	push	ds
  3886 00004392 6650                <1> 	push	ax
  3887 00004394 66B81000            <1> 	mov	ax, KDATA
  3888 00004398 8ED8                <1> 	mov	ds, ax
  3889 0000439A 6658                <1> 	pop	ax
  3890 0000439C B4AA                <1>         mov     ah, 0AAh        ; Hard disk drive not ready !
  3891                              <1> 				; (Programmer's guide to AMIBIOS, 1992)
  3892 0000439E 8825[43590100]      <1> 	mov     byte [DISK_STATUS1], ah
  3893 000043A4 1F                  <1> 	pop	ds
  3894 000043A5 EB38                <1> 	jmp	short RET_2
  3895                              <1> _A0:
  3896                              <1> 	; 18/01/2015
  3897 000043A7 08E4                <1> 	or	ah,ah
  3898 000043A9 743A                <1> 	jz	short A4
  3899 000043AB 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  3900 000043AE 7504                <1> 	jne	short A2
  3901 000043B0 28E4                <1> 	sub	ah,ah	; Reset
  3902 000043B2 EB31                <1> 	jmp	short A4
  3903                              <1> A2:
  3904 000043B4 80FC08              <1> 	CMP	AH,08H			; GET PARAMETERS IS A SPECIAL CASE
  3905                              <1> 	;JNZ	short A3
  3906                              <1>         ;JMP    GET_PARM_N
  3907 000043B7 0F8432030000        <1> 	je	GET_PARM_N
  3908 000043BD 80FC15              <1> A3:	CMP	AH,15H			; READ DASD TYPE IS ALSO
  3909                              <1> 	;JNZ	short A4
  3910                              <1>         ;JMP    READ_DASD_TYPE
  3911 000043C0 0F84DB020000        <1>         je      READ_DASD_TYPE
  3912                              <1> 	; 02/02/2015
  3913 000043C6 80FC1D              <1> 	cmp	ah, 1Dh			;(Temporary for Retro UNIX 386 v1)
  3914                              <1> 	; 12/01/2015
  3915 000043C9 F5                  <1> 	cmc
  3916 000043CA 7319                <1> 	jnc	short A4
  3917                              <1> int33h_bad_cmd:
  3918                              <1> 	; 16/05/2016
  3919                              <1> 	; 30/01/2015
  3920                              <1> 	; 29/05/2016
  3921 000043CC 1E                  <1> 	push	ds
  3922 000043CD 6650                <1> 	push	ax
  3923 000043CF 66B81000            <1> 	mov	ax, KDATA
  3924 000043D3 8ED8                <1> 	mov	ds, ax
  3925 000043D5 6658                <1> 	pop	ax
  3926 000043D7 B401                <1> 	mov	ah, BAD_CMD
  3927 000043D9 8825[43590100]      <1> 	mov     [DISK_STATUS1], ah ; BAD_CMD  ; COMMAND ERROR
  3928                              <1>         ;jmp	short RET_2
  3929                              <1> RET_2:
  3930                              <1> 	; (*) 29/05/2016
  3931                              <1> 	; (*) retf 4
  3932 000043DF 804C240801          <1> 	or	byte [esp+8], 1 ; set carry bit of eflags register
  3933 000043E4 CF                  <1> 	iretd
  3934                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  3935 000043E5 C8080000            <1> 	ENTER	8,0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  3936 000043E9 53                  <1> 	PUSH	eBX			;  IN THE STACK, THE COMMAND BLOCK IS:
  3937 000043EA 51                  <1> 	PUSH	eCX			;   @CMD_BLOCK == BYTE PTR [BP]-8
  3938 000043EB 52                  <1> 	PUSH	eDX
  3939 000043EC 1E                  <1> 	PUSH	DS
  3940 000043ED 06                  <1> 	PUSH	ES
  3941 000043EE 56                  <1> 	PUSH	eSI
  3942 000043EF 57                  <1> 	PUSH	eDI
  3943                              <1> 	;;04/01/2015
  3944                              <1> 	;;OR	AH,AH			; CHECK FOR RESET
  3945                              <1> 	;;JNZ	short A5
  3946                              <1> 	;;MOV	DL,80H			; FORCE DRIVE 80 FOR RESET
  3947                              <1> ;;A5:	
  3948                              <1> 	;push	cs
  3949                              <1> 	;pop	ds
  3950                              <1> 	; 21/02/2015
  3951 000043F0 6650                <1> 	push	ax
  3952 000043F2 66B81000            <1> 	mov	ax, KDATA
  3953 000043F6 8ED8                <1> 	mov	ds, ax
  3954 000043F8 8EC0                <1> 	mov	es, ax	
  3955 000043FA 6658                <1> 	pop	ax
  3956 000043FC E88D000000          <1> 	CALL	DISK_IO_CONT		; PERFORM THE OPERATION
  3957                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  3958 00004401 8A25[43590100]      <1> 	MOV	AH,[DISK_STATUS1]	; GET STATUS FROM OPERATION
  3959                              <1> 	;(*) CMP AH,1			; SET THE CARRY FLAG TO INDICATE
  3960                              <1> 	;(*) CMC			; SUCCESS OR FAILURE
  3961 00004407 5F                  <1> 	POP	eDI			; RESTORE REGISTERS
  3962 00004408 5E                  <1> 	POP	eSI
  3963 00004409 07                  <1>         POP     ES
  3964 0000440A 1F                  <1>         POP     DS
  3965 0000440B 5A                  <1> 	POP	eDX
  3966 0000440C 59                  <1> 	POP	eCX
  3967 0000440D 5B                  <1> 	POP	eBX
  3968 0000440E C9                  <1> 	LEAVE				; ADJUST (SP) AND RESTORE (BP)
  3969                              <1> 	;RETf	2			; THROW AWAY SAVED FLAGS
  3970                              <1> 	; (*) 29/05/2016
  3971                              <1> 	; (*) retf 4
  3972 0000440F 80FC01              <1> 	cmp	ah, 1
  3973 00004412 7205                <1> 	jc	short _A5 
  3974 00004414 804C240801          <1> 	or	byte [esp+8], 1 ; set carry bit of eflags register
  3975                              <1> _A5:
  3976 00004419 CF                  <1> 	iretd
  3977                              <1> 
  3978                              <1> ; 21/02/2015
  3979                              <1> ;       dw --> dd
  3980                              <1> D1:					; FUNCTION TRANSFER TABLE
  3981 0000441A [DD450000]          <1> 	dd	DISK_RESET		; 000H
  3982 0000441E [54460000]          <1> 	dd	RETURN_STATUS		; 001H
  3983 00004422 [61460000]          <1> 	dd	DISK_READ		; 002H
  3984 00004426 [6A460000]          <1> 	dd	DISK_WRITE		; 003H
  3985 0000442A [73460000]          <1> 	dd	DISK_VERF		; 004H
  3986 0000442E [8B460000]          <1> 	dd	FMT_TRK 		; 005H
  3987 00004432 [D3450000]          <1> 	dd	BAD_COMMAND		; 006H	FORMAT BAD SECTORS
  3988 00004436 [D3450000]          <1> 	dd	BAD_COMMAND		; 007H	FORMAT DRIVE
  3989 0000443A [D3450000]          <1> 	dd	BAD_COMMAND		; 008H	RETURN PARAMETERS
  3990 0000443E [76470000]          <1> 	dd	INIT_DRV		; 009H
  3991 00004442 [D5470000]          <1> 	dd	RD_LONG 		; 00AH
  3992 00004446 [DE470000]          <1> 	dd	WR_LONG 		; 00BH
  3993 0000444A [E7470000]          <1> 	dd	DISK_SEEK		; 00CH
  3994 0000444E [DD450000]          <1> 	dd	DISK_RESET		; 00DH
  3995 00004452 [D3450000]          <1> 	dd	BAD_COMMAND		; 00EH	READ BUFFER
  3996 00004456 [D3450000]          <1> 	dd	BAD_COMMAND		; 00FH	WRITE BUFFER
  3997 0000445A [0F480000]          <1> 	dd	TST_RDY 		; 010H
  3998 0000445E [33480000]          <1> 	dd	HDISK_RECAL		; 011H
  3999 00004462 [D3450000]          <1> 	dd	BAD_COMMAND		; 012H	MEMORY DIAGNOSTIC
  4000 00004466 [D3450000]          <1> 	dd	BAD_COMMAND		; 013H	DRIVE DIAGNOSTIC
  4001 0000446A [69480000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 014H	CONTROLLER DIAGNOSTIC
  4002                              <1> 	; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  4003 0000446E [D3450000]          <1> 	dd	BAD_COMMAND		; 015h
  4004 00004472 [D3450000]          <1> 	dd	BAD_COMMAND		; 016h
  4005 00004476 [D3450000]          <1> 	dd	BAD_COMMAND		; 017h
  4006 0000447A [D3450000]          <1> 	dd	BAD_COMMAND		; 018h
  4007 0000447E [D3450000]          <1> 	dd	BAD_COMMAND		; 019h
  4008 00004482 [D3450000]          <1> 	dd	BAD_COMMAND		; 01Ah
  4009 00004486 [61460000]          <1> 	dd	DISK_READ		; 01Bh ; LBA read
  4010 0000448A [6A460000]          <1> 	dd	DISK_WRITE		; 01Ch ; LBA write
  4011                              <1> D1L     EQU    $ - D1
  4012                              <1> 
  4013                              <1> DISK_IO_CONT:
  4014                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  4015 0000448E 80FC01              <1> 	CMP	AH,01H			; RETURN STATUS
  4016                              <1> 	;;JNZ	short SU0
  4017                              <1>         ;;JMP    RETURN_STATUS
  4018 00004491 0F84BD010000        <1> 	je	RETURN_STATUS
  4019                              <1> SU0:
  4020 00004497 C605[43590100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  4021                              <1> 	;;PUSH	BX			; SAVE DATA ADDRESS
  4022                              <1> 	;mov	si, bx ;; 14/02/2015
  4023 0000449E 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  4024 000044A0 8A1D[44590100]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  4025                              <1> 	;; 04/01/2015
  4026                              <1> 	;;PUSH	AX
  4027 000044A6 80E27F              <1> 	AND	DL,7FH			; GET DRIVE AS 0 OR 1
  4028                              <1> 					; (get drive number as 0 to 3)
  4029 000044A9 38D3                <1> 	CMP	BL,DL
  4030                              <1>         ;;JBE   BAD_COMMAND_POP         ; INVALID DRIVE
  4031 000044AB 0F8622010000        <1>         jbe     BAD_COMMAND ;; 14/02/2015
  4032                              <1>         ;
  4033                              <1> 	;;03/01/2015
  4034 000044B1 29DB                <1> 	sub	ebx, ebx
  4035 000044B3 88D3                <1> 	mov	bl, dl
  4036                              <1> 	;sub	bh, bh
  4037 000044B5 883D[58590100]      <1> 	mov	[LBAMode], bh 	; 0
  4038                              <1> 	;;test	byte [bx+hd0_type], 1	; LBA ready ?
  4039                              <1> 	;test	byte [ebx+hd0_type], 1
  4040                              <1> 	;jz	short su1		; no
  4041                              <1> 	;inc	byte [LBAMode]
  4042                              <1> ;su1:
  4043                              <1> 	; 21/02/2015 (32 bit modification)
  4044                              <1> 	;04/01/2015
  4045 000044BB 6650                <1> 	push	ax ; ***
  4046                              <1> 	;PUSH	ES ; **
  4047 000044BD 6652                <1> 	PUSH	DX ; *
  4048 000044BF 6650                <1> 	push	ax
  4049 000044C1 E889060000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS
  4050                              <1> 	; 02/02/2015
  4051                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  4052 000044C6 668B4310            <1> 	mov	ax, [ebx+16]
  4053 000044CA 66A3[185D0000]      <1> 	mov	[HF_PORT], ax
  4054                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  4055 000044D0 668B5312            <1> 	mov	dx, [ebx+18]
  4056 000044D4 668915[1A5D0000]    <1> 	mov	[HF_REG_PORT], dx
  4057                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  4058 000044DB 8A4314              <1> 	mov	al, [ebx+20]
  4059                              <1> 	; 23/02/2015
  4060 000044DE A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  4061 000044E0 7406                <1> 	jz 	short su1
  4062 000044E2 FE05[58590100]      <1> 	inc	byte [LBAMode] ; 1 
  4063                              <1> su1: 	 
  4064 000044E8 C0E804              <1> 	shr 	al, 4
  4065 000044EB 2401                <1> 	and	al, 1			
  4066 000044ED A2[1C5D0000]        <1> 	mov	[hf_m_s], al 
  4067                              <1> 	;
  4068                              <1> 	; 03/01/2015
  4069                              <1> 	;MOV	AL,byte [ES:BX+8]	; GET CONTROL BYTE MODIFIER
  4070 000044F2 8A4308              <1> 	mov	al, [ebx+8]
  4071                              <1> 	;MOV	DX,[HF_REG_PORT]	; Device Control register	
  4072 000044F5 EE                  <1> 	OUT	DX,AL			; SET EXTRA HEAD OPTION
  4073                              <1> 					; Control Byte:  (= 08h, here)
  4074                              <1> 					; bit 0 - 0
  4075                              <1> 					; bit 1 - nIEN (1 = disable irq)
  4076                              <1> 					; bit 2 - SRST (software RESET)
  4077                              <1> 					; bit 3 - use extra heads (8 to 15)
  4078                              <1> 					;         -always set to 1-	
  4079                              <1> 					; (bits 3 to 7 are reserved
  4080                              <1> 					;          for ATA devices)
  4081 000044F6 8A25[45590100]      <1> 	MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  4082 000044FC 80E4C0              <1> 	AND	AH,0C0H 		; CONTROL BYTE
  4083 000044FF 08C4                <1> 	OR	AH,AL
  4084 00004501 8825[45590100]      <1> 	MOV	[CONTROL_BYTE],AH	
  4085                              <1> 	; 04/01/2015
  4086 00004507 6658                <1> 	pop	ax
  4087 00004509 665A                <1> 	pop	dx ; * ;; 14/02/2015
  4088 0000450B 20E4                <1> 	and	ah, ah	; Reset function ?
  4089 0000450D 7507                <1> 	jnz	short su2
  4090                              <1> 	;;pop	dx ; * ;; 14/02/2015
  4091                              <1> 	;pop	es ; **
  4092 0000450F 6658                <1> 	pop	ax ; ***
  4093                              <1> 	;;pop	bx
  4094 00004511 E9C7000000          <1>         jmp     DISK_RESET
  4095                              <1> su2:
  4096 00004516 803D[58590100]00    <1> 	cmp	byte [LBAMode], 0
  4097 0000451D 7662                <1> 	jna	short su3
  4098                              <1> 	;
  4099                              <1> 	; 02/02/2015 (LBA read/write function calls)
  4100 0000451F 80FC1B              <1> 	cmp	ah, 1Bh
  4101 00004522 720B                <1> 	jb	short lbarw1
  4102 00004524 80FC1C              <1> 	cmp	ah, 1Ch
  4103 00004527 775D                <1> 	ja 	short invldfnc
  4104                              <1> 	;;pop	dx ; * ; 14/02/2015
  4105                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  4106 00004529 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  4107                              <1> 	;; 14/02/2015
  4108 0000452B 88D1                <1> 	mov	cl, dl ; 14/02/2015
  4109                              <1> 	;;mov	dx, bx
  4110                              <1> 	;mov	dx, si ; higher word of LBA address (bits 16-23)
  4111                              <1> 	;;mov	bx, di
  4112                              <1> 	;mov	si, di ; Buffer offset
  4113 0000452D EB32                <1> 	jmp	short lbarw2
  4114                              <1> lbarw1:
  4115                              <1> 	; convert CHS to LBA
  4116                              <1> 	;
  4117                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  4118                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  4119                              <1> 	;	+ Sector - 1
  4120 0000452F 6652                <1> 	push	dx ; * ;; 14/02/2015
  4121                              <1> 	;xor	dh, dh
  4122 00004531 31D2                <1> 	xor	edx, edx
  4123                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  4124 00004533 8A530E              <1> 	mov	dl, [ebx+14]
  4125                              <1> 	;xor	ah, ah
  4126 00004536 31C0                <1> 	xor	eax, eax
  4127                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  4128 00004538 8A4302              <1> 	mov	al, [ebx+2]
  4129 0000453B FEC8                <1> 	dec	al
  4130 0000453D 6640                <1> 	inc	ax		; 0 =  256
  4131 0000453F 66F7E2              <1> 	mul 	dx
  4132                              <1> 		; AX = # of Heads" * Sectors/Track
  4133 00004542 6689CA              <1> 	mov	dx, cx
  4134                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  4135 00004545 83E13F              <1> 	and	ecx, 3fh
  4136 00004548 86D6                <1> 	xchg	dl, dh
  4137 0000454A C0EE06              <1> 	shr	dh, 6
  4138                              <1> 		; DX = cylinder (0 to 1023)
  4139                              <1> 	;mul 	dx
  4140                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  4141 0000454D F7E2                <1> 	mul	edx
  4142 0000454F FEC9                <1> 	dec	cl  ; sector - 1
  4143                              <1> 	;add	ax, cx
  4144                              <1> 	;adc	dx, 0
  4145                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector -1
  4146 00004551 01C8                <1> 	add	eax, ecx
  4147 00004553 6659                <1> 	pop	cx ; * ; ch = head, cl = drive number (zero based)
  4148                              <1> 	;push	dx
  4149                              <1> 	;push	ax
  4150 00004555 50                  <1> 	push	eax
  4151                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  4152 00004556 8A430E              <1> 	mov	al, [ebx+14]
  4153 00004559 F6E5                <1> 	mul	ch
  4154                              <1> 		;  AX = Head * Sectors/Track
  4155 0000455B 0FB7C0              <1>         movzx	eax, ax ; 09/12/2017
  4156                              <1> 	;pop	dx
  4157 0000455E 5A                  <1> 	pop	edx
  4158                              <1> 	;add	ax, dx
  4159                              <1> 	;pop	dx
  4160                              <1> 	;adc	dx, 0 ; add carry bit
  4161 0000455F 01D0                <1> 	add	eax, edx
  4162                              <1> lbarw2:
  4163 00004561 29D2                <1> 	sub	edx, edx ; 21/02/2015
  4164 00004563 88CA                <1> 	mov	dl, cl ; 21/02/2015
  4165 00004565 C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  4166                              <1> 				; NOTE: Features register (1F1h, 171h)
  4167                              <1> 				; is not used for ATA device R/W functions. 
  4168                              <1> 				; It is old/obsolete 'write precompensation'
  4169                              <1> 				; register and error register
  4170                              <1> 				; for old ATA/IDE devices.
  4171                              <1> 	; 18/01/2014
  4172                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  4173 00004569 8A0D[1C5D0000]      <1> 	mov	cl, [hf_m_s]
  4174                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  4175                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  4176                              <1> 				; bit 6 = 1 = LBA mode
  4177                              <1> 				; bit 7 = 1
  4178 0000456F 80C90E              <1> 	or	cl, 0Eh ; 1110b
  4179                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  4180 00004572 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  4181 00004577 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  4182                              <1> 	;or	dh, ch
  4183 0000457A 09C8                <1> 	or	eax, ecx	
  4184                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  4185                              <1> 				  ; (Sector Number Register)
  4186                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  4187                              <1> 				  ; (Cylinder Low Register)
  4188                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  4189                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  4190                              <1> 				  ; (Cylinder High Register)
  4191                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  4192                              <1> 				  ; (Drive/Head Register)
  4193                              <1> 	
  4194                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  4195 0000457C 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  4196                              <1> 	;14/02/2015
  4197                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  4198 0000457F EB38                <1> 	jmp	short su4
  4199                              <1> su3:
  4200                              <1> 	; 02/02/2015 
  4201                              <1> 	; (Temporary functions 1Bh & 1Ch are not valid for CHS mode) 
  4202 00004581 80FC14              <1> 	cmp 	ah, 14h
  4203 00004584 7604                <1> 	jna 	short chsfnc
  4204                              <1> invldfnc:
  4205                              <1>         ; 14/02/2015  
  4206                              <1> 	;pop	es ; **
  4207 00004586 6658                <1>         pop     ax ; ***
  4208                              <1>         ;jmp     short BAD_COMMAND_POP
  4209 00004588 EB49                <1>         jmp     short BAD_COMMAND
  4210                              <1> chsfnc:	
  4211                              <1> 	;MOV	AX,[ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  4212 0000458A 668B4305            <1> 	mov	ax, [ebx+5]
  4213 0000458E 66C1E802            <1> 	SHR	AX,2
  4214 00004592 8845F8              <1> 	MOV	[CMD_BLOCK],AL
  4215                              <1> 	;;MOV	AL,[ES:BX+8]		; GET CONTROL BYTE MODIFIER
  4216                              <1> 	;;PUSH	DX
  4217                              <1> 	;;MOV	DX,[HF_REG_PORT]
  4218                              <1> 	;;OUT	DX,AL			; SET EXTRA HEAD OPTION
  4219                              <1> 	;;POP	DX ; * 
  4220                              <1> 	;;POP	ES ; **
  4221                              <1> 	;;MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  4222                              <1> 	;;AND	AH,0C0H 		; CONTROL BYTE	
  4223                              <1> 	;;OR	AH,AL
  4224                              <1> 	;;MOV	[CONTROL_BYTE],AH
  4225                              <1> 	;
  4226 00004595 88C8                <1> 	MOV	AL,CL			; GET SECTOR NUMBER
  4227 00004597 243F                <1> 	AND	AL,3FH
  4228 00004599 8845FA              <1> 	MOV	[CMD_BLOCK+2],AL
  4229 0000459C 886DFB              <1> 	MOV	[CMD_BLOCK+3],CH 	; GET CYLINDER NUMBER
  4230 0000459F 88C8                <1> 	MOV	AL,CL
  4231 000045A1 C0E806              <1> 	SHR	AL,6
  4232 000045A4 8845FC              <1> 	MOV	[CMD_BLOCK+4],AL 	; CYLINDER HIGH ORDER 2 BITS
  4233                              <1> 	;;05/01/2015
  4234                              <1> 	;;MOV	AL,DL			; DRIVE NUMBER
  4235 000045A7 A0[1C5D0000]        <1> 	mov	al, [hf_m_s]
  4236 000045AC C0E004              <1> 	SHL	AL,4
  4237 000045AF 80E60F              <1> 	AND	DH,0FH			; HEAD NUMBER
  4238 000045B2 08F0                <1> 	OR	AL,DH
  4239                              <1> 	;OR	AL,80H or 20H
  4240 000045B4 0CA0                <1> 	OR	AL,80h+20h		; ECC AND 512 BYTE SECTORS
  4241 000045B6 8845FD              <1> 	MOV	[CMD_BLOCK+5],AL 	; ECC/SIZE/DRIVE/HEAD
  4242                              <1> su4:
  4243                              <1> 	;POP	ES ; **
  4244                              <1>         ;; 14/02/2015
  4245                              <1>         ;;POP   AX
  4246                              <1>         ;;MOV   [CMD_BLOCK+1],AL        ; SECTOR COUNT
  4247                              <1>         ;;PUSH  AX
  4248                              <1>         ;;MOV   AL,AH                   ; GET INTO LOW BYTE
  4249                              <1>         ;;XOR   AH,AH                   ; ZERO HIGH BYTE
  4250                              <1>         ;;SAL   AX,1                    ; *2 FOR TABLE LOOKUP
  4251 000045B9 6658                <1>         pop     ax ; ***
  4252 000045BB 8845F9              <1>         mov     [CMD_BLOCK+1], al
  4253 000045BE 29DB                <1>         sub	ebx, ebx
  4254 000045C0 88E3                <1> 	mov     bl, ah
  4255                              <1>         ;xor     bh, bh
  4256                              <1>         ;sal     bx, 1
  4257 000045C2 66C1E302            <1>         sal	bx, 2	; 32 bit offset (21/02/2015)
  4258                              <1> 	;;MOV   SI,AX                   ; PUT INTO SI FOR BRANCH
  4259                              <1>         ;;CMP   AX,D1L                  ; TEST WITHIN RANGE
  4260                              <1>         ;;JNB   short BAD_COMMAND_POP
  4261                              <1>         ;cmp     bx, D1L
  4262 000045C6 83FB74              <1> 	cmp	ebx, D1L
  4263 000045C9 7308                <1> 	jnb	short BAD_COMMAND
  4264                              <1>         ;xchg    bx, si
  4265 000045CB 87DE                <1>         xchg	ebx, esi
  4266                              <1> 	;;;POP	AX			; RESTORE AX
  4267                              <1> 	;;;POP	BX			; AND DATA ADDRESS
  4268                              <1> 	
  4269                              <1> 	;;PUSH	CX
  4270                              <1> 	;;PUSH	AX			; ADJUST ES:BX
  4271                              <1> 	;MOV	CX,BX			; GET 3 HIGH ORDER NIBBLES OF BX
  4272                              <1> 	;SHR	CX,4
  4273                              <1> 	;MOV	AX,ES
  4274                              <1> 	;ADD	AX,CX
  4275                              <1> 	;MOV	ES,AX
  4276                              <1> 	;AND	BX,000FH		; ES:BX CHANGED TO ES:000X
  4277                              <1> 	;;POP	AX
  4278                              <1> 	;;POP	CX
  4279                              <1> 	;;JMP	word [CS:SI+D1]
  4280                              <1> 	;jmp	word [SI+D1]
  4281 000045CD FFA6[1A440000]      <1> 	jmp	dword [esi+D1]
  4282                              <1> ;;BAD_COMMAND_POP:
  4283                              <1> ;;	POP	AX
  4284                              <1> ;;	POP	BX
  4285                              <1> BAD_COMMAND:
  4286 000045D3 C605[43590100]01    <1>         MOV     byte [DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  4287 000045DA B000                <1> 	MOV	AL,0
  4288 000045DC C3                  <1> 	RETn
  4289                              <1> 
  4290                              <1> ;----------------------------------------
  4291                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  4292                              <1> ;----------------------------------------
  4293                              <1> 
  4294                              <1> ; 18-1-2015 : one controller reset (not other one)
  4295                              <1> 
  4296                              <1> DISK_RESET:
  4297 000045DD FA                  <1> 	CLI
  4298 000045DE E4A1                <1> 	IN	AL,INTB01		; GET THE MASK REGISTER
  4299                              <1> 	;JMP	$+2
  4300                              <1> 	IODELAY
  4300 000045E0 EB00                <2>  jmp short $+2
  4300 000045E2 EB00                <2>  jmp short $+2
  4301                              <1> 	;AND	AL,0BFH 		; ENABLE FIXED DISK INTERRUPT
  4302 000045E4 243F                <1> 	and	al,3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  4303 000045E6 E6A1                <1> 	OUT	INTB01,AL
  4304 000045E8 FB                  <1> 	STI				; START INTERRUPTS
  4305                              <1> 	; 14/02/2015
  4306 000045E9 6689D7              <1> 	mov	di, dx	
  4307                              <1> 	; 04/01/2015
  4308                              <1> 	;xor	di,di
  4309                              <1> drst0:
  4310 000045EC B004                <1> 	MOV	AL,04H  ; bit 2 - SRST 
  4311                              <1> 	;MOV	DX,HF_REG_PORT
  4312 000045EE 668B15[1A5D0000]    <1> 	MOV	DX,[HF_REG_PORT]
  4313 000045F5 EE                  <1> 	OUT	DX,AL			; RESET
  4314                              <1> ;	MOV	CX,10			; DELAY COUNT
  4315                              <1> ;DRD:	DEC	CX
  4316                              <1> ;	JNZ	short DRD		; WAIT 4.8 MICRO-SEC
  4317                              <1> 	;mov	cx,2			; wait for 30 micro seconds	
  4318 000045F6 B902000000          <1>         mov	ecx, 2 ; 21/02/2015
  4319 000045FB E81DD8FFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  4320                              <1>                                         ; 40 micro seconds)
  4321 00004600 A0[45590100]        <1> 	mov	al,[CONTROL_BYTE]
  4322 00004605 240F                <1> 	AND	AL,0FH			; SET HEAD OPTION
  4323 00004607 EE                  <1> 	OUT	DX,AL			; TURN RESET OFF
  4324 00004608 E838040000          <1> 	CALL	NOT_BUSY
  4325 0000460D 7515                <1> 	JNZ	short DRERR		; TIME OUT ON RESET
  4326 0000460F 668B15[185D0000]    <1> 	MOV	DX,[HF_PORT]
  4327 00004616 FEC2                <1> 	inc	dl  ; HF_PORT+1
  4328                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  4329                              <1>         ;mov     cl, 10
  4330 00004618 B90A000000          <1>         mov     ecx, 10 ; 21/02/2015 
  4331                              <1> drst1:
  4332 0000461D EC                  <1> 	IN	AL,DX			; GET RESET STATUS
  4333 0000461E 3C01                <1> 	CMP	AL,1
  4334                              <1> 	; 04/01/2015
  4335 00004620 740A                <1> 	jz	short drst2
  4336                              <1> 	;JNZ	short DRERR		; BAD RESET STATUS
  4337                              <1>         	; Drive/Head Register - bit 4
  4338 00004622 E2F9                <1> 	loop	drst1
  4339                              <1> DRERR:	
  4340 00004624 C605[43590100]05    <1> 	MOV	byte [DISK_STATUS1],BAD_RESET ; CARD FAILED
  4341 0000462B C3                  <1> 	RETn
  4342                              <1> drst2:
  4343                              <1> 	; 14/02/2015
  4344 0000462C 6689FA              <1> 	mov	dx,di
  4345                              <1> ;drst3:
  4346                              <1> ;	; 05/01/2015
  4347                              <1> ;	shl 	di,1
  4348                              <1> ;	; 04/01/2015
  4349                              <1> ;	mov	ax,[di+hd_cports]
  4350                              <1> ;	cmp	ax,[HF_REG_PORT]
  4351                              <1> ;	je	short drst4
  4352                              <1> ;	mov	[HF_REG_PORT], ax
  4353                              <1> ;	; 03/01/2015
  4354                              <1> ;	mov	ax,[di+hd_ports]
  4355                              <1> ;       mov     [HF_PORT], ax
  4356                              <1> ;	; 05/01/2014
  4357                              <1> ;	shr	di,1
  4358                              <1> ;	; 04/01/2015
  4359                              <1> ;	jmp	short drst0	; reset other controller
  4360                              <1> ;drst4:
  4361                              <1> ;	; 05/01/2015
  4362                              <1> ;	shr	di,1
  4363                              <1> ;	mov	al,[di+hd_dregs]
  4364                              <1> ;	and	al,10h ; bit 4 only
  4365                              <1> ;	shr	al,4 ; bit 4  -> bit 0
  4366                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  4367                              <1> 	;
  4368 0000462F A0[1C5D0000]        <1> 	mov	al, [hf_m_s] ; 18/01/2015
  4369 00004634 A801                <1> 	test	al,1
  4370                              <1> ;	jnz	short drst6
  4371 00004636 7516                <1>         jnz     short drst4
  4372 00004638 8065FDEF            <1> 	AND     byte [CMD_BLOCK+5],0EFH ; SET TO DRIVE 0
  4373                              <1> ;drst5:
  4374                              <1> drst3:
  4375 0000463C E835010000          <1> 	CALL	INIT_DRV		; SET MAX HEADS
  4376                              <1> 	;mov	dx,di
  4377 00004641 E8ED010000          <1> 	CALL	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  4378                              <1> 	; 04/01/2014
  4379                              <1> ;	inc	di
  4380                              <1> ;	mov	dx,di
  4381                              <1> ;	cmp	dl,[HF_NUM]
  4382                              <1> ;	jb	short drst3
  4383                              <1> ;DRE:
  4384 00004646 C605[43590100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; IGNORE ANY SET UP ERRORS
  4385 0000464D C3                  <1> 	RETn
  4386                              <1> ;drst6:
  4387                              <1> drst4:		; Drive/Head Register - bit 4
  4388 0000464E 804DFD10            <1> 	OR      byte [CMD_BLOCK+5],010H ; SET TO DRIVE 1     
  4389                              <1>         ;jmp    short drst5
  4390 00004652 EBE8                <1>         jmp     short drst3
  4391                              <1> 
  4392                              <1> ;----------------------------------------
  4393                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  4394                              <1> ;----------------------------------------
  4395                              <1> 
  4396                              <1> RETURN_STATUS:
  4397 00004654 A0[43590100]        <1> 	MOV	AL,[DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  4398 00004659 C605[43590100]00    <1>         MOV     byte [DISK_STATUS1],0   ; RESET STATUS
  4399 00004660 C3                  <1> 	RETn
  4400                              <1> 
  4401                              <1> ;----------------------------------------
  4402                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  4403                              <1> ;----------------------------------------
  4404                              <1> 
  4405                              <1> DISK_READ:
  4406 00004661 C645FE20            <1> 	MOV	byte [CMD_BLOCK+6],READ_CMD
  4407 00004665 E954020000          <1>         JMP     COMMANDI
  4408                              <1> 
  4409                              <1> ;----------------------------------------
  4410                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  4411                              <1> ;----------------------------------------
  4412                              <1> 
  4413                              <1> DISK_WRITE:
  4414 0000466A C645FE30            <1> 	MOV	byte [CMD_BLOCK+6],WRITE_CMD
  4415 0000466E E9A6020000          <1>         JMP     COMMANDO
  4416                              <1> 
  4417                              <1> ;----------------------------------------
  4418                              <1> ;	DISK VERIFY	     (AH = 04H) :
  4419                              <1> ;----------------------------------------
  4420                              <1> 
  4421                              <1> DISK_VERF:
  4422 00004673 C645FE40            <1> 	MOV	byte [CMD_BLOCK+6],VERIFY_CMD
  4423 00004677 E814030000          <1> 	CALL	COMMAND
  4424 0000467C 750C                <1> 	JNZ	short VERF_EXIT		; CONTROLLER STILL BUSY
  4425 0000467E E886030000          <1> 	CALL	_WAIT			; (Original: CALL WAIT)	
  4426 00004683 7505                <1> 	JNZ	short VERF_EXIT		; TIME OUT
  4427 00004685 E813040000          <1> 	CALL	CHECK_STATUS
  4428                              <1> VERF_EXIT:
  4429 0000468A C3                  <1> 	RETn
  4430                              <1> 
  4431                              <1> ;----------------------------------------
  4432                              <1> ;	FORMATTING	     (AH = 05H) :
  4433                              <1> ;----------------------------------------
  4434                              <1> 
  4435                              <1> FMT_TRK:				; FORMAT TRACK	(AH = 005H)
  4436 0000468B C645FE50            <1> 	MOV	byte [CMD_BLOCK+6],FMTTRK_CMD
  4437                              <1> 	;PUSH	ES
  4438                              <1> 	;PUSH	BX
  4439 0000468F 53                  <1> 	push	ebx
  4440 00004690 E8BA040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  4441                              <1> 	;MOV	AL,[ES:BX+14]		; GET SECTORS/TRACK
  4442 00004695 8A430E              <1> 	mov	al, [ebx+14]
  4443 00004698 8845F9              <1> 	MOV	[CMD_BLOCK+1],AL 	; SET SECTOR COUNT IN COMMAND
  4444 0000469B 5B                  <1> 	pop	ebx
  4445                              <1> 	;POP	BX
  4446                              <1> 	;POP	ES
  4447 0000469C E97F020000          <1>         JMP     CMD_OF                  ; GO EXECUTE THE COMMAND
  4448                              <1> 
  4449                              <1> ;----------------------------------------
  4450                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  4451                              <1> ;----------------------------------------
  4452                              <1> 
  4453                              <1> READ_DASD_TYPE:
  4454                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  4455 000046A1 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  4456                              <1> 	;PUSH	ES
  4457 000046A2 53                  <1> 	PUSH	eBX
  4458                              <1> 	;CALL	DDS			; ESTABLISH ADDRESSING
  4459                              <1> 	;push	cs
  4460                              <1> 	;pop	ds
  4461 000046A3 66BB1000            <1>         mov	bx, KDATA
  4462 000046A7 8EDB                <1> 	mov	ds, bx
  4463                              <1> 	;mov	es, bx
  4464 000046A9 C605[43590100]00    <1> 	MOV     byte [DISK_STATUS1],0
  4465 000046B0 8A1D[44590100]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  4466 000046B6 80E27F              <1> 	AND	DL,7FH			; GET DRIVE NUMBER
  4467 000046B9 38D3                <1> 	CMP	BL,DL
  4468 000046BB 7627                <1> 	JBE	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  4469 000046BD E88D040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETER ADDRESS
  4470                              <1> 	;MOV	AL,[ES:BX+2]		; HEADS
  4471 000046C2 8A4302              <1> 	mov	al, [ebx+2]
  4472                              <1> 	;MOV	CL,[ES:BX+14]
  4473 000046C5 8A4B0E              <1> 	mov	cl, [ebx+14]
  4474 000046C8 F6E9                <1> 	IMUL	CL			; * NUMBER OF SECTORS
  4475                              <1> 	;MOV	CX,[ES:BX]		; MAX NUMBER OF CYLINDERS
  4476 000046CA 668B0B              <1> 	mov	cx ,[ebx]
  4477                              <1> 	;
  4478                              <1> 	; 02/01/2015 
  4479                              <1> 	; ** leave the last cylinder as reserved for diagnostics **
  4480                              <1> 	; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  4481 000046CD 6649                <1> 	DEC	CX			; LEAVE ONE FOR DIAGNOSTICS
  4482                              <1> 	;
  4483 000046CF 66F7E9              <1> 	IMUL	CX			; NUMBER OF SECTORS
  4484 000046D2 6689D1              <1> 	MOV	CX,DX			; HIGH ORDER HALF
  4485 000046D5 6689C2              <1> 	MOV	DX,AX			; LOW ORDER HALF
  4486                              <1> 	;SUB	AX,AX
  4487 000046D8 28C0                <1> 	sub	al, al
  4488 000046DA B403                <1> 	MOV	AH,03H			; INDICATE FIXED DISK
  4489 000046DC 5B                  <1> RDT2:	POP	eBX			; RESTORE REGISTERS
  4490                              <1> 	;POP	ES
  4491 000046DD 1F                  <1> 	POP	DS
  4492                              <1> 	; (*) CLC			; CLEAR CARRY
  4493                              <1> 	;RETf	2
  4494                              <1> 	; (*) 29/05/2016
  4495                              <1> 	; (*) retf 4
  4496 000046DE 80642408FE          <1> 	and	byte [esp+8], 0FEh ; clear carry bit of eflags register
  4497 000046E3 CF                  <1> 	iretd
  4498                              <1> 
  4499                              <1> RDT_NOT_PRESENT:
  4500 000046E4 6629C0              <1> 	SUB	AX,AX			; DRIVE NOT PRESENT RETURN
  4501 000046E7 6689C1              <1> 	MOV	CX,AX			; ZERO BLOCK COUNT
  4502 000046EA 6689C2              <1> 	MOV	DX,AX
  4503 000046ED EBED                <1> 	JMP	short RDT2
  4504                              <1> 
  4505                              <1> ; 28/05/2016
  4506                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  4507                              <1> 
  4508                              <1> ;----------------------------------------
  4509                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  4510                              <1> ;----------------------------------------
  4511                              <1> 
  4512                              <1> GET_PARM_N:
  4513                              <1> 	; ebx = user's buffer address for parameters table
  4514                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  4515 000046EF 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  4516 000046F0 06                  <1> 	PUSH	ES
  4517 000046F1 53                  <1> 	PUSH	eBX
  4518                              <1> 	;MOV	AX,ABS0 		; ESTABLISH ADDRESSING
  4519                              <1> 	;MOV	DS,AX
  4520                              <1> 	;TEST	DL,1			; CHECK FOR DRIVE 1
  4521                              <1> 	;JZ	short G0
  4522                              <1> 	;LES	BX,@HF1_TBL_VEC
  4523                              <1> 	;JMP	SHORT G1
  4524                              <1> ;G0:	LES	BX,@HF_TBL_VEC
  4525                              <1> ;G1:
  4526                              <1> 	;CALL	DDS			; ESTABLISH SEGMENT
  4527                              <1> 	; 22/12/2014
  4528                              <1> 	;push	cs
  4529                              <1> 	;pop	ds
  4530 000046F2 66BB1000            <1> 	mov	bx, KDATA
  4531 000046F6 8EDB                <1> 	mov	ds, bx
  4532 000046F8 8EC3                <1> 	mov	es, bx	; 27/05/2016
  4533                              <1> 	;
  4534 000046FA 80EA80              <1> 	SUB	DL,80H
  4535 000046FD 80FA04              <1> 	CMP	DL,MAX_FILE		; TEST WITHIN RANGE
  4536 00004700 7361                <1> 	JAE	short G4
  4537                              <1> 	;
  4538 00004702 31DB                <1> 	xor	ebx, ebx ; 21/02/2015
  4539                              <1> 	; 22/12/2014
  4540 00004704 88D3                <1> 	mov	bl, dl
  4541                              <1> 	;xor	bh, bh  
  4542 00004706 C0E302              <1> 	shl	bl, 2			; convert index to offset
  4543                              <1> 	;add	bx, HF_TBL_VEC
  4544 00004709 81C3[48590100]      <1> 	add	ebx, HF_TBL_VEC
  4545                              <1> 	;mov	ax, [bx+2]
  4546                              <1> 	;mov	es, ax			; dpt segment
  4547                              <1> 	;mov	bx, [bx]		; dpt offset
  4548 0000470F 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  4549                              <1> 
  4550 00004711 C605[43590100]00    <1> 	MOV	byte [DISK_STATUS1],0
  4551                              <1>         ;MOV     AX,[ES:BX]             ; MAX NUMBER OF CYLINDERS
  4552 00004718 668B03              <1> 	mov	ax, [ebx]
  4553                              <1> 	;;SUB	AX,2			; ADJUST FOR 0-N
  4554 0000471B 6648                <1> 	dec	ax			; max. cylinder number
  4555 0000471D 88C5                <1> 	MOV	CH,AL
  4556 0000471F 66250003            <1> 	AND	AX,0300H		; HIGH TWO BITS OF CYLINDER
  4557 00004723 66D1E8              <1> 	SHR	AX,1
  4558 00004726 66D1E8              <1> 	SHR	AX,1
  4559                              <1> 	;OR	AL,[ES:BX+14]		; SECTORS
  4560 00004729 0A430E              <1> 	or	al, [ebx+14]
  4561 0000472C 88C1                <1> 	MOV	CL,AL
  4562                              <1> 	;MOV	DH,[ES:BX+2]		; HEADS
  4563 0000472E 8A7302              <1> 	mov	dh, [ebx+2]
  4564 00004731 FECE                <1> 	DEC	DH			; 0-N RANGE
  4565 00004733 8A15[44590100]      <1> 	MOV	DL,[HF_NUM]		; DRIVE COUNT
  4566 00004739 6629C0              <1> 	SUB	AX,AX
  4567                              <1>         ;27/12/2014 
  4568                              <1> 	;mov	di, bx			; HDPT offset
  4569                              <1> 	
  4570                              <1> 	; 27/05/2016
  4571                              <1> 	; return fixed disk parameters table to user
  4572                              <1> 	; in user's buffer, which is pointed by EBX
  4573                              <1> 	;
  4574 0000473C 873C24              <1> 	xchg	edi, [esp]		; ebx (input)-> edi, edi -> [esp]
  4575 0000473F 56                  <1> 	push	esi
  4576 00004740 89DE                <1> 	mov	esi, ebx		; hard disk parameter table (32 bytes)	
  4577 00004742 89FB                <1> 	mov	ebx, edi		; ebx = user's buffer address
  4578 00004744 51                  <1> 	push	ecx
  4579 00004745 50                  <1> 	push	eax
  4580 00004746 B920000000          <1> 	mov	ecx, 32 ; 32 bytes
  4581 0000474B E884A00000          <1> 	call	transfer_to_user_buffer ; trdosk6.s (16/05/2016)
  4582 00004750 58                  <1> 	pop	eax
  4583 00004751 59                  <1> 	pop	ecx
  4584 00004752 5E                  <1> 	pop	esi
  4585 00004753 5F                  <1> 	pop	edi
  4586 00004754 730A                <1> 	jnc	short G5
  4587                              <1> 	; 29/05/2016 (*)
  4588 00004756 B8FF000000          <1> 	mov	eax, 0FFh ; unknown error !
  4589                              <1> _G6:
  4590 0000475B 804C241001          <1> 	or	byte [esp+16], 1 ; set carry bit of eflags register
  4591                              <1> G5:
  4592                              <1> 	; 27/05/2016
  4593                              <1> 	;POP	eBX			; RESTORE REGISTERS
  4594 00004760 07                  <1> 	POP	ES
  4595 00004761 1F                  <1> 	POP	DS
  4596                              <1> 	;RETf	2
  4597                              <1> 	; (*) 29/05/2016
  4598                              <1> 	; (*) retf 4
  4599                              <1> 	; (*) or byte [esp+8], 1 ; set carry bit of eflags register
  4600 00004762 CF                  <1> 	iretd
  4601                              <1> G4:
  4602 00004763 C605[43590100]07    <1> 	MOV     byte [DISK_STATUS1],INIT_FAIL ; OPERATION FAILED
  4603 0000476A B407                <1> 	MOV	AH,INIT_FAIL
  4604 0000476C 28C0                <1> 	SUB	AL,AL
  4605 0000476E 6629D2              <1> 	SUB	DX,DX
  4606 00004771 6629C9              <1> 	SUB	CX,CX
  4607                              <1> 	; 29/05/2016 (*)
  4608                              <1> 	;STC				; SET ERROR FLAG
  4609                              <1> 	;JMP	short G5
  4610 00004774 EBE5                <1> 	jmp	short _G6
  4611                              <1> 
  4612                              <1> ;----------------------------------------
  4613                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  4614                              <1> ;----------------------------------------
  4615                              <1> 	; 03/01/2015
  4616                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  4617                              <1> 	; logical sector per logical track
  4618                              <1> 	; and logical heads - 1 would be set but
  4619                              <1> 	; it is seen as it will be good
  4620                              <1> 	; if physical parameters will be set here
  4621                              <1> 	; because, number of heads <= 16.
  4622                              <1> 	; (logical heads usually more than 16)
  4623                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  4624                              <1> 	;	== INT 13h physical parameters
  4625                              <1> 
  4626                              <1> ;INIT_DRV:
  4627                              <1> ;	MOV	byte [CMD_BLOCK+6],SET_PARM_CMD
  4628                              <1> ;	CALL	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  4629                              <1> ;	MOV	AL,[ES:BX+2]		; GET NUMBER OF HEADS
  4630                              <1> ;	DEC	AL			; CONVERT TO 0-INDEX
  4631                              <1> ;	MOV	AH,[CMD_BLOCK+5] 	; GET SDH REGISTER
  4632                              <1> ;	AND	AH,0F0H 		; CHANGE HEAD NUMBER
  4633                              <1> ;	OR	AH,AL			; TO MAX HEAD
  4634                              <1> ;	MOV	[CMD_BLOCK+5],AH
  4635                              <1> ;	MOV	AL,[ES:BX+14]		; MAX SECTOR NUMBER
  4636                              <1> ;	MOV	[CMD_BLOCK+1],AL
  4637                              <1> ;	SUB	AX,AX
  4638                              <1> ;	MOV	[CMD_BLOCK+3],AL 	; ZERO FLAGS
  4639                              <1> ;	CALL	COMMAND 		; TELL CONTROLLER
  4640                              <1> ;	JNZ	short INIT_EXIT		; CONTROLLER BUSY ERROR
  4641                              <1> ;	CALL	NOT_BUSY		; WAIT FOR IT TO BE DONE
  4642                              <1> ;	JNZ	short INIT_EXIT		; TIME OUT
  4643                              <1> ;	CALL	CHECK_STATUS
  4644                              <1> ;INIT_EXIT:
  4645                              <1> ;	RETn
  4646                              <1> 
  4647                              <1> ; 04/01/2015
  4648                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  4649                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  4650                              <1> INIT_DRV:
  4651                              <1> 	;xor	ah,ah
  4652 00004776 31C0                <1> 	xor	eax, eax ; 21/02/2015
  4653 00004778 B00B                <1> 	mov	al,11 ; Physical heads from translated HDPT
  4654 0000477A 3825[58590100]      <1>         cmp     [LBAMode], ah   ; 0
  4655 00004780 7702                <1> 	ja	short idrv0
  4656 00004782 B002                <1> 	mov	al,2  ; Physical heads from standard HDPT
  4657                              <1> idrv0:
  4658                              <1> 	; DL = drive number (0 based)
  4659 00004784 E8C6030000          <1> 	call	GET_VEC
  4660                              <1> 	;push	bx
  4661 00004789 53                  <1> 	push	ebx ; 21/02/2015
  4662                              <1> 	;add	bx,ax
  4663 0000478A 01C3                <1> 	add	ebx, eax
  4664                              <1> 	;; 05/01/2015
  4665 0000478C 8A25[1C5D0000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  4666                              <1> 	;;and 	ah,1 
  4667 00004792 C0E404              <1> 	shl	ah,4
  4668 00004795 80CCA0              <1> 	or	ah,0A0h  ; Drive/Head register - 10100000b (A0h)	
  4669                              <1> 	;mov	al,[es:bx]
  4670 00004798 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  4671 0000479A FEC8                <1> 	dec	al	 ; last head number 
  4672                              <1> 	;and	al,0Fh
  4673 0000479C 08E0                <1> 	or	al,ah	 ; lower 4 bits for head number
  4674                              <1> 	;
  4675 0000479E C645FE91            <1> 	mov	byte [CMD_BLOCK+6],SET_PARM_CMD
  4676 000047A2 8845FD              <1> 	mov	[CMD_BLOCK+5],al
  4677                              <1> 	;pop	bx
  4678 000047A5 5B                  <1> 	pop	ebx
  4679 000047A6 29C0                <1> 	sub	eax, eax ; 21/02/2015
  4680 000047A8 B004                <1> 	mov	al,4 ; Physical sec per track from translated HDPT
  4681 000047AA 803D[58590100]00    <1> 	cmp	byte [LBAMode], 0
  4682 000047B1 7702                <1> 	ja	short idrv1
  4683 000047B3 B00E                <1> 	mov	al,14 ; Physical sec per track from standard HDPT
  4684                              <1> idrv1:
  4685                              <1> 	;xor	ah,ah
  4686                              <1> 	;add	bx,ax
  4687 000047B5 01C3                <1> 	add	ebx, eax ; 21/02/2015
  4688                              <1> 	;mov	al,[es:bx]
  4689                              <1> 			; sector number
  4690 000047B7 8A03                <1> 	mov	al, [ebx]
  4691 000047B9 8845F9              <1> 	mov	[CMD_BLOCK+1],al
  4692 000047BC 28C0                <1> 	sub	al,al
  4693 000047BE 8845FB              <1> 	mov	[CMD_BLOCK+3],al  ; ZERO FLAGS
  4694 000047C1 E8CA010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  4695 000047C6 750C                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  4696 000047C8 E878020000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  4697 000047CD 7505                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  4698 000047CF E8C9020000          <1> 	call	CHECK_STATUS
  4699                              <1> INIT_EXIT:
  4700 000047D4 C3                  <1> 	RETn
  4701                              <1> 
  4702                              <1> ;----------------------------------------
  4703                              <1> ;	READ LONG	     (AH = 0AH) :
  4704                              <1> ;----------------------------------------
  4705                              <1> 
  4706                              <1> RD_LONG:
  4707                              <1> 	;MOV	@CMD_BLOCK+6,READ_CMD OR ECC_MODE
  4708 000047D5 C645FE22            <1>         mov     byte [CMD_BLOCK+6],READ_CMD + ECC_MODE 
  4709 000047D9 E9E0000000          <1>         JMP     COMMANDI
  4710                              <1> 
  4711                              <1> ;----------------------------------------
  4712                              <1> ;	WRITE LONG	     (AH = 0BH) :
  4713                              <1> ;----------------------------------------
  4714                              <1> 
  4715                              <1> WR_LONG:
  4716                              <1> 	;MOV	@CMD_BLOCK+6,WRITE_CMD OR ECC_MODE
  4717 000047DE C645FE32            <1>         MOV     byte [CMD_BLOCK+6],WRITE_CMD + ECC_MODE
  4718 000047E2 E932010000          <1>         JMP     COMMANDO
  4719                              <1> 
  4720                              <1> ;----------------------------------------
  4721                              <1> ;	SEEK		     (AH = 0CH) :
  4722                              <1> ;----------------------------------------
  4723                              <1> 
  4724                              <1> DISK_SEEK:
  4725 000047E7 C645FE70            <1>         MOV     byte [CMD_BLOCK+6],SEEK_CMD
  4726 000047EB E8A0010000          <1> 	CALL	COMMAND
  4727 000047F0 751C                <1> 	JNZ	short DS_EXIT 		; CONTROLLER BUSY ERROR
  4728 000047F2 E812020000          <1> 	CALL	_WAIT
  4729 000047F7 7515                <1>         JNZ     DS_EXIT                 ; TIME OUT ON SEEK
  4730 000047F9 E89F020000          <1> 	CALL	CHECK_STATUS
  4731 000047FE 803D[43590100]40    <1>         CMP     byte [DISK_STATUS1],BAD_SEEK
  4732 00004805 7507                <1> 	JNE	short DS_EXIT
  4733 00004807 C605[43590100]00    <1>         MOV     byte [DISK_STATUS1],0
  4734                              <1> DS_EXIT:
  4735 0000480E C3                  <1> 	RETn
  4736                              <1> 
  4737                              <1> ;----------------------------------------
  4738                              <1> ;	TEST DISK READY      (AH = 10H) :
  4739                              <1> ;----------------------------------------
  4740                              <1> 
  4741                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  4742 0000480F E831020000          <1> 	CALL	NOT_BUSY
  4743 00004814 751C                <1> 	JNZ	short TR_EX
  4744 00004816 8A45FD              <1> 	MOV	AL,[CMD_BLOCK+5] 	; SELECT DRIVE
  4745 00004819 668B15[185D0000]    <1> 	MOV	DX,[HF_PORT]
  4746 00004820 80C206              <1> 	add	dl,6
  4747 00004823 EE                  <1> 	OUT	DX,AL
  4748 00004824 E88C020000          <1> 	CALL	CHECK_ST		; CHECK STATUS ONLY
  4749 00004829 7507                <1> 	JNZ	short TR_EX
  4750 0000482B C605[43590100]00    <1> 	MOV	byte [DISK_STATUS1],0 	; WIPE OUT DATA CORRECTED ERROR
  4751                              <1> TR_EX:	
  4752 00004832 C3                  <1> 	RETn
  4753                              <1> 
  4754                              <1> ;----------------------------------------
  4755                              <1> ;	RECALIBRATE	     (AH = 11H) :
  4756                              <1> ;----------------------------------------
  4757                              <1> 
  4758                              <1> HDISK_RECAL:
  4759 00004833 C645FE10            <1>         MOV     byte [CMD_BLOCK+6],RECAL_CMD ; 10h, 16
  4760 00004837 E854010000          <1> 	CALL	COMMAND 		; START THE OPERATION
  4761 0000483C 7523                <1> 	JNZ	short RECAL_EXIT	; ERROR
  4762 0000483E E8C6010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION
  4763 00004843 7407                <1> 	JZ	short RECAL_X 		; TIME OUT ONE OK ?
  4764 00004845 E8BF010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION LONGER
  4765 0000484A 7515                <1> 	JNZ	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  4766                              <1> RECAL_X:
  4767 0000484C E84C020000          <1> 	CALL	CHECK_STATUS
  4768 00004851 803D[43590100]40    <1> 	CMP	byte [DISK_STATUS1],BAD_SEEK ; SEEK NOT COMPLETE
  4769 00004858 7507                <1> 	JNE	short RECAL_EXIT	; IS OK
  4770 0000485A C605[43590100]00    <1> 	MOV	byte [DISK_STATUS1],0
  4771                              <1> RECAL_EXIT:
  4772 00004861 803D[43590100]00    <1>         CMP     byte [DISK_STATUS1],0
  4773 00004868 C3                  <1> 	RETn
  4774                              <1> 
  4775                              <1> ;----------------------------------------
  4776                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  4777                              <1> ;----------------------------------------
  4778                              <1> 
  4779                              <1> CTLR_DIAGNOSTIC:
  4780 00004869 FA                  <1>         CLI                             ; DISABLE INTERRUPTS WHILE CHANGING MASK
  4781 0000486A E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  4782                              <1> 	;AND	AL,0BFH
  4783 0000486C 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  4784                              <1> 	;JMP	$+2
  4785                              <1> 	IODELAY
  4785 0000486E EB00                <2>  jmp short $+2
  4785 00004870 EB00                <2>  jmp short $+2
  4786 00004872 E6A1                <1> 	OUT	INTB01,AL
  4787                              <1> 	IODELAY
  4787 00004874 EB00                <2>  jmp short $+2
  4787 00004876 EB00                <2>  jmp short $+2
  4788 00004878 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  4789 0000487A 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  4790                              <1> 	;JMP	$+2
  4791                              <1> 	IODELAY
  4791 0000487C EB00                <2>  jmp short $+2
  4791 0000487E EB00                <2>  jmp short $+2
  4792 00004880 E621                <1> 	OUT	INTA01,AL
  4793 00004882 FB                  <1> 	STI
  4794 00004883 E8BD010000          <1> 	CALL	NOT_BUSY		; WAIT FOR CARD
  4795 00004888 752B                <1> 	JNZ	short CD_ERR		; BAD CARD
  4796                              <1> 	;MOV	DX, HF_PORT+7
  4797 0000488A 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4798 00004891 80C207              <1> 	add	dl, 7
  4799 00004894 B090                <1> 	MOV	AL,DIAG_CMD		; START DIAGNOSE
  4800 00004896 EE                  <1> 	OUT	DX,AL
  4801 00004897 E8A9010000          <1> 	CALL	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  4802 0000489C B480                <1> 	MOV	AH,TIME_OUT
  4803 0000489E 7517                <1> 	JNZ	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  4804                              <1> 	;MOV	DX,HF_PORT+1		; GET ERROR REGISTER
  4805 000048A0 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4806 000048A7 FEC2                <1> 	inc	dl
  4807 000048A9 EC                  <1> 	IN	AL,DX
  4808 000048AA A2[3A590100]        <1> 	MOV	[HF_ERROR],AL		; SAVE IT
  4809 000048AF B400                <1> 	MOV	AH,0
  4810 000048B1 3C01                <1> 	CMP	AL,1			; CHECK FOR ALL OK
  4811 000048B3 7402                <1> 	JE	SHORT CD_EXIT
  4812 000048B5 B420                <1> CD_ERR: MOV	AH,BAD_CNTLR
  4813                              <1> CD_EXIT:
  4814 000048B7 8825[43590100]      <1> 	MOV	[DISK_STATUS1],AH
  4815 000048BD C3                  <1> 	RETn
  4816                              <1> 
  4817                              <1> ;----------------------------------------
  4818                              <1> ; COMMANDI				:
  4819                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  4820                              <1> ;	NSECTOR RETURNS ZERO		:
  4821                              <1> ;----------------------------------------
  4822                              <1> COMMANDI:
  4823 000048BE E862020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  4824 000048C3 7253                <1> 	JC	short CMD_ABORT
  4825                              <1> 	;MOV	DI,BX
  4826 000048C5 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  4827 000048C7 E8C4000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  4828 000048CC 754A                <1> 	JNZ	short CMD_ABORT
  4829                              <1> CMD_I1:
  4830 000048CE E836010000          <1> 	CALL	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  4831 000048D3 7543                <1> 	JNZ	short TM_OUT		; TIME OUT
  4832                              <1> cmd_i1x: ; 18/02/2016
  4833                              <1> 	;MOV	CX,256			; SECTOR SIZE IN WORDS
  4834 000048D5 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015	
  4835                              <1> 	;MOV	DX,HF_PORT
  4836 000048DA 668B15[185D0000]    <1> 	mov	dx,[HF_PORT]
  4837 000048E1 FA                  <1> 	CLI
  4838 000048E2 FC                  <1> 	CLD
  4839 000048E3 F3666D              <1> 	REP	INSW			; GET THE SECTOR
  4840 000048E6 FB                  <1> 	STI
  4841 000048E7 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL INPUT
  4842 000048EB 7419                <1> 	JZ	short CMD_I3
  4843 000048ED E880010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4844 000048F2 7224                <1> 	JC	short TM_OUT
  4845                              <1> 	;MOV	DX,HF_PORT
  4846 000048F4 668B15[185D0000]    <1> 	mov	dx,[HF_PORT]
  4847                              <1> 	;MOV	CX,4			; GET ECC BYTES
  4848 000048FB B904000000          <1> 	mov 	ecx, 4 ; mov cx, 4 
  4849 00004900 EC                  <1> CMD_I2: IN	AL,DX
  4850                              <1> 	;MOV	[ES:DI],AL		; GO SLOW FOR BOARD
  4851 00004901 8807                <1> 	mov 	[edi], al ; 21/02/2015
  4852 00004903 47                  <1> 	INC	eDI
  4853 00004904 E2FA                <1> 	LOOP	CMD_I2
  4854                              <1> CMD_I3: 
  4855                              <1> 	; wait for 400 ns
  4856 00004906 80C207              <1> 	add 	dl, 7
  4857 00004909 EC                  <1> 	in	al, dx
  4858 0000490A EC                  <1> 	in	al, dx
  4859 0000490B EC                  <1> 	in	al, dx
  4860                              <1> 	;
  4861 0000490C E88C010000          <1> 	CALL	CHECK_STATUS
  4862 00004911 7505                <1> 	JNZ	short CMD_ABORT		; ERROR RETURNED
  4863 00004913 FE4DF9              <1> 	DEC	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  4864                              <1> 	;JNZ	SHORT CMD_I1
  4865 00004916 75BD                <1> 	jnz	short cmd_i1x ; 18/02/2016
  4866                              <1> CMD_ABORT:
  4867 00004918 C3                  <1> TM_OUT: RETn
  4868                              <1> 
  4869                              <1> ;----------------------------------------
  4870                              <1> ; COMMANDO				:
  4871                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  4872                              <1> ;	NSECTOR RETURNS ZERO		:
  4873                              <1> ;----------------------------------------
  4874                              <1> COMMANDO:
  4875 00004919 E807020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  4876 0000491E 72F8                <1> 	JC	short CMD_ABORT
  4877 00004920 89DE                <1> CMD_OF: MOV	eSI,eBX ; 21/02/2015
  4878 00004922 E869000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  4879 00004927 75EF                <1> 	JNZ	short CMD_ABORT
  4880 00004929 E844010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4881 0000492E 72E8                <1> 	JC	short TM_OUT			; TOO LONG
  4882                              <1> CMD_O1: ;PUSH	DS
  4883                              <1> 	;PUSH	ES			; MOVE ES TO DS
  4884                              <1> 	;POP	DS
  4885                              <1> 	;MOV	CX,256			; PUT THE DATA OUT TO THE CARD
  4886                              <1> 	;MOV	DX,HF_PORT
  4887                              <1> 	; 01/02/2015
  4888 00004930 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4889                              <1> 	;push	es
  4890                              <1> 	;pop	ds
  4891                              <1> 	;mov	cx, 256
  4892 00004937 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015
  4893 0000493C FA                  <1> 	CLI
  4894 0000493D FC                  <1> 	CLD
  4895 0000493E F3666F              <1> 	REP	OUTSW
  4896 00004941 FB                  <1> 	STI
  4897                              <1> 	;POP	DS			; RESTORE DS
  4898 00004942 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL OUTPUT
  4899 00004946 7419                <1> 	JZ	short CMD_O3
  4900 00004948 E825010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  4901 0000494D 72C9                <1> 	JC	short TM_OUT
  4902                              <1> 	;MOV	DX,HF_PORT
  4903 0000494F 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4904                              <1> 	;MOV	CX,4			; OUTPUT THE ECC BYTES
  4905 00004956 B904000000          <1> 	mov	ecx, 4  ; mov cx, 4
  4906                              <1> CMD_O2: ;MOV	AL,[ES:SI]
  4907 0000495B 8A06                <1> 	mov	al, [esi]
  4908 0000495D EE                  <1> 	OUT	DX,AL
  4909 0000495E 46                  <1> 	INC	eSI
  4910 0000495F E2FA                <1> 	LOOP	CMD_O2
  4911                              <1> CMD_O3:
  4912 00004961 E8A3000000          <1> 	CALL	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  4913 00004966 75B0                <1> 	JNZ	short TM_OUT		; ERROR RETURNED
  4914 00004968 E830010000          <1> 	CALL	CHECK_STATUS
  4915 0000496D 75A9                <1> 	JNZ	short CMD_ABORT
  4916 0000496F F605[39590100]08    <1> 	TEST	byte [HF_STATUS],ST_DRQ	; CHECK FOR MORE
  4917 00004976 75B8                <1> 	JNZ	SHORT CMD_O1
  4918                              <1> 	;MOV	DX,HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  4919 00004978 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4920                              <1> 	;add	dl, 2
  4921 0000497F FEC2                <1> 	inc	dl
  4922 00004981 FEC2                <1> 	inc	dl
  4923 00004983 EC                  <1> 	IN	AL,DX			;
  4924 00004984 A8FF                <1> 	TEST	AL,0FFH 		;
  4925 00004986 7407                <1> 	JZ	short CMD_O4			; COUNT = 0  OK
  4926 00004988 C605[43590100]BB    <1> 	MOV	byte [DISK_STATUS1],UNDEF_ERR 
  4927                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  4928                              <1> CMD_O4:
  4929 0000498F C3                  <1> 	RETn
  4930                              <1> 
  4931                              <1> ;--------------------------------------------------------
  4932                              <1> ; COMMAND						:
  4933                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  4934                              <1> ; OUTPUT						:
  4935                              <1> ;	BL = STATUS					:
  4936                              <1> ;	BH = ERROR REGISTER				:
  4937                              <1> ;--------------------------------------------------------
  4938                              <1> 
  4939                              <1> COMMAND:
  4940 00004990 53                  <1> 	PUSH	eBX			; WAIT FOR SEEK COMPLETE AND READY
  4941                              <1> 	;;MOV	CX,DELAY_2		; SET INITIAL DELAY BEFORE TEST
  4942                              <1> COMMAND1:
  4943                              <1> 	;;PUSH	CX			; SAVE LOOP COUNT
  4944 00004991 E879FEFFFF          <1> 	CALL	TST_RDY 		; CHECK DRIVE READY
  4945                              <1> 	;;POP	CX
  4946 00004996 7419                <1> 	JZ	short COMMAND2		; DRIVE IS READY
  4947 00004998 803D[43590100]80    <1>         CMP     byte [DISK_STATUS1],TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
  4948                              <1> 	;JZ	short CMD_TIMEOUT
  4949                              <1> 	;;LOOP	COMMAND1		; KEEP TRYING FOR A WHILE
  4950                              <1> 	;JMP	SHORT COMMAND4		; ITS NOT GOING TO GET READY
  4951 0000499F 7507                <1> 	jne	short COMMAND4
  4952                              <1> CMD_TIMEOUT:
  4953 000049A1 C605[43590100]20    <1> 	MOV	byte [DISK_STATUS1],BAD_CNTLR
  4954                              <1> COMMAND4:
  4955 000049A8 5B                  <1> 	POP	eBX
  4956 000049A9 803D[43590100]00    <1>         CMP     byte [DISK_STATUS1],0   ; SET CONDITION CODE FOR CALLER
  4957 000049B0 C3                  <1> 	RETn
  4958                              <1> COMMAND2:
  4959 000049B1 5B                  <1> 	POP	eBX
  4960 000049B2 57                  <1> 	PUSH	eDI
  4961 000049B3 C605[3B590100]00    <1> 	MOV	byte [HF_INT_FLAG],0	; RESET INTERRUPT FLAG
  4962 000049BA FA                  <1> 	CLI				; INHIBIT INTERRUPTS WHILE CHANGING MASK
  4963 000049BB E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  4964                              <1> 	;AND	AL,0BFH
  4965 000049BD 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
  4966                              <1> 	;JMP	$+2
  4967                              <1> 	IODELAY
  4967 000049BF EB00                <2>  jmp short $+2
  4967 000049C1 EB00                <2>  jmp short $+2
  4968 000049C3 E6A1                <1> 	OUT	INTB01,AL
  4969 000049C5 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  4970 000049C7 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  4971                              <1> 	;JMP	$+2
  4972                              <1> 	IODELAY
  4972 000049C9 EB00                <2>  jmp short $+2
  4972 000049CB EB00                <2>  jmp short $+2
  4973 000049CD E621                <1> 	OUT	INTA01,AL
  4974 000049CF FB                  <1> 	STI
  4975 000049D0 31FF                <1> 	XOR	eDI,eDI			; INDEX THE COMMAND TABLE
  4976                              <1> 	;MOV	DX,HF_PORT+1		; DISK ADDRESS
  4977 000049D2 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  4978 000049D9 FEC2                <1> 	inc	dl
  4979 000049DB F605[45590100]C0    <1> 	TEST	byte [CONTROL_BYTE],0C0H ; CHECK FOR RETRY SUPPRESSION
  4980 000049E2 7411                <1> 	JZ	short COMMAND3
  4981 000049E4 8A45FE              <1> 	MOV	AL, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
  4982 000049E7 24F0                <1> 	AND	AL,0F0H 		; GET RID OF MODIFIERS
  4983 000049E9 3C20                <1> 	CMP	AL,20H			; 20H-40H IS READ, WRITE, VERIFY
  4984 000049EB 7208                <1> 	JB	short COMMAND3
  4985 000049ED 3C40                <1> 	CMP	AL,40H
  4986 000049EF 7704                <1> 	JA	short COMMAND3
  4987 000049F1 804DFE01            <1> 	OR	byte [CMD_BLOCK+6],NO_RETRIES 
  4988                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
  4989                              <1> COMMAND3:
  4990 000049F5 8A443DF8            <1> 	MOV	AL,[CMD_BLOCK+eDI]	; GET THE COMMAND STRING BYTE
  4991 000049F9 EE                  <1> 	OUT	DX,AL			; GIVE IT TO CONTROLLER
  4992                              <1> 	IODELAY
  4992 000049FA EB00                <2>  jmp short $+2
  4992 000049FC EB00                <2>  jmp short $+2
  4993 000049FE 47                  <1> 	INC	eDI			; NEXT BYTE IN COMMAND BLOCK
  4994 000049FF 6642                <1> 	INC	DX			; NEXT DISK ADAPTER REGISTER
  4995 00004A01 6683FF07            <1> 	cmp	di, 7	; 1/1/2015	; ALL DONE?
  4996 00004A05 75EE                <1> 	JNZ	short COMMAND3		; NO--GO DO NEXT ONE
  4997 00004A07 5F                  <1> 	POP	eDI
  4998 00004A08 C3                  <1> 	RETn				; ZERO FLAG IS SET
  4999                              <1> 
  5000                              <1> ;CMD_TIMEOUT:
  5001                              <1> ;	MOV	byte [DISK_STATUS1],BAD_CNTLR
  5002                              <1> ;COMMAND4:
  5003                              <1> ;	POP	BX
  5004                              <1> ;	CMP	[DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  5005                              <1> ;	RETn
  5006                              <1> 
  5007                              <1> ;----------------------------------------
  5008                              <1> ;	WAIT FOR INTERRUPT		:
  5009                              <1> ;----------------------------------------
  5010                              <1> ;WAIT:
  5011                              <1> _WAIT:
  5012 00004A09 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
  5013                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
  5014                              <1> 	;CLC
  5015                              <1> 	;MOV	AX,9000H		; DEVICE WAIT INTERRUPT
  5016                              <1> 	;INT	15H
  5017                              <1> 	;JC	WT2			; DEVICE TIMED OUT
  5018                              <1> 	;MOV	BL,DELAY_1		; SET DELAY COUNT
  5019                              <1> 
  5020                              <1> 	;mov	bl, WAIT_HDU_INT_HI
  5021                              <1> 	;; 21/02/2015
  5022                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
  5023                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
  5024 00004A0A B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
  5025                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
  5026                              <1> ;-----	WAIT LOOP
  5027                              <1> 
  5028                              <1> WT1:	
  5029                              <1> 	;TEST	byte [HF_INT_FLAG],80H	; TEST FOR INTERRUPT
  5030 00004A0F F605[3B590100]C0    <1> 	test 	byte [HF_INT_FLAG],0C0h
  5031                              <1> 	;LOOPZ	WT1
  5032 00004A16 7517                <1> 	JNZ	short WT3		; INTERRUPT--LETS GO
  5033                              <1> 	;DEC	BL
  5034                              <1> 	;JNZ	short WT1		; KEEP TRYING FOR A WHILE
  5035                              <1> 
  5036                              <1> WT1_hi:
  5037 00004A18 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
  5038 00004A1A A810                <1> 	test	al, 10h			; transition on memory
  5039 00004A1C 75FA                <1> 	jnz	short WT1_hi		; refresh.
  5040                              <1> WT1_lo:
  5041 00004A1E E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
  5042 00004A20 A810                <1> 	test	al, 10h			
  5043 00004A22 74FA                <1> 	jz	short WT1_lo
  5044 00004A24 E2E9                <1> 	loop	WT1
  5045                              <1> 	;;or	bl, bl
  5046                              <1> 	;;jz	short WT2	
  5047                              <1> 	;;dec	bl
  5048                              <1> 	;;jmp	short WT1
  5049                              <1> 	;dec	bl
  5050                              <1> 	;jnz	short WT1	
  5051                              <1> 
  5052 00004A26 C605[43590100]80    <1> WT2:	MOV	byte [DISK_STATUS1],TIME_OUT ; REPORT TIME OUT ERROR
  5053 00004A2D EB0E                <1> 	JMP	SHORT WT4
  5054 00004A2F C605[43590100]00    <1> WT3:	MOV	byte [DISK_STATUS1],0
  5055 00004A36 C605[3B590100]00    <1> 	MOV	byte [HF_INT_FLAG],0
  5056 00004A3D 803D[43590100]00    <1> WT4:	CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  5057 00004A44 C3                  <1> 	RETn
  5058                              <1> 
  5059                              <1> ;----------------------------------------
  5060                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
  5061                              <1> ;----------------------------------------
  5062                              <1> NOT_BUSY:
  5063 00004A45 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
  5064                              <1> 	;PUSH	eBX
  5065                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
  5066 00004A46 668B15[185D0000]    <1> 	mov	DX, [HF_PORT]
  5067 00004A4D 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
  5068                              <1> 	;MOV	BL,DELAY_1
  5069                              <1> 					; wait for 10 seconds
  5070                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
  5071                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
  5072                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
  5073 00004A50 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
  5074                              <1> 	;
  5075                              <1> ;;      mov     byte [wait_count], 0    ; Reset wait counter
  5076                              <1> NB1:	
  5077 00004A55 EC                  <1> 	IN	AL,DX			; CHECK STATUS
  5078                              <1> 	;TEST	AL,ST_BUSY
  5079 00004A56 2480                <1> 	and	al, ST_BUSY
  5080                              <1> 	;LOOPNZ	NB1
  5081 00004A58 7410                <1> 	JZ	short NB2		; NOT BUSY--LETS GO
  5082                              <1> 	;DEC	BL			
  5083                              <1> 	;JNZ	short NB1		; KEEP TRYING FOR A WHILE
  5084                              <1> 
  5085 00004A5A E461                <1> NB1_hi: IN	AL,SYS1			; wait for hi to lo
  5086 00004A5C A810                <1> 	TEST	AL,010H			; transition on memory
  5087 00004A5E 75FA                <1> 	JNZ	SHORT NB1_hi		; refresh.
  5088 00004A60 E461                <1> NB1_lo: IN	AL,SYS1
  5089 00004A62 A810                <1> 	TEST	AL,010H
  5090 00004A64 74FA                <1> 	JZ	short NB1_lo
  5091 00004A66 E2ED                <1> 	LOOP	NB1
  5092                              <1> 	;dec	bl
  5093                              <1> 	;jnz	short NB1
  5094                              <1> 	;
  5095                              <1> ;;      cmp     byte [wait_count], 182  ; 10 seconds (182 timer ticks)
  5096                              <1> ;;	jb	short NB1
  5097                              <1> 	;
  5098                              <1> 	;MOV	[DISK_STATUS1],TIME_OUT	; REPORT TIME OUT ERROR
  5099                              <1> 	;JMP	SHORT NB3
  5100 00004A68 B080                <1> 	mov	al, TIME_OUT
  5101                              <1> NB2:	
  5102                              <1> 	;MOV	byte [DISK_STATUS1],0
  5103                              <1> ;NB3:	
  5104                              <1> 	;POP	eBX
  5105 00004A6A A2[43590100]        <1> 	mov	[DISK_STATUS1], al	;;; will be set after return
  5106                              <1> 	;CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
  5107 00004A6F 08C0                <1> 	or	al, al			; (zf = 0 --> timeout)
  5108 00004A71 C3                  <1> 	RETn
  5109                              <1> 
  5110                              <1> ;----------------------------------------
  5111                              <1> ;	WAIT FOR DATA REQUEST		:
  5112                              <1> ;----------------------------------------
  5113                              <1> WAIT_DRQ:
  5114                              <1> 	;MOV	CX,DELAY_3
  5115                              <1> 	;MOV	DX,HF_PORT+7
  5116 00004A72 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  5117 00004A79 80C207              <1> 	add	dl, 7
  5118                              <1> 	;;MOV	bl, WAIT_HDU_DRQ_HI	; 0
  5119                              <1> 	;MOV	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
  5120                              <1> 					; (but it is written as 2000
  5121                              <1> 					; micro seconds in ATORGS.ASM file
  5122                              <1> 					; of Award Bios - 1999, D1A0622)
  5123 00004A7C B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
  5124 00004A81 EC                  <1> WQ_1:	IN	AL,DX			; GET STATUS
  5125 00004A82 A808                <1> 	TEST	AL,ST_DRQ		; WAIT FOR DRQ
  5126 00004A84 7516                <1> 	JNZ	short WQ_OK
  5127                              <1> 	;LOOP	WQ_1			; KEEP TRYING FOR A SHORT WHILE
  5128                              <1> WQ_hi:	
  5129 00004A86 E461                <1> 	IN	AL,SYS1			; wait for hi to lo
  5130 00004A88 A810                <1> 	TEST	AL,010H			; transition on memory
  5131 00004A8A 75FA                <1> 	JNZ	SHORT WQ_hi		; refresh.
  5132 00004A8C E461                <1> WQ_lo:  IN      AL,SYS1
  5133 00004A8E A810                <1> 	TEST	AL,010H
  5134 00004A90 74FA                <1> 	JZ	SHORT WQ_lo
  5135 00004A92 E2ED                <1> 	LOOP	WQ_1
  5136                              <1> 
  5137 00004A94 C605[43590100]80    <1>         MOV     byte [DISK_STATUS1],TIME_OUT ; ERROR
  5138 00004A9B F9                  <1> 	STC
  5139                              <1> WQ_OK:
  5140 00004A9C C3                  <1> 	RETn
  5141                              <1> ;WQ_OK:	;CLC
  5142                              <1> ;	RETn
  5143                              <1> 
  5144                              <1> ;----------------------------------------
  5145                              <1> ;	CHECK FIXED DISK STATUS 	:
  5146                              <1> ;----------------------------------------
  5147                              <1> CHECK_STATUS:
  5148 00004A9D E813000000          <1> 	CALL	CHECK_ST		; CHECK THE STATUS BYTE
  5149 00004AA2 7509                <1> 	JNZ	short CHECK_S1		; AN ERROR WAS FOUND
  5150 00004AA4 A801                <1> 	TEST	AL,ST_ERROR		; WERE THERE ANY OTHER ERRORS
  5151 00004AA6 7405                <1> 	JZ	short CHECK_S1		; NO ERROR REPORTED
  5152 00004AA8 E849000000          <1> 	CALL	CHECK_ER		; ERROR REPORTED
  5153                              <1> CHECK_S1:
  5154 00004AAD 803D[43590100]00    <1> 	CMP	byte [DISK_STATUS1],0 	; SET STATUS FOR CALLER
  5155 00004AB4 C3                  <1> 	RETn
  5156                              <1> 
  5157                              <1> ;----------------------------------------
  5158                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
  5159                              <1> ;----------------------------------------
  5160                              <1> CHECK_ST:
  5161                              <1> 	;MOV	DX,HF_PORT+7		; GET THE STATUS
  5162 00004AB5 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]
  5163 00004ABC 80C207              <1> 	add	dl, 7
  5164                              <1> 	
  5165                              <1> 	; 17/02/2016
  5166                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
  5167                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
  5168 00004ABF EC                  <1> 	IN	AL,DX
  5169                              <1> 	;in	al, dx ; 100ns
  5170                              <1> 	;in	al, dx ; 100ns
  5171                              <1>  	;in	al, dx ; 100ns
  5172                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
  5172 00004AC0 E6EB                <2>  out 0ebh,al
  5173                              <1> 	;
  5174 00004AC2 A2[39590100]        <1> 	MOV	[HF_STATUS],AL
  5175 00004AC7 B400                <1> 	MOV	AH,0
  5176 00004AC9 A880                <1> 	TEST	AL,ST_BUSY		; IF STILL BUSY
  5177 00004ACB 751A                <1> 	JNZ	short CKST_EXIT		;  REPORT OK
  5178 00004ACD B4CC                <1> 	MOV	AH,WRITE_FAULT
  5179 00004ACF A820                <1> 	TEST	AL,ST_WRT_FLT		; CHECK FOR WRITE FAULT
  5180 00004AD1 7514                <1> 	JNZ	short CKST_EXIT
  5181 00004AD3 B4AA                <1> 	MOV	AH,NOT_RDY
  5182 00004AD5 A840                <1> 	TEST	AL,ST_READY		; CHECK FOR NOT READY
  5183 00004AD7 740E                <1> 	JZ	short CKST_EXIT
  5184 00004AD9 B440                <1> 	MOV	AH,BAD_SEEK
  5185 00004ADB A810                <1> 	TEST	AL,ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
  5186 00004ADD 7408                <1> 	JZ	short CKST_EXIT
  5187 00004ADF B411                <1> 	MOV	AH,DATA_CORRECTED
  5188 00004AE1 A804                <1> 	TEST	AL,ST_CORRCTD		; CHECK FOR CORRECTED ECC
  5189 00004AE3 7502                <1> 	JNZ	short CKST_EXIT
  5190 00004AE5 B400                <1> 	MOV	AH,0
  5191                              <1> CKST_EXIT:
  5192 00004AE7 8825[43590100]      <1> 	MOV	[DISK_STATUS1],AH	; SET ERROR FLAG
  5193 00004AED 80FC11              <1> 	CMP	AH,DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
  5194 00004AF0 7403                <1> 	JZ	short CKST_EX1
  5195 00004AF2 80FC00              <1> 	CMP	AH,0
  5196                              <1> CKST_EX1:
  5197 00004AF5 C3                  <1> 	RETn
  5198                              <1> 
  5199                              <1> ;----------------------------------------
  5200                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
  5201                              <1> ;----------------------------------------
  5202                              <1> CHECK_ER:
  5203                              <1> 	;MOV	DX, HF_PORT+1		; GET THE ERROR REGISTER
  5204 00004AF6 668B15[185D0000]    <1> 	mov	dx, [HF_PORT]		;
  5205 00004AFD FEC2                <1> 	inc	dl
  5206 00004AFF EC                  <1> 	IN	AL,DX
  5207 00004B00 A2[3A590100]        <1> 	MOV	[HF_ERROR],AL
  5208 00004B05 53                  <1> 	PUSH	eBX ; 21/02/2015
  5209 00004B06 B908000000          <1> 	MOV	eCX,8			; TEST ALL 8 BITS
  5210 00004B0B D0E0                <1> CK1:	SHL	AL,1			; MOVE NEXT ERROR BIT TO CARRY
  5211 00004B0D 7202                <1> 	JC	short CK2		; FOUND THE ERROR
  5212 00004B0F E2FA                <1> 	LOOP	CK1			; KEEP TRYING
  5213 00004B11 BB[0C5D0000]        <1> CK2:	MOV	eBX, ERR_TBL		; COMPUTE ADDRESS OF
  5214 00004B16 01CB                <1> 	ADD	eBX,eCX			; ERROR CODE
  5215                              <1> 	;;MOV	AH,BYTE [CS:BX]		; GET ERROR CODE
  5216                              <1> 	;mov	ah, [bx]
  5217 00004B18 8A23                <1> 	mov	ah, [ebx] ; 21/02/2015	
  5218 00004B1A 8825[43590100]      <1> CKEX:	MOV	[DISK_STATUS1],AH	; SAVE ERROR CODE
  5219 00004B20 5B                  <1> 	POP	eBX
  5220 00004B21 80FC00              <1> 	CMP	AH,0
  5221 00004B24 C3                  <1> 	RETn
  5222                              <1> 
  5223                              <1> ;--------------------------------------------------------
  5224                              <1> ; CHECK_DMA						:
  5225                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
  5226                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
  5227                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
  5228                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
  5229                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
  5230                              <1> ;  -ERROR OTHERWISE					:
  5231                              <1> ;--------------------------------------------------------
  5232                              <1> CHECK_DMA:
  5233 00004B25 6650                <1> 	PUSH	AX			; SAVE REGISTERS
  5234 00004B27 66B80080            <1> 	MOV	AX,8000H		; AH = MAX # SECTORS AL = MAX OFFSET
  5235 00004B2B F645FE02            <1>         TEST    byte [CMD_BLOCK+6],ECC_MODE
  5236 00004B2F 7404                <1> 	JZ	short CKD1
  5237 00004B31 66B8047F            <1> 	MOV	AX,7F04H		; ECC IS 4 MORE BYTES
  5238 00004B35 3A65F9              <1> CKD1:	CMP	AH, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
  5239 00004B38 7706                <1> 	JA	short CKDOK		; IT WILL FIT
  5240 00004B3A 7208                <1> 	JB	short CKDERR		; TOO MANY
  5241 00004B3C 38D8                <1> 	CMP	AL,BL			; CHECK OFFSET ON MAX SECTORS
  5242 00004B3E 7204                <1> 	JB	short CKDERR		; ERROR
  5243 00004B40 F8                  <1> CKDOK:	CLC				; CLEAR CARRY
  5244 00004B41 6658                <1> 	POP	AX
  5245 00004B43 C3                  <1> 	RETn				; NORMAL RETURN
  5246 00004B44 F9                  <1> CKDERR: STC				; INDICATE ERROR
  5247 00004B45 C605[43590100]09    <1>         MOV     byte [DISK_STATUS1],DMA_BOUNDARY
  5248 00004B4C 6658                <1> 	POP	AX
  5249 00004B4E C3                  <1> 	RETn
  5250                              <1> 
  5251                              <1> ;----------------------------------------
  5252                              <1> ;	SET UP ES:BX-> DISK PARMS	:
  5253                              <1> ;----------------------------------------
  5254                              <1> 					
  5255                              <1> ; INPUT -> DL = 0 based drive number
  5256                              <1> ; OUTPUT -> ES:BX = disk parameter table address
  5257                              <1> 
  5258                              <1> GET_VEC:
  5259                              <1> 	;SUB	AX,AX			; GET DISK PARAMETER ADDRESS
  5260                              <1> 	;MOV	ES,AX
  5261                              <1> 	;TEST	DL,1
  5262                              <1> 	;JZ	short GV_0
  5263                              <1> ;	LES	BX,[HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
  5264                              <1> ;	JMP	SHORT GV_EXIT
  5265                              <1> ;GV_0:
  5266                              <1> ;	LES	BX,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
  5267                              <1> ;
  5268                              <1> 	;xor	bh, bh
  5269 00004B4F 31DB                <1> 	xor	ebx, ebx
  5270 00004B51 88D3                <1> 	mov	bl, dl
  5271                              <1> 	;;02/01/2015
  5272                              <1> 	;;shl	bl, 1			; port address offset
  5273                              <1> 	;;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
  5274                              <1> 	;;shl	bl, 1			; dpt pointer offset
  5275 00004B53 C0E302              <1> 	shl	bl, 2	;;
  5276                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
  5277 00004B56 81C3[48590100]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
  5278                              <1> 	;push	word [bx+2]		; dpt segment
  5279                              <1> 	;pop	es
  5280                              <1> 	;mov	bx, [bx]		; dpt offset
  5281 00004B5C 8B1B                <1> 	mov	ebx, [ebx]		
  5282                              <1> ;GV_EXIT:
  5283 00004B5E C3                  <1> 	RETn
  5284                              <1> 
  5285                              <1> hdc1_int: ; 21/02/2015
  5286                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL  14 ) ----------------------
  5287                              <1> ;								:
  5288                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  5289                              <1> ;								:
  5290                              <1> ;----------------------------------------------------------------
  5291                              <1> 
  5292                              <1> ; 22/12/2014
  5293                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
  5294                              <1> ;	 '11/15/85'
  5295                              <1> ; AWARD BIOS 1999 (D1A0622) 
  5296                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
  5297                              <1> 
  5298                              <1> ;int_76h:
  5299                              <1> HD_INT:
  5300 00004B5F 6650                <1> 	PUSH	AX
  5301 00004B61 1E                  <1> 	PUSH	DS
  5302                              <1> 	;CALL	DDS
  5303                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  5304 00004B62 66B81000            <1> 	mov	ax, KDATA
  5305 00004B66 8ED8                <1> 	mov 	ds, ax
  5306                              <1> 	;
  5307                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
  5308                              <1>         ;mov     byte [CS:HF_INT_FLAG], 0FFh
  5309 00004B68 C605[3B590100]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
  5310                              <1> 	;
  5311 00004B6F 6652                <1> 	push	dx
  5312 00004B71 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
  5313                              <1> 					; Clear Controller
  5314                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
  5315 00004B75 EC                  <1> 	in	al, dx			;
  5316 00004B76 665A                <1> 	pop	dx
  5317                              <1> 	NEWIODELAY
  5317 00004B78 E6EB                <2>  out 0ebh,al
  5318                              <1> 	;
  5319 00004B7A B020                <1> 	MOV	AL,EOI			; NON-SPECIFIC END OF INTERRUPT
  5320 00004B7C E6A0                <1> 	OUT	INTB00,AL		; FOR CONTROLLER #2
  5321                              <1> 	;JMP	$+2			; WAIT
  5322                              <1> 	NEWIODELAY
  5322 00004B7E E6EB                <2>  out 0ebh,al
  5323 00004B80 E620                <1> 	OUT	INTA00,AL		; FOR CONTROLLER #1
  5324 00004B82 1F                  <1> 	POP	DS
  5325                              <1> 	;STI				; RE-ENABLE INTERRUPTS
  5326                              <1> 	;MOV	AX,9100H		; DEVICE POST
  5327                              <1> 	;INT	15H			;  INTERRUPT
  5328                              <1> irq15_iret: ; 25/02/2015
  5329 00004B83 6658                <1> 	POP	AX
  5330 00004B85 CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
  5331                              <1> 
  5332                              <1> hdc2_int: ; 21/02/2015
  5333                              <1> ;++++ HARDWARE INT 77H ++ ( IRQ LEVEL  15 ) +++++++++++++++++++++
  5334                              <1> ;								:
  5335                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  5336                              <1> ;								:
  5337                              <1> ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5338                              <1> 
  5339                              <1> ;int_77h:
  5340                              <1> HD1_INT:
  5341 00004B86 6650                <1> 	PUSH	AX
  5342                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
  5343                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  5344 00004B88 B00B                <1> 	mov	al, 0Bh  ; In-Service Register
  5345 00004B8A E6A0                <1> 	out	0A0h, al
  5346 00004B8C EB00                <1>         jmp short $+2
  5347 00004B8E EB00                <1> 	jmp short $+2
  5348 00004B90 E4A0                <1> 	in	al, 0A0h
  5349 00004B92 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
  5350 00004B94 74ED                <1> 	jz	short irq15_iret ; Fake (spurious)IRQ, do not send EOI)
  5351                              <1> 	;
  5352 00004B96 1E                  <1> 	PUSH	DS
  5353                              <1> 	;CALL	DDS
  5354                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  5355 00004B97 66B81000            <1> 	mov	ax, KDATA
  5356 00004B9B 8ED8                <1> 	mov 	ds, ax
  5357                              <1> 	;
  5358                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
  5359                              <1>         ;or      byte [CS:HF_INT_FLAG],0C0h 
  5360 00004B9D 800D[3B590100]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
  5361                              <1> 	;
  5362 00004BA4 6652                <1> 	push	dx
  5363 00004BA6 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
  5364                              <1> 					; Clear Controller (Award BIOS 1999)
  5365 00004BAA EBC9                <1> 	jmp	short Clear_IRQ1415
  5366                              <1> 
  5367                              <1> 
  5368                              <1> ;%include 'diskdata.inc' ; 11/03/2015
  5369                              <1> ;%include 'diskbss.inc' ; 11/03/2015
  5370                              <1> 
  5371                              <1> 
  5372                              <1> ;////////////////////////////////////////////////////////////////////
  5373                              <1> ;; END OF DISK I/O SYTEM ///
  2159                                  %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: 22/07/2017
     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 4 ;15/10/2016 (1->4); insufficient (out of) memory
    46                              <1> ERR_MINOR_PV	equ 6 ;15/10/2016 (1->4); protection violation
    47                              <1> SWP_DISK_READ_ERR 	   equ 40
    48                              <1> SWP_DISK_NOT_PRESENT_ERR   equ 41
    49                              <1> SWP_SECTOR_NOT_PRESENT_ERR equ 42
    50                              <1> SWP_NO_FREE_SPACE_ERR      equ 43
    51                              <1> SWP_DISK_WRITE_ERR         equ 44
    52                              <1> SWP_NO_PAGE_TO_SWAP_ERR    equ 45
    53                              <1> PTE_A_ACCESS_BIT equ 5  ; Bit 5 (accessed flag)        
    54                              <1> SECTOR_SHIFT     equ 3  ; sector shift (to convert page block number)
    55                              <1> ; 12/07/2016
    56                              <1> PTE_SHARED	 equ 400h		; AVL bit 1, direct memory access bit	
    57                              <1> 					; (Indicates that the page is not allocated
    58                              <1> 					; for the process, it is a shared or system
    59                              <1>                                         ; page, it must not be deallocated!)
    60                              <1> ;
    61                              <1> ;; Retro Unix 386 v1 - paging method/principles
    62                              <1> ;;
    63                              <1> ;; 10/10/2014
    64                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
    65                              <1> ;;
    66                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
    67                              <1> ;;	(virtual address = physical address)
    68                              <1> ;; KERNEL PAGE TABLES:
    69                              <1> ;;	Kernel page directory and all page tables are
    70                              <1> ;;	on memory as initialized, as equal to physical memory
    71                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
    72                              <1> ;;
    73                              <1> ;;	what for: User pages may be swapped out, when accessing
    74                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
    75                              <1> ;;	kernel would have to swap it in! But it is also may be
    76                              <1> ;;	in use by a user process. (In system/kernel mode
    77                              <1> ;;	kernel can access all memory pages even if they are
    78                              <1> ;;	reserved/allocated for user processes. Swap out/in would
    79                              <1> ;;	cause conflicts.) 
    80                              <1> ;;	
    81                              <1> ;;	As result of these conditions,
    82                              <1> ;;	all kernel pages must be initialized as equal to 
    83                              <1> ;;	physical layout for preventing page faults. 
    84                              <1> ;;	Also, calling "allocate page" procedure after
    85                              <1> ;;	a page fault can cause another page fault (double fault)
    86                              <1> ;;	if all kernel page tables would not be initialized.
    87                              <1> ;;
    88                              <1> ;;	[first_page] = Beginning of users space, as offset to 
    89                              <1> ;;	memory allocation table. (double word aligned)
    90                              <1> ;;
    91                              <1> ;;	[next_page] = first/next free space to be searched
    92                              <1> ;;	as offset to memory allocation table. (dw aligned)
    93                              <1> ;;
    94                              <1> ;;	[last_page] = End of memory (users space), as offset
    95                              <1> ;;	to memory allocation table. (double word aligned)
    96                              <1> ;;
    97                              <1> ;; USER PAGE TABLES:
    98                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
    99                              <1> ;;		'ready only' marked copies of the 
   100                              <1> ;;		parent process's page table entries (for
   101                              <1> ;;		same physical memory).
   102                              <1> ;;		(A page will be copied to a new page after
   103                              <1> ;;		 if it causes R/W page fault.)
   104                              <1> ;;
   105                              <1> ;;	Every user process has own (different)
   106                              <1> ;;	page directory and page tables.	
   107                              <1> ;;
   108                              <1> ;;	Code starts at virtual address 0, always.
   109                              <1> ;;	(Initial value of EIP is 0 in user mode.)
   110                              <1> ;;	(Programs can be written/developed as simple
   111                              <1> ;;	 flat memory programs.)
   112                              <1> ;;
   113                              <1> ;; MEMORY ALLOCATION STRATEGY:
   114                              <1> ;;	Memory page will be allocated by kernel only 
   115                              <1> ;;		(in kernel/system mode only).
   116                              <1> ;;	* After a
   117                              <1> ;;	  - 'not present' page fault
   118                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
   119                              <1> ;;	* For loading (opening, reading) a file or disk/drive
   120                              <1> ;;	* As responce to 'allocate additional memory blocks' 
   121                              <1> ;;	  request by running process.
   122                              <1> ;;	* While creating a process, allocating a new buffer,
   123                              <1> ;;	  new page tables etc.
   124                              <1> ;;
   125                              <1> ;;	At first,
   126                              <1> ;;	- 'allocate page' procedure will be called;
   127                              <1> ;,	   if it will return with a valid (>0) physical address
   128                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
   129                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
   130                              <1> ;;	- 'allocate page' will be called for allocating page
   131                              <1> ;;	   directory, page table and running space (data/code).
   132                              <1> ;;	- every successful 'allocate page' call will decrease
   133                              <1> ;;	  'free_pages' count (pointer).
   134                              <1> ;;	- 'out of (insufficient) memory error' will be returned
   135                              <1> ;;	  if 'free_pages' points to a ZERO.
   136                              <1> ;;	- swapping out and swapping in (if it is not a new page)
   137                              <1> ;;	  procedures will be called as responce to 'out of memory'
   138                              <1> ;;	  error except errors caused by attribute conflicts.
   139                              <1> ;;	 (swapper functions)	 
   140                              <1> ;;					
   141                              <1> ;;	At second,
   142                              <1> ;;	- page directory entry will be updated then page table
   143                              <1> ;;	  entry will be updated.		
   144                              <1> ;;
   145                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
   146                              <1> ;;	- M.A.T. has a size according to available memory as
   147                              <1> ;;	  follows:
   148                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
   149                              <1> ;;		  - a bit with value of 0 means allocated page
   150                              <1> ;;		  - a bit with value of 1 means a free page
   151                              <1> ;,	- 'free_pages' pointer holds count of free pages
   152                              <1> ;;	  depending on M.A.T.
   153                              <1> ;;		(NOTE: Free page count will not be checked
   154                              <1> ;;		again -on M.A.T.- after initialization. 
   155                              <1> ;;		Kernel will trust on initial count.)
   156                              <1> ;,	- 'free_pages' count will be decreased by allocation
   157                              <1> ;;	  and it will be increased by deallocation procedures.
   158                              <1> ;;	
   159                              <1> ;;	- Available memory will be calculated during
   160                              <1> ;;	  the kernel's initialization stage (in real mode).
   161                              <1> ;;	  Memory allocation table and kernel page tables 
   162                              <1> ;;	  will be formatted/sized as result of available
   163                              <1> ;;	  memory calculation before paging is enabled.
   164                              <1> ;;
   165                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
   166                              <1> ;;	- Memory Allocation Table size will be 128 KB.
   167                              <1> ;;	- Memory allocation for kernel page directory size 
   168                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   169                              <1> ;;	  for page tables)
   170                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
   171                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
   172                              <1> ;;	- User (available) space will be started 
   173                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
   174                              <1> ;;	- The first 640 KB is for kernel's itself plus
   175                              <1> ;;	  memory allocation table and kernel's page directory
   176                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   177                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   178                              <1> ;; 	  for buffers.
   179                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   180                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   181                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
   182                              <1> ;;
   183                              <1> ;; For 1GB Available Memory:
   184                              <1> ;;	- Memory Allocation Table size will be 32 KB.
   185                              <1> ;;	- Memory allocation for kernel page directory size 
   186                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   187                              <1> ;;	  for page tables)
   188                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
   189                              <1> ;;	  is 1 MB (256*4*1024 bytes).
   190                              <1> ;;	- User (available) space will be started 
   191                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
   192                              <1> ;;	- The first 640 KB is for kernel's itself plus
   193                              <1> ;;	  memory allocation table and kernel's page directory
   194                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   195                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   196                              <1> ;; 	  for buffers.
   197                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   198                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   199                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
   200                              <1> ;;
   201                              <1> ;;
   202                              <1> 
   203                              <1> 
   204                              <1> ;;************************************************************************************
   205                              <1> ;; 
   206                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
   207                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
   208                              <1> 
   209                              <1> ;; Main factor: "sys fork" system call 
   210                              <1> ;;	
   211                              <1> ;; 		FORK
   212                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
   213                              <1> ;;  writable pages ---->|
   214                              <1> ;;                      |----> child - duplicated PTEs, read only pages
   215                              <1> ;; 
   216                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
   217                              <1> ;; 
   218                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
   219                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
   220                              <1> ;;       -while R/W bit is 0-. 
   221                              <1> ;; 
   222                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
   223                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
   224                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
   225                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
   226                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
   227                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
   228                              <1> ;; 
   229                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
   230                              <1> ;; # Parent's read only pages are copied to new child pages. 
   231                              <1> ;;   Parent's PTE attributes are not changed.
   232                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
   233                              <1> ;;    destroy/mix previous fork result).
   234                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
   235                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
   236                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
   237                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
   238                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
   239                              <1> ;;   as Child's Page Table Entries without copying actual page.
   240                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
   241                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
   242                              <1> ;; 
   243                              <1> ;; !? WHAT FOR (duplication after duplication):
   244                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
   245                              <1> ;; program/executable code continues from specified location as child process, 
   246                              <1> ;; returns back previous code location as parent process, every child after 
   247                              <1> ;; every sys fork uses last image of code and data just prior the fork.
   248                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
   249                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
   250                              <1> ;; was copied to child's process segment (all of code and data) according to
   251                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
   252                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
   253                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
   254                              <1> ;; (complete running image of parent process) to the child process; 
   255                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
   256                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
   257                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
   258                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
   259                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
   260                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
   261                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
   262                              <1> ;; new/fresh pages will be used to load and run new executable/program.
   263                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
   264                              <1> ;; for sharing same read only pages between parent and child processes.
   265                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
   266                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
   267                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
   268                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
   269                              <1> ;; -deallocation problem-.
   270                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
   271                              <1> ;; 
   272                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   273                              <1> ;; # Page fault handler will do those:
   274                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   275                              <1> ;;   - If it is reset/clear, there is a child uses same page.
   276                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
   277                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
   278                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
   279                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
   280                              <1> ;;     read only page will be converted to writable and unique page which belongs
   281                              <1> ;;     to child process.)	
   282                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   283                              <1> ;; # Page fault handler will do those:
   284                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   285                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
   286                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
   287                              <1> ;;     address or not. 
   288                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
   289                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
   290                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
   291                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
   292                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
   293                              <1> ;; 
   294                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
   295                              <1> ;;       will be set as writable (and unique) in case of child process was using 
   296                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
   297                              <1> ;;       duplication method details, it is not possible multiple child processes
   298                              <1> ;;       were using same page with duplicated PTEs.
   299                              <1> ;; 
   300                              <1> ;;************************************************************************************   
   301                              <1> 
   302                              <1> ;; 08/10/2014
   303                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
   304                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
   305                              <1> 
   306                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
   307                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
   308                              <1> ;; (25/08/2014, Revision: 5057) file 
   309                              <1> ;; by KolibriOS Team (2004-2012)
   310                              <1> 
   311                              <1> allocate_page:
   312                              <1> 	; 01/07/2015
   313                              <1> 	; 05/05/2015
   314                              <1> 	; 30/04/2015
   315                              <1> 	; 16/10/2014
   316                              <1> 	; 08/10/2014
   317                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
   318                              <1> 	;
   319                              <1> 	; INPUT -> none
   320                              <1> 	;
   321                              <1> 	; OUTPUT ->
   322                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   323                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
   324                              <1> 	;
   325                              <1> 	;	CF = 1 and EAX = 0 
   326                              <1> 	; 		   if there is not a free page to be allocated	
   327                              <1> 	;
   328                              <1> 	; Modified Registers -> none (except EAX)
   329                              <1> 	;
   330 00004BAC A1[B0580100]        <1> 	mov	eax, [free_pages]
   331 00004BB1 21C0                <1> 	and	eax, eax
   332 00004BB3 7438                <1> 	jz	short out_of_memory
   333                              <1> 	;
   334 00004BB5 53                  <1> 	push	ebx
   335 00004BB6 51                  <1> 	push	ecx
   336                              <1> 	;
   337 00004BB7 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
   338 00004BBC 89D9                <1> 	mov	ecx, ebx
   339                              <1>  				     ; NOTE: 32 (first_page) is initial
   340                              <1> 				     ; value of [next_page].
   341                              <1> 				     ; It points to the first available
   342                              <1> 				     ; page block for users (ring 3) ...	
   343                              <1> 				     ; (MAT offset 32 = 1024/32)	
   344                              <1> 				     ; (at the of the first 4 MB)		
   345 00004BBE 031D[B4580100]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
   346                              <1> 				 ; next_free_page >> 5
   347 00004BC4 030D[B8580100]      <1> 	add	ecx, [last_page] ; Free page searching ends here
   348                              <1> 				 ; (total_pages - 1) >> 5
   349                              <1> al_p_scan:
   350 00004BCA 39CB                <1> 	cmp	ebx, ecx
   351 00004BCC 770A                <1> 	ja	short al_p_notfound
   352                              <1> 	;
   353                              <1> 	; 01/07/2015
   354                              <1> 	; AMD64 Architecture Programmers Manual
   355                              <1> 	; Volume 3:
   356                              <1> 	; General-Purpose and System Instructions
   357                              <1> 	;
   358                              <1> 	; BSF - Bit Scan Forward
   359                              <1> 	;
   360                              <1> 	;   Searches the value in a register or a memory location
   361                              <1> 	;   (second operand) for the least-significant set bit. 
   362                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
   363                              <1> 	;   and stores the index of the least-significant set bit in a destination
   364                              <1> 	;   register (first operand). If the second operand contains 0, 
   365                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
   366                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
   367                              <1> 	;   of the searched value
   368                              <1> 	;
   369 00004BCE 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
   370                              <1> 			   ; Clear ZF if a bit is found set (1) and 
   371                              <1> 			   ; loads the destination with an index to
   372                              <1> 			   ; first set bit. (0 -> 31) 
   373                              <1> 			   ; Sets ZF to 1 if no bits are found set.
   374 00004BD1 7525                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
   375                              <1> 			 ;
   376                              <1> 			 ; NOTE:  a Memory Allocation Table bit 
   377                              <1> 			 ;	  with value of 1 means 
   378                              <1> 			 ;	  the corresponding page is free 
   379                              <1> 			 ;	  (Retro UNIX 386 v1 feature only!)
   380 00004BD3 83C304              <1> 	add	ebx, 4
   381                              <1> 			 ; We return back for searching next page block
   382                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
   383                              <1> 			 ;	 we always will find at least 1 free page here.
   384 00004BD6 EBF2                <1>         jmp     short al_p_scan
   385                              <1> 	;
   386                              <1> al_p_notfound:
   387 00004BD8 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   388 00004BDE 890D[B4580100]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
   389                              <1> 				 ; (deallocate_page procedure will change it)
   390 00004BE4 31C0                <1> 	xor	eax, eax
   391 00004BE6 A3[B0580100]        <1> 	mov	[free_pages], eax ; 0
   392 00004BEB 59                  <1> 	pop	ecx
   393 00004BEC 5B                  <1> 	pop	ebx
   394                              <1> 	;
   395                              <1> out_of_memory:
   396 00004BED E85B040000          <1> 	call	swap_out
   397 00004BF2 7325                <1> 	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
   398                              <1> 	;
   399 00004BF4 29C0                <1> 	sub 	eax, eax ; 0
   400 00004BF6 F9                  <1> 	stc
   401 00004BF7 C3                  <1> 	retn
   402                              <1> 
   403                              <1> al_p_found:
   404 00004BF8 89D9                <1> 	mov	ecx, ebx
   405 00004BFA 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   406 00004C00 890D[B4580100]      <1> 	mov	[next_page], ecx ; Set first free page searching start
   407                              <1> 				 ; address/offset (to the next)
   408 00004C06 FF0D[B0580100]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
   409                              <1> 	;
   410 00004C0C 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
   411                              <1> 				 ; is copied into the Carry Flag and then cleared
   412                              <1> 				 ; in the destination.
   413                              <1> 				 ;
   414                              <1> 				 ; Reset the bit which is corresponding to the 
   415                              <1> 				 ; (just) allocated page.
   416                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
   417 00004C0F C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
   418 00004C12 01C8                <1> 	add	eax, ecx	 ; = page number
   419 00004C14 C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
   420                              <1> 	; EAX = physical address of memory page
   421                              <1> 	;
   422                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
   423                              <1> 	;       according to this EAX value...
   424 00004C17 59                  <1> 	pop	ecx
   425 00004C18 5B                  <1> 	pop	ebx
   426                              <1> al_p_ok:
   427 00004C19 C3                  <1> 	retn
   428                              <1> 
   429                              <1> 
   430                              <1> make_page_dir:
   431                              <1> 	; 18/04/2015
   432                              <1> 	; 12/04/2015
   433                              <1> 	; 23/10/2014
   434                              <1> 	; 16/10/2014
   435                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   436                              <1> 	;
   437                              <1> 	; INPUT ->
   438                              <1> 	;	none
   439                              <1> 	; OUTPUT ->
   440                              <1> 	;	(EAX = 0)
   441                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   442                              <1> 	;	cf = 0 ->
   443                              <1> 	;	u.pgdir = page directory (physical) address of the current
   444                              <1> 	;		  process/user.
   445                              <1> 	;
   446                              <1> 	; Modified Registers -> EAX
   447                              <1> 	;
   448 00004C1A E88DFFFFFF          <1> 	call	allocate_page
   449 00004C1F 7216                <1> 	jc	short mkpd_error
   450                              <1> 	;
   451 00004C21 A3[B8030300]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
   452                              <1> 				  ; (Physical address)
   453                              <1> clear_page:
   454                              <1> 	; 18/04/2015
   455                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   456                              <1> 	;
   457                              <1> 	; INPUT ->
   458                              <1> 	;	EAX = physical address of the page
   459                              <1> 	; OUTPUT ->
   460                              <1> 	;	all bytes of the page will be cleared
   461                              <1> 	;
   462                              <1> 	; Modified Registers -> none
   463                              <1> 	;
   464 00004C26 57                  <1> 	push	edi
   465 00004C27 51                  <1> 	push	ecx
   466 00004C28 50                  <1> 	push	eax
   467 00004C29 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
   468 00004C2E 89C7                <1> 	mov	edi, eax
   469 00004C30 31C0                <1> 	xor	eax, eax
   470 00004C32 F3AB                <1> 	rep	stosd
   471 00004C34 58                  <1> 	pop	eax
   472 00004C35 59                  <1> 	pop	ecx
   473 00004C36 5F                  <1> 	pop	edi
   474                              <1> mkpd_error:
   475                              <1> mkpt_error:
   476 00004C37 C3                  <1> 	retn
   477                              <1> 
   478                              <1> make_page_table:
   479                              <1> 	; 23/06/2015
   480                              <1> 	; 18/04/2015
   481                              <1> 	; 12/04/2015
   482                              <1> 	; 16/10/2014
   483                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   484                              <1> 	;
   485                              <1> 	; INPUT ->
   486                              <1> 	;	EBX = virtual (linear) address
   487                              <1> 	;	ECX = page table attributes (lower 12 bits)
   488                              <1> 	;	      (higher 20 bits must be ZERO)
   489                              <1> 	;	      (bit 0 must be 1)	 
   490                              <1> 	;	u.pgdir = page directory (physical) address
   491                              <1> 	; OUTPUT ->
   492                              <1> 	;	EDX = Page directory entry address
   493                              <1> 	;	EAX = Page table address
   494                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   495                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
   496                              <1> 	;
   497                              <1> 	; Modified Registers -> EAX, EDX
   498                              <1> 	;
   499 00004C38 E86FFFFFFF          <1> 	call	allocate_page
   500 00004C3D 72F8                <1> 	jc	short mkpt_error
   501 00004C3F E811000000          <1> 	call	set_pde	
   502 00004C44 EBE0                <1> 	jmp	short clear_page
   503                              <1> 
   504                              <1> make_page:
   505                              <1> 	; 24/07/2015
   506                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
   507                              <1> 	;
   508                              <1> 	; INPUT ->
   509                              <1> 	;	EBX = virtual (linear) address
   510                              <1> 	;	ECX = page attributes (lower 12 bits)
   511                              <1> 	;	      (higher 20 bits must be ZERO)
   512                              <1> 	;	      (bit 0 must be 1)	 
   513                              <1> 	;	u.pgdir = page directory (physical) address
   514                              <1> 	; OUTPUT ->
   515                              <1> 	;	EBX = Virtual address
   516                              <1> 	;	(EDX = PTE value)
   517                              <1> 	;	EAX = Physical address
   518                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   519                              <1> 	;
   520                              <1> 	; Modified Registers -> EAX, EDX
   521                              <1> 	;
   522 00004C46 E861FFFFFF          <1> 	call	allocate_page
   523 00004C4B 7207                <1> 	jc	short mkp_err
   524 00004C4D E821000000          <1> 	call	set_pte	
   525 00004C52 73D2                <1> 	jnc	short clear_page ; 18/04/2015
   526                              <1> mkp_err:
   527 00004C54 C3                  <1> 	retn
   528                              <1> 
   529                              <1> 
   530                              <1> set_pde:	; Set page directory entry (PDE)
   531                              <1> 	; 20/07/2015
   532                              <1> 	; 18/04/2015
   533                              <1> 	; 12/04/2015
   534                              <1> 	; 23/10/2014
   535                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   536                              <1> 	;
   537                              <1> 	; INPUT ->
   538                              <1> 	;	EAX = physical address
   539                              <1> 	;	      (use present value if EAX = 0)
   540                              <1> 	;	EBX = virtual (linear) address
   541                              <1> 	;	ECX = page table attributes (lower 12 bits)
   542                              <1> 	;	      (higher 20 bits must be ZERO)
   543                              <1> 	;	      (bit 0 must be 1)	 
   544                              <1> 	;	u.pgdir = page directory (physical) address
   545                              <1> 	; OUTPUT ->
   546                              <1> 	;	EDX = PDE address
   547                              <1> 	;	EAX = page table address (physical)
   548                              <1> 	;	;(CF=1 -> Invalid page address)
   549                              <1> 	;
   550                              <1> 	; Modified Registers -> EDX
   551                              <1> 	;
   552 00004C55 89DA                <1> 	mov	edx, ebx
   553 00004C57 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
   554 00004C5A C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
   555 00004C5D 0315[B8030300]      <1> 	add	edx, [u.pgdir]
   556                              <1> 	;
   557 00004C63 21C0                <1> 	and	eax, eax
   558 00004C65 7506                <1> 	jnz	short spde_1
   559                              <1> 	;
   560 00004C67 8B02                <1> 	mov	eax, [edx]  ; old PDE value
   561                              <1> 	;test	al, 1
   562                              <1> 	;jz	short spde_2
   563 00004C69 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
   564                              <1> spde_1:
   565                              <1> 	;and	cx, 0FFFh
   566 00004C6D 8902                <1> 	mov	[edx], eax
   567 00004C6F 66090A              <1> 	or	[edx], cx
   568 00004C72 C3                  <1> 	retn
   569                              <1> ;spde_2: ; error
   570                              <1> ;	stc
   571                              <1> ;	retn
   572                              <1> 
   573                              <1> set_pte:	; Set page table entry (PTE)
   574                              <1> 	; 24/07/2015
   575                              <1> 	; 20/07/2015
   576                              <1> 	; 23/06/2015
   577                              <1> 	; 18/04/2015
   578                              <1> 	; 12/04/2015
   579                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   580                              <1> 	;
   581                              <1> 	; INPUT ->
   582                              <1> 	;	EAX = physical page address
   583                              <1> 	;	      (use present value if EAX = 0)
   584                              <1> 	;	EBX = virtual (linear) address
   585                              <1> 	;	ECX = page attributes (lower 12 bits)
   586                              <1> 	;	      (higher 20 bits must be ZERO)
   587                              <1> 	;	      (bit 0 must be 1)	 
   588                              <1> 	;	u.pgdir = page directory (physical) address
   589                              <1> 	; OUTPUT ->
   590                              <1> 	;	EAX = physical page address
   591                              <1> 	;	(EDX = PTE value)
   592                              <1> 	;	EBX = virtual address
   593                              <1> 	;
   594                              <1> 	;	CF = 1 -> error
   595                              <1> 	;
   596                              <1> 	; Modified Registers -> EAX, EDX
   597                              <1> 	;
   598 00004C73 50                  <1> 	push	eax
   599 00004C74 A1[B8030300]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
   600 00004C79 E837000000          <1> 	call 	get_pde
   601                              <1> 		; EDX = PDE address
   602                              <1> 		; EAX = PDE value
   603 00004C7E 5A                  <1> 	pop	edx ; physical page address
   604 00004C7F 722A                <1> 	jc	short spte_err ; PDE not present
   605                              <1> 	;
   606 00004C81 53                  <1> 	push	ebx ; 24/07/2015
   607 00004C82 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   608                              <1> 			    ; EDX = PT address (physical)	
   609 00004C86 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
   610 00004C89 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
   611                              <1> 			 ; clear higher 10 bits (PD bits)
   612 00004C8F C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
   613 00004C92 01C3                <1> 	add	ebx, eax
   614                              <1> 	;
   615 00004C94 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
   616 00004C96 A801                <1> 	test	al, 1
   617 00004C98 740C                <1> 	jz	short spte_0
   618 00004C9A 09D2                <1> 	or	edx, edx
   619 00004C9C 750F                <1> 	jnz	short spte_1
   620 00004C9E 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
   621 00004CA2 89C2                <1> 	mov	edx, eax
   622 00004CA4 EB09                <1> 	jmp	short spte_2	
   623                              <1> spte_0:
   624                              <1> 	; If this PTE contains a swap (disk) address,
   625                              <1> 	; it can be updated by using 'swap_in' procedure
   626                              <1> 	; only!
   627 00004CA6 21C0                <1> 	and	eax, eax
   628 00004CA8 7403                <1> 	jz	short spte_1
   629                              <1> 	; 24/07/2015
   630                              <1> 	; swapped page ! (on disk)
   631 00004CAA 5B                  <1> 	pop	ebx
   632                              <1> spte_err:
   633 00004CAB F9                  <1> 	stc
   634 00004CAC C3                  <1> 	retn
   635                              <1> spte_1: 
   636 00004CAD 89D0                <1> 	mov	eax, edx
   637                              <1> spte_2:
   638 00004CAF 09CA                <1> 	or	edx, ecx
   639                              <1> 	; 23/06/2015
   640 00004CB1 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
   641                              <1> 	; 24/07/2015
   642 00004CB3 5B                  <1> 	pop	ebx
   643 00004CB4 C3                  <1> 	retn
   644                              <1> 
   645                              <1> get_pde:	; Get present value of the relevant PDE
   646                              <1> 	; 20/07/2015
   647                              <1> 	; 18/04/2015
   648                              <1> 	; 12/04/2015
   649                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   650                              <1> 	;
   651                              <1> 	; INPUT ->
   652                              <1> 	;	EBX = virtual (linear) address
   653                              <1> 	;	EAX = page directory (physical) address
   654                              <1> 	; OUTPUT ->
   655                              <1> 	;	EDX = Page directory entry address
   656                              <1> 	;	EAX = Page directory entry value
   657                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   658                              <1> 	; Modified Registers -> EDX, EAX
   659                              <1> 	;
   660 00004CB5 89DA                <1> 	mov	edx, ebx
   661 00004CB7 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
   662 00004CBA C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
   663 00004CBD 01C2                <1> 	add	edx, eax ; page directory address (physical)
   664 00004CBF 8B02                <1> 	mov	eax, [edx]
   665 00004CC1 A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
   666 00004CC3 751F                <1> 	jnz	short gpte_retn
   667 00004CC5 F9                  <1> 	stc
   668                              <1> gpde_retn:	
   669 00004CC6 C3                  <1> 	retn
   670                              <1> 
   671                              <1> get_pte:
   672                              <1> 		; Get present value of the relevant PTE
   673                              <1> 	; 29/07/2015
   674                              <1> 	; 20/07/2015
   675                              <1> 	; 18/04/2015
   676                              <1> 	; 12/04/2015
   677                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   678                              <1> 	;
   679                              <1> 	; INPUT ->
   680                              <1> 	;	EBX = virtual (linear) address
   681                              <1> 	;	EAX = page directory (physical) address
   682                              <1> 	; OUTPUT ->
   683                              <1> 	;	EDX = Page table entry address (if CF=0)
   684                              <1> 	;	      Page directory entry address (if CF=1)
   685                              <1> 	;            (Bit 0 value is 0 if PT is not present)
   686                              <1> 	;	EAX = Page table entry value (page address)
   687                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   688                              <1> 	; Modified Registers -> EAX, EDX
   689                              <1> 	;
   690 00004CC7 E8E9FFFFFF          <1> 	call 	get_pde
   691 00004CCC 72F8                <1> 	jc	short gpde_retn	; page table is not present
   692                              <1> 	;jnc	short gpte_1
   693                              <1> 	;retn
   694                              <1> ;gpte_1:
   695 00004CCE 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   696 00004CD2 89DA                <1> 	mov	edx, ebx
   697 00004CD4 C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
   698 00004CD7 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
   699                              <1> 			 ; clear higher 10 bits (PD bits)
   700 00004CDD C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
   701 00004CE0 01C2                <1> 	add	edx, eax
   702 00004CE2 8B02                <1> 	mov	eax, [edx]
   703                              <1> gpte_retn:
   704 00004CE4 C3                  <1> 	retn
   705                              <1> 
   706                              <1> deallocate_page_dir:
   707                              <1> 	; 15/09/2015
   708                              <1> 	; 05/08/2015
   709                              <1> 	; 30/04/2015
   710                              <1> 	; 28/04/2015
   711                              <1> 	; 17/10/2014
   712                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   713                              <1> 	;
   714                              <1> 	; INPUT ->
   715                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
   716                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   717                              <1> 	; OUTPUT ->
   718                              <1> 	;	All of page tables in the page directory
   719                              <1> 	;	and page dir's itself will be deallocated
   720                              <1> 	;	except 'read only' duplicated pages (will be converted
   721                              <1> 	;	to writable pages).
   722                              <1> 	;
   723                              <1> 	; Modified Registers -> EAX
   724                              <1> 	;
   725                              <1> 	;
   726 00004CE5 56                  <1> 	push	esi
   727 00004CE6 51                  <1> 	push	ecx
   728 00004CE7 50                  <1> 	push	eax
   729 00004CE8 89C6                <1> 	mov	esi, eax 
   730 00004CEA 31C9                <1> 	xor	ecx, ecx
   731                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
   732                              <1> 	; it must not be deallocated
   733 00004CEC 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
   734                              <1> dapd_0:
   735 00004CEE AD                  <1> 	lodsd
   736 00004CEF A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
   737 00004CF1 7409                <1> 	jz	short dapd_1	
   738 00004CF3 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   739 00004CF7 E812000000          <1> 	call	deallocate_page_table			
   740                              <1> dapd_1:
   741 00004CFC 41                  <1> 	inc	ecx ; page directory entry index
   742 00004CFD 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
   743 00004D03 72E9                <1> 	jb	short dapd_0
   744                              <1> dapd_2:
   745 00004D05 58                  <1> 	pop	eax
   746 00004D06 E87F000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
   747 00004D0B 59                  <1> 	pop	ecx
   748 00004D0C 5E                  <1> 	pop	esi
   749 00004D0D C3                  <1> 	retn
   750                              <1> 
   751                              <1> deallocate_page_table:
   752                              <1> 	; 12/07/2016
   753                              <1> 	; 19/09/2015
   754                              <1> 	; 15/09/2015
   755                              <1> 	; 05/08/2015
   756                              <1> 	; 30/04/2015
   757                              <1> 	; 28/04/2015
   758                              <1> 	; 24/10/2014
   759                              <1> 	; 23/10/2014
   760                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   761                              <1> 	;
   762                              <1> 	; INPUT ->
   763                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
   764                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   765                              <1> 	;	(ECX = page directory entry index)
   766                              <1> 	; OUTPUT ->
   767                              <1> 	;	All of pages in the page table and page table's itself
   768                              <1> 	;	will be deallocated except 'read only' duplicated pages
   769                              <1> 	;	(will be converted to writable pages).
   770                              <1> 	;
   771                              <1> 	; Modified Registers -> EAX
   772                              <1> 	;
   773 00004D0E 56                  <1> 	push	esi
   774 00004D0F 57                  <1> 	push	edi
   775 00004D10 52                  <1> 	push	edx
   776 00004D11 50                  <1> 	push	eax ; *
   777 00004D12 89C6                <1> 	mov	esi, eax 
   778 00004D14 31FF                <1> 	xor	edi, edi ; 0
   779                              <1> dapt_0:
   780 00004D16 AD                  <1> 	lodsd
   781 00004D17 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
   782 00004D19 7441                <1> 	jz	short dapt_1
   783                              <1> 	;
   784 00004D1B A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
   785                              <1> 				  ; (must be 1)
   786 00004D1D 754C                <1> 	jnz	short dapt_3
   787                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
   788 00004D1F 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
   789                              <1> 				   ; as child's page ?
   790 00004D23 7451                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
   791                              <1> 	; check the parent's PTE value is read only & same page or not.. 
   792                              <1> 	; ECX = page directory entry index (0-1023)
   793 00004D25 53                  <1> 	push	ebx
   794 00004D26 51                  <1> 	push	ecx
   795 00004D27 66C1E102            <1> 	shl	cx, 2 ; *4 
   796 00004D2B 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
   797 00004D2D 8B0B                <1> 	mov	ecx, [ebx]
   798 00004D2F F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
   799 00004D32 7435                <1> 	jz	short dapt_2	; parent process does not use this page
   800 00004D34 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
   801                              <1> 	; EDI = page table entry index (0-1023)
   802 00004D39 89FA                <1> 	mov	edx, edi 
   803 00004D3B 66C1E202            <1> 	shl	dx, 2 ; *4 
   804 00004D3F 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
   805 00004D41 8B1A                <1> 	mov	ebx, [edx]
   806 00004D43 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
   807 00004D46 7421                <1> 	jz	short dapt_2	; parent process does not use this page
   808 00004D48 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
   809 00004D4C 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
   810 00004D51 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
   811 00004D53 7514                <1> 	jne	short dapt_2	; not same page
   812                              <1> 				; deallocate the child's page
   813 00004D55 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
   814 00004D58 59                  <1> 	pop	ecx
   815 00004D59 5B                  <1> 	pop	ebx
   816 00004D5A EB1A                <1> 	jmp	short dapt_4
   817                              <1> dapt_1:
   818 00004D5C 09C0                <1> 	or	eax, eax	; swapped page ?
   819 00004D5E 741D                <1> 	jz	short dapt_5	; no
   820                              <1> 				; yes
   821 00004D60 D1E8                <1> 	shr	eax, 1
   822 00004D62 E8CA040000          <1> 	call	unlink_swap_block ; Deallocate swapped page block
   823                              <1> 				  ; on the swap disk (or in file)
   824 00004D67 EB14                <1> 	jmp	short dapt_5
   825                              <1> dapt_2:
   826 00004D69 59                  <1> 	pop	ecx
   827 00004D6A 5B                  <1> 	pop	ebx
   828                              <1> dapt_3:	
   829                              <1> 	; 12/07/2016
   830 00004D6B 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
   831 00004D6F 7505                <1> 	jnz	short dapt_4   ; AVL bit 1 = 1, do not deallocate this page!
   832                              <1> 	;
   833                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   834 00004D71 E814000000          <1> 	call	deallocate_page ; set the mem allocation bit of this page
   835                              <1> dapt_4:
   836 00004D76 C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
   837                              <1> dapt_5:
   838 00004D7D 47                  <1> 	inc	edi ; page table entry index
   839 00004D7E 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
   840 00004D84 7290                <1> 	jb	short dapt_0
   841                              <1> 	;
   842 00004D86 58                  <1> 	pop	eax ; *
   843 00004D87 5A                  <1> 	pop	edx
   844 00004D88 5F                  <1> 	pop	edi	
   845 00004D89 5E                  <1> 	pop	esi
   846                              <1> 	;
   847                              <1> 	;call	deallocate_page	; deallocate the page table's itself
   848                              <1> 	;retn
   849                              <1> 
   850                              <1> deallocate_page:
   851                              <1> 	; 15/09/2015
   852                              <1> 	; 28/04/2015
   853                              <1> 	; 10/03/2015
   854                              <1> 	; 17/10/2014
   855                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   856                              <1> 	;
   857                              <1> 	; INPUT -> 
   858                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   859                              <1> 	; OUTPUT ->
   860                              <1> 	;	[free_pages] is increased
   861                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
   862                              <1> 	;	CF = 1 if the page is already deallocated
   863                              <1> 	; 	       (or not allocated) before.  
   864                              <1> 	;
   865                              <1> 	; Modified Registers -> EAX
   866                              <1> 	;
   867 00004D8A 53                  <1> 	push	ebx
   868 00004D8B 52                  <1> 	push	edx
   869                              <1> 	;
   870 00004D8C C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
   871                              <1> 				     ; 12 bits right
   872                              <1> 				     ; to get page number
   873 00004D8F 89C2                <1> 	mov	edx, eax
   874                              <1> 	; 15/09/2015
   875 00004D91 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
   876                              <1> 				     ; (1 allocation bit = 1 page)
   877                              <1> 				     ; (1 allocation bytes = 8 pages)
   878 00004D94 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
   879                              <1> 				     ; (to get 32 bit position)			
   880                              <1> 	;
   881 00004D97 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
   882 00004D9C 01D3                <1> 	add	ebx, edx
   883 00004D9E 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
   884                              <1> 				     ; (allocation bit position)	 
   885 00004DA1 3B15[B4580100]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
   886                              <1> 				     ; than the address in 'next_page' ?
   887                              <1> 				     ; (next/first free page value)		
   888 00004DA7 7306                <1> 	jnb	short dap_1	     ; no	
   889 00004DA9 8915[B4580100]      <1> 	mov	[next_page], edx     ; yes
   890                              <1> dap_1:
   891 00004DAF 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
   892                              <1> 				     ; set relevant bit to 1.
   893                              <1> 				     ; set CF to the previous bit value	
   894                              <1> 	;cmc			     ; complement carry flag	
   895                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
   896                              <1> 				     ; if the page is already deallocated
   897                              <1> 				     ; before.	
   898 00004DB2 FF05[B0580100]      <1>         inc     dword [free_pages]
   899                              <1> dap_2:
   900 00004DB8 5A                  <1> 	pop	edx
   901 00004DB9 5B                  <1> 	pop	ebx
   902 00004DBA C3                  <1> 	retn
   903                              <1> 
   904                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   905                              <1> ;;                                                              ;;
   906                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
   907                              <1> ;; Distributed under terms of the GNU General Public License    ;;
   908                              <1> ;;                                                              ;;
   909                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   910                              <1> 
   911                              <1> ;;$Revision: 5057 $
   912                              <1> 
   913                              <1> 
   914                              <1> ;;align 4
   915                              <1> ;;proc alloc_page
   916                              <1> 
   917                              <1> ;;        pushfd
   918                              <1> ;;        cli
   919                              <1> ;;        push    ebx
   920                              <1> ;;;//-
   921                              <1> ;;        cmp     [pg_data.pages_free], 1
   922                              <1> ;;        jle     .out_of_memory
   923                              <1> ;;;//-
   924                              <1> ;;
   925                              <1> ;;        mov     ebx, [page_start]
   926                              <1> ;;        mov     ecx, [page_end]
   927                              <1> ;;.l1:
   928                              <1> ;;        bsf     eax, [ebx];
   929                              <1> ;;        jnz     .found
   930                              <1> ;;        add     ebx, 4
   931                              <1> ;;        cmp     ebx, ecx
   932                              <1> ;;        jb      .l1
   933                              <1> ;;        pop     ebx
   934                              <1> ;;        popfd
   935                              <1> ;;        xor     eax, eax
   936                              <1> ;;        ret
   937                              <1> ;;.found:
   938                              <1> ;;;//-
   939                              <1> ;;        dec     [pg_data.pages_free]
   940                              <1> ;;        jz      .out_of_memory
   941                              <1> ;;;//-
   942                              <1> ;;        btr     [ebx], eax
   943                              <1> ;;        mov     [page_start], ebx
   944                              <1> ;;        sub     ebx, sys_pgmap
   945                              <1> ;;        lea     eax, [eax+ebx*8]
   946                              <1> ;;        shl     eax, 12
   947                              <1> ;;;//-       dec [pg_data.pages_free]
   948                              <1> ;;        pop     ebx
   949                              <1> ;;        popfd
   950                              <1> ;;        ret
   951                              <1> ;;;//-
   952                              <1> ;;.out_of_memory:
   953                              <1> ;;        mov     [pg_data.pages_free], 1
   954                              <1> ;;        xor     eax, eax
   955                              <1> ;;        pop     ebx
   956                              <1> ;;        popfd
   957                              <1> ;;        ret
   958                              <1> ;;;//-
   959                              <1> ;;endp
   960                              <1> 
   961                              <1> duplicate_page_dir:
   962                              <1> 	; 21/09/2015
   963                              <1> 	; 31/08/2015
   964                              <1> 	; 20/07/2015
   965                              <1> 	; 28/04/2015
   966                              <1> 	; 27/04/2015
   967                              <1> 	; 18/04/2015
   968                              <1> 	; 12/04/2015
   969                              <1> 	; 18/10/2014
   970                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
   971                              <1> 	;
   972                              <1> 	; INPUT -> 
   973                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
   974                              <1> 	;		    page directory.
   975                              <1> 	; OUTPUT ->
   976                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
   977                              <1> 	;	       page directory.
   978                              <1> 	;	(New page directory with new page table entries.)
   979                              <1> 	;	(New page tables with read only copies of the parent's
   980                              <1> 	;	pages.)
   981                              <1> 	;	EAX = 0 -> Error (CF = 1)
   982                              <1> 	;
   983                              <1> 	; Modified Registers -> none (except EAX)
   984                              <1> 	;
   985 00004DBB E8ECFDFFFF          <1> 	call	allocate_page
   986 00004DC0 723E                <1> 	jc	short dpd_err
   987                              <1> 	;
   988 00004DC2 55                  <1> 	push	ebp ; 20/07/2015
   989 00004DC3 56                  <1> 	push	esi
   990 00004DC4 57                  <1> 	push	edi
   991 00004DC5 53                  <1> 	push	ebx
   992 00004DC6 51                  <1> 	push	ecx
   993 00004DC7 8B35[B8030300]      <1> 	mov	esi, [u.pgdir]
   994 00004DCD 89C7                <1> 	mov	edi, eax
   995 00004DCF 50                  <1> 	push	eax ; save child's page directory address
   996                              <1> 	; 31/08/2015
   997                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
   998                              <1> 	; (use same system space for all user page tables) 
   999 00004DD0 A5                  <1> 	movsd
  1000 00004DD1 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  1001 00004DD6 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  1002                              <1> dpd_0:	
  1003 00004DDB AD                  <1> 	lodsd
  1004                              <1> 	;or	eax, eax
  1005                              <1>         ;jnz     short dpd_1
  1006 00004DDC A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  1007 00004DDE 7508                <1> 	jnz	short dpd_1
  1008                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
  1009 00004DE0 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  1010 00004DE6 EB0F                <1> 	jmp	short dpd_2
  1011                              <1> dpd_1:	
  1012 00004DE8 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  1013 00004DEC 89C3                <1> 	mov	ebx, eax
  1014                              <1> 	; EBX = Parent's page table address
  1015 00004DEE E81F000000          <1> 	call	duplicate_page_table
  1016 00004DF3 720C                <1> 	jc	short dpd_p_err
  1017                              <1> 	; EAX = Child's page table address
  1018 00004DF5 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  1019                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  1020                              <1> 			 ; (present, writable, user)
  1021                              <1> dpd_2:
  1022 00004DF7 AB                  <1> 	stosd
  1023 00004DF8 E2E1                <1> 	loop	dpd_0
  1024                              <1> 	;
  1025 00004DFA 58                  <1> 	pop	eax  ; restore child's page directory address
  1026                              <1> dpd_3:
  1027 00004DFB 59                  <1> 	pop	ecx
  1028 00004DFC 5B                  <1> 	pop	ebx
  1029 00004DFD 5F                  <1> 	pop	edi
  1030 00004DFE 5E                  <1> 	pop	esi
  1031 00004DFF 5D                  <1> 	pop	ebp ; 20/07/2015
  1032                              <1> dpd_err:
  1033 00004E00 C3                  <1> 	retn
  1034                              <1> dpd_p_err:
  1035                              <1> 	; release the allocated pages missing (recover free space)
  1036 00004E01 58                  <1> 	pop	eax  ; the new page directory address (physical)
  1037 00004E02 8B1D[B8030300]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  1038 00004E08 E8D8FEFFFF          <1> 	call 	deallocate_page_dir
  1039 00004E0D 29C0                <1> 	sub	eax, eax ; 0
  1040 00004E0F F9                  <1> 	stc
  1041 00004E10 EBE9                <1> 	jmp	short dpd_3	
  1042                              <1> 
  1043                              <1> duplicate_page_table:
  1044                              <1> 	; 20/02/2017
  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> 	;       20/02/2017		 
  1057                              <1> 	;	EBP = Linear address of the page (from 'duplicate_page_dir')
  1058                              <1> 	;	      (Linear address = CORE + user's virtual address) 	
  1059                              <1> 	; OUTPUT ->
  1060                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  1061                              <1> 	;	      (with 'read only' attribute of page table entries)
  1062                              <1> 	;	20/02/2017
  1063                              <1> 	;	EBP = Next linear page address (for 'duplicate_page_dir')
  1064                              <1> 	;	
  1065                              <1> 	;	CF = 1 -> error 
  1066                              <1> 	;
  1067                              <1> 	; Modified Registers -> EBP (except EAX)
  1068                              <1> 	;
  1069 00004E12 E895FDFFFF          <1> 	call	allocate_page
  1070 00004E17 726A                <1> 	jc	short dpt_err
  1071                              <1> 	;
  1072 00004E19 50                  <1> 	push	eax ; *
  1073 00004E1A 56                  <1> 	push	esi
  1074 00004E1B 57                  <1> 	push	edi
  1075 00004E1C 52                  <1> 	push	edx
  1076 00004E1D 51                  <1> 	push	ecx
  1077                              <1> 	;
  1078 00004E1E 89DE                <1> 	mov	esi, ebx
  1079 00004E20 89C7                <1> 	mov	edi, eax
  1080 00004E22 89C2                <1> 	mov	edx, eax
  1081 00004E24 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  1082                              <1> dpt_0:
  1083 00004E2A AD                  <1> 	lodsd
  1084 00004E2B 21C0                <1> 	and	eax, eax
  1085 00004E2D 7444                <1> 	jz	short dpt_3
  1086 00004E2F A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
  1087 00004E31 7507                <1> 	jnz	short dpt_1
  1088                              <1> 	; 20/07/2015
  1089                              <1> 	; ebp = virtual (linear) address of the memory page
  1090 00004E33 E83F050000          <1> 	call	reload_page ; 28/04/2015
  1091 00004E38 7244                <1> 	jc	short dpt_p_err
  1092                              <1> dpt_1:
  1093                              <1> 	; 21/09/2015
  1094 00004E3A 89C1                <1> 	mov	ecx, eax
  1095 00004E3C 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1096 00004E40 F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
  1097 00004E43 7525                <1> 	jnz	short dpt_2
  1098                              <1> 	; Read only (parent) page
  1099                              <1> 	; 	- there is a third process which uses this page -
  1100                              <1> 	; Allocate a new page for the child process
  1101 00004E45 E862FDFFFF          <1> 	call	allocate_page
  1102 00004E4A 7232                <1> 	jc	short dpt_p_err
  1103 00004E4C 57                  <1> 	push	edi
  1104 00004E4D 56                  <1> 	push	esi
  1105 00004E4E 89CE                <1> 	mov	esi, ecx
  1106 00004E50 89C7                <1> 	mov	edi, eax
  1107 00004E52 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  1108 00004E57 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  1109 00004E59 5E                  <1> 	pop	esi
  1110 00004E5A 5F                  <1> 	pop	edi
  1111                              <1> 	; 
  1112 00004E5B 53                  <1> 	push	ebx
  1113 00004E5C 50                  <1> 	push	eax
  1114                              <1> 	; 20/07/2015
  1115 00004E5D 89EB                <1> 	mov	ebx, ebp
  1116                              <1> 	; ebx = virtual (linear) address of the memory page
  1117 00004E5F E887030000          <1> 	call	add_to_swap_queue
  1118 00004E64 58                  <1> 	pop	eax
  1119 00004E65 5B                  <1> 	pop	ebx
  1120                              <1> 	; 21/09/2015
  1121 00004E66 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  1122                              <1> 		; user + writable + present page
  1123 00004E68 EB09                <1> 	jmp	short dpt_3
  1124                              <1> dpt_2:
  1125                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  1126 00004E6A 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
  1127                              <1> 		    ; (read only page!)
  1128 00004E6C 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
  1129 00004E6F 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
  1130                              <1> dpt_3:
  1131 00004E73 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  1132                              <1> 	;
  1133 00004E74 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  1134                              <1> 	;
  1135 00004E7A 39D7                <1> 	cmp	edi, edx
  1136 00004E7C 72AC                <1> 	jb	short dpt_0
  1137                              <1> dpt_p_err:
  1138 00004E7E 59                  <1> 	pop	ecx
  1139 00004E7F 5A                  <1> 	pop	edx
  1140 00004E80 5F                  <1> 	pop	edi
  1141 00004E81 5E                  <1> 	pop	esi
  1142 00004E82 58                  <1> 	pop	eax ; *
  1143                              <1> dpt_err:
  1144 00004E83 C3                  <1> 	retn
  1145                              <1> 
  1146                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
  1147                              <1> 	; 21/09/2015
  1148                              <1> 	; 19/09/2015
  1149                              <1> 	; 17/09/2015
  1150                              <1> 	; 28/08/2015
  1151                              <1> 	; 20/07/2015
  1152                              <1> 	; 28/06/2015
  1153                              <1> 	; 03/05/2015
  1154                              <1> 	; 30/04/2015
  1155                              <1> 	; 18/04/2015
  1156                              <1> 	; 12/04/2015
  1157                              <1> 	; 30/10/2014
  1158                              <1> 	; 11/09/2014
  1159                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
  1160                              <1> 	;
  1161                              <1> 	; Note: This is not an interrupt/exception handler.
  1162                              <1> 	;	This is a 'page fault remedy' subroutine 
  1163                              <1> 	;	which will be called by standard/uniform
  1164                              <1> 	;	exception handler.
  1165                              <1> 	;
  1166                              <1> 	; INPUT -> 
  1167                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
  1168                              <1> 	;
  1169                              <1> 	;	cr2 = the virtual (linear) address 
  1170                              <1> 	;	      which has caused to page fault (19/09/2015)
  1171                              <1> 	;
  1172                              <1> 	; OUTPUT ->
  1173                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1174                              <1> 	;	EAX = 0 -> no error
  1175                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
  1176                              <1> 	;
  1177                              <1> 	; Modified Registers -> none (except EAX)
  1178                              <1> 	;	
  1179                              <1>         ;
  1180                              <1>         ; ERROR CODE:
  1181                              <1> 	;	 31  .....	4   3	2   1	0
  1182                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1183                              <1> 	;	|   Reserved  | I | R | U | W | P |
  1184                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1185                              <1> 	;
  1186                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
  1187                              <1>     	;		a page-protection violation. When not set,
  1188                              <1> 	;		it was caused by a non-present page.
  1189                              <1> 	; W : WRITE   -	When set, the page fault was caused by
  1190                              <1> 	;		a page write. When not set, it was caused
  1191                              <1> 	;		by a page read.
  1192                              <1> 	; U : USER    -	When set, the page fault was caused 
  1193                              <1> 	;		while CPL = 3. 
  1194                              <1> 	;		This does not necessarily mean that
  1195                              <1> 	;		the page fault was a privilege violation.
  1196                              <1> 	; R : RESERVD -	When set, the page fault was caused by
  1197                              <1> 	;     WRITE	reading a 1 in a reserved field.
  1198                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
  1199                              <1> 	;     FETCH	an instruction fetch
  1200                              <1> 	;
  1201                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
  1202                              <1> 	;  31               22                  12 11                    0
  1203                              <1> 	; +-------------------+-------------------+-----------------------+
  1204                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
  1205                              <1>        	; +-------------------+-------------------+-----------------------+
  1206                              <1> 	;
  1207                              <1> 
  1208                              <1> 	;; CR3 REGISTER (Control Register 3)
  1209                              <1> 	;  31                                   12             5 4 3 2   0
  1210                              <1> 	; +---------------------------------------+-------------+---+-----+
  1211                              <1>       	; |                                       |  		|P|P|     |
  1212                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
  1213                              <1>       	; |                                       | 		|D|T|     |
  1214                              <1>    	; +---------------------------------------+-------------+---+-----+
  1215                              <1> 	;
  1216                              <1> 	;	PWT    - WRITE THROUGH
  1217                              <1> 	;	PCD    - CACHE DISABLE		
  1218                              <1> 	;
  1219                              <1> 	;
  1220                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
  1221                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1222                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1223                              <1>       	; |                                       |     | | | | |P|P|U|R| |
  1224                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
  1225                              <1>       	; |                                       |     | | | | |D|T|S|W| |
  1226                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1227                              <1> 	;
  1228                              <1>         ;       P      - PRESENT
  1229                              <1>         ;       R/W    - READ/WRITE
  1230                              <1>         ;       U/S    - USER/SUPERVISOR
  1231                              <1> 	;	PWT    - WRITE THROUGH
  1232                              <1> 	;	PCD    - CACHE DISABLE	
  1233                              <1> 	;	A      - ACCESSED	
  1234                              <1>         ;       D      - DIRTY (IGNORED)
  1235                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1236                              <1> 	;	G      - GLOBAL	(IGNORED) 
  1237                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1238                              <1> 	;
  1239                              <1> 	;
  1240                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
  1241                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1242                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1243                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
  1244                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
  1245                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
  1246                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1247                              <1> 	;
  1248                              <1>         ;       P      - PRESENT
  1249                              <1>         ;       R/W    - READ/WRITE
  1250                              <1>         ;       U/S    - USER/SUPERVISOR
  1251                              <1> 	;	PWT    - WRITE THROUGH
  1252                              <1> 	;	PCD    - CACHE DISABLE	
  1253                              <1> 	;	A      - ACCESSED	
  1254                              <1>         ;       D      - DIRTY
  1255                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1256                              <1> 	;	G      - GLOBAL	 
  1257                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1258                              <1> 	;
  1259                              <1> 	;
  1260                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
  1261                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1262                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1263                              <1>       	; |                                       |     | | | | | | |U|R| |
  1264                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
  1265                              <1>       	; |                                       |     | | | | | | |S|W| |
  1266                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1267                              <1> 	;
  1268                              <1>         ;       P      - PRESENT
  1269                              <1>         ;       R/W    - READ/WRITE
  1270                              <1>         ;       U/S    - USER/SUPERVISOR
  1271                              <1>         ;       D      - DIRTY
  1272                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1273                              <1> 	;
  1274                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
  1275                              <1> 	;
  1276                              <1> 	;
  1277                              <1> 	;; Invalid Page Table Entry
  1278                              <1> 	; 31                                                           1 0
  1279                              <1>       	; +-------------------------------------------------------------+-+
  1280                              <1>       	; |                                                             | |
  1281                              <1>       	; |                          AVAILABLE                          |0|
  1282                              <1>       	; |                                                             | |
  1283                              <1>       	; +-------------------------------------------------------------+-+
  1284                              <1> 	;
  1285                              <1> 
  1286 00004E84 53                  <1> 	push	ebx
  1287 00004E85 52                  <1> 	push	edx
  1288 00004E86 51                  <1> 	push	ecx
  1289                              <1> 	;
  1290                              <1> 	; 21/09/2015 (debugging)
  1291 00004E87 FF05[CC030300]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
  1292 00004E8D FF05[80050300]      <1> 	inc	dword [PF_Count] ; total page fault count	
  1293                              <1> 	; 28/06/2015
  1294                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
  1295 00004E93 8A15[78050300]      <1> 	mov	dl, [error_code]
  1296                              <1> 	;
  1297 00004E99 F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
  1298                              <1> 			; sign
  1299 00004E9C 7422                <1> 	jz	short pfh_alloc_np
  1300                              <1> 	; 
  1301                              <1> 	; If it is not a 'write on read only page' type page fault
  1302                              <1> 	; major page fault error with minor reason must be returned without 
  1303                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
  1304                              <1> 	; after return here!
  1305                              <1> 	; Page fault will be remedied, by copying page contents
  1306                              <1> 	; to newly allocated page with write permission;
  1307                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
  1308                              <1> 	; used for working with minimum possible memory usage. 
  1309                              <1> 	; sys_fork will duplicate page directory and tables of parent  
  1310                              <1> 	; process with 'read only' flag. If the child process attempts to
  1311                              <1> 	; write on these read only pages, page fault will be directed here
  1312                              <1> 	; for allocating a new page with same data/content. 
  1313                              <1> 	;
  1314                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
  1315                              <1> 	; will not force to separate CODE and DATA space 
  1316                              <1> 	; in a process/program... 
  1317                              <1> 	; CODE segment/section may contain DATA!
  1318                              <1> 	; It is flat, smoth and simplest programming method already as in 
  1319                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
  1320                              <1> 	;	
  1321 00004E9E F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
  1322                              <1> 			; sign
  1323 00004EA1 0F84AB000000        <1>         jz      pfh_p_err
  1324                              <1> 	; 31/08/2015
  1325 00004EA7 F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
  1326                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
  1327 00004EAA 0F84A2000000        <1>         jz	pfh_pv_err
  1328                              <1> 	;
  1329                              <1> 	; make a new page and copy the parent's page content
  1330                              <1> 	; as the child's new page content
  1331                              <1> 	;
  1332 00004EB0 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
  1333                              <1> 			 ; which has caused to page fault
  1334 00004EB3 E8A2000000          <1> 	call 	copy_page
  1335 00004EB8 0F828D000000        <1>         jc      pfh_im_err ; insufficient memory
  1336                              <1> 	;
  1337 00004EBE EB7D                <1>         jmp     pfh_cpp_ok
  1338                              <1> 	;
  1339                              <1> pfh_alloc_np:
  1340 00004EC0 E8E7FCFFFF          <1> 	call	allocate_page	; (allocate a new page)
  1341 00004EC5 0F8280000000        <1>         jc      pfh_im_err	; 'insufficient memory' error
  1342                              <1> pfh_chk_cpl:
  1343                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1344                              <1> 		; (Lower 12 bits are ZERO, because 
  1345                              <1> 		;	the address is on a page boundary)
  1346 00004ECB 80E204              <1> 	and	dl, 4	; CPL = 3 ?
  1347 00004ECE 7505                <1> 	jnz	short pfh_um
  1348                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
  1349 00004ED0 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
  1350                              <1> 			 ; of the current/active page directory
  1351                              <1> 			 ; (Always kernel/system mode page directory, here!)
  1352                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
  1353 00004ED3 EB06                <1> 	jmp	short pfh_get_pde
  1354                              <1> 	;
  1355                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
  1356 00004ED5 8B1D[B8030300]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
  1357                              <1> 			; Physical address of the USER's page directory
  1358                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
  1359                              <1> pfh_get_pde:
  1360 00004EDB 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
  1361 00004EDE 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
  1362                              <1> 			 ; which has been caused to page fault
  1363                              <1> 			 ;
  1364 00004EE1 C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
  1365 00004EE4 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
  1366                              <1> 	;
  1367 00004EE7 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
  1368 00004EE9 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
  1369 00004EEB F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
  1370 00004EEE 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
  1371                              <1> 			  	  ; set/validate page directory entry
  1372 00004EF0 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  1373 00004EF5 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
  1374 00004EF7 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
  1375 00004EF9 EB16                <1> 	jmp	short pfh_get_pte
  1376                              <1> pfh_set_pde:
  1377                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
  1378                              <1> 	;;	 (So, we know this PDE is empty or invalid)
  1379                              <1> 	;
  1380 00004EFB 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
  1381 00004EFD 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
  1382 00004EFF 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
  1383 00004F01 89C3                <1> 	mov	ebx, eax
  1384 00004F03 E8A4FCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
  1385 00004F08 7241                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
  1386                              <1> pfh_spde_1:
  1387                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1388 00004F0A 89C1                <1> 	mov	ecx, eax
  1389 00004F0C E815FDFFFF          <1> 	call	clear_page ; Clear page content
  1390                              <1> pfh_get_pte:
  1391 00004F11 0F20D0              <1> 	mov	eax, cr2 ; virtual address
  1392                              <1> 			 ; which has been caused to page fault
  1393 00004F14 89C7                <1> 	mov	edi, eax ; 20/07/2015
  1394 00004F16 C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
  1395                              <1> 			 ; higher 20 bits of the page fault address 
  1396 00004F19 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
  1397 00004F1E C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
  1398 00004F21 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
  1399 00004F23 8B03                <1> 	mov	eax, [ebx] ; get previous value of pte
  1400                              <1> 		; bit 0 of EAX is always 0 (otherwise we would not be here)
  1401 00004F25 21C0                <1> 	and	eax, eax
  1402 00004F27 7410                <1> 	jz	short pfh_gpte_1
  1403                              <1> 	; 20/07/2015
  1404 00004F29 87D9                <1> 	xchg	ebx, ecx ; new page address (physical)
  1405 00004F2B 55                  <1> 	push	ebp ; 20/07/2015
  1406 00004F2C 0F20D5              <1> 	mov	ebp, cr2
  1407                              <1> 		; ECX = physical address of the page table entry
  1408                              <1> 		; EBX = Memory page address (physical!)
  1409                              <1> 		; EAX = Swap disk (offset) address
  1410                              <1> 		; EBP = virtual address (page fault address)
  1411 00004F2F E8B7000000          <1> 	call	swap_in
  1412 00004F34 5D                  <1> 	pop	ebp
  1413 00004F35 7210                <1> 	jc      short pfh_err_retn
  1414 00004F37 87CB                <1> 	xchg	ecx, ebx
  1415                              <1> 		; EBX = physical address of the page table entry
  1416                              <1> 		; ECX = new page
  1417                              <1> pfh_gpte_1:
  1418 00004F39 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
  1419 00004F3B 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
  1420                              <1> pfh_cpp_ok:
  1421                              <1> 	; 20/07/2015
  1422 00004F3D 0F20D3              <1> 	mov	ebx, cr2
  1423 00004F40 E8A6020000          <1> 	call 	add_to_swap_queue
  1424                              <1> 	;
  1425                              <1> 	; The new PTE (which contains the new page) will be added to 
  1426                              <1> 	; the swap queue, here. 
  1427                              <1> 	; (Later, if memory will become insufficient, 
  1428                              <1> 	; one page will be swapped out which is at the head of 
  1429                              <1> 	; the swap queue by using FIFO and access check methods.)
  1430                              <1> 	;
  1431 00004F45 31C0                <1> 	xor	eax, eax  ; 0
  1432                              <1> 	;
  1433                              <1> pfh_err_retn:
  1434 00004F47 59                  <1> 	pop	ecx
  1435 00004F48 5A                  <1> 	pop	edx
  1436 00004F49 5B                  <1> 	pop	ebx
  1437 00004F4A C3                  <1> 	retn 
  1438                              <1> 	
  1439                              <1> pfh_im_err:
  1440 00004F4B B8E4000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
  1441                              <1> 			; Major (Primary) Error: Page Fault
  1442                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
  1443 00004F50 EBF5                <1> 	jmp	short pfh_err_retn
  1444                              <1> 
  1445                              <1> 
  1446                              <1> pfh_p_err: ; 09/03/2015
  1447                              <1> pfh_pv_err:
  1448                              <1> 	; Page fault was caused by a protection-violation
  1449 00004F52 B8E6000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
  1450                              <1> 			; Major (Primary) Error: Page Fault
  1451                              <1> 			; Minor (Secondary) Error: Protection violation !
  1452 00004F57 F9                  <1> 	stc
  1453 00004F58 EBED                <1> 	jmp	short pfh_err_retn
  1454                              <1> 
  1455                              <1> copy_page:
  1456                              <1> 	; 22/09/2015
  1457                              <1> 	; 21/09/2015
  1458                              <1> 	; 19/09/2015
  1459                              <1> 	; 07/09/2015
  1460                              <1> 	; 31/08/2015
  1461                              <1> 	; 20/07/2015
  1462                              <1> 	; 05/05/2015
  1463                              <1> 	; 03/05/2015
  1464                              <1> 	; 18/04/2015
  1465                              <1> 	; 12/04/2015
  1466                              <1> 	; 30/10/2014
  1467                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
  1468                              <1> 	;
  1469                              <1> 	; INPUT -> 
  1470                              <1> 	;	EBX = Virtual (linear) address of source page
  1471                              <1> 	;	     (Page fault address)
  1472                              <1> 	; OUTPUT ->
  1473                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
  1474                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1475                              <1> 	;	EAX = 0 (CF = 1) 
  1476                              <1> 	;		if there is not a free page to be allocated
  1477                              <1> 	;	(page content of the source page will be copied
  1478                              <1> 	;	onto the target/new page) 	
  1479                              <1> 	;
  1480                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
  1481                              <1> 	;	
  1482 00004F5A 56                  <1> 	push	esi
  1483 00004F5B 57                  <1> 	push	edi
  1484                              <1> 	;push	ebx
  1485                              <1> 	;push	ecx
  1486 00004F5C 31F6                <1> 	xor 	esi, esi
  1487 00004F5E C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
  1488 00004F61 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
  1489 00004F63 C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
  1490 00004F66 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
  1491 00004F69 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
  1492 00004F6B 031D[B8030300]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
  1493 00004F71 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
  1494 00004F73 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
  1495 00004F77 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
  1496 00004F79 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1497 00004F7F 66C1E302            <1> 	shl	bx, 2	   ; shift 2 bits left to get PTE offset
  1498 00004F83 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
  1499                              <1> 	; 07/09/2015
  1500 00004F85 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
  1501                              <1> 				     ; read only page as a child process?)	
  1502 00004F8A 7509                <1> 	jnz	short cpp_0 ; yes
  1503 00004F8C 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
  1504 00004F8E 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
  1505 00004F93 EB32                <1> 	jmp	short cpp_1
  1506                              <1> cpp_0:
  1507 00004F95 89FE                <1> 	mov	esi, edi
  1508 00004F97 0335[BC030300]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
  1509 00004F9D 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
  1510 00004F9F 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1511 00004FA3 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
  1512 00004FA5 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1513 00004FAB 66C1E602            <1> 	shl	si, 2	   ; shift 2 bits left to get PTE offset
  1514 00004FAF 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
  1515 00004FB1 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
  1516                              <1> 	; 21/09/2015
  1517 00004FB3 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
  1518 00004FB5 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
  1519                              <1> 	;
  1520 00004FB9 F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
  1521 00004FBC 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
  1522                              <1> 	;
  1523 00004FBE 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
  1524 00004FC3 39C8                <1> 	cmp	eax, ecx   ; Same page?	
  1525 00004FC5 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
  1526                              <1> 			    ; Convert child's page to writable page
  1527                              <1> cpp_1:
  1528 00004FC7 E8E0FBFFFF          <1> 	call	allocate_page
  1529 00004FCC 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
  1530 00004FCE 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
  1531 00004FD0 7405                <1> 	jz	short cpp_2
  1532                              <1> 		; Convert read only page to writable page 
  1533                              <1> 		;(for the parent of the current process)
  1534                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
  1535                              <1> 	; 22/09/2015
  1536 00004FD2 890E                <1> 	mov	[esi], ecx
  1537 00004FD4 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
  1538                              <1> 				 ; 1+2+4 = 7
  1539                              <1> cpp_2:
  1540 00004FD7 89C7                <1> 	mov	edi, eax ; new page address of the child process
  1541                              <1> 	; 07/09/2015
  1542 00004FD9 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
  1543 00004FDB B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
  1544 00004FE0 F3A5                <1> 	rep	movsd ; 31/08/2015
  1545                              <1> cpp_3:		
  1546 00004FE2 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
  1547 00004FE4 8903                <1> 	mov	[ebx], eax ; Update PTE
  1548 00004FE6 28C0                <1> 	sub	al, al ; clear attributes
  1549                              <1> cpp_4:
  1550                              <1> 	;pop	ecx
  1551                              <1> 	;pop	ebx
  1552 00004FE8 5F                  <1> 	pop	edi
  1553 00004FE9 5E                  <1> 	pop	esi
  1554 00004FEA C3                  <1> 	retn
  1555                              <1> 
  1556                              <1> ;; 28/04/2015
  1557                              <1> ;; 24/10/2014
  1558                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
  1559                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
  1560                              <1> ;;
  1561                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
  1562                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
  1563                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
  1564                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
  1565                              <1> ;;
  1566                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
  1567                              <1> ;;
  1568                              <1> ;; Method:
  1569                              <1> ;;	Swap page queue is a list of allocated pages with physical
  1570                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
  1571                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
  1572                              <1> ;;	When a new page is being allocated, swap queue is updated
  1573                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
  1574                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
  1575                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
  1576                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
  1577                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
  1578                              <1> ;;	offset value becomes it's previous offset value - 4.
  1579                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
  1580                              <1> ;;	the queue/list is not shifted.
  1581                              <1> ;;	After the queue/list shift, newly allocated page is added
  1582                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
  1583                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
  1584                              <1> ;;	will not be added to the tail of swap page queue.  		 
  1585                              <1> ;;	
  1586                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
  1587                              <1> ;;	the first non-accessed, writable page in the list, 
  1588                              <1> ;;	from the head to the tail. The list is shifted to left 
  1589                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
  1590                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
  1591                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
  1592                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
  1593                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
  1594                              <1> ;;	procedure will be failed)...
  1595                              <1> ;;
  1596                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
  1597                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
  1598                              <1> ;;	(PTE) will be added to the tail of the queue after
  1599                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
  1600                              <1> ;;	the queue will be rotated and the PTE in the head will be
  1601                              <1> ;;	added to the tail after resetting 'accessed' bit. 
  1602                              <1> ;;
  1603                              <1> ;;
  1604                              <1> ;;	
  1605                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
  1606                              <1> ;;
  1607                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
  1608                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
  1609                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
  1610                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
  1611                              <1> ;;
  1612                              <1> ;; [swpd_next] = the first free block address in swapped page records
  1613                              <1> ;;    		 for next free block search by 'swap_out' procedure.
  1614                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
  1615                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
  1616                              <1> ;; 		 (entire swap space must be accessed by using
  1617                              <1> ;;		 31 bit offset address) 
  1618                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
  1619                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
  1620                              <1> ;;		  0 for file, or beginning sector of the swap partition
  1621                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
  1622                              <1> ;;
  1623                              <1> ;; 					
  1624                              <1> ;; Method:
  1625                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
  1626                              <1> ;;	procedure swaps out a page from memory to the swap disk 
  1627                              <1> ;;	(partition) or swap file to get a new free page at the memory.
  1628                              <1> ;;	Swapping out is performed by using swap page queue.
  1629                              <1> ;;
  1630                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
  1631                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
  1632                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
  1633                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
  1634                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
  1635                              <1> ;;	Absolute physical (logical) address of the swapped page is 
  1636                              <1> ;;	calculated by adding offset value to the swap partition's 
  1637                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
  1638                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
  1639                              <1> ;;	and offset value is equal to absolute (physical or logical)
  1640                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
  1641                              <1> ;;	is in a partitioned virtual hard disk.) 
  1642                              <1> ;;
  1643                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
  1644                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
  1645                              <1> ;;
  1646                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
  1647                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
  1648                              <1> ;;
  1649                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
  1650                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
  1651                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
  1652                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
  1653                              <1> ;;	it means relevant (respective) block is in use, and, 
  1654                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
  1655                              <1> ;;      swap disk/file block is free.
  1656                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
  1657                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
  1658                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
  1659                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
  1660                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
  1661                              <1> ;;	------------------------------------------------------------
  1662                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
  1663                              <1> ;;	------------------------------------------------------------
  1664                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
  1665                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
  1666                              <1> ;;
  1667                              <1> ;;	..............................................................
  1668                              <1> ;;
  1669                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
  1670                              <1> ;;	then it searches Swap Allocation Table if free count is not
  1671                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
  1672                              <1> ;;	position with value of 1 on the table is converted to swap
  1673                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
  1674                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
  1675                              <1> ;;	number of physical swap disk or virtual swap disk)
  1676                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
  1677                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
  1678                              <1> ;;	(memory page). That will be a direct disk write procedure.
  1679                              <1> ;;	(for preventing late memory allocation, significant waiting). 
  1680                              <1> ;;	If disk write procedure returns with error or free count of 
  1681                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
  1682                              <1> ;;	'insufficient memory error' (cf=1). 
  1683                              <1> ;;
  1684                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
  1685                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
  1686                              <1> ;;	in other words, 'swap_out' will not check the table for other
  1687                              <1> ;;	free blocks after a disk write error. It will return to 
  1688                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
  1689                              <1> ;;
  1690                              <1> ;;	After writing the page on to swap disk/file address/sector,
  1691                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
  1692                              <1> ;;	address (cf=0). 
  1693                              <1> ;;
  1694                              <1> ;;	..............................................................
  1695                              <1> ;;
  1696                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
  1697                              <1> ;;	file sectors at specified memory page. Then page allocation
  1698                              <1> ;;	procedure updates relevant page table entry with 'present' 
  1699                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
  1700                              <1> ;;	to do, except to terminate the process which is the owner of
  1701                              <1> ;;	the swapped page.
  1702                              <1> ;;
  1703                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
  1704                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
  1705                              <1> ;;	updates [swpd_first] pointer if it is required.
  1706                              <1> ;;
  1707                              <1> ;;	..............................................................	 
  1708                              <1> ;;
  1709                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
  1710                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
  1711                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
  1712                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
  1713                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
  1714                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
  1715                              <1> ;;
  1716                              <1> 
  1717                              <1> swap_in:
  1718                              <1> 	; 31/08/2015
  1719                              <1> 	; 20/07/2015
  1720                              <1> 	; 28/04/2015
  1721                              <1> 	; 18/04/2015
  1722                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  1723                              <1> 	;
  1724                              <1> 	; INPUT -> 
  1725                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
  1726                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
  1727                              <1> 	;	EAX = Offset Address for the swapped page on the
  1728                              <1> 	;	      swap disk or in the swap file.
  1729                              <1> 	;
  1730                              <1> 	; OUTPUT ->
  1731                              <1> 	;	EAX = 0 if loading at memory has been successful
  1732                              <1> 	;
  1733                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
  1734                              <1> 	;		  or sector not present or drive not ready
  1735                              <1> 	;	     EAX = Error code
  1736                              <1> 	;	     [u.error] = EAX 
  1737                              <1> 	;		       = The last error code for the process
  1738                              <1> 	;		         (will be reset after returning to user)	  
  1739                              <1> 	;
  1740                              <1> 	; Modified Registers -> EAX
  1741                              <1> 	;
  1742                              <1> 
  1743 00004FEB 833D[62050300]00    <1>         cmp     dword [swp_drv], 0
  1744 00004FF2 7646                <1> 	jna	short swpin_dnp_err
  1745                              <1> 
  1746 00004FF4 3B05[66050300]      <1> 	cmp	eax, [swpd_size]
  1747 00004FFA 734A                <1> 	jnb	short swpin_snp_err
  1748                              <1> 
  1749 00004FFC 56                  <1> 	push	esi
  1750 00004FFD 53                  <1> 	push	ebx
  1751 00004FFE 51                  <1> 	push	ecx
  1752 00004FFF 8B35[62050300]      <1> 	mov	esi, [swp_drv]	
  1753 00005005 B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1754                              <1> 		; Note: Even if corresponding physical disk's sector 
  1755                              <1> 		; size different than 512 bytes, logical disk sector
  1756                              <1> 		; size is 512 bytes and disk reading procedure
  1757                              <1> 		; will be performed for reading 4096 bytes
  1758                              <1> 		; (2*2048, 8*512). 
  1759                              <1> 	; ESI = Logical disk description table address
  1760                              <1> 	; EBX = Memory page (buffer) address (physical!)
  1761                              <1> 	; EAX = Sector adress (offset address, logical sector number)
  1762                              <1> 	; ECX = Sector count ; 8 sectors
  1763 0000500A 50                  <1> 	push	eax
  1764 0000500B E8AF020000          <1> 	call	logical_disk_read
  1765 00005010 58                  <1> 	pop	eax
  1766 00005011 730C                <1> 	jnc	short swpin_read_ok
  1767                              <1> 	;
  1768 00005013 B828000000          <1> 	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
  1769 00005018 A3[C8030300]        <1> 	mov	[u.error], eax
  1770 0000501D EB17                <1> 	jmp	short swpin_retn
  1771                              <1> 	;
  1772                              <1> swpin_read_ok:
  1773                              <1> 	; EAX = Offset address (logical sector number)
  1774 0000501F E80D020000          <1> 	call	unlink_swap_block  ; Deallocate swap block	
  1775                              <1> 	;
  1776                              <1> 	; EBX = Memory page (buffer) address (physical!)
  1777                              <1> 	; 20/07/2015
  1778 00005024 89EB                <1> 	mov	ebx, ebp ; virtual address (page fault address)
  1779 00005026 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  1780 0000502B 8A1D[B3030300]      <1> 	mov	bl, [u.uno] ; current process number
  1781                              <1> 	; EBX = Virtual (Linear) address & process number combination
  1782 00005031 E8DB000000          <1> 	call	swap_queue_shift
  1783                              <1> 	; eax = 0 ; 10/06/2016 (if ebx input > 0, eax output = 0)
  1784                              <1> 	;sub	eax, eax  ; 0 ; Error Code = 0  (no error)
  1785                              <1> 	; zf = 1
  1786                              <1> swpin_retn:
  1787 00005036 59                  <1> 	pop	ecx
  1788 00005037 5B                  <1> 	pop	ebx
  1789 00005038 5E                  <1> 	pop	esi
  1790 00005039 C3                  <1> 	retn
  1791                              <1> 
  1792                              <1> swpin_dnp_err:
  1793 0000503A B829000000          <1> 	mov	eax, SWP_DISK_NOT_PRESENT_ERR
  1794                              <1> swpin_err_retn:
  1795 0000503F A3[C8030300]        <1> 	mov	[u.error], eax
  1796 00005044 F9                  <1> 	stc
  1797 00005045 C3                  <1> 	retn
  1798                              <1> 
  1799                              <1> swpin_snp_err:
  1800 00005046 B82A000000          <1> 	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
  1801 0000504B EBF2                <1> 	jmp	short swpin_err_retn
  1802                              <1> 
  1803                              <1> swap_out:
  1804                              <1> 	; 10/06/2016
  1805                              <1> 	; 07/06/2016
  1806                              <1>         ; 23/05/2016
  1807                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1808                              <1> 	; 24/10/2014 - 31/08/2015 (Retro UNIX 386 v1)
  1809                              <1> 	;
  1810                              <1> 	; INPUT -> 
  1811                              <1> 	;	none
  1812                              <1> 	;
  1813                              <1> 	; OUTPUT ->
  1814                              <1> 	;	EAX = Physical page address (which is swapped out
  1815                              <1> 	;	      for allocating a new page)
  1816                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
  1817                              <1> 	;		  or sector not present or drive not ready
  1818                              <1> 	;	     EAX = Error code
  1819                              <1> 	;	     [u.error] = EAX 
  1820                              <1> 	;		       = The last error code for the process
  1821                              <1> 	;		         (will be reset after returning to user)	  
  1822                              <1> 	;
  1823                              <1> 	; Modified Registers -> none (except EAX)
  1824                              <1> 	;
  1825 0000504D 66833D[60050300]01  <1> 	cmp 	word [swpq_count], 1
  1826 00005055 0F82AF000000        <1>         jc      swpout_im_err ; 'insufficient memory'
  1827                              <1> 
  1828                              <1>         ;cmp    dword [swp_drv], 1
  1829                              <1> 	;jc	short swpout_dnp_err ; 'swap disk/file not present'
  1830                              <1> 
  1831 0000505B 833D[6A050300]01    <1>         cmp     dword [swpd_free], 1
  1832 00005062 0F828F000000        <1>         jc      swpout_nfspc_err ; 'no free space on swap disk'
  1833                              <1> 
  1834 00005068 53                  <1> 	push	ebx ; *
  1835                              <1> swpout_1:
  1836                              <1> 	; 10/06/2016
  1837 00005069 31DB                <1> 	xor	ebx, ebx ; shift the queue and return a PTE value
  1838 0000506B E8A1000000          <1> 	call	swap_queue_shift
  1839 00005070 21C0                <1> 	and	eax, eax	; 0 = empty queue (improper entries)
  1840 00005072 0F848A000000        <1>         jz      swpout_npts_err        ; There is not any proper PTE
  1841                              <1> 				       ; pointer in the swap queue
  1842                              <1> 	; EAX = PTE value of the page
  1843                              <1> 	; EBX = PTE address of the page
  1844 00005078 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1845                              <1> 	;
  1846                              <1> 	; 07/06/2016
  1847                              <1> 	; 19/05/2016
  1848                              <1> 	; check this page is in timer events or not
  1849                              <1> 	
  1850                              <1> swpout_timer_page_0:
  1851 0000507C 52                  <1> 	push	edx ; **
  1852                              <1> 
  1853                              <1> 	; 07/06/2016
  1854 0000507D 803D[33650100]00    <1> 	cmp	byte [timer_events], 0 
  1855 00005084 762F                <1> 	jna	short swpout_2
  1856                              <1> 	;
  1857 00005086 8A15[33650100]      <1> 	mov	dl, [timer_events]
  1858                              <1> 
  1859 0000508C 51                  <1> 	push	ecx ; ***
  1860 0000508D 53                  <1> 	push	ebx ; ****
  1861 0000508E BB[60040300]        <1> 	mov	ebx, timer_set ; beginning address of timer event
  1862                              <1> 			       ; structures 
  1863                              <1> swpout_timer_page_1:
  1864 00005093 8A0B                <1> 	mov	cl, [ebx]
  1865 00005095 08C9                <1> 	or	cl, cl ; 0 = free, >0 = process number
  1866 00005097 7415                <1> 	jz	short swpout_timer_page_3
  1867 00005099 8B4B0C              <1> 	mov	ecx, [ebx+12] ; response (signal return) address
  1868 0000509C 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; clear offset part (right 12 bits)
  1869                              <1> 				; of the response byte address, to
  1870                              <1> 				; get beginning of the page address)
  1871 000050A1 39C8                <1> 	cmp	eax, ecx
  1872 000050A3 7505                <1> 	jne	short swpout_timer_page_2 ; not same page
  1873                              <1> 	
  1874                              <1> 	; !same page!
  1875                              <1> 	;
  1876                              <1> 	; NOTE: // 19/05/2016 // - TRDOS 386 feature only ! -
  1877                              <1> 	; This page will be used by the kernel to put timer event
  1878                              <1> 	; response (signal return) byte at the requested address;
  1879                              <1> 	; in order to prevent a possible wrong write (while
  1880                              <1> 	; this page is swapped out) on physical memory,
  1881                              <1> 	; we must protect this page against to be swapped out!
  1882                              <1> 	;
  1883 000050A5 5B                  <1> 	pop	ebx ; ****
  1884 000050A6 59                  <1> 	pop	ecx ; ***
  1885 000050A7 5A                  <1> 	pop	edx ; **
  1886 000050A8 EBBF                <1> 	jmp	short swpout_1	; do not swap out this page !
  1887                              <1>  
  1888                              <1> swpout_timer_page_2:
  1889                              <1> 	; 07/06/2016
  1890 000050AA FECA                <1> 	dec	dl
  1891 000050AC 7405                <1> 	jz	short swpout_timer_page_4
  1892                              <1> swpout_timer_page_3:
  1893                              <1> 	;cmp	ebx, timer_set + 240 ; last timer event (15*16) 
  1894                              <1> 	;jnb	short swpout_timer_page_4
  1895 000050AE 83C310              <1> 	add	ebx, 16
  1896 000050B1 EBE0                <1> 	jmp	short swpout_timer_page_1	
  1897                              <1> 
  1898                              <1> swpout_timer_page_4:
  1899 000050B3 5B                  <1> 	pop	ebx ; ****
  1900 000050B4 59                  <1> 	pop	ecx ; ***
  1901                              <1> swpout_2:
  1902 000050B5 89DA                <1> 	mov	edx, ebx	       ; Page table entry address	
  1903 000050B7 89C3                <1> 	mov	ebx, eax	       ; Buffer (Page) Address				
  1904                              <1> 	;
  1905 000050B9 E8A6010000          <1> 	call	link_swap_block
  1906 000050BE 7304                <1> 	jnc	short swpout_3	       ; It may not be needed here	
  1907                              <1> 				       ; because [swpd_free] value
  1908                              <1> 				       ; was checked at the beginging. 	
  1909 000050C0 5A                  <1> 	pop	edx ; **
  1910 000050C1 5B                  <1> 	pop	ebx ; *
  1911 000050C2 EB33                <1> 	jmp	short swpout_nfspc_err 
  1912                              <1> swpout_3:
  1913 000050C4 A900000080          <1> 	test	eax, 80000000h ; test bit 31 (this may not be needed!)
  1914 000050C9 752C                <1> 	jnz	short swpout_nfspc_err  ; 10/06/2016 (bit 31 = 1 !)
  1915                              <1> 	;	
  1916 000050CB 56                  <1> 	push	esi ; **
  1917 000050CC 51                  <1> 	push	ecx ; ***
  1918 000050CD 50                  <1> 	push	eax ; sector address ; (31 bit !, bit 31 = 0)
  1919 000050CE 8B35[62050300]      <1> 	mov	esi, [swp_drv]	
  1920 000050D4 B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1921                              <1> 		; Note: Even if corresponding physical disk's sector 
  1922                              <1> 		; size different than 512 bytes, logical disk sector
  1923                              <1> 		; size is 512 bytes and disk writing procedure
  1924                              <1> 		; will be performed for writing 4096 bytes
  1925                              <1> 		; (2*2048, 8*512). 
  1926                              <1> 	; ESI = Logical disk description table address
  1927                              <1> 	; EBX = Buffer (Page) address
  1928                              <1> 	; EAX = Sector adress (offset address, logical sector number)
  1929                              <1> 	; ECX = Sector count ; 8 sectors
  1930                              <1> 	; edx = PTE address
  1931 000050D9 E8E2010000          <1> 	call	logical_disk_write
  1932                              <1> 	; edx = PTE address
  1933 000050DE 59                  <1> 	pop	ecx ; sector address	
  1934 000050DF 730C                <1> 	jnc	short swpout_write_ok
  1935                              <1> 	;
  1936                              <1> 	;; call	unlink_swap_block ; this block must be left as 'in use'
  1937                              <1> swpout_dw_err:
  1938 000050E1 B82C000000          <1> 	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
  1939 000050E6 A3[C8030300]        <1> 	mov	[u.error], eax
  1940 000050EB EB06                <1> 	jmp	short swpout_retn
  1941                              <1> 	;
  1942                              <1> swpout_write_ok:
  1943                              <1> 	; EBX = Buffer (page) address
  1944                              <1> 	; EDX = Page Table Entry address
  1945                              <1> 	; ECX = Swap disk sector (file block) address (31 bit)
  1946 000050ED D1E1                <1> 	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
  1947 000050EF 890A                <1> 	mov 	[edx], ecx 
  1948                              <1> 		; bit 0 = 0 (swapped page)
  1949 000050F1 89D8                <1> 	mov	eax, ebx
  1950                              <1> swpout_retn:
  1951 000050F3 59                  <1> 	pop	ecx ; ***
  1952 000050F4 5E                  <1> 	pop	esi ; **
  1953 000050F5 5B                  <1> 	pop	ebx ; *
  1954 000050F6 C3                  <1> 	retn
  1955                              <1> 
  1956                              <1> ;swpout_dnp_err:
  1957                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
  1958                              <1> ;	jmp	short swpout_err_retn
  1959                              <1> swpout_nfspc_err:
  1960 000050F7 B82B000000          <1> 	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
  1961                              <1> swpout_err_retn:
  1962 000050FC A3[C8030300]        <1> 	mov	[u.error], eax
  1963                              <1> 	;stc
  1964 00005101 C3                  <1> 	retn
  1965                              <1> swpout_npts_err:
  1966 00005102 B82D000000          <1> 	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
  1967 00005107 5B                  <1> 	pop	ebx
  1968 00005108 EBF2                <1> 	jmp	short swpout_err_retn
  1969                              <1> swpout_im_err:
  1970 0000510A B804000000          <1> 	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
  1971 0000510F EBEB                <1> 	jmp	short swpout_err_retn
  1972                              <1> 
  1973                              <1> swap_queue_shift:
  1974                              <1> 	; 26/03/2017
  1975                              <1> 	; 10/06/2016
  1976                              <1> 	; 09/06/2016 - TRDOS 386 (TRDOS v2.0)
  1977                              <1> 	; 23/10/2014 - 20/07/2015 (Retro UNIX 386 v1)
  1978                              <1> 	;
  1979                              <1> 	; INPUT ->
  1980                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
  1981                              <1> 	;	      and process number combination (bit 0 to 11)
  1982                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
  1983                              <1> 	;	
  1984                              <1> 	; OUTPUT ->
  1985                              <1> 	;	If EBX input > 0 
  1986                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  1987                              <1> 	; 	   from the tail to the head, up to entry offset
  1988                              <1> 	; 	   which points to EBX input value or nothing
  1989                              <1> 	;	   to do if EBX value is not found on the queue.
  1990                              <1> 	;	   (The entry -with EBX value- will be removed
  1991                              <1> 	;	   from the queue if it is found.)
  1992                              <1> 	;
  1993                              <1> 	;	   EAX = 0		
  1994                              <1> 	;
  1995                              <1> 	;	If EBX input = 0
  1996                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  1997                              <1> 	; 	   from the tail to the head, if the PTE address
  1998                              <1> 	;	   which is pointed in head of the queue is marked
  1999                              <1> 	;	   as "accessed" or it is marked as "non present".
  2000                              <1> 	;	   (If "accessed" flag of the PTE -which is pointed
  2001                              <1> 	;	   in the head- is set -to 1-, it will be reset
  2002                              <1> 	;	   -to 0- and then, the queue will be rotated 
  2003                              <1> 	;	   -without dropping pointer of the PTE from 
  2004                              <1> 	;	   the queue- for 4 bytes on head to tail direction.
  2005                              <1> 	;	   Pointer in the head will be moved into the tail,
  2006                              <1> 	;	   other PTEs will be shifted on head direction.)
  2007                              <1> 	;
  2008                              <1> 	;	   Swap queue will be shifted up to the first
  2009                              <1> 	;	   'present' or 'non accessed' page will be found
  2010                              <1> 	;	   (as pointed) on the queue head (then it will be
  2011                              <1>         ;          removed/dropped from the queue).
  2012                              <1> 	;
  2013                              <1> 	;	   EAX (> 0) = PTE value of the page which is
  2014                              <1> 	;		 (it's pointer -virtual address-) dropped
  2015                              <1> 	;		 (removed) from swap queue.
  2016                              <1> 	;	   EBX = PTE address of the page (if EAX > 0)
  2017                              <1> 	;	         which is (it's pointer -virtual address-)
  2018                              <1> 	;		 dropped (removed) from swap queue.
  2019                              <1> 	;
  2020                              <1> 	;	   EAX = 0 -> empty swap queue ! 
  2021                              <1> 	;
  2022                              <1> 	; Modified Registers -> EAX, EBX
  2023                              <1> 	;
  2024 00005111 0FB705[60050300]    <1> 	movzx   eax, word [swpq_count]  ; Max. 1024
  2025 00005118 6621C0              <1> 	and	ax, ax
  2026 0000511B 7431                <1> 	jz	short swpqs_retn
  2027 0000511D 57                  <1> 	push	edi
  2028 0000511E 56                  <1> 	push	esi
  2029 0000511F 51                  <1> 	push	ecx
  2030 00005120 BE00E00800          <1> 	mov	esi, swap_queue
  2031 00005125 89C1                <1> 	mov	ecx, eax
  2032 00005127 09DB                <1> 	or	ebx, ebx
  2033 00005129 7424                <1> 	jz	short swpqs_7
  2034                              <1> swpqs_1:
  2035 0000512B AD                  <1> 	lodsd
  2036 0000512C 39D8                <1> 	cmp	eax, ebx
  2037 0000512E 7406                <1> 	je	short swpqs_2
  2038 00005130 E2F9                <1> 	loop	swpqs_1
  2039                              <1> 	; 10/06/2016
  2040 00005132 29C0                <1> 	sub	eax, eax 
  2041 00005134 EB15                <1> 	jmp	short swpqs_6
  2042                              <1> swpqs_2:
  2043 00005136 89F7                <1> 	mov	edi, esi
  2044 00005138 83EF04              <1> 	sub 	edi, 4
  2045                              <1> swpqs_3:
  2046 0000513B 66FF0D[60050300]    <1> 	dec	word [swpq_count]
  2047 00005142 7403                <1> 	jz	short swpqs_5
  2048                              <1> swpqs_4:
  2049 00005144 49                  <1> 	dec 	ecx
  2050 00005145 F3A5                <1> 	rep	movsd	; shift up (to the head)
  2051                              <1> swpqs_5:
  2052 00005147 31C0                <1> 	xor	eax, eax
  2053 00005149 8907                <1> 	mov	[edi], eax
  2054                              <1> swpqs_6:
  2055 0000514B 59                  <1> 	pop	ecx
  2056 0000514C 5E                  <1> 	pop	esi
  2057 0000514D 5F                  <1> 	pop	edi
  2058                              <1> swpqs_retn:
  2059 0000514E C3                  <1> 	retn		
  2060                              <1> swpqs_7:
  2061 0000514F 89F7                <1> 	mov	edi, esi ; head
  2062 00005151 AD                  <1> 	lodsd
  2063                              <1> 	; 20/07/2015
  2064 00005152 89C3                <1> 	mov	ebx, eax
  2065 00005154 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF ; ~0FFFh 
  2066                              <1> 		      ; ebx = virtual address (at page boundary)	
  2067 0000515A 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 0FFFh
  2068                              <1> 		      ; ax = process number (1 to 4095)
  2069 0000515F 3A05[B3030300]      <1> 	cmp	al, [u.uno]
  2070                              <1> 		; Max. 16 (nproc) processes for Retro UNIX 386 v1
  2071 00005165 7507                <1> 	jne	short swpqs_8
  2072 00005167 A1[B8030300]        <1> 	mov	eax, [u.pgdir]
  2073 0000516C EB28                <1> 	jmp	short swpqs_9
  2074                              <1> swpqs_8:
  2075                              <1> 	; 09/06/2016
  2076 0000516E 80B8[AF000300]00    <1> 	cmp	byte [eax+p.stat-1], 0
  2077 00005175 76C4                <1> 	jna	short swpqs_3     ; free (or terminated) process
  2078 00005177 80B8[AF000300]02    <1> 	cmp	byte [eax+p.stat-1], 2 ; waiting
  2079 0000517E 77BB                <1> 	ja	short swpqs_3 	  ; zombie (3) or undefined ?	
  2080                              <1> 
  2081                              <1> 	;shl	ax, 2
  2082 00005180 C0E002              <1> 	shl	al, 2
  2083 00005183 8B80[BC000300]      <1> 	mov 	eax, [eax+p.upage-4]
  2084 00005189 09C0                <1> 	or	eax, eax
  2085 0000518B 74AE                <1> 	jz	short swpqs_3 ; invalid upage
  2086 0000518D 83C05C              <1> 	add	eax, u.pgdir - user
  2087                              <1> 			 ; u.pgdir value for the process
  2088                              <1> 			 ; is in [eax]
  2089 00005190 8B00                <1> 	mov	eax, [eax]
  2090 00005192 21C0                <1> 	and	eax, eax
  2091 00005194 74A5                <1> 	jz	short swpqs_3 ; invalid page directory
  2092                              <1> swpqs_9:
  2093 00005196 52                  <1> 	push	edx
  2094                              <1> 	; eax = page directory
  2095                              <1> 	; ebx = virtual address
  2096 00005197 E82BFBFFFF          <1> 	call	get_pte
  2097 0000519C 89D3                <1> 	mov	ebx, edx	; PTE address
  2098 0000519E 5A                  <1> 	pop	edx
  2099                              <1> 	; 10/06/2016
  2100 0000519F 723A                <1> 	jc	short swpqs_13 ; empty PDE
  2101                              <1> 	; EAX = PTE value
  2102 000051A1 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0 = 1
  2103 000051A3 7436                <1> 	jz	short swpqs_13  ; Drop non-present page
  2104                              <1> 			        ; from the queue (head)
  2105 000051A5 A802                <1> 	test	al, PTE_A_WRITE	; bit 1 = 0 (read only)
  2106 000051A7 7432                <1> 	jz	short swpqs_13  ; Drop read only page
  2107                              <1> 			        ; from the queue (head) 	
  2108                              <1> 	;test	al, PTE_A_ACCESS ; bit 5 = 1 (Accessed)
  2109                              <1> 	;jnz	short swpqs_11  ; present
  2110                              <1> 			        ; accessed page
  2111 000051A9 0FBAF005            <1>         btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
  2112 000051AD 7210                <1> 	jc	short swpqs_11  ; accessed page
  2113                              <1> 
  2114 000051AF 49                  <1> 	dec	ecx
  2115 000051B0 66890D[60050300]    <1> 	mov	[swpq_count], cx
  2116 000051B7 7402                <1>         jz      short swpqs_10
  2117                              <1> 		; esi = head + 4
  2118                              <1> 		; edi = head
  2119 000051B9 F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2120                              <1> swpqs_10:
  2121 000051BB 890F                <1> 	mov	[edi], ecx ; 0
  2122 000051BD EB8C                <1> 	jmp	short swpqs_6 ; 26/03/2017
  2123                              <1> 
  2124                              <1> swpqs_11:
  2125 000051BF 8903                <1> 	mov	[ebx], eax     ; save changed attribute
  2126                              <1> 	; Rotation (head -> tail)
  2127 000051C1 49                  <1> 	dec	ecx     ; entry count -> last entry number		
  2128 000051C2 74F7                <1> 	jz	short swpqs_10
  2129                              <1> 		; esi = head + 4
  2130                              <1> 		; edi = head
  2131 000051C4 8B07                <1> 	mov	eax, [edi] ; 20/07/2015
  2132 000051C6 F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2133 000051C8 8907                <1> 	mov	[edi], eax ; head -> tail ; [k] = [1]
  2134                              <1> 
  2135 000051CA 668B0D[60050300]    <1> 	mov	cx, [swpq_count]
  2136                              <1> 
  2137                              <1> swpqs_12:
  2138 000051D1 BE00E00800          <1> 	mov	esi, swap_queue ; head
  2139 000051D6 E974FFFFFF          <1>         jmp     swpqs_7
  2140                              <1> 
  2141                              <1> swpqs_13:
  2142 000051DB 49                  <1> 	dec	ecx
  2143 000051DC 66890D[60050300]    <1> 	mov	[swpq_count], cx
  2144 000051E3 0F845EFFFFFF        <1>         jz      swpqs_5
  2145 000051E9 EBE6                <1> 	jmp	short swpqs_12
  2146                              <1> 
  2147                              <1> add_to_swap_queue:
  2148                              <1> ; temporary - 16/09/2015
  2149 000051EB C3                  <1> retn
  2150                              <1> 	; 20/02/2017
  2151                              <1> 	; 20/07/2015
  2152                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2153                              <1> 	;
  2154                              <1> 	; Adds new page to swap queue
  2155                              <1> 	; (page directories and page tables must not be added
  2156                              <1> 	; to swap queue)	
  2157                              <1> 	;
  2158                              <1> 	; INPUT ->
  2159                              <1> 	;	EBX = Linear (Virtual) addr for current process
  2160                              <1> 	;	[u.uno]
  2161                              <1> 	;	20/02/2017
  2162                              <1> 	;	(Linear address = CORE + user's virtual address)
  2163                              <1> 	;
  2164                              <1> 	; OUTPUT ->
  2165                              <1> 	;	EAX = [swpq_count]
  2166                              <1> 	;	      (after the PTE has been added)
  2167                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
  2168                              <1> 	;	      the PTE could not be added.
  2169                              <1> 	;
  2170                              <1> 	; Modified Registers -> EAX
  2171                              <1> 	;
  2172 000051EC 53                  <1> 	push	ebx
  2173 000051ED 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  2174 000051F2 8A1D[B3030300]      <1> 	mov	bl, [u.uno] ; current process number
  2175 000051F8 E814FFFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
  2176                              <1> 				 ; it is already on the queue
  2177                              <1> 		; then add it to the tail of the queue
  2178 000051FD 0FB705[60050300]    <1> 	movzx	eax, word [swpq_count]
  2179 00005204 663D0004            <1> 	cmp	ax, 1024
  2180 00005208 7205                <1> 	jb	short atsq_1
  2181 0000520A 6629C0              <1> 	sub	ax, ax
  2182 0000520D 5B                  <1> 	pop	ebx
  2183 0000520E C3                  <1> 	retn
  2184                              <1> atsq_1:
  2185 0000520F 56                  <1> 	push	esi
  2186 00005210 BE00E00800          <1> 	mov	esi, swap_queue
  2187 00005215 6621C0              <1> 	and	ax, ax
  2188 00005218 740A                <1> 	jz	short atsq_2
  2189 0000521A 66C1E002            <1> 	shl	ax, 2	; convert to offset
  2190 0000521E 01C6                <1> 	add	esi, eax
  2191 00005220 66C1E802            <1> 	shr	ax, 2
  2192                              <1> atsq_2:
  2193 00005224 6640                <1> 	inc	ax
  2194 00005226 891E                <1> 	mov	[esi], ebx ; Virtual address + [u.uno] combination
  2195 00005228 66A3[60050300]      <1> 	mov	[swpq_count], ax
  2196 0000522E 5E                  <1> 	pop	esi
  2197 0000522F 5B                  <1> 	pop	ebx
  2198 00005230 C3                  <1> 	retn
  2199                              <1> 
  2200                              <1> unlink_swap_block:
  2201                              <1> 	; 15/09/2015
  2202                              <1> 	; 30/04/2015
  2203                              <1> 	; 18/04/2015
  2204                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2205                              <1> 	;
  2206                              <1> 	; INPUT -> 
  2207                              <1> 	;	EAX = swap disk/file offset address
  2208                              <1> 	;	      (bit 1 to bit 31)
  2209                              <1> 	; OUTPUT ->
  2210                              <1> 	;	[swpd_free] is increased
  2211                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
  2212                              <1> 	;
  2213                              <1> 	; Modified Registers -> EAX
  2214                              <1> 	;
  2215 00005231 53                  <1> 	push	ebx
  2216 00005232 52                  <1> 	push	edx
  2217                              <1> 	;
  2218 00005233 C1E804              <1> 	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
  2219                              <1> 				     ; 3 bits right
  2220                              <1> 				     ; to get swap block/page number
  2221 00005236 89C2                <1> 	mov	edx, eax
  2222                              <1> 	; 15/09/2015
  2223 00005238 C1EA03              <1> 	shr	edx, 3		     ; to get offset to S.A.T.
  2224                              <1> 				     ; (1 allocation bit = 1 page)
  2225                              <1> 				     ; (1 allocation bytes = 8 pages)
  2226 0000523B 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2227                              <1> 				     ; (to get 32 bit position)			
  2228                              <1> 	;
  2229 0000523E BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table address
  2230 00005243 01D3                <1> 	add	ebx, edx
  2231 00005245 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
  2232                              <1> 				     ; (allocation bit position)	 
  2233 00005248 3B05[6E050300]      <1> 	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
  2234                              <1> 				     ; than the address in 'swpd_next' ?
  2235                              <1> 				     ; (next/first free block value)		
  2236 0000524E 7305                <1> 	jnb	short uswpbl_1	     ; no	
  2237 00005250 A3[6E050300]        <1> 	mov	[swpd_next], eax     ; yes	
  2238                              <1> uswpbl_1:
  2239 00005255 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate block
  2240                              <1> 				     ; set relevant bit to 1.
  2241                              <1> 				     ; set CF to the previous bit value	
  2242 00005258 F5                  <1> 	cmc			     ; complement carry flag	
  2243 00005259 7206                <1> 	jc	short uswpbl_2	     ; do not increase swfd_free count
  2244                              <1> 				     ; if the block is already deallocated
  2245                              <1> 				     ; before.	
  2246 0000525B FF05[6A050300]      <1>         inc     dword [swpd_free]
  2247                              <1> uswpbl_2:
  2248 00005261 5A                  <1> 	pop	edx
  2249 00005262 5B                  <1> 	pop	ebx
  2250 00005263 C3                  <1> 	retn
  2251                              <1> 
  2252                              <1> link_swap_block:
  2253                              <1> 	; 01/07/2015
  2254                              <1> 	; 18/04/2015
  2255                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2256                              <1> 	;
  2257                              <1> 	; INPUT -> none
  2258                              <1> 	;
  2259                              <1> 	; OUTPUT ->
  2260                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
  2261                              <1> 	;	      in sectors (corresponding 
  2262                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
  2263                              <1> 	;
  2264                              <1> 	;	CF = 1 and EAX = 0 
  2265                              <1> 	; 		   if there is not a free block to be allocated	
  2266                              <1> 	;
  2267                              <1> 	; Modified Registers -> none (except EAX)
  2268                              <1> 	;
  2269                              <1> 
  2270                              <1> 	;mov	eax, [swpd_free]
  2271                              <1> 	;and	eax, eax
  2272                              <1> 	;jz	short out_of_swpspc
  2273                              <1> 	;
  2274 00005264 53                  <1> 	push	ebx
  2275 00005265 51                  <1> 	push	ecx
  2276                              <1> 	;
  2277 00005266 BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
  2278 0000526B 89D9                <1> 	mov	ecx, ebx
  2279 0000526D 031D[6E050300]      <1> 	add	ebx, [swpd_next] ; Free block searching starts from here
  2280                              <1> 				 ; next_free_swap_block >> 5
  2281 00005273 030D[72050300]      <1> 	add	ecx, [swpd_last] ; Free block searching ends here
  2282                              <1> 				 ; (total_swap_blocks - 1) >> 5
  2283                              <1> lswbl_scan:
  2284 00005279 39CB                <1> 	cmp	ebx, ecx
  2285 0000527B 770A                <1> 	ja	short lswbl_notfound
  2286                              <1> 	;
  2287 0000527D 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
  2288                              <1> 			   ; Clears ZF if a bit is found set (1) and 
  2289                              <1> 			   ; loads the destination with an index to
  2290                              <1> 			   ; first set bit. (0 -> 31) 
  2291                              <1> 			   ; Sets ZF to 1 if no bits are found set.
  2292                              <1> 	; 01/07/2015
  2293 00005280 751C                <1> 	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
  2294                              <1> 			 ;
  2295                              <1> 			 ; NOTE:  a Swap Disk Allocation Table bit 
  2296                              <1> 			 ;	  with value of 1 means 
  2297                              <1> 			 ;	  the corresponding page is free 
  2298                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
  2299 00005282 83C304              <1> 	add	ebx, 4
  2300                              <1> 			 ; We return back for searching next page block
  2301                              <1> 			 ; NOTE: [swpd_free] is not ZERO; so, 
  2302                              <1> 			 ;	 we always will find at least 1 free block here.
  2303 00005285 EBF2                <1> 	jmp    	short lswbl_scan
  2304                              <1> 	;
  2305                              <1> lswbl_notfound:	
  2306 00005287 81E900000D00        <1> 	sub	ecx, swap_alloc_table
  2307 0000528D 890D[6E050300]      <1> 	mov	[swpd_next], ecx ; next/first free page = last page 
  2308                              <1> 				 ; (unlink_swap_block procedure will change it)
  2309 00005293 31C0                <1> 	xor	eax, eax
  2310 00005295 A3[6A050300]        <1> 	mov	[swpd_free], eax
  2311 0000529A F9                  <1> 	stc
  2312                              <1> lswbl_ok:
  2313 0000529B 59                  <1> 	pop	ecx
  2314 0000529C 5B                  <1> 	pop	ebx
  2315 0000529D C3                  <1> 	retn
  2316                              <1> 	;
  2317                              <1> ;out_of_swpspc:
  2318                              <1> ;	stc
  2319                              <1> ;	retn
  2320                              <1> 
  2321                              <1> lswbl_found:
  2322 0000529E 89D9                <1> 	mov	ecx, ebx
  2323 000052A0 81E900000D00        <1> 	sub	ecx, swap_alloc_table
  2324 000052A6 890D[6E050300]      <1> 	mov	[swpd_next], ecx ; Set first free block searching start
  2325                              <1> 				 ; address/offset (to the next)
  2326 000052AC FF0D[6A050300]      <1>         dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
  2327                              <1> 	;
  2328 000052B2 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
  2329                              <1> 				 ; is copied into the Carry Flag and then cleared
  2330                              <1> 				 ; in the destination.
  2331                              <1> 				 ;
  2332                              <1> 				 ; Reset the bit which is corresponding to the 
  2333                              <1> 				 ; (just) allocated block.
  2334 000052B5 C1E105              <1> 	shl	ecx, 5		 ; (block offset * 32) + block index
  2335 000052B8 01C8                <1> 	add	eax, ecx	 ; = block number
  2336 000052BA C1E003              <1> 	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
  2337                              <1> 				 ; 1 block =  8 sectors
  2338                              <1> 	;
  2339                              <1> 	; EAX = offset address of swap disk/file sector (beginning of the block)
  2340                              <1> 	;
  2341                              <1> 	; NOTE: The relevant page table entry will be updated
  2342                              <1> 	;       according to this EAX value...
  2343                              <1> 	;
  2344 000052BD EBDC                <1> 	jmp	short lswbl_ok
  2345                              <1> 
  2346                              <1> logical_disk_read:
  2347                              <1> 	; 20/07/2015
  2348                              <1> 	; 09/03/2015 (temporary code here)
  2349                              <1> 	;
  2350                              <1> 	; INPUT ->
  2351                              <1> 	; 	ESI = Logical disk description table address
  2352                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2353                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2354                              <1> 	; 	ECX = Sector count
  2355                              <1> 	;
  2356                              <1> 	;
  2357 000052BF C3                  <1> 	retn
  2358                              <1> 
  2359                              <1> logical_disk_write:
  2360                              <1> 	; 20/07/2015
  2361                              <1> 	; 09/03/2015 (temporary code here)
  2362                              <1> 	;
  2363                              <1> 	; INPUT ->
  2364                              <1> 	; 	ESI = Logical disk description table address
  2365                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2366                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2367                              <1> 	; 	ECX = Sector count
  2368                              <1> 	;
  2369 000052C0 C3                  <1> 	retn
  2370                              <1> 
  2371                              <1> get_physical_addr:
  2372                              <1> 	; 26/03/2017
  2373                              <1> 	; 20/02/2017
  2374                              <1> 	; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  2375                              <1> 	; 18/10/2015
  2376                              <1> 	; 29/07/2015
  2377                              <1> 	; 20/07/2015
  2378                              <1> 	; 04/06/2015
  2379                              <1> 	; 20/05/2015
  2380                              <1> 	; 28/04/2015
  2381                              <1> 	; 18/04/2015
  2382                              <1> 	; Get physical address
  2383                              <1> 	;     (allocates a new page for user if it is not present)
  2384                              <1> 	;	
  2385                              <1> 	; (This subroutine is needed for mapping user's virtual 
  2386                              <1> 	; (buffer) address to physical address (of the buffer).)
  2387                              <1> 	; ('sys write', 'sys read' system calls...)
  2388                              <1> 	;
  2389                              <1> 	; INPUT ->
  2390                              <1> 	;	EBX = virtual address
  2391                              <1> 	;	u.pgdir = page directory (physical) address
  2392                              <1> 	;
  2393                              <1> 	; OUTPUT ->
  2394                              <1> 	;	EAX = physical address 
  2395                              <1> 	;	EBX = linear address	
  2396                              <1> 	;	EDX = physical address of the page frame
  2397                              <1> 	;	      (with attribute bits)
  2398                              <1> 	;	ECX = byte count within the page frame
  2399                              <1> 	;
  2400                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
  2401                              <1> 	;
  2402 000052C1 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
  2403                              <1> get_physical_addr_x: ; 27/05/2016
  2404 000052C7 A1[B8030300]        <1> 	mov	eax, [u.pgdir]
  2405 000052CC E8F6F9FFFF          <1> 	call	get_pte
  2406                              <1> 		; EDX = Page table entry address (if CF=0)
  2407                              <1> 	        ;       Page directory entry address (if CF=1)
  2408                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  2409                              <1> 		; EAX = Page table entry value (page address)
  2410                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
  2411 000052D1 731C                <1> 	jnc	short gpa_1
  2412                              <1> 	;
  2413 000052D3 E8D4F8FFFF          <1> 	call	allocate_page
  2414 000052D8 7248                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
  2415                              <1> gpa_0:
  2416 000052DA E847F9FFFF          <1> 	call 	clear_page
  2417                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  2418 000052DF 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  2419                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  2420                              <1> 			   ; (user, writable, present page)	
  2421 000052E1 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  2422 000052E3 A1[B8030300]        <1> 	mov	eax, [u.pgdir]	
  2423 000052E8 E8DAF9FFFF          <1> 	call	get_pte
  2424 000052ED 7233                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2425                              <1> gpa_1:
  2426                              <1> 	; EAX = PTE value, EDX = PTE address
  2427 000052EF A801                <1> 	test 	al, PTE_A_PRESENT
  2428 000052F1 751F                <1> 	jnz	short gpa_3 ; 26/03/2017
  2429 000052F3 09C0                <1> 	or	eax, eax
  2430 000052F5 7456                <1> 	jz	short gpa_7  ; Allocate a new page
  2431                              <1> 	; 20/07/2015
  2432 000052F7 55                  <1> 	push	ebp
  2433 000052F8 89DD                <1> 	mov	ebp, ebx ; virtual (linear) address
  2434                              <1> 	; reload swapped page
  2435 000052FA E878000000          <1> 	call	reload_page ; 28/04/2015
  2436 000052FF 5D                  <1> 	pop	ebp
  2437 00005300 724A                <1> 	jc	short gpa_retn
  2438                              <1> gpa_2:
  2439                              <1> 	; 26/03/2017
  2440                              <1> 	; 20/02/2017
  2441                              <1> 	; If a page will contain a Signal Response Byte
  2442                              <1> 	; it must not be swapped out, because
  2443                              <1> 	; timer service or irq callback service
  2444                              <1> 	; will write a signal return/response byte 
  2445                              <1> 	; directly by using physical address of Signal
  2446                              <1> 	; Response Byte.(Even if process is not running,
  2447                              <1> 	; or it is running with swapped out pages.)
  2448                              <1> 	;
  2449                              <1> 	; 'no_page_swap' will be set by 'systimer' or
  2450                              <1> 	; 'syscalbac' sistem functions/calls. (*)
  2451                              <1> 	;
  2452 00005302 803D[726A0100]00    <1> 	cmp	byte [no_page_swap], 0
  2453 00005309 761D                <1> 	jna	short gpa_4 ; this page can be swapped out
  2454                              <1> 	; this page must not be swapped out
  2455                              <1> 	; but 'no_page_swap' must be reset here
  2456                              <1> 	; imediately for other callers (*)
  2457                              <1> 	; (otherwise, swap queue would not be long enough) 
  2458 0000530B E84B000000          <1> 	call	gpa_8 ; 26/03/2017
  2459 00005310 EB1D                <1> 	jmp	short gpa_5
  2460                              <1> gpa_3: 
  2461                              <1> 	; 26/03/2017
  2462 00005312 803D[726A0100]00    <1> 	cmp	byte [no_page_swap], 0
  2463 00005319 7618                <1> 	jna	short gpa_6 ; this page can be swapped out
  2464 0000531B E83B000000          <1> 	call	gpa_8
  2465 00005320 EB11                <1> 	jmp	short gpa_6
  2466                              <1> 
  2467                              <1> gpa_im_err:	
  2468 00005322 B804000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2469                              <1> 				  ; Major error = 0 (No protection fault)	
  2470 00005327 C3                  <1> 	retn
  2471                              <1> gpa_4:
  2472                              <1> 	; 20/07/2015
  2473                              <1> 	; 20/05/2015
  2474                              <1> 	; add this page to swap queue
  2475 00005328 50                  <1> 	push	eax 
  2476                              <1> 	; EBX = Linear (CORE+virtual) address ; 20/02/2017 
  2477 00005329 E8BDFEFFFF          <1> 	call 	add_to_swap_queue
  2478 0000532E 58                  <1> 	pop	eax
  2479                              <1> gpa_5:
  2480                              <1> 		; PTE address in EDX
  2481                              <1> 		; virtual address in EBX
  2482                              <1> 	; EAX = memory page address
  2483 0000532F 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
  2484                              <1> 				  ; present flag, bit 0 = 1
  2485                              <1> 				  ; user flag, bit 2 = 1	
  2486                              <1> 				  ; writable flag, bit 1 = 1
  2487 00005331 8902                <1> 	mov	[edx], eax  ; Update PTE value
  2488                              <1> gpa_6:
  2489                              <1> 	; 18/10/2015
  2490 00005333 89D9                <1> 	mov	ecx, ebx
  2491 00005335 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
  2492 0000533B 89C2                <1> 	mov 	edx, eax
  2493 0000533D 662500F0            <1> 	and	ax, PTE_A_CLEAR
  2494 00005341 01C8                <1> 	add	eax, ecx
  2495 00005343 F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
  2496 00005345 81C100100000        <1> 	add	ecx, PAGE_SIZE
  2497 0000534B F8                  <1> 	clc
  2498                              <1> gpa_retn:
  2499 0000534C C3                  <1> 	retn
  2500                              <1> gpa_7:	
  2501 0000534D E85AF8FFFF          <1> 	call	allocate_page
  2502 00005352 72CE                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2503 00005354 E8CDF8FFFF          <1> 	call	clear_page
  2504 00005359 EBA7                <1> 	jmp	short gpa_2
  2505                              <1> 
  2506                              <1> gpa_8: ; 26/03/2017
  2507 0000535B C605[726A0100]00    <1> 	mov	byte [no_page_swap], 0
  2508 00005362 53                  <1> 	push	ebx
  2509 00005363 50                  <1> 	push	eax ; 26/03/2017
  2510 00005364 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  2511 00005369 8A1D[B3030300]      <1> 	mov	bl, [u.uno] ; current process number
  2512 0000536F E89DFDFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
  2513                              <1> 				 ; it is already on the queue
  2514 00005374 58                  <1> 	pop	eax ; 26/03/2017
  2515 00005375 5B                  <1> 	pop	ebx
  2516 00005376 C3                  <1> 	retn
  2517                              <1> 
  2518                              <1> reload_page:
  2519                              <1> 	; 20/07/2015
  2520                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
  2521                              <1> 	;
  2522                              <1> 	; Reload (Restore) swapped page at memory
  2523                              <1> 	;
  2524                              <1> 	; INPUT -> 
  2525                              <1> 	;	EBP = Virtual (linear) memory address
  2526                              <1> 	;	EAX = PTE value (swap disk sector address)
  2527                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
  2528                              <1> 	; OUTPUT ->
  2529                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
  2530                              <1> 	;
  2531                              <1> 	;	CF = 1 and EAX = error code
  2532                              <1> 	;
  2533                              <1> 	; Modified Registers -> none (except EAX)
  2534                              <1> 	;
  2535 00005377 D1E8                <1> 	shr	eax, 1   ; Convert PTE value to swap disk address 
  2536 00005379 53                  <1> 	push	ebx      ;
  2537 0000537A 89C3                <1> 	mov	ebx, eax ; Swap disk (offset) address	
  2538 0000537C E82BF8FFFF          <1> 	call	allocate_page
  2539 00005381 720C                <1> 	jc	short rlp_im_err
  2540 00005383 93                  <1> 	xchg 	eax, ebx	
  2541                              <1> 	; EBX = Physical memory (page) address
  2542                              <1> 	; EAX = Swap disk (offset) address
  2543                              <1> 	; EBP = Virtual (linear) memory address
  2544 00005384 E862FCFFFF          <1> 	call	swap_in
  2545 00005389 720B                <1> 	jc	short rlp_swp_err  ; (swap disk/file read error)
  2546 0000538B 89D8                <1> 	mov	eax, ebx	
  2547                              <1> rlp_retn:
  2548 0000538D 5B                  <1> 	pop	ebx
  2549 0000538E C3                  <1> 	retn
  2550                              <1> 	
  2551                              <1> rlp_im_err:	
  2552 0000538F B804000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2553                              <1> 				  ; Major error = 0 (No protection fault)	
  2554 00005394 EBF7                <1> 	jmp	short rlp_retn
  2555                              <1> 
  2556                              <1> rlp_swp_err:
  2557 00005396 B828000000          <1> 	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
  2558 0000539B EBF0                <1> 	jmp	short rlp_retn
  2559                              <1> 
  2560                              <1> 
  2561                              <1> copy_page_dir:
  2562                              <1> 	; 19/09/2015
  2563                              <1> 	; temporary - 07/09/2015
  2564                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2565                              <1> 	;
  2566                              <1> 	; INPUT -> 
  2567                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
  2568                              <1> 	;		    page directory.
  2569                              <1> 	; OUTPUT ->
  2570                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
  2571                              <1> 	;	       page directory.
  2572                              <1> 	;	(New page directory with new page table entries.)
  2573                              <1> 	;	(New page tables with read only copies of the parent's
  2574                              <1> 	;	pages.)
  2575                              <1> 	;	EAX = 0 -> Error (CF = 1)
  2576                              <1> 	;
  2577                              <1> 	; Modified Registers -> none (except EAX)
  2578                              <1> 	;
  2579 0000539D E80AF8FFFF          <1> 	call	allocate_page
  2580 000053A2 723E                <1> 	jc	short cpd_err
  2581                              <1> 	;
  2582 000053A4 55                  <1> 	push	ebp ; 20/07/2015
  2583 000053A5 56                  <1> 	push	esi
  2584 000053A6 57                  <1> 	push	edi
  2585 000053A7 53                  <1> 	push	ebx
  2586 000053A8 51                  <1> 	push	ecx
  2587 000053A9 8B35[B8030300]      <1> 	mov	esi, [u.pgdir]
  2588 000053AF 89C7                <1> 	mov	edi, eax
  2589 000053B1 50                  <1> 	push	eax ; save child's page directory address
  2590                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
  2591                              <1> 	; (use same system space for all user page tables) 
  2592 000053B2 A5                  <1> 	movsd
  2593 000053B3 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  2594 000053B8 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  2595                              <1> cpd_0:	
  2596 000053BD AD                  <1> 	lodsd
  2597                              <1> 	;or	eax, eax
  2598                              <1>         ;jnz     short cpd_1
  2599 000053BE A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  2600 000053C0 7508                <1> 	jnz	short cpd_1
  2601                              <1>  	; (virtual address at the end of the page table)	
  2602 000053C2 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  2603 000053C8 EB0F                <1> 	jmp	short cpd_2
  2604                              <1> cpd_1:	
  2605 000053CA 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  2606 000053CE 89C3                <1> 	mov	ebx, eax
  2607                              <1> 	; EBX = Parent's page table address
  2608 000053D0 E81F000000          <1> 	call	copy_page_table
  2609 000053D5 720C                <1> 	jc	short cpd_p_err
  2610                              <1> 	; EAX = Child's page table address
  2611 000053D7 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  2612                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  2613                              <1> 			 ; (present, writable, user)
  2614                              <1> cpd_2:
  2615 000053D9 AB                  <1> 	stosd
  2616 000053DA E2E1                <1> 	loop	cpd_0
  2617                              <1> 	;
  2618 000053DC 58                  <1> 	pop	eax  ; restore child's page directory address
  2619                              <1> cpd_3:
  2620 000053DD 59                  <1> 	pop	ecx
  2621 000053DE 5B                  <1> 	pop	ebx
  2622 000053DF 5F                  <1> 	pop	edi
  2623 000053E0 5E                  <1> 	pop	esi
  2624 000053E1 5D                  <1> 	pop	ebp
  2625                              <1> cpd_err:
  2626 000053E2 C3                  <1> 	retn
  2627                              <1> cpd_p_err:
  2628                              <1> 	; release the allocated pages missing (recover free space)
  2629 000053E3 58                  <1> 	pop	eax  ; the new page directory address (physical)
  2630 000053E4 8B1D[B8030300]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  2631 000053EA E8F6F8FFFF          <1> 	call 	deallocate_page_dir
  2632 000053EF 29C0                <1> 	sub	eax, eax ; 0
  2633 000053F1 F9                  <1> 	stc
  2634 000053F2 EBE9                <1> 	jmp	short cpd_3	
  2635                              <1> 
  2636                              <1> copy_page_table:
  2637                              <1> 	; 19/09/2015
  2638                              <1> 	; temporary - 07/09/2015
  2639                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2640                              <1> 	;
  2641                              <1> 	; INPUT -> 
  2642                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
  2643                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
  2644                              <1> 	; OUTPUT ->
  2645                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  2646                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
  2647                              <1> 	;	CF = 1 -> error 
  2648                              <1> 	;
  2649                              <1> 	; Modified Registers -> EBP (except EAX)
  2650                              <1> 	;
  2651 000053F4 E8B3F7FFFF          <1> 	call	allocate_page
  2652 000053F9 725A                <1> 	jc	short cpt_err
  2653                              <1> 	;
  2654 000053FB 50                  <1> 	push	eax ; *
  2655                              <1> 	;push 	ebx
  2656 000053FC 56                  <1> 	push	esi
  2657 000053FD 57                  <1> 	push	edi
  2658 000053FE 52                  <1> 	push	edx
  2659 000053FF 51                  <1> 	push	ecx
  2660                              <1> 	;
  2661 00005400 89DE                <1> 	mov	esi, ebx
  2662 00005402 89C7                <1> 	mov	edi, eax
  2663 00005404 89C2                <1> 	mov	edx, eax
  2664 00005406 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  2665                              <1> cpt_0:
  2666 0000540C AD                  <1> 	lodsd
  2667 0000540D A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
  2668 0000540F 750B                <1> 	jnz	short cpt_1
  2669 00005411 21C0                <1> 	and	eax, eax
  2670 00005413 7430                <1> 	jz	short cpt_2
  2671                              <1> 	; ebp = virtual (linear) address of the memory page
  2672 00005415 E85DFFFFFF          <1> 	call	reload_page ; 28/04/2015
  2673 0000541A 7234                <1> 	jc	short cpt_p_err
  2674                              <1> cpt_1:
  2675 0000541C 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  2676 00005420 89C1                <1> 	mov	ecx, eax
  2677                              <1> 	; Allocate a new page for the child process
  2678 00005422 E885F7FFFF          <1> 	call	allocate_page
  2679 00005427 7227                <1> 	jc	short cpt_p_err
  2680 00005429 57                  <1> 	push	edi
  2681 0000542A 56                  <1> 	push	esi
  2682 0000542B 89CE                <1> 	mov	esi, ecx
  2683 0000542D 89C7                <1> 	mov	edi, eax
  2684 0000542F B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  2685 00005434 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  2686 00005436 5E                  <1> 	pop	esi
  2687 00005437 5F                  <1> 	pop	edi
  2688                              <1> 	; 
  2689 00005438 53                  <1> 	push	ebx
  2690 00005439 50                  <1> 	push	eax
  2691 0000543A 89EB                <1> 	mov	ebx, ebp
  2692                              <1> 	; ebx = virtual address of the memory page
  2693 0000543C E8AAFDFFFF          <1> 	call	add_to_swap_queue
  2694 00005441 58                  <1> 	pop	eax
  2695 00005442 5B                  <1> 	pop	ebx
  2696                              <1> 	;
  2697                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  2698 00005443 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  2699                              <1> cpt_2:
  2700 00005445 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  2701                              <1> 	;
  2702 00005446 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  2703                              <1> 	;
  2704 0000544C 39D7                <1> 	cmp	edi, edx
  2705 0000544E 72BC                <1> 	jb	short cpt_0
  2706                              <1> cpt_p_err:
  2707 00005450 59                  <1> 	pop	ecx
  2708 00005451 5A                  <1> 	pop	edx
  2709 00005452 5F                  <1> 	pop	edi
  2710 00005453 5E                  <1> 	pop	esi
  2711                              <1> 	;pop	ebx
  2712 00005454 58                  <1> 	pop	eax ; *
  2713                              <1> cpt_err:
  2714 00005455 C3                  <1> 	retn
  2715                              <1> 
  2716                              <1> allocate_memory_block:
  2717                              <1> 	; 01/05/2017
  2718                              <1> 	; 28/04/2017
  2719                              <1> 	; 25/04/2017
  2720                              <1> 	; 01/04/2016, 02/04/2016, 03/04/2016
  2721                              <1> 	; 13/03/2016, 14/03/2016
  2722                              <1> 	; 12/03/2016 (TRDOS 386 = TRDOS v2.0)
  2723                              <1> 	; Allocating contiguous memory pages (in the kernel's memory space)
  2724                              <1> 	;
  2725                              <1> 	; INPUT -> 
  2726                              <1> 	;	EAX = Beginning address (physical)
  2727                              <1> 	;	EAX = 0 -> Allocate memory block from the first proper aperture	
  2728                              <1> 	;	ECX = Number of bytes to be allocated
  2729                              <1> 	;
  2730                              <1> 	; OUTPUT ->
  2731                              <1> 	; 	1) cf = 0 -> successful
  2732                              <1> 	;	EAX = Beginning (physical) address of the allocated memory block
  2733                              <1> 	;	ECX = Number of allocated bytes (rounded up to page borders) 
  2734                              <1> 	;	2) cf = 1 -> unsuccessful
  2735                              <1> 	;	 2.1) If EAX > 0 -> 
  2736                              <1> 	;	      (Number of requested pages is more than # of free pages
  2737                              <1> 	;	       but contiguous free pages -the aperture- is not enough!)	   	
  2738                              <1> 	;	      EAX = Beginning address of available aperture
  2739                              <1> 	;		    (one of all aperture with max. aperture size/length)		
  2740                              <1> 	;	      ECX = Size of available aperture (memory block) in bytes
  2741                              <1> 	;	 2.2) If EAX = 0 -> Out of memory error 
  2742                              <1> 	;	            (number of free pages is less than requested number)
  2743                              <1> 	;	      ECX = Total number of free bytes (free pages * 4096) 
  2744                              <1> 	;		    (It is not number of contiguous free bytes)	
  2745                              <1> 	;
  2746                              <1> 	; (Modified Registers -> EAX, ECX)
  2747                              <1> 	;
  2748                              <1> 	; PURPOSE: Loading a file at memory for copying or running etc.
  2749                              <1> 	; If this procedure returns with cf is set, ECX contains maximum
  2750                              <1> 	; available space and EAX contains the beginning address of it.
  2751                              <1> 	; If EAX has zero, ECX contains total number of free bytes.
  2752                              <1> 	; If requested block has been successfully allocated (by rounding up to
  2753                              <1> 	; the last page border), it must be deallocated later by using
  2754                              <1> 	; 'deallocate_memory_block' procedure.    
  2755                              <1> 
  2756 00005456 52                  <1> 	push	edx ; *
  2757 00005457 BAFF0F0000          <1> 	mov	edx, PAGE_SIZE - 1   ; 4095
  2758 0000545C 01D0                <1> 	add	eax, edx
  2759 0000545E 01D1                <1> 	add	ecx, edx
  2760 00005460 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  2761                              <1> 
  2762                              <1> 	; ECX = number of contiguous pages to be allocated
  2763 00005463 8B15[B0580100]      <1> 	mov	edx, [free_pages]
  2764                              <1> 	; 01/05/2017
  2765                              <1> 	;or	ecx, ecx
  2766                              <1> 	;jz	short amb3
  2767                              <1> 	; If ECX=0, set cf to 1 and return with max. available mem block size
  2768                              <1> 
  2769 00005469 39D1                <1> 	cmp	ecx, edx
  2770 0000546B 7760                <1> 	ja	short amb_3
  2771                              <1> 
  2772 0000546D C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; 12
  2773                              <1> 
  2774 00005470 89C2                <1> 	mov	edx, eax 	     ; page number
  2775 00005472 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2776                              <1> 				     ; (1 allocation bit = 1 page)
  2777                              <1> 				     ; (1 allocation bytes = 8 pages)
  2778 00005475 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2779                              <1> 				     ; (to get 32 bit position)	
  2780 00005478 53                  <1> 	push	ebx ; **
  2781                              <1> amb_0:
  2782 00005479 890D[5C640100]      <1> 	mov	[mem_ipg_count], ecx ; initial (reset) value of page count
  2783 0000547F 890D[60640100]      <1> 	mov	[mem_pg_count], ecx
  2784 00005485 31C9                <1> 	xor	ecx, ecx ; 0
  2785 00005487 890D[64640100]      <1> 	mov	[mem_aperture], ecx ; 0
  2786 0000548D 890D[68640100]      <1> 	mov	[mem_max_aperture], ecx ; 0
  2787                              <1> 	
  2788 00005493 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address.
  2789 00005498 3B15[B4580100]      <1> 	cmp	edx, [next_page]     ; Is the beginning page address lower
  2790                              <1> 				     ; than the address in 'next_page' ?
  2791                              <1> 				     ; (the first/next free page of user space)		
  2792 0000549E 7208                <1> 	jb	short amb_1
  2793 000054A0 3B15[B8580100]      <1> 	cmp 	edx, [last_page]     ; is the beginning page address higher
  2794                              <1> 				     ; than the address in 'last_page' ?
  2795                              <1> 				     ; (end of the memory)		
  2796 000054A6 7606                <1> 	jna	short amb_2	     ; no	
  2797                              <1> amb_1:
  2798 000054A8 8B15[B4580100]      <1> 	mov	edx, [next_page]     ; M.A.T. offset (1 M.A.T. byte = 8 pages)
  2799                              <1> amb_2:
  2800 000054AE 01D3                <1> 	add	ebx, edx
  2801                              <1> 
  2802                              <1> 	; 28/04/2017
  2803                              <1> 	;xor	ecx, ecx
  2804 000054B0 0FBC0B              <1> 	bsf	ecx, [ebx]	     ; 0 to 31
  2805 000054B3 89D0                <1> 	mov	eax, edx
  2806 000054B5 C1E003              <1> 	shl	eax, 3		     ; *8	
  2807 000054B8 01C8                <1> 	add	eax, ecx	     ; beginning page number
  2808                              <1> 
  2809 000054BA A3[6C640100]        <1> 	mov	[mem_pg_pos], eax    ; beginning page no (for curr. mem. aperture)
  2810 000054BF A3[70640100]        <1>  	mov	[mem_max_pg_pos], eax ; beginning page no for max. mem. aperture
  2811                              <1> 
  2812 000054C4 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only (0 to 31)
  2813                              <1> 				     ; (allocation bit position)	 
  2814 000054C7 750E                <1> 	jnz	short amb_4	     ; 0
  2815 000054C9 B120                <1> 	mov	cl, 32
  2816 000054CB EB4B                <1> 	jmp	short amb_10
  2817                              <1> 
  2818                              <1> amb_3:	; out_of_memory
  2819 000054CD 31C0                <1> 	xor	eax, eax ; 0
  2820 000054CF 89D1                <1> 	mov	ecx, edx ; free pages
  2821 000054D1 C1E10C              <1> 	shl	ecx, PAGE_SHIFT
  2822 000054D4 5A                  <1> 	pop	edx ; *
  2823 000054D5 F9                  <1> 	stc
  2824 000054D6 C3                  <1> 	retn	
  2825                              <1> amb_4:
  2826 000054D7 8B13                <1> 	mov	edx, [ebx]
  2827 000054D9 88C1                <1> 	mov	cl, al ; 1 to 31
  2828 000054DB D3EA                <1> 	shr	edx, cl
  2829 000054DD 89D0                <1> 	mov	eax, edx
  2830                              <1> amb_5:
  2831 000054DF D1E8                <1> 	shr	eax, 1 ; (***)
  2832 000054E1 7317                <1> 	jnc	short amb_7
  2833 000054E3 FF05[64640100]      <1> 	inc	dword [mem_aperture]
  2834 000054E9 FF0D[60640100]      <1> 	dec	dword [mem_pg_count]
  2835 000054EF 7470                <1> 	jz	short amb_15
  2836                              <1> amb_6:
  2837                              <1> 	; 28/04/2017
  2838 000054F1 FEC1                <1> 	inc	cl
  2839 000054F3 80F920              <1> 	cmp	cl, 32
  2840 000054F6 730D                <1> 	jnb	short amb_9
  2841 000054F8 EBE5                <1> 	jmp	short amb_5
  2842                              <1> amb_7:
  2843 000054FA 50                  <1> 	push	eax ; (***) allocation bits (in shifted status)
  2844 000054FB E81B010000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2845 00005500 58                  <1> 	pop	eax ; (***)
  2846 00005501 EBEE                <1> 	jmp	short amb_6
  2847                              <1> amb_8:
  2848                              <1> 	; 28/04/2017
  2849 00005503 B120                <1> 	mov	cl, 32
  2850                              <1> amb_9:
  2851 00005505 89DA                <1> 	mov	edx, ebx
  2852 00005507 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
  2853 0000550D 3B15[B8580100]      <1> 	cmp	edx, [last_page]
  2854 00005513 7336                <1> 	jnb	short amb_14 ; contiguous pages not enough
  2855 00005515 83C304              <1> 	add	ebx, 4
  2856                              <1> amb_10:
  2857 00005518 8B03                <1> 	mov	eax, [ebx]
  2858 0000551A 21C0                <1> 	and 	eax, eax
  2859 0000551C 7408                <1>         jz      short amb_11 ; there is not a free page bit in this alloc dword
  2860 0000551E 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
  2861 0000551F 740C                <1> 	jz	short amb_12 ; all of bits are set (32 free pages)
  2862 00005521 48                  <1> 	dec	eax
  2863 00005522 28C9                <1> 	sub	cl, cl ; 0
  2864 00005524 EBB9                <1> 	jmp	short amb_5
  2865                              <1> amb_11:
  2866 00005526 E8F0000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2867 0000552B EBD8                <1> 	jmp	short amb_9	
  2868                              <1> amb_12:
  2869 0000552D 390D[60640100]      <1> 	cmp	[mem_pg_count], ecx ; 32
  2870 00005533 7306                <1> 	jnb	short amb_13
  2871 00005535 8B0D[60640100]      <1> 	mov	ecx, [mem_pg_count]
  2872                              <1> amb_13:
  2873 0000553B 010D[64640100]      <1> 	add	[mem_aperture], ecx
  2874 00005541 290D[60640100]      <1> 	sub	[mem_pg_count], ecx
  2875 00005547 7618                <1> 	jna	short amb_15
  2876 00005549 EBBA                <1> 	jmp	short amb_9 ; 01/05/2017
  2877                              <1> amb_14:
  2878 0000554B E8CB000000          <1> 	call	amb_26 ; 28/04/2017
  2879 00005550 A1[70640100]        <1> 	mov	eax, [mem_max_pg_pos] ; begin address of max. mem aperture	
  2880 00005555 8B0D[68640100]      <1> 	mov	ecx, [mem_max_aperture] ; max. (largest) memory aperture
  2881 0000555B F9                  <1> 	stc
  2882 0000555C E9AF000000          <1>         jmp     amb_25
  2883                              <1> 
  2884                              <1> amb_15: ; OK !
  2885 00005561 A1[6C640100]        <1> 	mov	eax, [mem_pg_pos]    ; Beginning address as page number
  2886 00005566 8B0D[64640100]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count (>=1)
  2887                              <1> amb_16:
  2888                              <1> 	; allocate contiguous memory pages (via memory allocation table bits)
  2889 0000556C 89C2                <1> 	mov	edx, eax
  2890                              <1> 	; 25/04/2017
  2891 0000556E C1EA03              <1> 	shr	edx, 3		 ; 8 pages in one allocation byte
  2892 00005571 80E2FC              <1> 	and	dl, 0FCh	 ; clear lower 2 bits
  2893                              <1> 				 ; (for dword/32bit positioning)	
  2894                              <1> 
  2895 00005574 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  2896 00005579 01D3                <1> 	add	ebx, edx
  2897 0000557B 83E01F              <1> 	and	eax, 1Fh ; 31
  2898                              <1> 	; 03/04/2016
  2899 0000557E BA20000000          <1> 	mov	edx, 32
  2900 00005583 28C2                <1> 	sub	dl, al
  2901 00005585 39CA                <1> 	cmp	edx, ecx	 ; ecx >= 1
  2902 00005587 7602                <1> 	jna	short amb_17
  2903 00005589 89CA                <1> 	mov	edx, ecx
  2904                              <1> amb_17:
  2905 0000558B 29D1                <1> 	sub	ecx, edx
  2906 0000558D 51                  <1> 	push	ecx ; ***
  2907 0000558E 89D1                <1> 	mov	ecx, edx
  2908                              <1> amb_18:		
  2909 00005590 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
  2910                              <1> 				 ; is copied into the Carry Flag and then cleared
  2911                              <1> 				 ; in the destination.
  2912 00005593 FF0D[B0580100]      <1> 	dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
  2913 00005599 49                  <1> 	dec	ecx
  2914 0000559A 7404                <1> 	jz	short amb_19
  2915 0000559C FEC0                <1> 	inc	al
  2916 0000559E EBF0                <1> 	jmp	short amb_18
  2917                              <1> amb_19:	
  2918 000055A0 59                  <1> 	pop	ecx ; ***
  2919 000055A1 21C9                <1> 	and	ecx, ecx ; 0 ?
  2920 000055A3 741E                <1> 	jz	short amb_22	
  2921                              <1> 	; 01/04/2016
  2922 000055A5 B020                <1> 	mov	al, 32
  2923                              <1> amb_20:
  2924 000055A7 83C304              <1> 	add	ebx, 4
  2925 000055AA 39C1                <1> 	cmp	ecx, eax ; 32
  2926 000055AC 7305                <1> 	jnb	short amb_21
  2927                              <1> 	; ECX < 32
  2928 000055AE 28C0                <1> 	sub	al, al ; 0
  2929 000055B0 50                  <1> 	push	eax ; 0 ***
  2930 000055B1 EBDD                <1> 	jmp	short amb_18
  2931                              <1> amb_21:
  2932 000055B3 2905[B0580100]      <1> 	sub	[free_pages], eax   ; [free_pages] = [free_pages] - 32
  2933 000055B9 C70300000000        <1> 	mov	dword [ebx], 0	    ; reset 32 bits
  2934 000055BF 29C1                <1> 	sub	ecx, eax ; 32
  2935 000055C1 75E4                <1> 	jnz	short amb_20
  2936                              <1> amb_22:
  2937 000055C3 A1[6C640100]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
  2938 000055C8 8B0D[64640100]      <1> 	mov	ecx, [mem_aperture] ; Free contiguous page count
  2939                              <1> 	; [next_page] update
  2940 000055CE 89C2                <1> 	mov	edx, eax
  2941                              <1> 	; 03/04/2016
  2942 000055D0 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2943                              <1> 				     ; (1 allocation bit = 1 page)
  2944                              <1> 				     ; (1 allocation bytes = 8 pages)
  2945 000055D3 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2946                              <1> 				     ; (to get 32 bit position)	
  2947 000055D6 3B15[B4580100]      <1> 	cmp	edx, [next_page] ; first free page pointer offset
  2948 000055DC 7732                <1> 	ja	short amb_25
  2949 000055DE BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  2950 000055E3 833C1300            <1> 	cmp	dword [ebx+edx], 0
  2951 000055E7 7721                <1> 	ja	short amb_24
  2952 000055E9 89C2                <1> 	mov	edx, eax
  2953 000055EB 01CA                <1> 	add	edx, ecx
  2954 000055ED C1EA03              <1> 	shr	edx, 3
  2955 000055F0 80E2FC              <1> 	and	dl, 0FCh
  2956                              <1> amb_23:
  2957 000055F3 833C1300            <1> 	cmp	dword [ebx+edx], 0
  2958 000055F7 7711                <1> 	ja	short amb_24
  2959 000055F9 83C204              <1> 	add	edx, 4
  2960 000055FC 3B15[B8580100]      <1> 	cmp	edx, [last_page]    ; last page pointer offset
  2961 00005602 76EF                <1> 	jna	short amb_23
  2962 00005604 8B15[BC580100]      <1> 	mov	edx, [first_page]   ; (for) beginning of user's space
  2963                              <1> amb_24:
  2964 0000560A 8915[B4580100]      <1> 	mov	[next_page], edx
  2965                              <1> amb_25:
  2966 00005610 9C                  <1> 	pushf
  2967 00005611 C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
  2968 00005614 C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
  2969 00005617 9D                  <1> 	popf
  2970 00005618 5B                  <1> 	pop	ebx ; **
  2971 00005619 5A                  <1> 	pop	edx ; *
  2972 0000561A C3                  <1> 	retn
  2973                              <1> 
  2974                              <1> amb_26:	; set maximum free memory aperture (free memory block size) 
  2975 0000561B 89DA                <1> 	mov	edx, ebx ; current address
  2976 0000561D 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL ; MAT beginning address
  2977                              <1> 	; 02/04/2016 
  2978 00005623 C1E203              <1> 	shl	edx, 3 ; MAT byte offset * 8 = page number base
  2979 00005626 01CA                <1> 	add	edx, ecx ; current page number (ecx = 0 to 32)
  2980                              <1> 	;
  2981 00005628 A1[64640100]        <1> 	mov	eax, [mem_aperture]
  2982 0000562D 21C0                <1> 	and	eax, eax
  2983 0000562F 7421                <1>         jz      short amb_27
  2984 00005631 C705[64640100]0000- <1>         mov     dword [mem_aperture], 0
  2984 00005639 0000                <1>
  2985 0000563B 3B05[68640100]      <1> 	cmp	eax, [mem_max_aperture]
  2986 00005641 760F                <1> 	jna	short amb_27
  2987 00005643 A3[68640100]        <1> 	mov	[mem_max_aperture], eax
  2988                              <1> 	; 25/04/2017
  2989 00005648 A1[6C640100]        <1> 	mov	eax, [mem_pg_pos]
  2990                              <1> 	; EAX = Beginning page number of the max. aperture 
  2991 0000564D A3[70640100]        <1> 	mov	[mem_max_pg_pos], eax
  2992                              <1> amb_27: 
  2993 00005652 8915[6C640100]      <1> 	mov	[mem_pg_pos], edx ; current page
  2994                              <1> 
  2995 00005658 A1[5C640100]        <1> 	mov	eax, [mem_ipg_count] ; initial (reset) value of page count
  2996 0000565D A3[60640100]        <1> 	mov	[mem_pg_count], eax
  2997                              <1> 
  2998 00005662 C3                  <1> 	retn
  2999                              <1> 
  3000                              <1> deallocate_memory_block:
  3001                              <1> 	; 03/04/2016
  3002                              <1> 	; 14/03/2016 (TRDOS 386 = TRDOS v2.0)
  3003                              <1> 	; Deallocating contiguous memory pages (in the kernel's memory space)
  3004                              <1> 	;
  3005                              <1> 	; INPUT -> 
  3006                              <1> 	;	EAX = Beginning address (physical)
  3007                              <1> 	;	ECX = Number of bytes to be deallocated
  3008                              <1> 	;
  3009                              <1> 	; OUTPUT ->
  3010                              <1> 	;	Memory Allocation Table bits will be updated
  3011                              <1> 	;	[free_pages] will be changed (increased)
  3012                              <1> 	;
  3013                              <1> 	; (Modified Registers -> EAX, ECX)
  3014                              <1> 	;
  3015                              <1> 	; PURPOSE: Unloading/Freeing a file -or an allocated memory block- 
  3016                              <1> 	; at memory after copying, running, saving, reading, writing etc.
  3017                              <1> 	;
  3018                              <1> 
  3019 00005663 52                  <1> 	push	edx ; *
  3020 00005664 53                  <1> 	push	ebx ; **
  3021                              <1> 
  3022 00005665 C1E80C              <1> 	shr	eax, PAGE_SHIFT	     ; 12
  3023 00005668 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  3024                              <1> 
  3025                              <1> 	; EAX = Beginning page number
  3026                              <1> 	; ECX = Number of contiguous pages to be deallocated
  3027                              <1> damb_0:
  3028                              <1> 	; deallocate contiguous memory pages (via memory allocation table bits)
  3029 0000566B 89C2                <1> 	mov	edx, eax
  3030 0000566D C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  3031                              <1> 				     ; (1 allocation bit = 1 page)
  3032                              <1> 				     ; (1 allocation bytes = 8 pages)
  3033 00005670 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  3034                              <1> 				     ; (to get 32 bit position)	
  3035 00005673 3B15[B4580100]      <1> 	cmp	edx, [next_page] ; next free page
  3036 00005679 7306                <1> 	jnb	short damb_1
  3037 0000567B 8915[B4580100]      <1> 	mov	[next_page], edx
  3038                              <1> damb_1:
  3039 00005681 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  3040 00005686 01D3                <1> 	add	ebx, edx
  3041 00005688 83E01F              <1> 	and	eax, 1Fh ; 31
  3042                              <1> 
  3043                              <1> 	; 03/04/2016
  3044 0000568B BA20000000          <1> 	mov	edx, 32
  3045 00005690 28C2                <1> 	sub	dl, al
  3046 00005692 39CA                <1> 	cmp	edx, ecx
  3047 00005694 7602                <1> 	jna	short damb_2
  3048 00005696 89CA                <1> 	mov	edx, ecx
  3049                              <1> damb_2:
  3050 00005698 29D1                <1> 	sub	ecx, edx
  3051 0000569A 51                  <1> 	push	ecx ; ***
  3052 0000569B 89D1                <1> 	mov	ecx, edx
  3053                              <1> damb_3:		
  3054 0000569D 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
  3055                              <1> 				     ; set relevant bit to 1.
  3056                              <1> 				     ; set CF to the previous bit value	
  3057 000056A0 FF05[B0580100]      <1> 	inc     dword [free_pages]   ; 1 page has been deallocated (X = X+1) 
  3058 000056A6 49                  <1> 	dec	ecx
  3059 000056A7 7404                <1> 	jz	short damb_4
  3060 000056A9 FEC0                <1> 	inc	al
  3061 000056AB EBF0                <1> 	jmp	short damb_3
  3062                              <1> damb_4:	
  3063 000056AD 59                  <1> 	pop	ecx ; ***
  3064 000056AE 21C9                <1> 	and	ecx, ecx ; 0 ?
  3065 000056B0 741E                <1> 	jz	short damb_7
  3066                              <1> 	; 03/04/2016
  3067 000056B2 B020                <1> 	mov	al, 32
  3068                              <1> damb_5:
  3069 000056B4 83C304              <1> 	add	ebx, 4
  3070 000056B7 39C1                <1> 	cmp	ecx, eax ; 32
  3071 000056B9 7305                <1> 	jnb	short damb_6
  3072                              <1> 	; ECX < 32
  3073 000056BB 28C0                <1> 	sub	al, al ; 0
  3074 000056BD 50                  <1> 	push	eax ; 0 ***
  3075 000056BE EBDD                <1> 	jmp	short damb_3
  3076                              <1> damb_6:
  3077 000056C0 0105[B0580100]      <1> 	add	[free_pages], eax ; [free_pages] = [free_pages] + 32
  3078 000056C6 C703FFFFFFFF        <1> 	mov	dword [ebx], 0FFFFFFFFh ; set 32 bits
  3079 000056CC 29C1                <1> 	sub	ecx, eax ; 32
  3080 000056CE 75E4                <1> 	jnz	short damb_5
  3081                              <1> damb_7:
  3082 000056D0 5B                  <1> 	pop	ebx ; **
  3083 000056D1 5A                  <1> 	pop	edx ; *
  3084 000056D2 C3                  <1> 	retn
  3085                              <1> 
  3086                              <1> direct_memory_access:
  3087                              <1> 	; 22/07/2017
  3088                              <1> 	; 12/05/2017
  3089                              <1> 	; 16/07/2016
  3090                              <1> 	; 12/07/2016 (TRDOS 386 = TRDOS v2.0)
  3091                              <1> 	; This processure will be called to map
  3092                              <1> 	; user's (ring 3) page tables to access phsical
  3093                              <1> 	; (flat/linear) memory addresses, directly (without
  3094                              <1> 	;  kernel's data transfer functions).
  3095                              <1> 	; 
  3096                              <1> 	; Purpose: Video memory access and shared memory access.
  3097                              <1> 	;
  3098                              <1> 	; INPUT -> 
  3099                              <1> 	;	EAX = Beginning address (physical).
  3100                              <1> 	;	EBX = User's buffer address ; 12/05/2017
  3101                              <1> 	;	ECX = Number of contiguous pages to be mapped.
  3102                              <1> 	; OUTPUT ->
  3103                              <1> 	;	User's page directory and pages tables
  3104                              <1> 	;	will be updated.
  3105                              <1> 	;	
  3106                              <1> 	;	If an old page table entry has valid page address, 
  3107                              <1> 	;	that page will be deallocated just before PTE will
  3108                              <1> 	;	be changed for direct (1 to 1) memory page access.
  3109                              <1> 	;
  3110                              <1> 	;	If old PTE value points to a swapped page,
  3111                              <1>         ;       that page (block) will be unlinked on swap disk. 
  3112                              <1> 	;
  3113                              <1> 	;	Newly allocated pages (except page tables) will not
  3114                              <1> 	;	be applied to Memory Allocation Table.
  3115                              <1> 	;	AVL bit 1 (PTE bit 10) of page table entry will be
  3116                              <1> 	;	used to indicate shared (direct) memory page; then,
  3117                              <1> 	;	this page will not be deallocated later during
  3118                              <1> 	;	process termination. (Memory Allocation Table and
  3119                              <1> 	;	free memory count will not be affected.
  3120                              <1> 	;	(Except deallocating page table's itself.)
  3121                              <1> 	;	
  3122                              <1> 	;      CF = 1 -> error (EAX = error code)
  3123                              <1> 	;      CF = 0 -> success (EAX = beginning address)
  3124                              <1> 	;
  3125                              <1> 	;; (Modified Registers -> none)
  3126                              <1> 	; Modified registers: ebp, edx, ecx, ebx, esi, edi	
  3127                              <1> 	;
  3128                              <1> 
  3129                              <1> 	;push	ebp
  3130                              <1> 	;push	ebx
  3131                              <1> 	;push	ecx
  3132                              <1> 	;push	edx
  3133 000056D3 662500F0            <1> 	and	ax, PTE_A_CLEAR ; clear page offset
  3134 000056D7 50                  <1> 	push	eax
  3135                              <1> 	;and	ecx, ecx ; page count
  3136                              <1> 	;jz	dmem_acc_7  ; 'insufficient memory' error
  3137 000056D8 89C5                <1> 	mov	ebp, eax
  3138 000056DA 81C300004000        <1> 	add	ebx, CORE ; 12/05/2017
  3139                              <1> dmem_acc_0: 
  3140 000056E0 891D[5C6F0100]      <1> 	mov	[base_addr], ebx ; 12/05/2017
  3141 000056E6 A1[B8030300]        <1> 	mov	eax, [u.pgdir] ; page dir address (physical)
  3142 000056EB E8D7F5FFFF          <1> 	call	get_pte
  3143                              <1> 		; EDX = Page table entry address (if CF=0)
  3144                              <1> 	        ;       Page directory entry address (if CF=1)
  3145                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  3146                              <1> 		; EAX = Page table entry value (page address)
  3147                              <1> 		;	CF = 1 -> PDE not present or invalid ? 	
  3148 000056F0 7324                <1> 	jnc	short dmem_acc_1
  3149                              <1> 	;
  3150 000056F2 E8B5F4FFFF          <1> 	call	allocate_page
  3151 000056F7 0F82AB000000        <1>         jc      dmem_acc_7  ; 'insufficient memory' error
  3152                              <1> 	;
  3153 000056FD E824F5FFFF          <1> 	call 	clear_page
  3154                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  3155 00005702 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  3156                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  3157                              <1> 			   ; (user, writable, present page)	
  3158 00005704 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  3159 00005706 A1[B8030300]        <1> 	mov	eax, [u.pgdir]	
  3160 0000570B E8B7F5FFFF          <1> 	call	get_pte
  3161 00005710 0F8292000000        <1>         jc      dmem_acc_7 ; 'insufficient memory' error
  3162                              <1> dmem_acc_1:
  3163                              <1> 	; EAX = PTE value, EDX = PTE address
  3164 00005716 A801                <1> 	test 	al, PTE_A_PRESENT
  3165 00005718 750D                <1> 	jnz	short dmem_acc_2
  3166 0000571A 09C0                <1> 	or	eax, eax
  3167 0000571C 7468                <1> 	jz	short dmem_acc_6   ; Change PTE
  3168 0000571E D1E8                <1> 	shr	eax, 1		; swap disk block (8 sectors) address
  3169                              <1> 	; unlink swap disk block
  3170 00005720 E80CFBFFFF          <1> 	call	unlink_swap_block
  3171 00005725 EB5F                <1> 	jmp	short dmem_acc_6
  3172                              <1> 
  3173                              <1> dmem_acc_2:
  3174 00005727 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3175                              <1> 				  ; (must be 1)
  3176 00005729 7550                <1> 	jnz	short dmem_acc_4
  3177                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3178 0000572B 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3179                              <1> 				   ; as child's page ?
  3180 0000572F 7455                <1> 	jz	short dmem_acc_5 ; Change PTE but don't deallocate the page!
  3181                              <1> 
  3182                              <1> 	;push	edi
  3183                              <1> 	;push	esi
  3184                              <1> 
  3185 00005731 51                  <1> 	push	ecx
  3186                              <1> 	;push	ebx
  3187 00005732 8B1D[BC030300]      <1> 	mov	ebx, [u.ppgdir] ; parent's page dir address (physical)
  3188                              <1> 	
  3189                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3190 00005738 89EF                <1> 	mov	edi, ebp
  3191 0000573A C1EF16              <1> 	shr	edi, PAGE_D_SHIFT ; 22
  3192                              <1> 	; EDI = page directory entry index (0-1023)
  3193 0000573D 89EE                <1> 	mov	esi, ebp
  3194 0000573F C1EE0C              <1> 	shr	esi, PAGE_SHIFT ; 12	
  3195 00005742 81E6FF030000        <1> 	and	esi, PTE_MASK
  3196                              <1> 	; ESI = page table entry index (0-1023)
  3197                              <1> 
  3198 00005748 66C1E702            <1> 	shl	di, 2 ; * 4
  3199 0000574C 01FB                <1> 	add	ebx, edi ; PDE offset (for the parent)
  3200 0000574E 8B0F                <1> 	mov	ecx, [edi]
  3201 00005750 F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
  3202 00005753 7425                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3203 00005755 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3204 0000575A 66C1E602            <1> 	shl	si, 2 ; *4 
  3205 0000575E 01CE                <1> 	add	esi, ecx ; PTE offset (for the parent)
  3206 00005760 8B1E                <1> 	mov	ebx, [esi]
  3207 00005762 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3208 00005765 7413                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3209 00005767 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3210 0000576B 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3211 00005770 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3212 00005772 7506                <1> 	jne	short dmem_acc_3	; not same page
  3213                              <1> 				; deallocate the child's page
  3214 00005774 800E02              <1>         or      byte [esi], PTE_A_WRITE ; convert to writable page (parent)
  3215                              <1> 	;pop	ebx
  3216 00005777 59                  <1> 	pop	ecx
  3217 00005778 EB0C                <1> 	jmp	short dmem_acc_5
  3218                              <1> dmem_acc_3:
  3219                              <1> 	;pop	ebx
  3220 0000577A 59                  <1> 	pop	ecx
  3221                              <1> dmem_acc_4:	
  3222 0000577B 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
  3223 0000577F 7505                <1> 	jnz	short dmem_acc_5   ; AVL bit 1 = 1, do not deallocate this page!
  3224                              <1> 	;
  3225                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3226 00005781 E804F6FFFF          <1> 	call	deallocate_page
  3227                              <1> dmem_acc_5:
  3228                              <1> 	;pop	esi
  3229                              <1> 	;pop	edi
  3230                              <1> dmem_acc_6:
  3231 00005786 89E8                <1> 	mov	eax, ebp ; physical page (offset=0) address
  3232                              <1> 	; EAX = memory page address
  3233                              <1> 	; EDX = PTE entry address (physical)
  3234 00005788 660D0704            <1> 	or	ax, PTE_A_PRESENT+PTE_A_USER+PTE_A_WRITE+PTE_SHARED
  3235                              <1> 			; present flag, bit 0 = 1
  3236                              <1> 			; user flag, bit 2 = 1	
  3237                              <1> 			; writable flag, bit 1 = 1
  3238                              <1> 			; direct memory access flag, bit 10 = 1
  3239                              <1> 			; (This page must not be deallocated!)
  3240 0000578C 8902                <1> 	mov	[edx], eax  ; Update PTE value
  3241 0000578E 49                  <1> 	dec	ecx ; remain count of contiguous pages
  3242 0000578F 741E                <1> 	jz	short dmem_acc_8
  3243 00005791 81C500100000        <1> 	add	ebp, PAGE_SIZE ; next physical page address
  3244                              <1> 	; 22/07/2017
  3245                              <1> 	;mov	eax, ebp
  3246                              <1> 	; 12/05/2017
  3247 00005797 8B1D[5C6F0100]      <1> 	mov	ebx, [base_addr] ; linear address (virtual+CORE)
  3248 0000579D 81C300100000        <1> 	add	ebx, PAGE_SIZE	; next linear address
  3249 000057A3 E938FFFFFF          <1>         jmp     dmem_acc_0
  3250                              <1> dmem_acc_7:  ; ERROR ! 
  3251 000057A8 C7042404000000      <1> 	mov	dword [esp], ERR_MINOR_IM 
  3252                              <1> 		; Insufficient memory (minor) error!
  3253                              <1> 		; Major error = 0 (No protection fault)	
  3254                              <1> 	; cf = 1
  3255                              <1> dmem_acc_8:
  3256 000057AF 58                  <1> 	pop	eax
  3257                              <1> 	;pop	edx
  3258                              <1> 	;pop	ecx
  3259                              <1> 	;pop	ebx
  3260                              <1> 	;pop	ebp
  3261 000057B0 C3                  <1> 	retn
  3262                              <1> 
  3263                              <1> deallocate_user_pages:
  3264                              <1> 	; 20/05/2017
  3265                              <1> 	; 15/05/2017
  3266                              <1> 	; 20/02/2017
  3267                              <1> 	; 19/02/2017 (TRDOS 386 = TRDOS v2.0)
  3268                              <1> 	;
  3269                              <1> 	; Deallocate virtually contiguous user pages (memory block)
  3270                              <1> 	; (caller: 'sysdalloc' system call)
  3271                              <1> 	;
  3272                              <1> 	; INPUT ->
  3273                              <1> 	;	EBX = VIRTUAL ADDRESS (beginning address)
  3274                              <1> 	;	ECX = byte count
  3275                              <1> 	;	[u.pgdir] = user's page directory
  3276                              <1> 	;	[u.ppdir] = parent's page directory
  3277                              <1> 	;
  3278                              <1> 	; OUTPUT ->
  3279                              <1> 	;    If CF = 0 	
  3280                              <1> 	;	EAX = Deallocated memory bytes
  3281                              <1> 	;	  (Even if shared or read only pages will not be
  3282                              <1> 	;	   deallocated on M.A.T., this byte count will be
  3283                              <1> 	;	   returned as virtually deallocated bytes; in fact
  3284                              <1> 	;	   virtually deallocated user pages * 4096.) 
  3285                              <1> 	;	EBX = Virtual address (as rounded up)
  3286                              <1> 	;    If CF = 1    	
  3287                              <1> 	;	EAX = 0 (there is not any deallocated pages)
  3288                              <1> 	;
  3289                              <1> 	; Note: Empty page tables will not be deallocated!!!
  3290                              <1> 	;     (they will be deallocated at process termination stage)
  3291                              <1> 	;
  3292                              <1> 	; Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP
  3293                              <1> 	;
  3294 000057B1 89DE                <1> 	mov	esi, ebx
  3295 000057B3 89F7                <1> 	mov	edi, esi
  3296 000057B5 01CF                <1> 	add	edi, ecx
  3297 000057B7 81C6FF0F0000        <1> 	add	esi, PAGE_SIZE - 1  ; 4095 (round up)	
  3298 000057BD C1EE0C              <1> 	shr	esi, PAGE_SHIFT
  3299 000057C0 C1EF0C              <1> 	shr	edi, PAGE_SHIFT
  3300 000057C3 89F8                <1> 	mov	eax, edi ; end page
  3301 000057C5 29F0                <1> 	sub	eax, esi ; end page - start page
  3302 000057C7 0F86D5000000        <1> 	jna	da_u_pd_err  ; < 1
  3303 000057CD 89F3                <1> 	mov	ebx, esi
  3304 000057CF C1E30C              <1> 	shl	ebx, PAGE_SHIFT ; virtual address (as rounded up)
  3305 000057D2 53                  <1> 	push	ebx ; *
  3306 000057D3 89C1                <1> 	mov	ecx, eax ; page count
  3307 000057D5 C1E00C              <1> 	shl	eax, PAGE_SHIFT ; byte count as adjusted
  3308 000057D8 50                  <1> 	push	eax ; **
  3309 000057D9 8B1D[B8030300]      <1> 	mov	ebx, [u.pgdir] ; physical addr of user's page dir
  3310 000057DF 81C600040000        <1>  	add	esi, CORE/PAGE_SIZE 
  3311 000057E5 89F7                <1> 	mov	edi, esi
  3312 000057E7 81E7FF030000        <1> 	and	edi, PTE_MASK ; PTE entry in the page table
  3313 000057ED 57                  <1> 	push	edi ; *** ; PTE index (of page directory)
  3314 000057EE C1EE0A              <1> 	shr	esi, PAGE_D_SHIFT - PAGE_SHIFT ; 22-12=10
  3315 000057F1 89F2                <1> 	mov	edx, esi 
  3316                              <1> 	; EDX = PDE index
  3317 000057F3 C1E602              <1> 	shl	esi, 2 ; convert PDE index to dword offset
  3318 000057F6 01DE                <1> 	add	esi, ebx ; add page directory address
  3319                              <1> da_u_pd_1:
  3320 000057F8 AD                  <1> 	lodsd
  3321                              <1> 	;
  3322 000057F9 89F5                <1> 	mov	ebp, esi ; 20/02/2017
  3323                              <1> 	; EBP = next PDE address
  3324                              <1> 	;
  3325 000057FB A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
  3326 000057FD 0F8494000000        <1> 	jz	da_u_pd_3 ; 20/05/2017	
  3327 00005803 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3328                              <1> 	; EAX = PHYSICAL (flat) ADDRESS OF THE PAGE TABLE
  3329 00005807 8B3C24              <1> 	mov	edi, [esp] ; ***
  3330                              <1> 	; EDI = PTE index (of complete page directory)
  3331                              <1> 	;and	edi, PTE_MASK ; PTE entry in the page table
  3332 0000580A C1E702              <1> 	shl	edi, 2 ; convert PTE index to dword offset
  3333 0000580D 89FE                <1> 	mov	esi, edi ; PTE offset in page table (0-4092)
  3334 0000580F 01C6                <1> 	add	esi, eax ; now, esi points to requested PTE
  3335                              <1> da_u_pt_0:
  3336 00005811 AD                  <1> 	lodsd
  3337 00005812 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
  3338 00005814 743F                <1> 	jz	short da_u_pt_1
  3339                              <1> 	;
  3340 00005816 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3341                              <1> 				  ; (must be 1)
  3342 00005818 7549                <1> 	jnz	short da_u_pt_3
  3343                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3344 0000581A 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3345                              <1> 				   ; as child's page ?
  3346 0000581E 744E                <1> 	jz	short da_u_pt_4 ; Clear PTE but don't deallocate the page!
  3347                              <1> 	;
  3348                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3349                              <1> 	; EDX = page directory entry index (0-1023)
  3350 00005820 52                  <1> 	push	edx ; ****
  3351                              <1> 	; EDI = page table entry offset (0-4092)
  3352 00005821 8B1D[BC030300]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  3353 00005827 66C1E202            <1> 	shl	dx, 2 ; *4 
  3354 0000582B 01D3                <1> 	add	ebx, edx ; PDE address (for the parent)
  3355 0000582D 8B13                <1> 	mov	edx, [ebx] ; page table address
  3356 0000582F F6C201              <1> 	test	dl, PDE_A_PRESENT ; present (valid) or not ?
  3357 00005832 742E                <1> 	jz	short da_u_pt_2	; parent process does not use this page
  3358 00005834 6681E200F0          <1> 	and	dx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3359                              <1> 	; EDI = page table entry offset (0-4092)
  3360 00005839 01D7                <1> 	add	edi, edx	; PTE address (for the parent)
  3361 0000583B 8B1F                <1> 	mov	ebx, [edi]
  3362 0000583D F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3363 00005840 7420                <1> 	jz	short da_u_pt_2	; parent process does not use this page
  3364 00005842 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3365 00005846 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3366 0000584B 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3367 0000584D 7513                <1> 	jne	short da_u_pt_2	; not same page
  3368                              <1> 				; deallocate the child's page
  3369 0000584F 800F02              <1>         or      byte [edi], PTE_A_WRITE ; convert to writable page (parent)
  3370 00005852 5A                  <1> 	pop	edx ; ****
  3371 00005853 EB19                <1> 	jmp	short da_u_pt_4
  3372                              <1> da_u_pt_1:
  3373 00005855 09C0                <1> 	or	eax, eax	; swapped page ?
  3374 00005857 741C                <1> 	jz	short da_u_pt_5	; no
  3375                              <1> 				; yes
  3376 00005859 D1E8                <1> 	shr	eax, 1
  3377 0000585B E8D1F9FFFF          <1> 	call	unlink_swap_block ; Deallocate swapped page block
  3378                              <1> 				  ; on the swap disk (or in file)
  3379 00005860 EB13                <1> 	jmp	short da_u_pt_5
  3380                              <1> da_u_pt_2:
  3381 00005862 5A                  <1> 	pop	edx ; ****
  3382                              <1> da_u_pt_3:
  3383 00005863 66A90004            <1> 	test	ax, PTE_SHARED	; shared or direct memory access indicator
  3384 00005867 7505                <1> 	jnz	short da_u_pt_4	; AVL bit 1 = 1, do not deallocate this page!
  3385                              <1> 	;
  3386                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3387 00005869 E81CF5FFFF          <1> 	call	deallocate_page ; set the mem allocation bit of this page
  3388                              <1> da_u_pt_4:
  3389 0000586E C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
  3390                              <1> da_u_pt_5:
  3391                              <1> 	; 20/05/2017
  3392 00005875 58                  <1> 	pop	eax ; *** PTE index (of page directory)
  3393 00005876 49                  <1> 	dec	ecx ; remain page count
  3394 00005877 7426                <1> 	jz	short da_u_pd_4
  3395 00005879 40                  <1> 	inc	eax ; next PTE
  3396 0000587A 6625FF03            <1> 	and	ax, PTE_MASK ; PTE entry index in the page table
  3397 0000587E 50                  <1> 	push	eax ; *** (save again)
  3398                              <1> 	;mov	edi, eax
  3399                              <1> 	;and 	di, PTE_MASK
  3400                              <1> 	;cmp	edi, PAGE_SIZE / 4 ; 1024
  3401                              <1> 	;jnb	short da_u_pd_2
  3402 0000587F 89C7                <1> 	mov	edi, eax
  3403 00005881 C1E702              <1> 	shl	edi, 2 ; convert index to dword offset
  3404                              <1> 	;test	ax, PTE_MASK ; 3FFh
  3405 00005884 09C0                <1> 	or	eax, eax
  3406 00005886 7589                <1> 	jnz	short da_u_pt_0 ; 1-1023
  3407                              <1> da_u_pd_2:
  3408 00005888 42                  <1> 	inc	edx
  3409                              <1> 	; 20/05/2017
  3410 00005889 6681E2FF03          <1> 	and	dx, PTE_MASK  ; 3FFh
  3411 0000588E 740F                <1> 	jz	short da_u_pd_4  ; 0 (1024)
  3412                              <1> 	;cmp	edx, 1024
  3413                              <1> 	;jnb	short da_u_pd_4
  3414 00005890 89EE                <1> 	mov	esi, ebp ; 20/02/2017
  3415 00005892 E961FFFFFF          <1> 	jmp	da_u_pd_1
  3416                              <1> da_u_pd_3:
  3417                              <1> 	; 15/05/2017 (empty page directory entry)
  3418 00005897 81E900040000        <1> 	sub	ecx, 1024
  3419 0000589D 77E9                <1> 	ja	short da_u_pd_2 ; 20/05/2017
  3420                              <1> da_u_pd_4:
  3421 0000589F 58                  <1> 	pop	eax ; **
  3422 000058A0 5B                  <1> 	pop	ebx ; *
  3423 000058A1 C3                  <1> 	retn
  3424                              <1> 
  3425                              <1> da_u_pd_err:
  3426 000058A2 31C0                <1> 	xor	eax, eax
  3427 000058A4 F9                  <1> 	stc	
  3428 000058A5 C3                  <1> 	retn
  3429                              <1> 
  3430                              <1> allocate_user_pages:
  3431                              <1> 	; 20/05/2017
  3432                              <1> 	; 01/05/2017, 02/05/2017, 15/05/2017
  3433                              <1> 	; 04/03/2017
  3434                              <1> 	; 20/02/2017 (TRDOS 386 = TRDOS v2.0)
  3435                              <1> 	;
  3436                              <1> 	; Allocate physically contiguous user pages (memory block)
  3437                              <1> 	; (caller: 'sysalloc' system call)
  3438                              <1> 	;
  3439                              <1> 	; Note: This procedure does not alloc a page's itself
  3440                              <1> 	;	(page bit) on Memory Allocation Table.
  3441                              <1> 	;	(allocate_memory_block is needed before this proc)
  3442                              <1> 	;
  3443                              <1> 	; INPUT ->
  3444                              <1> 	;	EAX = PHYSICAL ADDRESS (beginning address)
  3445                              <1> 	;	EBX = VIRTUAL ADDRESS (beginning address)
  3446                              <1> 	;	ECX = byte count (>=4096)
  3447                              <1> 	;	[u.pgdir] = user's page directory
  3448                              <1> 	;	
  3449                              <1> 	;	Note: All addresses are (must be) already adjusted
  3450                              <1> 	;	to page	borders, otherwise, lower 12bits of addresses
  3451                              <1> 	;	and byte count would be truncated.
  3452                              <1> 	;
  3453                              <1> 	; OUTPUT ->
  3454                              <1> 	;	none
  3455                              <1> 	;
  3456                              <1> 	;	CF = 1 -> insufficient memory error
  3457                              <1> 	;
  3458                              <1> 	; Note: All pages will be allocated in physical page order 
  3459                              <1> 	;	from the beginning page address. 
  3460                              <1> 	;	* A new page table will be added to the page dir
  3461                              <1> 	;	  when the requested PDE is invalid.
  3462                              <1> 	;	* Those pages will not be added to swap queue
  3463                              <1> 	;	  because main purpose of this allocation is to
  3464                              <1> 	;	  set a direct memory access (DMA controller) buffer.
  3465                              <1> 	;	 (Swapping out a page in a DMA buffer would be wrong!)
  3466                              <1> 	;	* Previous content of page tables (PTEs) would be
  3467                              <1> 	;	  (should be) deallocated before entering this
  3468                              <1> 	;	  procedure. So, new page table entries (PTEs)
  3469                              <1> 	;	  directly will be written without checking
  3470                              <1> 	;	  their previous content.	
  3471                              <1> 	;	* Only solution to increase free memory by removing
  3472                              <1> 	;	  that non-swappable memory block is to terminate
  3473                              <1> 	;	  the process or to wait until the process will 
  3474                              <1> 	;	  deallocate that memory block as itself. ('sysdalloc')
  3475                              <1> 	;	  (No problem, if the process does not grab all of
  3476                              <1> 	;	  -very big amount of- free memory by using
  3477                              <1> 	;	  'sysalloc' system call!?)
  3478                              <1> 	;	  (Even if the process has grabbed all of free memory, 
  3479                              <1> 	;	  no problem if the process is not running in 
  3480                              <1> 	;	  multitasking mode. No problem in multitasking
  3481                              <1> 	;	  mode if there is not another process which is running
  3482                              <1> 	;	  or waiting or sleeping for an event as it's pages
  3483                              <1> 	;	  are swapped-out. But a new process can not start to
  3484                              <1> 	;	  run if all of free memory has beeen allocated 
  3485                              <1> 	;	  by running processes. Deallocation -'sysdalloc'- 
  3486                              <1> 	;	  or terminate a running process is needed 
  3487                              <1> 	;	  in order to run a new process.) 
  3488                              <1> 	;
  3489                              <1> 	; Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP
  3490                              <1> 	;
  3491                              <1> 
  3492                              <1> 	; 01/05/2017
  3493 000058A6 662500F0            <1> 	and	ax, ~PAGE_OFF
  3494 000058AA 6681E300F0          <1> 	and	bx, ~PAGE_OFF
  3495                              <1> 	; 02/05/2017 
  3496 000058AF BD00F0FFFF          <1> 	mov	ebp, 0FFFFF000h ; 4 Giga Bytes - 4096 Bytes (for Stack)
  3497 000058B4 C1E90C              <1> 	shr	ecx, PAGE_SHIFT ; page count
  3498 000058B7 83F901              <1> 	cmp	ecx, 1
  3499 000058BA 7251                <1> 	jb	short a_u_im_retn
  3500 000058BC 89C2                <1> 	mov	edx, eax
  3501 000058BE 01CA                <1> 	add	edx, ecx
  3502 000058C0 724B                <1> 	jc	short a_u_im_retn
  3503 000058C2 39D5                <1> 	cmp	ebp, edx
  3504 000058C4 7247                <1> 	jb	short a_u_im_retn
  3505 000058C6 89DA                <1> 	mov	edx, ebx
  3506 000058C8 81C200004000        <1> 	add	edx, CORE
  3507 000058CE 723D                <1> 	jc	short a_u_im_retn	
  3508 000058D0 01CA                <1> 	add	edx, ecx
  3509 000058D2 7239                <1> 	jc	short a_u_im_retn
  3510 000058D4 39D5                <1> 	cmp	ebp, edx
  3511 000058D6 7235                <1> 	jb	short a_u_im_retn
  3512                              <1> 	;
  3513 000058D8 89C5                <1> 	mov	ebp, eax ; physical address
  3514 000058DA 89DE                <1> 	mov	esi, ebx
  3515 000058DC 81C600004000        <1> 	add	esi, CORE ; start of user's memory (4M) 
  3516 000058E2 C1EE0C              <1> 	shr	esi, PAGE_SHIFT ; higher 20 bits of the linear address
  3517                              <1> 	;shr	ecx, PAGE_SHIFT ; page count
  3518 000058E5 8B1D[B8030300]      <1> 	mov	ebx, [u.pgdir] ; physical addr of user's page dir
  3519 000058EB 89F7                <1> 	mov	edi, esi
  3520 000058ED 81E7FF030000        <1> 	and	edi, PTE_MASK ; PTE entry index in the page table
  3521 000058F3 57                  <1> 	push	edi  ; * ; PTE index (in page directory)
  3522 000058F4 C1EE0A              <1> 	shr	esi, PAGE_D_SHIFT - PAGE_SHIFT ; 22-12=10
  3523 000058F7 89F2                <1> 	mov	edx, esi 
  3524                              <1> 	; EDX = PDE index
  3525 000058F9 C1E602              <1> 	shl	esi, 2 ; convert PDE index to dword offset
  3526 000058FC 01DE                <1> 	add	esi, ebx ; add page directory address
  3527                              <1> a_u_pd_0:
  3528 000058FE AD                  <1> 	lodsd
  3529                              <1> 	;
  3530 000058FF 89F3                <1> 	mov	ebx, esi ; next PDE address
  3531                              <1> 	;
  3532 00005901 A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
  3533 00005903 7513                <1> 	jnz	short a_u_pd_2
  3534                              <1> 	;
  3535                              <1> 	; empty PDE (it does not point to valid page table address)
  3536 00005905 E8A2F2FFFF          <1> 	call	allocate_page  ; (allocate a new page table)
  3537 0000590A 7302                <1> 	jnc	short a_u_pd_1 ; OK... now, we have a new page table.
  3538                              <1> 	; cf = 1
  3539                              <1> 	; There is not a free memory page to allocate a new page table !!!
  3540 0000590C 5E                  <1> 	pop	esi ; *
  3541                              <1> a_u_im_retn:
  3542 0000590D C3                  <1> 	retn	; return to 'sysalloc' with 'insufficient memory' error
  3543                              <1> 	;
  3544                              <1> a_u_pd_1: ; clear the new page table content 
  3545                              <1> 	; EAX = Physical (base) address of the new page table
  3546 0000590E E813F3FFFF          <1> 	call	clear_page ; Clear page content
  3547                              <1> 	;
  3548 00005913 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  3549                              <1> 		 ; set bit 0, bit 1 and bit 2 to 1
  3550                              <1> 		 ; (present, writable, user)
  3551 00005915 8946FC              <1> 	mov	[esi-4], eax
  3552                              <1> a_u_pd_2:
  3553 00005918 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3554                              <1> 	; EAX = PHYSICAL (flat) ADDRESS OF THE PAGE TABLE
  3555 0000591C 8B3C24              <1> 	mov	edi, [esp] ; *
  3556                              <1> 	; EDI = PTE index (of page directory)
  3557                              <1> 	;and	edi, PTE_MASK ; PTE entry index in the page table	
  3558                              <1> 	; EBX = next PDE address
  3559 0000591F 89FE                <1> 	mov	esi, edi ; PTE index in page table (0-1023)
  3560 00005921 C1E702              <1> 	shl	edi, 2 ; convert PTE index to dword offset
  3561 00005924 01C7                <1> 	add	edi, eax ; now, edi points to requested PTE
  3562                              <1> a_u_pt_0:
  3563                              <1> 	; 02/05/2017
  3564 00005926 8B07                <1> 	mov	eax, [edi]
  3565                              <1> 	;
  3566 00005928 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
  3567 0000592A 7445                <1> 	jz	short a_u_pt_1
  3568                              <1> 	;
  3569 0000592C A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3570                              <1> 				  ; (must be 1)
  3571 0000592E 7550                <1> 	jnz	short a_u_pt_3
  3572                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3573 00005930 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3574                              <1> 				   ; as child's page ?
  3575 00005934 7455                <1> 	jz	short a_u_pt_4	; Clear PTE but don't deallocate the page!
  3576                              <1> 	;
  3577                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3578                              <1> 	; EDX = page directory entry index (0-1023)
  3579 00005936 52                  <1> 	push	edx ; **
  3580 00005937 53                  <1> 	push	ebx ; ***
  3581                              <1> 	; ESI = page table entry index (0-1023)
  3582                              <1> 	;push	esi ; **** ; 20/05/2017
  3583 00005938 8B1D[BC030300]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  3584 0000593E 66C1E202            <1> 	shl	dx, 2 ; *4 
  3585 00005942 01D3                <1> 	add	ebx, edx ; PTE address,0 (for the parent)
  3586 00005944 8B13                <1> 	mov	edx, [ebx] ; page table address
  3587 00005946 F6C201              <1> 	test	dl, PDE_A_PRESENT ; present (valid) or not ?
  3588 00005949 7433                <1> 	jz	short a_u_pt_2	; parent process does not use this page
  3589 0000594B 6681E200F0          <1> 	and	dx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3590 00005950 66C1E602            <1> 	shl	si, 2 ; *4
  3591                              <1> 	; ESI = page table entry offset (0-4092)
  3592 00005954 01D6                <1> 	add	esi, edx	; PTE address (for the parent)
  3593 00005956 8B1E                <1> 	mov	ebx, [esi]
  3594 00005958 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3595 0000595B 7421                <1> 	jz	short a_u_pt_2	; parent process does not use this page
  3596 0000595D 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3597 00005961 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3598 00005966 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3599 00005968 7514                <1> 	jne	short a_u_pt_2	; not same page
  3600                              <1> 				; deallocate the child's page
  3601 0000596A 800E02              <1>         or      byte [esi], PTE_A_WRITE ; convert to writable page (parent)
  3602                              <1> 	;pop	esi ; **** ; 20/05/2017
  3603 0000596D 5B                  <1> 	pop	ebx ; ***
  3604 0000596E 5A                  <1> 	pop	edx ; **
  3605 0000596F EB1A                <1> 	jmp	short a_u_pt_4
  3606                              <1> a_u_pt_1:
  3607 00005971 09C0                <1> 	or	eax, eax	; swapped page ?
  3608 00005973 7416                <1> 	jz	short a_u_pt_4	; no
  3609                              <1> 				; yes
  3610 00005975 D1E8                <1> 	shr	eax, 1
  3611 00005977 E8B5F8FFFF          <1> 	call	unlink_swap_block ; Deallocate swapped page block
  3612                              <1> 				  ; on the swap disk (or in file)
  3613 0000597C EB0D                <1> 	jmp	short a_u_pt_4
  3614                              <1> a_u_pt_2:
  3615                              <1> 	;pop	esi ; **** ; 20/05/2017
  3616 0000597E 5B                  <1> 	pop	ebx ; ***
  3617 0000597F 5A                  <1> 	pop	edx ; **
  3618                              <1> a_u_pt_3:
  3619 00005980 66A90004            <1> 	test	ax, PTE_SHARED	; shared or direct memory access indicator
  3620 00005984 7505                <1> 	jnz	short a_u_pt_4	; AVL bit 1 = 1, do not deallocate this page!
  3621                              <1> 	;
  3622                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3623 00005986 E8FFF3FFFF          <1> 	call	deallocate_page ; set the mem allocation bit of this page
  3624                              <1> 	;
  3625                              <1> a_u_pt_4:
  3626 0000598B 89E8                <1> 	mov	eax, ebp ; physical address
  3627 0000598D 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 04/03/2017
  3628 0000598F AB                  <1> 	stosd
  3629 00005990 5E                  <1> 	pop	esi ; * ; 20/05/2017
  3630 00005991 49                  <1> 	dec	ecx ; remain page count
  3631 00005992 7417                <1> 	jz	short a_u_pd_5
  3632 00005994 81C500100000        <1> 	add	ebp, PAGE_SIZE
  3633 0000599A 46                  <1> 	inc	esi ; next PTE (index)
  3634                              <1> 	; 20/05/2017
  3635                              <1> 	;cmp	esi, PAGE_SIZE/4 ; 1024
  3636                              <1> 	;jb	short a_u_pt_0
  3637 0000599B 6681E6FF03          <1> 	and	si, PTE_MASK ; 3FFh (0 to 1023)
  3638 000059A0 56                  <1> 	push	esi ; *
  3639 000059A1 7583                <1> 	jnz	short a_u_pt_0 ; > 0 (<1024)
  3640                              <1> a_u_pd_3:
  3641 000059A3 42                  <1> 	inc	edx
  3642                              <1> ;	cmp	edx, 1024
  3643                              <1> ;	jnb	short a_u_pd_4 ; 02/05/2017 (error!, ecx > 0)
  3644 000059A4 89DE                <1> 	mov	esi, ebx ; the next PDE address
  3645 000059A6 E953FFFFFF          <1> 	jmp	a_u_pd_0
  3646                              <1> a_u_pd_4:
  3647                              <1> 	; 02/05/2017
  3648                              <1> ;	stc
  3649                              <1> a_u_pd_5:
  3650                              <1> 	; 20/05/2017
  3651                              <1> 	;pop	edi ; *
  3652 000059AB C3                  <1> 	retn
  3653                              <1> 
  3654                              <1> 
  3655                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
  3656                              <1> 
  3657                              <1> ;; Data:
  3658                              <1> 
  3659                              <1> ; 09/03/2015
  3660                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
  3661                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
  3662                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  3663                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  3664                              <1> ;swpd_next:  dd 0 ; next free page block
  3665                              <1> ;swpd_last:  dd 0 ; last swap page block
  2160                                  %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: 15/01/2017
     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 000059AC 9C                  <1> 	pushfd
    30 000059AD 0E                  <1> 	push 	cs
    31 000059AE E801000000          <1> 	call 	TIME_OF_DAY_1
    32 000059B3 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> ; 15/01/2017
    98                              <1> ; 14/01/2017
    99                              <1> ; 07/01/2017
   100                              <1> ; 02/01/2017
   101                              <1> ; 29/05/2016
   102                              <1> ; 29/01/2016
   103                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   104                              <1> 
   105                              <1> ; 29/05/2016
   106                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   107                              <1> int35h:  ; Date/Time functions
   108                              <1> 
   109                              <1> TIME_OF_DAY_1:
   110                              <1> 	;sti				; INTERRUPTS BACK ON
   111                              <1> 	; 29/05/2016
   112 000059B4 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   113                              <1> 	;
   114 000059B9 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
   115 000059BC F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
   116                              <1> 	; (*) jc short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
   117 000059BD 721A                <1> 	jc	short _TIME_9 ; 29/05/2016
   118                              <1> 
   119 000059BF 1E                  <1> 	push	ds
   120 000059C0 56                  <1> 	push	esi
   121 000059C1 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
   122 000059C5 8EDE                <1> 	mov	ds, si
   123                              <1> 
   124                              <1> 	;;15/01/2017
   125                              <1> 	; 14/01/2017
   126                              <1> 	; 02/01/2017
   127                              <1> 	;;mov	byte [intflg], 35h	; date & time interrupt 
   128                              <1> 	;sti
   129                              <1> 	;
   130 000059C7 C0E402              <1> 	shl	ah, 2			; convert function to dword offset
   131 000059CA 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
   132                              <1> 	;cli				; NO INTERRUPTS DURING TIME FUNCTIONS
   133 000059CD FF96[DF590000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
   134                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
   135                              <1> 	;sti				; INTERRUPTS BACK ON
   136 000059D3 B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
   137 000059D5 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
   138 000059D6 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
   139                              <1> 
   140                              <1> 	;;15/01/2017
   141                              <1> 	; 02/01/2017
   142                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
   143                              <1> 
   144                              <1> ;TIME_9:
   145                              <1> 					; RETURN WITH CY= 0 IF NO ERROR
   146                              <1> 	; (*) 29/05/2016
   147                              <1> 	; (*) retf 4 ; skip eflags on stack
   148 000059D7 7305                <1> 	jnc	short _TIME_10
   149                              <1> _TIME_9:
   150                              <1> 	; 29/05/2016 -set carry flag on stack-
   151                              <1> 	; [esp] = EIP
   152                              <1> 	; [esp+4] = CS
   153                              <1> 	; [esp+8] = E-FLAGS
   154 000059D9 804C240801          <1> 	or	byte [esp+8], 1	 ; set carry bit of eflags register
   155                              <1> 	; [esp+12] = ESP (user)
   156                              <1> 	; [esp+16] = SS (User)
   157                              <1> _TIME_10:
   158 000059DE CF                  <1> 	iretd
   159                              <1> 	
   160                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
   161                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   162                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   163                              <1> 	; // RETF instruction:
   164                              <1> 	;
   165                              <1> 	; IF OperandMode=32 THEN
   166                              <1>  	;    Load CS:EIP from stack;
   167                              <1>  	;    Set CS RPL to CPL;
   168                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
   169                              <1>  	;    Load SS:eSP from stack;
   170                              <1>  	; ELSE (* OperandMode=16 *)
   171                              <1>  	;    Load CS:IP from stack;
   172                              <1>  	;    Set CS RPL to CPL;
   173                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
   174                              <1> 	;    Load SS:eSP from stack;
   175                              <1>  	; FI;
   176                              <1> 	;
   177                              <1> 	; //					
   178                              <1> 					; ROUTINE VECTOR TABLE (AH)=
   179                              <1> RTC_TB:
   180 000059DF [FF590000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
   181 000059E3 [125A0000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
   182 000059E7 [205A0000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
   183 000059EB [4F5A0000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
   184 000059EF [915A0000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
   185 000059F3 [BE5A0000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
   186 000059F7 [0B5B0000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
   187 000059FB [5E5B0000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
   188                              <1> 
   189                              <1> RTC_TBE	equ	$
   190                              <1> 
   191                              <1> RTC_00:				; READ TIME COUNT
   192 000059FF A0[2C590100]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
   193 00005A04 C605[2C590100]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
   194 00005A0B 8B0D[28590100]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
   195 00005A11 C3                  <1> 	retn
   196                              <1> 
   197                              <1> RTC_10:				; SET TIME COUNT
   198 00005A12 890D[28590100]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
   199 00005A18 C605[2C590100]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
   200 00005A1F C3                  <1> 	retn				; RETURN WITH NO CARRY
   201                              <1> 
   202                              <1> RTC_20:				; GET RTC TIME
   203 00005A20 E8EB010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   204 00005A25 7227                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
   205                              <1> 
   206 00005A27 B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
   207 00005A29 E8FD010000          <1> 	call	CMOS_READ		; GET SECONDS
   208 00005A2E 88C6                <1> 	mov	dh, al			; SAVE
   209 00005A30 B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   210 00005A32 E8F4010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
   211 00005A37 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
   212 00005A39 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
   213 00005A3B B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
   214 00005A3D E8E9010000          <1> 	call	CMOS_READ		; GET MINUTES
   215 00005A42 88C1                <1> 	mov	cl, al			; SAVE
   216 00005A44 B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
   217 00005A46 E8E0010000          <1> 	call	CMOS_READ		; GET HOURS
   218 00005A4B 88C5                <1> 	mov	ch, al			; SAVE
   219 00005A4D F8                  <1> 	clc				; SET CY= 0
   220                              <1> RTC_29:
   221 00005A4E C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
   222                              <1> 
   223                              <1> RTC_30:				; SET RTC TIME
   224 00005A4F E8BC010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   225 00005A54 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
   226 00005A56 E817010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
   227                              <1> RTC_35:
   228 00005A5B 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
   229 00005A5D B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
   230 00005A5F E8E0010000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
   231 00005A64 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
   232 00005A66 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
   233 00005A68 E8D7010000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
   234 00005A6D 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
   235 00005A6F B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
   236 00005A71 E8CE010000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
   237                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   238                              <1> 	;mov	ah, al
   239 00005A76 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   240 00005A7A E8AC010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
   241 00005A7F 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
   242 00005A81 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
   243 00005A83 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
   244 00005A86 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
   245 00005A88 86E0                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
   246 00005A8A E8B5010000          <1> 	call	CMOS_WRITE		; SET NEW ALARM SITS
   247 00005A8F F8                  <1> 	clc				; SET CY= 0
   248 00005A90 C3                  <1> 	retn				; RETURN WITH CY= 0
   249                              <1> 
   250                              <1> RTC_40:				; GET RTC DATE
   251 00005A91 E87A010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   252 00005A96 7225                <1> 	jc	short RTC_49		; EXIT IF ERROR (CY= 1)
   253                              <1> 
   254 00005A98 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
   255 00005A9A E88C010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
   256 00005A9F 88C2                <1> 	mov	dl, al			; SAVE
   257 00005AA1 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
   258 00005AA3 E883010000          <1> 	call	CMOS_READ		; READ MONTH
   259 00005AA8 88C6                <1> 	mov	dh, al			; SAVE
   260 00005AAA B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
   261 00005AAC E87A010000          <1> 	call	CMOS_READ		; READ YEAR
   262 00005AB1 88C1                <1> 	mov	cl, al			; SAVE
   263 00005AB3 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
   264 00005AB5 E871010000          <1> 	call	CMOS_READ		; GET CENTURY BYTE
   265 00005ABA 88C5                <1> 	mov	ch, al			; SAVE
   266 00005ABC F8                  <1> 	clc				; SET CY=0
   267                              <1> RTC_49:
   268 00005ABD C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAG
   269                              <1> 
   270                              <1> RTC_50:				; SET RTC DATE
   271 00005ABE E84D010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   272 00005AC3 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
   273 00005AC5 E8A8000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   274                              <1> RTC_55:
   275 00005ACA 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
   276 00005ACE E871010000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
   277 00005AD3 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
   278 00005AD5 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
   279 00005AD7 E868010000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
   280 00005ADC 88F4                <1> 	mov	ah, dh			; GET MONTH
   281 00005ADE B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
   282 00005AE0 E85F010000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
   283 00005AE5 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
   284 00005AE7 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
   285 00005AE9 E856010000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
   286 00005AEE 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
   287 00005AF0 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
   288 00005AF2 E84D010000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
   289                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   290                              <1> 	;mov	ah, al
   291 00005AF7 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   292 00005AFB E82B010000          <1> 	call	CMOS_READ		; READ WIRRENT SETTINGS
   293 00005B00 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
   294 00005B02 86E0                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
   295 00005B04 E83B010000          <1> 	call	CMOS_WRITE		; AND START CLOCK UPDATING
   296 00005B09 F8                  <1> 	clc				; SET CY= 0
   297 00005B0A C3                  <1> 	retn				; RETURN CY=0
   298                              <1> 
   299                              <1> RTC_60:				; SET RTC ALARM
   300 00005B0B B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
   301 00005B0D E819010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   302 00005B12 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
   303 00005B14 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
   304 00005B15 7542                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
   305 00005B17 E8F4000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   306 00005B1C 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
   307 00005B1E E84F000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   308                              <1> RTC_65:	
   309 00005B23 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
   310 00005B25 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
   311 00005B27 E818010000          <1> 	call	CMOS_WRITE		; INSERT SECONDS
   312 00005B2C 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
   313 00005B2E B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
   314 00005B30 E80F010000          <1> 	call	CMOS_WRITE		; INSERT MINUTES
   315 00005B35 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
   316 00005B37 B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
   317 00005B39 E806010000          <1> 	call	CMOS_WRITE		; INSERT HOURS
   318 00005B3E E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
   319 00005B40 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
   320 00005B42 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
   321                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   322                              <1> 	;mov	ah, al
   323 00005B44 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   324 00005B48 E8DE000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
   325 00005B4D 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
   326 00005B4F 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
   327 00005B51 86E0                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
   328 00005B53 E8EC000000          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
   329 00005B58 F8                  <1> 	clc				; SET CY= 0
   330                              <1> RTC_69:
   331 00005B59 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
   332 00005B5D C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
   333                              <1> 
   334                              <1> RTC_70:				; RESET ALARM
   335                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   336                              <1> 	;mov	ah, al
   337 00005B5E 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
   338 00005B62 E8C4000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   339 00005B67 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
   340 00005B69 86E0                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
   341 00005B6B E8D4000000          <1> 	call	CMOS_WRITE		; RESTORE NEW VALUE
   342 00005B70 F8                  <1> 	clc				; SET CY= 0
   343 00005B71 C3                  <1> 	retn				; RETURN WITH NO CARRY
   344                              <1> 
   345                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
   346                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
   347                              <1> 	;mov	ah, 26h
   348 00005B72 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
   349 00005B76 E8C9000000          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
   350                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
   351                              <1> 	;mov	ah, 82h
   352 00005B7B 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
   353 00005B7F E8C0000000          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
   354 00005B84 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
   355 00005B86 E8A0000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
   356 00005B8B B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
   357 00005B8D E899000000          <1> 	call	CMOS_READ		; READ REGISTER D TO INITIALIZE
   358 00005B92 C3                  <1> 	retn
   359                              <1> 
   360                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   361                              <1> 
   362                              <1> ;--- HARDWARE INT  70 H -- ( IRQ LEVEL  8) --------------------------------------
   363                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
   364                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
   365                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
   366                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
   367                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
   368                              <1> ;										:
   369                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
   370                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
   371                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
   372                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
   373                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
   374                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
   375                              <1> ;--------------------------------------------------------------------------------
   376                              <1> 
   377                              <1> RTC_A_INT: ; 07/01/2017
   378                              <1> ;RTC_INT:				; ALARM INTERRUPT
   379 00005B93 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
   380 00005B94 50                  <1> 	push	eax			; SAVE REGISTERS
   381 00005B95 57                  <1> 	push	edi
   382                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
   383 00005B96 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
   384 00005B9A E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
   385 00005B9C 90                  <1> 	nop				; I/O DELAY
   386 00005B9D EB00                <1> 	jmp	short $+2
   387 00005B9F E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
   388 00005BA1 A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
   389 00005BA3 745D                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
   390                              <1> 
   391 00005BA5 86E0                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
   392 00005BA7 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
   393 00005BA9 90                  <1> 	nop				; I/O DELAY
   394 00005BAA EB00                <1> 	jmp	short $+2	
   395 00005BAC E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
   396 00005BAE 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
   397 00005BB0 A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
   398 00005BB2 743B                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
   399                              <1> 
   400                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
   401                              <1> 
   402 00005BB4 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
   403 00005BB8 8EDF                <1> 	mov	ds, di
   404                              <1> 	
   405 00005BBA 812D[20590100]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
   405 00005BC2 0000                <1>
   406 00005BC4 7329                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
   407                              <1> 
   408                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
   409                              <1> 
   410 00005BC6 6650                <1> 	push	ax			; SAVE INTERRUPT FLAG MASK
   411 00005BC8 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
   412 00005BCC E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
   413 00005BCE 90                  <1> 	nop				; I/O DELAY
   414 00005BCF EB00                <1> 	jmp	short $+2
   415 00005BD1 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
   416 00005BD3 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
   417 00005BD5 86C4                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
   418 00005BD7 E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
   419 00005BD9 86C4                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
   420 00005BDB E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
   421 00005BDD C605[24590100]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
   422 00005BE4 8B3D[25590100]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
   423 00005BEA C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
   424 00005BED 6658                <1> 	pop	ax			; GET INTERRUPT SOURCE BACK
   425                              <1> RTC_I_5:
   426 00005BEF A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
   427 00005BF1 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
   428                              <1> 
   429 00005BF3 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   430 00005BF5 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   431 00005BF7 FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
   432 00005BF8 52                  <1> 	push	edx
   433 00005BF9 E8329E0000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
   434 00005BFE 5A                  <1> 	pop	edx
   435 00005BFF FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
   436                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
   437 00005C00 EB94                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
   438                              <1> 
   439                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
   440 00005C02 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   441 00005C04 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   442 00005C06 B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
   443 00005C08 E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
   444 00005C0A E620                <1> 	out	INTA00,	al		; TO 8259 - 1
   445 00005C0C 5F                  <1> 	pop	edi			; RESTORE REGISTERS
   446 00005C0D 58                  <1> 	pop	eax
   447 00005C0E 1F                  <1> 	pop	ds
   448 00005C0F CF                  <1> 	iretd				; END OF INTERRUPT
   449                              <1> 
   450                              <1> 	
   451                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
   452                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   453                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
   454                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
   455 00005C10 51                  <1> 	push	ecx
   456                              <1> 
   457                              <1> 	; 29/05/2016
   458 00005C11 B968110000          <1> 	mov	ecx, ((1984+244)*4)/2	; AWARD BIOS 1999, ATIME.ASM		
   459                              <1> 					; 'WAITCPU_CK_UD_STAT'
   460                              <1> 					; (244Us + 1984Us)
   461                              <1> 					; (assume each read takes
   462                              <1> 					;  2 microseconds).
   463                              <1> 	;mov	ecx, 65535		
   464                              <1> 		;mov cx, 800		; SET TIMEOUT LOOP COUNT (= 800)	
   465                              <1> UPD_10:
   466 00005C16 B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
   467 00005C18 FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
   468 00005C19 E80D000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
   469 00005C1E A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
   470 00005C20 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
   471 00005C22 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
   472 00005C23 E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
   473 00005C25 31C0                <1> 	xor	eax, eax		; CLEAR RESULTS IF ERROR
   474                              <1> 		; xor ax, ax
   475 00005C27 F9                  <1> 	stc				; SET CARRY FOR ERROR
   476                              <1> UPD_90:
   477 00005C28 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
   478 00005C29 FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
   479 00005C2A C3                  <1> 	retn				; RETURN WITH CY FLAG SET
   480                              <1> 
   481                              <1> 
   482                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0) 
   483                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   484                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
   485                              <1> 
   486                              <1> ;--- CMOS_READ -----------------------------------------------------------------
   487                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
   488                              <1> ;									       :
   489                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
   490                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   491                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
   492                              <1> ;									       :
   493                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
   494                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
   495                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   496                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   497                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   498                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
   499                              <1> ;-------------------------------------------------------------------------------
   500                              <1> 
   501                              <1> CMOS_READ:
   502 00005C2B 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   503 00005C2C D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   504 00005C2E F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   505 00005C2F D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   506 00005C31 FA                  <1> 	cli				; DISABLE INTERRUPTS
   507 00005C32 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   508                              <1> 	; 29/05/2016
   509                              <1> 	;nop				; I/O DELAY
   510 00005C34 E6EB                <1> 	out	0ebh,al	; NEWIODELAY ; AWARD BIOS 1999, ATIME.ASM
   511                              <1> 	;
   512 00005C36 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
   513 00005C38 6650                <1> 	push	ax			; SAVE (AH) REGISTER VALUE AND CMOS BYTE
   514                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
   515                              <1> 		     ; ----- 10/06/85 (test4.asm)
   516 00005C3A B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 	; GET ADDRESS OF DEFAULT LOCATION
   517                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   518 00005C3C D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   519 00005C3E E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   520 00005C40 6658                <1> 	pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
   521 00005C42 9D                  <1> 	popf	
   522 00005C43 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
   523                              <1> 
   524                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   525                              <1> 
   526                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
   527                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
   528                              <1> ;									       :
   529                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
   530                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   531                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
   532                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
   533                              <1> ;									       :
   534                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
   535                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
   536                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   537                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   538                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   539                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
   540                              <1> ;-------------------------------------------------------------------------------
   541                              <1> 
   542                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
   543 00005C44 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   544 00005C45 6650                <1> 	push	ax			; SAVE WORK REGISTER VALUES
   545 00005C47 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   546 00005C49 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   547 00005C4A D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   548 00005C4C FA                  <1> 	cli				; DISABLE INTERRUPTS
   549 00005C4D E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   550 00005C4F 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
   551 00005C51 E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
   552 00005C53 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
   553                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   554 00005C55 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   555 00005C57 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   556 00005C59 90                  <1> 	nop				; I/O DELAY
   557 00005C5A E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
   558 00005C5C 6658                <1> 	pop	ax			; RESTORE WORK REGISTERS
   559 00005C5E 9D                  <1> 	popf
   560 00005C5F C3                  <1> 	retn
   561                              <1> 
   562                              <1> ; /// End Of TIMER FUNCTIONS ///
  2161                                  
  2162                                  Align 16
  2163                                  
  2164                                  gdt:	; Global Descriptor Table
  2165                                  	; (30/07/2015, conforming cs)
  2166                                  	; (26/03/2015)
  2167                                  	; (24/03/2015, tss)
  2168                                  	; (19/03/2015)
  2169                                  	; (29/12/2013)
  2170                                  	;
  2171 00005C60 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
  2172                                  	; 18/08/2014
  2173                                  			; 8h kernel code segment, base = 00000000h		
  2174                                  	;dw 0FFFFh, 0, 9E00h, 00CFh	; KCODE  ; 30/12/2016	 
  2175 00005C68 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
  2176                                  			; 10h kernel data segment, base = 00000000h	
  2177 00005C70 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
  2178                                  			; 1Bh user code segment, base address = 400000h ; CORE
  2179                                  	;dw 0FBFFh, 0, 0FE40h, 00CFh	; UCODE  ; 30/12/2016	
  2180 00005C78 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE 
  2181                                  			; 23h user data segment, base address = 400000h ; CORE
  2182 00005C80 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
  2183                                  			; Task State Segment
  2184 00005C88 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
  2185                                  			       ;  no IO permission in ring 3)
  2186                                  gdt_tss0:
  2187 00005C8A 0000                    	dw 0  ; TSS base address, bits 0-15 
  2188                                  gdt_tss1:
  2189 00005C8C 00                      	db 0  ; TSS base address, bits 16-23 
  2190                                  	      		; 49h	
  2191 00005C8D E9                      	db 11101001b ; E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
  2192 00005C8E 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
  2193                                  gdt_tss2:
  2194 00005C8F 00                      	db 0  ; TSS base address, bits 24-31 
  2195                                  
  2196                                  gdt_end:
  2197                                  	;; 9Eh = 1001 1110b (GDT byte 5) P=1/DPL=00/1/TYPE=1110, 
  2198                                  					;; Type= 1 (code)/C=1/R=1/A=0
  2199                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  2200                                  		; 1= Code C= Conforming, R= Readable, A = Accessed
  2201                                  
  2202                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  2203                                  					;; Type= 1 (code)/C=0/R=1/A=0
  2204                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  2205                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
  2206                                  
  2207                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  2208                                  					;; Type= 0 (data)/E=0/W=1/A=0
  2209                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  2210                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  2211                                  		; W= Writeable, A= Accessed
  2212                                  
  2213                                  	;; FEh = 1111 1110b (GDT byte 5) P=1/DPL=11/1/TYPE=1110, 
  2214                                  					;; Type= 1 (code)/C=1/R=1/A=0
  2215                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  2216                                  		; 1= Code C= Conforming, R= Readable, A = Accessed
  2217                                  	
  2218                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
  2219                                  					;; Type= 1 (code)/C=0/R=1/A=0
  2220                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  2221                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
  2222                                  
  2223                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
  2224                                  					;; Type= 0 (data)/E=0/W=1/A=0
  2225                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  2226                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  2227                                  	
  2228                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
  2229                                  
  2230                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
  2231                                  		;	 = 100000h * 1000h (G=1) = 4GB
  2232                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
  2233                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
  2234                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
  2235                                  		; AVL= Available to programmers	
  2236                                  
  2237                                  gdtd:
  2238 00005C90 2F00                            dw gdt_end - gdt - 1    ; Limit (size)
  2239 00005C92 [605C0000]                      dd gdt			; Address of the GDT
  2240                                  
  2241                                  	; 20/08/2014
  2242                                  idtd:
  2243 00005C96 7F02                            dw idt_end - idt - 1    ; Limit (size)
  2244 00005C98 [C0550100]                      dd idt			; Address of the IDT
  2245                                  
  2246                                  ; 20/02/2017
  2247                                  ;;; 11/03/2015
  2248                                  %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 00005C9C [FF5C0000]          <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 00005CA0 01                  <1> 		DB	01		;DRIVE TYPE, MEDIA TABLE
   113                              <1>                 ;DW      MD_TBL1
   114 00005CA1 [BE5C0000]          <1> 		dd	MD_TBL1
   115 00005CA5 82                  <1> 		DB	02+BIT7ON
   116                              <1> 		;DW      MD_TBL2
   117 00005CA6 [CB5C0000]          <1>                 dd      MD_TBL2
   118 00005CAA 02                  <1> DR_DEFAULT:	DB	02
   119                              <1>                 ;DW      MD_TBL3
   120 00005CAB [D85C0000]          <1> 		dd      MD_TBL3
   121 00005CAF 03                  <1> 		DB	03
   122                              <1>                 ;DW      MD_TBL4
   123 00005CB0 [E55C0000]          <1> 		dd      MD_TBL4
   124 00005CB4 84                  <1> 		DB	04+BIT7ON
   125                              <1>                 ;DW      MD_TBL5
   126 00005CB5 [F25C0000]          <1> 		dd      MD_TBL5
   127 00005CB9 04                  <1> 		DB	04
   128                              <1>                 ;DW      MD_TBL6
   129 00005CBA [FF5C0000]          <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 00005CBE DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   141 00005CBF 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   142 00005CC0 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   143 00005CC1 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   144 00005CC2 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   145 00005CC3 2A                  <1> 	DB	02AH		; GAP LENGTH
   146 00005CC4 FF                  <1> 	DB	0FFH		; DTL
   147 00005CC5 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   148 00005CC6 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   149 00005CC7 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   150 00005CC8 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   151 00005CC9 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   152 00005CCA 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 00005CCB DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   158 00005CCC 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   159 00005CCD 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   160 00005CCE 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   161 00005CCF 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   162 00005CD0 2A                  <1> 	DB	02AH		; GAP LENGTH
   163 00005CD1 FF                  <1> 	DB	0FFH		; DTL
   164 00005CD2 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   165 00005CD3 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   166 00005CD4 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   167 00005CD5 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   168 00005CD6 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   169 00005CD7 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 00005CD8 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   175 00005CD9 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   176 00005CDA 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   177 00005CDB 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   178 00005CDC 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
   179 00005CDD 1B                  <1> 	DB	01BH		; GAP LENGTH
   180 00005CDE FF                  <1> 	DB	0FFH		; DTL
   181 00005CDF 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
   182 00005CE0 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   183 00005CE1 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   184 00005CE2 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   185 00005CE3 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   186 00005CE4 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 00005CE5 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   192 00005CE6 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   193 00005CE7 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   194 00005CE8 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   195 00005CE9 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   196 00005CEA 2A                  <1> 	DB	02AH		; GAP LENGTH
   197 00005CEB FF                  <1> 	DB	0FFH		; DTL
   198 00005CEC 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   199 00005CED F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   200 00005CEE 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   201 00005CEF 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   202 00005CF0 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   203 00005CF1 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 00005CF2 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   209 00005CF3 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   210 00005CF4 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   211 00005CF5 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   212 00005CF6 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   213 00005CF7 2A                  <1> 	DB	02AH		; GAP LENGTH
   214 00005CF8 FF                  <1> 	DB	0FFH		; DTL
   215 00005CF9 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   216 00005CFA F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   217 00005CFB 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   218 00005CFC 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   219 00005CFD 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   220 00005CFE 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 00005CFF AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
   226 00005D00 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   227 00005D01 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   228 00005D02 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   229 00005D03 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
   230 00005D04 1B                  <1> 	DB	01BH		; GAP LENGTH
   231 00005D05 FF                  <1> 	DB	0FFH		; DTL
   232 00005D06 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
   233 00005D07 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   234 00005D08 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   235 00005D09 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   236 00005D0A 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   237 00005D0B 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 00005D0C E0                  <1> 	db	NO_ERR
   280 00005D0D 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
   281 00005D11 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 00005D15 00                  <1> cfd:		db 0			; current floppy drive (for GET_PARM)
   286                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
   287 00005D16 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 00005D17 90                  <1> align 2
   293                              <1> 
   294 00005D18 F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
   295                              <1> 			      ; (170h)
   296 00005D1A F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
   297                              <1> 
   298                              <1> ; 05/01/2015 
   299 00005D1C 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
   300                              <1> 
   301                              <1> ; *****************************************************************************
  2249                                  
  2250 00005D1D 90                      Align 2
  2251                                  
  2252                                  ; 04/11/2014 (Retro UNIX 386 v1)
  2253 00005D1E 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
  2254                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
  2255 00005D20 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
  2256                                  		   ; between 16 MB and 4 GB.
  2257                                  
  2258                                  ; 12/11/2014 (Retro UNIX 386 v1)
  2259 00005D22 00                      boot_drv:    db 0 ; boot drive number (physical)
  2260                                  ; 24/11/2014
  2261 00005D23 00                      drv:	     db 0 
  2262 00005D24 00                      last_drv:    db 0 ; last hdd
  2263 00005D25 00                      hdc:         db 0  ; number of hard disk drives
  2264                                  		     ; (present/detected)
  2265                                  
  2266                                  ; 24/11/2014 (Retro UNIX 386 v1)
  2267                                  ; Physical drive type & flags
  2268 00005D26 00                      fd0_type:    db 0  ; floppy drive type
  2269 00005D27 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
  2270                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
  2271                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
  2272                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
  2273                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
  2274 00005D28 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
  2275 00005D29 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
  2276 00005D2A 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
  2277 00005D2B 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
  2278                                  		     ; bit 0 - Fixed disk access subset supported
  2279                                  		     ; bit 1 - Drive locking and ejecting
  2280                                  		     ; bit 2 - Enhanced disk drive support
  2281                                  		     ; bit 3 = Reserved (64 bit EDD support)
  2282                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
  2283                                  		     ; will interpret it as 'LBA ready'!)
  2284                                  
  2285                                  ; 11/03/2015 - 10/07/2015
  2286 00005D2C 000000000000000000-     drv.cylinders: dw 0,0,0,0,0,0,0
  2286 00005D35 0000000000         
  2287 00005D3A 000000000000000000-     drv.heads:     dw 0,0,0,0,0,0,0
  2287 00005D43 0000000000         
  2288 00005D48 000000000000000000-     drv.spt:       dw 0,0,0,0,0,0,0
  2288 00005D51 0000000000         
  2289 00005D56 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
  2289 00005D5F 000000000000000000-
  2289 00005D68 000000000000000000-
  2289 00005D71 00                 
  2290 00005D72 00000000000000          drv.status:    db 0,0,0,0,0,0,0
  2291 00005D79 00000000000000          drv.error:     db 0,0,0,0,0,0,0	
  2292                                  
  2293                                  Align 2
  2294                                  
  2295                                  ;;; 11/03/2015
  2296                                  %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 00005D80 524F50514B          <1> K30:	db	82,79,80,81,75
    36 00005D85 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
    37                              <1> ;-----	SUPER-SHIFT-TABLE 
    38 00005D8A 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
    39 00005D90 161718191E1F        <1> 	db	22,23,24,25,30,31
    40 00005D96 202122232425        <1> 	db	32,33,34,35,36,37
    41 00005D9C 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
    42 00005DA2 3132                <1> 	db	49,50
    43                              <1> 
    44                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
    45                              <1> ;-----	KEY_TABLE 
    46 00005DA4 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
    47 00005DA5 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
    48 00005DAA 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
    49                              <1> _K6L    equ     $-_K6
    50                              <1> 
    51                              <1> ;-----	MASK_TABLE
    52 00005DAC 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
    53 00005DAD 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
    54 00005DB2 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
    55                              <1> 
    56                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
    57 00005DB4 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
    58 00005DBA 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
    59 00005DC0 FF7FFF111705        <1> 	db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
    60 00005DC6 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
    61 00005DCC 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
    62 00005DD2 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
    63 00005DD8 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
    64 00005DDE 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
    65 00005DE4 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
    66 00005DEA 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
    67                              <1> 	;				;----- FUNCTIONS ------		
    68 00005DEE 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
    69 00005DF4 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
    70 00005DFA 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
    71 00005E00 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
    72 00005E06 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
    73                              <1> 
    74                              <1> ;-----	TABLES FOR LOWER CASE ----------
    75 00005E0C 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
    75 00005E15 39302D3D0809        <1>
    76 00005E1B 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
    76 00005E24 705B5D0DFF61736466- <1>
    76 00005E2D 67686A6B6C3B27      <1>
    77 00005E34 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
    77 00005E3D 6D2C2E2FFF2AFF20FF  <1>
    78                              <1> ;-----	LC TABLE SCAN
    79 00005E46 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
    80 00005E4B 4041424344          <1> 	db	64,65,66,67,68
    81 00005E50 FFFF                <1> 	db	-1,-1			; NL, SL
    82                              <1> 
    83                              <1> ;-----	KEYPAD TABLE
    84 00005E52 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
    85 00005E58 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
    86 00005E5F FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
    87                              <1> 
    88                              <1> ;-----	TABLES FOR UPPER CASE ----------
    89 00005E64 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
    89 00005E6D 28295F2B0800        <1>
    90 00005E73 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
    90 00005E7C 507B7D0DFF41534446- <1>
    90 00005E85 47484A4B4C3A22      <1>
    91 00005E8C 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
    91 00005E95 4D3C3E3FFF2AFF20FF  <1>
    92                              <1> ;-----	UC TABLE SCAN
    93 00005E9E 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
    94 00005EA3 595A5B5C5D          <1> 	db	89,90,91,92,93
    95 00005EA8 FFFF                <1> 	db	-1,-1			; NL, SL
    96                              <1> 
    97                              <1> ;-----	NUM STATE TABLE
    98 00005EAA 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
    98 00005EB3 3233302E            <1>
    99                              <1> 	;
   100 00005EB7 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 00005EBC 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 00005EBD 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
   118 00005EBE 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
   119 00005EBF 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
   120 00005EC0 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
   121 00005EC1 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
   122 00005EC2 [D25E0000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
   123 00005EC6 [F25E0000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
   124 00005ECA [D25E0000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
   125 00005ECE [D25E0000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
   126                              <1> ; ------	HEAD = TAIL	INDICATES THAT THE BUFFER IS EMPTY
   127 00005ED2 0000<rept>          <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
   128                              <1> 
   129                              <1> ; /// End Of KEYBOARD DATA ///
  2297                                  %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 00005EF2 03                  <1> CRT_MODE:	db	3	; CURRENT DISPLAY MODE (TYPE)
    29 00005EF3 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 00005EF4 50                  <1> CRT_COLS:	db	80	; Number of columns
    52                              <1> 
    53                              <1> ; 01/07/2016
    54 00005EF5 00                  <1> CRT_PALETTE:	db 	0	; Current palette setting
    55                              <1> 
    56                              <1> ; 03/07/2016
    57 00005EF6 10                  <1> CHAR_HEIGHT:	db	16	; Default character height
    58 00005EF7 60                  <1> VGA_VIDEO_CTL:	db	60h	; ROM BIOS DATA AREA Offset 87h
    59 00005EF8 F9                  <1> VGA_SWITCHES:	db 	0F9h	; Feature Bit Switches (the basic screen)
    60 00005EF9 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 00005EFA 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 00005EFB 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
    77                              <1> ; 30/01/2016
    78                              <1> vmode:
    79 00005F03 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 00005F0B 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 00005F0D 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 00005F0E 0302010007040506    <1> 	db 	03h, 02h, 01h, 00h, 07h, 04h, 05h, 06h
    96                              <1> vga_g_modes: ; 31/07/2016
    97 00005F16 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 00005F1E [7E5F0000]          <1> 	dd	vga_mode_03h
   104 00005F22 [7E5F0000]          <1> 	dd	vga_mode_03h ; mode 02h -> mode 03h 
   105 00005F26 [BE5F0000]          <1> 	dd	vga_mode_01h
   106 00005F2A [BE5F0000]          <1> 	dd	vga_mode_01h ; mode 00h -> mode 01h
   107                              <1> 	;dd	vga_mode_07h
   108 00005F2E [7E5F0000]          <1> 	dd	vga_mode_03h ; mode 07h -> mode 03h
   109 00005F32 [FE5F0000]          <1> 	dd	vga_mode_04h
   110 00005F36 [FE5F0000]          <1> 	dd	vga_mode_04h ; mode 05h -> mode 04h	
   111 00005F3A [3E600000]          <1> 	dd	vga_mode_06h
   112 00005F3E [7E600000]          <1> 	dd	vga_mode_13h
   113 00005F42 [BE600000]          <1> 	dd	vga_mode_F0h
   114 00005F46 [FE600000]          <1> 	dd	vga_mode_12h
   115 00005F4A [3E610000]          <1> 	dd	vga_mode_6Ah
   116 00005F4E [7E610000]          <1> 	dd	vga_mode_0Dh
   117 00005F52 [BE610000]          <1> 	dd	vga_mode_0Eh
   118 00005F56 [FE610000]          <1> 	dd	vga_mode_10h
   119 00005F5A [3E620000]          <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 00005F5E 0000000000020202    <1> 	db	CTEXT, CTEXT, CTEXT, CTEXT, MTEXT, CGA, CGA, CGA
   132                              <1> vga_g_memmodel: ; 31/07/2016
   133 00005F66 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 00005F6E 020202020001010103- <1> 	db	2, 2, 2, 2, 0, 1, 1, 1, 3, 3, 2, 2, 1, 1, 2, 2
   139 00005F77 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 00005F7E 5018100010          <1>  	db	80, 24, 16, 00h, 10h ; tw, th-1, ch, slength (5)
   154 00005F83 00030002            <1>  	db	00h, 03h, 00h, 02h ; sequ regs (4)
   155 00005F87 67                  <1>  	db	67h	; misc reg (1)
   156 00005F88 5F4F50825581BF1F    <1>  	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
   157 00005F90 004F                <1>  	db	00h, 4Fh
   158                              <1> vga_p_cm_pos equ $ - vga_mode_03h
   159 00005F92 0D0E00000000        <1> 	db	0Dh, 0Eh, 00h, 00h, 00h, 00h
   160 00005F98 9C8E8F281F96B9A3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 1Fh, 96h, 0B9h, 0A3h
   161 00005FA0 FF                  <1> 	db	0FFh	; crtc_regs (25)
   162 00005FA1 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   163 00005FA9 38393A3B3C3D3E3F    <1>  	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   164 00005FB1 0C000F08            <1>  	db	0Ch, 00h, 0Fh, 08h  ; actl regs (20)
   165 00005FB5 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 00005FBE 2818100008          <1> 	db	40, 24, 16, 00h, 08h ; tw, th-1, ch, slength
   168 00005FC3 08030002            <1> 	db	08h, 03h, 00h, 02h  ; sequ regs
   169 00005FC7 67                  <1> 	db	67h	; misc reg
   170 00005FC8 2D2728902BA0BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 0A0h, 0BFh, 1Fh
   171 00005FD0 004F0D0E00000000    <1> 	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
   172 00005FD8 9C8E8F141F96B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 1Fh, 96h, 0B9h, 0A3h
   173 00005FE0 FF                  <1> 	db	0FFh	; crtc_regs
   174 00005FE1 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   175 00005FE9 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   176 00005FF1 0C000F08            <1> 	db	0Ch, 00h, 0Fh, 08h  ; actl regs
   177 00005FF5 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 00005FFE 2818080008          <1> 	db	40, 24, 8, 00h, 08h   ; tw, th-1, ch, slength
   192 00006003 09030002            <1> 	db	09h, 03h, 00h, 02h ; sequ regs
   193 00006007 63                  <1> 	db	63h	; misc reg
   194 00006008 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   195 00006010 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   196 00006018 9C8E8F140096B9A2    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0A2h
   197 00006020 FF                  <1> 	db	0FFh	; crtc_regs
   198 00006021 0013151702040607    <1> 	db	00h, 13h, 15h, 17h, 02h, 04h, 06h, 07h
   199 00006029 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   200 00006031 01000300            <1> 	db	01h, 00h, 03h, 00h ; actl regs
   201 00006035 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 0000603E 5018080010          <1> 	db	80, 24, 8, 00h, 10h   ;	tw, th-1, ch, slength
   204 00006043 01010006            <1> 	db	01h, 01h, 00h, 06h ; sequ regs
   205 00006047 63                  <1> 	db	63h	; misc reg
   206 00006048 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   207 00006050 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   208 00006058 9C8E8F280096B9C2    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0C2h
   209 00006060 FF                  <1> 	db	0FFh	; crtc regs
   210 00006061 0017171717171717    <1> 	db	00h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   211 00006069 1717171717171717    <1> 	db	17h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   212 00006071 01000100            <1> 	db	01h, 00h, 01, 00h  ; actl regs
   213 00006075 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 0000607E 2818080000          <1> 	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength (5)
   216 00006083 010F000E            <1> 	db	01h, 0Fh, 00h, 0Eh ; sequ regs (4)
   217 00006087 63                  <1> 	db	63h	; misc reg (1)
   218 00006088 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh 
   219 00006090 0041000000000000    <1>  	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
   220 00006098 9C8E8F284096B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 40h, 96h, 0B9h, 0A3h
   221 000060A0 FF                  <1> 	db	0FFh	; crtc regs (25)
   222 000060A1 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   223 000060A9 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   224 000060B1 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs (20)
   225 000060B5 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 000060BE 2818080000          <1> 	db 	40, 24, 8, 0, 0	; tw, th-1, ch, slength
   229 000060C3 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   230 000060C7 E3                  <1> 	db	0E3h	; misc reg
   231 000060C8 5F4F508254800D3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Dh, 3Eh 
   232 000060D0 0041000000000000    <1>  	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
   233 000060D8 EAACDF2800E706E3    <1> 	db	0EAh, 0ACh, 0DFh, 28h, 00h, 0E7h, 06h, 0E3h
   234 000060E0 FF                  <1> 	db	0FFh	; crtc regs (25)
   235 000060E1 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   236 000060E9 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   237 000060F1 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs
   238 000060F5 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 000060FE 501D100000          <1>  	db 	80, 29, 16, 0, 0 ; tw, th-1, ch, slength
   241 00006103 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   242 00006107 E3                  <1> 	db 	0E3h	; misc reg
   243 00006108 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   244 00006110 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   245 00006118 EA8CDF2800E704E3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   246 00006120 FF                  <1> 	db	0FFh	; crtc regs
   247 00006121 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   248 00006129 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   249 00006131 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   250 00006135 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 0000613E 6424100000          <1>  	db 	100, 36, 16, 0, 0 ; tw, th-1, ch, slength
   253 00006143 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   254 00006147 E3                  <1> 	db 	0E3h	; misc reg
   255 00006148 7F6363836B1B72F0    <1> 	db	7Fh, 63h, 63h, 83h, 6Bh, 1Bh, 72h, 0F0h
   256 00006150 0060000000000000    <1> 	db	00h, 60h, 00h, 00h, 00h, 00h, 00h, 00h
   257 00006158 598D5732005773E3    <1>  	db	59h, 8Dh, 57h, 32h, 00h, 57h, 73h, 0E3h
   258 00006160 FF                  <1> 	db	0FFh	; crtc regs
   259 00006161 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   260 00006169 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   261 00006171 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   262 00006175 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 0000617E 2818080020          <1>  	db 	40, 24, 8, 0, 20h ; tw, th-1, ch, slength
   265 00006183 090F0006            <1> 	db	09h, 0Fh, 00h, 06h ; sequ regs
   266 00006187 63                  <1> 	db 	63h	; misc reg
   267 00006188 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   268 00006190 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   269 00006198 9C8E8F140096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0E3h
   270 000061A0 FF                  <1> 	db	0FFh	; crtc regs
   271 000061A1 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   272 000061A9 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   273 000061B1 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   274 000061B5 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 000061BE 5018080040          <1>  	db 	80, 24, 8, 0, 40h ; tw, th-1, ch, slength
   277 000061C3 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   278 000061C7 63                  <1> 	db 	63h	; misc reg
   279 000061C8 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   280 000061D0 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   281 000061D8 9C8E8F280096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0E3h
   282 000061E0 FF                  <1> 	db	0FFh	; crtc regs
   283 000061E1 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   284 000061E9 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   285 000061F1 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   286 000061F5 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 000061FE 50180E0080          <1>  	db 	80, 24, 14, 0, 80h ; tw, th-1, ch, slength
   289 00006203 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   290 00006207 A3                  <1> 	db 	0A3h	; misc reg
   291 00006208 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   292 00006210 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   293 00006218 83855D280F63BAE3    <1>  	db	83h, 85h, 5Dh, 28h, 0Fh, 63h, 0BAh, 0E3h
   294 00006220 FF                  <1> 	db	0FFh	; crtc regs
   295 00006221 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   296 00006229 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   297 00006231 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   298 00006235 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 0000623E 501D100000          <1>  	db 	80, 29, 16, 0, 0   ; tw, th-1, ch, slength
   301 00006243 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   302 00006247 E3                  <1> 	db 	0E3h	; misc reg
   303 00006248 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   304 00006250 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   305 00006258 EA8CDF2800E704E3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   306 00006260 FF                  <1> 	db	0FFh	; crtc regs
   307 00006261 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   308 00006269 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   309 00006271 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   310 00006275 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 ///
  2298                                  ;%include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
  2299                                  ;;;
  2300                                  
  2301                                  Align 2
  2302                                  
  2303                                  %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: 31/12/2017
     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> ; 31/12/2017
    79                              <1> ; 19/02/2017
    80                              <1> ; 15/10/2016
    81                              <1> ; 20/05/2016
    82                              <1> ; 19/05/2016
    83                              <1> ; 18/05/2016
    84                              <1> ; 29/04/2016 
    85                              <1> ; TRDOS 386 (TRDOS v2.0) system calls - temporary List 
    86                              <1> ; 14/07/2013 - 21/09/2015 (Retro UNIX 8086 & 386 system calls) 
    87                              <1> _ver 	equ 0 ; Get TRDOS version (v2.0)
    88                              <1> _exit 	equ 1
    89                              <1> _fork 	equ 2
    90                              <1> _read 	equ 3
    91                              <1> _write	equ 4
    92                              <1> _open	equ 5
    93                              <1> _close 	equ 6
    94                              <1> _wait 	equ 7
    95                              <1> _creat 	equ 8
    96                              <1> _rename	equ 9  ; TRDOS 386, Rename File (31/12/2017)	
    97                              <1> _delete	equ 10 ; TRDOS 386, Delete File (29/12/2017)
    98                              <1> _exec	equ 11
    99                              <1> _chdir	equ 12
   100                              <1> _time 	equ 13 ; TRDOS 386, Get Sys Date&Time (30/12/2017)
   101                              <1> _mkdir 	equ 14
   102                              <1> _chmod	equ 15 ; TRDOS 386, Change Attributes (30/12/2017) 
   103                              <1> _rmdir	equ 16 ; TRDOS 386, Remove Directory (29/12/2017)
   104                              <1> _break	equ 17
   105                              <1> _drive	equ 18 ; TRDOS 386, Get/Set Current Drv (30/12/2017) 
   106                              <1> _seek	equ 19
   107                              <1> _tell 	equ 20
   108                              <1> _mem	equ 21 ; TRDOS 386, Get Total&Free Mem (31/12/2017)
   109                              <1> _prompt	equ 22 ; TRDOS 386, Change Cmd Prompt (31/12/2017)
   110                              <1> _path	equ 23 ; TRDOS 386, Get/Set Run Path (31/12/2017)
   111                              <1> _env	equ 24 ; TRDOS 386, Get/Set Env Vars (31/12/2017)
   112                              <1> _stime	equ 25 ; TRDOS 386, Set Sys Date&Time (30/12/2017)
   113                              <1> _quit	equ 26	
   114                              <1> _intr	equ 27
   115                              <1> _dir	equ 28 ; TRDOS 386, Get Curr Drive&Dir (30/12/2017) 
   116                              <1> _emt 	equ 29
   117                              <1> _ldrvt 	equ 30 ; TRDOS 386, Get Logical DOS DDT (30/12/2017)
   118                              <1> _video  equ 31 ; TRDOS 386 Video Functions (16/05/2016)
   119                              <1> _audio	equ 32 ; TRDOS 386 Video Functions (16/05/2016)
   120                              <1> _timer	equ 33 ; TRDOS 386 Timer Functions (18/05/2016)
   121                              <1> _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
   122                              <1> _msg	equ 35 ; Retro UNIX 386 v1 feature only !
   123                              <1> _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
   124                              <1> _fpsave equ 37 ; TRDOS 386 FPU state option (28/02/2017)
   125                              <1> _pri 	equ 38 ; change priority - TRDOS 386 (20/05/2016)
   126                              <1> _rele	equ 39 ; TRDOS 386 (19/05/2016)
   127                              <1> _fff	equ 40 ; Find First File - TRDOS 386 (15/10/2016)
   128                              <1> _fnf	equ 41 ; Find Next File - TRDOS 386 (15/10/2016)
   129                              <1> _alloc	equ 42 ; Allocate memory - TRDOS 386 (19/02/2017)
   130                              <1> 	       ; TRDOS 386 (19/02/2017) DMA buff fuctions		
   131                              <1> _dalloc equ 43 ; Deallocate mem - TRDOS 386 (19/02/2017)
   132                              <1> _calbac equ 44 ; Set IRQ callback - TRDOS 386 (20/02/2017)  				
   133                              <1> _dma	equ 45 ; DMA service - TRDOS 386 (20/08/2017)  
   134                              <1> 
   135                              <1> %macro sys 1-4
   136                              <1>     ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
   137                              <1>     ; 03/09/2015	
   138                              <1>     ; 13/04/2015
   139                              <1>     ; Retro UNIX 386 v1 system call.		
   140                              <1>     %if %0 >= 2   
   141                              <1>         mov ebx, %2
   142                              <1>         %if %0 >= 3    
   143                              <1>             mov ecx, %3
   144                              <1>             %if %0 = 4
   145                              <1>                mov edx, %4   
   146                              <1>             %endif
   147                              <1>         %endif
   148                              <1>     %endif
   149                              <1>     mov eax, %1
   150                              <1>     ;int 30h
   151                              <1>     int 40h ; TRDOS 386 (TRDOS v2.0)		   
   152                              <1> %endmacro
   153                              <1> 
   154                              <1> ; TRDOS 386 system calls, interrupt number
   155                              <1> ; 25/12/2016
   156                              <1> SYSCALL_INT_NUM   equ '40' ; '40h'
   157                              <1> 
   158                              <1> ; 13/05/2015 - ERROR CODES
   159                              <1> ERR_FILE_NOT_OPEN  equ 10 ; 'file not open !' error
   160                              <1> ERR_FILE_ACCESS    equ 11 ; 'permission denied !' error
   161                              <1> ; 14/05/2015
   162                              <1> ERR_DIR_ACCESS     equ 11 ; 'permission denied !' error
   163                              <1> ERR_FILE_NOT_FOUND equ 12 ; 'file not found !' error
   164                              <1> ERR_TOO_MANY_FILES equ 13 ; 'too many open files !' error
   165                              <1> ERR_DIR_EXISTS     equ 14 ; 'directory already exists !' error 	
   166                              <1> ; 16/05/2015		
   167                              <1> ERR_DRV_NOT_RDY    equ 15 ; 'drive not ready !' error
   168                              <1> ; 18/05/2015
   169                              <1> ERR_DEV_NOT_RDY    equ 15 ; 'device not ready !' error
   170                              <1> ERR_DEV_ACCESS     equ 11 ; 'permission denied !' error 
   171                              <1> ERR_DEV_NOT_OPEN   equ 10 ; 'device not open !' error	
   172                              <1> ; 07/06/2015
   173                              <1> ERR_FILE_EOF	   equ 16 ; 'end of file !' error
   174                              <1> ERR_DEV_VOL_SIZE   equ 16 ; 'out of volume !' error
   175                              <1> ; 09/06/2015
   176                              <1> ERR_DRV_READ	   equ 17 ; 'disk read error !'
   177                              <1> ERR_DRV_WRITE	   equ 18 ; 'disk write error !'
   178                              <1> ; 16/06/2015
   179                              <1> ERR_NOT_DIR	   equ 19 ; 'not a (valid) directory !' error
   180                              <1> ERR_FILE_SIZE	   equ 20 ; 'file size error !'	
   181                              <1> ; 22/06/2015
   182                              <1> ERR_NOT_SUPERUSER  equ 11 ; 'permission denied !' error
   183                              <1> ERR_NOT_OWNER      equ 11 ; 'permission denied !' error
   184                              <1> ERR_NOT_FILE       equ 11 ; 'permission denied !' error	
   185                              <1> ; 23/06/2015
   186                              <1> ERR_FILE_EXISTS    equ 14 ; 'file already exists !' error
   187                              <1> ERR_DRV_NOT_SAME   equ 21 ; 'not same drive !' error
   188                              <1> ERR_DIR_NOT_FOUND  equ 12 ; 'directory not found !' error
   189                              <1> ERR_NOT_EXECUTABLE equ 22 ; 'not executable file !' error
   190                              <1> ; 27/06/2015
   191                              <1> ERR_INV_PARAMETER  equ 23 ; 'invalid parameter !' error
   192                              <1> ERR_INV_DEV_NAME   equ 24 ; 'invalid device name !' error
   193                              <1> ; 29/06/2015
   194                              <1> ERR_TIME_OUT	   equ 25 ; 'time out !' error			
   195                              <1> ERR_DEV_NOT_RESP   equ 25 ; 'device not responding !' error
   196                              <1> ; 10/10/2016
   197                              <1> ERR_INV_FILE_NAME  equ 26 ; 'invalid file name !' error
   198                              <1> ERR_INV_FLAGS	   equ 23 ; 'invalid flags !' error
   199                              <1> ; For code compatibility with previous version of TRDOS (2011)
   200                              <1> ; (Temporary error codes for current TRDOS 386 -2016- version) 
   201                              <1> ERR_NO_MORE_FILES  equ 12 ; 'no more files !' error
   202                              <1> ERR_PATH_NOT_FOUND equ  3 ; 'path not found !' error 
   203                              <1> 			  ; 'dir not found !' ; TRDOS 8086
   204                              <1> ERR_NOT_FOUND:	   equ  2 ; 'file not found !' ; TRDOS 8086
   205                              <1> ERR_DISK_SPACE	   equ 39 ; 'out of volume !' TRDOS 8086
   206                              <1> 			  ; 'insufficient disk space !' ; 27h
   207                              <1> ERR_DISK_WRITE	   equ 30 ; 'disk write protected !' ; 16/10/2016
   208                              <1> ERR_ACCESS_DENIED  equ  5 ; 'access denied !' ; TRDOS 8086 	
   209                              <1> ; 28/02/2017
   210                              <1> ERR_PERM_DENIED	   equ 11 ; 'permission denied !' error  	
   211                              <1> ; 18/05/2016
   212                              <1> ERR_MISC	   equ 27 ; miscellaneous/other errors
   213                              <1> ; 15/10/2016
   214                              <1> ; TRDOS 8086 -> TRDOS 386 (0Bh -> 28)
   215                              <1> ERR_INV_FORMAT	   equ 28 ; 'invalid format !' error
   216                              <1> ; TRDOS 8086 -> TRDOS 386 (0Dh -> 29)
   217                              <1> ERR_INV_DATA	   equ 29 ; 'invalid data !' error
   218                              <1> ; TRDOS 8086 -> TRDOS 386 (0Eh -> 20)
   219                              <1> ERR_ZERO_LENGTH	   equ 20  ; 'zero length !' error 	
   220                              <1> ; TRDOS 8086 -> TRDOS 386 (15h -> 17, 1Dh -> 18, 1Eh -> 17) 	
   221                              <1> ERR_DRV_NR_READ	   equ 17 ; 'drive not ready or read error !'
   222                              <1> ERR_DRV_NR_WRITE   equ 18 ; 'drive not ready or write error !'		
   223                              <1> ; 15/10/2016
   224                              <1> ERR_INV_PATH_NAME  equ 19 ; 'bad path name !' error
   225                              <1> ERR_BAD_CMD_ARG	   equ  1 ; 'bad command argument !' ; TRDOS 8086
   226                              <1> ERR_INV_FNUMBER	   equ  1 ; 'invalid function number !' ; TRDOS 8086
   227                              <1> ERR_BIG_FILE	   equ  8 ; 'big file & out of memory ! ; TRDOS 8086 	
   228                              <1> ERR_BIG_DATA	   equ  8 ; 'big data & out of memory ! ; TRDOS 8086
   229                              <1> ERR_CLUSTER	   equ 35 ; 'cluster not available !' ; TRDOS 8086
   230                              <1> ERR_OUT_OF_MEMORY  equ  4 ; 'out of memory !'
   231                              <1> 			  ; 'insufficient memory !'
   232                              <1> ERR_P_VIOLATION	   equ	6 ; 'protection violation !'
   233                              <1> ERR_PAGE_FAULT	   equ 224 ;'page fault !' ;0E0h						 
   234                              <1> ERR_SWP_DISK_READ  	   equ 40
   235                              <1> ERR_SWP_DISK_NOT_PRESENT   equ 41
   236                              <1> ERR_SWP_SECTOR_NOT_PRESENT equ 42
   237                              <1> ERR_SWP_NO_FREE_SPACE      equ 43
   238                              <1> ERR_SWP_DISK_WRITE         equ 44
   239                              <1> ERR_SWP_NO_PAGE_TO_SWAP    equ 45
   240                              <1> ; 10/04/2017
   241                              <1> ERR_BUFFER	   equ 46  ; 'buffer error !'
   242                              <1> ; 28/08/2017 (20/08/2017)
   243                              <1> ERR_DMA		   equ -1  ; DMA buffer (allocation/misc.) error!
   244                              <1> 
   245                              <1> ; 26/08/2015
   246                              <1> ; 24/07/2015
   247                              <1> ; 24/06/2015
   248                              <1> MAX_ARG_LEN	   equ 256 ; max. length of sys exec arguments
   249                              <1> ; 01/07/2015
   250                              <1> MAX_MSG_LEN	   equ 255 ; max. msg length for 'sysmsg'
   251                              <1> ;	
   252                              <1> ; 06/10/2016
   253                              <1> OPENFILES	   equ 10  ; max. number of open files (system)
   254                              <1> ; 07/10/2016
   255                              <1> ;NUMOFDEVICES	   equ 20  ; max. num of available devices (sys)
   256                              <1> 			 		
  2304                                  %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
  2305                                  %include 'trdosk1.s' ; 04/01/2016 
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.1) - SYS INIT : trdosk1.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/01/2018
     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> 	; 20/01/2018  (v2.0.1)
    18                              <1> 	; 23/01/2017  (v2.0.0)
    19                              <1> 	; 07/05/2016
    20                              <1> 	; 02/05/2016
    21                              <1> 	; 24/04/2016
    22                              <1> 	; 14/04/2016
    23                              <1> 	; 13/04/2016
    24                              <1> 	; 30/03/2016
    25                              <1> 	; 24/01/2016
    26                              <1> 	; 06/01/2016
    27                              <1> 	; 04/01/2016
    28                              <1> 
    29                              <1> 	; 23/01/2017 - reset timer frequency (to 18.2Hz)
    30 0000627E B036                <1> 	mov	al, 00110110b ; 36h
    31 00006280 E643                <1>  	out	43h, al
    32 00006282 31C0                <1> 	xor	eax, eax  ; sub	al, al ; 0
    33 00006284 E640                <1> 	out	40h, al ; LB
    34 00006286 E640                <1> 	out	40h, al ; HB
    35                              <1>  	; 
    36                              <1> 	; 30/03/2016
    37                              <1> 	; Clear Logical DOS Disk Description Tables Area
    38                              <1> 	;xor	eax, eax
    39 00006288 BF00010900          <1> 	mov	edi, Logical_DOSDisks
    40 0000628D B980060000          <1> 	mov	ecx, 6656/4 ; 26*256 = 6656 bytes
    41 00006292 F3AB                <1> 	rep	stosd ; 1664 times 4 bytes
    42                              <1> 
    43 00006294 B83F3A2F00          <1> 	mov	eax, '?:/'
    44 00006299 A3[6F590100]        <1> 	mov	[Current_Dir_Drv], eax
    45                              <1> 
    46                              <1> 	; Logical DRV INIT (only for hard disks)
    47 0000629E E813040000          <1> 	call 	ldrv_init  ; trdosk2.s
    48                              <1> 	
    49                              <1> 	; When floppy_drv_init call is disabled
    50                              <1> 	; media changed sign is needed
    51                              <1> 	; for proper drive initialization
    52                              <1>         
    53 000062A3 BE00010900          <1> 	mov 	esi, Logical_DOSDisks
    54 000062A8 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
    55 000062AA 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
    56 000062AD 8806                <1> 	mov 	[esi], al ; A:
    57 000062AF 81C600010000        <1> 	add 	esi, 100h 
    58 000062B5 8806                <1> 	mov 	[esi], al ; B: 
    59                              <1>            
    60                              <1> _current_drive_bootdisk:
    61 000062B7 8A15[225D0000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
    62 000062BD 80FAFF              <1> 	cmp 	dl, 0FFh
    63 000062C0 740A                <1> 	je 	short _last_dos_diskno_check
    64                              <1> _boot_drive_check:
    65 000062C2 80FA80              <1> 	cmp 	dl, 80h
    66 000062C5 7218                <1> 	jb 	short _current_drive_a
    67 000062C7 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
    68 000062CA EB13                <1> 	jmp 	short _current_drive_a 
    69                              <1> 
    70                              <1> _last_dos_diskno_check:
    71 000062CC 8A15[3A0D0100]      <1> 	mov 	dl, [Last_DOS_DiskNo]
    72 000062D2 80FA02              <1> 	cmp 	dl, 2
    73 000062D5 7706                <1> 	ja 	short _current_drive_c
    74 000062D7 7406                <1> 	je 	short _current_drive_a
    75 000062D9 30D2                <1> 	xor 	dl, dl ; A:
    76 000062DB EB02                <1> 	jmp 	short _current_drive_a
    77                              <1> 
    78                              <1> _current_drive_c:
    79 000062DD B202                <1> 	mov 	dl, 2 ; C:
    80                              <1> 
    81                              <1> _current_drive_a:
    82 000062DF 8815[235D0000]      <1> 	mov	[drv], dl
    83 000062E5 BE[3C0D0100]        <1>         mov     esi, msg_CRLF_temp
    84 000062EA E8AE000000          <1> 	call 	print_msg
    85                              <1> 
    86 000062EF 8A15[235D0000]      <1> 	mov	dl, [drv]
    87                              <1> _default_drive_c:
    88 000062F5 E8210C0000          <1> 	call 	change_current_drive
    89 000062FA 731C                <1> 	jnc 	short _start_mainprog
    90                              <1> 
    91                              <1> _drv_not_ready_error: 
    92 000062FC BE[F70F0100]        <1> 	mov 	esi, msgl_drv_not_ready
    93 00006301 E897000000          <1> 	call 	print_msg
    94                              <1>         ;jmp	_end_of_mainprog
    95                              <1> 
    96                              <1> 	; 20/01/2018
    97 00006306 B202                <1> 	mov	dl, 2
    98 00006308 3815[235D0000]      <1> 	cmp	[drv], dl
    99 0000630E 736B                <1> 	jnb	short _end_of_mainprog
   100 00006310 8815[235D0000]      <1> 	mov	[drv], dl
   101 00006316 EBDD                <1> 	jmp	short _default_drive_c
   102                              <1> 
   103                              <1> _start_mainprog:
   104                              <1> 	; 07/01/2017
   105                              <1> 	; 07/05/2016
   106                              <1> 	; 02/05/2016
   107                              <1> 	; 24/04/2016
   108                              <1> 	; Retro UNIX 386 v1, 'sys_init' (u0.s)
   109                              <1> 	; 23/06/2015
   110                              <1> 
   111                              <1> 	; 02/05/2016
   112                              <1> 	; 24/04/2016
   113 00006318 66B80100            <1> 	mov	ax, 1
   114 0000631C A2[B3030300]        <1> 	mov	[u.uno], al
   115 00006321 66A3[4E030300]      <1> 	mov	[mpid], ax
   116 00006327 66A3[20000300]      <1> 	mov	[p.pid], ax
   117 0000632D A2[B0000300]        <1> 	mov	[p.stat], al
   118 00006332 C605[A8030300]04    <1> 	mov	byte [u.quant], time_count  ; 07/01/2017
   119                              <1> 	;
   120 00006339 A1[A8580100]        <1> 	mov	eax, [k_page_dir]
   121 0000633E A3[B8030300]        <1> 	mov	[u.pgdir], eax ; reset
   122                              <1> 	;
   123 00006343 E864E8FFFF          <1> 	call	allocate_page
   124 00006348 0F82A3000000        <1> 	jc	panic
   125 0000634E A3[B4030300]        <1> 	mov	[u.upage], eax ; user structure page	
   126 00006353 A3[C0000300]        <1> 	mov	[p.upage], eax
   127 00006358 E8C9E8FFFF          <1> 	call	clear_page
   128                              <1> 	;
   129                              <1> 	; 24/08/2015
   130 0000635D FE0D[5B030300]      <1> 	dec 	byte [sysflg] ; FFh = ready for system call
   131                              <1> 			      ; 0 = executing a system call
   132                              <1> 	; 13/04/2016
   133                              <1> 	; Clear Environment Variables Page/Area
   134 00006363 BF00300900          <1> 	mov	edi, Env_Page ; 93000h
   135 00006368 B980000000          <1> 	mov	ecx, Env_Page_Size / 4 	; 512/4  (4096/4)				 	  		 	  
   136 0000636D 31C0                <1> 	xor	eax, eax
   137 0000636F F3AB                <1> 	rep	stosd
   138                              <1> 
   139                              <1> 	; 14/04/2016
   140 00006371 E8FC340000          <1>  	call	mainprog_startup_configuration
   141                              <1> 
   142 00006376 E8E10C0000          <1>         call    dos_prompt
   143                              <1>               
   144                              <1> _end_of_mainprog:
   145 0000637B BE[3C0D0100]        <1>         mov     esi, msg_CRLF_temp
   146 00006380 E818000000          <1> 	call 	print_msg
   147 00006385 BE[420D0100]        <1> 	mov 	esi, mainprog_Version
   148 0000638A E80E000000          <1> 	call 	print_msg
   149                              <1> 	; 24/01/2016
   150 0000638F 28E4                <1> 	sub	ah, ah
   151 00006391 E8B0A8FFFF          <1> 	call	int16h ; call getch
   152 00006396 E990ADFFFF          <1> 	jmp	cpu_reset
   153                              <1> 
   154 0000639B EBFE                <1> infinitiveloop: jmp short infinitiveloop
   155                              <1> 
   156                              <1> print_msg:
   157                              <1> 	; 13/05/2016
   158                              <1> 	; 04/01/2016
   159                              <1> 	; 01/07/2015
   160                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   161                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   162                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
   163                              <1> 	;
   164 0000639D 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   165                              <1> 	;mov	bl, 07h ; Black background, light gray forecolor
   166                              <1> 
   167 000063A3 AC                  <1> 	lodsb
   168                              <1> pmsg1:
   169 000063A4 56                  <1> 	push 	esi
   170                              <1> 	;mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   171 000063A5 B307                <1> 	mov	bl, 07h ; Black background, light gray forecolor
   172 000063A7 E836B9FFFF          <1> 	call 	_write_tty
   173 000063AC 5E                  <1> 	pop	esi
   174 000063AD AC                  <1> 	lodsb
   175 000063AE 20C0                <1> 	and 	al, al
   176 000063B0 75F2                <1> 	jnz 	short pmsg1
   177 000063B2 C3                  <1> 	retn
   178                              <1> 
   179                              <1> clear_screen:
   180                              <1> 	; 13/05/2016
   181                              <1> 	; 30/01/2016
   182                              <1> 	; 24/01/2016
   183                              <1> 	; 04/01/2016
   184 000063B3 0FB61D[D6580100]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
   185 000063BA 8AA3[035F0000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
   186 000063C0 80FC04              <1> 	cmp	ah, 4
   187 000063C3 7205                <1> 	jb	short cls1
   188 000063C5 80FC07              <1> 	cmp	ah, 7
   189 000063C8 7526                <1> 	jne	short vga_clear
   190                              <1> cls1:
   191                              <1> 	;mov	bh, bl
   192                              <1> 	;mov	bl, 7
   193 000063CA 3A25[F25E0000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
   194                              <1> 	;je	short cls2 ; yes (current video mode = 3)
   195                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
   196                              <1> 	;;retn
   197                              <1> 	;jmp	set_mode_3
   198 000063D0 0F8516B9FFFF        <1> 	jne	set_mode_3
   199                              <1> cls2:
   200 000063D6 88DF                <1> 	mov	bh, bl ; video page (0 to 7)
   201 000063D8 B307                <1> 	mov	bl, 07h ; attribute to be used on blanked line
   202 000063DA 28C0                <1> 	sub 	al, al ; 0 =  entire window
   203 000063DC 6631C9              <1> 	xor 	cx, cx
   204 000063DF 66BA4F18            <1> 	mov 	dx, 184Fh
   205 000063E3 E852B6FFFF          <1> 	call	_scroll_up ; 24/01/2016
   206                              <1> 	;
   207                              <1> 	;mov	bh, [ACTIVE_PAGE] ; video page number (0 to 7)
   208 000063E8 6631D2              <1> 	xor 	dx, dx
   209 000063EB E888B9FFFF          <1> 	call	_set_cpos ; 24/01/2016 
   210                              <1> 	;retn
   211                              <1> vga_clear:
   212 000063F0 C3                  <1> 	retn	
   213                              <1> 
   214                              <1> panic:
   215                              <1> 	; 13/05/2016 (TRDOS 386 = TRDOS v2)
   216                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   217                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   218 000063F1 BE[DA190100]        <1> 	mov 	esi, panic_msg
   219 000063F6 E8A2FFFFFF          <1> 	call 	print_msg
   220                              <1> key_to_reboot:
   221                              <1>         ; 24/01/2016
   222 000063FB 28E4                <1>         sub     ah, ah
   223 000063FD E844A8FFFF          <1>         call    int16h ; call   getch
   224                              <1>         ; wait for a character from the current tty
   225                              <1> 	;
   226 00006402 B00A                <1> 	mov	al, 0Ah
   227 00006404 8A3D[D6580100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
   228 0000640A B307                <1> 	mov	bl, 07h ; Black background, 
   229                              <1> 			; light gray forecolor
   230 0000640C E8D1B8FFFF          <1> 	call 	_write_tty
   231 00006411 E915ADFFFF          <1> 	jmp	cpu_reset 
   232                              <1> 
   233                              <1> ctrlbrk:
   234                              <1> 	; 12/11/2015
   235                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   236                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
   237                              <1> 	;
   238                              <1> 	; INT 1Bh (control+break) handler		
   239                              <1> 	;
   240                              <1>       	; Retro Unix 8086 v1 feature only!
   241                              <1>       	;
   242 00006416 66833D[AA030300]00  <1> 	cmp 	word [u.intr], 0
   243 0000641E 7645                <1> 	jna 	short cbrk4
   244                              <1> cbrk0:
   245                              <1> 	; 12/11/2015
   246                              <1> 	; 06/12/2013
   247 00006420 66833D[AC030300]00  <1> 	cmp 	word [u.quit], 0
   248 00006428 743B                <1> 	jz	short cbrk4
   249                              <1> 	;
   250                              <1> 	; 20/09/2013	
   251 0000642A 6650                <1> 	push 	ax
   252 0000642C A0[D6580100]        <1> 	mov	al, [ptty]
   253                              <1> 	;
   254                              <1> 	; 12/11/2015
   255                              <1> 	;
   256                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
   257                              <1> 	; or ctrl+break from console (pseudo) tty
   258                              <1> 	; (!redirection!)
   259                              <1> 	;
   260 00006431 3C08                <1> 	cmp	al, 8 ; serial port tty nums > 7
   261 00006433 7211                <1>         jb      short cbrk1 ; console (pseudo) tty
   262                              <1> 	;	
   263                              <1> 	; Serial port interrupt handler sets [ptty]
   264                              <1> 	; to the port's tty number (as temporary).
   265                              <1> 	;
   266                              <1> 	; If active process is using a stdin or 
   267                              <1> 	; stdout redirection (by the shell),
   268                              <1>         ; console tty keyboard must be available
   269                              <1> 	; to terminate running process,
   270                              <1> 	; in order to prevent a deadlock. 
   271                              <1> 	;
   272 00006435 52                  <1> 	push	edx
   273 00006436 0FB615[B3030300]    <1> 	movzx	edx, byte [u.uno]
   274 0000643D 3A82[7F000300]      <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
   275 00006443 5A                  <1> 	pop	edx
   276 00006444 7412                <1> 	je	short cbrk2
   277                              <1> cbrk1:
   278 00006446 FEC0                <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
   279                              <1> 	; 06/12/2013
   280 00006448 3A05[94030300]      <1> 	cmp	al, [u.ttyp] ; recent open tty (r)
   281 0000644E 7408                <1> 	je	short cbrk2	
   282 00006450 3A05[95030300]      <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
   283 00006456 750B                <1> 	jne	short cbrk3	
   284                              <1> cbrk2:
   285                              <1> 	;; 06/12/2013
   286                              <1> 	;mov	ax, [u.quit]
   287                              <1> 	;and	ax, ax
   288                              <1> 	;jz	short cbrk3
   289                              <1> 	;
   290 00006458 6631C0              <1> 	xor	ax, ax ; 0
   291 0000645B 6648                <1> 	dec	ax
   292                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
   293 0000645D 66A3[AC030300]      <1> 	mov	[u.quit], ax
   294                              <1> cbrk3:
   295 00006463 6658                <1> 	pop	ax
   296                              <1> cbrk4:
   297 00006465 C3                  <1> 	retn
   298                              <1> 
   299                              <1> 
   300                              <1> ; 31/12/2017
   301                              <1> ; TRDOS 386 - 30/12/2017
   302                              <1> %define get_rtc_date RTC_40
   303                              <1> %define get_rtc_time RTC_20
   304                              <1> %define	set_rtc_date RTC_50
   305                              <1> %define set_rtc_time RTC_30	
   306                              <1> get_rtc_date_time:
   307                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (01/09/2014)
   308                              <1> ;epoch:
   309                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
   310                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   311                              <1> 	; 09/04/2013 (Retro UNIX 8086 v1 - UNIX.ASM)
   312                              <1> 	; 'epoch' procedure prototype: 
   313                              <1> 	; 	            UNIXCOPY.ASM, 10/03/2013
   314                              <1> 	; 14/11/2012
   315                              <1> 	; unixboot.asm (boot file configuration)
   316                              <1> 	; version of "epoch" procedure in "unixproc.asm"
   317                              <1> 	; 21/7/2012
   318                              <1> 	; 15/7/2012
   319                              <1> 	; 14/7/2012		
   320                              <1> 	; Erdogan Tan - RETRO UNIX v0.1
   321                              <1> 	; compute current date and time as UNIX Epoch/Time
   322                              <1> 	; UNIX Epoch: seconds since 1/1/1970 00:00:00
   323                              <1> 	;
   324                              <1>         ;  ((Modified registers: EAX, EDX, ECX, EBX))  
   325                              <1> 	;
   326                              <1> 
   327 00006466 E8B5F5FFFF          <1> 	call 	get_rtc_time		; Return Current Time
   328 0000646B 86E9                <1>         xchg 	ch,cl
   329 0000646D 66890D[9C550100]    <1>         mov 	[hour], cx
   330 00006474 86F2                <1>         xchg 	dh,dl
   331 00006476 668915[A0550100]    <1>         mov 	[second], dx
   332                              <1> 	;
   333 0000647D E80FF6FFFF          <1>         call 	get_rtc_date		; Return Current Date
   334 00006482 86E9                <1>         xchg 	ch,cl
   335 00006484 66890D[96550100]    <1>         mov 	[year], cx
   336 0000648B 86F2                <1>         xchg 	dh,dl
   337 0000648D 668915[98550100]    <1>         mov 	[month], dx
   338                              <1> 	;
   339 00006494 66B93030            <1> 	mov 	cx, 3030h
   340                              <1> 	;
   341 00006498 A0[9C550100]        <1> 	mov 	al, [hour] ; Hour
   342                              <1>         	; AL <= BCD number)
   343 0000649D D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   344                              <1> 					; AH = AL / 10h
   345                              <1> 					; AL = AL MOD 10h
   346 0000649F D50A                <1>         aad 	; AX= AH*10+AL
   347 000064A1 A2[9C550100]        <1> 	mov 	[hour], al
   348 000064A6 A0[9D550100]        <1> 	mov 	al, [hour+1] ; Minute
   349                              <1>         	; AL <= BCD number)
   350 000064AB D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   351                              <1> 					; AH = AL / 10h
   352                              <1> 					; AL = AL MOD 10h
   353 000064AD D50A                <1>         aad 	; AX= AH*10+AL
   354 000064AF A2[9E550100]        <1> 	mov 	[minute], al
   355 000064B4 A0[A0550100]        <1> 	mov 	al, [second] ; Second
   356                              <1>         	; AL <= BCD number)
   357 000064B9 D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   358                              <1> 					; AH = AL / 10h
   359                              <1> 					; AL = AL MOD 10h
   360 000064BB D50A                <1>         aad 	; AX= AH*10+AL
   361 000064BD A2[A0550100]        <1> 	mov 	[second], al
   362 000064C2 66A1[96550100]      <1> 	mov 	ax, [year] ; Year (century)
   363 000064C8 6650                <1>         push 	ax
   364                              <1> 	   	; AL <= BCD number)
   365 000064CA D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   366                              <1> 					; AH = AL / 10h
   367                              <1> 					; AL = AL MOD 10h
   368 000064CC D50A                <1>         aad 	; AX= AH*10+AL
   369 000064CE B464                <1> 	mov 	ah, 100
   370 000064D0 F6E4                <1> 	mul 	ah
   371 000064D2 66A3[96550100]      <1> 	mov 	[year], ax
   372 000064D8 6658                <1> 	pop	ax
   373 000064DA 88E0                <1> 	mov	al, ah
   374                              <1>         	; AL <= BCD number)
   375 000064DC D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   376                              <1> 					; AH = AL / 10h
   377                              <1> 					; AL = AL MOD 10h
   378 000064DE D50A                <1>         aad 	; AX= AH*10+AL
   379 000064E0 660105[96550100]    <1> 	add 	[year], ax
   380 000064E7 A0[98550100]        <1> 	mov 	al, [month] ; Month
   381                              <1>            	; AL <= BCD number)
   382 000064EC D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   383                              <1> 					; AH = AL / 10h
   384                              <1> 					; AL = AL MOD 10h
   385 000064EE D50A                <1>         aad 	; AX= AH*10+AL
   386 000064F0 A2[98550100]        <1> 	mov 	[month], al	
   387 000064F5 A0[99550100]        <1>         mov     al, [month+1]      	; Day
   388                              <1>            	; AL <= BCD number)
   389 000064FA D410                <1>         db 	0D4h,10h		; Undocumented inst. AAM
   390                              <1> 					; AH = AL / 10h
   391                              <1> 					; AL = AL MOD 10h
   392 000064FC D50A                <1>         aad 	; AX= AH*10+AL
   393 000064FE A2[9A550100]        <1>         mov     [day], al
   394                              <1> 	
   395 00006503 C3                  <1> 	retn	; 30/12/2017
   396                              <1> 
   397                              <1> epoch:
   398 00006504 E85DFFFFFF          <1> 	call	get_rtc_date_time ; TRDOS 386 - 30/12/2017
   399                              <1> 
   400                              <1> convert_to_epoch:
   401                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
   402                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit modification)
   403                              <1> 	; 09/04/2013 (Retro UNIX 8086 v1)
   404                              <1> 	;
   405                              <1> 	; ((Modified registers: EAX, EDX, EBX)) 
   406                              <1> 	;
   407                              <1> 	; Derived from DALLAS Semiconductor
   408                              <1> 	; Application Note 31 (DS1602/DS1603)
   409                              <1> 	; 6 May 1998
   410 00006509 29C0                <1> 	sub 	eax, eax
   411 0000650B 66A1[96550100]      <1> 	mov 	ax, [year]
   412 00006511 662DB207            <1> 	sub 	ax, 1970
   413 00006515 BA6D010000          <1> 	mov 	edx, 365
   414 0000651A F7E2                <1> 	mul 	edx
   415 0000651C 31DB                <1> 	xor 	ebx, ebx
   416 0000651E 8A1D[98550100]      <1> 	mov 	bl, [month]
   417 00006524 FECB                <1> 	dec 	bl
   418 00006526 D0E3                <1> 	shl 	bl, 1
   419                              <1> 	;sub	edx, edx
   420 00006528 668B93[A2550100]    <1> 	mov 	dx, [EBX+DMonth]
   421 0000652F 8A1D[9A550100]      <1>         mov     bl, [day]
   422 00006535 FECB                <1> 	dec 	bl
   423 00006537 01D0                <1> 	add 	eax, edx
   424 00006539 01D8                <1> 	add 	eax, ebx
   425                              <1> 			; EAX = days since 1/1/1970
   426 0000653B 668B15[96550100]    <1> 	mov 	dx, [year]
   427 00006542 6681EAB107          <1> 	sub 	dx, 1969
   428 00006547 66D1EA              <1> 	shr 	dx, 1
   429 0000654A 66D1EA              <1> 	shr 	dx, 1		
   430                              <1> 		; (year-1969)/4
   431 0000654D 01D0                <1> 	add 	eax, edx
   432                              <1> 			; + leap days since 1/1/1970
   433 0000654F 803D[98550100]02    <1> 	cmp 	byte [month], 2	; if past february
   434 00006556 7610                <1> 	jna 	short cte1
   435 00006558 668B15[96550100]    <1> 	mov 	dx, [year]
   436 0000655F 6683E203            <1> 	and 	dx, 3 ; year mod 4
   437 00006563 7503                <1> 	jnz 	short cte1		
   438                              <1> 			; and if leap year
   439 00006565 83C001              <1> 	add 	eax, 1 	; add this year's leap day (february 29)
   440                              <1> cte1: 			; compute seconds since 1/1/1970
   441 00006568 BA18000000          <1> 	mov 	edx, 24
   442 0000656D F7E2                <1> 	mul	edx
   443 0000656F 8A15[9C550100]      <1> 	mov 	dl, [hour]
   444 00006575 01D0                <1> 	add 	eax, edx
   445                              <1> 		; EAX = hours since 1/1/1970 00:00:00
   446                              <1> 	;mov	ebx, 60
   447 00006577 B33C                <1> 	mov	bl, 60
   448 00006579 F7E3                <1> 	mul	ebx
   449 0000657B 8A15[9E550100]      <1> 	mov 	dl, [minute]
   450 00006581 01D0                <1> 	add 	eax, edx
   451                              <1> 		; EAX = minutes since 1/1/1970 00:00:00
   452                              <1> 	;mov 	ebx, 60
   453 00006583 F7E3                <1> 	mul	ebx
   454 00006585 8A15[A0550100]      <1> 	mov 	dl, [second]
   455 0000658B 01D0                <1> 	add 	eax, edx
   456                              <1>  		; EAX -> seconds since 1/1/1970 00:00:00
   457 0000658D C3                  <1> 	retn
   458                              <1> 
   459                              <1> ;set_date_time:
   460                              <1> convert_from_epoch:
   461                              <1> 	; 31/12/2017 (v2.0.0)
   462                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
   463                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   464                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
   465                              <1> 	; 'convert_from_epoch' procedure prototype: 
   466                              <1> 	; 	            UNIXCOPY.ASM, 10/03/2013
   467                              <1> 	;
   468                              <1> 	; ((Modified registers: EAX, EDX, ECX, EBX))	
   469                              <1> 	;
   470                              <1> 	; Derived from DALLAS Semiconductor
   471                              <1> 	; Application Note 31 (DS1602/DS1603)
   472                              <1> 	; 6 May 1998
   473                              <1> 	;
   474                              <1> 	; INPUT:
   475                              <1> 	; EAX = Unix (Epoch) Time
   476                              <1> 	;
   477 0000658E 31D2                <1> 	xor 	edx, edx
   478 00006590 B93C000000          <1> 	mov 	ecx, 60
   479 00006595 F7F1                <1> 	div	ecx
   480                              <1> 	;mov 	[imin], eax   ; whole minutes
   481                              <1> 			  ; since 1/1/1970
   482 00006597 668915[A0550100]    <1> 	mov 	[second], dx  ; leftover seconds
   483 0000659E 29D2                <1> 	sub 	edx, edx
   484 000065A0 F7F1                <1> 	div	ecx
   485                              <1> 	;mov 	[ihrs], eax   ; whole hours
   486                              <1> 	;		      ; since 1/1/1970
   487 000065A2 668915[9E550100]    <1> 	mov 	[minute], dx  ; leftover minutes
   488 000065A9 31D2                <1> 	xor	edx, edx
   489                              <1> 	;mov 	cx, 24
   490 000065AB B118                <1> 	mov 	cl, 24
   491 000065AD F7F1                <1> 	div	ecx
   492                              <1> 	;mov 	[iday], ax   ; whole days
   493                              <1> 			     ; since 1/1/1970
   494 000065AF 668915[9C550100]    <1> 	mov 	[hour], dx   ; leftover hours
   495 000065B6 05DB020000          <1> 	add 	eax, 365+366 ; whole day since
   496                              <1> 			     ; 1/1/1968 	
   497                              <1> 	;mov 	[iday], ax
   498 000065BB 50                  <1> 	push 	eax
   499 000065BC 29D2                <1> 	sub	edx, edx
   500 000065BE B9B5050000          <1> 	mov 	ecx, (4*365)+1 ; 4 years = 1461 days
   501 000065C3 F7F1                <1> 	div	ecx
   502 000065C5 59                  <1> 	pop 	ecx
   503                              <1> 	;mov 	[lday], ax   ; count of quadyrs (4 years)
   504 000065C6 6652                <1> 	push 	dx
   505                              <1> 	;mov 	[qday], dx   ; days since quadyr began
   506 000065C8 6683FA3C            <1> 	cmp 	dx, 31 + 29  ; if past feb 29 then
   507 000065CC F5                  <1> 	cmc		     ; add this quadyr's leap day
   508 000065CD 83D000              <1> 	adc 	eax, 0	     ; to # of qadyrs (leap days)
   509                              <1> 	;mov 	[lday], ax   ; since 1968			  
   510                              <1> 	;mov 	cx, [iday]
   511 000065D0 91                  <1> 	xchg 	ecx, eax     ; ECX = lday, EAX = iday		  
   512 000065D1 29C8                <1> 	sub 	eax, ecx     ; iday - lday
   513 000065D3 B96D010000          <1> 	mov 	ecx, 365
   514 000065D8 31D2                <1> 	xor	edx, edx
   515                              <1> 	; EAX = iday-lday, EDX = 0
   516 000065DA F7F1                <1> 	div	ecx
   517                              <1> 	;mov 	[iyrs], ax   ; whole years since 1968
   518                              <1> 	;jday = iday - (iyrs*365) - lday
   519                              <1> 	;mov [jday], dx      ; days since 1/1 of current year
   520                              <1> 	;add	eax, 1968
   521 000065DC 6605B007            <1> 	add 	ax, 1968     ; compute year
   522 000065E0 66A3[96550100]      <1> 	mov 	[year], ax
   523 000065E6 6689D1              <1> 	mov 	cx, dx
   524                              <1> 	;mov 	dx, [qday]
   525 000065E9 665A                <1> 	pop 	dx
   526 000065EB 6681FA6D01          <1> 	cmp 	dx, 365	     ; if qday <= 365 and qday >= 60	
   527 000065F0 7709                <1> 	ja 	short cfe1   ; jday = jday +1
   528 000065F2 6683FA3C            <1> 	cmp 	dx, 60       ; if past 2/29 and leap year then
   529 000065F6 F5                  <1>         cmc		     ; add a leap day to the # of whole
   530 000065F7 6683D100            <1> 	adc 	cx, 0        ; days since 1/1 of current year
   531                              <1> cfe1:			
   532                              <1> 	;mov 	[jday], cx
   533 000065FB 66BB0C00            <1> 	mov 	bx, 12       ; estimate month
   534 000065FF 66BA6E01            <1> 	mov 	dx, 366      ; mday, max. days since 1/1 is 365
   535 00006603 6683E003            <1> 	and 	ax, 11b      ; year mod 4 (and dx, 3) 
   536                              <1> cfe2:	; Month calculation  ; 0 to 11  (11 to 0)	
   537 00006607 6639D1              <1> 	cmp 	cx, dx       ; mday = # of days passed from 1/1
   538 0000660A 731D                <1> 	jnb 	short cfe3
   539 0000660C 664B                <1> 	dec 	bx           ; month = month - 1
   540 0000660E 66D1E3              <1> 	shl 	bx, 1 
   541 00006611 668B93[A2550100]    <1> 	mov 	dx, [EBX+DMonth] ; # elapsed days at 1st of month
   542 00006618 66D1EB              <1> 	shr 	bx, 1        ; bx = month - 1 (0 to 11)
   543 0000661B 6683FB01            <1> 	cmp	bx, 1        ; if month > 2 and year mod 4  = 0	
   544 0000661F 76E6                <1> 	jna 	short cfe2   ; then mday = mday + 1
   545 00006621 08C0                <1> 	or 	al, al       ; if past 2/29 and leap year then
   546 00006623 75E2                <1> 	jnz 	short cfe2   ; add leap day (to mday)
   547 00006625 6642                <1> 	inc 	dx           ; mday = mday + 1
   548 00006627 EBDE                <1> 	jmp 	short cfe2
   549                              <1> cfe3:
   550 00006629 6643                <1> 	inc 	bx	     ; -> bx = month, 1 to 12
   551 0000662B 66891D[98550100]    <1> 	mov 	[month], bx
   552 00006632 6629D1              <1> 	sub 	cx, dx	     ; day = jday - mday + 1	
   553 00006635 6641                <1> 	inc 	cx 			  
   554 00006637 66890D[9A550100]    <1> 	mov 	[day], cx
   555                              <1> 	
   556                              <1> 	; eax, ebx, ecx, edx is changed at return
   557                              <1> 	; output ->
   558                              <1> 	; [year], [month], [day], [hour], [minute], [second]
   559                              <1> 
   560 0000663E C3                  <1> 	retn	; 31/12/2017 (TRDOS 386)
   561                              <1> 
   562                              <1> set_rtc_date_time:
   563                              <1> 	; 31/12/2017 (v2.0.0)
   564                              <1> 	; 30/12/2017 (TRDOS 386)
   565                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   566                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
   567 0000663F E80F000000          <1> 	call	set_date_bcd
   568                              <1> 	; Set real-time clock date
   569 00006644 E875F4FFFF          <1> 	call	set_rtc_date ; RTC_50
   570                              <1> 	; Set real-time clock time
   571 00006649 E832000000          <1> 	call	set_time_bcd
   572 0000664E E9FCF3FFFF          <1> 	jmp	set_rtc_time ; RTC_30	
   573                              <1> 
   574                              <1> ; 31/12/2017
   575                              <1> set_date_bcd:
   576 00006653 A0[97550100]        <1>         mov     al, [year+1]
   577 00006658 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   578 0000665A D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   579                              <1> 			     ; AL = AH * 10h + AL
   580 0000665C 88C5                <1> 	mov 	ch, al ; century (BCD)
   581 0000665E A0[96550100]        <1> 	mov 	al, [year]
   582 00006663 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   583 00006665 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   584                              <1> 			     ; AL = AH * 10h + AL
   585 00006667 88C1                <1> 	mov 	cl, al ; year (BCD)
   586 00006669 A0[98550100]        <1>         mov 	al, [month]
   587 0000666E D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   588 00006670 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   589                              <1> 			     ; AL = AH * 10h + AL
   590 00006672 88C6                <1> 	mov 	dh, al ; month (BCD)
   591 00006674 A0[9A550100]        <1> 	mov 	al, [day]
   592 00006679 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   593 0000667B D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   594                              <1> 			     ; AL = AH * 10h + AL
   595 0000667D 88C6                <1> 	mov 	dh, al ; day (BCD)
   596 0000667F C3                  <1> 	retn	; 30/12/2017
   597                              <1> 
   598                              <1> ; 31/12/2017
   599                              <1> set_time_bcd:
   600                              <1>         ; Read real-time clock time 
   601                              <1> 	; (get day light saving time bit status)
   602 00006680 FA                  <1>  	cli
   603 00006681 E88AF5FFFF          <1> 	CALL	UPD_IPR 		; CHECK FOR UPDATE IN PROCESS
   604                              <1> 	; cf = 1 -> al = 0
   605 00006686 7207                <1>         jc      short stime1
   606 00006688 B00B                <1> 	MOV	AL,CMOS_REG_B		; ADDRESS ALARM REGISTER
   607 0000668A E89CF5FFFF          <1> 	CALL	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
   608                              <1> stime1:
   609 0000668F FB                  <1> 	sti
   610 00006690 2401                <1> 	AND	AL,00000001B		; MASK FOR VALID DSE BIT
   611 00006692 88C2                <1> 	MOV	DL,AL			; SET [DL] TO ZERO FOR NO DSE BIT
   612                              <1> 	; DL = 1 or 0 (day light saving time)
   613                              <1> 	;	
   614 00006694 A0[9C550100]        <1> 	mov 	al, [hour]
   615 00006699 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   616 0000669B D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   617                              <1> 			     ; AL = AH * 10h + AL
   618 0000669D 88C5                <1> 	mov 	ch, al ; hour (BCD)
   619 0000669F A0[9E550100]        <1>         mov     al, [minute]
   620 000066A4 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   621 000066A6 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   622                              <1> 			     ; AL = AH * 10h + AL
   623 000066A8 88C1                <1> 	mov 	cl, al       ; minute (BCD)
   624 000066AA A0[A0550100]        <1>         mov     al, [second]
   625 000066AF D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   626 000066B1 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   627                              <1> 			     ; AL = AH * 10h + AL
   628 000066B3 88C6                <1> 	mov 	dh, al	     ; second (BCD)
   629 000066B5 C3                  <1> 	retn	; 30/12/2017
  2306                                  %include 'trdosk2.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.2) - DRV INIT : trdosk2.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/07/2020
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.14 (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> 	; 20/07/2020
    18                              <1> 	; 17/07/2020
    19                              <1> 	; 15/07/2020
    20                              <1> 	; 14/07/2020
    21                              <1> 	; 30/01/2018
    22                              <1> 	; 27/12/2017
    23                              <1> 	; 12/02/2016
    24                              <1> 	; 06/01/2016
    25                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
    26                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
    27                              <1> 	; 07/08/2011
    28                              <1> 	; 20/09/2009
    29                              <1> 	; 2005
    30                              <1> 
    31                              <1> 	; 15/07/2020
    32                              <1> 	;movzx	ecx, byte [HF_NUM] ; number of fixed disks
    33                              <1> 	;cmp	cl, 1
    34                              <1> 	;jnb	short load_hd_partition_tables
    35                              <1> 
    36 000066B6 A0[44590100]        <1> 	mov	al, [HF_NUM] ; number of fixed disks
    37 000066BB 20C0                <1> 	and 	al, al
    38 000066BD 7501                <1> 	jnz	short load_hd_partition_tables
    39                              <1> 
    40                              <1> 	; no any hard disks
    41 000066BF C3                  <1> 	retn			
    42                              <1> 
    43                              <1> load_hd_partition_tables:
    44                              <1> 	;mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
    45                              <1> 	; 15/07/2020
    46 000066C0 BE[48590100]        <1> 	mov	esi, HDPM_TBL_VEC
    47 000066C5 BF[6E5D0100]        <1> 	mov 	edi, PTable_hd0
    48 000066CA B280                <1> 	mov 	dl, 80h
    49                              <1> 	; 15/07/2020
    50 000066CC A2[255D0000]        <1> 	mov	[hdc], al
    51                              <1> 	;xor	ecx, ecx ; 0
    52                              <1> load_next_hd_partition_table:
    53                              <1> 	; 20/07/2020
    54 000066D1 31C9                <1> 	xor	ecx, ecx ; 0
    55                              <1> 	;push	ecx
    56 000066D3 57                  <1> 	push	edi ; *
    57                              <1> 	;push	esi ; FDPT (+ DPTE) address
    58                              <1> 	; 15/07/2020
    59 000066D4 AD                  <1> 	lodsd
    60 000066D5 56                  <1> 	push	esi ; ** ; next FDPT (+ DPTE) address ptr
    61                              <1> 	
    62                              <1> 	;mov	al, [esi+20] ; DPTE offset 4
    63                              <1> 	;and	al, 40h ;  LBA bit (bit 6)
    64                              <1> 	;;shr	al, 6
    65                              <1> 	;mov 	[HD_LBA_yes], al
    66                              <1> 	
    67                              <1> 	; 15/07/2020
    68 000066D6 8A4814              <1> 	mov	cl, [eax+20]
    69 000066D9 80E140              <1> 	and	cl, 40h
    70 000066DC 880D[6F5E0100]      <1> 	mov	[HD_LBA_yes], cl
    71                              <1> 	
    72 000066E2 E83D040000          <1> 	call	load_masterboot
    73 000066E7 7276                <1> 	jc	short pass_pt_this_hard_disk
    74                              <1> 
    75 000066E9 BB[2C5D0100]        <1> 	mov	ebx, PartitionTable
    76 000066EE 89DE                <1> 	mov	esi, ebx
    77                              <1> 	;mov	ecx, 16
    78 000066F0 B110                <1> 	mov	cl, 16
    79 000066F2 F3A5                <1> 	rep 	movsd
    80 000066F4 89DE                <1> 	mov 	esi, ebx 
    81                              <1> 	;mov 	byte [hdc], 4 ; 4 - partition index
    82                              <1> 	; 15/07/2020
    83 000066F6 C605[705E0100]04    <1> 	mov	byte [PP_Counter], 4
    84                              <1> loc_validate_hdp_partition:
    85 000066FD 807E0400            <1> 	cmp 	byte [esi+ptFileSystemID], 0
    86 00006701 7644                <1> 	jna	short loc_validate_next_hdp_partition2
    87                              <1> 
    88 00006703 56                  <1> 	push	esi ; *** ; Masterboot partition table offset
    89 00006704 52                  <1> 	push	edx ; **** ; dl = Physical drive number 
    90                              <1> 	
    91                              <1> 	;inc	byte [PP_Counter]
    92                              <1> 	; 15/07/2020
    93 00006705 FE05[715E0100]      <1> 	inc 	byte [EP_Counter] ; disk has valid partition(s)       
    94                              <1> 
    95 0000670B 31FF                <1> 	xor	edi, edi ; 0  
    96                              <1> 	; Input -> ESI = PartitionTable offset
    97                              <1> 	; DL = Hard disk drive number 
    98                              <1> 	; EDI = 0 -> Primary Partition
    99                              <1> 	; EDI > 0 -> Extended Partition's Start Sector   
   100 0000670D E896010000          <1> 	call 	validate_hd_fat_partition
   101 00006712 730E                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
   102                              <1> 
   103                              <1> 	;pop	edx
   104                              <1> 	;push	edx
   105 00006714 8B1424              <1> 	mov	edx, [esp]  ; ****
   106 00006717 8B742404            <1> 	mov	esi, [esp+4] ; *** ; 30/01/2018
   107 0000671B E8E2020000          <1> 	call	validate_hd_fs_partition
   108 00006720 7223                <1> 	jc	short loc_validate_next_hdp_partition1
   109                              <1> loc_set_valid_hdp_partition_entry:
   110 00006722 8A0D[3A0D0100]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
   111 00006728 80C141              <1> 	add 	cl, 'A'
   112                              <1> 	; ESI = Logical dos drive description table address
   113 0000672B 880E                <1> 	mov	[esi+LD_Name], cl
   114                              <1> 	; 15/07/2020
   115 0000672D 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo] ; Physical drive number
   116                              <1> 	;mov	al, [esp] ; ****
   117 00006730 2C7F                <1> 	sub	al, 7Fh
   118                              <1> 		; AL = 1 to 4	
   119 00006732 C0E002              <1> 	shl	al, 2 ; AL = 4 to 16
   120                              <1> 
   121 00006735 8A15[705E0100]      <1> 	mov	dl, [PP_Counter]
   122                              <1> 
   123                              <1> 	;sub	al, [PP_Counter]
   124 0000673B 28D0                <1> 	sub	al, dl ; [PP_Counter] ; 4 - partition index
   125                              <1> 
   126                              <1> 	; AL = Partition entry/index, 0 based
   127                              <1> 	;  0 -> hd 0, Partition Table offset = 0
   128                              <1> 	; 15 -> hd 3, Partition Table offset = 3
   129                              <1> 
   130                              <1> 	;mov	[esi+LD_PartitionEntry], al 
   131                              <1> 	
   132                              <1> 	; 15/07/2020
   133 0000673D B404                <1> 	mov	ah, 4
   134                              <1> 	;sub	ah, [PP_Counter]
   135 0000673F 28D4                <1> 	sub	ah, dl
   136                              <1> 
   137                              <1> 	; AH = Primary partition index, 0 to 3 ; pt entry
   138                              <1> 	;		(4 to 7 for logical disk partitions)
   139                              <1> 
   140                              <1> 	;mov 	[esi+LD_DParamEntry], ah 
   141 00006741 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
   142                              <1> 
   143                              <1> loc_validate_next_hdp_partition1:
   144 00006745 5A                  <1> 	pop 	edx ; **** ; dl = Physical drive number 
   145 00006746 5E                  <1> 	pop	esi ; *** ; Masterboot partition table offset
   146                              <1> 
   147                              <1> loc_validate_next_hdp_partition2:
   148                              <1> 	; ESI = PartitionTable offset
   149                              <1> 	; DL = Hard/Fixed disk drive number
   150                              <1> 	
   151                              <1> 	;dec	byte [hdc] ; 4 - partition index
   152                              <1> 	;jz	short pass_pt_this_hard_disk
   153                              <1> 	; 15/07/2020
   154 00006747 FE0D[705E0100]      <1> 	dec	byte [PP_Counter] ; 4 - partition index
   155 0000674D 7410                <1> 	jz	short pass_pt_this_hard_disk
   156                              <1> 	
   157 0000674F 83C610              <1> 	add	esi, 16 ; 10h
   158 00006752 EBA9                <1> 	jmp	short loc_validate_hdp_partition
   159                              <1> 
   160                              <1> loc_not_any_extd_partitions:
   161                              <1> 	; 15/07/2020
   162 00006754 C3                  <1> 	retn	
   163                              <1> 
   164                              <1> loc_next_hd_partition_table:
   165 00006755 FEC2                <1> 	inc	dl
   166                              <1> 	; 15/07/2020
   167                              <1> 	;add	esi, 32 ; next FDPT address
   168 00006757 83C740              <1> 	add	edi, 64 ; next partition table destination
   169 0000675A E972FFFFFF          <1>         jmp     load_next_hd_partition_table
   170                              <1> 
   171                              <1> pass_pt_this_hard_disk:
   172                              <1> 	;pop	esi ; FDPT (+ DPTE) address
   173                              <1> 	; 15/07/2020
   174 0000675F 5E                  <1> 	pop	esi ; ** ; next FDPT (+ DPTE) address ptr
   175 00006760 5F                  <1> 	pop	edi ; * ; Ptable_hd?
   176                              <1> 	;pop	ecx
   177                              <1> 	;loop	loc_next_hd_partition_table
   178 00006761 FE0D[255D0000]      <1> 	dec	byte [hdc]
   179 00006767 75EC                <1> 	jnz	short loc_next_hd_partition_table
   180                              <1> 
   181                              <1> 	;cmp	byte [PP_Counter], 1
   182                              <1> 	;jnb	short load_extended_dos_partitions
   183                              <1> 	;; Empty partition table
   184                              <1> 	;retn
   185                              <1> 
   186                              <1> 	; 17/07/2020
   187                              <1> check_extended_partitions:
   188                              <1> 	; 15/07/2020
   189 00006769 803D[715E0100]00    <1> 	cmp	byte [EP_Counter], 0
   190 00006770 76E2                <1> 	jna	short loc_not_any_extd_partitions
   191                              <1> 
   192                              <1> load_extended_dos_partitions:
   193 00006772 BE[6E5D0100]        <1> 	mov	esi, PTable_hd0
   194 00006777 C605[255D0000]80    <1> 	mov	byte [hdc], 80h
   195                              <1> next_hd_extd_partition:
   196                              <1> 	; 17/07/2020
   197 0000677E C605[715E0100]00    <1> 	mov 	byte [EP_Counter], 0 ; Reset for each physical disk
   198                              <1> 	
   199 00006785 56                  <1> 	push	esi ; **** ; PTable_hd? offset
   200                              <1> 	
   201 00006786 C605[705E0100]04    <1> 	mov 	byte [PP_Counter], 4 
   202                              <1> 				; set for each extd partition table
   203                              <1> 	;;mov	ecx, 4
   204                              <1> 	;mov	cl, 4
   205 0000678D 8A15[255D0000]      <1> 	mov	dl, [hdc]
   206                              <1> hd_check_fs_id_05h:
   207 00006793 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   208 00006796 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
   209 00006798 7411                <1> 	je	short loc_set_ep_start_sector ; yes
   210                              <1> hd_check_fs_id_0Fh:
   211 0000679A 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
   212 0000679C 740D                <1> 	je	short loc_set_ep_start_sector ; yes
   213                              <1> 
   214                              <1> continue_to_check_ep:
   215                              <1> 	;add	esi, 16
   216                              <1> 	;loop	hd_check_fs_id_05h
   217                              <1> 	; 15/07/2020
   218                              <1> 	;dec	cl
   219                              <1> 	;jz	short continue_check_ep_next_disk
   220 0000679E FE0D[705E0100]      <1> 	dec	byte [PP_Counter] ; 4 --> 0
   221 000067A4 742B                <1> 	jz	short continue_check_ep_next_disk
   222 000067A6 83C610              <1> 	add	esi, 16
   223 000067A9 EBE8                <1> 	jmp	short hd_check_fs_id_05h
   224                              <1> 
   225                              <1> loc_set_ep_start_sector:
   226                              <1> 	; dl = [hdc] ; Drive number
   227                              <1> 	; 15/07/2020
   228 000067AB 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
   229                              <1> 	; 20/07/2020
   230                              <1> loc_validate_hde_partition_next:
   231 000067AE 890D[725E0100]      <1> 	mov	[EP_StartSector], ecx ; Extended partition's start sector
   232 000067B4 BB[6E5B0100]        <1>         mov	ebx, MasterBootBuff
   233 000067B9 803D[6F5E0100]01    <1> 	cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
   234 000067C0 722B                <1> 	jb	short loc_hd_load_ep_05h ; cf = 1 ; 20/07/2020 
   235 000067C2 3C05                <1> 	cmp	al, 05h
   236 000067C4 7427                <1> 	je	short loc_hd_load_ep_05h
   237                              <1> loc_hd_load_ep_0Fh:
   238                              <1> 	; 04/01/2016
   239                              <1> 	;push	ecx
   240                              <1> 	; 15/07/2020
   241                              <1> 	;mov	ecx, [esi+ptStartSector] ; sector number
   242                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
   243                              <1> 	; LBA read/write (with private LBA function) 
   244                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   245                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   246                              <1> 	;mov	ah, 1Bh ; LBA read
   247                              <1> 	;mov	al, 1 ; sector count
   248 000067C6 66B8011B            <1> 	mov	ax, 1B01h
   249 000067CA E868DAFFFF          <1> 	call	int13h
   250                              <1> 	;pop	ecx
   251                              <1> 	;jnc	short loc_hd_move_ep_table
   252                              <1> 	; 15/07/2020
   253 000067CF 732E                <1> 	jnc	short loc_validate_hde_partition
   254                              <1> 
   255                              <1> continue_check_ep_next_disk:
   256                              <1> 	; 15/07/2020
   257                              <1> 	;pop	edi ; PTable_ep?
   258 000067D1 5E                  <1> 	pop	esi ; **** ; PTable_hd?
   259 000067D2 A0[44590100]        <1> 	mov	al, [HF_NUM] ; number of hard disks
   260 000067D7 047F                <1> 	add	al, 7Fh
   261 000067D9 3805[255D0000]      <1> 	cmp	[hdc], al
   262 000067DF 730B                <1> 	jnb	short loc_validating_hd_partitions_ok
   263 000067E1 83C640              <1> 	add	esi, 64
   264                              <1> 	; 15/07/2020
   265                              <1> 	;add	edi, 64
   266 000067E4 FE05[255D0000]      <1> 	inc	byte [hdc]
   267 000067EA EB92                <1> 	jmp	short next_hd_extd_partition
   268                              <1> 
   269                              <1> loc_validating_hd_partitions_ok:
   270                              <1> 	; 15/07/2020
   271                              <1> 	;mov	al, [Last_DOS_DiskNo]
   272                              <1> loc_drv_init_retn:
   273 000067EC C3                  <1> 	retn
   274                              <1> 	
   275                              <1> loc_hd_load_ep_05h:
   276                              <1> 	; 20/07/2020 ('diskio.s', int13h, cf = 1 -> bugfix)
   277                              <1> 	;clc    ; (Bug: int13h would not clear carry flag bit, 
   278                              <1> 	;	; enven if there would not be an error)
   279                              <1> 	;	; ((Fix: now, int13h procedure clears carry flag
   280                              <1> 	;	;  at the entrance of it.. 20/07/2020))
   281                              <1> 	; 15/07/2020
   282                              <1> 	;push	ecx 
   283 000067ED 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   284 000067F0 668B4E02            <1>         mov     cx, [esi+ptBeginSector]
   285 000067F4 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   286                              <1> 	;mov	ebx, MasterBootBuff
   287 000067F8 E83ADAFFFF          <1> 	call	int13h ; 20/07/2020
   288                              <1> 		       ; 'diskio.s' modification, 'clc'
   289                              <1> 	;pop	ecx  
   290 000067FD 72D2                <1> 	jc	short continue_check_ep_next_disk
   291                              <1> 	; 15/07/2020
   292                              <1> 	;jmp	short loc_validate_hde_partition
   293                              <1> 
   294                              <1> 	; 15/07/2020
   295                              <1> ;loc_hd_move_ep_table:
   296                              <1> 	;;pop	edi
   297                              <1> 	;;push	edi  ; PTable_ep?
   298                              <1> 	;mov	edi, [esp]        
   299                              <1>         ;mov	esi, PartitionTable ; Extended
   300                              <1> 	;mov	ebx, esi
   301                              <1> 	;;mov	ecx, 16
   302                              <1> 	;mov	cl, 16
   303                              <1>        	;rep	movsd
   304                              <1> 	;mov	esi, ebx 
   305                              <1> ;loc_set_hde_sub_partition_count:
   306                              <1> 	;mov	byte [PP_Counter], 4
   307                              <1> 	;mov	byte [EP_Counter], 0
   308                              <1> 
   309                              <1> loc_validate_hde_partition:
   310                              <1> 	; 15/07/2020
   311 000067FF C605[705E0100]04    <1> 	mov	byte [PP_Counter], 4
   312 00006806 BE[2C5D0100]        <1> 	mov	esi, PartitionTable ; (in MasterBootBuff)
   313                              <1> get_minidisk_partition_entry:
   314                              <1> 	; 20/07/2020
   315 0000680B 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
   316 0000680F 770D                <1> 	ja	short loc_validate_minidisk_partition
   317 00006811 FE0D[705E0100]      <1> 	dec 	byte [PP_Counter]
   318 00006817 74B8                <1> 	jz	short continue_check_ep_next_disk
   319                              <1> 	; 20/07/2020
   320                              <1> get_minidisk_partition_entry_next:
   321 00006819 83C610              <1> 	add 	esi, 16 ; 10h
   322 0000681C EBED                <1> 	jmp	short get_minidisk_partition_entry
   323                              <1> 
   324                              <1> loc_validate_minidisk_partition:
   325                              <1> 	; 20/07/2020
   326 0000681E 56                  <1> 	push	esi ; *** ; Extended partition table offset
   327                              <1> 
   328 0000681F BF[725E0100]        <1> 	mov	edi, EP_StartSector
   329                              <1> 
   330                              <1> 	; Input -> ESI = PartitionTable offset
   331                              <1> 	; DL = Hard disk drive number   
   332                              <1> 	; EDI = Extended partition start sector pointer
   333 00006824 E87F000000          <1> 	call	validate_hd_fat_partition
   334                              <1> 	;pop	ecx ; *
   335 00006829 7314                <1> 	jnc	short loc_set_valid_hde_partition_entry
   336                              <1> 			 ; jump down to deep !!!
   337                              <1> 
   338 0000682B 5E                  <1> 	pop	esi ; *** ; Extended partition table offset
   339                              <1> 
   340                              <1> 	; ESI = Extended partition table offset
   341                              <1> 	;mov	dl, [hdc]
   342                              <1> 	;; DL = Hard disk drive number
   343 0000682C FE0D[705E0100]      <1> 	dec	byte [PP_Counter]
   344 00006832 749D                <1> 	jz	short continue_check_ep_next_disk
   345 00006834 83C610              <1> 	add 	esi, 16 ; 10h
   346 00006837 8A15[255D0000]      <1> 	mov	dl, [hdc]
   347 0000683D EBCC                <1> 	jmp	short get_minidisk_partition_entry
   348                              <1> 
   349                              <1> 	; 17/07/2020
   350                              <1> 	;; jumping down to deep levels !!!
   351                              <1> 	; ((That is a pitty microsoft preferred ep table chain
   352                              <1> 	; instead of a single table as mbr partition table!?))
   353                              <1> 
   354                              <1> loc_set_valid_hde_partition_entry:
   355                              <1> 	; 15/07/2020
   356 0000683F A0[255D0000]        <1> 	mov	al, [hdc] ; Hard disk drive number (>=80h)
   357 00006844 88C2                <1> 	mov	dl, al ; mov dl, [hdc]
   358 00006846 2C7F                <1> 	sub	al, 7Fh
   359                              <1> 		    ; 1 to 4	
   360 00006848 C0E002              <1> 	shl	al, 2 ; 4 to 16
   361 0000684B 2A05[705E0100]      <1> 	sub	al, [PP_Counter] ; al - (4 - partition index)
   362                              <1> 			; (disk number * 4) + partition index
   363                              <1> 	
   364                              <1> 	; AL = Partition entry/index, 0 based
   365                              <1>         ;  0 -> hd 0, Partition Table offset = 0
   366                              <1>         ; 15 -> hd 3, Partition Table offset = 3
   367                              <1> 
   368 00006851 B404                <1> 	mov	ah, 4 ; Logical dos partition (>= 4)
   369 00006853 0225[715E0100]      <1> 	add	ah, [EP_Counter]
   370                              <1> 		; Logical disk partition index = 4 to 7
   371                              <1> 		; (Primary disk partition index = 0 to 3)
   372                              <1> 
   373                              <1> 	; 15/07/2020
   374                              <1> 	; CX -> AX
   375                              <1> 	;; 06/01/2016 (TRDOS v2.0)
   376                              <1> 	;; BUGFIX *
   377                              <1> 	;;mov	[esi+LD_PartitionEntry], cl 
   378                              <1> 	;;mov	[esi+LD_DParamEntry], ch 
   379                              <1> 	;mov	[esi+LD_PartitionEntry], cx 
   380 00006859 6689467C            <1> 	mov	[esi+LD_PartitionEntry], ax 	
   381                              <1> 
   382 0000685D 8A0D[3A0D0100]      <1> 	mov	cl, [Last_DOS_DiskNo] 
   383 00006863 80C141              <1> 	add	cl, 'A'
   384 00006866 880E                <1> 	mov	[esi+LD_Name], cl
   385                              <1> 
   386                              <1> 	; 17/07/2020
   387                              <1> 	;cmp	cl, 'Z'
   388                              <1> 	;jb	short logical_drive_count_ok_for_next
   389                              <1> 	;pop	esi ; ***
   390                              <1> 	;pop	esi ; ****
   391                              <1> 	;retn
   392                              <1> 
   393                              <1> ;logical_drive_count_ok_for_next:
   394                              <1> 
   395                              <1> 	; 15/07/2020
   396 00006868 FE05[715E0100]      <1> 	inc	byte [EP_Counter]
   397                              <1> 
   398                              <1> 	;mov	dl, [hdc]
   399                              <1> 
   400                              <1> 	; 17/07/2020
   401                              <1> 	;; Now, 
   402                              <1> 	;; we are swimming in deep of an extended partition !!!
   403                              <1> 	; (! sub or chained extended partition tables !)
   404                              <1> 	; ((Logical dos partitions in extended partition were called
   405                              <1> 	;  as 'mini disk partition' in msdos 6.0 source code.))
   406                              <1> 
   407                              <1> validate_next_minidisk_partition:
   408 0000686E 5E                  <1> 	pop	esi ; *** ; Extended partition table offset
   409                              <1> 
   410                              <1> 	; 17/07/2020
   411 0000686F 803D[715E0100]04    <1> 	cmp	byte [EP_Counter], 4 ; max. 4 logical disks
   412                              <1> 				;	 per extd partition
   413 00006876 0F8355FFFFFF        <1> 	jnb	continue_check_ep_next_disk
   414                              <1> 
   415 0000687C FE0D[705E0100]      <1> 	dec	byte [PP_Counter] ; 4 --> 0
   416 00006882 0F8449FFFFFF        <1> 	jz	continue_check_ep_next_disk
   417                              <1> 
   418 00006888 83C610              <1> 	add	esi, 16
   419                              <1> 
   420                              <1> 	; 20/07/2020
   421 0000688B 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   422                              <1> 
   423                              <1> 	; 20/07/2020
   424 0000688E 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
   425 00006890 7408                <1> 	je	short loc_minidisk_next_ep_lba_chs ; 17/07/2020
   426 00006892 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
   427 00006894 0F8537FFFFFF        <1> 	jne	continue_check_ep_next_disk ; AL must be 0 here
   428                              <1> 					; (when it is not 05h or 0Fh)
   429                              <1> 					; If AL is not ZERO -> EP Bug!
   430                              <1> 					; (!Microsoft DOS convention!)
   431                              <1> loc_minidisk_next_ep_lba_chs:
   432                              <1> 	; 17/07/2020
   433 0000689A 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; relative start sector number
   434 0000689D 030D[725E0100]      <1> 	add	ecx, [EP_StartSector]	
   435                              <1> 	; 20/07/2020
   436 000068A3 E906FFFFFF          <1> 	jmp	loc_validate_hde_partition_next
   437                              <1> 
   438                              <1> validate_hd_fat_partition:
   439                              <1> 	; 17/07/2020
   440                              <1> 	; 15/07/2020
   441                              <1> 	;	(optimization)
   442                              <1> 	; 14/07/2020
   443                              <1> 	;	(fat16 -big- partition search bugfix)
   444                              <1> 	; 27/12/2017
   445                              <1> 	; 12/02/2016
   446                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
   447                              <1> 	; 07/08/2011
   448                              <1> 	; 23/07/2011
   449                              <1> 	; Input
   450                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   451                              <1> 	;   ESI = PartitionTable offset
   452                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
   453                              <1> 	;   EDI = 0 -> Primary Partition 
   454                              <1> 	;   byte [Last_DOS_DiskNo]
   455                              <1>  	; Output
   456                              <1> 	;  cf=0 -> Validated
   457                              <1> 	;   ESI = Logical dos drv desc. table
   458                              <1> 	;   EBX = FAT boot sector buffer
   459                              <1> 	;   byte [Last_DOS_DiskNo]
   460                              <1> 	;  cf=1 -> Not a valid FAT partition
   461                              <1> 	; EAX, EDX, ECX, EDI -> changed 
   462                              <1> 	
   463                              <1> 	;mov 	esi, PartitionTable
   464 000068A8 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
   465 000068AB B002                <1> 	mov	al, 2 ; 27/12/2017
   466 000068AD 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition (>=32MB)
   467                              <1> 	; 12/02/2016
   468                              <1> 	;;jb	short loc_not_a_valid_fat_partition2
   469                              <1>  	;jnb	short vhdp_FAT16_32
   470                              <1> 	; 14/07/2020 (BugFix)
   471 000068B0 7711                <1> 	ja	short vhdp_FAT16_32
   472 000068B2 7425                <1> 	je	short loc_set_valid_hd_partition_params
   473                              <1> 
   474                              <1> vhdp_FAT12_16:
   475                              <1> 	; 27/12/2017
   476 000068B4 FEC8                <1> 	dec	al ; mov al, 1
   477 000068B6 38C4                <1> 	cmp	ah, al ; 1 ; FAT12 partition
   478 000068B8 741F                <1> 	je	short loc_set_valid_hd_partition_params
   479                              <1> 	;
   480 000068BA FEC0                <1> 	inc	al ; mov al, 2
   481 000068BC 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)
   482 000068BF 7418                <1> 	je	short loc_set_valid_hd_partition_params
   483                              <1> 	
   484                              <1> 	; 15/07/2020
   485                              <1> 	; (ah = 05h, 02h or 03h)
   486                              <1> loc_not_a_valid_fat_partition1:
   487 000068C1 F9                  <1> 	stc
   488                              <1> 	; cf=1
   489 000068C2 C3                  <1> 	retn
   490                              <1> 
   491                              <1> vhdp_FAT16_32:
   492                              <1> 	; 15/07/2020
   493                              <1> 	;mov	al, 3
   494 000068C3 FEC0                <1> 	inc	al
   495 000068C5 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
   496 000068C8 740F                <1> 	je	short loc_set_valid_hd_partition_params
   497 000068CA 7706                <1> 	ja	short vhdp_check_FAT16_lba
   498                              <1> 
   499                              <1> vhdp_check_FAT32_chs:
   500 000068CC 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
   501 000068CF 7408                <1> 	je	short loc_set_valid_hd_partition_params
   502                              <1> 	;jne	short loc_not_a_valid_fat_partition1
   503                              <1> 
   504                              <1> 	;stc
   505                              <1> loc_not_a_valid_fat_partition2:
   506 000068D1 C3                  <1> 	retn
   507                              <1> 
   508                              <1> vhdp_check_FAT16_lba:
   509 000068D2 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
   510 000068D5 75EA                <1> 	jne	short loc_not_a_valid_fat_partition1
   511                              <1> 
   512                              <1> 	;mov	al, 2
   513 000068D7 FEC8                <1> 	dec	al
   514                              <1> 
   515                              <1> loc_set_valid_hd_partition_params:
   516                              <1> 	; 15/07/2020
   517                              <1> 	;inc 	byte [Last_DOS_DiskNo] ; > 1
   518                              <1> 	;
   519 000068D9 31DB                <1> 	xor	ebx, ebx
   520 000068DB 8A3D[3A0D0100]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256	
   521 000068E1 FEC7                <1> 	inc	bh ; 15/07/2020
   522 000068E3 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   523                              <1> 	;
   524 000068E9 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   525 000068ED 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
   526                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
   527                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
   528 000068F0 66894303            <1> 	mov	word [ebx+LD_FATType], ax
   529                              <1> 	;
   530 000068F4 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
   531 000068F7 09FF                <1> 	or	edi, edi 
   532 000068F9 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
   533                              <1> loc_add_hd_FAT_ep_start_sector:
   534                              <1> 	; 17/07/2020
   535 000068FB 030F                <1> 	add	ecx, [edi]
   536                              <1> pass_hd_FAT_ep_start_sector_adding:
   537 000068FD 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
   538                              <1> loc_hd_FAT_logical_drv_init:
   539 00006900 89DD                <1> 	mov	ebp, ebx
   540                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   541 00006902 A0[6F5E0100]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
   542 00006907 884305              <1> 	mov	[ebx+LD_LBAYes], al
   543 0000690A BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   544 0000690F 08C0                <1> 	or	al, al
   545 00006911 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
   546                              <1> loc_hd_FAT_drv_init_load_bs_lba:
   547                              <1> 	; DL = Physical drive number
   548                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
   549                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   550                              <1> 	; LBA read/write (with private LBA function) 
   551                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   552                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   553 00006913 B41B                <1> 	mov	ah, 1Bh ; LBA read
   554 00006915 B001                <1> 	mov	al, 1 ; sector count
   555 00006917 E81BD9FFFF          <1> 	call	int13h
   556 0000691C 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
   557                              <1> loc_not_a_valid_fat_partition3:
   558 0000691E C3                  <1> 	retn
   559                              <1> loc_hd_FAT_drv_init_load_bs_chs:
   560 0000691F 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   561 00006922 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   562 00006926 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   563                              <1> 	;mov	ebx, DOSBootSectorBuff
   564 0000692A E808D9FFFF          <1> 	call	int13h
   565 0000692F 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
   566                              <1> loc_hd_drv_FAT_boot_validation:
   567                              <1> 	;mov	esi, DOSBootSectorBuff
   568 00006931 89DE                <1> 	mov	esi, ebx
   569 00006933 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   570 0000693C 7512                <1> 	jne	short loc_not_a_valid_fat_partition4
   571 0000693E 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
   572 00006942 750C                <1> 	jne	short loc_not_a_valid_fat_partition4
   573                              <1> 
   574                              <1> 	; 27/12/2017
   575 00006944 807D0303            <1> 	cmp	byte [ebp+LD_FATType], 3
   576 00006948 7508                <1> 	jne	short loc_hd_FAT16_BPB
   577                              <1> 
   578                              <1> loc_hd_drv_FAT32_boot_validation:
   579 0000694A 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
   580 0000694E 7416                <1> 	je	short loc_hd_FAT32_BPB
   581                              <1> 
   582                              <1> loc_not_a_valid_fat_partition4:
   583 00006950 F9                  <1> 	stc
   584 00006951 C3                  <1> 	retn
   585                              <1> 
   586                              <1> loc_hd_FAT16_BPB:
   587 00006952 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
   588 00006956 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
   589                              <1> 
   590 00006958 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
   591 0000695D 7607                <1> 	jna	short loc_hd_big_FAT16_BPB
   592 0000695F B920000000          <1> 	mov	ecx, 32
   593 00006964 EB05                <1> 	jmp	short loc_hd_move_FAT_BPB
   594                              <1> 
   595                              <1> loc_hd_FAT32_BPB:
   596                              <1> 	;cmp	word [esi+BPB_FATSz16], 0
   597                              <1> 	;ja	short loc_not_a_valid_fat_partition4
   598                              <1> loc_hd_big_FAT16_BPB:
   599 00006966 B92D000000          <1> 	mov	ecx, 45
   600                              <1> 	
   601                              <1> loc_hd_move_FAT_BPB:
   602 0000696B 89EF                <1> 	mov 	edi, ebp
   603                              <1> 	;mov	esi, ebx ; Boot sector
   604 0000696D 57                  <1> 	push	edi
   605 0000696E 83C706              <1> 	add	edi, LD_BPB
   606 00006971 F366A5              <1> 	rep	movsw 
   607 00006974 5E                  <1> 	pop	esi
   608 00006975 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
   609 00006979 03466C              <1> 	add	eax, [esi+LD_StartSector]
   610 0000697C 894660              <1> 	mov	[esi+LD_FATBegin], eax
   611 0000697F 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
   612 00006983 7224                <1> 	jb	short loc_set_FAT16_RootDirLoc
   613                              <1> loc_set_FAT32_RootDirLoc:
   614 00006985 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
   615 00006988 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
   616 0000698C F7E3                <1> 	mul	ebx
   617 0000698E 034660              <1> 	add	eax, [esi+LD_FATBegin]
   618                              <1> loc_set_FAT32_data_begin:
   619 00006991 894668              <1> 	mov	[esi+LD_DATABegin], eax
   620 00006994 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   621                              <1> 	; If Root Directory Cluster <> 2 then
   622                              <1> 	; change the beginning sector value 
   623                              <1> 	; of the root dir by adding sector offset.
   624 00006997 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
   625 0000699A 83E802              <1> 	sub	eax, 2
   626 0000699D 7435                <1> 	jz	short short loc_set_32bit_FAT_total_sectors  
   627                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
   628 0000699F 8A5E13              <1> 	mov	bl, [esi+LD_BPB+BPB_SecPerClust] 
   629 000069A2 F7E3                <1> 	mul	ebx
   630 000069A4 014664              <1> 	add	[esi+LD_ROOTBegin], eax
   631 000069A7 EB2B                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
   632                              <1> 	;
   633                              <1> loc_set_FAT16_RootDirLoc:
   634 000069A9 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
   635 000069AD 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
   636 000069B1 F7E2                <1> 	mul	edx
   637 000069B3 034660              <1> 	add	eax, [esi+LD_FATBegin]  
   638 000069B6 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   639                              <1> loc_set_FAT16_data_begin:
   640 000069B9 894668              <1> 	mov	[esi+LD_DATABegin], eax 
   641                              <1> 	;mov	eax, 20h  ; Size of a directory entry
   642                              <1> 	;;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
   643                              <1>         ;mov     dx, [esi+LD_BPB+BPB_RootEntCnt]
   644                              <1>         ;mul	edx
   645                              <1> 	;;mov	ecx, 511
   646                              <1> 	;mov	cx, 511
   647                              <1> 	;add	eax, ecx
   648                              <1> 	;inc	ecx ; 512
   649                              <1> 	;div	ecx
   650                              <1> 	; 14/07/2020
   651 000069BC 0FB74617            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RootEntCnt]
   652 000069C0 6683C00F            <1> 	add	ax, 15
   653 000069C4 66C1E804            <1> 	shr	ax, 4 ; / 16 ; (16 entries per sector)
   654 000069C8 014668              <1> 	add	[esi+LD_DATABegin], eax
   655                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
   656 000069CB 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
   657 000069CF 6685C0              <1> 	test	ax, ax
   658                              <1> 	;jz	short loc_set_32bit_FAT_total_sectors
   659                              <1> ;loc_set_16bit_FAT_total_sectors:
   660                              <1> 	;mov	[esi+LD_TotalSectors], eax
   661                              <1> 	;jmp	short loc_set_hd_FAT_cluster_count
   662                              <1> 	; 14/07/2020
   663 000069D2 7503                <1> 	jnz	short loc_set_hd_FAT_cluster_count
   664                              <1> loc_set_32bit_FAT_total_sectors:
   665 000069D4 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
   666                              <1> 	;mov	[esi+LD_TotalSectors], eax
   667                              <1> loc_set_hd_FAT_cluster_count:
   668 000069D7 894670              <1> 	mov	[esi+LD_TotalSectors], eax ; 14/07/2020
   669 000069DA 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
   670 000069DD 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
   671 000069E0 29D0                <1> 	sub	eax, edx
   672 000069E2 31D2                <1> 	xor	edx, edx ; 0
   673 000069E4 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
   674 000069E8 F7F1                <1>         div	ecx 
   675 000069EA 894678              <1> 	mov	[esi+LD_Clusters], eax
   676                              <1> 	; Maximum Valid Cluster Number= EAX +1
   677                              <1> 	; with 2 reserved clusters= EAX +2
   678                              <1> loc_set_hd_FAT_fs_free_sectors:
   679                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
   680 000069ED E855010000          <1> 	call	get_free_FAT_sectors
   681 000069F2 720D                <1> 	jc	short loc_validate_hd_FAT_partition_retn
   682 000069F4 894674              <1> 	mov	[esi+LD_FreeSectors], eax
   683 000069F7 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
   684                              <1> 
   685                              <1> 	; 15/07/2020
   686 000069FB FE05[3A0D0100]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
   687                              <1> 
   688                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
   689                              <1> 	;add	cl, 'A'
   690                              <1> 	;mov	[esi+LD_FS_Name], cl
   691                              <1> 
   692                              <1> loc_validate_hd_FAT_partition_retn:         
   693 00006A01 C3                  <1> 	retn
   694                              <1> 
   695                              <1> validate_hd_fs_partition:
   696                              <1> 	; 03/02/2018
   697                              <1> 	; 09/12/2017
   698                              <1> 	; 13/02/2016
   699                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   700                              <1> 	; 29/01/2011
   701                              <1> 	; 23/07/2011
   702                              <1> 	; Input
   703                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   704                              <1> 	;   ESI = PartitionTable offset
   705                              <1> 	;   byte [Last_DOS_DiskNo]
   706                              <1> 	; Output
   707                              <1> 	;  cf=0 -> Validated
   708                              <1> 	;   ESI = Logical dos drv desc. table
   709                              <1> 	;   EBX = Singlix FS boot sector buffer
   710                              <1> 	;   byte [Last_DOS_DiskNo]
   711                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
   712                              <1> 	; EAX, EDX, ECX, EDI -> changed 
   713                              <1> 
   714                              <1> 	;mov	esi, PartitionTable
   715 00006A02 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
   716 00006A05 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
   717 00006A08 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   718                              <1> loc_set_valid_hd_fs_partition_params:
   719 00006A0A FE05[3A0D0100]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
   720 00006A10 30C0                <1> 	xor	al, al ; mov al, 0
   721                              <1> 	;mov	[drv], dl
   722 00006A12 29DB                <1> 	sub	ebx, ebx ; 0
   723 00006A14 8A3D[3A0D0100]      <1> 	mov	bh, [Last_DOS_DiskNo] 
   724 00006A1A 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   725 00006A20 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   726 00006A24 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
   727                              <1> 	;mov	[ebx+LD_FATType], al ; 0
   728                              <1> 	;mov	[ebx+LD_FSType], ah
   729 00006A27 66894303            <1> 	mov	[ebx+LD_FATType], ax
   730                              <1> 	;mov	eax, [esi+ptStartSector]
   731                              <1> 	;mov	[ebx+LD_StartSector], eax
   732                              <1> loc_hd_fs_logical_drv_init:
   733 00006A2B 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
   734                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   735 00006A2D A0[6F5E0100]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
   736 00006A32 884305              <1> 	mov	[ebx+LD_LBAYes], al
   737 00006A35 89DE                <1> 	mov	esi, ebx
   738 00006A37 BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   739 00006A3C 08C0                <1> 	or	al, al
   740 00006A3E 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
   741                              <1> loc_hd_fs_drv_init_load_bs_chs:
   742 00006A40 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   743 00006A43 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   744 00006A47 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   745                              <1> 	;mov	ebx, DOSBootSectorBuff
   746 00006A4B E8E7D7FFFF          <1> 	call	int13h
   747 00006A50 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
   748                              <1> loc_validate_hd_fs_partition_err_retn:
   749 00006A52 C3                  <1> 	retn
   750                              <1> loc_validate_hd_fs_partition_stc_retn:
   751 00006A53 F9                  <1> 	stc
   752 00006A54 C3                  <1> 	retn
   753                              <1> loc_hd_fs_drv_init_load_bs_lba:
   754                              <1> 	; DL = Physical drive number
   755                              <1> 	;mov	esi, ebx
   756 00006A55 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
   757                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   758                              <1> 	; LBA read/write (with private LBA function) 
   759                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   760                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   761 00006A58 B41B                <1> 	mov	ah, 1Bh ; LBA read
   762 00006A5A B001                <1> 	mov	al, 1 ; sector count
   763 00006A5C E8D6D7FFFF          <1> 	call	int13h
   764 00006A61 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
   765                              <1> loc_hd_drv_fs_boot_validation:
   766                              <1> 	;mov	esi, DOSBootSectorBuff
   767 00006A63 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
   768 00006A65 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   769 00006A6E 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   770                              <1>         ;
   771                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
   772 00006A70 66817E034653        <1> 	cmp	word [esi+bs_FS_Identifier], 'FS' ; 03/02/2018
   773 00006A76 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   774                              <1>         ;'A1h' check is not necessary
   775                              <1> 	;  if 'FS' check is passed as OK/Yes.
   776 00006A78 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
   777 00006A7C 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   778                              <1> 	;
   779 00006A7E 89EF                <1> 	mov	edi, ebp ; 10/01/2016
   780                              <1> 	;
   781 00006A80 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
   782 00006A83 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
   783                              <1> 	;
   784                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
   785 00006A86 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
   786 00006A89 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
   787                              <1> 	;
   788 00006A8C 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
   789 00006A8F 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
   790                              <1> 	;
   791 00006A92 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
   792 00006A96 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
   793 00006A9A 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
   794 00006A9D 30E4                <1> 	xor	ah, ah ; 09/12/2017
   795 00006A9F 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
   796 00006AA3 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
   797 00006AA6 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
   798                              <1> 	;
   799 00006AAA 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
   800 00006AAD 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
   801 00006AB0 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
   802 00006AB3 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
   803 00006AB6 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
   804 00006AB9 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
   805 00006ABC 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
   806 00006ABF 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
   807 00006AC2 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
   808 00006AC5 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
   809                              <1> 	;
   810 00006AC8 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
   811 00006ACA 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   812 00006ACD 89FE                <1> 	mov	esi, edi
   813                              <1> mread_hd_fs_MAT_sector:
   814                              <1>        ;mov	ebx, DOSBootSectorBuff
   815 00006ACF B901000000          <1> 	mov	ecx, 1
   816 00006AD4 E85A8D0000          <1> 	call	disk_read
   817 00006AD9 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
   818                              <1> 	; EDI will not be changed
   819 00006ADB 89DE                <1> 	mov	esi, ebx
   820                              <1> use_hdfs_mat_sector_params:
   821 00006ADD 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
   822 00006AE0 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
   823 00006AE3 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
   824 00006AE6 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
   825 00006AE9 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
   826 00006AEC 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
   827 00006AEF 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
   828 00006AF2 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
   829 00006AF5 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
   830 00006AF8 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   831 00006AFB 89FE                <1> 	mov	esi, edi   
   832                              <1> read_hd_fs_RDT_sector:
   833 00006AFD BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff
   834                              <1> 	;mov	ecx, 1
   835 00006B02 B101                <1> 	mov	cl, 1
   836 00006B04 E82A8D0000          <1> 	call	disk_read
   837 00006B09 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
   838                              <1> 	; EDI will not be changed
   839 00006B0B 89DE                <1> 	mov	esi, ebx
   840                              <1> use_hdfs_RDT_sector_params:
   841 00006B0D 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
   842 00006B10 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
   843 00006B13 57                  <1> 	push	edi
   844                              <1> 	;mov	ecx, 16
   845 00006B14 B110                <1> 	mov	cl, 16
   846 00006B16 83C640              <1> 	add	esi, FS_RDT_VolumeName
   847 00006B19 83C72C              <1> 	add	edi, LD_FS_VolumeName
   848 00006B1C F3A5                <1> 	rep	movsd ; 64 bytes
   849 00006B1E 5E                  <1> 	pop	esi
   850                              <1> 		; Volume Name Reset
   851 00006B1F C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
   852                              <1> 	;
   853                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
   854                              <1> 	;add	cl, 'A'
   855                              <1> 	;mov	[esi+LD_FS_Name], cl
   856                              <1> 
   857                              <1> loc_validate_hd_fs_partition_retn:
   858 00006B23 C3                  <1> 	retn
   859                              <1> 
   860                              <1> load_masterboot:
   861                              <1> 	; 14/07/2020 (Reset function has been removed)
   862                              <1> 	;
   863                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   864                              <1> 	; 2005 - 2011
   865                              <1> 	; input -> DL = drive number
   866                              <1> ;	mov	ah, 0Dh ; Alternate disk reset
   867                              <1> ;	call	int13h
   868                              <1> ;	jnc	short pass_reset_error
   869                              <1> ;harddisk_error:
   870                              <1> ;  	retn
   871                              <1> ;pass_reset_error:
   872 00006B24 BB[6E5B0100]        <1> 	mov	ebx, MasterBootBuff
   873 00006B29 66B80102            <1> 	mov	ax, 0201h
   874 00006B2D 66B90100            <1> 	mov	cx, 1
   875 00006B31 30F6                <1> 	xor	dh, dh
   876 00006B33 E8FFD6FFFF          <1>  	call	int13h
   877 00006B38 720C                <1> 	jc	short harddisk_error
   878                              <1> 	;
   879 00006B3A 66813D[6C5D0100]55- <1> 	cmp	word [MBIDCode], 0AA55h
   879 00006B42 AA                  <1>
   880 00006B43 7401                <1> 	je	short load_masterboot_ok
   881 00006B45 F9                  <1> 	stc
   882                              <1> harddisk_error:
   883                              <1> load_masterboot_ok:
   884 00006B46 C3                  <1> 	retn
   885                              <1> 
   886                              <1> get_free_FAT_sectors:
   887                              <1> 	; 21/12/2017
   888                              <1> 	; 29/02/2016
   889                              <1> 	; 13/02/2016
   890                              <1> 	; 04/02/2016
   891                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
   892                              <1> 	; 11/07/2010
   893                              <1> 	; 21/06/2009
   894                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
   895                              <1> 	; OUTPUT: STC => Error
   896                              <1>         ;	cf = 0 and EAX = Free FAT sectors
   897                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
   898                              <1> 
   899 00006B47 31C0                <1> 	xor	eax, eax
   900                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
   901                              <1> 	
   902 00006B49 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
   903 00006B4D 7654                <1> 	jna	short loc_gfc_get_fat_free_clusters
   904                              <1> 
   905                              <1> 	; 29/02/2016
   906 00006B4F 48                  <1> 	dec	eax ; 0FFFFFFFFh
   907 00006B50 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
   908 00006B53 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
   909 00006B56 40                  <1> 	inc	eax ; 0
   910                              <1> 	;
   911 00006B57 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
   912 00006B5B 03466C              <1> 	add	eax, [esi+LD_StartSector]
   913                              <1> 
   914 00006B5E BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff
   915 00006B63 B901000000          <1> 	mov	ecx, 1
   916 00006B68 E8C68C0000          <1>  	call	disk_read
   917 00006B6D 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
   918                              <1> retn_gfc_get_fsinfo_sec:
   919 00006B6F C3                  <1> 	retn
   920                              <1> 
   921                              <1> loc_gfc_check_fsinfo_signs:
   922 00006B70 BB[765E0100]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
   923 00006B75 813B52526141        <1>         cmp     dword [ebx], 41615252h
   924 00006B7B 7524                <1> 	jne	short retn_gfc_get_fsinfo_stc
   925                              <1> 	;add	ebx, 484
   926                              <1> 	;cmp	dword [ebx], 61417272h
   927 00006B7D 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
   927 00006B86 61                  <1>
   928 00006B87 7518                <1> 	jne	short retn_gfc_get_fsinfo_stc
   929                              <1> 	;add	ebx, 4
   930                              <1> 	;mov	eax, [ebx]
   931 00006B89 8B83E8010000        <1> 	mov	eax, [ebx+488]
   932                              <1> 	; 29/02/2016
   933 00006B8F 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
   934 00006B92 8B93EC010000        <1> 	mov	edx,  [ebx+492] 
   935 00006B98 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster
   936                              <1> 	; 21/12/2017
   937 00006B9B 89C3                <1> 	mov	ebx, eax ; (initial value = 0FFFFFFFFh)
   938 00006B9D 43                  <1> 	inc	ebx ; 0FFFFFFFFh -> 0  
   939 00006B9E 7513                <1> 	jnz	short short retn_from_get_free_fat32_clusters
   940 00006BA0 C3                  <1> 	retn
   941                              <1> 
   942                              <1> retn_gfc_get_fsinfo_stc:
   943 00006BA1 F9                  <1> 	stc
   944 00006BA2 C3                  <1> 	retn
   945                              <1> 
   946                              <1> loc_gfc_get_fat_free_clusters:
   947                              <1> 	;mov	eax, 2
   948 00006BA3 B002                <1> 	mov	al, 2
   949                              <1> 	;mov	[FAT_CurrentCluster], eax
   950                              <1> loc_gfc_loop_get_next_cluster:
   951 00006BA5 E8F94F0000          <1> 	call	get_next_cluster
   952 00006BAA 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
   953 00006BAC 21C0                <1> 	and	eax, eax
   954 00006BAE 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
   955                              <1>  
   956                              <1> retn_from_get_free_fat_clusters:
   957 00006BB0 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
   958                              <1> retn_from_get_free_fat32_clusters:
   959 00006BB3 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
   960 00006BB7 F7E3                <1>       	mul	ebx
   961                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
   962                              <1> retn_get_free_sectors_calc:
   963 00006BB9 C3                  <1> 	retn
   964                              <1> 
   965                              <1> loc_gfc_free_fat_clusters_cont:
   966 00006BBA 09C0                <1> 	or	eax, eax
   967 00006BBC 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
   968 00006BBE FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
   969                              <1>    
   970                              <1> loc_gfc_pass_inc_free_cluster_count:
   971                              <1> 	;mov	eax, [FAT_CurrentCluster]
   972 00006BC1 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
   973 00006BC3 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
   974 00006BC6 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
   975 00006BC8 40                  <1> 	inc	eax
   976                              <1> 	;mov	[FAT_CurrentCluster], eax
   977 00006BC9 EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
   978                              <1> 
   979                              <1> floppy_drv_init:
   980                              <1> 	; 09/12/2017
   981                              <1> 	; 06/07/2016
   982                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   983                              <1> 	; 24/07/2011
   984                              <1> 	; 04/07/2009
   985                              <1> 	; INPUT ->
   986                              <1> 	;	DL = Drive number (0,1)
   987                              <1> 	; OUTPUT ->
   988                              <1> 	;	BL = drive name
   989                              <1> 	;	BH = drive number
   990                              <1> 	;	ESI = Logical DOS drv description table
   991                              <1> 	;	EAX = Volume serial number
   992                              <1>  
   993 00006BCB BE[265D0000]        <1> 	mov	esi, fd0_type ; 10/01/2016
   994 00006BD0 BF00010900          <1> 	mov	edi, Logical_DOSDisks
   995 00006BD5 08D2                <1> 	or	dl, dl
   996 00006BD7 7407                <1> 	jz	short loc_drv_init_fd0_fd1
   997 00006BD9 81C700010000        <1> 	add	edi, 100h
   998 00006BDF 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
   999                              <1> loc_drv_init_fd0_fd1:
  1000 00006BE0 C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
  1001 00006BE4 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
  1002                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
  1003 00006BE7 7221                <1> 	jb	short read_fd_boot_sector_retn
  1004 00006BE9 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
  1005                              <1> read_fd_boot_sector:
  1006 00006BEC 30F6                <1> 	xor	dh, dh
  1007 00006BEE B904000000          <1> 	mov	ecx, 4 ; Retry Count
  1008                              <1> read_fd_boot_sector_again:
  1009 00006BF3 51                  <1> 	push 	ecx
  1010                              <1> 	;mov	cx, 1
  1011 00006BF4 B101                <1> 	mov	cl, 1
  1012 00006BF6 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
  1013 00006BFA BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff
  1014 00006BFF E833D6FFFF          <1> 	call	int13h
  1015 00006C04 59                  <1> 	pop	ecx
  1016 00006C05 7304                <1> 	jnc	short use_fd_boot_sector_params
  1017 00006C07 E2EA                <1> 	loop	read_fd_boot_sector_again
  1018                              <1> 
  1019                              <1> read_fd_boot_sector_stc_retn:
  1020 00006C09 F9                  <1> 	stc
  1021                              <1> read_fd_boot_sector_retn:
  1022 00006C0A C3                  <1> 	retn
  1023                              <1> 
  1024                              <1> use_fd_boot_sector_params:
  1025                              <1> 	;mov	esi, DOSBootSectorBuff
  1026 00006C0B 89DE                <1> 	mov	esi, ebx
  1027 00006C0D 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
  1028 00006C16 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
  1029 00006C18 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
  1030 00006C1E 0F85A2000000        <1>         jne     use_fd_fatfs_boot_sector_params
  1031                              <1> 	;
  1032 00006C24 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
  1033 00006C27 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
  1034                              <1> 	;
  1035                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
  1036 00006C2A 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
  1037 00006C2D 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
  1038                              <1> 	;
  1039 00006C30 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
  1040 00006C33 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
  1041 00006C36 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
  1042 00006C3A 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
  1043 00006C3E 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
  1044 00006C41 28E4                <1> 	sub	ah, ah ; 09/12/2017
  1045 00006C43 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
  1046 00006C47 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
  1047 00006C4A 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
  1048                              <1> 	;
  1049 00006C4E 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
  1050 00006C51 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
  1051 00006C54 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
  1052 00006C57 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
  1053 00006C5A 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
  1054 00006C5D 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
  1055 00006C60 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
  1056 00006C63 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
  1057 00006C66 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
  1058 00006C69 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
  1059                              <1> 	;		
  1060 00006C6C 89FE                <1> 	mov	esi, edi
  1061 00006C6E 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
  1062                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
  1063                              <1> read_fd_MAT_sector_again:
  1064                              <1> 	;mov	ebx, DOSBootSectorBuff
  1065                              <1> 	;mov	ecx, 1
  1066 00006C71 B101                <1> 	mov	cl, 1
  1067 00006C73 E8C18B0000          <1> 	call	chs_read
  1068 00006C78 89DE                <1> 	mov	esi, ebx
  1069 00006C7A 7301                <1> 	jnc	short use_fdfs_mat_sector_params
  1070                              <1> 	;jmp	short read_fd_boot_sector_retn
  1071 00006C7C C3                  <1> 	retn
  1072                              <1> use_fdfs_mat_sector_params:
  1073 00006C7D 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
  1074 00006C80 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
  1075 00006C83 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
  1076 00006C86 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
  1077 00006C89 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
  1078 00006C8C 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
  1079 00006C8F 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
  1080 00006C92 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
  1081                              <1> 	;
  1082 00006C95 89FE                <1> 	mov	esi, edi
  1083 00006C97 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
  1084                              <1> read_fd_RDT_sector_again:
  1085                              <1> 	;mov	ebx, DOSBootSectorBuff
  1086                              <1> 	;mov	cx, 1
  1087 00006C9A B101                <1> 	mov	cl, 1
  1088 00006C9C E8988B0000          <1> 	call	chs_read
  1089 00006CA1 89DE                <1> 	mov	esi, ebx
  1090 00006CA3 7220                <1> 	jc	short read_fd_RDT_sector_retn
  1091                              <1> use_fdfs_RDT_sector_params:
  1092 00006CA5 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
  1093 00006CA8 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
  1094 00006CAB 57                  <1> 	push	edi
  1095                              <1> 	;mov	ecx, 16
  1096 00006CAC B110                <1> 	mov	cl, 16	
  1097 00006CAE 83C640              <1> 	add	esi, FS_RDT_VolumeName
  1098 00006CB1 83C72C              <1> 	add	edi, LD_FS_VolumeName
  1099 00006CB4 F3A5                <1> 	rep	movsd ; 64 bytes
  1100 00006CB6 5E                  <1> 	pop	esi
  1101 00006CB7 C6460300            <1> 	mov	byte [esi+LD_FATType], 0
  1102 00006CBB C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h  
  1103 00006CBF E9A5000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
  1104                              <1> 
  1105                              <1> read_fd_RDT_sector_stc_retn:
  1106 00006CC4 F9                  <1> 	stc
  1107                              <1> read_fd_RDT_sector_retn:
  1108 00006CC5 C3                  <1> 	retn
  1109                              <1> 
  1110                              <1> use_fd_fatfs_boot_sector_params:
  1111 00006CC6 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
  1112 00006CCA 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
  1113 00006CCC 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
  1114 00006CD0 72F3                <1> 	jb	short read_fd_RDT_sector_retn
  1115 00006CD2 57                  <1> 	push	edi
  1116 00006CD3 83C706              <1> 	add	edi, LD_BPB
  1117                              <1> 	;mov	ecx, 16
  1118 00006CD6 B110                <1> 	mov	cl, 16
  1119 00006CD8 F3A5                <1> 	rep	movsd ; 64 bytes 
  1120 00006CDA 5E                  <1> 	pop	esi
  1121 00006CDB 31C0                <1> 	xor	eax, eax
  1122 00006CDD 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
  1123 00006CE0 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
  1124 00006CE4 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs] 
  1125 00006CE7 F7E1                <1>   	mul	ecx
  1126                              <1> 	; edx = 0 !
  1127 00006CE9 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
  1128 00006CED 66895660            <1> 	mov	[esi+LD_FATBegin], dx
  1129                              <1> 	;add	eax, edx
  1130 00006CF1 6601D0              <1> 	add	ax, dx
  1131 00006CF4 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
  1132 00006CF7 894668              <1> 	mov	[esi+LD_DATABegin], eax 
  1133 00006CFA 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
  1134                              <1> 	;;shl	edx, 5 ; * 32 (Size of a directory entry)
  1135                              <1> 	;shl	dx, 5
  1136                              <1> 	;;add	edx, 511
  1137                              <1> 	;add	dx, 511
  1138                              <1> 	;;shr	edx, 9 ; edx = ((edx*32)+511) / 512
  1139                              <1> 	;shr	dx, 9
  1140 00006CFE 6683C20F            <1> 	add	dx, 15 ; 06/07/2016 (+(512/32)-1)
  1141 00006D02 66C1EA04            <1> 	shr	dx, 4 ; / 16 (==16 entries per sector)
  1142 00006D06 015668              <1> 	add 	[esi+LD_DATABegin], edx ; + rd sectors
  1143                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
  1144 00006D09 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
  1145 00006D0D 894670              <1> 	mov	[esi+LD_TotalSectors], eax
  1146 00006D10 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
  1147                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
  1148 00006D13 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]  
  1149 00006D16 80F901              <1> 	cmp	cl, 1
  1150 00006D19 7605                <1> 	jna	short save_fd_fatfs_cluster_count
  1151                              <1> 	;sub	edx, edx
  1152 00006D1B 6629D2              <1> 	sub	dx, dx ; 0
  1153                              <1> 	;sub	dl, dl ; 06/07/2016
  1154 00006D1E F7F1                <1> 	div	ecx
  1155                              <1> save_fd_fatfs_cluster_count:
  1156 00006D20 894678              <1> 	mov	[esi+LD_Clusters], eax
  1157                              <1> 
  1158                              <1>       ; Maximum Valid Cluster Number = EAX +1
  1159                              <1>       ; with 2 reserved clusters= EAX +2
  1160                              <1>  
  1161                              <1> reset_FAT_buffer_decriptors:
  1162 00006D23 29C0                <1> 	sub	eax, eax ; 0  
  1163 00006D25 A2[7A600100]        <1> 	mov	[FAT_BuffValidData], al ; 0
  1164 00006D2A A2[7B600100]        <1> 	mov	[FAT_BuffDrvName], al ; 0
  1165 00006D2F A3[7E600100]        <1> 	mov	[FAT_BuffSector], eax ; 0
  1166                              <1> 
  1167                              <1> read_fd_FAT_sectors:
  1168 00006D34 BB001C0900          <1>   	mov	ebx, FAT_Buffer
  1169 00006D39 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
  1170                              <1> 	;mov	ecx, 3
  1171 00006D3D B103                <1> 	mov	cl, 3 ; 3 sectors
  1172 00006D3F E8F58A0000          <1> 	call	chs_read
  1173 00006D44 7240                <1> 	jc	short read_fd_FAT_sectors_retn
  1174                              <1> use_fd_FAT_sectors:
  1175 00006D46 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
  1176 00006D49 0441                <1> 	add	al, 'A' 
  1177 00006D4B A2[7B600100]        <1> 	mov	[FAT_BuffDrvName], al 
  1178 00006D50 C605[7A600100]01    <1>  	mov	byte [FAT_BuffValidData], 1
  1179 00006D57 E82B000000          <1> 	call	fd_init_calculate_free_clusters
  1180 00006D5C 7228                <1> 	jc	short read_fd_FAT_sectors_retn
  1181                              <1>   
  1182                              <1> loc_use_fd_boot_sector_params_FAT:
  1183 00006D5E C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
  1184 00006D62 C6460401            <1> 	mov	byte [esi+LD_FSType], 1
  1185 00006D66 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
  1186                              <1> loc_cont_use_fd_boot_sector_params:
  1187 00006D69 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
  1188 00006D6C 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
  1189 00006D6F 88FB                <1> 	mov	bl, bh
  1190 00006D71 80C341              <1> 	add	bl, 'A'
  1191 00006D74 881E                <1> 	mov	byte [esi+LD_Name], bl
  1192 00006D76 C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
  1193 00006D7A C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
  1194 00006D7E C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
  1195 00006D82 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
  1196                              <1> 
  1197                              <1> read_fd_FAT_sectors_retn:
  1198 00006D86 C3                  <1> 	retn   
  1199                              <1> 
  1200                              <1> fd_init_calculate_free_clusters:
  1201                              <1> 	; 09/12/2017
  1202                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1203                              <1> 	; 04/07/2009
  1204                              <1> 	; INPUT ->
  1205                              <1> 	;     ESI = Logical DOS drive description table address
  1206                              <1> 	; OUTPUT ->
  1207                              <1> 	;    [ESI+LD_FreeSectors] will be set
  1208                              <1> 	
  1209 00006D87 29C0                <1> 	sub	eax, eax
  1210 00006D89 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
  1211 00006D8C B002                <1> 	mov	al, 2 ; eax = 2
  1212                              <1> 
  1213                              <1> fd_init_loop_get_next_cluster:
  1214 00006D8E E830000000          <1> 	call	fd_init_get_next_cluster
  1215 00006D93 722D                <1> 	jc	short fd_init_calculate_free_clusters_retn
  1216                              <1> 
  1217                              <1> fd_init_free_fat_clusters:
  1218                              <1> 	;cmp 	eax, 0
  1219                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
  1220                              <1> 	;and	eax, eax
  1221                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
  1222 00006D95 6621C0              <1> 	and	ax, ax
  1223 00006D98 7504                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
  1224                              <1> 	;inc	dword [esi+LD_FreeSectors]
  1225 00006D9A 66FF4674            <1>         inc	word [esi+LD_FreeSectors]
  1226                              <1>     
  1227                              <1> fd_init_pass_inc_free_cluster_count:
  1228                              <1>   	;mov	eax, [FAT_CurrentCluster]
  1229 00006D9E 66A1[76600100]      <1> 	mov	ax, [FAT_CurrentCluster]
  1230                              <1> 	;cmp	eax, [esi+LD_Clusters]
  1231 00006DA4 663B4678            <1> 	cmp	ax, [esi+LD_Clusters]
  1232 00006DA8 7704                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
  1233                              <1> 	;inc	eax
  1234 00006DAA 6640                <1> 	inc	ax
  1235 00006DAC EBE0                <1> 	jmp	short fd_init_loop_get_next_cluster
  1236                              <1> 
  1237                              <1> retn_from_fd_init_calculate_free_clusters:
  1238 00006DAE 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
  1239 00006DB1 3C01                <1>   	cmp	al, 1
  1240 00006DB3 760D                <1> 	jna	short fd_init_calculate_free_clusters_retn
  1241                              <1> 	;movzx	eax, al
  1242 00006DB5 30E4                <1> 	xor	ah, ah ; 09/12/2017
  1243                              <1> 	;mov	ecx, [esi+LD_FreeSectors]
  1244 00006DB7 668B4E74            <1> 	mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
  1245                              <1>   	;mul	ecx
  1246 00006DBB 66F7E1              <1> 	mul	cx
  1247                              <1> 	;mov	[esi+LD_FreeSectors], eax
  1248 00006DBE 66894674            <1> 	mov	[esi+LD_FreeSectors], ax
  1249                              <1> fd_init_calculate_free_clusters_retn:
  1250 00006DC2 C3                  <1> 	retn
  1251                              <1> 
  1252                              <1> fd_init_get_next_cluster:
  1253                              <1> 	; 04/02/2016
  1254                              <1> 	; 02/02/2016
  1255                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1256                              <1> 	; 04/07/2009
  1257                              <1> 	; INPUT ->
  1258                              <1> 	;    EAX = Current cluster
  1259                              <1> 	;    ESI = Logical DOS drive description table address
  1260                              <1> 	;    EDX = 0
  1261                              <1> 	; OUTPUT ->
  1262                              <1> 	;    EAX = Next cluster
  1263                              <1> 
  1264 00006DC3 A3[76600100]        <1> 	mov	[FAT_CurrentCluster], eax
  1265                              <1> fd_init_get_next_cluster_readnext:
  1266 00006DC8 29D2                <1> 	sub	edx, edx ; 0
  1267 00006DCA BB00040000          <1>   	mov	ebx, 1024 ; 400h
  1268 00006DCF F7F3                <1>   	div	ebx
  1269                              <1>   	; EAX = Count of 3 FAT sectors
  1270                              <1>   	; EDX = Buffer entry index
  1271 00006DD1 89C1                <1> 	mov	ecx, eax
  1272                              <1> 	;mov	eax, 3
  1273 00006DD3 B003                <1> 	mov	al, 3
  1274 00006DD5 F7E2                <1> 	mul	edx ; Multiply by 3
  1275 00006DD7 66D1E8              <1> 	shr	ax, 1 ; Divide by 2
  1276 00006DDA 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
  1277 00006DDC 81C3001C0900        <1> 	add	ebx, FAT_Buffer
  1278 00006DE2 89C8                <1> 	mov	eax, ecx
  1279                              <1> 	;mov	edx, 3
  1280 00006DE4 66BA0300            <1> 	mov	dx, 3
  1281 00006DE8 F7E2                <1> 	mul	edx 
  1282                              <1>   	; EAX = FAT Beginning Sector
  1283                              <1> 	; EDX = 0
  1284 00006DEA 8A0E                <1> 	mov	cl, [esi+LD_Name]
  1285                              <1> 	;cmp	byte [FAT_BuffValidData], 0
  1286                              <1> 	;jna	short fd_init_load_FAT_sectors0
  1287 00006DEC 3A0D[7B600100]      <1> 	cmp	cl, [FAT_BuffDrvName]
  1288 00006DF2 751E                <1> 	jne	short fd_init_load_FAT_sectors0
  1289 00006DF4 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
  1290 00006DFA 751C                <1> 	jne	short fd_init_load_FAT_sectors1
  1291                              <1> 	;mov	eax, [FAT_CurrentCluster]
  1292 00006DFC A0[76600100]        <1> 	mov	al, [FAT_CurrentCluster]
  1293                              <1> 	;shr	eax, 1
  1294 00006E01 D0E8                <1> 	shr	al, 1
  1295 00006E03 668B03              <1> 	mov	ax, [ebx]
  1296 00006E06 7306                <1>   	jnc	short fd_init_gnc_even
  1297 00006E08 66C1E804            <1> 	shr	ax, 4
  1298                              <1> fd_init_gnc_clc_retn:
  1299 00006E0C F8                  <1> 	clc
  1300 00006E0D C3                  <1> 	retn
  1301                              <1> 
  1302                              <1> fd_init_gnc_even:
  1303 00006E0E 80E40F              <1> 	and	ah, 0Fh
  1304 00006E11 C3                  <1> 	retn
  1305                              <1> 
  1306                              <1> fd_init_load_FAT_sectors0:
  1307 00006E12 880D[7B600100]      <1> 	mov 	[FAT_BuffDrvName], cl
  1308                              <1> fd_init_load_FAT_sectors1:
  1309 00006E18 C605[7A600100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1310 00006E1F A3[7E600100]        <1> 	mov	[FAT_BuffSector], eax
  1311 00006E24 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1312 00006E27 BB001C0900          <1>  	mov	ebx, FAT_Buffer
  1313                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
  1314 00006E2C 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
  1315 00006E30 662B0D[7E600100]    <1> 	sub	cx, [FAT_BuffSector]
  1316                              <1>         ;cmp	ecx, 3
  1317 00006E37 6683F903            <1> 	cmp	cx, 3
  1318 00006E3B 7605                <1> 	jna	short fdinit_pass_fix_sector_count_3
  1319                              <1> 	;mov	ecx, 3
  1320 00006E3D B903000000          <1> 	mov	ecx, 3
  1321                              <1> fdinit_pass_fix_sector_count_3:  
  1322 00006E42 E8F2890000          <1> 	call	chs_read
  1323 00006E47 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
  1324 00006E49 C605[7A600100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1325                              <1> 		; Drv not ready or read Error !
  1326 00006E50 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
  1327                              <1> 	;xor	edx, edx
  1328 00006E55 C3                  <1> 	retn
  1329                              <1> 
  1330                              <1> fd_init_FAT_sectors_no_load_error:
  1331 00006E56 C605[7A600100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1332 00006E5D A1[76600100]        <1> 	mov	eax, [FAT_CurrentCluster]
  1333 00006E62 E961FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
  1334                              <1> 
  1335                              <1> get_FAT_volume_name:
  1336                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1337                              <1> 	; 12/09/2009
  1338                              <1> 	; INPUT ->
  1339                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
  1340                              <1> 	;       BL = 0
  1341                              <1> 	; OUTPUT ->
  1342                              <1> 	;	CF = 0 -> ESI = Volume name address
  1343                              <1> 	; 	CF = 1 -> Root volume name not found
  1344                              <1> 
  1345                              <1> 	;mov 	ah, 0FFh
  1346                              <1> 	;mov 	al, [Last_Dos_DiskNo]
  1347                              <1> 	;cmp 	al, bh
  1348                              <1> 	;jb     short loc_gfvn_dir_load_err
  1349                              <1> 
  1350 00006E67 89DE                <1> 	mov	esi, ebx
  1351 00006E69 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
  1352 00006E6F 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1353 00006E75 8A06                <1> 	mov     al, [esi+LD_Name]
  1354 00006E77 8A6603              <1> 	mov     ah, [esi+LD_FATType]
  1355 00006E7A 80FC01              <1> 	cmp     ah, 1
  1356 00006E7D 7210                <1> 	jb    	short loc_gfvn_dir_load_err
  1357 00006E7F 3C41                <1> 	cmp 	al, 'A'
  1358 00006E81 720C                <1> 	jb      short loc_gfvn_dir_load_err
  1359 00006E83 80FC02              <1> 	cmp 	ah, 2 
  1360 00006E86 7708                <1> 	ja      short get_FAT32_root_cluster
  1361                              <1> 	
  1362 00006E88 E8714E0000          <1> 	call    load_FAT_root_directory
  1363 00006E8D 730B                <1> 	jnc     short loc_get_volume_name
  1364                              <1> 
  1365                              <1> loc_gfvn_dir_load_err:
  1366 00006E8F C3                  <1> 	retn
  1367                              <1> 
  1368                              <1> get_FAT32_root_cluster:
  1369 00006E90 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
  1370 00006E93 E8F14E0000          <1> 	call    load_FAT_sub_directory
  1371 00006E98 7224                <1> 	jc	short loc_get_volume_name_retn
  1372                              <1> 
  1373                              <1> loc_get_volume_name:
  1374 00006E9A BE00000800          <1>         mov     esi, Directory_Buffer
  1375 00006E9F 6631C9              <1> 	xor	cx, cx ; 0
  1376                              <1> check_root_volume_name:
  1377 00006EA2 8A06                <1> 	mov	al, [esi]
  1378 00006EA4 08C0                <1> 	or      al, al
  1379 00006EA6 7416                <1> 	jz      short loc_get_volume_name_retn
  1380 00006EA8 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
  1381 00006EAC 7410                <1> 	je      short loc_get_volume_name_retn
  1382 00006EAE 663B0D[8F600100]    <1> 	cmp     cx, [DirBuff_LastEntry]
  1383 00006EB5 7308                <1> 	jnb     short pass_check_root_volume_name
  1384 00006EB7 6641                <1> 	inc     cx
  1385 00006EB9 83C620              <1> 	add     esi, 32
  1386 00006EBC EBE4                <1> 	jmp     short check_root_volume_name
  1387                              <1> 
  1388                              <1> loc_get_volume_name_retn:
  1389 00006EBE C3                  <1> 	retn
  1390                              <1>     
  1391                              <1> pass_check_root_volume_name:
  1392 00006EBF 803D[8B600100]03    <1> 	cmp	byte [DirBuff_FATType], 3
  1393 00006EC6 7230                <1> 	jb	short loc_get_volume_name_retn_xor
  1394                              <1> 
  1395 00006EC8 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1396 00006ECD BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1397 00006ED2 31C0                <1> 	xor	eax, eax
  1398 00006ED4 8A25[8A600100]      <1> 	mov	ah, [DirBuff_DRV]
  1399 00006EDA 80EC41              <1> 	sub	ah, 'A' 
  1400 00006EDD 01C6                <1> 	add	esi, eax
  1401 00006EDF A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
  1402 00006EE4 E8BA4C0000          <1> 	call	get_next_cluster
  1403 00006EE9 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
  1404                              <1>   	
  1405 00006EEB 83F801              <1> 	cmp     eax, 1
  1406 00006EEE F5                  <1> 	cmc
  1407 00006EEF C3                  <1> 	retn
  1408                              <1>   
  1409                              <1> loc_gfvn_load_FAT32_dir_cluster:
  1410 00006EF0 E8944E0000          <1> 	call	load_FAT_sub_directory
  1411 00006EF5 73A3                <1> 	jnc	short loc_get_volume_name
  1412 00006EF7 C3                  <1> 	retn
  1413                              <1> 
  1414                              <1> loc_get_volume_name_retn_xor:
  1415 00006EF8 31C0                <1> 	xor 	eax, eax
  1416 00006EFA C3                  <1> 	retn
  1417                              <1> 
  1418                              <1> get_media_change_status:
  1419                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1420                              <1> 	; 09/09/2009
  1421                              <1> 	; INPUT:
  1422                              <1> 	;     DL = Drive number (physical)
  1423                              <1> 	; OUTPUT: clc & AH = 6 media changed
  1424                              <1> 	;     clc & AH = 0 media not changed         
  1425                              <1> 	;     stc -> Drive not ready or an error 
  1426                              <1>   
  1427 00006EFB B416                <1> 	mov	ah, 16h
  1428 00006EFD E835D3FFFF          <1>   	call	int13h
  1429 00006F02 80FC06              <1> 	cmp	ah, 06h
  1430 00006F05 7405                <1> 	je	short loc_gmc_status_retn
  1431 00006F07 08E4                <1> 	or	ah, ah
  1432 00006F09 7401                <1> 	jz	short loc_gmc_status_retn
  1433                              <1> loc_gmc_status_stc_retn:    
  1434 00006F0B F9                  <1> 	stc
  1435                              <1> loc_gmc_status_retn:
  1436 00006F0C C3                  <1> 	retn
  1437                              <1> 
  1438                              <1> ; temporary
  1439                              <1> MsgBurasi:
  1440 00006F0D 0D0A                <1> db 0Dh,0Ah
  1441 00006F0F 4275726173692E2E2E  <1> db "Burasi..."
  1442 00006F18 0D0A00              <1> db 0Dh, 0Ah, 0
  2307                                  %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: 31/12/2017
     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> 	; 16/10/2016
    21                              <1> 	; 02/02/2016
    22                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
    23                              <1> 	; 18/08/2011
    24                              <1> 	; 09/09/2009
    25                              <1> 	; INPUT:
    26                              <1> 	;   DL = Logical DOS Drive Number
    27                              <1> 	; OUTPUT:
    28                              <1> 	;  cf=1 -> Not successful
    29                              <1> 	;   EAX = Error code
    30                              <1> 	;  cf=0 ->
    31                              <1> 	;   EAX = 0 (successful)
    32                              <1> 
    33 00006F1B 31DB                <1> 	xor	ebx, ebx
    34 00006F1D 88D7                <1> 	mov	bh, dl
    35                              <1> 
    36                              <1> 	;cmp	dl, 1
    37                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
    38                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
    39                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
    40                              <1> 
    41                              <1> loc_ccdrv_initial_media_change_check:
    42 00006F1F BE00010900          <1> 	mov	esi, Logical_DOSDisks
    43 00006F24 01DE                <1> 	add	esi, ebx
    44                              <1> loc_ccdrv_dos_drive_name_check:
    45 00006F26 80FA02              <1> 	cmp	dl, 2
    46 00006F29 720F                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
    47                              <1> 
    48 00006F2B 8A06                <1> 	mov	al, [esi+LD_Name]
    49 00006F2D 2C41                <1> 	sub	al, 'A'
    50 00006F2F 38D0                <1> 	cmp	al, dl
    51 00006F31 7407                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
    52                              <1> 
    53                              <1> loc_ccdrv_drive_not_ready_err:
    54                              <1> 	; 16/10/2016 (15h -> 15)
    55 00006F33 B80F000000          <1> 	mov	eax, 15 ; Drive not ready
    56                              <1> loc_change_current_drive_stc_retn:
    57 00006F38 F9                  <1> 	stc
    58 00006F39 C3                  <1> 	retn  
    59                              <1> 
    60                              <1> loc_ccdrv_dos_drive_name_check_ok:
    61 00006F3A 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
    62 00006F3D 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
    63 00006F40 7455                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
    64                              <1> 
    65 00006F42 80FA01              <1> 	cmp	dl, 1
    66 00006F45 777D                <1> 	ja	short loc_gmcs_init_drv_hd
    67                              <1> 
    68                              <1> loc_gmcs_init_drv_fd:
    69 00006F47 08E4                <1> 	or	ah, ah 
    70                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
    71 00006F49 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
    72                              <1> 
    73 00006F4B E8ABFFFFFF          <1> 	call	get_media_change_status
    74 00006F50 72E1                <1> 	jc	short loc_ccdrv_drive_not_ready_err
    75                              <1> 
    76 00006F52 20E4                <1> 	and	ah, ah
    77 00006F54 7476                <1> 	jz	short loc_change_current_drv3
    78                              <1> 
    79 00006F56 80F406              <1> 	xor	ah, 6
    80 00006F59 75D8                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
    81                              <1> 
    82                              <1> loc_ccdrv_call_fd_init_check_vol_id:
    83 00006F5B E8440A0000          <1> 	call	get_volume_serial_number
    84 00006F60 730D                <1> 	jnc	short loc_ccdrv_check_vol_serial
    85                              <1> 
    86                              <1> loc_ccdrv_call_fd_init:
    87 00006F62 E864FCFFFF          <1> 	call	floppy_drv_init
    88 00006F67 731A                <1> 	jnc	short loc_reset_drv_fd_current_dir
    89                              <1> 
    90                              <1> loc_ccdrv_fdinit_fail_retn:
    91                              <1> 	; 16/10/2016
    92 00006F69 B80F000000          <1> 	mov	eax, 15 ; Drive not ready
    93 00006F6E C3                  <1> 	retn
    94                              <1> 
    95                              <1> loc_ccdrv_check_vol_serial:
    96 00006F6F A3[64590100]        <1> 	mov	[Current_VolSerial], eax
    97                              <1> 	;mov	dl, bh
    98 00006F74 E852FCFFFF          <1> 	call	floppy_drv_init
    99 00006F79 72EE                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
   100                              <1> 
   101 00006F7B 3B05[64590100]      <1> 	cmp	eax, [Current_VolSerial]
   102 00006F81 7445                <1> 	je	short loc_change_current_drv2
   103                              <1> 
   104                              <1> loc_reset_drv_fd_current_dir:
   105 00006F83 31C0                <1> 	xor	eax, eax              
   106 00006F85 88467F              <1>         mov	[esi+LD_CDirLevel], al
   107 00006F88 89F7                <1> 	mov	edi, esi
   108 00006F8A 81C780000000        <1> 	add	edi, LD_CurrentDirectory
   109 00006F90 B920000000          <1> 	mov	ecx, 32
   110 00006F95 F3AB                <1> 	rep	stosd   
   111                              <1>  
   112                              <1> loc_ccdrv_get_FAT_volume_name_0:
   113 00006F97 8A4603              <1> 	mov	al, [esi+LD_FATType]
   114 00006F9A 08C0                <1> 	or	al, al
   115 00006F9C 742A                <1> 	jz	short loc_change_current_drv2
   116                              <1> 
   117 00006F9E 56                  <1> 	push	esi 
   118 00006F9F 3C02                <1> 	cmp	al, 2
   119 00006FA1 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
   120                              <1>              
   121                              <1> loc_ccdrv_get_FAT2_16_vol_name:
   122 00006FA3 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
   123 00006FA6 EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
   124                              <1> 
   125                              <1> loc_ccdrv_get_FAT32_vol_name:
   126 00006FA8 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
   127                              <1> loc_ccdrv_get_FAT_volume_name_1:
   128 00006FAB 53                  <1> 	push	ebx
   129 00006FAC 56                  <1> 	push	esi
   130 00006FAD E8B5FEFFFF          <1> 	call	get_FAT_volume_name
   131 00006FB2 5F                  <1> 	pop	edi
   132 00006FB3 5B                  <1> 	pop	ebx
   133                              <1> 	; BL = 0
   134 00006FB4 720B                <1> 	jc	short loc_change_current_drv1
   135 00006FB6 20C0                <1> 	and	al, al
   136 00006FB8 7407                <1> 	jz	short loc_change_current_drv1
   137                              <1> 
   138                              <1> loc_ccdrv_move_FAT_volume_name:
   139 00006FBA B90B000000          <1> 	mov	ecx, 11
   140 00006FBF F3A4                <1> 	rep	movsb
   141                              <1> 
   142                              <1> loc_change_current_drv1:
   143 00006FC1 5E                  <1> 	pop	esi
   144 00006FC2 EB04                <1> 	jmp	short loc_change_current_drv2
   145                              <1> 
   146                              <1> loc_gmcs_init_drv_hd:
   147 00006FC4 08E4                <1> 	or	ah, ah
   148 00006FC6 7404                <1> 	jz	short loc_change_current_drv3
   149                              <1> 	; BL = 0, BH = Logical DOS drive number
   150                              <1> loc_change_current_drv2:
   151 00006FC8 C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
   152                              <1> loc_change_current_drv3:
   153 00006FCC 883D[6E590100]      <1> 	mov	[Current_Drv], bh
   154                              <1> 
   155                              <1> 	;call	restore_current_directory
   156                              <1> 	;retn
   157                              <1> 
   158                              <1> restore_current_directory:
   159                              <1> 	; 11/02/2016
   160                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
   161                              <1> 	; 25/01/2010
   162                              <1> 	; 12/10/2009
   163                              <1> 	;
   164                              <1> 	; INPUT:
   165                              <1> 	;   ESI = Logical DOS Drive Description Table
   166                              <1> 	;
   167                              <1> 	; OUTPUT:
   168                              <1> 	;   ESI = Logical DOS Drive Description Table
   169                              <1> 	;   EDI = offset Current_Dir_Drv 
   170                              <1> 
   171 00006FD2 8A4603              <1> 	mov	al, [esi+LD_FATType]
   172 00006FD5 A2[6D590100]        <1> 	mov	[Current_FATType], al
   173                              <1> 
   174 00006FDA 8A26                <1> 	mov	ah, [esi+LD_Name] 
   175 00006FDC 8825[6F590100]      <1> 	mov	[Current_Dir_Drv], ah
   176                              <1> 
   177 00006FE2 20C0                <1> 	and	al, al
   178 00006FE4 741D                <1> 	jz	short loc_restore_FS_current_directory
   179                              <1> 
   180                              <1> loc_restore_FAT_current_directory:
   181 00006FE6 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   182 00006FE9 8825[6C590100]      <1> 	mov	[Current_Dir_Level], ah
   183 00006FEF 08E4                <1> 	or	ah, ah
   184 00006FF1 7416                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
   185                              <1> 
   186 00006FF3 0FB6D4              <1> 	movzx	edx, ah
   187 00006FF6 C0E204              <1> 	shl	dl, 4 ; * 16
   188 00006FF9 01F2                <1>         add	edx, esi
   189 00006FFB 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
   190 00007001 EB2C                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
   191                              <1> 
   192                              <1> loc_restore_FS_current_directory:
   193 00007003 E8BC4D0000          <1> 	call	load_current_FS_directory 
   194 00007008 C3                  <1> 	retn 
   195                              <1> 
   196                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
   197 00007009 3C03                <1> 	cmp	al, 3
   198 0000700B 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
   199                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
   200 0000700D 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   201 00007010 EB04                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
   202                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
   203 00007012 30C0                <1> 	xor	al, al  ; xor eax, eax
   204 00007014 31D2                <1> 	xor	edx, edx
   205                              <1> loc_ccdrv_check_rootdir_sign:
   206 00007016 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
   207 0000701D 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
   208                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
   209 0000701F 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
   210 00007025 C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
   210 0000702E 54                  <1>
   211                              <1> 
   212                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
   213 0000702F A3[68590100]        <1> 	mov	[Current_Dir_FCluster], eax
   214                              <1> 
   215 00007034 BF[C3600100]        <1> 	mov	edi, PATH_Array
   216 00007039 89F2                <1> 	mov	edx, esi
   217 0000703B 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   218 00007041 B920000000          <1> 	mov	ecx, 32
   219 00007046 F3A5                <1> 	rep	movsd
   220                              <1> 
   221 00007048 E84C2D0000          <1> 	call	change_prompt_dir_string
   222                              <1> 	
   223 0000704D 89D6                <1> 	mov	esi, edx
   224                              <1> 	
   225 0000704F 29C0                <1>         sub	eax, eax
   226                              <1>        ;sub	edx, edx
   227 00007051 BF[6F590100]        <1> 	mov	edi, Current_Dir_Drv
   228                              <1> 
   229 00007056 A2[3B0D0100]        <1> 	mov	[Restore_CDIR], al ; 0
   230 0000705B C3                  <1> 	retn
   231                              <1> 
   232                              <1> dos_prompt:
   233                              <1> 	; 06/05/2016
   234                              <1> 	; 30/01/2016
   235                              <1> 	; 29/01/2016
   236                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   237                              <1> 	; 15/09/2011
   238                              <1> 	; 13/09/2009
   239                              <1> 	; 2004-2005
   240                              <1> 
   241                              <1> 	; 06/05/2016
   242 0000705C C705[20650100]-     <1> 	mov	dword [mainprog_return_addr], return_from_cmd_interpreter
   242 00007062 [10710000]          <1>
   243                              <1> 
   244                              <1> loc_TRDOS_prompt:
   245 00007066 BF[6E5A0100]        <1> 	mov	edi, TextBuffer
   246 0000706B C6075B              <1> 	mov	byte [edi], "["
   247 0000706E 47                  <1> 	inc	edi
   248 0000706F BE[8E0D0100]        <1> 	mov	esi, TRDOSPromptLabel
   249                              <1> get_next_prompt_label_char:
   250 00007074 803E20              <1> 	cmp	byte [esi], 20h
   251 00007077 7203                <1> 	jb	short pass_prompt_label
   252 00007079 A4                  <1> 	movsb
   253 0000707A EBF8                <1> 	jmp	short get_next_prompt_label_char
   254                              <1> pass_prompt_label:
   255 0000707C C6075D              <1> 	mov	byte [edi], "]"
   256 0000707F 47                  <1> 	inc	edi
   257 00007080 C60720              <1> 	mov	byte [edi], 20h
   258 00007083 47                  <1> 	inc	edi
   259 00007084 BE[6F590100]        <1> 	mov	esi, Current_Dir_Drv
   260 00007089 66A5                <1> 	movsw
   261 0000708B A4                  <1> 	movsb 
   262                              <1> loc_prompt_current_directory:
   263 0000708C 803E20              <1> 	cmp	byte [esi], 20h
   264 0000708F 7203                <1> 	jb	short pass_prompt_current_directory
   265 00007091 A4                  <1> 	movsb
   266 00007092 EBF8                <1> 	jmp	short loc_prompt_current_directory  
   267                              <1> pass_prompt_current_directory:
   268 00007094 C6073E              <1> 	mov	byte [edi], '>'
   269 00007097 47                  <1> 	inc	edi
   270 00007098 C60700              <1> 	mov	byte [edi], 0  
   271 0000709B BE[6E5A0100]        <1> 	mov	esi, TextBuffer
   272 000070A0 E8F8F2FFFF          <1> 	call	print_msg
   273                              <1>         
   274                              <1> 	;sub	bh, bh ; video page = 0
   275                              <1> 	;call	get_cpos ; get cursor position
   276 000070A5 668B15[C6580100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   277 000070AC 8815[CE590100]      <1> 	mov	[CursorColumn], dl
   278                              <1> 
   279                              <1> 	; 30/01/2016 (to show cursor on the row, again)
   280                              <1> 	; (Initial color attributes of video page 0 is 0)
   281                              <1> 	; (see: 'StartPMP' in trdos386.s)
   282                              <1> 	; 
   283                              <1> 	;mov	edi, 0B8000h ; start of video page 0
   284                              <1> 	;movzx	ecx, dl ; column	 
   285                              <1> 	;mov	al, 80
   286                              <1> 	;mul	dh
   287                              <1> 	;add	ax, cx
   288                              <1> 	;shl	ax, 1 ; character + attribute
   289                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
   290                              <1> 	;neg	cl
   291                              <1> 	;add	cl, 80
   292                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
   293                              <1> 	;rep	stosw	
   294                              <1> 
   295                              <1> loc_rw_char:
   296 000070B2 E899000000          <1> 	call	rw_char
   297                              <1> loc_move_command:
   298 000070B7 BE[1E5A0100]        <1> 	mov	esi, CommandBuffer
   299 000070BC 89F7                <1> 	mov	edi, esi
   300 000070BE 31C9                <1> 	xor	ecx, ecx
   301                              <1> first_command_char:
   302 000070C0 AC                  <1> 	lodsb
   303 000070C1 3C20                <1> 	cmp	al, 20h
   304 000070C3 772E                <1> 	ja	short pass_space_control
   305 000070C5 7241                <1> 	jb	short loc_move_cmd_arguments_ok
   306 000070C7 81FE[6D5A0100]      <1> 	cmp	esi, CommandBuffer + 79
   307 000070CD 72F1                <1> 	jb	short first_command_char
   308 000070CF EB37                <1> 	jmp	short loc_move_cmd_arguments_ok
   309                              <1> 
   310                              <1> next_command_char:
   311 000070D1 AC                  <1> 	lodsb
   312 000070D2 3C20                <1> 	cmp	al, 20h
   313 000070D4 771D                <1> 	ja	short pass_space_control
   314 000070D6 7230                <1> 	jb	short loc_move_cmd_arguments_ok
   315                              <1> 
   316                              <1> loc_1st_cmd_arg: ; 30/01/2016
   317 000070D8 AC                  <1> 	lodsb
   318 000070D9 3C20                <1> 	cmp	al, 20h
   319 000070DB 74FB                <1> 	je	short loc_1st_cmd_arg
   320 000070DD 7229                <1> 	jb	short loc_move_cmd_arguments_ok
   321                              <1> 	
   322 000070DF C60700              <1>         mov     byte [edi], 0
   323 000070E2 47                  <1> 	inc	edi
   324                              <1> 
   325                              <1> loc_move_cmd_arguments:
   326 000070E3 AA                  <1> 	stosb
   327 000070E4 81FE[6D5A0100]      <1> 	cmp	esi, CommandBuffer + 79
   328 000070EA 731C                <1> 	jnb	short loc_move_cmd_arguments_ok
   329 000070EC AC                  <1>         lodsb
   330 000070ED 3C20                <1> 	cmp	al, 20h
   331 000070EF 73F2                <1> 	jnb	short loc_move_cmd_arguments
   332 000070F1 EB15                <1> 	jmp	short loc_move_cmd_arguments_ok
   333                              <1> 
   334                              <1> pass_space_control:
   335 000070F3 3C61                <1> 	cmp	al, 61h
   336 000070F5 7206                <1> 	jb	short pass_capitalize
   337 000070F7 3C7A                <1> 	cmp	al, 7Ah
   338 000070F9 7702                <1> 	ja	short pass_capitalize
   339 000070FB 24DF                <1> 	and	al, 0DFh
   340                              <1> pass_capitalize:
   341 000070FD AA                  <1> 	stosb   
   342 000070FE FEC1                <1> 	inc     cl
   343 00007100 81FE[6D5A0100]      <1>         cmp     esi, CommandBuffer + 79
   344 00007106 72C9                <1> 	jb      short next_command_char 
   345                              <1> 
   346                              <1> loc_move_cmd_arguments_ok:
   347 00007108 C60700              <1>         mov     byte [edi], 0
   348                              <1> 
   349                              <1> call_command_interpreter:
   350 0000710B E8CF080000          <1> 	call    command_interpreter
   351                              <1> 
   352                              <1> return_from_cmd_interpreter:
   353 00007110 B950000000          <1>         mov	ecx, 80
   354                              <1> 	;mov	cx, 80
   355 00007115 BF[1E5A0100]        <1> 	mov	edi, CommandBuffer
   356 0000711A 30C0                <1> 	xor	al, al
   357 0000711C F3AA                <1> 	rep	stosb
   358                              <1> 	;cmp	byte [Program_Exit], 0
   359                              <1> 	;ja	short loc_terminate_trdos
   360                              <1>         
   361                              <1> 	; 16/01/2016
   362 0000711E 803D[F25E0000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
   363 00007125 741D                <1> 	je	short pass_set_txt_mode
   364                              <1> 
   365 00007127 E867A4FFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
   366                              <1> 	; 07/01/2017
   367 0000712C 30C0                <1> 	xor	al, al
   368                              <1> 
   369                              <1> loc_check_active_page:
   370                              <1> 	;xor	al, al
   371 0000712E 3805[D6580100]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
   372 00007134 0F842CFFFFFF        <1>         je      loc_TRDOS_prompt 
   373                              <1> 	; AL = 0 = video page 0
   374 0000713A E86DA8FFFF          <1> 	call	set_active_page
   375 0000713F E922FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
   376                              <1> 
   377                              <1> pass_set_txt_mode: 
   378 00007144 BE[D7190100]        <1> 	mov	esi, nextline
   379 00007149 E84FF2FFFF          <1> 	call	print_msg
   380 0000714E EBDE                <1> 	jmp     short loc_check_active_page
   381                              <1> 
   382                              <1> rw_char:
   383                              <1> 	; 13/05/2016
   384                              <1> 	; 30/01/2016
   385                              <1> 	; 29/01/2016
   386                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   387                              <1> 	; 2004-2005
   388                              <1> 	
   389                              <1> 	; DH = cursor row, DL = cursor column
   390                              <1> 	; BH = 0 = video page number (active page)
   391                              <1> 
   392                              <1> 	;xor	bh, bh ; 0 = video page 0
   393                              <1> 
   394                              <1> readnextchar:
   395 00007150 30E4                <1> 	xor     ah, ah
   396 00007152 E8EF9AFFFF          <1> 	call	int16h
   397 00007157 20C0                <1> 	and	al, al
   398 00007159 7432                <1> 	jz	short loc_arrow    
   399 0000715B 3CE0                <1> 	cmp	al, 0E0h          
   400 0000715D 742E                <1> 	je	short loc_arrow
   401 0000715F 3C08                <1> 	cmp	al, 08h             
   402 00007161 7542                <1> 	jne	short char_return
   403                              <1> loc_back:
   404 00007163 3A15[CE590100]      <1> 	cmp	dl, [CursorColumn]
   405 00007169 76E5                <1> 	jna     short readnextchar
   406                              <1> prev_column:
   407 0000716B FECA                <1> 	dec	dl
   408                              <1> set_cursor_pos:
   409                              <1> 	;push	dx
   410 0000716D 52                  <1> 	push	edx ; 29/12/2017
   411                              <1> 	;xor	bh, bh ; 0 = video page 0
   412                              <1> 	; DH = Row, DL = Column
   413 0000716E E805ACFFFF          <1> 	call	_set_cpos ; 17/01/2016
   414 00007173 5A                  <1>         pop	edx ; 29/12/2017
   415                              <1> 	;pop	dx
   416                              <1> 	;movzx	ebx, dl
   417 00007174 88D3                <1> 	mov	bl, dl
   418 00007176 2A1D[CE590100]      <1> 	sub	bl, [CursorColumn] 
   419 0000717C B020                <1> 	mov	al, 20h
   420 0000717E 8883[1E5A0100]      <1> 	mov	[CommandBuffer+ebx], al
   421                              <1> 	;sub	bh, bh ; video page 0
   422                              <1> 	;mov	cx, 1
   423 00007184 B307                <1> 	mov	bl, 7 ; color attribute
   424 00007186 E8DEAAFFFF          <1> 	call	_write_c_current ; 17/01/2016
   425                              <1> 	;mov	dx, [CURSOR_POSN]
   426 0000718B EBC3                <1> 	jmp	short readnextchar
   427                              <1> loc_arrow:    
   428 0000718D 80FC4B              <1> 	cmp	ah, 4Bh
   429 00007190 74D1                <1> 	je	short loc_back
   430 00007192 80FC53              <1> 	cmp	ah, 53h
   431 00007195 74CC                <1> 	je      short loc_back
   432 00007197 80FC4D              <1> 	cmp	ah, 4Dh
   433 0000719A 75B4                <1> 	jne	short readnextchar
   434 0000719C 80FA4F              <1> 	cmp	dl, 79
   435 0000719F 73AF                <1> 	jnb	short readnextchar
   436 000071A1 FEC2                <1> 	inc	dl
   437 000071A3 EBC8                <1> 	jmp	short set_cursor_pos
   438                              <1> char_return:
   439 000071A5 0FB6DA              <1> 	movzx	ebx, dl
   440 000071A8 2A1D[CE590100]      <1> 	sub	bl, [CursorColumn] 
   441 000071AE 3C20                <1> 	cmp	al, 20h
   442 000071B0 721D                <1> 	jb	short loc_escape
   443 000071B2 8883[1E5A0100]      <1> 	mov	[CommandBuffer+ebx], al
   444 000071B8 80FA4F              <1> 	cmp	dl, 79
   445 000071BB 7393                <1> 	jnb	short readnextchar
   446 000071BD 66BB0700            <1> 	mov	bx, 7 ; color attribute
   447 000071C1 E81CABFFFF          <1> 	call	_write_tty
   448 000071C6 668B15[C6580100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   449 000071CD EB81                <1>         jmp     readnextchar
   450                              <1> loc_escape:
   451 000071CF 3C1B                <1> 	cmp	al, 1Bh
   452 000071D1 7418                <1> 	je	short rw_char_retn
   453                              <1> 	;
   454 000071D3 3C0D                <1> 	cmp	al, 0Dh ; CR
   455 000071D5 0F8575FFFFFF        <1>         jne     readnextchar
   456                              <1> 	; 13/05/2016
   457 000071DB 66BB0700            <1> 	mov	bx, 7 ; attribute/color (bl)
   458                              <1> 		      ; video page 0 (bh=0)	
   459 000071DF E8FEAAFFFF          <1> 	call	_write_tty
   460                              <1> 	;mov	bx, 7  ; attribute/color
   461                              <1> 		      ; video page 0 (bh=0)
   462 000071E4 B00A                <1> 	mov	al, 0Ah ; LF
   463 000071E6 E8F7AAFFFF          <1> 	call	_write_tty
   464                              <1> rw_char_retn:
   465 000071EB C3                  <1> 	retn
   466                              <1> 
   467                              <1> show_date:
   468                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   469                              <1>         ; 2004-2005
   470                              <1> 
   471                              <1> 	;mov	ah, 04h
   472                              <1> 	;call	int1Ah
   473 000071EC E8A0E8FFFF          <1> 	call	RTC_40	; GET RTC DATE
   474                              <1> 
   475 000071F1 88D0                <1> 	mov	al, dl
   476 000071F3 E8459AFFFF          <1>   	call	bcd_to_ascii
   477 000071F8 66A3[7A0E0100]      <1> 	mov	[Day], ax
   478                              <1> 
   479 000071FE 88F0                <1> 	mov	al, dh
   480 00007200 E8389AFFFF          <1>   	call	bcd_to_ascii
   481 00007205 66A3[7D0E0100]      <1> 	mov	[Month], ax
   482                              <1> 
   483 0000720B 88E8                <1> 	mov	al, ch
   484 0000720D E82B9AFFFF          <1>   	call	bcd_to_ascii
   485 00007212 66A3[800E0100]      <1> 	mov	[Century], ax
   486                              <1> 
   487 00007218 88C8                <1> 	mov	al, cl
   488 0000721A E81E9AFFFF          <1>   	call	bcd_to_ascii
   489 0000721F 66A3[820E0100]      <1> 	mov	word [Year], ax
   490                              <1> 
   491 00007225 BE[6A0E0100]        <1> 	mov	esi, Msg_Show_Date
   492 0000722A E86EF1FFFF          <1> 	call	print_msg
   493                              <1> 
   494 0000722F C3                  <1> 	retn
   495                              <1> 
   496                              <1> set_date:
   497                              <1> 	; 13/05/2016
   498                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   499                              <1>         ; 2004-2005
   500                              <1> 
   501 00007230 BE[4E0E0100]        <1> 	mov	esi, Msg_Enter_Date
   502 00007235 E863F1FFFF          <1> 	call	print_msg
   503                              <1> 
   504                              <1> loc_enter_day_1:
   505 0000723A 30E4                <1> 	xor     ah, ah
   506 0000723C E8059AFFFF          <1> 	call	int16h
   507                              <1> 	; AL = ASCII Code of the Character
   508 00007241 3C0D                <1> 	cmp	al, 13
   509 00007243 0F84B7010000        <1> 	je	loc_set_date_retn
   510 00007249 3C1B                <1> 	cmp	al, 27
   511 0000724B 0F84AF010000        <1> 	je	loc_set_date_retn
   512 00007251 A2[7A0E0100]        <1> 	mov	[Day], al
   513 00007256 3C30                <1> 	cmp	al, '0'
   514 00007258 0F82AD010000        <1> 	jb	loc_set_date_stc_0
   515 0000725E 3C33                <1> 	cmp	al, '3'
   516 00007260 0F87A5010000        <1> 	ja	loc_set_date_stc_0
   517                              <1> 	; 13/05/2016
   518                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   519                              <1> 		      ; video page 0 (bh)	
   520 00007266 B307                <1> 	mov	bl, 7
   521 00007268 E875AAFFFF          <1> 	call	_write_tty
   522                              <1> loc_enter_day_2:
   523 0000726D 30E4                <1> 	xor     ah, ah
   524 0000726F E8D299FFFF          <1> 	call	int16h
   525                              <1> 	; AL = ASCII Code of the Character
   526 00007274 3C1B                <1> 	cmp	al, 27
   527 00007276 0F8484010000        <1>         je      loc_set_date_retn
   528 0000727C A2[7B0E0100]        <1> 	mov	[Day+1], al
   529 00007281 3C30                <1> 	cmp	al, '0'
   530 00007283 0F828C010000        <1>         jb      loc_set_date_stc_1
   531 00007289 3C39                <1> 	cmp	al, '9'
   532 0000728B 0F8784010000        <1>         ja      loc_set_date_stc_1
   533 00007291 803D[7A0E0100]33    <1> 	cmp	byte [Day], '3'
   534 00007298 7208                <1> 	jb	short pass_set_day_31
   535 0000729A 3C31                <1> 	cmp	al, '1'
   536 0000729C 0F8773010000        <1>         ja      loc_set_date_stc_1
   537                              <1> pass_set_day_31:
   538                              <1> 	; 13/05/2016
   539                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   540                              <1> 		      ; video page 0 (bh)	
   541 000072A2 B307                <1> 	mov	bl, 7
   542 000072A4 E839AAFFFF          <1> 	call	_write_tty
   543                              <1> loc_enter_separator_1:
   544 000072A9 28E4                <1> 	sub     ah, ah ; 0
   545 000072AB E89699FFFF          <1> 	call	int16h
   546                              <1> 	; AL = ASCII Code of the Character
   547 000072B0 3C1B                <1> 	cmp	al, 27
   548 000072B2 0F8448010000        <1>         je      loc_set_date_retn
   549 000072B8 3C2D                <1> 	cmp	al, '-'
   550 000072BA 7408                <1> 	je	short pass_set_date_separator_1
   551 000072BC 3C2F                <1> 	cmp	al, '/'
   552 000072BE 0F856C010000        <1>         jne     loc_set_date_stc_2
   553                              <1> pass_set_date_separator_1:
   554                              <1> 	; 13/05/2016
   555                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   556                              <1> 		      ; video page 0 (bh)
   557 000072C4 B307                <1> 	mov	bl, 7	
   558 000072C6 E817AAFFFF          <1> 	call	_write_tty
   559                              <1> loc_enter_month_1:
   560 000072CB 30E4                <1> 	xor     ah, ah ; 0
   561 000072CD E87499FFFF          <1> 	call	int16h
   562                              <1> 	; AL = ASCII Code of the Character
   563 000072D2 3C1B                <1> 	cmp	al, 27
   564 000072D4 0F8426010000        <1>         je      loc_set_date_retn
   565 000072DA A2[7D0E0100]        <1> 	mov	[Month], al
   566 000072DF 3C30                <1> 	cmp	al, '0'
   567 000072E1 0F8264010000        <1>         jb      loc_set_date_stc_3
   568 000072E7 3C31                <1> 	cmp	al, '1'
   569 000072E9 0F875C010000        <1>         ja      loc_set_date_stc_3
   570                              <1> 	; 13/05/2016
   571                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   572                              <1> 		      ; video page 0 (bh)	
   573 000072EF B307                <1> 	mov	bl, 7
   574 000072F1 E8ECA9FFFF          <1> 	call	_write_tty
   575                              <1> loc_enter_month_2:
   576 000072F6 30E4                <1> 	xor     ah, ah
   577 000072F8 E84999FFFF          <1> 	call	int16h
   578                              <1> 	; AL = ASCII Code of the Character
   579 000072FD 3C1B                <1> 	cmp	al, 27
   580 000072FF 0F84FB000000        <1>         je      loc_set_date_retn
   581 00007305 A2[7E0E0100]        <1> 	mov	[Month+1], al
   582 0000730A 3C30                <1> 	cmp	al, '0'
   583 0000730C 0F8254010000        <1>         jb      loc_set_date_stc_4
   584 00007312 3C39                <1> 	cmp	al, '9'
   585 00007314 0F874C010000        <1>         ja      loc_set_date_stc_4
   586 0000731A 803D[7D0E0100]31    <1> 	cmp	byte [Month], '1'
   587 00007321 7208                <1> 	jb	short pass_set_month_12
   588 00007323 3C32                <1> 	cmp	al, '2'
   589 00007325 0F873B010000        <1>         ja      loc_set_date_stc_4
   590                              <1> pass_set_month_12:
   591                              <1> 	; 13/05/2016
   592                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   593                              <1> 		      ; video page 0 (bh)
   594 0000732B B307                <1> 	mov	bl, 7	
   595 0000732D E8B0A9FFFF          <1> 	call	_write_tty
   596                              <1> loc_enter_separator_2:
   597 00007332 28E4                <1> 	sub     ah, ah
   598 00007334 E80D99FFFF          <1> 	call	int16h
   599                              <1> 	; AL = ASCII Code of the Character
   600 00007339 3C1B                <1> 	cmp	al, 27
   601 0000733B 0F84BF000000        <1>         je      loc_set_date_retn
   602 00007341 3C2D                <1> 	cmp	al, '-'
   603 00007343 7408                <1> 	je	short pass_set_date_separator_2
   604 00007345 3C2F                <1> 	cmp	al, '/'
   605 00007347 0F8534010000        <1>         jne     loc_set_date_stc_5
   606                              <1> pass_set_date_separator_2:
   607                              <1> 	; 13/05/2016
   608                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   609                              <1> 		      ; video page 0 (bh)	
   610 0000734D B307                <1> 	mov	bl, 7
   611 0000734F E88EA9FFFF          <1> 	call	_write_tty
   612                              <1> loc_enter_year_1:
   613 00007354 30E4                <1> 	xor    ah, ah
   614 00007356 E8EB98FFFF          <1> 	call	int16h
   615                              <1> 	; AL = ASCII Code of the Character
   616 0000735B 3C1B                <1> 	cmp	al, 27
   617 0000735D 0F849D000000        <1>         je      loc_set_date_retn
   618 00007363 A2[820E0100]        <1> 	mov	[Year], al
   619 00007368 3C30                <1> 	cmp	al, '0'
   620 0000736A 0F822C010000        <1>         jb      loc_set_date_stc_6
   621 00007370 3C39                <1> 	cmp	al, '9'
   622 00007372 0F8724010000        <1>         ja      loc_set_date_stc_6
   623                              <1> 	; 13/05/2016
   624                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   625                              <1> 		      ; video page 0 (bh)
   626 00007378 B307                <1> 	mov	bl, 7	
   627 0000737A E863A9FFFF          <1> 	call	_write_tty
   628                              <1> loc_enter_year_2:
   629 0000737F 30E4                <1> 	xor	ah, ah
   630 00007381 E8C098FFFF          <1> 	call	int16h
   631                              <1> 	; AL = ASCII Code of the Character
   632 00007386 3C1B                <1> 	cmp	al, 27
   633 00007388 7476                <1> 	je	short loc_set_date_retn
   634 0000738A A2[830E0100]        <1> 	mov	byte [Year+1], al
   635 0000738F 3C30                <1> 	cmp	al, '0'
   636 00007391 0F8220010000        <1>         jb      loc_set_date_stc_7
   637 00007397 3C39                <1> 	cmp	al, '9'
   638 00007399 0F8718010000        <1>         ja      loc_set_date_stc_7
   639                              <1> 	; 13/05/2016
   640                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   641                              <1> 		      ; video page 0 (bh)
   642 0000739F B307                <1> 	mov	bl, 7	
   643 000073A1 E83CA9FFFF          <1> 	call	_write_tty
   644                              <1> loc_set_date_get_lchar_again:
   645 000073A6 28E4                <1> 	sub	ah, ah ; 0
   646 000073A8 E89998FFFF          <1> 	call	int16h
   647                              <1> 	; AL = ASCII Code of the Character
   648 000073AD 3C0D                <1> 	cmp	al, 13 ; ENTER key
   649 000073AF 7412                <1> 	je	short loc_set_date_progress
   650 000073B1 3C1B                <1> 	cmp	al, 27 ; ESC key
   651 000073B3 744B                <1> 	je	short loc_set_date_retn
   652                              <1> 	;
   653 000073B5 E82A010000          <1> 	call	check_for_backspace
   654 000073BA 75EA                <1> 	jne	short loc_set_date_get_lchar_again
   655                              <1> 
   656                              <1> loc_set_date_bs_8:
   657 000073BC E811010000          <1> 	call	write_backspace
   658 000073C1 EBBC                <1> 	jmp	short loc_enter_year_2
   659                              <1> 
   660                              <1> loc_set_date_progress:
   661                              <1> 	; Get Current Date
   662                              <1> 	;mov	ah, 04h
   663                              <1> 	;call	int1Ah
   664 000073C3 E8C9E6FFFF          <1> 	call	RTC_40	; GET RTC DATE
   665                              <1> 	; CH = century (in BCD)
   666                              <1> 
   667 000073C8 66A1[820E0100]      <1> 	mov	ax, [Year]
   668 000073CE 662D3030            <1> 	sub	ax, '00'
   669 000073D2 C0E004              <1> 	shl	al, 4 ; * 16
   670 000073D5 88C1                <1> 	mov	cl, al
   671 000073D7 00E1                <1> 	add	cl, ah
   672 000073D9 66A1[7D0E0100]      <1> 	mov	ax, [Month]
   673 000073DF 662D3030            <1> 	sub	ax, '00'
   674 000073E3 C0E004              <1> 	shl	al, 4 ; * 16
   675 000073E6 88C6                <1> 	mov	dh, al
   676 000073E8 00E6                <1> 	add	dh, ah
   677 000073EA 66A1[7A0E0100]      <1> 	mov	ax, [Day]
   678 000073F0 662D3030            <1> 	sub	ax, '00'
   679 000073F4 C0E004              <1> 	shl	al, 4 ; * 16
   680 000073F7 88C2                <1> 	mov	dl, al
   681 000073F9 00E2                <1> 	add	dl, ah
   682                              <1> 
   683                              <1> 	;mov	ah, 05h
   684                              <1> 	;call	int1Ah
   685 000073FB E8BEE6FFFF          <1> 	call	RTC_50	; SET RTC DATE
   686                              <1> 
   687                              <1> loc_set_date_retn:
   688 00007400 BE[D7190100]        <1> 	mov	esi, nextline
   689 00007405 E893EFFFFF          <1> 	call	print_msg
   690 0000740A C3                  <1> 	retn
   691                              <1> 
   692                              <1> loc_set_date_stc_0:
   693                              <1> 	;xor	bh, bh ; video page 0
   694 0000740B E8B2A9FFFF          <1> 	call	beeper ; BEEP !
   695 00007410 E925FEFFFF          <1>         jmp     loc_enter_day_1
   696                              <1> loc_set_date_stc_1:
   697 00007415 E8CA000000          <1> 	call	check_for_backspace
   698 0000741A 740A                <1> 	je	short loc_set_date_bs_1
   699                              <1> 	;xor	bh, bh ; video page 0
   700 0000741C E8A1A9FFFF          <1> 	call	beeper ; BEEP !
   701 00007421 E947FEFFFF          <1>         jmp     loc_enter_day_2
   702                              <1> loc_set_date_bs_1:
   703 00007426 E8A7000000          <1> 	call	write_backspace
   704 0000742B E90AFEFFFF          <1>         jmp     loc_enter_day_1
   705                              <1> loc_set_date_stc_2:
   706 00007430 E8AF000000          <1> 	call	check_for_backspace
   707 00007435 740A                <1> 	je	short loc_set_date_bs_2
   708                              <1> 	;xor	bh, bh ; video page 0
   709 00007437 E886A9FFFF          <1> 	call	beeper ; BEEP !
   710 0000743C E968FEFFFF          <1>         jmp     loc_enter_separator_1
   711                              <1> loc_set_date_bs_2:
   712 00007441 E88C000000          <1> 	call	write_backspace
   713 00007446 E922FEFFFF          <1>         jmp     loc_enter_day_2
   714                              <1> loc_set_date_stc_3:
   715 0000744B E894000000          <1> 	call	check_for_backspace	
   716 00007450 740A                <1> 	je short loc_set_date_bs_3
   717                              <1> 	;xor	bh, bh ; video page 0
   718 00007452 E86BA9FFFF          <1> 	call	beeper ; BEEP !
   719 00007457 E96FFEFFFF          <1>         jmp     loc_enter_month_1
   720                              <1> loc_set_date_bs_3:
   721 0000745C E871000000          <1> 	call	write_backspace
   722 00007461 E943FEFFFF          <1>         jmp     loc_enter_separator_1
   723                              <1> loc_set_date_stc_4:
   724 00007466 E879000000          <1> 	call	check_for_backspace	
   725 0000746B 740A                <1> 	je	short loc_set_date_bs_4
   726                              <1> 	;xor	bh, bh ; video page 0
   727 0000746D E850A9FFFF          <1> 	call	beeper ; BEEP !
   728 00007472 E97FFEFFFF          <1>         jmp     loc_enter_month_2
   729                              <1> loc_set_date_bs_4:
   730 00007477 E856000000          <1> 	call	write_backspace
   731 0000747C E94AFEFFFF          <1>         jmp     loc_enter_month_1
   732                              <1> loc_set_date_stc_5:
   733 00007481 E85E000000          <1> 	call	check_for_backspace
   734 00007486 740A                <1> 	je	short loc_set_date_bs_5
   735                              <1> 	;xor	bh, bh ; video page 0
   736 00007488 E835A9FFFF          <1> 	call	beeper ; BEEP !
   737 0000748D E9A0FEFFFF          <1>         jmp     loc_enter_separator_2
   738                              <1> loc_set_date_bs_5:
   739 00007492 E83B000000          <1> 	call	write_backspace
   740 00007497 E95AFEFFFF          <1>         jmp     loc_enter_month_2
   741                              <1> loc_set_date_stc_6:
   742 0000749C E843000000          <1> 	call	check_for_backspace
   743 000074A1 740A                <1>         je      short  loc_set_date_bs_6
   744                              <1> 	;xor	bh, bh ; video page 0
   745 000074A3 E81AA9FFFF          <1> 	call	beeper ; BEEP !
   746 000074A8 E9A7FEFFFF          <1>         jmp     loc_enter_year_1
   747                              <1> loc_set_date_bs_6:
   748 000074AD E820000000          <1> 	call	write_backspace
   749 000074B2 E97BFEFFFF          <1>         jmp     loc_enter_separator_2
   750                              <1> loc_set_date_stc_7:
   751 000074B7 E828000000          <1> 	call	check_for_backspace
   752 000074BC 740A                <1> 	je	short loc_set_date_bs_7
   753                              <1> 	;xor	bh, bh ; video page 0
   754 000074BE E8FFA8FFFF          <1> 	call	beeper ; BEEP !
   755 000074C3 E9B7FEFFFF          <1>         jmp     loc_enter_year_2
   756                              <1> loc_set_date_bs_7:
   757 000074C8 E805000000          <1> 	call	write_backspace
   758 000074CD E982FEFFFF          <1>         jmp     loc_enter_year_1
   759                              <1> 
   760                              <1> write_backspace:
   761                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   762 000074D2 B008                <1> 	mov	al, 08h ; BACKSPACE
   763                              <1> 	; 13/05/2016
   764 000074D4 66BB0700            <1> 	mov	bx, 7 ; bl = attribute/color
   765                              <1> 		      ; bh = video page = 0	
   766 000074D8 E805A8FFFF          <1> 	call	_write_tty
   767 000074DD B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
   768                              <1> 	;mov	bx, 7 ; attribute/color
   769                              <1> 	;call	_write_c_current
   770                              <1> 	;retn
   771 000074DF E985A7FFFF          <1> 	jmp	_write_c_current
   772                              <1> 
   773                              <1> check_for_backspace:
   774                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   775 000074E4 663D080E            <1> 	cmp	ax, 0E08h
   776 000074E8 7410                <1> 	je	short cfbs_retn
   777 000074EA 663DE04B            <1> 	cmp	ax, 4BE0h
   778 000074EE 740A                <1> 	je	short cfbs_retn
   779 000074F0 663D004B            <1> 	cmp	ax, 4B00h
   780 000074F4 7404                <1> 	je	short cfbs_retn
   781 000074F6 663DE053            <1> 	cmp	ax, 53E0h
   782                              <1> cfbs_retn:
   783 000074FA C3                  <1> 	retn
   784                              <1> 
   785                              <1> show_time:
   786                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   787                              <1>         ; 2004-2005
   788                              <1> 
   789                              <1> 	;mov	ah, 02h
   790                              <1> 	;call	int1Ah
   791 000074FB E820E5FFFF          <1> 	call	RTC_20	; GET RTC TIME
   792                              <1> 	
   793 00007500 88E8                <1> 	mov	al, ch
   794 00007502 E83697FFFF          <1> 	call	bcd_to_ascii
   795 00007507 66A3[A80E0100]      <1> 	mov	[Hour], ax
   796                              <1> 
   797 0000750D 88C8                <1> 	mov	al, cl
   798 0000750F E82997FFFF          <1> 	call	bcd_to_ascii
   799 00007514 66A3[AB0E0100]      <1> 	mov	[Minute], ax
   800                              <1> 
   801 0000751A 88F0                <1> 	mov	al, dh
   802 0000751C E81C97FFFF          <1> 	call	bcd_to_ascii
   803 00007521 66A3[AE0E0100]      <1> 	mov	[Second], ax
   804                              <1> 
   805 00007527 BE[980E0100]        <1> 	mov	esi, Msg_Show_Time
   806 0000752C E86CEEFFFF          <1> 	call	print_msg
   807 00007531 C3                  <1> 	retn
   808                              <1> 
   809                              <1> set_time:
   810                              <1> 	; 13/05/2016
   811                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   812                              <1>         ; 2004-2005
   813                              <1> 
   814 00007532 BE[870E0100]        <1> 	mov 	esi, Msg_Enter_Time
   815 00007537 E861EEFFFF          <1> 	call	print_msg
   816                              <1> 
   817                              <1> loc_enter_hour_1:
   818 0000753C 30E4                <1> 	xor     ah, ah
   819 0000753E E80397FFFF          <1> 	call	int16h
   820                              <1> 	; AL = ASCII Code of the Character
   821 00007543 3C0D                <1> 	cmp	al, 13 ; ENTER key
   822 00007545 0F84AE010000        <1>         je      loc_set_time_retn
   823 0000754B 3C1B                <1> 	cmp	al, 27 ; ESC key
   824 0000754D 0F84A6010000        <1>         je      loc_set_time_retn
   825 00007553 A2[A80E0100]        <1> 	mov	[Hour], al
   826 00007558 3C30                <1> 	cmp	al, '0'
   827 0000755A 0F82A4010000        <1>         jb      loc_set_time_stc_0
   828 00007560 3C32                <1> 	cmp	al, '2'
   829 00007562 0F879C010000        <1>         ja      loc_set_time_stc_0
   830                              <1> 	; 13/05/2016
   831                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   832                              <1> 		      ; video page 0 (bh)
   833 00007568 B307                <1> 	mov	bl, 7	
   834 0000756A E873A7FFFF          <1> 	call	_write_tty
   835                              <1> loc_enter_hour_2:
   836 0000756F 30E4                <1> 	xor     ah, ah
   837 00007571 E8D096FFFF          <1> 	call	int16h
   838                              <1> 	; AL = ASCII Code of the Character
   839 00007576 3C1B                <1> 	cmp	al, 27
   840 00007578 0F847B010000        <1>         je      loc_set_time_retn
   841 0000757E A2[A90E0100]        <1> 	mov	[Hour+1], al
   842 00007583 3C30                <1> 	cmp	al, '0'
   843 00007585 0F8283010000        <1>         jb      loc_set_time_stc_1
   844 0000758B 3C39                <1> 	cmp	al, '9'
   845 0000758D 0F877B010000        <1> 	ja	loc_set_time_stc_1
   846 00007593 803D[A80E0100]32    <1>         cmp     byte [Hour], '2'
   847 0000759A 7208                <1> 	jb	short pass_set_time_24
   848 0000759C 3C34                <1> 	cmp	al, '4'
   849 0000759E 0F876A010000        <1>         ja      loc_set_time_stc_1
   850                              <1> pass_set_time_24:
   851                              <1> 	; 13/05/2016
   852                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   853                              <1> 		      ; video page 0 (bh)
   854 000075A4 B307                <1> 	mov	bl, 7	
   855 000075A6 E837A7FFFF          <1> 	call	_write_tty
   856                              <1> loc_enter_time_separator_1:
   857 000075AB 28E4                <1> 	sub    ah, ah ; 0
   858 000075AD E89496FFFF          <1> 	call	int16h
   859                              <1> 	; AL = ASCII Code of the Character
   860 000075B2 3C1B                <1> 	cmp	al, 27
   861 000075B4 0F843F010000        <1>         je      loc_set_time_retn
   862 000075BA 3C3A                <1> 	cmp	al, ':'
   863 000075BC 0F8567010000        <1>         jne     loc_set_time_stc_2
   864                              <1> 	; 13/05/2016
   865                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   866                              <1> 		      ; video page 0 (bh)
   867 000075C2 B307                <1> 	mov	bl, 7	
   868 000075C4 E819A7FFFF          <1> 	call	_write_tty
   869                              <1> loc_enter_minute_1:
   870 000075C9 30E4                <1> 	xor     ah, ah
   871 000075CB E87696FFFF          <1> 	call	int16h
   872                              <1> 	; AL = ASCII Code of the Character
   873 000075D0 3C1B                <1> 	cmp	al, 27
   874 000075D2 0F8421010000        <1>         je      loc_set_time_retn
   875 000075D8 A2[AB0E0100]        <1> 	mov	[Minute], al
   876 000075DD 3C30                <1> 	cmp	al, '0'
   877 000075DF 0F825F010000        <1>         jb      loc_set_time_stc_3
   878 000075E5 3C35                <1> 	cmp	al, '5'
   879 000075E7 0F8757010000        <1>         ja      loc_set_time_stc_3
   880                              <1> 	; 13/05/2016
   881                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   882                              <1> 		      ; video page 0 (bh)
   883 000075ED B307                <1> 	mov	bl, 7	
   884 000075EF E8EEA6FFFF          <1> 	call	_write_tty
   885                              <1> loc_enter_minute_2:
   886 000075F4 30E4                <1> 	xor     ah, ah
   887 000075F6 E84B96FFFF          <1> 	call	int16h
   888                              <1> 	; AL = ASCII Code of the Character
   889 000075FB 3C1B                <1> 	cmp	al, 27
   890 000075FD 0F84F6000000        <1>         je      loc_set_time_retn
   891 00007603 A2[AC0E0100]        <1> 	mov	[Minute+1], al
   892 00007608 3C30                <1> 	cmp	al, '0'
   893 0000760A 0F824F010000        <1>         jb      loc_set_time_stc_4
   894 00007610 3C39                <1> 	cmp	al, '9'
   895 00007612 0F8747010000        <1>         ja      loc_set_time_stc_4
   896                              <1> 	; 13/05/2016
   897                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   898                              <1> 		      ; video page 0 (bh)
   899 00007618 B307                <1> 	mov	bl, 7	
   900 0000761A E8C3A6FFFF          <1> 	call	_write_tty
   901                              <1> loc_enter_time_separator_2:
   902 0000761F 66C705[AE0E0100]30- <1> 	mov	word [Second], 3030h
   902 00007627 30                  <1>
   903 00007628 28E4                <1> 	sub     ah, ah
   904 0000762A E81796FFFF          <1> 	call	int16h
   905                              <1> 	; AL = ASCII Code of the Character
   906 0000762F 3C0D                <1> 	cmp	al, 13
   907 00007631 0F8485000000        <1>         je      loc_set_time_progress
   908 00007637 3C1B                <1> 	cmp	al, 27
   909 00007639 0F84BA000000        <1>         je      loc_set_time_retn
   910 0000763F 3C3A                <1> 	cmp	al, ':'
   911 00007641 0F8533010000        <1>         jne     loc_set_time_stc_5
   912                              <1> 	; 13/05/2016
   913                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   914                              <1> 		      ; video page 0 (bh)
   915 00007647 B307                <1> 	mov	bl, 7	
   916 00007649 E894A6FFFF          <1> 	call	_write_tty
   917                              <1> loc_enter_second_1:
   918 0000764E 30E4                <1> 	xor     ah, ah
   919 00007650 E8F195FFFF          <1> 	call	int16h
   920                              <1> 	; AL = ASCII Code of the Character
   921 00007655 3C0D                <1> 	cmp	al, 13
   922 00007657 7463                <1> 	je	short loc_set_time_progress
   923 00007659 3C1B                <1> 	cmp	al, 27
   924 0000765B 0F8498000000        <1>         je      loc_set_time_retn
   925 00007661 A2[AE0E0100]        <1> 	mov	[Second], al
   926 00007666 3C30                <1> 	cmp	al, '0'
   927 00007668 0F8227010000        <1>         jb      loc_set_time_stc_6
   928 0000766E 3C35                <1> 	cmp	al, '5'
   929 00007670 0F871F010000        <1>         ja      loc_set_time_stc_6
   930                              <1> 	; 13/05/2016
   931                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   932                              <1> 		      ; video page 0 (bh)
   933 00007676 B307                <1> 	mov	bl, 7	
   934 00007678 E865A6FFFF          <1> 	call	_write_tty
   935                              <1> loc_enter_second_2:
   936 0000767D 30E4                <1> 	xor     ah, ah
   937 0000767F E8C295FFFF          <1> 	call	int16h
   938                              <1> 	; AL = ASCII Code of the Character
   939 00007684 3C1B                <1> 	cmp	al, 27
   940 00007686 7471                <1> 	je	short loc_set_time_retn
   941 00007688 3C30                <1> 	cmp	al, '0'
   942 0000768A 0F8229010000        <1>         jb      loc_set_time_stc_7
   943 00007690 3C39                <1> 	cmp	al, '9'
   944 00007692 0F8721010000        <1>         ja      loc_set_time_stc_7
   945                              <1> 	; 13/05/2016
   946                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   947                              <1> 		      ; video page 0 (bh)
   948 00007698 B307                <1> 	mov	bl, 7	
   949 0000769A E843A6FFFF          <1> 	call	_write_tty
   950                              <1> loc_set_time_get_lchar_again:
   951 0000769F 28E4                <1> 	sub	ah, ah ; 0
   952 000076A1 E8A095FFFF          <1> 	call	int16h
   953                              <1> 	; AL = ASCII Code of the Character
   954 000076A6 3C0D                <1> 	cmp	al, 13
   955 000076A8 7412                <1> 	je	short loc_set_time_progress
   956 000076AA 3C1B                <1> 	cmp	al, 27
   957 000076AC 744B                <1> 	je	short loc_set_time_retn
   958                              <1> 	;
   959 000076AE E831FEFFFF          <1> 	call	check_for_backspace
   960 000076B3 75EA                <1> 	jne	short loc_set_time_get_lchar_again
   961                              <1> 
   962                              <1> loc_set_time_bs_8:
   963 000076B5 E818FEFFFF          <1> 	call	write_backspace
   964 000076BA EBC1                <1> 	jmp	short loc_enter_second_2
   965                              <1> 
   966                              <1> loc_set_time_progress:
   967                              <1> 	; Get Current Time
   968                              <1> 	;mov 	ah, 02h
   969                              <1> 	;call	int1Ah
   970 000076BC E85FE3FFFF          <1> 	call	RTC_20	; GET RTC TIME
   971                              <1> 	;DL = Daylight Savings Enable option (0-1)	
   972                              <1> 
   973 000076C1 66A1[A80E0100]      <1> 	mov	ax, [Hour]
   974 000076C7 662D3030            <1> 	sub	ax, '00'
   975 000076CB C0E004              <1> 	shl	al, 4 ; * 16
   976 000076CE 88C5                <1> 	mov	ch, al
   977 000076D0 00E5                <1> 	add	ch, ah
   978 000076D2 66A1[AB0E0100]      <1> 	mov	ax, [Minute]
   979 000076D8 662D3030            <1> 	sub	ax, '00'
   980 000076DC C0E004              <1> 	shl	al, 4 ; * 16
   981 000076DF 88C1                <1> 	mov	cl, al
   982 000076E1 00E1                <1> 	add	cl, ah
   983 000076E3 66A1[AE0E0100]      <1> 	mov	ax, [Second]
   984 000076E9 662D3030            <1> 	sub	ax, '00'
   985 000076ED C0E004              <1> 	shl	al, 4 ; * 16
   986 000076F0 88C6                <1> 	mov	dh, al
   987 000076F2 00E6                <1> 	add	dh, ah
   988                              <1> 	
   989                              <1> 	;mov	ah, 03h
   990                              <1> 	;call	int1Ah
   991 000076F4 E856E3FFFF          <1> 	call	RTC_30	; SET RTC TIME
   992                              <1> 
   993                              <1> loc_set_time_retn:
   994 000076F9 BE[D7190100]        <1> 	mov 	esi, nextline
   995 000076FE E89AECFFFF          <1> 	call	print_msg
   996 00007703 C3                  <1> 	retn
   997                              <1> 
   998                              <1> loc_set_time_stc_0:
   999                              <1> 	;xor	bh, bh ; video page 0
  1000 00007704 E8B9A6FFFF          <1> 	call	beeper ; BEEP !
  1001 00007709 E92EFEFFFF          <1>         jmp     loc_enter_hour_1
  1002                              <1> loc_set_time_stc_1:
  1003 0000770E E8D1FDFFFF          <1> 	call	check_for_backspace
  1004 00007713 740A                <1> 	je	short loc_set_time_bs_1
  1005                              <1> 	;xor	bh, bh ; video page 0
  1006 00007715 E8A8A6FFFF          <1> 	call	beeper ; BEEP !
  1007 0000771A E950FEFFFF          <1>         jmp     loc_enter_hour_2
  1008                              <1> loc_set_time_bs_1:
  1009 0000771F E8AEFDFFFF          <1> 	call	write_backspace
  1010 00007724 E913FEFFFF          <1>         jmp     loc_enter_hour_1
  1011                              <1> loc_set_time_stc_2:
  1012 00007729 E8B6FDFFFF          <1> 	call	check_for_backspace
  1013 0000772E 740A                <1> 	je	short loc_set_time_bs_2
  1014                              <1> 	;xor	bh, bh ; video page 0
  1015 00007730 E88DA6FFFF          <1> 	call	beeper ; BEEP !
  1016 00007735 E971FEFFFF          <1>         jmp     loc_enter_time_separator_1
  1017                              <1> loc_set_time_bs_2:
  1018 0000773A E893FDFFFF          <1> 	call	write_backspace
  1019 0000773F E92BFEFFFF          <1>         jmp     loc_enter_hour_2
  1020                              <1> loc_set_time_stc_3:
  1021 00007744 E89BFDFFFF          <1> 	call	check_for_backspace
  1022 00007749 740A                <1> 	je	short loc_set_time_bs_3
  1023                              <1> 	;xor	bh, bh ; video page 0
  1024 0000774B E872A6FFFF          <1> 	call	beeper ; BEEP !6
  1025 00007750 E974FEFFFF          <1>         jmp     loc_enter_minute_1
  1026                              <1> loc_set_time_bs_3:
  1027 00007755 E878FDFFFF          <1> 	call	write_backspace
  1028 0000775A E94CFEFFFF          <1>         jmp     loc_enter_time_separator_1
  1029                              <1> loc_set_time_stc_4:
  1030 0000775F E880FDFFFF          <1> 	call	check_for_backspace
  1031 00007764 740A                <1> 	je	short loc_set_time_bs_4
  1032                              <1> 	;xor	bh, bh ; video page 0
  1033 00007766 E857A6FFFF          <1> 	call	beeper ; BEEP !
  1034 0000776B E984FEFFFF          <1>         jmp     loc_enter_minute_2
  1035                              <1> loc_set_time_bs_4:
  1036 00007770 E85DFDFFFF          <1> 	call	write_backspace
  1037 00007775 E94FFEFFFF          <1>         jmp     loc_enter_minute_1
  1038                              <1> loc_set_time_stc_5:
  1039 0000777A E865FDFFFF          <1> 	call	check_for_backspace
  1040 0000777F 740A                <1> 	je	short loc_set_time_bs_5
  1041                              <1> 	;xor	bh, bh ; video page 0
  1042 00007781 E83CA6FFFF          <1> 	call	beeper ; BEEP !
  1043 00007786 E994FEFFFF          <1>         jmp     loc_enter_time_separator_2
  1044                              <1> loc_set_time_bs_5:
  1045 0000778B E842FDFFFF          <1> 	call	write_backspace
  1046 00007790 E95FFEFFFF          <1>         jmp     loc_enter_minute_2
  1047                              <1> loc_set_time_stc_6:
  1048 00007795 E84AFDFFFF          <1> 	call	check_for_backspace
  1049 0000779A 7413                <1> 	je	short loc_set_time_bs_6
  1050                              <1> 	;xor	bh, bh ; video page 0
  1051 0000779C E821A6FFFF          <1> 	call	beeper ; BEEP !
  1052 000077A1 66C705[AE0E0100]30- <1> 	mov	word [Second], 3030h
  1052 000077A9 30                  <1>
  1053 000077AA E99FFEFFFF          <1>         jmp     loc_enter_second_1
  1054                              <1> loc_set_time_bs_6:
  1055 000077AF E81EFDFFFF          <1> 	call	write_backspace
  1056 000077B4 E966FEFFFF          <1>         jmp     loc_enter_time_separator_2
  1057                              <1> loc_set_time_stc_7:
  1058 000077B9 E826FDFFFF          <1> 	call	check_for_backspace
  1059 000077BE 740A                <1> 	je	short loc_set_time_bs_7
  1060                              <1> 	;xor	bh, bh ; video page 0
  1061 000077C0 E8FDA5FFFF          <1> 	call	beeper ; BEEP !
  1062 000077C5 E9B3FEFFFF          <1>         jmp     loc_enter_second_2
  1063                              <1> loc_set_time_bs_7:
  1064 000077CA E803FDFFFF          <1> 	call	write_backspace
  1065 000077CF E97AFEFFFF          <1>         jmp     loc_enter_second_1
  1066                              <1> 
  1067                              <1> print_volume_info:
  1068                              <1> 	; 01/03/2016
  1069                              <1> 	; 08/02/2016
  1070                              <1> 	; 06/02/2016
  1071                              <1> 	; 04/02/2016
  1072                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
  1073                              <1> 	; 25/10/2009
  1074                              <1> 	;
  1075                              <1> 	; "Volume Serial No: "
  1076                              <1>  	;
  1077                              <1> 	; INPUT  : AL = DOS Drive Number
  1078                              <1> 	; OUTPUT : AH = FS Type
  1079                              <1> 	;          AL = DOS Drive Name
  1080                              <1> 	; CF = 0 -> OK
  1081                              <1> 	; CF = 1 -> Drive not ready 
  1082                              <1> 
  1083 000077D4 88C4                <1> 	mov	ah, al
  1084 000077D6 28C0                <1> 	sub	al, al
  1085 000077D8 0FB7F0              <1> 	movzx	esi, ax	
  1086 000077DB 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1087 000077E1 8A06                <1> 	mov	al, [esi]
  1088 000077E3 3C41                <1> 	cmp	al, 'A'  
  1089 000077E5 7304                <1> 	jnb	short loc_pvi_set_vol_name
  1090 000077E7 8A6604              <1> 	mov	ah, [esi+LD_FSType]
  1091 000077EA C3                  <1> 	retn
  1092                              <1> 
  1093                              <1> loc_pvi_set_vol_name:
  1094 000077EB A2[E20E0100]        <1> 	mov	[Vol_Drv_Name], al
  1095 000077F0 56                  <1> 	push	esi
  1096 000077F1 E858010000          <1> 	call	move_volume_name_and_serial_no ;;;
  1097 000077F6 7302                <1> 	jnc	short loc_pvi_mvn_ok
  1098 000077F8 5E                  <1> 	pop	esi
  1099 000077F9 C3                  <1> 	retn
  1100                              <1> 
  1101                              <1> loc_pvi_mvn_ok:
  1102 000077FA 8B3424              <1> 	mov	esi, [esp]
  1103 000077FD 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1104 00007801 7509                <1> 	jne	short loc_pvi_fat_vol_size
  1105 00007803 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
  1106 00007806 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1107 0000780A EB07                <1> 	jmp	short loc_vol_size_mul32
  1108                              <1> loc_pvi_fat_vol_size:
  1109 0000780C 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
  1110 0000780F 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1111                              <1> loc_vol_size_mul32:
  1112 00007813 F7E3                <1> 	mul	ebx
  1113 00007815 09D2                <1> 	or	edx, edx
  1114 00007817 7507                <1> 	jnz	short loc_vol_size_in_kbytes
  1115                              <1> loc_vol_size_in_bytes:
  1116 00007819 B9[C00E0100]        <1> 	mov	ecx, VolSize_Bytes
  1117 0000781E EB0D                <1> 	jmp	short loc_write_vol_size_str
  1118                              <1> loc_vol_size_in_kbytes:
  1119 00007820 66BB0004            <1> 	mov	bx, 1024
  1120 00007824 F7F3                <1> 	div	ebx
  1121 00007826 B9[B30E0100]        <1> 	mov 	ecx, VolSize_KiloBytes
  1122 0000782B 31D2                <1> 	xor	edx, edx ; 0
  1123                              <1> loc_write_vol_size_str:
  1124 0000782D 890D[9B600100]      <1> 	mov	[VolSize_Unit1], ecx
  1125                              <1> 	; 
  1126 00007833 BF[B1600100]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
  1127                              <1>         ;mov	byte [edi], 0
  1128 00007838 B90A000000          <1> 	mov	ecx, 10
  1129                              <1> loc_write_vol_size_chr:
  1130 0000783D F7F1                <1> 	div	ecx
  1131 0000783F 80C230              <1> 	add	dl, '0'
  1132 00007842 4F                  <1> 	dec	edi	
  1133 00007843 8817                <1> 	mov	[edi], dl
  1134 00007845 85C0                <1> 	test	eax, eax
  1135 00007847 7404                <1> 	jz	short loc_write_vol_size_str_ok
  1136 00007849 28D2                <1> 	sub	dl, dl ; 0
  1137 0000784B EBF0                <1> 	jmp	short loc_write_vol_size_chr
  1138                              <1> 
  1139                              <1> loc_write_vol_size_str_ok:
  1140 0000784D 893D[A3600100]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
  1141                              <1> 	;
  1142 00007853 BF[CB0E0100]        <1> 	mov	edi, Vol_FS_Name
  1143 00007858 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
  1144 0000785B 20C9                <1> 	and	cl, cl ; 0 ?
  1145 0000785D 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
  1146 0000785F 66C7075452          <1> 	mov	word [edi], 'TR'
  1147 00007864 C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
  1148                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1149 0000786B 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
  1150 0000786F 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
  1151 00007872 EB36                <1> 	jmp	short loc_vol_freespace_mul32
  1152                              <1> 
  1153                              <1> loc_write_vol_FAT_str_1:
  1154 00007874 66B83332            <1> 	mov	ax, '32' ; FAT32
  1155 00007878 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
  1156 0000787B 7708                <1> 	ja	short loc_write_vol_FAT_str_2
  1157 0000787D 66B83132            <1> 	mov	ax, '12' ; FAT12
  1158 00007881 7202                <1> 	jb	short loc_write_vol_FAT_str_2
  1159 00007883 B436                <1> 	mov	ah, '6'  ; FAT16
  1160                              <1> loc_write_vol_FAT_str_2:
  1161 00007885 C70746415420        <1> 	mov	dword [edi], 'FAT '
  1162 0000788B 66894704            <1> 	mov	word [edi+4], ax
  1163                              <1> 	;
  1164                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1165 0000788F 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
  1166 00007893 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1167                              <1> 
  1168                              <1> loc_vol_freespace_recalc0:
  1169                              <1> 	; 01/03/2016
  1170 00007896 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  1171 00007899 720F                <1> 	jb	short loc_vol_freespace_mul32
  1172                              <1> 	;inc	eax ; 0
  1173 0000789B 20C9                <1> 	and	cl, cl ; byte [esi+LD_FATType]
  1174 0000789D 740B                <1> 	jz	short loc_vol_freespace_mul32 	
  1175 0000789F 53                  <1> 	push	ebx
  1176 000078A0 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free sectors
  1177 000078A4 E876490000          <1> 	call	calculate_fat_freespace
  1178 000078A9 5B                  <1> 	pop	ebx
  1179                              <1> 
  1180                              <1> loc_vol_freespace_mul32:
  1181 000078AA F7E3                <1> 	mul	ebx
  1182 000078AC 09D2                <1> 	or	edx, edx
  1183 000078AE 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
  1184                              <1> loc_vol_fspace_in_bytes:
  1185 000078B0 B9[C00E0100]        <1> 	mov	ecx, VolSize_Bytes
  1186 000078B5 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
  1187                              <1> loc_vol_fspace_in_kbytes:
  1188 000078B7 66BB0004            <1> 	mov	bx, 1024
  1189 000078BB F7F3                <1> 	div	ebx
  1190 000078BD B9[B30E0100]        <1> 	mov 	ecx, VolSize_KiloBytes
  1191 000078C2 31D2                <1> 	xor	edx, edx ; 0
  1192                              <1> loc_write_vol_fspace_str:
  1193 000078C4 890D[9F600100]      <1> 	mov	[VolSize_Unit2], ecx
  1194                              <1> 	;	
  1195 000078CA BF[C1600100]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
  1196                              <1>         ;mov	byte [edi], 0
  1197 000078CF B90A000000          <1> 	mov	ecx, 10
  1198                              <1> loc_write_vol_fspace_chr:
  1199 000078D4 F7F1                <1> 	div	ecx
  1200 000078D6 80C230              <1> 	add	dl, '0'
  1201 000078D9 4F                  <1> 	dec	edi	
  1202 000078DA 8817                <1> 	mov	[edi], dl
  1203 000078DC 85C0                <1> 	test	eax, eax
  1204 000078DE 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
  1205 000078E0 28D2                <1> 	sub	dl, dl ; 0
  1206 000078E2 EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
  1207                              <1> 
  1208                              <1> loc_write_vol_fspace_str_ok:
  1209 000078E4 893D[B3600100]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
  1210                              <1> 	;
  1211 000078EA BE[C90E0100]        <1> 	mov	esi, Volume_in_drive
  1212 000078EF E8A9EAFFFF          <1> 	call	print_msg
  1213 000078F4 BE[090F0100]        <1> 	mov	esi, Vol_Name
  1214 000078F9 E89FEAFFFF          <1> 	call	print_msg
  1215 000078FE BE[D7190100]        <1> 	mov	esi, nextline
  1216 00007903 E895EAFFFF          <1> 	call	print_msg
  1217                              <1> 	;
  1218 00007908 BE[6A0F0100]        <1> 	mov	esi, Vol_Total_Sector_Header
  1219 0000790D E88BEAFFFF          <1> 	call	print_msg
  1220 00007912 8B35[A3600100]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
  1221 00007918 E880EAFFFF          <1> 	call	print_msg
  1222 0000791D 8B35[9B600100]      <1> 	mov	esi, [VolSize_Unit1]
  1223 00007923 E875EAFFFF          <1> 	call	print_msg
  1224                              <1> 	;
  1225 00007928 BE[7B0F0100]        <1> 	mov	esi, Vol_Free_Sectors_Header
  1226 0000792D E86BEAFFFF          <1> 	call	print_msg
  1227 00007932 8B35[B3600100]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
  1228 00007938 E860EAFFFF          <1> 	call	print_msg
  1229 0000793D 8B35[9F600100]      <1> 	mov	esi, [VolSize_Unit2]
  1230 00007943 E855EAFFFF          <1> 	call	print_msg
  1231                              <1> 	;
  1232 00007948 5E                  <1> 	pop	esi
  1233                              <1> 	
  1234                              <1> 	;mov	ah, [esi+LD_FSType]
  1235                              <1> 	;mov	al, [esi+LD_FATType]
  1236 00007949 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1237                              <1> 
  1238 0000794D C3                  <1> 	retn
  1239                              <1> 
  1240                              <1> move_volume_name_and_serial_no:
  1241                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
  1242                              <1> 	; this routine will be called by
  1243                              <1> 	; "print_volume_info" and "print_directory"
  1244                              <1> 	; INPUT ->
  1245                              <1> 	;	ESI = Logical DOS drv descripton table address
  1246                              <1> 	; OUTPUT ->
  1247                              <1> 	;	*Volume name will be moved to text area
  1248                              <1> 	;	*Volume serial number will be converted to
  1249                              <1> 	;	 text and will be moved to text area
  1250                              <1> 	;   cf = 1 -> invalid/unknown dos drive
  1251                              <1> 	;   cf = 0 -> ecx = 0
  1252                              <1> 	;
  1253                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
  1254                              <1> 
  1255 0000794E BF[090F0100]        <1> 	mov 	edi, Vol_Name
  1256                              <1> 
  1257                              <1> 	;mov	ah, [esi+LD_FSType]
  1258                              <1> 	;mov	al, [esi+LD_FATType]
  1259 00007953 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1260 00007957 80FCA1              <1> 	cmp	ah, 0A1h
  1261 0000795A 7418                <1> 	je	short mvn_2
  1262 0000795C 08E4                <1> 	or	ah, ah
  1263 0000795E 7404                <1> 	jz	short mvn_0
  1264 00007960 08C0                <1> 	or	al, al
  1265 00007962 7504                <1> 	jnz	short mvn_1
  1266                              <1> mvn_0:
  1267 00007964 8A06                <1> 	mov	al, [esi]
  1268 00007966 F9                  <1> 	stc
  1269 00007967 C3                  <1> 	retn
  1270                              <1> mvn_1:
  1271 00007968 3C02                <1> 	cmp	al, 2
  1272 0000796A 7717                <1> 	ja	short mvn_3 
  1273                              <1> 	;or	al, al
  1274                              <1> 	;jz	short mvn_2
  1275 0000796C 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
  1276 0000796F 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
  1277 00007972 EB15                <1> 	jmp	short mvn_4
  1278                              <1> mvn_2:
  1279 00007974 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
  1280 00007977 83C62C              <1> 	add	esi, LD_FS_VolumeName
  1281 0000797A B910000000          <1> 	mov	ecx, 16
  1282 0000797F F3A5                <1> 	rep	movsd
  1283 00007981 EB10                <1> 	jmp	short mvn_5
  1284                              <1> mvn_3:
  1285 00007983 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
  1286 00007986 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
  1287                              <1> mvn_4:
  1288 00007989 B90B000000          <1> 	mov	ecx, 11
  1289 0000798E F3A4                <1> 	rep	movsb
  1290 00007990 C60700              <1> 	mov	byte [edi], 0
  1291                              <1> mvn_5:
  1292                              <1> 	;mov	[Current_VolSerial], eax  
  1293 00007993 E8A1B9FFFF          <1> 	call	dwordtohex
  1294 00007998 8915[5E0F0100]      <1> 	mov	[Vol_Serial1], edx
  1295 0000799E A3[630F0100]        <1> 	mov	[Vol_Serial2], eax
  1296                              <1> 	; ecx = 0
  1297 000079A3 C3                  <1> 	retn
  1298                              <1> 
  1299                              <1> get_volume_serial_number:
  1300                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
  1301                              <1> 	; 08/08/2010
  1302                              <1> 	;
  1303                              <1> 	; INPUT -> DL = Logical DOS Drive number
  1304                              <1> 	; OUTPUT -> EAX = Volume serial number
  1305                              <1> 	;          BL= FAT Type	    
  1306                              <1> 	;          BH = Logical DOS drv Number (DL input)
  1307                              <1> 	; cf = 1 -> Drive not ready
  1308                              <1> 
  1309 000079A4 31DB                <1> 	xor	ebx, ebx
  1310 000079A6 88D7                <1> 	mov	bh, dl
  1311 000079A8 3815[3A0D0100]      <1> 	cmp	[Last_DOS_DiskNo], dl
  1312 000079AE 7304                <1> 	jnb	short loc_gvsn_start
  1313                              <1> loc_gvsn_stc_retn:
  1314 000079B0 31C0                <1> 	xor	eax, eax
  1315 000079B2 F9                  <1> 	stc 
  1316 000079B3 C3                  <1>         retn 
  1317                              <1> loc_gvsn_start:
  1318 000079B4 56                  <1> 	push	esi
  1319 000079B5 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1320 000079BA 01DE                <1> 	add	esi, ebx
  1321 000079BC 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
  1322 000079BF 20DB                <1> 	and	bl, bl
  1323 000079C1 740F                <1> 	jz	short loc_gvsn_fs
  1324 000079C3 80FB02              <1> 	cmp	bl, 2
  1325 000079C6 7705                <1> 	ja	short loc_gvsn_fat32
  1326                              <1> loc_gvsn_fat:
  1327 000079C8 83C62D              <1> 	add	esi, LD_BPB + VolumeID
  1328 000079CB EB0E                <1> 	jmp	short loc_gvsn_return
  1329                              <1> loc_gvsn_fat32: 
  1330 000079CD 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
  1331 000079D0 EB09                <1> 	jmp	short loc_gvsn_return 
  1332                              <1> loc_gvsn_fs:
  1333 000079D2 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1334 000079D6 75D8                <1> 	jne	short loc_gvsn_stc_retn 
  1335 000079D8 83C628              <1> 	add	esi, LD_FS_VolumeSerial
  1336                              <1> loc_gvsn_return:
  1337 000079DB 8B06                <1> 	mov	eax, [esi]
  1338 000079DD 5E                  <1> 	pop	esi
  1339 000079DE C3                  <1> 	retn
  1340                              <1> 
  1341                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
  1342                              <1> ; 09/11/2011
  1343                              <1> ; 29/01/2005
  1344                              <1> 
  1345                              <1> command_interpreter:
  1346                              <1> 	; 16/10/2016
  1347                              <1> 	; 12/10/2016
  1348                              <1> 	; 13/05/2016
  1349                              <1> 	; 07/05/2016
  1350                              <1> 	; 04/03/2016
  1351                              <1> 	; 04/02/2016
  1352                              <1> 	; 03/02/2016
  1353                              <1> 	; 30/01/2016
  1354                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
  1355                              <1> 	; 15/09/2011         
  1356                              <1> 	; 29/01/2005
  1357                              <1>         
  1358                              <1> 	; Input: ecx = command word length (CL)
  1359                              <1> 	;	 CommandBuffer = Command string offset
  1360                              <1>  
  1361 000079DF C605[54610100]00    <1> 	mov	byte [Program_Exit],0
  1362 000079E6 80F904              <1> 	cmp	cl, 4
  1363 000079E9 0F87B5020000        <1>         ja      c_6
  1364 000079EF 0F8237010000        <1>         jb      c_2
  1365                              <1> c_4:
  1366                              <1> 
  1367                              <1> cmp_cmd_exit:
  1368 000079F5 BF[A80D0100]        <1> 	mov	edi, Cmd_Exit
  1369 000079FA E8C2030000          <1> 	call	cmp_cmd	
  1370 000079FF 7208                <1> 	jc	short cmp_cmd_date
  1371                              <1> 
  1372 00007A01 C605[54610100]01    <1>         mov     byte [Program_Exit], 1
  1373 00007A08 C3                  <1>         retn
  1374                              <1> 
  1375                              <1> cmp_cmd_date:
  1376 00007A09 B104                <1> 	mov	cl, 4
  1377 00007A0B BF[C40D0100]        <1> 	mov	edi, Cmd_Date
  1378 00007A10 E8AC030000          <1> 	call	cmp_cmd	
  1379 00007A15 720B                <1>         jc	short cmp_cmd_time
  1380                              <1> 	
  1381 00007A17 E8D0F7FFFF          <1> 	call	show_date
  1382 00007A1C E80FF8FFFF          <1> 	call	set_date
  1383 00007A21 C3                  <1> 	retn
  1384                              <1> 
  1385                              <1> cmp_cmd_time:
  1386 00007A22 B104                <1> 	mov	cl, 4
  1387 00007A24 BF[C90D0100]        <1> 	mov	edi, Cmd_Time
  1388 00007A29 E893030000          <1>    	call	cmp_cmd	
  1389 00007A2E 720B                <1> 	jc	short cmp_cmd_show
  1390                              <1> 
  1391 00007A30 E8C6FAFFFF          <1> 	call	show_time
  1392 00007A35 E8F8FAFFFF          <1> 	call	set_time
  1393 00007A3A C3                  <1> 	retn
  1394                              <1> 
  1395                              <1> cmp_cmd_show:
  1396 00007A3B B104                <1> 	mov	cl, 4
  1397 00007A3D BF[DA0D0100]        <1> 	mov	edi, Cmd_Show
  1398 00007A42 E87A030000          <1>    	call	cmp_cmd	
  1399 00007A47 0F83050A0000        <1>         jnc     show_file
  1400                              <1> 
  1401                              <1> cmp_cmd_echo:
  1402 00007A4D B104                <1> 	mov	cl, 4
  1403 00007A4F BF[160E0100]        <1> 	mov	edi, Cmd_Echo
  1404 00007A54 E868030000          <1>    	call	cmp_cmd	
  1405 00007A59 7224                <1> 	jc	short cmp_cmd_copy
  1406                              <1> 	
  1407                              <1> 	; 22/11/2017
  1408                              <1> 	; AL = 0
  1409 00007A5B 803E20              <1> 	cmp	byte [esi], 20h
  1410 00007A5E 7215                <1> 	jb	short cmd_echo_nextline
  1411                              <1> 	; 14/04/2016
  1412 00007A60 56                  <1> 	push	esi
  1413                              <1> cmd_echo_asciiz:
  1414                              <1> 	;inc	esi
  1415                              <1> 	;mov	al, [esi]
  1416                              <1> 	; 22/11/2017
  1417 00007A61 AC                  <1> 	lodsb
  1418 00007A62 3C20                <1> 	cmp	al, 20h
  1419 00007A64 73FB                <1> 	jnb	short cmd_echo_asciiz
  1420 00007A66 4E                  <1> 	dec	esi
  1421 00007A67 C60600              <1> 	mov	byte [esi], 0
  1422 00007A6A 5E                  <1> 	pop	esi
  1423 00007A6B 89F7                <1> 	mov	edi, esi
  1424 00007A6D E82BE9FFFF          <1> 	call	print_msg
  1425 00007A72 C60700              <1> 	mov	byte [edi], 0	
  1426                              <1> cmd_echo_nextline:
  1427 00007A75 BE[201A0100]        <1> 	mov	esi, NextLine
  1428                              <1> 	;call	print_msg   
  1429                              <1> 	;retn
  1430 00007A7A E91EE9FFFF          <1> 	jmp	print_msg
  1431                              <1> 
  1432                              <1> cmp_cmd_copy:
  1433 00007A7F B104                <1> 	mov	cl, 4
  1434 00007A81 BF[FD0D0100]        <1> 	mov	edi, Cmd_Copy
  1435 00007A86 E836030000          <1>    	call	cmp_cmd	
  1436 00007A8B 0F83CC170000        <1> 	jnc	copy_file
  1437                              <1> 
  1438                              <1> cmp_cmd_move:
  1439 00007A91 B104                <1> 	mov	cl, 4
  1440 00007A93 BF[020E0100]        <1> 	mov	edi, Cmd_Move
  1441 00007A98 E824030000          <1>    	call	cmp_cmd	
  1442 00007A9D 0F836E160000        <1> 	jnc	move_file
  1443                              <1> 
  1444                              <1> cmp_cmd_path:
  1445 00007AA3 B104                <1> 	mov	cl, 4
  1446 00007AA5 BF[070E0100]        <1> 	mov	edi, Cmd_Path
  1447 00007AAA E812030000          <1>    	call	cmp_cmd	
  1448 00007AAF 0F83F0190000        <1> 	jnc	set_get_path
  1449                              <1> 
  1450                              <1> cmp_cmd_beep:
  1451 00007AB5 B104                <1> 	mov	cl, 4
  1452 00007AB7 BF[340E0100]        <1> 	mov	edi, Cmd_Beep
  1453 00007ABC E800030000          <1>    	call	cmp_cmd	
  1454 00007AC1 720B                <1> 	jc	short cmp_cmd_find
  1455                              <1> 	; 13/05/2016
  1456 00007AC3 8A3D[D6580100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  1457 00007AC9 E9F4A2FFFF          <1> 	jmp	beeper
  1458                              <1> 
  1459                              <1> cmp_cmd_find:
  1460 00007ACE B104                <1> 	mov	cl, 4
  1461 00007AD0 BF[110E0100]        <1> 	mov	edi, Cmd_Find
  1462 00007AD5 E8E7020000          <1>    	call	cmp_cmd	
  1463 00007ADA 0F82C4020000        <1>         jc      cmp_cmd_external
  1464                              <1> 
  1465                              <1> 	;call	find_and_list_files
  1466 00007AE0 E9AF220000          <1> 	jmp	find_and_list_files
  1467                              <1> 	;retn
  1468                              <1> 
  1469                              <1> c_1:
  1470 00007AE5 AD                  <1> 	lodsd
  1471                              <1> cmp_cmd_help:
  1472 00007AE6 3C3F                <1> 	cmp	al, '?'
  1473 00007AE8 751D                <1>         jne     short cmp_cmd_remark
  1474                              <1> 
  1475 00007AEA BE[9A0D0100]        <1> 	mov	esi, Command_List
  1476                              <1> cmd_help_next_w:
  1477 00007AEF E8A9E8FFFF          <1> 	call	print_msg
  1478                              <1> 
  1479 00007AF4 803E20              <1> 	cmp	byte [esi], 20h ; 0
  1480 00007AF7 7232                <1> 	jb	short cmd_help_retn
  1481                              <1> 	
  1482 00007AF9 56                  <1> 	push	esi
  1483 00007AFA BE[D7190100]        <1> 	mov	esi, nextline
  1484 00007AFF E899E8FFFF          <1> 	call	print_msg
  1485 00007B04 5E                  <1> 	pop	esi
  1486 00007B05 EBE8                <1> 	jmp	short cmd_help_next_w	
  1487                              <1> 
  1488                              <1> cmp_cmd_remark:
  1489 00007B07 3C2A                <1> 	cmp	al, '*'
  1490 00007B09 0F8595020000        <1>         jne     cmp_cmd_external
  1491 00007B0F 46                  <1> 	inc	esi
  1492 00007B10 BF[D0590100]        <1> 	mov	edi, Remark
  1493 00007B15 8A06                <1> 	mov	al, [esi]
  1494 00007B17 3C20                <1> 	cmp	al, 20h
  1495 00007B19 7707                <1> 	ja	short cmd_remark_write
  1496 00007B1B 89FE                <1> 	mov	esi, edi ; Remark
  1497 00007B1D E97BE8FFFF          <1> 	jmp	print_msg
  1498                              <1> 
  1499                              <1> cmd_remark_write:
  1500 00007B22 AA                  <1> 	stosb
  1501 00007B23 AC                  <1> 	lodsb
  1502 00007B24 3C20                <1> 	cmp	al, 20h
  1503 00007B26 73FA                <1> 	jnb	short cmd_remark_write
  1504 00007B28 C60700              <1> 	mov	byte [edi], 0
  1505                              <1> 
  1506                              <1> cmd_help_retn:
  1507                              <1> cmd_remark_retn:
  1508                              <1> cd_retn:
  1509 00007B2B C3                  <1> 	retn
  1510                              <1> 
  1511                              <1> c_2:
  1512 00007B2C 80F902              <1> 	cmp	cl, 2
  1513 00007B2F 0F87AF000000        <1>         ja      c_3
  1514 00007B35 BE[1E5A0100]        <1> 	mov	esi, CommandBuffer
  1515 00007B3A 72A9                <1> 	jb	short c_1
  1516                              <1> 
  1517                              <1> cmp_cmd_cd:
  1518 00007B3C 66AD                <1> 	lodsw
  1519 00007B3E 663D4344            <1> 	cmp	ax, 'CD'
  1520 00007B42 7551                <1> 	jne	short cmp_cmd_drive
  1521 00007B44 46                  <1>         inc	esi
  1522                              <1> cd_0:
  1523 00007B45 668B06              <1> 	mov	ax, [esi]	
  1524 00007B48 3C20                <1> 	cmp	al, 20h
  1525 00007B4A 76DF                <1> 	jna	short cd_retn
  1526                              <1> 	; 10/02/2016
  1527 00007B4C 80FC3A              <1> 	cmp	ah, ':'
  1528 00007B4F 7504                <1> 	jne	short cd_1
  1529 00007B51 46                  <1> 	inc	esi
  1530 00007B52 46                  <1> 	inc	esi
  1531 00007B53 EB49                <1> 	jmp	short cd_2
  1532                              <1> 
  1533                              <1> cd_1:	; change current directory
  1534                              <1> 	; 29/11/2009
  1535                              <1> 	; AH = CDh	; to separate 'CD' command from others
  1536                              <1> 			; for restoring current directory
  1537                              <1> 			; 0CDh sign is for saving cdir into 
  1538                              <1> 			; DOS drv description table cdir area
  1539                              <1> 	
  1540 00007B55 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
  1541                              <1> 
  1542 00007B57 E81D230000          <1> 	call	change_current_directory
  1543 00007B5C 0F8337220000        <1>         jnc     change_prompt_dir_string
  1544                              <1> 
  1545                              <1> cd_error_messages:
  1546 00007B62 3C03                <1> 	cmp	al, 3
  1547 00007B64 740C                <1> 	je	short cd_path_not_found
  1548                              <1> 	; 16/10/2016 (15h -> 15)
  1549 00007B66 3C0F                <1> 	cmp	al, 15 ; drive not ready error 
  1550 00007B68 7459                <1> 	je	short cd_drive_not_ready
  1551 00007B6A 3C11                <1> 	cmp	al, 17 ; read error
  1552 00007B6C 7455                <1> 	je	short cd_drive_not_ready	
  1553 00007B6E 3C13                <1> 	cmp	al, 19 ; ; Bad directory/path name 
  1554 00007B70 7466                <1> 	je	short cd_command_failed
  1555                              <1> 
  1556                              <1> cd_path_not_found:
  1557 00007B72 50                  <1> 	push	eax ; 29/12/2017
  1558                              <1> 	;push	ax	
  1559 00007B73 BE[3D100100]        <1> 	mov	esi, Msg_Dir_Not_Found
  1560 00007B78 E820E8FFFF          <1> 	call	print_msg
  1561                              <1> 	;pop	ax
  1562 00007B7D 58                  <1> 	pop	eax ; 29/12/2017
  1563 00007B7E 3A25[6C590100]      <1> 	cmp	ah, [Current_Dir_Level]
  1564 00007B84 0F830F220000        <1>         jnb     change_prompt_dir_string
  1565 00007B8A 8825[6C590100]      <1> 	mov	[Current_Dir_Level], ah
  1566 00007B90 E904220000          <1>         jmp     change_prompt_dir_string   
  1567                              <1> 
  1568                              <1> cmp_cmd_drive: ; change current drive
  1569                              <1> 	; C:, D:, E: etc.
  1570 00007B95 80FC3A              <1> 	cmp	ah, ':'
  1571 00007B98 0F8506020000        <1>         jne     cmp_cmd_external
  1572                              <1> 
  1573                              <1> cd_2:	; 'CD C:', 'CD D:' ...
  1574 00007B9E 803E20              <1> 	cmp	byte [esi], 20h
  1575 00007BA1 0F8707020000        <1>         ja      loc_cmd_failed
  1576                              <1> 
  1577 00007BA7 24DF                <1> 	and	al, 0DFh
  1578 00007BA9 2C41                <1> 	sub	al, 'A'
  1579 00007BAB 0F82FD010000        <1>         jc      loc_cmd_failed
  1580                              <1> 
  1581 00007BB1 3A05[3A0D0100]      <1>         cmp     al, [Last_DOS_DiskNo]
  1582 00007BB7 770A                <1>         ja	short cd_drive_not_ready
  1583                              <1> 	
  1584 00007BB9 88C2                <1> 	mov	dl, al
  1585 00007BBB E85BF3FFFF          <1> 	call 	change_current_drive
  1586 00007BC0 7201                <1> 	jc	short cd_drive_not_ready	
  1587 00007BC2 C3                  <1> 	retn
  1588                              <1> 
  1589                              <1> cd_drive_not_ready:
  1590 00007BC3 BE[FA0F0100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1591 00007BC8 E8D0E7FFFF          <1> 	call	print_msg
  1592                              <1> 
  1593                              <1> cd_fail_drive_restart:
  1594 00007BCD 8A15[6E590100]      <1> 	mov	dl, [Current_Drv]
  1595                              <1> 	;call 	change_current_drive
  1596 00007BD3 E943F3FFFF          <1>         jmp     change_current_drive
  1597                              <1> 	;retn
  1598                              <1> 
  1599                              <1> cd_command_failed:
  1600 00007BD8 BE[DB0F0100]        <1> 	mov	esi, Msg_Bad_Command
  1601 00007BDD E8BBE7FFFF          <1> 	call	print_msg
  1602 00007BE2 EBE9                <1> 	jmp	short cd_fail_drive_restart
  1603                              <1> 
  1604                              <1> c_3:
  1605                              <1> cmp_cmd_dir:
  1606 00007BE4 BF[9A0D0100]        <1> 	mov	edi, Cmd_Dir
  1607 00007BE9 E8D3010000          <1> 	call	cmp_cmd	
  1608 00007BEE 0F8380020000        <1> 	jnc	print_directory_list
  1609                              <1> 
  1610                              <1> cmp_cmd_cls:
  1611 00007BF4 B103                <1> 	mov	cl, 3
  1612 00007BF6 BF[D60D0100]        <1> 	mov	edi, Cmd_Cls
  1613 00007BFB E8C1010000          <1> 	call	cmp_cmd	
  1614 00007C00 0F83ADE7FFFF        <1>         jnc	clear_screen
  1615                              <1> 
  1616                              <1> cmp_cmd_ver:
  1617 00007C06 B103                <1> 	mov	cl, 3
  1618 00007C08 BF[A40D0100]        <1> 	mov	edi, Cmd_Ver
  1619 00007C0D E8AF010000          <1> 	call	cmp_cmd	
  1620 00007C12 720A                <1> 	jc	short cmp_cmd_mem
  1621                              <1> 
  1622 00007C14 BE[420D0100]        <1> 	mov	esi, mainprog_Version
  1623                              <1> 	;call	print_msg
  1624 00007C19 E97FE7FFFF          <1> 	jmp	print_msg
  1625                              <1> 	;retn
  1626                              <1> 
  1627                              <1> cmp_cmd_mem:
  1628 00007C1E B103                <1> 	mov	cl, 3
  1629 00007C20 BF[0C0E0100]        <1> 	mov	edi, Cmd_Mem
  1630 00007C25 E897010000          <1> 	call	cmp_cmd	
  1631 00007C2A 0F8354B6FFFF        <1> 	jnc	memory_info
  1632                              <1> 
  1633                              <1> cmp_cmd_del:
  1634 00007C30 B103                <1> 	mov	cl, 3
  1635 00007C32 BF[DF0D0100]        <1> 	mov	edi, Cmd_Del
  1636 00007C37 E885010000          <1> 	call	cmp_cmd	
  1637 00007C3C 0F83280F0000        <1>         jnc     delete_file
  1638                              <1> 
  1639                              <1> cmp_cmd_set:
  1640 00007C42 B103                <1> 	mov	cl, 3
  1641 00007C44 BF[D20D0100]        <1> 	mov	edi, Cmd_Set
  1642 00007C49 E873010000          <1> 	call	cmp_cmd	
  1643 00007C4E 0F83C9170000        <1>         jnc     set_get_env
  1644                              <1> 
  1645                              <1> cmp_cmd_run:
  1646 00007C54 B103                <1> 	mov	cl, 3
  1647 00007C56 BF[CE0D0100]        <1> 	mov	edi, Cmd_Run
  1648 00007C5B E861010000          <1> 	call	cmp_cmd	
  1649                              <1> 	; 07/05/2016
  1650 00007C60 0F823E010000        <1>         jc      cmp_cmd_external
  1651 00007C66 E90F1E0000          <1> 	jmp	load_and_execute_file
  1652                              <1> c_5:
  1653                              <1> cmp_cmd_mkdir:
  1654 00007C6B BF[F70D0100]        <1> 	mov	edi, Cmd_Mkdir
  1655 00007C70 E84C010000          <1> 	call	cmp_cmd	
  1656 00007C75 0F83990A0000        <1>         jnc     make_directory
  1657                              <1> 
  1658                              <1> cmp_cmd_rmdir:
  1659 00007C7B B105                <1> 	mov	cl, 5
  1660 00007C7D BF[F10D0100]        <1> 	mov	edi, Cmd_Rmdir
  1661 00007C82 E83A010000          <1> 	call	cmp_cmd	
  1662 00007C87 0F83AA0B0000        <1>         jnc     delete_directory
  1663                              <1> 
  1664                              <1> cmp_cmd_chdir:
  1665 00007C8D B105                <1> 	mov	cl, 5
  1666 00007C8F BF[2E0E0100]        <1> 	mov	edi, Cmd_Chdir
  1667 00007C94 E828010000          <1> 	call	cmp_cmd	
  1668 00007C99 0F8205010000        <1>         jc      cmp_cmd_external
  1669                              <1> 
  1670 00007C9F E9A1FEFFFF          <1> 	jmp	cd_0
  1671                              <1> 
  1672                              <1> c_6:
  1673 00007CA4 80F906              <1> 	cmp	cl, 6
  1674 00007CA7 0F87E0000000        <1>         ja      c_8
  1675 00007CAD 72BC                <1> 	jb	short c_5
  1676                              <1> cmp_cmd_prompt:
  1677 00007CAF BF[AD0D0100]        <1> 	mov	edi, Cmd_Prompt
  1678 00007CB4 E808010000          <1> 	call	cmp_cmd	
  1679 00007CB9 722F                <1>         jc	short cmp_cmd_volume
  1680                              <1> get_prompt_name_fchar:
  1681 00007CBB AC                  <1> 	lodsb
  1682 00007CBC 3C20                <1> 	cmp	al, 20h
  1683 00007CBE 74FB                <1> 	je	short get_prompt_name_fchar
  1684 00007CC0 7713                <1> 	ja	short loc_change_prompt_label
  1685                              <1> default_command_prompt: ; 31/12/2017 ('sysprompt')
  1686 00007CC2 BE[8E0D0100]        <1> 	mov	esi, TRDOSPromptLabel
  1687 00007CC7 C7065452444F        <1> 	mov	dword [esi], "TRDO"
  1688 00007CCD 66C746045300        <1>        	mov	word [esi+4], "S" 
  1689                              <1> loc_cmd_prompt_return:
  1690 00007CD3 C3                  <1> 	retn
  1691                              <1> 
  1692                              <1> set_command_prompt: ; 31/12/2017 ('sysprompt')
  1693 00007CD4 AC                  <1> 	lodsb
  1694                              <1> loc_change_prompt_label:
  1695 00007CD5 66B90B00            <1> 	mov	cx, 11
  1696 00007CD9 BF[8E0D0100]        <1> 	mov	edi, TRDOSPromptLabel
  1697                              <1> put_char_new_prompt_label:
  1698 00007CDE AA                  <1> 	stosb
  1699 00007CDF AC                  <1> 	lodsb
  1700 00007CE0 3C20                <1> 	cmp	al, 20h
  1701 00007CE2 7202                <1> 	jb	short pass_put_new_prompt_label
  1702 00007CE4 E2F8                <1> 	loop	put_char_new_prompt_label
  1703                              <1> pass_put_new_prompt_label:
  1704 00007CE6 C60700              <1> 	mov	byte [edi], 0
  1705 00007CE9 C3                  <1> 	retn
  1706                              <1> 
  1707                              <1> cmp_cmd_volume:
  1708 00007CEA B106                <1> 	mov	cl, 6
  1709 00007CEC BF[B40D0100]        <1> 	mov	edi, Cmd_Volume
  1710 00007CF1 E8CB000000          <1> 	call	cmp_cmd	
  1711 00007CF6 7255                <1>         jc	short cmp_cmd_attrib
  1712                              <1> 
  1713                              <1> cmd_vol1:
  1714 00007CF8 AC                  <1> 	lodsb
  1715 00007CF9 3C20                <1> 	cmp	al, 20h
  1716 00007CFB 7707                <1> 	ja	short cmd_vol2
  1717 00007CFD A0[6E590100]        <1> 	mov	al, [Current_Drv]
  1718 00007D02 EB3D                <1> 	jmp	short cmd_vol4
  1719                              <1> cmd_vol2:
  1720 00007D04 3C41                <1> 	cmp	al, 'A'
  1721 00007D06 0F82A2000000        <1>         jb      loc_cmd_failed
  1722 00007D0C 3C7A                <1> 	cmp	al, 'z'
  1723 00007D0E 0F879A000000        <1>         ja      loc_cmd_failed
  1724 00007D14 3C5A                <1> 	cmp	al, 'Z'
  1725 00007D16 760A                <1> 	jna	short cmd_vol3
  1726 00007D18 3C61                <1> 	cmp	al, 'a'
  1727 00007D1A 0F828E000000        <1>         jb      loc_cmd_failed
  1728 00007D20 24DF                <1> 	and	al, 0DFh
  1729                              <1> cmd_vol3:
  1730 00007D22 8A26                <1> 	mov	ah, [esi]
  1731 00007D24 80FC3A              <1> 	cmp	ah, ':'
  1732 00007D27 0F8581000000        <1>         jne     loc_cmd_failed
  1733 00007D2D 2C41                <1> 	sub	al, 'A'
  1734 00007D2F 3A05[3A0D0100]      <1>         cmp     al, [Last_DOS_DiskNo]
  1735 00007D35 760A                <1> 	jna	short cmd_vol4
  1736                              <1> 
  1737 00007D37 BE[FA0F0100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1738 00007D3C E95CE6FFFF          <1> 	jmp	print_msg
  1739                              <1> 	
  1740                              <1> cmd_vol4:
  1741 00007D41 E88EFAFFFF          <1> 	call	print_volume_info
  1742 00007D46 0F8277FEFFFF        <1>         jc      cd_drive_not_ready
  1743 00007D4C C3                  <1> 	retn
  1744                              <1> 
  1745                              <1> cmp_cmd_attrib:
  1746 00007D4D B106                <1> 	mov	cl, 6
  1747 00007D4F BF[E30D0100]        <1> 	mov	edi, Cmd_Attrib
  1748 00007D54 E868000000          <1> 	call	cmp_cmd	
  1749 00007D59 0F831D0F0000        <1>         jnc     set_file_attributes
  1750                              <1> 
  1751                              <1> cmp_cmd_rename:
  1752 00007D5F B106                <1> 	mov	cl, 6
  1753 00007D61 BF[EA0D0100]        <1> 	mov	edi, Cmd_Rename
  1754 00007D66 E856000000          <1> 	call	cmp_cmd	
  1755 00007D6B 0F8353110000        <1>         jnc     rename_file
  1756                              <1> 
  1757                              <1> cmp_cmd_device:
  1758 00007D71 B106                <1> 	mov	cl, 6
  1759 00007D73 BF[1F0E0100]        <1> 	mov	edi, Cmd_Device
  1760 00007D78 E844000000          <1> 	call	cmp_cmd	
  1761 00007D7D 7225                <1>         jc	short cmp_cmd_external
  1762                              <1> 
  1763 00007D7F C3                  <1> 	retn
  1764                              <1> 
  1765                              <1> c_7:
  1766                              <1> cmp_cmd_devlist:
  1767 00007D80 BF[260E0100]        <1> 	mov	edi, Cmd_DevList
  1768 00007D85 E837000000          <1> 	call	cmp_cmd	
  1769 00007D8A 7218                <1>         jc	short cmp_cmd_external
  1770                              <1> 
  1771                              <1> loc_cmd_return:
  1772 00007D8C C3                  <1> 	retn
  1773                              <1> 
  1774                              <1> c_8:
  1775 00007D8D 80F908              <1>         cmp	cl, 8
  1776 00007D90 7712                <1> 	ja	short cmp_cmd_external
  1777 00007D92 72EC                <1> 	jb	short c_7
  1778                              <1> 
  1779                              <1> cmp_cmd_longname:
  1780 00007D94 BF[BB0D0100]        <1> 	mov	edi, Cmd_LongName
  1781 00007D99 E823000000          <1> 	call	cmp_cmd	
  1782 00007D9E 0F8350060000        <1>         jnc     get_and_print_longname
  1783                              <1> 
  1784                              <1> cmp_cmd_external:
  1785                              <1> 	; 07/05/2016
  1786                              <1> 	; 22/04/2016
  1787 00007DA4 BE[1E5A0100]        <1> 	mov	esi, CommandBuffer
  1788 00007DA9 E9CC1C0000          <1> 	jmp	loc_run_check_filename 
  1789                              <1> 
  1790                              <1> loc_cmd_failed:
  1791 00007DAE 803D[1E5A0100]20    <1> 	cmp	byte [CommandBuffer], 20h
  1792 00007DB5 76D5                <1> 	jna	short loc_cmd_return
  1793 00007DB7 BE[DB0F0100]        <1> 	mov	esi, Msg_Bad_Command
  1794                              <1> ;	call	print_msg
  1795                              <1> ;loc_cmd_return:
  1796                              <1> ;	retn
  1797 00007DBC E9DCE5FFFF          <1> 	jmp	print_msg
  1798                              <1> 
  1799                              <1> cmp_cmd:
  1800                              <1> 	 ; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
  1801 00007DC1 BE[1E5A0100]        <1>          mov	esi, CommandBuffer
  1802                              <1>          ; edi = internal command word (ASCIIZ)
  1803                              <1> 	 ; ecx = command length (<=8)
  1804                              <1> cmp_cmd_1:
  1805 00007DC6 AC                  <1> 	lodsb
  1806 00007DC7 AE                  <1> 	scasb
  1807 00007DC8 750D                <1> 	jne	short cmp_cmd_3
  1808 00007DCA E2FA                <1> 	loop	cmp_cmd_1
  1809 00007DCC AC                  <1>  	lodsb
  1810 00007DCD 3C20                <1> 	cmp	al, 20h
  1811 00007DCF 7703                <1> 	ja	short cmp_cmd_2
  1812 00007DD1 30C0                <1> 	xor	al, al
  1813                              <1> 	; ZF = 1 -> internal command word matches
  1814 00007DD3 C3                  <1> 	retn
  1815                              <1> cmp_cmd_2:
  1816                              <1> 	; ZF = 0 (CF = 0) -> external command word 	
  1817 00007DD4 58                  <1> 	pop	eax ; no return to the caller from here 
  1818 00007DD5 EBCD                <1> 	jmp	cmp_cmd_external	
  1819                              <1> cmp_cmd_3:
  1820 00007DD7 F9                  <1> 	stc
  1821                              <1> 	; CF = 1 -> internal command word does not match
  1822 00007DD8 C3                  <1> 	retn
  1823                              <1> 
  1824                              <1> loc_run_cmd_failed:
  1825                              <1> 	; 15/03/2016
  1826                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  1827                              <1> 	; 07/12/2009 (CMD_INTR.ASM)	
  1828                              <1> 	; 29/11/2009
  1829                              <1> 
  1830 00007DD9 E863000000          <1> 	call	restore_cdir_after_cmd_fail
  1831                              <1> 
  1832                              <1> loc_run_cmd_failed_cmp_al:
  1833                              <1> 	; End of Restore_CDIR code (29/11/2009)
  1834                              <1> 
  1835 00007DDE 3C01                <1> 	cmp	al, 1 ; Bad command or file name
  1836 00007DE0 74CC                <1> 	je	loc_cmd_failed
  1837                              <1> loc_run_dir_not_found:
  1838 00007DE2 3C03                <1> 	cmp	al, 3
  1839 00007DE4 750A                <1> 	jne	short loc_run_file_notfound_msg
  1840                              <1> 	; Path not found (MS-DOS Error Code = 3)
  1841 00007DE6 BE[3D100100]        <1> 	mov	esi, Msg_Dir_Not_Found
  1842 00007DEB E9ADE5FFFF          <1> 	jmp	print_msg
  1843                              <1> 
  1844                              <1> loc_run_file_notfound_msg:
  1845 00007DF0 3C02                <1> 	cmp	al, 2 ; File not found
  1846 00007DF2 750A                <1> 	jne	short loc_run_file_drv_read_err
  1847                              <1> 
  1848                              <1> loc_print_file_notfound_msg: 
  1849 00007DF4 BE[54100100]        <1>         mov     esi, Msg_File_Not_Found
  1850                              <1> 	;call	proc_printmsg
  1851                              <1> 	;retn
  1852 00007DF9 E99FE5FFFF          <1> 	jmp	print_msg
  1853                              <1> 
  1854                              <1> loc_run_file_drv_read_err:
  1855                              <1> 	; Err: 17 (Read fault)
  1856 00007DFE 3C11                <1> 	cmp	al, 17 ; Drive not ready or read error
  1857 00007E00 7404                <1> 	je	short loc_run_file_print_drv_read_err
  1858                              <1> 	;
  1859 00007E02 3C0F                <1> 	cmp	al, 15 ; Drive not ready (or read error)
  1860 00007E04 750A                <1> 	jne	short loc_run_file_toobig
  1861                              <1> 
  1862                              <1> loc_run_file_print_drv_read_err:
  1863 00007E06 BE[FA0F0100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  1864 00007E0B E98DE5FFFF          <1> 	jmp	print_msg
  1865                              <1> 
  1866                              <1> loc_run_file_toobig:
  1867 00007E10 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
  1868 00007E12 750A                <1> 	jne	short loc_run_file_perm_denied
  1869 00007E14 BE[9F100100]        <1> 	mov	esi, Msg_Insufficient_Memory
  1870 00007E19 E97FE5FFFF          <1> 	jmp	print_msg
  1871                              <1> 
  1872                              <1> loc_run_file_perm_denied:
  1873                              <1> 	; 29/12/2017
  1874 00007E1E 3C0B                <1> 	cmp	al, ERR_PERM_DENIED ; 11 ; Permission denied
  1875 00007E20 750A                <1> 	jne	short loc_run_misc_error
  1876 00007E22 BE[34120100]        <1> 	mov	esi, Msg_Permission_Denied
  1877 00007E27 E971E5FFFF          <1> 	jmp	print_msg	
  1878                              <1> 
  1879                              <1> 	; 15/03/2016
  1880                              <1> print_misc_error_msg:
  1881                              <1> loc_run_misc_error:
  1882                              <1> 	; AL = Error code
  1883 00007E2C E8C8B4FFFF          <1> 	call	bytetohex
  1884 00007E31 66A3[D3100100]      <1>         mov     [error_code_hex], ax
  1885                              <1> 	
  1886 00007E37 BE[B6100100]        <1> 	mov	esi, Msg_Error_Code 
  1887                              <1> 	;call	print_msg 
  1888                              <1> 	;retn
  1889                              <1> 
  1890 00007E3C E95CE5FFFF          <1> 	jmp	print_msg
  1891                              <1> 
  1892                              <1> restore_cdir_after_cmd_fail:
  1893                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  1894 00007E41 50                  <1> 	push	eax
  1895 00007E42 8A3D[C2600100]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
  1896                              <1> 				; of the 'run' command.
  1897 00007E48 3A3D[6E590100]      <1> 	cmp	bh, [Current_Drv]
  1898 00007E4E 7409                <1> 	je	short loc_run_restore_cdir
  1899 00007E50 88FA                <1> 	mov	dl, bh
  1900 00007E52 E8C4F0FFFF          <1> 	call	change_current_drive 
  1901 00007E57 EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
  1902                              <1> 
  1903                              <1> loc_run_restore_cdir:
  1904 00007E59 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  1905 00007E60 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
  1906 00007E62 30DB                <1> 	xor	bl, bl
  1907 00007E64 0FB7F3              <1> 	movzx	esi, bx
  1908 00007E67 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1909 00007E6D E860F1FFFF          <1> 	call	restore_current_directory
  1910                              <1> 
  1911                              <1> loc_run_err_pass_restore_cdir:
  1912 00007E72 58                  <1> 	pop	eax
  1913 00007E73 C3                  <1> 	retn
  1914                              <1> 
  1915                              <1> print_directory_list:
  1916                              <1> 	; 10/02/2016
  1917                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  1918                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
  1919                              <1> 	;
  1920 00007E74 66C705[04620100]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
  1920 00007E7C 08                  <1>
  1921 00007E7D A0[6E590100]        <1> 	mov	al, [Current_Drv]
  1922 00007E82 A2[C2600100]        <1> 	mov	[RUN_CDRV], al
  1923                              <1> get_dfname_fchar:
  1924 00007E87 AC                  <1> 	lodsb
  1925 00007E88 3C20                <1> 	cmp	al, 20h
  1926 00007E8A 74FB                <1> 	je	short get_dfname_fchar
  1927 00007E8C 0F82A4000000        <1>         jb      loc_print_dir_call_all
  1928 00007E92 3C2D                <1> 	cmp	al, '-'
  1929 00007E94 7542                <1> 	jne	short loc_print_dir_call_flt
  1930                              <1> get_next_attr_char:
  1931 00007E96 AC                  <1> 	lodsb
  1932 00007E97 3C20                <1> 	cmp	al, 20h
  1933 00007E99 74FB                <1> 	je	short get_next_attr_char
  1934 00007E9B 0F820DFFFFFF        <1>         jb      loc_cmd_failed
  1935 00007EA1 24DF                <1> 	and	al, 0DFh
  1936 00007EA3 3C44                <1> 	cmp	al, 'D' ; directories only ?
  1937 00007EA5 7512                <1> 	jne	short pass_only_directories
  1938 00007EA7 AC                  <1> 	lodsb
  1939 00007EA8 3C20                <1> 	cmp	al, 20h
  1940 00007EAA 0F87FEFEFFFF        <1>         ja      loc_cmd_failed
  1941 00007EB0 800D[04620100]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
  1942 00007EB7 EB18                <1> 	jmp	short get_dfname_fchar_attr
  1943                              <1> pass_only_directories:
  1944 00007EB9 3C46                <1> 	cmp	al, 'F'	; files only ?
  1945 00007EBB 0F85B0000000        <1>         jne     check_attr_s
  1946 00007EC1 AC                  <1> 	lodsb
  1947 00007EC2 3C20                <1> 	cmp	al, 20h
  1948 00007EC4 0F87E4FEFFFF        <1>         ja      loc_cmd_failed
  1949 00007ECA 800D[05620100]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
  1950                              <1> get_dfname_fchar_attr:
  1951 00007ED1 AC                  <1> 	lodsb
  1952 00007ED2 3C20                <1> 	cmp	al, 20h
  1953 00007ED4 74FB                <1> 	je	short get_dfname_fchar_attr
  1954 00007ED6 725E                <1> 	jb	short loc_print_dir_call_all
  1955                              <1> 
  1956                              <1> loc_print_dir_call_flt:
  1957 00007ED8 4E                  <1> 	dec	esi
  1958 00007ED9 BF[06620100]        <1> 	mov	edi, FindFile_Drv
  1959 00007EDE E8AC250000          <1> 	call	parse_path_name
  1960 00007EE3 7308                <1>  	jnc	short loc_print_dir_change_drv_1
  1961 00007EE5 3C01                <1> 	cmp	al, 1
  1962 00007EE7 0F87ECFEFFFF        <1>         ja      loc_run_cmd_failed
  1963                              <1> 
  1964                              <1> loc_print_dir_change_drv_1:
  1965 00007EED 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  1966                              <1> loc_print_dir_change_drv_2:
  1967 00007EF3 3A15[C2600100]      <1> 	cmp	dl, [RUN_CDRV]
  1968 00007EF9 740B                <1> 	je	short loc_print_dir_change_directory 
  1969 00007EFB E81BF0FFFF          <1> 	call	change_current_drive
  1970 00007F00 0F82D3FEFFFF        <1>         jc      loc_run_cmd_failed
  1971                              <1> loc_print_dir_change_directory:
  1972 00007F06 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
  1973 00007F0D 761D                <1> 	jna	short pass_print_dir_change_directory
  1974                              <1> 
  1975 00007F0F FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  1976 00007F15 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  1977 00007F1A 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  1978 00007F1C E8581F0000          <1> 	call	change_current_directory
  1979 00007F21 0F82B2FEFFFF        <1>         jc      loc_run_cmd_failed
  1980                              <1> 
  1981                              <1> loc_print_dir_change_prompt_dir_string:
  1982 00007F27 E86D1E0000          <1> 	call	change_prompt_dir_string
  1983                              <1> 
  1984                              <1> pass_print_dir_change_directory:
  1985 00007F2C BE[48620100]        <1> 	mov	esi, FindFile_Name
  1986 00007F31 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
  1987 00007F34 7706                <1> 	ja	short loc_print_dir_call
  1988                              <1> 
  1989                              <1> loc_print_dir_call_all:
  1990 00007F36 C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
  1991                              <1> loc_print_dir_call:
  1992 00007F3C E87E000000          <1> 	call	print_directory
  1993                              <1> 
  1994 00007F41 8A15[C2600100]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
  1995 00007F47 3A15[6E590100]      <1> 	cmp	dl, [Current_Drv]
  1996 00007F4D 7406                <1> 	je	short loc_print_dir_call_restore_cdir_retn
  1997 00007F4F E8C7EFFFFF          <1> 	call	change_current_drive 
  1998 00007F54 C3                  <1> 	retn
  1999                              <1> 
  2000                              <1> loc_print_dir_call_restore_cdir_retn:
  2001 00007F55 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2002 00007F5C 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
  2003                              <1> 
  2004 00007F5E BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2005 00007F63 31C0                <1> 	xor	eax, eax
  2006 00007F65 88D4                <1> 	mov	ah, dl
  2007 00007F67 01C6                <1> 	add	esi, eax
  2008                              <1> 
  2009 00007F69 E864F0FFFF          <1> 	call	restore_current_directory
  2010                              <1> 
  2011                              <1> pass_print_dir_call_restore_cdir_retn:
  2012 00007F6E C3                  <1> 	retn
  2013                              <1> 
  2014                              <1> check_attr_s_cap:
  2015 00007F6F 24DF                <1> 	and	al, 0DFh
  2016                              <1> check_attr_s:
  2017 00007F71 3C53                <1> 	cmp	al, 'S'
  2018 00007F73 7514                <1> 	jne	short pass_attr_s
  2019 00007F75 800D[04620100]04    <1> 	or	byte [AttributesMask], 4 ; system
  2020 00007F7C AC                  <1> 	lodsb
  2021 00007F7D 3C20                <1> 	cmp	al, 20h
  2022 00007F7F 0F844CFFFFFF        <1>         je      get_dfname_fchar_attr
  2023 00007F85 72AF                <1> 	jb	short loc_print_dir_call_all
  2024 00007F87 24DF                <1> 	and	al, 0DFh
  2025                              <1> pass_attr_s:
  2026 00007F89 3C48                <1> 	cmp	al, 'H'
  2027 00007F8B 7514                <1> 	jne	short pass_attr_h
  2028 00007F8D 800D[04620100]02    <1> 	or	byte [AttributesMask], 2 ; hidden
  2029                              <1> pass_attr_shr:
  2030 00007F94 AC                  <1> 	lodsb
  2031 00007F95 3C20                <1> 	cmp	al, 20h
  2032 00007F97 0F8434FFFFFF        <1>         je      get_dfname_fchar_attr
  2033 00007F9D 7297                <1> 	jb	short loc_print_dir_call_all
  2034 00007F9F EBCE                <1> 	jmp	short check_attr_s_cap
  2035                              <1> 
  2036                              <1> pass_attr_h:
  2037 00007FA1 3C52                <1> 	cmp	al, 'R'
  2038 00007FA3 7509                <1> 	jne	short pass_attr_r
  2039 00007FA5 800D[04620100]01    <1> 	or	byte [AttributesMask], 1 ; read only
  2040 00007FAC EBE6                <1> 	jmp	short pass_attr_shr
  2041                              <1> 
  2042                              <1> pass_attr_r:
  2043 00007FAE 3C41                <1> 	cmp	al, 'A'
  2044 00007FB0 0F85F8FDFFFF        <1>         jne     loc_cmd_failed
  2045 00007FB6 800D[04620100]20    <1> 	or	byte [AttributesMask], 20h ; archive
  2046 00007FBD EBD5                <1> 	jmp	short pass_attr_shr
  2047                              <1> 
  2048                              <1> print_directory:
  2049                              <1> 	; 13/05/2016
  2050                              <1> 	; 11/02/2016
  2051                              <1> 	; 10/02/2016
  2052                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2053                              <1> 	; 30/10/2010 ('proc_print_directory')	
  2054                              <1> 	; 19/09/2009
  2055                              <1> 	; 2005 
  2056                              <1> 	; INPUT ->
  2057                              <1> 	;	ESI = Asciiz File/Dir Name Address
  2058                              <1> 
  2059 00007FBF 56                  <1> 	push	esi
  2060                              <1> 
  2061 00007FC0 29C0                <1> 	sub	eax, eax
  2062                              <1> 
  2063 00007FC2 66A3[90620100]      <1> 	mov	word [Dir_Count], ax ; 0
  2064 00007FC8 66A3[8E620100]      <1> 	mov 	word [File_Count], ax ; 0
  2065 00007FCE A3[92620100]        <1> 	mov 	dword [Total_FSize], eax ; 0
  2066                              <1> 
  2067 00007FD3 E8DBE3FFFF          <1> 	call    clear_screen
  2068                              <1> 	
  2069 00007FD8 31C9                <1> 	xor	ecx, ecx	
  2070 00007FDA 8A2D[6E590100]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
  2071 00007FE0 A0[6F590100]        <1> 	mov     al, [Current_Dir_Drv] 
  2072 00007FE5 A2[F80E0100]        <1> 	mov     [Dir_Drive_Name], al
  2073 00007FEA BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2074 00007FEF 01CE                <1> 	add	esi, ecx
  2075                              <1> 
  2076 00007FF1 E858F9FFFF          <1> 	call	move_volume_name_and_serial_no
  2077 00007FF6 730C                <1> 	jnc	short print_dir_strlen_check
  2078                              <1> 
  2079 00007FF8 5E                  <1> 	pop	esi
  2080 00007FF9 8A3D[D6580100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  2081                              <1> 	;call	beeper
  2082                              <1> 	;retn
  2083 00007FFF E9BE9DFFFF          <1> 	jmp	beeper  ; beep ! and return
  2084                              <1> 
  2085                              <1> print_dir_strlen_check:
  2086 00008004 BE[71590100]        <1> 	mov	esi, Current_Dir_Root
  2087 00008009 BF[950F0100]        <1> 	mov	edi, Dir_Str_Root
  2088                              <1> 	
  2089                              <1> 	;xor	ecx, ecx
  2090 0000800E 8A0D[CD590100]      <1>         mov     cl, [Current_Dir_StrLen]
  2091 00008014 FEC1                <1> 	inc	cl
  2092 00008016 80F940              <1> 	cmp	cl, 64
  2093 00008019 760D                <1> 	jna	short pass_print_dir_strlen_shorting
  2094 0000801B 46                  <1> 	inc	esi
  2095 0000801C 01CE                <1> 	add	esi, ecx
  2096 0000801E 83EE40              <1> 	sub	esi, 64 
  2097 00008021 47                  <1> 	inc	edi
  2098 00008022 B82E2E2E20          <1> 	mov	eax, '... ' 
  2099 00008027 AB                  <1> 	stosd
  2100                              <1>  
  2101                              <1> pass_print_dir_strlen_shorting:
  2102 00008028 F3A4                <1> 	rep	movsb
  2103                              <1> 
  2104 0000802A BE[EB0E0100]        <1> 	mov	esi, Dir_Drive_Str
  2105 0000802F E869E3FFFF          <1> 	call	print_msg
  2106                              <1> 
  2107 00008034 BE[4A0F0100]        <1> 	mov	esi, Vol_Serial_Header
  2108 00008039 E85FE3FFFF          <1> 	call	print_msg
  2109                              <1> 
  2110 0000803E BE[8A0F0100]        <1> 	mov	esi, Dir_Str_Header
  2111 00008043 E855E3FFFF          <1> 	call	print_msg
  2112                              <1> 	
  2113 00008048 BE[D5190100]        <1> 	mov	esi, next2line
  2114 0000804D E84BE3FFFF          <1> 	call	print_msg
  2115                              <1> 
  2116                              <1> loc_print_dir_first_file:
  2117 00008052 C605[A5620100]10    <1> 	mov	byte [PrintDir_RowCounter], 16
  2118 00008059 66A1[04620100]      <1> 	mov	ax, [AttributesMask]
  2119 0000805F 5E                  <1> 	pop	esi
  2120                              <1> 
  2121 00008060 E859020000          <1> 	call	find_first_file
  2122 00008065 0F826F010000        <1>         jc      loc_dir_ok
  2123                              <1> 	 
  2124                              <1> loc_dfname_use_this:
  2125                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
  2126 0000806B F6C310              <1> 	test	bl, 10h  ; Is it a directory?
  2127 0000806E 741B                <1> 	jz	short loc_not_dir
  2128                              <1> 
  2129 00008070 66FF05[90620100]    <1> 	inc	word [Dir_Count]
  2130 00008077 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
  2131 00008079 BE[DA100100]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
  2132 0000807E BF[F1100100]        <1> 	mov	edi, Dir_Or_FileSize
  2133                              <1> 	; move 10 bytes
  2134 00008083 A5                  <1> 	movsd
  2135 00008084 A5                  <1> 	movsd
  2136 00008085 66A5                <1> 	movsw	    	
  2137 00008087 89D6                <1> 	mov	esi, edx
  2138 00008089 EB36                <1> 	jmp     short loc_dir_attribute
  2139                              <1> 
  2140                              <1> loc_not_dir:
  2141 0000808B 66FF05[8E620100]    <1> 	inc	word [File_Count]
  2142 00008092 0105[92620100]      <1> 	add	[Total_FSize], eax
  2143                              <1> 
  2144 00008098 B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
  2145 0000809D 89CF                <1> 	mov	edi, ecx
  2146 0000809F 81C7[F1100100]      <1> 	add	edi, Dir_Or_FileSize
  2147                              <1> loc_dir_rdivide:
  2148 000080A5 29D2                <1> 	sub	edx, edx
  2149 000080A7 F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
  2150 000080A9 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
  2151 000080AC 4F                  <1> 	dec	edi
  2152 000080AD 8817                <1> 	mov     [edi], dl
  2153 000080AF 21C0                <1> 	and	eax, eax
  2154 000080B1 75F2                <1> 	jnz	short loc_dir_rdivide
  2155                              <1> 
  2156                              <1> loc_dir_fill_space:
  2157 000080B3 81FF[F1100100]      <1> 	cmp     edi, Dir_Or_FileSize
  2158 000080B9 7606                <1> 	jna     short loc_dir_attribute
  2159 000080BB 4F                  <1> 	dec     edi
  2160 000080BC C60720              <1> 	mov     byte [edi], 20h
  2161 000080BF EBF2                <1> 	jmp     short loc_dir_fill_space
  2162                              <1> 
  2163                              <1> loc_dir_attribute:
  2164 000080C1 C705[FC100100]2020- <1> 	mov	dword [File_Attribute], 20202020h
  2164 000080C9 2020                <1>
  2165                              <1> 
  2166 000080CB 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
  2167 000080CE 7207                <1> 	jb	short loc_dir_pass_arch
  2168 000080D0 C605[FF100100]41    <1> 	mov	byte [File_Attribute+3], 'A'
  2169                              <1> 
  2170                              <1> loc_dir_pass_arch:
  2171 000080D7 80E307              <1> 	and	bl, 7
  2172 000080DA 7428                <1> 	jz	short loc_dir_file_name
  2173 000080DC 88DF                <1> 	mov	bh, bl
  2174 000080DE 80E303              <1> 	and	bl, 3
  2175 000080E1 38DF                <1> 	cmp	bh, bl
  2176 000080E3 7607                <1> 	jna	short loc_dir_pass_s
  2177 000080E5 C605[FC100100]53    <1> 	mov	byte [File_Attribute], 'S'
  2178                              <1> 
  2179                              <1> loc_dir_pass_s:
  2180 000080EC 80E302              <1> 	and     bl,2
  2181 000080EF 7407                <1> 	jz      short loc_dir_pass_h
  2182 000080F1 C605[FD100100]48    <1> 	mov     byte [File_Attribute+1], 'H'
  2183                              <1> loc_dir_pass_h:
  2184 000080F8 80E701              <1> 	and     bh,1
  2185 000080FB 7407                <1> 	jz      short loc_dir_file_name
  2186 000080FD C605[FE100100]52    <1> 	mov     byte [File_Attribute+2], 'R'
  2187                              <1> loc_dir_file_name:
  2188                              <1> 	;mov     bx, [esi+18h] ; Date
  2189                              <1> 	;mov     dx, [esi+16h] ; Time
  2190 00008104 8B5E16              <1> 	mov	ebx, [esi+16h]
  2191 00008107 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
  2192 00008109 BF[E4100100]        <1> 	mov     edi, File_Name
  2193                              <1> 	; move 8 bytes
  2194 0000810E A5                  <1> 	movsd
  2195 0000810F A5                  <1> 	movsd
  2196 00008110 C60720              <1> 	mov	byte [edi], 20h
  2197 00008113 47                  <1> 	inc	edi
  2198                              <1> 	; move 3 bytes
  2199 00008114 66A5                <1> 	movsw
  2200 00008116 A4                  <1> 	movsb
  2201 00008117 89CE                <1> 	mov	esi, ecx
  2202                              <1> 
  2203                              <1> Dir_Time_start:
  2204                              <1> 	;mov	ax, dx		; Time
  2205 00008119 6689D8              <1> 	mov	ax, bx
  2206 0000811C 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
  2207 00008120 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
  2208 00008124 D40A                <1> 	aam			; Q([AL]/10)->AH
  2209                              <1> 				; R([AL]/10)->AL
  2210                              <1> 				; [AL]+[AH]= Minute as BCD
  2211 00008126 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2212 0000812A 86E0                <1> 	xchg	ah, al
  2213 0000812C 66A3[0F110100]      <1> 	mov	[File_Minute], ax
  2214                              <1> 
  2215                              <1> 	;mov	al, dh
  2216 00008132 88F8                <1> 	mov	al, bh
  2217 00008134 C0E803              <1> 	shr	al, 3		; shift right 3 times
  2218 00008137 D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
  2219 00008139 660D3030            <1> 	or	ax, '00'
  2220 0000813D 86E0                <1> 	xchg	ah, al
  2221 0000813F 66A3[0C110100]      <1> 	mov     [File_Hour], ax
  2222                              <1> 
  2223 00008145 C1EB10              <1> 	shr	ebx, 16		; BX = Date
  2224                              <1> 	
  2225                              <1> Dir_Date_start:
  2226 00008148 6689D8              <1> 	mov	ax, bx		; Date
  2227 0000814B 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
  2228 0000814F D40A                <1> 	aam			; Q([AL]/10)->AH
  2229                              <1> 				; R([AL]/10)->AL
  2230                              <1> 				; [AL]+[AH]= Day as BCD
  2231 00008151 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2232 00008155 86C4                <1> 	xchg	al, ah
  2233                              <1> 
  2234 00008157 66A3[01110100]      <1> 	mov	[File_Day], ax
  2235                              <1> 
  2236 0000815D 6689D8              <1> 	mov	ax, bx
  2237 00008160 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
  2238 00008164 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
  2239 00008168 D40A                <1> 	aam
  2240 0000816A 660D3030            <1> 	or	ax, '00'
  2241 0000816E 86E0                <1> 	xchg	ah, al
  2242 00008170 66A3[04110100]      <1> 	mov	[File_Month], ax
  2243                              <1> 
  2244 00008176 6689D8              <1> 	mov	ax, bx
  2245 00008179 66C1E809            <1> 	shr     ax, 9
  2246 0000817D 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
  2247 00008181 6605BC07            <1> 	add	ax, 1980
  2248                              <1> 
  2249 00008185 B10A                <1> 	mov	cl, 10
  2250 00008187 F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
  2251 00008189 80CC30              <1> 	or	ah, '0'
  2252 0000818C 8825[0A110100]      <1> 	mov	[File_Year+3], ah
  2253 00008192 D40A                <1> 	aam
  2254 00008194 86E0                <1> 	xchg	ah, al
  2255 00008196 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
  2256 00008199 8825[09110100]      <1> 	mov	[File_Year+2], ah
  2257 0000819F D40A                <1> 	aam
  2258 000081A1 86C4                <1> 	xchg	al, ah
  2259 000081A3 660D3030            <1> 	or	ax, '00'
  2260 000081A7 66A3[07110100]      <1> 	mov	[File_Year], ax
  2261                              <1> 
  2262                              <1> loc_show_line:
  2263 000081AD 56                  <1> 	push	esi
  2264 000081AE BE[E4100100]        <1> 	mov     esi, File_Name
  2265 000081B3 E8E5E1FFFF          <1> 	call	print_msg
  2266 000081B8 BE[D7190100]        <1> 	mov	esi, nextline
  2267 000081BD E8DBE1FFFF          <1> 	call	print_msg
  2268 000081C2 5E                  <1> 	pop	esi
  2269                              <1> 
  2270 000081C3 FE0D[A5620100]      <1> 	dec	byte [PrintDir_RowCounter]
  2271 000081C9 0F84D4000000        <1>         jz      pause_dir_scroll
  2272                              <1> 
  2273                              <1> loc_next_entry:
  2274 000081CF E899010000          <1> 	call	find_next_file
  2275 000081D4 0F8391FEFFFF        <1>         jnc     loc_dfname_use_this
  2276                              <1> 
  2277                              <1> loc_dir_ok:
  2278 000081DA B90A000000          <1> 	mov     ecx, 10
  2279 000081DF 66A1[90620100]      <1> 	mov	ax, [Dir_Count]
  2280 000081E5 BF[25110100]        <1> 	mov	edi, Decimal_Dir_Count
  2281 000081EA 6639C8              <1> 	cmp	ax, cx ; 10
  2282 000081ED 7216                <1> 	jb	short pass_ddc
  2283 000081EF 47                  <1> 	inc	edi
  2284 000081F0 6683F864            <1> 	cmp	ax, 100
  2285 000081F4 720F                <1> 	jb	short pass_ddc
  2286 000081F6 47                  <1> 	inc	edi
  2287 000081F7 663DE803            <1> 	cmp	ax, 1000
  2288 000081FB 7208                <1> 	jb	short pass_ddc
  2289 000081FD 47                  <1> 	inc	edi
  2290 000081FE 663D1027            <1> 	cmp	ax, 10000
  2291 00008202 7201                <1> 	jb	short pass_ddc
  2292 00008204 47                  <1> 	inc	edi
  2293                              <1> pass_ddc:
  2294 00008205 886F01              <1> 	mov     [edi+1], ch ; 0
  2295                              <1> loc_ddc_rediv:
  2296 00008208 31D2                <1> 	xor     edx, edx
  2297 0000820A 66F7F1              <1> 	div     cx	; 10
  2298 0000820D 80C230              <1> 	add     dl, '0'
  2299 00008210 8817                <1> 	mov     [edi], dl
  2300 00008212 4F                  <1> 	dec     edi
  2301 00008213 6609C0              <1> 	or	ax, ax
  2302 00008216 75F0                <1> 	jnz	short loc_ddc_rediv
  2303                              <1> 
  2304 00008218 66A1[8E620100]      <1> 	mov     ax, [File_Count]
  2305 0000821E BF[14110100]        <1> 	mov     edi, Decimal_File_Count
  2306 00008223 6639C8              <1> 	cmp     ax, cx ; 10
  2307 00008226 7216                <1> 	jb      short pass_dfc
  2308 00008228 47                  <1> 	inc     edi
  2309 00008229 6683F864            <1> 	cmp     ax, 100
  2310 0000822D 720F                <1> 	jb      short pass_dfc
  2311 0000822F 47                  <1> 	inc     edi
  2312 00008230 663DE803            <1> 	cmp     ax, 1000
  2313 00008234 7208                <1> 	jb      short pass_dfc
  2314 00008236 47                  <1> 	inc     edi
  2315 00008237 663D1027            <1> 	cmp     ax, 10000
  2316 0000823B 7201                <1> 	jb      short pass_dfc
  2317 0000823D 47                  <1> 	inc     edi
  2318                              <1> pass_dfc:
  2319                              <1> 	;mov    cx, 10
  2320 0000823E 886F01              <1> 	mov     [edi+1], ch ; 00
  2321                              <1> loc_dfc_rediv:
  2322                              <1> 	;xor	dx, dx
  2323 00008241 30D2                <1> 	xor	dl, dl
  2324 00008243 66F7F1              <1> 	div	cx
  2325 00008246 80C230              <1> 	add	dl, '0'
  2326 00008249 8817                <1> 	mov	[edi], dl
  2327 0000824B 4F                  <1> 	dec	edi
  2328 0000824C 6609C0              <1> 	or	ax, ax
  2329 0000824F 75F0                <1> 	jnz	short loc_dfc_rediv
  2330                              <1> 
  2331 00008251 BF[A4620100]        <1> 	mov     edi, TFS_Dec_End
  2332                              <1>         ;mov    byte [edi], 0
  2333 00008256 A1[92620100]        <1> 	mov     eax, [Total_FSize]
  2334                              <1> 	;mov    ecx, 10
  2335                              <1> rediv_tfs_hex:
  2336                              <1> 	;sub	edx, edx
  2337 0000825B 28D2                <1> 	sub	dl, dl
  2338 0000825D F7F1                <1> 	div	ecx
  2339 0000825F 80C230              <1> 	add	dl, '0'
  2340 00008262 4F                  <1> 	dec     edi
  2341 00008263 8817                <1> 	mov     [edi], dl
  2342 00008265 21C0                <1> 	and	eax, eax
  2343 00008267 75F2                <1> 	jnz	short rediv_tfs_hex
  2344                              <1> 	
  2345 00008269 893D[96620100]      <1> 	mov	[TFS_Dec_Begin], edi
  2346 0000826F BE[12110100]        <1> 	mov	esi, Decimal_File_Count_Header
  2347 00008274 E824E1FFFF          <1> 	call	print_msg
  2348 00008279 BE[1A110100]        <1> 	mov	esi, str_files
  2349 0000827E E81AE1FFFF          <1> 	call	print_msg
  2350 00008283 BE[2B110100]        <1> 	mov	esi, str_dirs
  2351 00008288 E810E1FFFF          <1> 	call	print_msg
  2352 0000828D 8B35[96620100]      <1> 	mov	esi, [TFS_Dec_Begin]
  2353 00008293 E805E1FFFF          <1> 	call	print_msg
  2354 00008298 BE[3C110100]        <1> 	mov	esi, str_bytes
  2355 0000829D E8FBE0FFFF          <1> 	call	print_msg
  2356                              <1> 
  2357 000082A2 C3                  <1> 	retn
  2358                              <1> 
  2359                              <1> pause_dir_scroll:
  2360 000082A3 28E4                <1> 	sub	ah, ah           
  2361 000082A5 E89C89FFFF          <1> 	call	int16h
  2362 000082AA 3C1B                <1> 	cmp	al, 1Bh
  2363 000082AC 0F8428FFFFFF        <1>         je      loc_dir_ok
  2364 000082B2 C605[A5620100]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
  2365 000082B9 E911FFFFFF          <1>         jmp     loc_next_entry
  2366                              <1> 
  2367                              <1> find_first_file:
  2368                              <1> 	; 11/02/2016
  2369                              <1> 	; 10/02/2016
  2370                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2371                              <1> 	; 09/10/2011
  2372                              <1> 	; 17/09/2009
  2373                              <1> 	; 2005
  2374                              <1> 	; INPUT ->
  2375                              <1> 	;	ESI = ASCIIZ File/Dir Name Address (in Current Directory)
  2376                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
  2377                              <1> 	;	      bit 0 = Read Only
  2378                              <1> 	;	      bir 1 = Hidden
  2379                              <1> 	;	      bit 2 = System
  2380                              <1> 	;	      bit 3 = Volume Label
  2381                              <1> 	;	      bit 4 = Directory
  2382                              <1> 	;	      bit 5 = Archive
  2383                              <1> 	;	      bit 6 = Reserved, must be 0
  2384                              <1> 	;	      bit 7 = Reserved, must be 0
  2385                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
  2386                              <1> 	;
  2387                              <1> 	; OUTPUT ->
  2388                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  2389                              <1> 	;	CF = 0 ->
  2390                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
  2391                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
  2392                              <1> 	;	     EAX = File Size
  2393                              <1> 	;	      BL = Attributes of The File/Directory
  2394                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  2395                              <1> 	;             DX > 0 : Ambiguous filename chars are used
  2396                              <1> 	;
  2397                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2398                              <1> 
  2399 000082BE 66A3[56620100]      <1> 	mov	[FindFile_AttributesMask], ax
  2400 000082C4 BF[58620100]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
  2401 000082C9 31C0                <1> 	xor	eax, eax
  2402 000082CB B90B000000          <1> 	mov	ecx, 11
  2403 000082D0 F3AB                <1> 	rep	stosd	; 44 bytes
  2404                              <1> 	;stosw		; +2 bytes 
  2405                              <1> 	    
  2406 000082D2 BF[48620100]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
  2407 000082D7 39FE                <1> 	cmp	esi, edi
  2408 000082D9 7408                <1> 	je	short loc_fff_mfn_ok
  2409 000082DB 89FA                <1> 	mov	edx, edi 
  2410                              <1> 	 ; move 13 bytes
  2411 000082DD A5                  <1> 	movsd
  2412 000082DE A5                  <1> 	movsd
  2413 000082DF A5                  <1> 	movsd
  2414 000082E0 AA                  <1> 	stosb
  2415 000082E1 89D6                <1> 	mov	esi, edx
  2416                              <1> loc_fff_mfn_ok:
  2417 000082E3 BF[F7610100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  2418 000082E8 E8D7200000          <1> 	call	convert_file_name
  2419 000082ED 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  2420                              <1> 
  2421 000082EF 66A1[56620100]      <1> 	mov	ax, [FindFile_AttributesMask]
  2422                              <1> 	;xor	ecx, ecx
  2423 000082F5 30C9                <1> 	xor	cl, cl  
  2424 000082F7 E8D11D0000          <1> 	call	locate_current_dir_file
  2425 000082FC 726E                <1> 	jc	short loc_fff_retn
  2426                              <1> 	; EDI = Directory Entry
  2427                              <1> 	; EBX = Directory Buffer Entry Index/Number
  2428                              <1> 
  2429                              <1> loc_fff_fnf_ln_check:
  2430 000082FE 30ED                <1> 	xor	ch, ch 
  2431 00008300 80F60F              <1> 	xor	dh, 0Fh
  2432 00008303 7408                <1> 	jz	short loc_fff_longname_yes
  2433 00008305 882D[55620100]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
  2434 0000830B EB0C                <1> 	jmp	short loc_fff_longname_no
  2435                              <1> 
  2436                              <1> loc_fff_longname_yes:
  2437                              <1> 	;inc	byte [FindFile_LongNameYes]
  2438 0000830D 8A0D[62610100]      <1> 	mov	cl, [LFN_EntryLength]  
  2439 00008313 880D[55620100]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
  2440                              <1> 
  2441                              <1> loc_fff_longname_no:
  2442                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
  2443 00008319 66891D[80620100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  2444 00008320 6689C2              <1> 	mov	dx, ax ; Ambiguous Filename chars used sign > 0
  2445                              <1> 
  2446 00008323 A0[6E590100]        <1> 	mov	al, [Current_Drv]
  2447 00008328 A2[06620100]        <1> 	mov	[FindFile_Drv], al 
  2448                              <1> 
  2449 0000832D A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2450 00008332 A3[78620100]        <1> 	mov	[FindFile_DirFirstCluster], eax
  2451                              <1> 
  2452 00008337 A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
  2453 0000833C A3[7C620100]        <1> 	mov	[FindFile_DirCluster], eax
  2454                              <1> 
  2455 00008341 66FF05[82620100]    <1> 	inc	word [FindFile_MatchCounter]
  2456                              <1> 
  2457 00008348 89FB                <1> 	mov	ebx, edi
  2458 0000834A 89FE                <1> 	mov	esi, edi
  2459 0000834C BF[58620100]        <1> 	mov	edi, FindFile_DirEntry
  2460 00008351 89F8                <1> 	mov	eax, edi
  2461 00008353 B108                <1> 	mov	cl, 8
  2462 00008355 F3A5                <1> 	rep	movsd
  2463 00008357 89C6                <1> 	mov	esi, eax
  2464 00008359 89DF                <1> 	mov	edi, ebx
  2465                              <1> 
  2466 0000835B A1[74620100]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
  2467                              <1> 
  2468 00008360 8A1D[63620100]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes 
  2469 00008366 8A3D[55620100]      <1> 	mov	bh, [FindFile_LongNameYes]
  2470                              <1> 
  2471                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  2472                              <1> 	;mov	[FindFile_DirEntryNumber], cx
  2473                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
  2474                              <1> 	; ecx = 0
  2475                              <1> 
  2476                              <1> loc_fff_retn:
  2477 0000836C C3                  <1> 	retn
  2478                              <1> 
  2479                              <1> find_next_file:
  2480                              <1> 	; 15/10/2016
  2481                              <1> 	; 10/02/2016
  2482                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2483                              <1> 	; 06/02/2011
  2484                              <1> 	; 17/09/2009
  2485                              <1> 	; 2005
  2486                              <1> 	; INPUT ->
  2487                              <1> 	;	NONE, Find First File Parameters
  2488                              <1> 	; OUTPUT ->
  2489                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  2490                              <1> 	;	CF = 0 -> 
  2491                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
  2492                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
  2493                              <1> 	;	    EAX = File Size
  2494                              <1> 	;	      BL = Attributes of The File/Directory
  2495                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  2496                              <1> 	;             DX > 0 : Ambiguous filename chars are used 
  2497                              <1> 	;
  2498                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2499                              <1> 
  2500 0000836D 66833D[82620100]00  <1> 	cmp	word [FindFile_MatchCounter], 0
  2501 00008375 7707                <1> 	ja	short loc_start_search_next_file
  2502                              <1> 
  2503                              <1> loc_fnf_stc_retn:
  2504 00008377 F9                  <1> 	stc
  2505                              <1> loc_fnf_ax12h_retn:
  2506 00008378 B80C000000          <1> 	mov	eax, 12 ; No More files
  2507                              <1> ;loc_fnf_retn:
  2508 0000837D C3                  <1> 	retn
  2509                              <1> 
  2510                              <1> loc_start_search_next_file:
  2511 0000837E 668B1D[80620100]    <1> 	mov	bx, [FindFile_DirEntryNumber]
  2512 00008385 6643                <1> 	inc	bx
  2513 00008387 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  2514 0000838E 7719                <1> 	ja	short loc_cont_search_next_file
  2515                              <1> 
  2516                              <1> loc_fnf_search:
  2517 00008390 BE[F7610100]        <1> 	mov	esi, Dir_Entry_Name
  2518 00008395 66A1[56620100]      <1> 	mov	ax, [FindFile_AttributesMask]
  2519 0000839B 6631C9              <1> 	xor	cx, cx
  2520 0000839E E82E1E0000          <1> 	call	find_directory_entry
  2521 000083A3 0F8355FFFFFF        <1>         jnc     loc_fff_fnf_ln_check
  2522                              <1> 
  2523                              <1> loc_cont_search_next_file:
  2524 000083A9 31DB                <1> 	xor	ebx, ebx
  2525 000083AB 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  2526 000083B1 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2527 000083B6 01DE                <1> 	add	esi, ebx
  2528                              <1> 
  2529 000083B8 803D[6C590100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2530 000083BF 7608                <1> 	jna	short loc_fnf_check_FAT_type
  2531 000083C1 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2532 000083C5 72B1                <1> 	jb	short loc_fnf_ax12h_retn
  2533 000083C7 EB06                <1> 	jmp	short loc_fnf_check_next_cluster
  2534                              <1>  
  2535                              <1> loc_fnf_check_FAT_type:
  2536 000083C9 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
  2537 000083CD 72A9                <1> 	jb	short loc_fnf_ax12h_retn
  2538                              <1> 
  2539                              <1> loc_fnf_check_next_cluster:
  2540 000083CF A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
  2541 000083D4 E8CA370000          <1> 	call	get_next_cluster
  2542 000083D9 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
  2543 000083DB 09C0                <1> 	or	eax, eax
  2544 000083DD 7498                <1> 	jz	short loc_fnf_stc_retn
  2545                              <1> 	;mov	eax, 17 ;Drive not ready or read error
  2546 000083DF F5                  <1>  	cmc	;stc
  2547                              <1> loc_fnf_retn:
  2548 000083E0 C3                  <1> 	retn
  2549                              <1> 
  2550                              <1> loc_fnf_load_next_dir_cluster:
  2551 000083E1 E8A3390000          <1> 	call	load_FAT_sub_directory
  2552 000083E6 72F8                <1> 	jc	short loc_fnf_retn
  2553 000083E8 6631DB              <1> 	xor	bx, bx
  2554 000083EB 66891D[80620100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  2555 000083F2 EB9C                <1> 	jmp	short loc_fnf_search
  2556                              <1> 
  2557                              <1> get_and_print_longname:
  2558                              <1> 	; 16/10/2016
  2559                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  2560                              <1> 	; 24/01/2010
  2561                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
  2562                              <1> get_longname_fchar:
  2563 000083F4 803E20              <1> 	cmp	byte [esi], 20h
  2564 000083F7 7701                <1> 	ja	short loc_find_longname
  2565                              <1> 	;jb	short loc_longname_retn
  2566                              <1> 	;inc	esi
  2567                              <1> 	;je	short get_longname_fchar
  2568                              <1> ;loc_longname_retn:
  2569 000083F9 C3                  <1> 	retn
  2570                              <1> loc_find_longname:
  2571 000083FA E839210000          <1> 	call	find_longname
  2572 000083FF 7328                <1> 	jnc	short loc_print_longname
  2573                              <1> 	
  2574 00008401 08C0                <1> 	or	al, al
  2575 00008403 741A                <1> 	jz	short loc_longname_not_found
  2576                              <1> 	  
  2577                              <1> 	; 16/10/2016 (15h -> 15, 17)
  2578 00008405 3C0F                <1> 	cmp	al, 15
  2579 00008407 0F84B6F7FFFF        <1> 	je	cd_drive_not_ready ; drive not ready
  2580                              <1> 				   ; or
  2581 0000840D 3C11                <1> 	cmp	al, 17		   ; read error	
  2582 0000840F 0F84AEF7FFFF        <1> 	je	cd_drive_not_ready 
  2583                              <1> 
  2584                              <1> loc_ln_file_dir_not_found:
  2585 00008415 BE[66100100]        <1> 	mov	esi, Msg_File_Directory_Not_Found
  2586                              <1> 	;call	print_msg	
  2587                              <1>         ;retn
  2588 0000841A E97EDFFFFF          <1> 	jmp	print_msg
  2589                              <1> 
  2590                              <1> loc_longname_not_found:
  2591 0000841F BE[85100100]        <1>         mov     esi, Msg_LongName_Not_Found
  2592                              <1> 	;call	print_msg	
  2593                              <1>         ;retn
  2594 00008424 E974DFFFFF          <1> 	jmp	print_msg
  2595                              <1> 
  2596                              <1> loc_print_longname:
  2597                              <1> 	;mov	esi, LongFileName
  2598 00008429 BF[6E5A0100]        <1> 	mov	edi, TextBuffer
  2599 0000842E 57                  <1> 	push	edi 
  2600 0000842F 3C00                <1> 	cmp	al, 0
  2601 00008431 7708                <1> 	ja	short loc_print_longname_1
  2602                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
  2603 00008433 AC                  <1> 	lodsb
  2604 00008434 AA                  <1> 	stosb  
  2605 00008435 08C0                <1> 	or	al, al
  2606 00008437 75FA                <1> 	jnz	short loc_print_FS_longname
  2607 00008439 EB07                <1> 	jmp	short loc_print_longname_2
  2608                              <1> 	;
  2609                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
  2610 0000843B 66AD                <1> 	lodsw
  2611 0000843D AA                  <1> 	stosb  
  2612 0000843E 08C0                <1> 	or	al, al
  2613 00008440 75F9                <1> 	jnz	short loc_print_longname_1
  2614                              <1> 	;
  2615                              <1> loc_print_longname_2:	
  2616 00008442 5E                  <1> 	pop	esi
  2617 00008443 E855DFFFFF          <1> 	call	print_msg
  2618 00008448 BE[D7190100]        <1>   	mov	esi, nextline
  2619                              <1> 	;call	print_msg
  2620                              <1> 	;retn
  2621 0000844D E94BDFFFFF          <1> 	jmp	print_msg	
  2622                              <1> 
  2623                              <1> show_file:
  2624                              <1> 	; 18/02/2016
  2625                              <1> 	; 17/02/2016
  2626                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2627                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
  2628                              <1> 	; 08/11/2009
  2629                              <1> 
  2630                              <1> loc_show_parse_path_name:
  2631 00008452 BF[06620100]        <1> 	mov	edi, FindFile_Drv
  2632 00008457 E833200000          <1> 	call	parse_path_name
  2633 0000845C 0F824CF9FFFF        <1> 	jc	loc_cmd_failed
  2634                              <1> 
  2635                              <1> loc_show_check_filename_exists:
  2636 00008462 BE[48620100]        <1> 	mov	esi, FindFile_Name
  2637 00008467 803E20              <1> 	cmp	byte [esi], 20h
  2638 0000846A 0F863EF9FFFF        <1> 	jna	loc_cmd_failed
  2639                              <1> 
  2640                              <1> 	; 15/02/2016 (invalid file name check)
  2641 00008470 E807020000          <1> 	call	check_filename 	
  2642 00008475 730A                <1> 	jnc	short loc_show_change_drv
  2643                              <1> 
  2644 00008477 BE[52110100]        <1> 	mov	esi, Msg_invalid_name_chars
  2645 0000847C E91CDFFFFF          <1> 	jmp	print_msg
  2646                              <1>    
  2647                              <1> loc_show_change_drv:
  2648 00008481 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  2649 00008487 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  2650 0000848D 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  2651 00008493 38F2                <1> 	cmp	dl, dh
  2652 00008495 740B                <1> 	je	short loc_show_change_directory
  2653 00008497 E87FEAFFFF          <1> 	call	change_current_drive
  2654                              <1> 	;jc	loc_file_rw_cmd_failed
  2655 0000849C 0F8237F9FFFF        <1> 	jc	loc_run_cmd_failed
  2656                              <1> 
  2657                              <1> loc_show_change_directory:
  2658 000084A2 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  2659 000084A9 7618                <1> 	jna	short loc_findload_showfile
  2660                              <1> 
  2661 000084AB FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  2662 000084B1 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  2663 000084B6 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2664 000084B8 E8BC190000          <1> 	call	change_current_directory
  2665                              <1> 	;jc	loc_file_rw_cmd_failed
  2666 000084BD 0F8216F9FFFF        <1> 	jc	loc_run_cmd_failed
  2667                              <1> 
  2668                              <1> ;loc_show_change_prompt_dir_string:
  2669                              <1> 	;call	change_prompt_dir_string
  2670                              <1> 
  2671                              <1> loc_findload_showfile:
  2672                              <1> 	; 15/02/2016
  2673 000084C3 BE[48620100]        <1> 	mov	esi, FindFile_Name
  2674 000084C8 BF[F7610100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  2675 000084CD E8F21E0000          <1> 	call	convert_file_name
  2676 000084D2 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  2677                              <1> 
  2678 000084D4 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
  2679                              <1> 	; Directory attribute : 10h
  2680                              <1> 	; Volume name attribute: 8h
  2681 000084D6 B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
  2682                              <1> 	;
  2683 000084D8 6631C9              <1> 	xor	cx, cx  
  2684 000084DB E8ED1B0000          <1> 	call	locate_current_dir_file
  2685                              <1> 	;jc	loc_file_rw_cmd_failed
  2686 000084E0 0F82F3F8FFFF        <1> 	jc	loc_run_cmd_failed
  2687                              <1> 
  2688                              <1> loc_show_load_file:
  2689                              <1> 	; EDI = Directory Entry
  2690 000084E6 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
  2691 000084EA C1E010              <1> 	shl	eax, 16
  2692 000084ED 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
  2693 000084F1 A3[B0620100]        <1> 	mov	[Show_Cluster], eax
  2694 000084F6 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
  2695 000084F9 21C0                <1> 	and	eax, eax ; Empty file !
  2696 000084FB 0F8491000000        <1>         jz      end_of_show_file 
  2697 00008501 A3[B4620100]        <1> 	mov	[Show_FileSize], eax
  2698 00008506 31C0                <1> 	xor	eax, eax
  2699 00008508 A3[B8620100]        <1> 	mov	[Show_FilePointer], eax ; 0
  2700 0000850D 66A3[BC620100]      <1> 	mov	[Show_ClusterPointer], ax ; 0
  2701 00008513 29DB                <1> 	sub	ebx, ebx
  2702 00008515 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  2703 0000851B BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2704 00008520 01DE                <1> 	add	esi, ebx
  2705 00008522 8935[AC620100]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
  2706                              <1> 
  2707 00008528 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0	
  2708 0000852C 7713                <1> 	ja	short loc_show_calculate_cluster_size
  2709                              <1> 	; Singlix FS
  2710                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
  2711 0000852E 8B15[B0620100]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)	
  2712 00008534 8915[A8620100]      <1> 	mov	[Show_FDT], edx
  2713 0000853A 31C0                <1> 	xor	eax, eax
  2714 0000853C A3[B0620100]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
  2715                              <1> 				    ; (next time it will be 1)			
  2716                              <1> loc_show_calculate_cluster_size:
  2717 00008541 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
  2718                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS	
  2719 00008545 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
  2720                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  2721 00008548 F7E3                <1> 	mul	ebx	
  2722                              <1> 
  2723                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
  2724                              <1> 	;ja	short end_of_show_file	
  2725 0000854A 66A3[BE620100]      <1> 	mov	[Show_ClusterSize], ax
  2726                              <1> 
  2727                              <1> loc_start_show_file:
  2728 00008550 BE[D7190100]        <1> 	mov	esi, nextline
  2729 00008555 E843DEFFFF          <1> 	call	print_msg
  2730                              <1> 
  2731 0000855A A1[B0620100]        <1> 	mov	eax, [Show_Cluster]
  2732 0000855F C605[C0620100]17    <1> 	mov	byte [Show_RowCount], 23
  2733                              <1> 
  2734                              <1> 	; 17/02/2016
  2735 00008566 8B35[AC620100]      <1> 	mov	esi, [Show_LDDDT]
  2736                              <1> 
  2737                              <1> loc_show_next_cluster:
  2738                              <1> 	; 15/02/2016
  2739 0000856C BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  2740                              <1> 	; ESI = Logical DOS drv description table address
  2741 00008571 E851380000          <1> 	call	read_cluster
  2742                              <1> 	;jc	loc_file_rw_cmd_failed
  2743 00008576 0F825DF8FFFF        <1> 	jc	loc_run_cmd_failed
  2744                              <1> 
  2745 0000857C 31DB                <1> 	xor 	ebx, ebx
  2746                              <1> loc_show_next_byte:
  2747 0000857E 803D[C0620100]00    <1> 	cmp	byte [Show_RowCount], 0
  2748 00008585 7521                <1> 	jne	short pass_show_wait_for_key
  2749 00008587 30E4                <1> 	xor	ah, ah
  2750 00008589 E8B886FFFF          <1> 	call	int16h
  2751 0000858E 3C1B                <1> 	cmp	al, 1Bh
  2752 00008590 750F                <1> 	jne	short pass_exit_show
  2753                              <1> end_of_show_file:
  2754                              <1> pass_show_file:
  2755 00008592 BE[D7190100]        <1> 	mov	esi, nextline
  2756 00008597 E801DEFFFF          <1> 	call	print_msg
  2757 0000859C E94B010000          <1> 	jmp	loc_file_rw_restore_retn
  2758                              <1> 
  2759                              <1> pass_exit_show:
  2760 000085A1 C605[C0620100]14    <1> 	mov	byte [Show_RowCount], 20
  2761                              <1> pass_show_wait_for_key:
  2762 000085A8 81C300000700        <1> 	add	ebx, Cluster_Buffer
  2763 000085AE 8A03                <1> 	mov	al, [ebx]
  2764 000085B0 3C0D                <1> 	cmp	al, 0Dh
  2765 000085B2 0F8590000000        <1>         jne     loc_show_check_tab_space
  2766 000085B8 FE0D[C0620100]      <1> 	dec	byte [Show_RowCount]
  2767                              <1> pass_show_dec_rowcount:
  2768 000085BE B307                <1> 	mov	bl, 7 ; (light gray character color, black background)
  2769 000085C0 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  2770 000085C6 E81797FFFF          <1> 	call	_write_tty
  2771                              <1> loc_show_check_eof:
  2772 000085CB FF05[B8620100]      <1> 	inc	dword [Show_FilePointer]
  2773 000085D1 A1[B8620100]        <1> 	mov	eax, [Show_FilePointer]
  2774 000085D6 3B05[B4620100]      <1> 	cmp	eax, [Show_FileSize]
  2775 000085DC 73B4                <1> 	jnb	short end_of_show_file
  2776 000085DE 66FF05[BC620100]    <1> 	inc	word [Show_ClusterPointer]
  2777 000085E5 0FB71D[BC620100]    <1> 	movzx	ebx, word [Show_ClusterPointer]
  2778                              <1> 
  2779                              <1> 	; 17/02/2016
  2780                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
  2781 000085EC 66F7C3FF01          <1>         test    bx, 1FFh ;  1 to 511
  2782 000085F1 758B                <1> 	jnz	short loc_show_next_byte
  2783                              <1> 
  2784                              <1> 	; 16/02/2016
  2785 000085F3 8B35[AC620100]      <1> 	mov	esi, [Show_LDDDT]
  2786                              <1> 	;
  2787 000085F9 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2788 000085FD 7719                <1> 	ja	short loc_show_check_fat_cluster_size
  2789                              <1> 
  2790                              <1> 	; Singlix FS
  2791                              <1> 	; 1 sector, more... (cluster size = 1 sector)
  2792 000085FF A1[B0620100]        <1> 	mov	eax, [Show_Cluster]
  2793 00008604 40                  <1> 	inc	eax
  2794 00008605 A3[B0620100]        <1> 	mov	[Show_Cluster], eax
  2795                              <1> 
  2796 0000860A 6621DB              <1> 	and	bx, bx ; 65536 -> 0
  2797 0000860D 0F856BFFFFFF        <1>         jnz	loc_show_next_byte
  2798 00008613 E954FFFFFF          <1> 	jmp     loc_show_next_cluster
  2799                              <1> 	 
  2800                              <1> loc_show_check_fat_cluster_size:
  2801                              <1> 	; 17/02/2016
  2802 00008618 663B1D[BE620100]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
  2803 0000861F 0F8259FFFFFF        <1>         jb	loc_show_next_byte
  2804 00008625 66C705[BC620100]00- <1> 	mov	word [Show_ClusterPointer], 0
  2804 0000862D 00                  <1>
  2805                              <1> 
  2806 0000862E A1[B0620100]        <1> 	mov	eax, [Show_Cluster]
  2807                              <1> 	;mov	esi, [Show_LDDDT]
  2808                              <1> loc_show_get_next_cluster:
  2809 00008633 E86B350000          <1> 	call	get_next_cluster
  2810                              <1> 	;jc	loc_file_rw_cmd_failed
  2811 00008638 0F829BF7FFFF        <1> 	jc	loc_run_cmd_failed
  2812                              <1> loc_show_update_ccluster:
  2813 0000863E A3[B0620100]        <1> 	mov	[Show_Cluster], eax			
  2814 00008643 E924FFFFFF          <1>         jmp     loc_show_next_cluster
  2815                              <1> 
  2816                              <1> loc_show_check_tab_space:
  2817 00008648 3C09                <1> 	cmp	al, 09h
  2818 0000864A 0F856EFFFFFF        <1>         jne     pass_show_dec_rowcount
  2819                              <1> loc_show_put_tab_space:
  2820 00008650 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  2821 00008656 E81693FFFF          <1> 	call	get_cpos
  2822                              <1> 	; dl = cursor column
  2823 0000865B 80E207              <1> 	and	dl, 7 ; 18/02/2016
  2824                              <1> 	;shr	bh, 1 ; [ACTIVE_PAGE]
  2825 0000865E 8A3D[D6580100]      <1> 	mov	bh, [ACTIVE_PAGE]
  2826 00008664 B307                <1> 	mov	bl, 7 ; color attribute
  2827                              <1> loc_show_put_space_chars:
  2828 00008666 B020                <1> 	mov	al, 20h ; space
  2829                              <1> 	;mov	bh, [ACTIVE_PAGE] ; [ptty]
  2830                              <1> 	;mov	bl, 7 ; color attribute
  2831                              <1> 	;push	dx
  2832 00008668 52                  <1> 	push	edx ; 29/12/2017
  2833 00008669 E87496FFFF          <1> 	call	_write_tty
  2834 0000866E 5A                  <1> 	pop	edx ; 29/12/2017
  2835                              <1> 	;pop	dx
  2836                              <1> 	; 18/02/2016
  2837 0000866F 80FA07              <1> 	cmp	dl, 7
  2838 00008672 0F8353FFFFFF        <1> 	jnb	loc_show_check_eof
  2839 00008678 FEC2                <1> 	inc	dl
  2840 0000867A EBEA                <1> 	jmp	short loc_show_put_space_chars
  2841                              <1> 
  2842                              <1> check_filename:
  2843                              <1> 	; 10/10/2016
  2844                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2845                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
  2846                              <1> 	; 10/07/2010
  2847                              <1> 	; Derived from 'proc_check_filename'
  2848                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  2849                              <1> 	;
  2850                              <1> 	; INPUT -> 
  2851                              <1> 	;	ESI = Dot File Name Location
  2852                              <1> 	; OUTPUT ->
  2853                              <1> 	;	cf = 1 -> error code in AL
  2854                              <1> 	;	     AL = ERR_INV_FILE_NAME (=26)
  2855                              <1> 	;		  Invalid file name chars   
  2856                              <1> 	;	cf = 0 -> valid file name
  2857                              <1> 	; 
  2858                              <1> 	;(EAX, ECX, EDI will be changed)
  2859                              <1> 
  2860                              <1> check_invalid_filename_chars:
  2861                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2862                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
  2863                              <1> 	; 10/02/2010
  2864                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
  2865                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  2866                              <1> 	;
  2867                              <1> 	; INPUT -> 
  2868                              <1> 	;	ESI = ASCIIZ FileName
  2869                              <1> 	; OUTPUT ->
  2870                              <1> 	;	cf = 1 -> invalid
  2871                              <1> 	;	cf = 0 -> valid
  2872                              <1> 	; 
  2873                              <1> 	;(EAX, ECX, EDI will be changed)
  2874                              <1>   
  2875 0000867C 56                  <1> 	push	esi
  2876                              <1> 
  2877 0000867D BF[3A0E0100]        <1>         mov     edi, invalid_fname_chars
  2878 00008682 AC                  <1> 	lodsb
  2879                              <1> check_filename_next_char:
  2880 00008683 B914000000          <1> 	mov	ecx, sizeInvFnChars
  2881 00008688 BF[3A0E0100]        <1> 	mov	edi, invalid_fname_chars
  2882                              <1> loc_scan_invalid_filename_char:
  2883 0000868D AE                  <1> 	scasb 
  2884 0000868E 741F                <1> 	je	short loc_invalid_filename_stc 
  2885 00008690 E2FB                <1> 	loop	loc_scan_invalid_filename_char
  2886 00008692 AC                  <1> 	lodsb
  2887 00008693 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
  2888 00008695 77EC                <1> 	ja	short check_filename_next_char
  2889                              <1> 
  2890                              <1> check_filename_dot:
  2891 00008697 8B3424              <1> 	mov	esi, [esp]
  2892                              <1> 
  2893 0000869A B421                <1> 	mov	ah, 21h
  2894 0000869C B908000000          <1> 	mov	ecx, 8
  2895                              <1> loc_check_filename_next_char:
  2896 000086A1 AC                  <1> 	lodsb
  2897 000086A2 3C2E                <1> 	cmp	al, 2Eh
  2898 000086A4 7511                <1> 	jne	short pass_check_fn_dot_check
  2899                              <1> loc_check_filename_ext_0:
  2900 000086A6 AC                  <1> 	lodsb
  2901 000086A7 38E0                <1> 	cmp	al, ah ; 21h
  2902 000086A9 7205                <1> 	jb	short loc_invalid_filename
  2903 000086AB 3C2E                <1> 	cmp	al, 2Eh
  2904 000086AD 7519                <1> 	jne	short loc_check_filename_ext_1
  2905                              <1> 
  2906                              <1> loc_invalid_filename_stc:
  2907                              <1> loc_check_fn_stc_rtn:
  2908 000086AF F9                  <1> 	stc
  2909                              <1> loc_invalid_filename:
  2910                              <1> 	; 10/10/2016 (0Bh -> 26)
  2911 000086B0 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; (=26)
  2912                              <1> 	; Invalid file name chars
  2913                              <1> loc_check_fn_rtn:
  2914 000086B5 5E                  <1> 	pop	esi
  2915 000086B6 C3                  <1> 	retn
  2916                              <1> 
  2917                              <1> pass_check_fn_dot_check:
  2918 000086B7 38E0                <1> 	cmp	al, ah ; 21h
  2919 000086B9 7224                <1> 	jb	short loc_check_fn_clc_rtn
  2920 000086BB E2E4                <1> 	loop	loc_check_filename_next_char
  2921 000086BD AC                  <1> 	lodsb
  2922 000086BE 38E0                <1> 	cmp	al, ah ; 21h
  2923 000086C0 721D                <1> 	jb	short loc_check_fn_clc_rtn
  2924 000086C2 3C2E                <1> 	cmp	al, 2Eh
  2925 000086C4 75E9                <1> 	jne	short loc_check_fn_stc_rtn
  2926 000086C6 EBDE                <1> 	jmp	short loc_check_filename_ext_0
  2927                              <1> 
  2928                              <1> loc_check_filename_ext_1:
  2929 000086C8 AC                  <1> 	lodsb
  2930 000086C9 38E0                <1> 	cmp	al, ah ; 21h
  2931 000086CB 7212                <1> 	jb	short loc_check_fn_clc_rtn
  2932 000086CD 3C2E                <1> 	cmp	al, 2Eh
  2933 000086CF 74DE                <1> 	je	short loc_check_fn_stc_rtn
  2934 000086D1 AC                  <1> 	lodsb
  2935 000086D2 38E0                <1> 	cmp	al, ah ; 21h
  2936 000086D4 7209                <1> 	jb	short loc_check_fn_clc_rtn
  2937 000086D6 3C2E                <1> 	cmp	al, 2Eh
  2938 000086D8 74D5                <1> 	je	short loc_check_fn_stc_rtn
  2939 000086DA AC                  <1> 	lodsb
  2940 000086DB 38E0                <1> 	cmp	al, ah ; 21h
  2941 000086DD 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
  2942                              <1> 
  2943                              <1> loc_check_fn_clc_rtn:
  2944 000086DF 5E                  <1> 	pop	esi
  2945 000086E0 F8                  <1> 	clc
  2946 000086E1 C3                  <1> 	retn
  2947                              <1> 
  2948                              <1> loc_print_deleted_message:
  2949 000086E2 BE[27120100]        <1> 	mov	esi, Msg_Deleted
  2950 000086E7 E8B1DCFFFF          <1> 	call	print_msg
  2951                              <1> 
  2952                              <1> 	;clc
  2953                              <1> 
  2954                              <1> loc_file_rw_restore_retn:
  2955                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2956                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
  2957                              <1> loc_file_rw_cmd_failed:
  2958 000086EC 9C                  <1> 	pushf 
  2959 000086ED E84FF7FFFF          <1> 	call	restore_cdir_after_cmd_fail	
  2960 000086F2 9D                  <1> 	popf
  2961 000086F3 720D                <1> 	jc	short loc_file_rw_check_write_fault
  2962 000086F5 C3                  <1> 	retn
  2963                              <1> 
  2964                              <1> loc_permission_denied:
  2965                              <1> 	; 27/02/2016
  2966 000086F6 BE[34120100]        <1> 	mov	esi, Msg_Permission_Denied
  2967 000086FB E89DDCFFFF          <1> 	call	print_msg
  2968 00008700 EBEA                <1> 	jmp	short loc_file_rw_restore_retn
  2969                              <1> 
  2970                              <1> loc_file_rw_check_write_fault:
  2971                              <1> 	;cmp	al, 1Dh ; Write Fault
  2972 00008702 3C12                <1>         cmp	al, 18 ; 05/11/2016
  2973 00008704 0F85D4F6FFFF        <1> 	jne     loc_run_cmd_failed_cmp_al
  2974 0000870A BE[1B100100]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
  2975                              <1> 	;call	print_msg
  2976                              <1> 	;retn
  2977 0000870F E989DCFFFF          <1> 	jmp	print_msg
  2978                              <1> 
  2979                              <1> make_directory:
  2980                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  2981                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
  2982                              <1> 	; 14/08/2010
  2983                              <1> 	; 10/07/2010
  2984                              <1> 	; 29/11/2009
  2985                              <1> 	;
  2986                              <1> get_mkdir_fchar:
  2987                              <1> 	; esi = directory name
  2988 00008714 803E20              <1> 	cmp	byte [esi], 20h
  2989 00008717 7701                <1>         ja	short loc_mkdir_parse_path_name
  2990                              <1> 
  2991                              <1> loc_mkdir_nodirname_retn:
  2992 00008719 C3                  <1> 	retn
  2993                              <1> 
  2994                              <1> loc_mkdir_parse_path_name:
  2995 0000871A BF[06620100]        <1> 	mov	edi, FindFile_Drv
  2996 0000871F E86B1D0000          <1>         call    parse_path_name
  2997 00008724 0F8284F6FFFF        <1> 	jc	loc_cmd_failed
  2998                              <1> 
  2999                              <1> loc_mkdir_check_dirname_exists:
  3000 0000872A BE[48620100]        <1> 	mov	esi, FindFile_Name
  3001 0000872F 803E20              <1> 	cmp	byte [esi], 20h
  3002 00008732 0F8676F6FFFF        <1> 	jna	loc_cmd_failed
  3003 00008738 8935[C4620100]      <1> 	mov	[DelFile_FNPointer], esi
  3004 0000873E E839FFFFFF          <1> 	call	check_filename
  3005 00008743 7259                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
  3006                              <1> 
  3007                              <1> loc_mkdir_drv:
  3008 00008745 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  3009 0000874B 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  3010                              <1> 	
  3011 00008751 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  3012 00008757 38F2                <1> 	cmp	dl, dh
  3013 00008759 7407                <1> 	je	short loc_mkdir_change_directory
  3014                              <1> 
  3015 0000875B E8BBE7FFFF          <1> 	call	change_current_drive
  3016 00008760 728A                <1> 	jc	loc_file_rw_cmd_failed
  3017                              <1> 
  3018                              <1> loc_mkdir_change_directory:
  3019 00008762 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3020 00008769 7614                <1> 	jna	short loc_mkdir_find_directory
  3021                              <1> 
  3022 0000876B FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3023 00008771 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  3024 00008776 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3025 00008778 E8FC160000          <1> 	call	change_current_directory
  3026 0000877D 722E                <1> 	jc	short loc_mkdir_check_error_code
  3027                              <1> 
  3028                              <1> ;loc_mkdir_change_prompt_dir_string:
  3029                              <1> 	;call	change_prompt_dir_string
  3030                              <1> 
  3031                              <1> loc_mkdir_find_directory:
  3032                              <1> 	;mov	esi, FindFile_Name
  3033 0000877F 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3034                              <1> 	;xor	eax, eax
  3035 00008785 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
  3036 00008788 E831FBFFFF          <1> 	call	find_first_file
  3037 0000878D 721E                <1> 	jc	short loc_mkdir_check_error_code
  3038                              <1> 
  3039                              <1> loc_mkdir_directory_found:
  3040 0000878F BE[7F110100]        <1> 	mov	esi, Msg_Name_Exists
  3041 00008794 E804DCFFFF          <1> 	call	print_msg
  3042                              <1> 
  3043 00008799 E94EFFFFFF          <1>         jmp     loc_file_rw_restore_retn
  3044                              <1> 
  3045                              <1> loc_mkdir_invalid_dir_name_chars:
  3046 0000879E BE[52110100]        <1> 	mov	esi, Msg_invalid_name_chars
  3047 000087A3 E8F5DBFFFF          <1> 	call	print_msg
  3048                              <1> 
  3049 000087A8 E93FFFFFFF          <1>         jmp     loc_file_rw_restore_retn
  3050                              <1> 
  3051                              <1> loc_mkdir_check_error_code:
  3052 000087AD 3C02                <1> 	cmp	al, 2
  3053                              <1> 	;je	short loc_mkdir_directory_not_found
  3054 000087AF 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
  3055 000087B1 F9                  <1> 	stc
  3056 000087B2 E935FFFFFF          <1>         jmp     loc_file_rw_cmd_failed
  3057                              <1> 
  3058                              <1> loc_mkdir_directory_not_found:
  3059                              <1> loc_mkdir_ask_for_yes_no:
  3060 000087B7 BE[A0110100]        <1> 	mov	esi, Msg_DoYouWantMkdir
  3061 000087BC E8DCDBFFFF          <1> 	call	print_msg
  3062 000087C1 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3063 000087C7 E8D1DBFFFF          <1> 	call	print_msg
  3064 000087CC BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  3065 000087D1 E8C7DBFFFF          <1> 	call	print_msg
  3066                              <1> 
  3067 000087D6 C605[C9110100]20    <1> 	mov	byte [Y_N_nextline], 20h
  3068                              <1> 
  3069                              <1> loc_mkdir_ask_again:
  3070 000087DD 30E4                <1> 	xor	ah, ah
  3071 000087DF E86284FFFF          <1> 	call	int16h
  3072 000087E4 3C1B                <1> 	cmp	al, 1Bh
  3073                              <1> 	;je	short loc_do_not_make_directory
  3074 000087E6 7439                <1> 	je	short loc_mkdir_y_n_escape
  3075 000087E8 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
  3076 000087EA 3C59                <1> 	cmp	al, 'Y' ; 'yes'
  3077 000087EC 7404                <1> 	je	short loc_mkdir_yes_make_directory
  3078 000087EE 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3079 000087F0 75EB                <1> 	jne	short loc_mkdir_ask_again
  3080                              <1> 
  3081                              <1> loc_do_not_make_directory:
  3082                              <1> loc_mkdir_yes_make_directory:
  3083 000087F2 E82E000000          <1> 	call	y_n_answer ; 29/12/2017
  3084                              <1> 	;cmp	al, 'Y' ; 'yes'
  3085                              <1> 	;cmc
  3086                              <1>         ;jnc	loc_file_rw_restore_retn
  3087 000087F7 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3088 000087F9 0F84EDFEFFFF        <1>         je	loc_file_rw_restore_retn  
  3089                              <1> 
  3090                              <1> loc_mkdir_call_make_sub_directory:
  3091 000087FF 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3092 00008805 B110                <1> 	mov	cl, 10h ; Directory attributes 
  3093 00008807 E8821D0000          <1> 	call	make_sub_directory
  3094                              <1> loc_rename_file_ok: ; 06/03/2016
  3095 0000880C 0F82DAFEFFFF        <1>         jc	loc_file_rw_cmd_failed
  3096                              <1> move_source_file_to_destination_OK:
  3097 00008812 BE[CD110100]        <1> 	mov	esi, Msg_OK
  3098 00008817 E881DBFFFF          <1> 	call	print_msg
  3099 0000881C E9CBFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3100                              <1> 
  3101                              <1> loc_mkdir_y_n_escape:
  3102 00008821 B04E                <1> 	mov	al, 'N' ; 'no'
  3103 00008823 EBCD                <1> 	jmp	short loc_do_not_make_directory
  3104                              <1> 
  3105                              <1> y_n_answer:
  3106                              <1> 	; 29/12/2017
  3107 00008825 A2[C9110100]        <1> 	mov	[Y_N_nextline], al
  3108                              <1> 	;push	ax
  3109 0000882A 50                  <1> 	push	eax
  3110 0000882B BE[C9110100]        <1> 	mov	esi, Y_N_nextline
  3111 00008830 E868DBFFFF          <1> 	call	print_msg
  3112 00008835 58                  <1> 	pop	eax
  3113                              <1> 	;pop	ax
  3114 00008836 C3                  <1> 	retn
  3115                              <1> 
  3116                              <1> delete_directory:
  3117                              <1> 	; 29/12/2017
  3118                              <1> 	; 15/10/2016
  3119                              <1> 	; 01/03/2016, 06/03/2016
  3120                              <1> 	; 27/02/2016, 28/02/2016, 29/02/2016
  3121                              <1> 	; 26/02/2016 (TRDOS 386 = TRDOS v2.0)
  3122                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
  3123                              <1> 	; 05/06/2010
  3124                              <1> 	;
  3125                              <1> get_fchar:
  3126                              <1> 	; esi = directory name
  3127 00008837 803E20              <1> 	cmp	byte [esi], 20h
  3128 0000883A 7701                <1>         ja	short loc_rmdir_parse_path_name
  3129                              <1> 
  3130                              <1> loc_rmdir_nodirname_retn:
  3131 0000883C C3                  <1> 	retn
  3132                              <1> 
  3133                              <1> loc_rmdir_parse_path_name:
  3134 0000883D BF[06620100]        <1> 	mov	edi, FindFile_Drv
  3135 00008842 E8481C0000          <1> 	call	parse_path_name
  3136 00008847 0F8261F5FFFF        <1> 	jc	loc_cmd_failed
  3137                              <1> 
  3138                              <1> loc_rmdir_check_dirname_exists:
  3139 0000884D BE[48620100]        <1> 	mov	esi, FindFile_Name
  3140 00008852 803E20              <1> 	cmp	byte [esi], 20h
  3141 00008855 0F8653F5FFFF        <1> 	jna	loc_cmd_failed
  3142 0000885B 8935[C4620100]      <1> 	mov	[DelFile_FNPointer], esi 
  3143                              <1> 
  3144                              <1> loc_rmdir_drv:
  3145 00008861 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  3146 00008867 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  3147                              <1> 
  3148 0000886D 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  3149 00008873 38F2                <1> 	cmp	dl, dh
  3150 00008875 740B                <1> 	je	short loc_rmdir_change_directory
  3151                              <1> 
  3152 00008877 E89FE6FFFF          <1> 	call	change_current_drive
  3153 0000887C 0F826AFEFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3154                              <1> 
  3155                              <1> loc_rmdir_change_directory:
  3156 00008882 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3157 00008889 7614                <1> 	jna	short loc_rmdir_find_directory
  3158                              <1> 
  3159 0000888B FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3160 00008891 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  3161 00008896 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3162 00008898 E8DC150000          <1> 	call	change_current_directory
  3163 0000889D 7211                <1> 	jc	short loc_rmdir_check_error_code
  3164                              <1> 
  3165                              <1> ;loc_rmdir_change_prompt_dir_string:
  3166                              <1> 	;call	change_prompt_dir_string
  3167                              <1> 
  3168                              <1> loc_rmdir_find_directory:
  3169                              <1> 	;mov	esi, FindFile_Name
  3170 0000889F 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3171 000088A5 66B81008            <1> 	mov	ax, 0810h ; Only directories
  3172 000088A9 E810FAFFFF          <1> 	call	find_first_file
  3173 000088AE 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
  3174                              <1> 
  3175                              <1> loc_rmdir_check_error_code:
  3176 000088B0 3C02                <1> 	cmp	al, 2
  3177 000088B2 740B                <1> 	je	short loc_rmdir_directory_not_found
  3178 000088B4 F9                  <1> 	stc
  3179 000088B5 E932FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3180                              <1> 
  3181                              <1> loc_rmdir_ambgfn_check:
  3182 000088BA 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3183 000088BD 740F                <1> 	jz	short loc_rmdir_directory_found
  3184                              <1> 
  3185                              <1> loc_rmdir_directory_not_found:
  3186 000088BF BE[3D100100]        <1> 	mov	esi, Msg_Dir_Not_Found
  3187 000088C4 E8D4DAFFFF          <1> 	call	print_msg
  3188                              <1> 
  3189 000088C9 E91EFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3190                              <1> 
  3191                              <1> loc_rmdir_directory_found:
  3192 000088CE 80E307              <1> 	and	bl, 07h ; Attributes
  3193 000088D1 0F851FFEFFFF        <1> 	jnz	loc_permission_denied
  3194                              <1> 
  3195                              <1> loc_rmdir_save_lnel: ; 28/02/2016
  3196                              <1>        ;mov	bh, [LongName_EntryLength]
  3197 000088D7 883D[CE620100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  3198                              <1> 	; edi = Directory Entry Offset (DirBuff)
  3199                              <1> 	; esi = Directory Entry (FFF Structure)
  3200                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
  3201                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
  3202                              <1>         ;shl	eax, 16
  3203                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
  3204                              <1> 	; ROOT Dir First Cluster = 0
  3205                              <1>         ;cmp	eax, 2
  3206                              <1> 	;jb	loc_update_direntry_1
  3207                              <1> 
  3208                              <1> pass_rmdir_fc_check:
  3209 000088DD 57                  <1> 	push	edi ; * (29/02/2016)
  3210                              <1> 
  3211 000088DE BE[D3110100]        <1> 	mov	esi, Msg_DoYouWantRmDir
  3212 000088E3 E8B5DAFFFF          <1> 	call	print_msg
  3213 000088E8 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3214 000088EE E8AADAFFFF          <1> 	call	print_msg
  3215 000088F3 BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  3216 000088F8 E8A0DAFFFF          <1> 	call	print_msg
  3217                              <1> 
  3218                              <1> loc_rmdir_ask_again:
  3219 000088FD 30E4                <1> 	xor	ah, ah
  3220 000088FF E84283FFFF          <1> 	call	int16h
  3221 00008904 3C1B                <1> 	cmp	al, 1Bh
  3222                              <1> 	;je	short loc_do_not_delete_directory
  3223 00008906 7433                <1>         je      loc_rmdir_y_n_escape ; 06/03/2016
  3224 00008908 24DF                <1> 	and	al, 0DFh
  3225 0000890A A2[C9110100]        <1> 	mov	[Y_N_nextline], al
  3226 0000890F 3C59                <1> 	cmp	al, 'Y'
  3227 00008911 7404                <1> 	je	short loc_rmdir_yes_delete_directory
  3228 00008913 3C4E                <1> 	cmp	al, 'N'
  3229 00008915 75E6                <1> 	jne	short loc_rmdir_ask_again
  3230                              <1> 
  3231                              <1> loc_do_not_delete_directory:
  3232                              <1> loc_rmdir_yes_delete_directory:
  3233 00008917 E809FFFFFF          <1> 	call	y_n_answer ; 29/12/2017
  3234 0000891C 5F                  <1> 	pop	edi ; * (29/02/2016)
  3235                              <1> 	;cmp	al, 'Y' ; 'yes'
  3236                              <1> 	;cmc
  3237                              <1>         ;jnc	loc_file_rw_restore_retn
  3238 0000891D 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3239 0000891F 0F84C7FDFFFF        <1>         je	loc_file_rw_restore_retn 
  3240                              <1> 
  3241                              <1> 	; 29/12/2017
  3242 00008925 E869000000          <1> 	call	delete_sub_directory
  3243 0000892A 7213                <1> 	jc	short loc_rmdir_cmd_failed
  3244                              <1> 
  3245                              <1> loc_rmdir_ok:
  3246 0000892C BE[CD110100]        <1> 	mov	esi, Msg_OK
  3247 00008931 E867DAFFFF          <1> 	call	print_msg
  3248 00008936 E9B1FDFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3249                              <1> 
  3250                              <1> loc_rmdir_y_n_escape:
  3251 0000893B B04E                <1> 	mov	al, 'N' ; 'no'
  3252 0000893D EBD8                <1>         jmp     loc_do_not_delete_directory
  3253                              <1> 
  3254                              <1> loc_rmdir_cmd_failed:
  3255                              <1> 	; 29/12/2017
  3256 0000893F 09C0                <1> 	or	eax, eax ; EAX = 0 -> Directory not empty!
  3257 00008941 7426                <1> 	jz	short loc_rmdir_directory_not_empty
  3258                              <1> 
  3259                              <1> 	; EAX > 0 -> Error code in AL (or AX or EAX)
  3260                              <1> 
  3261 00008943 833D[82600100]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
  3262 0000894A 0F829CFDFFFF        <1> 	jb	loc_file_rw_cmd_failed	
  3263 00008950 F9                  <1> 	stc
  3264                              <1> loc_rmdir_cmd_return:
  3265                              <1> 	; 01/03/2016
  3266 00008951 9C                  <1> 	pushf
  3267                              <1> 	; ESI = Logical DOS Drive Description Table address	
  3268 00008952 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
  3269                              <1> 	           ; BL = 0 -> Recalculate free cluster count
  3270 00008956 50                  <1> 	push	eax
  3271 00008957 E8C3380000          <1> 	call	calculate_fat_freespace	
  3272 0000895C 58                  <1> 	pop	eax
  3273 0000895D 9D                  <1> 	popf
  3274 0000895E 0F8288FDFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3275 00008964 E983FDFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3276                              <1> 
  3277                              <1> loc_rmdir_directory_not_empty:
  3278 00008969 BE[F4110100]        <1> 	mov	esi, Msg_Dir_Not_Empty
  3279 0000896E E82ADAFFFF          <1> 	call	print_msg
  3280                              <1> 	; 01/03/2016
  3281 00008973 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  3282 00008978 09C0                <1> 	or	eax, eax ; 0 ?
  3283 0000897A 0F846CFDFFFF        <1> 	jz	loc_file_rw_restore_retn
  3284                              <1> 	; ESI = Logical DOS Drive Description Table address	
  3285 00008980 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
  3286                              <1> 	           ; BL = 1 -> add free clusters
  3287 00008984 E896380000          <1> 	call	calculate_fat_freespace
  3288 00008989 09C9                <1> 	or	ecx, ecx
  3289 0000898B 0F845BFDFFFF        <1>         jz      loc_file_rw_restore_retn ; ecx = 0 -> OK
  3290                              <1> 	; ecx > 0 -> Error (Recalculation is needed)
  3291 00008991 EBBE                <1> 	jmp	short loc_rmdir_cmd_return
  3292                              <1> 
  3293                              <1> 
  3294                              <1> delete_sub_directory:
  3295                              <1> 	; 29/12/2017 
  3296                              <1> 	; (moved here from 'delete_directory' for 'sysrmdir' )
  3297                              <1> 
  3298                              <1> 	; EDI = Directory buffer entry offset/address
  3299                              <1> 
  3300                              <1> loc_rmdir_delete_short_name_check_dir_empty:
  3301 00008993 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  3302 00008997 C1E010              <1>         shl	eax, 16
  3303 0000899A 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  3304                              <1> 
  3305                              <1> 	;mov 	[DelFile_FCluster], eax
  3306                              <1> 
  3307                              <1> 	;;mov	bx, [DirBuff_EntryCounter]
  3308                              <1> 	;mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
  3309                              <1> 	;mov	[DelFile_EntryCounter], bx
  3310                              <1> 
  3311 0000899E 29DB                <1>     	sub	ebx, ebx
  3312                              <1> 	; 29/12/2017
  3313 000089A0 891D[82600100]      <1> 	mov	[FAT_ClusterCounter], ebx ; 0 ; Reset
  3314                              <1> 
  3315 000089A6 8A3D[06620100]      <1> 	mov	bh, [FindFile_Drv]
  3316 000089AC BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3317 000089B1 01DE                <1> 	add	esi, ebx
  3318                              <1> 
  3319 000089B3 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
  3320 000089B9 745A                <1> 	je	short loc_rmdir_check_fs_directory
  3321                              <1> 
  3322                              <1> 	;cmp	byte [esi+LD_FATType], 1
  3323                              <1> 	;jb	short loc_rmdir_get__last_cluster_0
  3324                              <1> 
  3325                              <1> 	; 29/12/2017
  3326 000089BB 83F802              <1> 	cmp	eax, 2
  3327 000089BE 7306                <1> 	jnb	short loc_rmdir_get_last_cluster_1
  3328                              <1> 	; eax < 2
  3329                              <1> loc_rmdir_get_last_cluster_0:
  3330                              <1> 	;mov	eax, ERR_INV_FORMAT ; invalid format!
  3331 000089C0 B813000000          <1> 	mov	eax, ERR_NOT_DIR ; not a valid directory!
  3332                              <1> 	;stc
  3333 000089C5 C3                  <1> 	retn
  3334                              <1> 
  3335                              <1> loc_rmdir_get_last_cluster_1:
  3336 000089C6 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3 ; FAT32
  3337 000089CA 750C                <1> 	jne	short loc_rmdir_get_last_cluster_2
  3338                              <1> 
  3339                              <1> 	; is it root directory ?
  3340 000089CC 3B4632              <1> 	cmp	eax, [esi+LD_BPB+BPB_RootClus]
  3341 000089CF 7507                <1> 	jne	short loc_rmdir_get_last_cluster_2
  3342                              <1> 
  3343                              <1> 	; root directory can not be deleted !!
  3344                              <1> loc_rmdir_permission_denied:
  3345 000089D1 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; permission denied!
  3346 000089D6 F9                  <1> 	stc
  3347 000089D7 C3                  <1> 	retn		
  3348                              <1> 
  3349                              <1> loc_rmdir_get_last_cluster_2:
  3350                              <1> 	; 29/12/2017
  3351 000089D8 A3[C8620100]        <1> 	mov 	[DelFile_FCluster], eax
  3352                              <1> 	
  3353                              <1> 	;mov	dx, [DirBuff_EntryCounter]
  3354 000089DD 668B15[80620100]    <1> 	mov	dx, [FindFile_DirEntryNumber] ; 27/02/2016
  3355 000089E4 668915[CC620100]    <1> 	mov	[DelFile_EntryCounter], dx
  3356                              <1> 	
  3357 000089EB 8B15[91600100]      <1> 	mov	edx, [DirBuff_Cluster]
  3358 000089F1 8915[F8620100]      <1> 	mov	[RmDir_ParentDirCluster], edx
  3359                              <1> 
  3360 000089F7 893D[F4620100]      <1> 	mov	[RmDir_DirEntryOffset], edi
  3361                              <1> 
  3362                              <1> 	; 01/03/2016
  3363                              <1> 	;mov	dword [FAT_ClusterCounter], 0 ; Reset
  3364                              <1> 
  3365                              <1> loc_rmdir_get_last_cluster_3:
  3366 000089FD E89C390000          <1> 	call	get_last_cluster
  3367                              <1>         ;jc	loc_rmdir_cmd_failed
  3368 00008A02 721E                <1> 	jc	short loc_delete_sub_dir_retn ; 29/12/2017
  3369                              <1> 	
  3370 00008A04 3B05[C8620100]      <1> 	cmp	eax, [DelFile_FCluster]
  3371 00008A0A 7517                <1> 	jne	short loc_rmdir_multi_dir_clusters
  3372                              <1> 
  3373 00008A0C C605[F3620100]00    <1> 	mov	byte [RmDir_MultiClusters], 0
  3374 00008A13 EB15                <1> 	jmp	short pass_rmdir_multi_dir_clusters
  3375                              <1> 
  3376                              <1> loc_rmdir_check_fs_directory:
  3377                              <1> 	; 29/12/2017
  3378 00008A15 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  3379 00008A19 75B6                <1> 	jne	short loc_rmdir_permission_denied
  3380                              <1> 
  3381                              <1> loc_rmdir_delete_fs_directory:
  3382 00008A1B E876130000          <1> 	call	delete_fs_directory
  3383                              <1> 	;jnc	loc_print_deleted_message
  3384 00008A20 7300                <1> 	jnc	short loc_delete_sub_dir_retn ; 29/12/2017
  3385                              <1> 
  3386                              <1> 	; EAX=0 -> Directory not empty !
  3387                              <1> 	; EAX>0 -> Disk r/w error or another (misc) error
  3388                              <1> 	
  3389                              <1> 	;or	eax, eax
  3390                              <1> 	;jz	loc_rmdir_directory_not_empty_2         
  3391                              <1> 	;;stc
  3392                              <1> 	;;jmp	loc_file_rw_cmd_failed
  3393                              <1> 	
  3394                              <1> loc_delete_sub_dir_retn:
  3395 00008A22 C3                  <1> 	retn
  3396                              <1>  
  3397                              <1> loc_rmdir_multi_dir_clusters:
  3398 00008A23 C605[F3620100]01    <1> 	mov	byte [RmDir_MultiClusters], 1
  3399                              <1> 
  3400                              <1> pass_rmdir_multi_dir_clusters:
  3401 00008A2A A3[FC620100]        <1> 	mov 	[RmDir_DirLastCluster], eax
  3402 00008A2F 890D[00630100]      <1> 	mov	[RmDir_PreviousCluster], ecx
  3403                              <1> 
  3404                              <1> loc_rmdir_load_fat_sub_directory:
  3405 00008A35 E84F330000          <1> 	call	load_FAT_sub_directory
  3406                              <1> 	;jc	loc_rmdir_cmd_failed
  3407 00008A3A 72E6                <1> 	jc	short loc_delete_sub_dir_retn
  3408                              <1> 
  3409                              <1> loc_rmdir_find_last_dir_entry:
  3410 00008A3C 56                  <1> 	push	esi
  3411 00008A3D BE[EA610100]        <1> 	mov	esi, Dir_File_Name
  3412 00008A42 C6062A              <1> 	mov	byte [esi], '*'
  3413 00008A45 C646082A            <1> 	mov	byte [esi+8], '*'
  3414 00008A49 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
  3415                              <1> loc_rmdir_find_last_dir_entry_next:
  3416 00008A4B 66B80008            <1> 	mov	ax, 0800h ; Except volume/long names
  3417 00008A4F 6631C9              <1> 	xor	cx, cx ; 0 = Find a valid file or dir name
  3418 00008A52 E87A170000          <1> 	call	find_directory_entry
  3419 00008A57 7225                <1> 	jc	short loc_rmdir_empty_dir_cluster
  3420 00008A59 83FB01              <1> 	cmp	ebx, 1
  3421 00008A5C 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
  3422                              <1> loc_rmdir_dot_entry_check:
  3423 00008A5E 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
  3424 00008A61 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
  3425 00008A63 08DB                <1> 	or	bl, bl
  3426 00008A65 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
  3427 00008A67 807F0120            <1> 	cmp	byte [edi+1], 20h
  3428 00008A6B EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
  3429                              <1> 
  3430                              <1> loc_rmdir_dotdot_entry_check:
  3431 00008A6D 66817F012E20        <1> 	cmp	word [edi+1], '. '
  3432                              <1> pass_rmdir_dot_entry_check:	
  3433 00008A73 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
  3434 00008A75 FEC3                <1> 	inc	bl
  3435 00008A77 EBD2                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next 
  3436                              <1> 
  3437                              <1> loc_rmdir_directory_not_empty_1:
  3438 00008A79 58                  <1> 	pop	eax ; pushed esi 
  3439 00008A7A 31C0                <1> 	xor	eax, eax ; 0
  3440                              <1> loc_rmdir_directory_not_empty_2:
  3441                              <1> loc_delete_sub_dir_stc_retn:
  3442 00008A7C F9                  <1> 	stc
  3443 00008A7D C3                  <1> 	retn
  3444                              <1> 
  3445                              <1> loc_rmdir_empty_dir_cluster:
  3446 00008A7E 5E                  <1> 	pop	esi
  3447                              <1> 
  3448                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
  3449 00008A7F 803D[F3620100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  3450 00008A86 7613                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
  3451                              <1> 
  3452 00008A88 A1[00630100]        <1> 	mov	eax, [RmDir_PreviousCluster]
  3453                              <1> 	;xor	ecx, ecx
  3454 00008A8D 49                  <1> 	dec	ecx ; FFFFFFFFh
  3455 00008A8E E83A340000          <1> 	call	update_cluster
  3456 00008A93 7306                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
  3457                              <1> 
  3458                              <1> 	; 01/03/2016
  3459                              <1> 	;cmp	eax, 1  ; eax = 0 -> end of cluster chain
  3460                              <1> 	;cmc 
  3461                              <1> 	;jc	short loc_rmdir_cmd_failed
  3462                              <1> 	;jmp	short loc_rmdir_save_fat_buffer
  3463                              <1> 	; 29/12/2017 
  3464 00008A95 21C0                <1> 	and	eax, eax
  3465 00008A97 75E3                <1> 	jnz	short loc_delete_sub_dir_stc_retn
  3466 00008A99 EB12                <1> 	jmp	short loc_rmdir_save_fat_buffer	
  3467                              <1> 
  3468                              <1> loc_rmdir_unlink_dir_last_cluster:
  3469 00008A9B A1[FC620100]        <1> 	mov	eax, [RmDir_DirLastCluster]
  3470 00008AA0 31C9                <1> 	xor	ecx, ecx ; 0
  3471 00008AA2 E826340000          <1> 	call	update_cluster
  3472 00008AA7 7327                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh
  3473                              <1> 	; Because of it is the last cluster
  3474                              <1> 	; 'update_cluster' must return with eocc error 
  3475 00008AA9 09C0                <1> 	or	eax, eax
  3476                              <1> 	;jz	short loc_rmdir_save_fat_buffer ; eocc	
  3477                              <1> 	;stc
  3478                              <1>         ;jmp     short loc_rmdir_cmd_failed
  3479                              <1> 	; 29/12/2017
  3480 00008AAB 75CF                <1> 	jnz	short loc_delete_sub_dir_stc_retn
  3481                              <1> 	
  3482                              <1> loc_rmdir_save_fat_buffer:
  3483 00008AAD 803D[7A600100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  3484 00008AB4 7528                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
  3485 00008AB6 E8CF360000          <1> 	call	save_fat_buffer
  3486                              <1> 	;jc	short loc_rmdir_cmd_failed
  3487                              <1> 	; 29/12/2017
  3488 00008ABB 7219                <1> 	jc	short loc_rmdir_unlink_error_retn
  3489                              <1> 
  3490                              <1> 	; 01/03/2016
  3491 00008ABD 803D[F3620100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  3492 00008AC4 7618                <1> 	jna	short loc_rmdir_calculate_FAT_freespace
  3493                              <1> 
  3494 00008AC6 A1[C8620100]        <1> 	mov	eax, [DelFile_FCluster]
  3495 00008ACB E92DFFFFFF          <1>         jmp     loc_rmdir_get_last_cluster_3
  3496                              <1> 
  3497                              <1> loc_rmdir_unlink_stc_retn_0Bh:
  3498                              <1> 	; 15/10/2016 (0Bh -> 28)
  3499 00008AD0 B81C000000          <1> 	mov	eax, ERR_INV_FORMAT ; 28 = Invalid format
  3500                              <1> loc_rmdir_unlink_stc_retn:
  3501 00008AD5 F9                  <1> 	stc
  3502                              <1> loc_rmdir_unlink_error_retn:
  3503 00008AD6 C3                  <1> 	retn
  3504                              <1> 
  3505                              <1> loc_rmdir_delete_short_name_invalid_data:
  3506 00008AD7 B81D000000          <1> 	mov	eax, 29 ; Invalid data (15/10/2016)
  3507                              <1> 	;stc
  3508                              <1>         ;jmp	loc_rmdir_cmd_failed
  3509                              <1> 	; 29/12/2017
  3510 00008ADC EBF7                <1> 	jmp	short loc_rmdir_unlink_stc_retn
  3511                              <1> 
  3512                              <1> loc_rmdir_calculate_FAT_freespace:
  3513                              <1> 	;mov	eax, [FAT_ClusterCounter]
  3514                              <1> 	; 29/12/2017
  3515 00008ADE 29C0                <1> 	sub	eax, eax ; 0
  3516 00008AE0 8705[82600100]      <1> 	xchg	eax, [FAT_ClusterCounter]
  3517                              <1> 	;
  3518 00008AE6 66BB01FF            <1> 	mov	bx, 0FF01h
  3519                              <1> 	; BL = 1 -> Add EAX to free space count
  3520                              <1> 	; BH = FFh ->
  3521                              <1> 	; ESI = Logical DOS Drive Description Table address
  3522 00008AEA E830370000          <1> 	call	calculate_fat_freespace
  3523                              <1> 
  3524 00008AEF 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
  3525 00008AF1 7409                <1> 	jz 	short loc_rmdir_delete_short_name_continue
  3526                              <1> 
  3527                              <1> loc_rmdir_recalculate_FAT_freespace:
  3528 00008AF3 66BB00FF            <1>         mov     bx, 0FF00h ; BL = 0 -> Recalculate free space
  3529 00008AF7 E823370000          <1> 	call	calculate_fat_freespace
  3530                              <1> 	          
  3531                              <1> loc_rmdir_delete_short_name_continue:
  3532 00008AFC A1[F8620100]        <1> 	mov	eax, [RmDir_ParentDirCluster]
  3533 00008B01 83F802              <1> 	cmp	eax, 2
  3534 00008B04 7309                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
  3535 00008B06 E8F3310000          <1> 	call	load_FAT_root_directory
  3536                              <1> 	;jc	loc_file_rw_cmd_failed
  3537                              <1> 	; 29/12/2017
  3538 00008B0B 72C9                <1> 	jc	short loc_rmdir_unlink_error_retn
  3539 00008B0D EB07                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
  3540                              <1> 
  3541                              <1> loc_rmdir_del_short_name_load_sub_dir:	
  3542 00008B0F E875320000          <1> 	call	load_FAT_sub_directory
  3543                              <1> 	;jc	loc_file_rw_cmd_failed
  3544                              <1> 	; 29/12/2017
  3545 00008B14 72C0                <1> 	jc	short loc_rmdir_unlink_error_retn
  3546                              <1> 
  3547                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
  3548 00008B16 0FB73D[F4620100]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
  3549 00008B1D 81C700000800        <1> 	add	edi, Directory_Buffer
  3550                              <1> 
  3551 00008B23 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  3552 00008B27 C1E010              <1> 	shl	eax, 16
  3553 00008B2A 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  3554                              <1>         ; Not necessary... 
  3555 00008B2E 3B05[C8620100]      <1> 	cmp	eax, [DelFile_FCluster]
  3556 00008B34 75A1                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
  3557                              <1> 	;
  3558 00008B36 C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
  3559                              <1> 	; 27/02/2016
  3560                              <1> 	; TRDOS v1 has a bug here! it does not set
  3561                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  3562                              <1> 	; 'save_directory_buffer' would not save the change ! 
  3563 00008B39 C605[8C600100]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
  3564                              <1> 	;
  3565 00008B40 E8AE1D0000          <1> 	call	save_directory_buffer
  3566                              <1> 	;jc	loc_file_rw_cmd_failed
  3567                              <1> 	; 29/12/2017
  3568 00008B45 728F                <1> 	jc	short loc_rmdir_unlink_error_retn
  3569                              <1> 
  3570                              <1> loc_rmdir_del_long_name:
  3571 00008B47 0FB615[CE620100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  3572 00008B4E 08D2                <1> 	or	dl, dl
  3573 00008B50 7410                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
  3574                              <1>              
  3575 00008B52 0FB705[CC620100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  3576 00008B59 29D0                <1> 	sub	eax, edx
  3577                              <1> 	; 29/12/2017
  3578 00008B5B 7205                <1> 	jc	short loc_rmdir_update_parent_dir_lmdt
  3579                              <1>  
  3580                              <1>  	; EAX = Directory Entry Number of the long name last entry
  3581 00008B5D E8EF1E0000          <1> 	call	delete_longname
  3582                              <1> 
  3583                              <1> loc_rmdir_update_parent_dir_lmdt:
  3584 00008B62 E8271E0000          <1> 	call	update_parent_dir_lmdt
  3585                              <1> 	;jc	short loc_file_rw_cmd_failed
  3586                              <1> 	; 29/12/2017
  3587                              <1> 	;jc	short loc_rmdir_unlink_error_retn
  3588                              <1> 
  3589                              <1> loc_delete_sub_directory_ok:
  3590                              <1> 	; 29/12/2017
  3591 00008B67 31C0                <1> 	xor	eax, eax ;  0 ;  cf = 0
  3592 00008B69 C3                  <1> 	retn
  3593                              <1> 
  3594                              <1> 
  3595                              <1> delete_file:
  3596                              <1> 	; 29/02/2016
  3597                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  3598                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
  3599                              <1> 	; 28/02/2010
  3600                              <1> 
  3601                              <1> get_delfile_fchar:
  3602                              <1> 	; esi = file name
  3603 00008B6A 803E20              <1> 	cmp	byte [esi], 20h
  3604 00008B6D 7701                <1>         ja	short loc_delfile_parse_path_name
  3605                              <1> 
  3606                              <1> loc_delfile_nofilename_retn:
  3607 00008B6F C3                  <1> 	retn
  3608                              <1> 
  3609                              <1> loc_delfile_parse_path_name:
  3610 00008B70 BF[06620100]        <1> 	mov	edi, FindFile_Drv
  3611 00008B75 E815190000          <1> 	call	parse_path_name
  3612 00008B7A 0F822EF2FFFF        <1> 	jc	loc_cmd_failed
  3613                              <1> 
  3614                              <1> loc_delfile_check_filename_exists:
  3615 00008B80 BE[48620100]        <1> 	mov	esi, FindFile_Name
  3616 00008B85 803E20              <1> 	cmp	byte [esi], 20h
  3617 00008B88 0F8620F2FFFF        <1> 	jna	loc_cmd_failed
  3618 00008B8E 8935[C4620100]      <1> 	mov	[DelFile_FNPointer], esi 
  3619                              <1> 
  3620                              <1> loc_delfile_drv:
  3621 00008B94 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  3622 00008B9A 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  3623 00008BA0 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  3624 00008BA6 38F2                <1> 	cmp	dl, dh
  3625 00008BA8 740B                <1> 	je	short loc_delfile_change_directory
  3626                              <1> 
  3627 00008BAA E86CE3FFFF          <1> 	call	change_current_drive
  3628 00008BAF 0F8237FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3629                              <1> 
  3630                              <1> loc_delfile_change_directory:
  3631 00008BB5 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3632 00008BBC 7618                <1> 	jna	short loc_delfile_find
  3633                              <1> 
  3634 00008BBE FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3635 00008BC4 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  3636 00008BC9 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3637 00008BCB E8A9120000          <1> 	call	change_current_directory
  3638 00008BD0 0F8216FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3639                              <1> 
  3640                              <1> ;loc_delfile_change_prompt_dir_string:
  3641                              <1> 	;call	change_prompt_dir_string
  3642                              <1> 
  3643                              <1> loc_delfile_find:
  3644                              <1> 	;mov	esi, FindFile_Name
  3645 00008BD6 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3646 00008BDC 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  3647 00008BE0 E8D9F6FFFF          <1> 	call	find_first_file
  3648 00008BE5 0F8201FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
  3649                              <1> 
  3650                              <1> loc_delfile_ambgfn_check:
  3651 00008BEB 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3652 00008BEE 740B                <1> 	jz	short loc_delfile_found
  3653                              <1> 
  3654                              <1> loc_file_not_found:
  3655 00008BF0 B802000000          <1> 	mov	eax, 2 ; File not found sign
  3656 00008BF5 F9                  <1> 	stc
  3657 00008BF6 E9F1FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed   
  3658                              <1> 
  3659                              <1> loc_delfile_found:
  3660 00008BFB 80E307              <1> 	and	bl, 07h ; Attributes
  3661 00008BFE 0F85F2FAFFFF        <1>         jnz     loc_permission_denied
  3662                              <1> 
  3663                              <1> ;loc_delfile_found_save_lnel:
  3664                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  3665                              <1> 
  3666                              <1> loc_delfile_ask_for_delete:
  3667 00008C04 57                  <1> 	push	edi ; * (29/02/2016)
  3668                              <1> 
  3669 00008C05 BE[0B120100]        <1> 	mov	esi, Msg_DoYouWantDelete
  3670 00008C0A E88ED7FFFF          <1> 	call	print_msg
  3671 00008C0F 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3672 00008C15 E883D7FFFF          <1> 	call	print_msg
  3673 00008C1A BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  3674 00008C1F E879D7FFFF          <1> 	call	print_msg
  3675                              <1> 
  3676                              <1> loc_delfile_ask_again:
  3677 00008C24 30E4                <1> 	xor	ah, ah
  3678 00008C26 E81B80FFFF          <1> 	call	int16h
  3679 00008C2B 3C1B                <1> 	cmp	al, 1Bh
  3680                              <1> 	;je	short loc_do_not_delete_file
  3681 00008C2D 7449                <1> 	je	short loc_delfile_y_n_escape ; 06/03/2016
  3682 00008C2F 24DF                <1> 	and	al, 0DFh
  3683 00008C31 A2[C9110100]        <1> 	mov	[Y_N_nextline], al
  3684 00008C36 3C59                <1> 	cmp	al, 'Y'
  3685 00008C38 7404                <1> 	je	short loc_yes_delete_file
  3686 00008C3A 3C4E                <1> 	cmp	al, 'N'
  3687 00008C3C 75E6                <1> 	jne	short loc_delfile_ask_again
  3688                              <1> 
  3689                              <1> loc_do_not_delete_file:
  3690                              <1> loc_yes_delete_file:
  3691 00008C3E E8E2FBFFFF          <1> 	call	y_n_answer ; 29/12/2017
  3692 00008C43 5F                  <1> 	pop	edi ; * (29/02/2016)
  3693                              <1> 	;cmp	al, 'Y' ; 'yes'
  3694                              <1> 	;cmc
  3695                              <1>         ;jnc	loc_file_rw_restore_retn
  3696 00008C44 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3697 00008C46 0F84A0FAFFFF        <1>         je	loc_file_rw_restore_retn  
  3698                              <1> 
  3699                              <1> loc_delete_file:
  3700 00008C4C 8A3D[06620100]      <1> 	mov	bh, [FindFile_Drv]
  3701                              <1> 	;mov	bl, [DelFile_LNEL]
  3702 00008C52 8A1D[55620100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  3703                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  3704 00008C58 668B0D[80620100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  3705                              <1> 	; (*) EDI = Directory buffer entry offset/address 
  3706 00008C5F E8D71F0000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
  3707 00008C64 0F8378FAFFFF        <1> 	jnc	loc_print_deleted_message
  3708                              <1> 
  3709                              <1> 	;cmp	al, 05h
  3710 00008C6A 3C0B                <1> 	cmp	al, ERR_PERM_DENIED  ; 29/12/2017 (5 -> 11)
  3711 00008C6C 0F8484FAFFFF        <1> 	je	loc_permission_denied
  3712 00008C72 F9                  <1> 	stc
  3713 00008C73 E974FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3714                              <1> 
  3715                              <1> loc_delfile_y_n_escape:
  3716 00008C78 B04E                <1> 	mov	al, 'N' ; 'no'
  3717 00008C7A EBC2                <1> 	jmp	short loc_do_not_delete_file
  3718                              <1> 
  3719                              <1> set_file_attributes:
  3720                              <1> 	; 06/03/2016
  3721                              <1> 	; 04/03/2016 (TRDOS 386 = TRDOS v2.0)
  3722                              <1> 	; 10/07/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_attrib')
  3723                              <1> 	; 23/05/2010 
  3724                              <1> 	; 17/12/2000 (P2000.ASM)
  3725                              <1> 
  3726                              <1> 	; esi = file or directory name
  3727 00008C7C 6631C0              <1> 	xor	ax, ax
  3728 00008C7F 66A3[5C120100]      <1> 	mov	[Attr_Chars], ax
  3729 00008C85 A2[1C630100]        <1> 	mov	[Attributes], al
  3730                              <1> 
  3731                              <1> get_attrib_fchar:
  3732                              <1> 	; esi = file name
  3733 00008C8A 8A06                <1> 	mov	al, [esi]
  3734 00008C8C 3C20                <1> 	cmp	al, 20h
  3735 00008C8E 7623                <1> 	jna	short loc_attr_file_nofilename_retn
  3736                              <1> 
  3737                              <1> loc_scan_attrib_params:
  3738 00008C90 3C2D                <1> 	cmp	al, '-'
  3739 00008C92 0F871C010000        <1> 	ja	loc_attr_file_parse_path_name
  3740 00008C98 7408                <1> 	je	short loc_attr_space
  3741                              <1> 
  3742 00008C9A 3C2B                <1> 	cmp	al, '+'
  3743 00008C9C 0F850CF1FFFF        <1> 	jne	loc_cmd_failed
  3744                              <1> 
  3745                              <1> loc_attr_space:
  3746 00008CA2 8A6601              <1> 	mov	ah, [esi+1]
  3747 00008CA5 80FC20              <1>  	cmp	ah, 20h
  3748 00008CA8 770A                <1> 	ja	short pass_attr_space
  3749 00008CAA 0F82FEF0FFFF        <1> 	jb	loc_cmd_failed
  3750 00008CB0 46                  <1> 	inc	esi
  3751 00008CB1 EBEF                <1> 	jmp	short loc_attr_space
  3752                              <1> 
  3753                              <1> loc_attr_file_nofilename_retn:
  3754 00008CB3 C3                  <1> 	retn
  3755                              <1> 
  3756                              <1> pass_attr_space:
  3757 00008CB4 80E4DF              <1> 	and	ah, 0DFh
  3758 00008CB7 80FC53              <1> 	cmp	ah, 'S'
  3759 00008CBA 0F87EEF0FFFF        <1> 	ja	loc_cmd_failed
  3760 00008CC0 7204                <1> 	jb	short pass_attr_system
  3761 00008CC2 B404                <1> 	mov	ah, 04h   ; System
  3762 00008CC4 EB21                <1> 	jmp	short pass_attr_archive
  3763                              <1> 
  3764                              <1> pass_attr_system:
  3765 00008CC6 80FC48              <1> 	cmp	ah, 'H'
  3766 00008CC9 7706                <1> 	ja	short pass_attr_hidden
  3767 00008CCB 7213                <1> 	jb	short pass_attr_read_only
  3768 00008CCD B402                <1> 	mov	ah, 02h    ; Hidden
  3769 00008CCF EB16                <1> 	jmp	short pass_attr_archive
  3770                              <1> 
  3771                              <1> pass_attr_hidden:
  3772 00008CD1 80FC52              <1> 	cmp	ah, 'R'
  3773 00008CD4 0F87D4F0FFFF        <1> 	ja	loc_cmd_failed
  3774 00008CDA 7204                <1> 	jb	short pass_attr_read_only ; Read only
  3775 00008CDC B401                <1> 	mov	ah, 01h
  3776 00008CDE EB07                <1> 	jmp	short pass_attr_archive
  3777                              <1> 
  3778                              <1> pass_attr_read_only:
  3779 00008CE0 80FC41              <1> 	cmp	ah, 'A'
  3780 00008CE3 753B                <1> 	jne	short loc_chk_attr_enter
  3781 00008CE5 B420                <1> 	mov	ah, 20h    ; Archive
  3782                              <1> 
  3783                              <1> pass_attr_archive:
  3784 00008CE7 3C2D                <1> 	cmp	al, '-'
  3785 00008CE9 7508                <1> 	jne	short pass_reducing_attributes
  3786 00008CEB 0825[5C120100]      <1> 	or	[Attr_Chars], ah
  3787 00008CF1 EB06                <1> 	jmp	short loc_change_attributes_inc
  3788                              <1> 
  3789                              <1> pass_reducing_attributes:
  3790 00008CF3 0825[5D120100]      <1> 	or	[Attr_Chars+1], ah
  3791                              <1> 
  3792                              <1> loc_change_attributes_inc:
  3793 00008CF9 46                  <1> 	inc	esi
  3794 00008CFA 8A6601              <1> 	mov	ah, [esi+1]
  3795 00008CFD 80FC20              <1> 	cmp	ah, 20h
  3796 00008D00 7227                <1> 	jb	short pass_change_attr
  3797 00008D02 74F5                <1> 	je	short loc_change_attributes_inc
  3798 00008D04 80FC2D              <1> 	cmp	ah, '-'
  3799 00008D07 770D                <1> 	ja	short loc_chk_next_attr_char1
  3800 00008D09 7405                <1> 	je	short loc_chk_next_attr_char0
  3801 00008D0B 80FC2B              <1> 	cmp	ah, '+'
  3802 00008D0E 7506                <1> 	jne	short loc_chk_next_attr_char1
  3803                              <1> 
  3804                              <1> loc_chk_next_attr_char0:
  3805 00008D10 46                  <1> 	inc	esi
  3806 00008D11 668B06              <1> 	mov	ax, [esi]
  3807 00008D14 EB9E                <1> 	jmp	short pass_attr_space
  3808                              <1> 
  3809                              <1> loc_chk_next_attr_char1:
  3810 00008D16 803E2D              <1> 	cmp	byte [esi], '-'
  3811 00008D19 7799                <1> 	ja	short pass_attr_space
  3812 00008D1B E988000000          <1>         jmp     loc_attr_file_check_fname_fchar
  3813                              <1> 
  3814                              <1> loc_chk_attr_enter:
  3815 00008D20 80FC0D              <1> 	cmp	ah, 0Dh
  3816 00008D23 0F8585F0FFFF        <1> 	jne	loc_cmd_failed
  3817                              <1> 
  3818                              <1> pass_change_attr:
  3819 00008D29 A0[5C120100]        <1> 	mov	al, [Attr_Chars]
  3820 00008D2E F6D0                <1> 	not	al
  3821 00008D30 2005[1C630100]      <1> 	and	[Attributes], al
  3822 00008D36 A0[5D120100]        <1> 	mov	al, [Attr_Chars+1]
  3823 00008D3B 0805[1C630100]      <1> 	or	[Attributes], al
  3824                              <1> 
  3825                              <1> loc_show_attributes:
  3826 00008D41 BE[D7190100]        <1> 	mov	esi, nextline
  3827 00008D46 E852D6FFFF          <1> 	call	print_msg
  3828                              <1> 
  3829                              <1> loc_show_attributes_no_nextline:
  3830 00008D4B C705[5C120100]4E4F- <1> 	mov	dword [Attr_Chars], 'NORM'
  3830 00008D53 524D                <1>
  3831 00008D55 66C705[60120100]41- <1> 	mov	word [Attr_Chars+4], 'AL'
  3831 00008D5D 4C                  <1>
  3832 00008D5E BE[5C120100]        <1> 	mov	esi, Attr_Chars
  3833 00008D63 A0[1C630100]        <1> 	mov	al, [Attributes]
  3834 00008D68 A804                <1> 	test	al, 04h
  3835 00008D6A 7406                <1> 	jz	short pass_put_attr_s
  3836 00008D6C 66C7065300          <1> 	mov	word [esi], 0053h     ; S
  3837 00008D71 46                  <1> 	inc	esi
  3838                              <1> 
  3839                              <1> pass_put_attr_s:
  3840 00008D72 A802                <1> 	test	al, 02h
  3841 00008D74 7406                <1> 	jz	short pass_put_attr_h
  3842 00008D76 66C7064800          <1> 	mov	word [esi], 0048h     ; H
  3843 00008D7B 46                  <1> 	inc	esi
  3844                              <1> 
  3845                              <1> pass_put_attr_h:
  3846 00008D7C A801                <1> 	test	al, 01h
  3847 00008D7E 7406                <1> 	jz	short pass_put_attr_r
  3848 00008D80 66C7065200          <1> 	mov	word [esi], 0052h     ; R
  3849 00008D85 46                  <1> 	inc	esi
  3850                              <1> 
  3851                              <1> pass_put_attr_r:
  3852 00008D86 3C20                <1> 	cmp	al, 20h
  3853 00008D88 7205                <1> 	jb	short pass_put_attr_a
  3854 00008D8A 66C7064100          <1> 	mov	word [esi], 0041h     ; A
  3855                              <1> 
  3856                              <1> pass_put_attr_a:
  3857 00008D8F BE[4F120100]        <1> 	mov	esi, Str_Attributes
  3858 00008D94 E804D6FFFF          <1> 	call	print_msg
  3859 00008D99 BE[D7190100]        <1> 	mov	esi, nextline
  3860 00008D9E E8FAD5FFFF          <1> 	call	print_msg
  3861 00008DA3 E944F9FFFF          <1> 	jmp	loc_file_rw_restore_retn 
  3862                              <1> 
  3863                              <1> loc_attr_file_check_fname_fchar:
  3864 00008DA8 46                  <1> 	inc	esi
  3865 00008DA9 803E20              <1> 	cmp	byte [esi], 20h
  3866 00008DAC 74FA                <1> 	je	short loc_attr_file_check_fname_fchar
  3867 00008DAE 0F8275FFFFFF        <1>         jb      pass_change_attr
  3868                              <1> 		   
  3869                              <1> loc_attr_file_parse_path_name:
  3870 00008DB4 BF[06620100]        <1> 	mov	edi, FindFile_Drv
  3871 00008DB9 E8D1160000          <1> 	call	parse_path_name
  3872 00008DBE 0F82EAEFFFFF        <1> 	jc	loc_cmd_failed
  3873                              <1> 
  3874                              <1> loc_attr_file_check_filename_exists:
  3875 00008DC4 BE[48620100]        <1> 	mov	esi, FindFile_Name
  3876 00008DC9 803E20              <1> 	cmp	byte [esi], 20h
  3877 00008DCC 0F86DCEFFFFF        <1> 	jna	loc_cmd_failed
  3878 00008DD2 8935[C4620100]      <1> 	mov	[DelFile_FNPointer], esi 
  3879                              <1> 
  3880                              <1> loc_attr_file_drv:
  3881 00008DD8 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  3882 00008DDE 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  3883                              <1> 
  3884 00008DE4 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  3885 00008DEA 38F2                <1> 	cmp	dl, dh
  3886 00008DEC 740B                <1> 	je	short loc_attr_file_change_directory
  3887                              <1> 
  3888 00008DEE E828E1FFFF          <1> 	call	change_current_drive
  3889 00008DF3 0F82F3F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3890                              <1> 
  3891                              <1> loc_attr_file_change_directory:
  3892 00008DF9 803D[07620100]20    <1>         cmp     byte [FindFile_Directory], 20h
  3893 00008E00 7618                <1> 	jna	short loc_attr_file_find
  3894                              <1> 
  3895 00008E02 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3896                              <1> 	
  3897 00008E08 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  3898 00008E0D 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3899 00008E0F E865100000          <1> 	call	change_current_directory
  3900 00008E14 0F82D2F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3901                              <1> 
  3902                              <1> ;loc_attr_file_change_prompt_dir_string:
  3903                              <1> 	;call	change_prompt_dir_string
  3904                              <1> 
  3905                              <1> loc_attr_file_find:
  3906                              <1> 	;mov	esi, FindFile_Name
  3907 00008E1A 8B35[C4620100]      <1> 	mov	esi, [DelFile_FNPointer]
  3908 00008E20 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  3909 00008E24 E895F4FFFF          <1> 	call	find_first_file
  3910 00008E29 0F82BDF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3911                              <1> 
  3912                              <1> loc_attr_file_ambgfn_check:
  3913 00008E2F 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3914                              <1> 	;	(Note: It was BX in TRDOS v1)
  3915                              <1> 	;jz	short loc_attr_file_found
  3916 00008E32 0F85B8FDFFFF        <1>         jnz     loc_file_not_found ; 06/03/2016 
  3917                              <1> 
  3918                              <1> 	;mov	eax, 2 ; File not found sign
  3919                              <1> 	;stc
  3920                              <1> 	;jmp	loc_file_rw_cmd_failed   
  3921                              <1> 
  3922                              <1> loc_attr_file_found:
  3923                              <1> 	; EDI = Directory buffer entry offset/address
  3924                              <1> 	; BL = File (or Directory) Attributes 
  3925                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  3926                              <1> 	; mov	bl, [EDI+0Bh]
  3927                              <1> 	
  3928 00008E38 66833D[5C120100]00  <1> 	cmp	word [Attr_Chars], 0
  3929 00008E40 770B                <1> 	ja	short loc_attr_file_change_attributes
  3930 00008E42 881D[1C630100]      <1> 	mov	[Attributes], bl
  3931 00008E48 E9F4FEFFFF          <1> 	jmp	loc_show_attributes
  3932                              <1> 
  3933                              <1> loc_attr_file_change_attributes:
  3934 00008E4D A0[5C120100]        <1> 	mov	al, [Attr_Chars]
  3935 00008E52 F6D0                <1> 	not	al
  3936 00008E54 20C3                <1> 	and	bl, al
  3937 00008E56 A0[5D120100]        <1> 	mov	al, [Attr_Chars+1]
  3938 00008E5B 08C3                <1> 	or	bl, al
  3939                              <1> 
  3940 00008E5D 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
  3941 00008E63 741D                <1> 	je	short loc_attr_file_fs_check
  3942                              <1> 
  3943 00008E65 881D[1C630100]      <1> 	mov	[Attributes], bl
  3944 00008E6B 885F0B              <1> 	mov	[edi+0Bh], bl    ; Attributes (New!)
  3945                              <1> 
  3946                              <1> 	; 04/03/2016
  3947                              <1> 	; TRDOS v1 has a bug here! it does not set
  3948                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  3949                              <1> 	; 'save_directory_buffer' would not save the new attributes ! 
  3950                              <1> 	
  3951 00008E6E C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  3952                              <1> 
  3953 00008E75 E8791A0000          <1> 	call 	save_directory_buffer
  3954 00008E7A 0F826CF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3955                              <1> 
  3956 00008E80 EB33                <1> 	jmp	short loc_print_attr_changed_message
  3957                              <1> 
  3958                              <1> loc_attr_file_fs_check:
  3959 00008E82 29C0                <1> 	sub	eax, eax
  3960 00008E84 8A25[8A600100]      <1>         mov     ah, [DirBuff_DRV]
  3961 00008E8A BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3962 00008E8F 01C6                <1>         add     esi, eax
  3963 00008E91 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
  3964 00008E95 7309                <1> 	jnc	short loc_attr_file_change_fs_file_attributes
  3965                              <1> 	; 29/12/2017 (0Dh -> 29)	
  3966 00008E97 66B81D00            <1> 	mov	ax, 29 ; Invalid Data
  3967 00008E9B E94CF8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3968                              <1> 
  3969                              <1> loc_attr_file_change_fs_file_attributes:
  3970                              <1> 	; BL = New MS-DOS File Attributes
  3971 00008EA0 88D8                <1> 	mov	al, bl ; File/Directory Attributes
  3972 00008EA2 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign	  
  3973 00008EA4 E873050000          <1> 	call	change_fs_file_attributes
  3974 00008EA9 0F823DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
  3975                              <1> 
  3976 00008EAF 881D[1C630100]      <1> 	mov	[Attributes], bl 
  3977                              <1> 
  3978                              <1> loc_print_attr_changed_message:
  3979 00008EB5 BE[4A120100]        <1> 	mov	esi, Msg_New
  3980 00008EBA E8DED4FFFF          <1> 	call	print_msg
  3981 00008EBF E987FEFFFF          <1> 	jmp	loc_show_attributes_no_nextline
  3982                              <1> 
  3983                              <1> rename_file:
  3984                              <1> 	; 13/11/2017
  3985                              <1> 	; 06/11/2016
  3986                              <1> 	; 05/11/2016
  3987                              <1> 	; 16/10/2016
  3988                              <1> 	; 08/03/2016
  3989                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
  3990                              <1> 	; 20/11/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_rename')
  3991                              <1> 	; 16/11/2010 
  3992                              <1> 
  3993                              <1> get_rename_source_fchar:
  3994                              <1> 	; esi = file name
  3995 00008EC4 803E20              <1> 	cmp	byte [esi], 20h
  3996 00008EC7 7614                <1>         jna	short loc_rename_nofilename_retn
  3997                              <1> 
  3998 00008EC9 8935[44630100]      <1> 	mov	[SourceFilePath], esi
  3999                              <1> 
  4000                              <1> rename_scan_source_file:
  4001 00008ECF 46                  <1> 	inc	esi
  4002 00008ED0 803E20              <1> 	cmp	byte [esi], 20h
  4003 00008ED3 7409                <1> 	je	short rename_scan_destination_file_1
  4004                              <1> 	;jb	short loc_rename_nofilename_retn
  4005 00008ED5 0F82D3EEFFFF        <1> 	jb	loc_cmd_failed
  4006 00008EDB EBF2                <1> 	jmp	short rename_scan_source_file
  4007                              <1> 
  4008                              <1> loc_rename_nofilename_retn: ; 08/03/2016
  4009 00008EDD C3                  <1> 	retn
  4010                              <1> 
  4011                              <1> rename_scan_destination_file_1:
  4012 00008EDE C60600              <1> 	mov	byte [esi], 0
  4013                              <1> 
  4014                              <1> rename_scan_destination_file_2:
  4015 00008EE1 46                  <1> 	inc	esi  
  4016 00008EE2 803E20              <1> 	cmp	byte [esi], 20h
  4017 00008EE5 74FA                <1> 	je	short rename_scan_destination_file_2
  4018                              <1> 	;jb	short loc_rename_nofilename_retn
  4019 00008EE7 0F82C1EEFFFF        <1> 	jb	loc_cmd_failed
  4020                              <1> 
  4021 00008EED 8935[48630100]      <1> 	mov	[DestinationFilePath], esi
  4022                              <1> 
  4023                              <1> rename_scan_destination_file_3:
  4024 00008EF3 46                  <1> 	inc	esi  
  4025 00008EF4 803E20              <1> 	cmp	byte [esi], 20h
  4026 00008EF7 77FA                <1> 	ja	short rename_scan_destination_file_3
  4027                              <1> 
  4028 00008EF9 C60600              <1> 	mov	byte [esi], 0
  4029                              <1> 
  4030                              <1> loc_rename_save_current_drive:
  4031 00008EFC 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  4032 00008F02 8835[C2600100]      <1> 	mov	byte [RUN_CDRV], dh
  4033                              <1> 
  4034                              <1> loc_rename_sf_parse_path_name:
  4035 00008F08 8B35[44630100]      <1> 	mov	esi, [SourceFilePath] 
  4036 00008F0E BF[06620100]        <1> 	mov	edi, FindFile_Drv
  4037 00008F13 E877150000          <1> 	call	parse_path_name
  4038 00008F18 0F8290EEFFFF        <1> 	jc	loc_cmd_failed
  4039                              <1> 
  4040                              <1> loc_rename_sf_check_filename_exists:
  4041 00008F1E BE[48620100]        <1> 	mov	esi, FindFile_Name
  4042 00008F23 803E20              <1> 	cmp	byte [esi], 20h
  4043 00008F26 0F8682EEFFFF        <1> 	jna	loc_cmd_failed
  4044                              <1> 
  4045                              <1> 	;mov	[DelFile_FNPointer], esi 
  4046                              <1> 
  4047                              <1> loc_rename_sf_drv:
  4048                              <1> 	;mov	dh, [Current_Drv]
  4049                              <1> 	;mov	[RUN_CDRV], dh
  4050                              <1> 
  4051 00008F2C 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  4052 00008F32 38F2                <1> 	cmp	dl, dh ; dh = [Current_Drv]
  4053 00008F34 740B                <1> 	je	short rename_sf_change_directory
  4054                              <1> 
  4055 00008F36 E8E0DFFFFF          <1> 	call	change_current_drive
  4056 00008F3B 0F82ABF7FFFF        <1> 	jc	loc_file_rw_cmd_failed
  4057                              <1> 
  4058                              <1> rename_sf_change_directory:
  4059 00008F41 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  4060 00008F48 7618                <1> 	jna	short rename_sf_find
  4061                              <1> 
  4062 00008F4A FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  4063 00008F50 BE[07620100]        <1> 	mov	esi, FindFile_Directory
  4064 00008F55 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  4065 00008F57 E81D0F0000          <1> 	call	change_current_directory
  4066 00008F5C 0F828AF7FFFF        <1>  	jc	loc_file_rw_cmd_failed
  4067                              <1> 
  4068                              <1> ;rename_sf_change_prompt_dir_string:
  4069                              <1> 	;call	change_prompt_dir_string
  4070                              <1> 
  4071                              <1> rename_sf_find:
  4072                              <1> 	;mov	esi, [DelFile_FNPointer]
  4073 00008F62 BE[48620100]        <1> 	mov	esi, FindFile_Name
  4074                              <1> 
  4075 00008F67 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  4076 00008F6B E84EF3FFFF          <1> 	call	find_first_file
  4077 00008F70 0F8276F7FFFF        <1> 	jc	loc_file_rw_cmd_failed
  4078                              <1> 
  4079                              <1> loc_rename_sf_ambgfn_check:
  4080 00008F76 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  4081                              <1> 	;	(Note: It was BX in TRDOS v1)
  4082                              <1> 	;jz	short loc_rename_sf_found
  4083 00008F79 0F8571FCFFFF        <1> 	jnz	loc_file_not_found
  4084                              <1> 
  4085                              <1> 	;mov	eax, 2 ; File not found sign
  4086                              <1> 	;stc
  4087                              <1> 	;jmp	loc_file_rw_cmd_failed   
  4088                              <1> 
  4089                              <1> loc_rename_sf_found:
  4090                              <1> 	; EDI = Directory buffer entry offset/address
  4091                              <1> 	; BL = File (or Directory) Attributes 
  4092                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  4093                              <1> 	; mov	bl, [EDI+0Bh]
  4094                              <1> 
  4095 00008F7F F6C307              <1> 	test	bl, 07h ; Attributes, S-H-R
  4096 00008F82 0F856EF7FFFF        <1> 	jnz	loc_permission_denied
  4097                              <1> 	
  4098 00008F88 BE[06620100]        <1>         mov     esi, FindFile_Drv
  4099 00008F8D BF[4C630100]        <1>         mov     edi, SourceFile_Drv
  4100 00008F92 B920000000          <1> 	mov	ecx, 32
  4101 00008F97 F3A5                <1> 	rep	movsd
  4102                              <1> 
  4103                              <1> loc_rename_df_parse_path_name:
  4104 00008F99 8B35[48630100]      <1> 	mov	esi, [DestinationFilePath]
  4105 00008F9F BF[06620100]        <1> 	mov	edi, FindFile_Drv
  4106 00008FA4 E8E6140000          <1> 	call	parse_path_name
  4107 00008FA9 7219                <1> 	jc	short loc_rename_df_cmd_failed
  4108                              <1> 
  4109                              <1> 	;mov	dh, [RUN_CDRV]
  4110 00008FAB 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  4111                              <1> 
  4112                              <1> 	; 'rename' command is valid only for same dos drive and same dir!
  4113                              <1> 	; ('move' command must be used if source file and destination file
  4114                              <1> 	; directories are not same!) 
  4115 00008FB1 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  4116 00008FB7 38F2                <1> 	cmp	dl, dh ; are source and destination drives different ?!
  4117 00008FB9 7509                <1> 	jne	short loc_rename_df_cmd_failed ; yes! 
  4118                              <1> 
  4119                              <1> rename_df_check_dirname_exists:
  4120 00008FBB 803D[07620100]00    <1> 	cmp	byte [FindFile_Directory], 0
  4121 00008FC2 760B                <1> 	jna	short rename_df_check_filename_exists
  4122                              <1> 
  4123                              <1> 	; different source file and destination file directories !
  4124                              <1> loc_rename_df_cmd_failed:
  4125 00008FC4 B801000000          <1> 	mov	eax, 1 ; TRDOS 'Bad command or file name' error
  4126 00008FC9 F9                  <1> 	stc
  4127 00008FCA E91DF7FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4128                              <1> 	  
  4129                              <1> rename_df_check_filename_exists:
  4130 00008FCF BE[48620100]        <1> 	mov	esi, FindFile_Name
  4131 00008FD4 E8A3F6FFFF          <1> 	call	check_filename
  4132 00008FD9 0F82BFF7FFFF        <1> 	jc	loc_mkdir_invalid_dir_name_chars
  4133                              <1> 
  4134                              <1> 	;mov	[DelFile_FNPointer], esi 
  4135                              <1> 	;cmp	byte [esi], 20h
  4136                              <1> 	;ja	short loc_rename_df_find
  4137                              <1> 
  4138                              <1> 	;mov	dh, [Current_Drv] ; dh has not been changed
  4139                              <1> 
  4140                              <1> rename_df_drv_check_writable:
  4141 00008FDF 0FB6F6              <1> 	movzx	esi, dh
  4142                              <1> 	;movzx	esi, byte [Current_Drv]
  4143 00008FE2 81C600010900        <1> 	add	esi, Logical_DOSDisks
  4144                              <1> 
  4145 00008FE8 88F2                <1> 	mov	dl, dh ; dl = [Current_Drv]
  4146 00008FEA 8A7601              <1> 	mov	dh, [esi+LD_DiskType]
  4147                              <1> 
  4148 00008FED 80FE01              <1> 	cmp	dh, 1 ; 0 = Invalid
  4149 00008FF0 7310                <1> 	jnb	short rename_df_compare_sf_df_name
  4150                              <1> 
  4151                              <1> 	; 16/10/2016 (13h -> 30)
  4152 00008FF2 B81E000000          <1> 	mov	eax, 30 ; 'Disk write-protected' error
  4153 00008FF7 8B1D[48630100]      <1> 	mov	ebx, [DestinationFilePath] 
  4154 00008FFD E9EAF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4155                              <1> 
  4156                              <1> rename_df_compare_sf_df_name:
  4157 00009002 BE[48620100]        <1> 	mov	esi, FindFile_Name
  4158 00009007 BF[8E630100]        <1> 	mov	edi, SourceFile_Name
  4159 0000900C B90C000000          <1> 	mov	ecx, 12
  4160                              <1> rename_df_compare_sf_df_name_next: 
  4161 00009011 AC                  <1> 	lodsb
  4162 00009012 AE                  <1> 	scasb
  4163 00009013 7506                <1> 	jne	short loc_rename_df_find
  4164 00009015 08C0                <1> 	or	al, al
  4165 00009017 74AB                <1> 	jz	short loc_rename_df_cmd_failed
  4166 00009019 E2F6                <1> 	loop	rename_df_compare_sf_df_name_next 
  4167                              <1> 
  4168                              <1> loc_rename_df_find:
  4169                              <1> 	;mov	esi, [DelFile_FNPointer]
  4170 0000901B BE[48620100]        <1> 	mov	esi, FindFile_Name
  4171                              <1> 
  4172 00009020 6631C0              <1> 	xor	ax, ax ; Any
  4173 00009023 E896F2FFFF          <1> 	call	find_first_file
  4174                              <1> 	;jnc	short loc_rename_df_found
  4175                              <1> 	; 29/12/2017
  4176 00009028 0F83C8F6FFFF        <1> 	jnc	loc_permission_denied
  4177                              <1> 
  4178                              <1> loc_rename_df_check_error_code:
  4179                              <1> 	;cmp	eax, 2
  4180 0000902E 3C02                <1> 	cmp	al, 2 ; Not found error
  4181 00009030 7406                <1> 	je	short rename_df_move_find_struct_to_dest
  4182 00009032 F9                  <1> 	stc
  4183 00009033 E9B4F6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4184                              <1> 
  4185                              <1> ;loc_rename_df_found:
  4186                              <1> 	; 05/11/2016
  4187                              <1> 	; Permission denied error
  4188                              <1> 	;mov	eax, ERR_PERM_DENIED ; 29/12/2017
  4189                              <1> 	;stc
  4190                              <1> 	;jmp	loc_permission_denied  ; 06/11/2016
  4191                              <1> 
  4192                              <1> rename_df_move_find_struct_to_dest:
  4193 00009038 BE[06620100]        <1>         mov     esi, FindFile_Drv
  4194 0000903D BF[CC630100]        <1>         mov     edi, DestinationFile_Drv
  4195 00009042 B920000000          <1> 	mov	ecx, 32
  4196 00009047 F3A5                <1> 	rep	movsd
  4197                              <1> 
  4198                              <1> loc_rename_df_process_q_sf:
  4199                              <1> 	;mov	ecx, 12
  4200 00009049 B10C                <1> 	mov	cl, 12
  4201 0000904B BE[8E630100]        <1>  	mov	esi, SourceFile_Name
  4202 00009050 BF[8B120100]        <1> 	mov	edi, Rename_OldName
  4203                              <1> rename_df_process_q_nml_1_sf:
  4204 00009055 AC                  <1> 	lodsb
  4205 00009056 3C20                <1>         cmp	al, 20h
  4206 00009058 7603                <1>         jna	short rename_df_process_q_nml_2_sf
  4207 0000905A AA                  <1> 	stosb
  4208 0000905B E2F8                <1> 	loop	rename_df_process_q_nml_1_sf
  4209                              <1> 
  4210                              <1> rename_df_process_q_nml_2_sf:
  4211 0000905D C60700              <1> 	mov	byte [edi], 0
  4212                              <1> 
  4213                              <1> loc_rename_df_process_q_df:
  4214                              <1> 	;mov	ecx, 12
  4215 00009060 B10C                <1> 	mov	cl, 12
  4216 00009062 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  4217 00009067 BF[9C120100]        <1> 	mov	edi, Rename_NewName
  4218                              <1> rename_df_process_q_nml_1_df:
  4219 0000906C AC                  <1> 	lodsb
  4220 0000906D 3C20                <1> 	cmp	al, 20h
  4221 0000906F 7603                <1> 	jna	short loc_rename_df_process_q_nml_2_df
  4222 00009071 AA                  <1> 	stosb
  4223 00009072 E2F8                <1> 	loop	rename_df_process_q_nml_1_df
  4224                              <1> 
  4225                              <1> loc_rename_df_process_q_nml_2_df:
  4226 00009074 C60700              <1> 	mov	byte [edi], 0
  4227                              <1> 
  4228                              <1> loc_rename_confirmation_question:
  4229 00009077 BE[63120100]        <1> 	mov	esi, Msg_DoYouWantRename
  4230 0000907C E81CD3FFFF          <1> 	call	print_msg
  4231                              <1> 
  4232 00009081 A0[A9630100]        <1> 	mov	al, [SourceFile_DirEntry+11] ; Attributes
  4233 00009086 2410                <1> 	and	al, 10h
  4234 00009088 750C                <1> 	jnz	short rename_confirmation_question_dir
  4235                              <1> 
  4236                              <1> rename_confirmation_question_file:
  4237 0000908A BE[7A120100]        <1> 	mov	esi, Rename_File
  4238 0000908F E809D3FFFF          <1> 	call	print_msg 
  4239 00009094 EB0A                <1> 	jmp	short rename_confirmation_question_as 
  4240                              <1> 
  4241                              <1> rename_confirmation_question_dir:
  4242 00009096 BE[80120100]        <1> 	mov	esi, Rename_Directory
  4243 0000909B E8FDD2FFFF          <1> 	call	print_msg
  4244                              <1> 
  4245                              <1> rename_confirmation_question_as:
  4246 000090A0 BE[8B120100]        <1> 	mov	esi, Rename_OldName
  4247 000090A5 E8F3D2FFFF          <1> 	call	print_msg
  4248 000090AA BE[98120100]        <1> 	mov	esi, Msg_File_rename_as
  4249 000090AF E8E9D2FFFF          <1> 	call	print_msg
  4250 000090B4 BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  4251 000090B9 E8DFD2FFFF          <1> 	call	print_msg
  4252                              <1> 
  4253                              <1> loc_rename_ask_again:
  4254 000090BE 30E4                <1> 	xor	ah, ah
  4255 000090C0 E8817BFFFF          <1> 	call	int16h
  4256 000090C5 3C1B                <1> 	cmp	al, 1Bh
  4257 000090C7 740F                <1> 	je	short loc_do_not_rename_file
  4258 000090C9 24DF                <1> 	and	al, 0DFh
  4259 000090CB A2[C9110100]        <1> 	mov	[Y_N_nextline], al
  4260 000090D0 3C59                <1> 	cmp	al, 'Y'
  4261 000090D2 7404                <1> 	je	short loc_yes_rename_file
  4262 000090D4 3C4E                <1> 	cmp	al, 'N'
  4263 000090D6 75E6                <1> 	jne	short loc_rename_ask_again
  4264                              <1> 
  4265                              <1> loc_do_not_rename_file:
  4266                              <1> loc_yes_rename_file:
  4267 000090D8 E848F7FFFF          <1> 	call	y_n_answer ; 29/12/2017
  4268                              <1> 	;cmp	al, 'Y' ; 'yes'
  4269                              <1> 	;cmc
  4270                              <1>         ;jnc	loc_file_rw_restore_retn
  4271 000090DD 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4272 000090DF 0F8407F6FFFF        <1>         je	loc_file_rw_restore_retn  
  4273                              <1> 
  4274 000090E5 BE[9C120100]        <1> 	mov	esi, Rename_NewName
  4275 000090EA 668B0D[C6630100]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
  4276 000090F1 66A1[B2630100]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
  4277 000090F7 C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  4278 000090FA 66A1[B8630100]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
  4279                              <1> 
  4280 00009100 0FB61D[9B630100]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]  
  4281 00009107 E8CB1B0000          <1>    	call	rename_directory_entry
  4282 0000910C E9FBF6FFFF          <1> 	jmp	loc_rename_file_ok	
  4283                              <1> ;loc_rename_file_ok:
  4284                              <1> ;	jc	loc_run_cmd_failed
  4285                              <1> ;	mov	esi, Msg_OK
  4286                              <1> ;	call	proc_printmsg
  4287                              <1> ;	jmp	loc_file_rw_restore_retn
  4288                              <1> 
  4289                              <1> move_file:
  4290                              <1> 	; 11/03/2016
  4291                              <1> 	; 09/03/2016
  4292                              <1> 	; 08/03/2016 (TRDOS 386 = TRDOS v2.0)
  4293                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_move')
  4294                              <1> 	; 23/04/2011
  4295                              <1> 
  4296                              <1> get_move_source_fchar:
  4297                              <1> 	; esi = file name
  4298 00009111 803E20              <1> 	cmp	byte [esi], 20h
  4299 00009114 7614                <1>         jna	short loc_move_nofilename_retn
  4300                              <1> 
  4301 00009116 8935[44630100]      <1> 	mov	[SourceFilePath], esi
  4302                              <1> 
  4303                              <1> move_scan_source_file:
  4304 0000911C 46                  <1> 	inc	esi
  4305 0000911D 803E20              <1> 	cmp	byte [esi], 20h
  4306 00009120 7409                <1>         je      short move_scan_destination_1
  4307                              <1> 	;jb	short loc_move_nofilename_retn
  4308 00009122 0F8286ECFFFF        <1> 	jb	loc_cmd_failed
  4309 00009128 EBF2                <1> 	jmp	short move_scan_source_file
  4310                              <1> 
  4311                              <1> loc_move_nofilename_retn:
  4312 0000912A C3                  <1> 	retn
  4313                              <1> 
  4314                              <1> move_scan_destination_1:
  4315 0000912B C60600              <1> 	mov	byte [esi], 0
  4316                              <1> 
  4317                              <1> move_scan_destination_2:
  4318 0000912E 46                  <1> 	inc	esi  
  4319 0000912F 803E20              <1> 	cmp	byte [esi], 20h
  4320 00009132 74FA                <1> 	je	short move_scan_destination_2
  4321                              <1> 	;jb	short loc_move_nofilename_retn
  4322 00009134 0F8274ECFFFF        <1> 	jb	loc_cmd_failed
  4323                              <1> 
  4324 0000913A 8935[48630100]      <1> 	mov	[DestinationFilePath], esi
  4325                              <1> 
  4326                              <1> move_scan_destination_3:
  4327 00009140 46                  <1> 	inc	esi  
  4328 00009141 803E20              <1> 	cmp	byte [esi], 20h
  4329 00009144 77FA                <1> 	ja	short move_scan_destination_3
  4330 00009146 C60600              <1> 	mov	byte [esi], 0
  4331                              <1> 
  4332                              <1> loc_move_scan_destination_OK:
  4333 00009149 8B35[44630100]      <1> 	mov	esi, [SourceFilePath]
  4334 0000914F 8B3D[48630100]      <1> 	mov	edi, [DestinationFilePath]
  4335                              <1> 
  4336 00009155 B001                <1> 	mov	al, 1  ; move procedure Phase 1
  4337 00009157 E8F71B0000          <1> 	call	move_source_file_to_destination_file
  4338 0000915C 7328                <1> 	jnc	short move_source_file_to_destination_question
  4339                              <1> 
  4340                              <1> loc_move_cmd_failed_1:
  4341 0000915E 08C0                <1> 	or	al, al
  4342 00009160 0F8448ECFFFF        <1> 	jz	loc_cmd_failed 
  4343 00009166 3C11                <1> 	cmp	al, 11h
  4344 00009168 740D                <1> 	je	short loc_msg_not_same_device   
  4345                              <1> 	;cmp	al, 05h
  4346                              <1> 	;cmp	al, ERR_PERM_DENIED ; 29/12/2017
  4347                              <1> 	;jne	loc_run_cmd_failed
  4348                              <1> 	;jmp	loc_permission_denied
  4349 0000916A 3C0B                <1> 	cmp	al, ERR_PERM_DENIED
  4350 0000916C 0F8484F5FFFF        <1> 	je	loc_permission_denied
  4351 00009172 E962ECFFFF          <1> 	jmp	loc_run_cmd_failed
  4352                              <1> 
  4353                              <1> 	;mov	esi, Msg_Permission_denied
  4354                              <1> 	;call	print_msg
  4355                              <1> 	;jmp	loc_file_rw_restore_retn
  4356                              <1> 
  4357                              <1> loc_msg_not_same_device:
  4358 00009177 BE[A9120100]        <1> 	mov	esi, msg_not_same_drv 
  4359 0000917C E81CD2FFFF          <1> 	call	print_msg
  4360 00009181 E966F5FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4361                              <1> 
  4362                              <1> move_source_file_to_destination_question:
  4363 00009186 A0[4C630100]        <1>         mov     al, [SourceFile_Drv]
  4364 0000918B 0441                <1> 	add	al, 'A'
  4365 0000918D A2[0B130100]        <1> 	mov	[msg_source_file_drv], al
  4366 00009192 A0[CC630100]        <1>         mov     al, [DestinationFile_Drv]
  4367 00009197 0441                <1> 	add	al, 'A'
  4368 00009199 A2[2A130100]        <1> 	mov	[msg_destination_file_drv], al
  4369                              <1> 
  4370 0000919E 57                  <1> 	push	edi ; *
  4371                              <1> 
  4372 0000919F BE[EF120100]        <1> 	mov	esi, msg_source_file
  4373 000091A4 E8F4D1FFFF          <1> 	call	print_msg
  4374 000091A9 BE[4D630100]        <1> 	mov	esi, SourceFile_Directory
  4375 000091AE 803E20              <1> 	cmp	byte [esi], 20h
  4376 000091B1 7605                <1> 	jna	short msftdfq_sfn
  4377 000091B3 E8E5D1FFFF          <1> 	call	print_msg
  4378                              <1> msftdfq_sfn:
  4379 000091B8 BE[8E630100]        <1> 	mov	esi, SourceFile_Name
  4380 000091BD E8DBD1FFFF          <1> 	call	print_msg
  4381 000091C2 BE[0E130100]        <1> 	mov	esi, msg_destination_file
  4382 000091C7 E8D1D1FFFF          <1> 	call	print_msg
  4383 000091CC BE[CD630100]        <1> 	mov	esi, DestinationFile_Directory
  4384 000091D1 803E20              <1> 	cmp	byte [esi], 20h
  4385 000091D4 7605                <1> 	jna	short msftdfq_dfn
  4386 000091D6 E8C2D1FFFF          <1> 	call	print_msg
  4387                              <1> msftdfq_dfn:
  4388 000091DB BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  4389 000091E0 E8B8D1FFFF          <1> 	call	print_msg
  4390 000091E5 BE[2D130100]        <1> 	mov	esi, msg_copy_nextline
  4391 000091EA E8AED1FFFF          <1> 	call	print_msg
  4392 000091EF BE[2D130100]        <1> 	mov	esi, msg_copy_nextline
  4393 000091F4 E8A4D1FFFF          <1> 	call	print_msg
  4394                              <1> 
  4395                              <1> loc_move_ask_for_new_file_yes_no:
  4396 000091F9 BE[BB120100]        <1> 	mov	esi, Msg_DoYouWantMoveFile
  4397 000091FE E89AD1FFFF          <1> 	call	print_msg
  4398 00009203 BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  4399 00009208 E890D1FFFF          <1> 	call	print_msg
  4400                              <1> loc_move_ask_for_new_file_again:
  4401 0000920D 30E4                <1> 	xor	ah, ah
  4402 0000920F E8327AFFFF          <1> 	call	int16h
  4403 00009214 3C1B                <1> 	cmp	al, 1Bh
  4404                              <1> 	;je	short loc_do_not_move_file
  4405 00009216 7441                <1> 	je	short loc_move_y_n_escape
  4406 00009218 24DF                <1> 	and	al, 0DFh
  4407 0000921A A2[C9110100]        <1>         mov     [Y_N_nextline], al
  4408 0000921F 3C59                <1> 	cmp	al, 'Y'
  4409 00009221 7404                <1> 	je	short loc_yes_move_file
  4410 00009223 3C4E                <1> 	cmp	al, 'N'
  4411 00009225 75E6                <1> 	jne	short loc_move_ask_for_new_file_again
  4412                              <1> 
  4413                              <1> loc_do_not_move_file:
  4414                              <1> loc_yes_move_file:
  4415 00009227 E8F9F5FFFF          <1> 	call	y_n_answer ; 29/12/2017
  4416 0000922C 5F                  <1> 	pop	edi ; *
  4417                              <1> 	;cmp	al, 'Y' ; 'yes'
  4418                              <1> 	;cmc
  4419                              <1>         ;jnc	loc_file_rw_restore_retn
  4420 0000922D 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4421 0000922F 0F84B7F4FFFF        <1>         je	loc_file_rw_restore_retn
  4422                              <1> 
  4423                              <1> loc_move_yes_move_file:
  4424 00009235 B002                <1> 	mov	al, 2 ; move procedure Phase 2
  4425 00009237 E8171B0000          <1> 	call	move_source_file_to_destination_file
  4426                              <1> 	;jc	short loc_move_cmd_failed_2
  4427 0000923C 0F83D0F5FFFF        <1>         jnc     move_source_file_to_destination_OK
  4428                              <1> 
  4429                              <1> ;move_source_file_to_destination_OK:
  4430                              <1> ;	mov	esi, Msg_OK
  4431                              <1> ;	call	print_msg
  4432                              <1> ;	jmp	loc_file_rw_restore_retn
  4433                              <1> 
  4434                              <1> loc_move_cmd_failed_2:
  4435 00009242 3C27                <1> 	cmp	al, 27h
  4436 00009244 0F858FEBFFFF        <1> 	jne	loc_run_cmd_failed
  4437                              <1> 
  4438 0000924A BE[D4120100]        <1> 	mov	esi, msg_insufficient_disk_space
  4439 0000924F E849D1FFFF          <1> 	call	print_msg
  4440                              <1> 
  4441 00009254 E993F4FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4442                              <1> 
  4443                              <1> loc_move_y_n_escape:
  4444 00009259 B04E                <1> 	mov	al, 'N' ; 'no'
  4445 0000925B EBCA                <1> 	jmp	short loc_do_not_move_file
  4446                              <1> 
  4447                              <1> copy_file:
  4448                              <1> 	; 15/10/2016
  4449                              <1> 	; 24/03/2016
  4450                              <1> 	; 21/03/2016
  4451                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
  4452                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_copy')
  4453                              <1> 	; 01/08/2010
  4454                              <1> 
  4455                              <1> get_copy_source_fchar:
  4456                              <1> 	; esi = file name
  4457 0000925D 803E20              <1> 	cmp	byte [esi], 20h
  4458 00009260 7614                <1>         jna     short loc_copy_nofilename_retn
  4459                              <1> 
  4460 00009262 8935[44630100]      <1> 	mov	[SourceFilePath], esi
  4461                              <1> 
  4462                              <1> copy_scan_source_file:
  4463 00009268 46                  <1> 	inc	esi  
  4464 00009269 803E20              <1> 	cmp	byte [esi], 20h
  4465 0000926C 7409                <1> 	je	short copy_scan_destination_1
  4466                              <1> 	;jb	short loc_copy_nofilename_retn
  4467 0000926E 0F823AEBFFFF        <1> 	jb	loc_cmd_failed
  4468 00009274 EBF2                <1> 	jmp	short copy_scan_source_file
  4469                              <1> 
  4470                              <1> loc_copy_nofilename_retn:
  4471 00009276 C3                  <1> 	retn
  4472                              <1> 
  4473                              <1> copy_scan_destination_1:
  4474 00009277 C60600              <1> 	mov	byte [esi], 0
  4475                              <1> 
  4476                              <1> copy_scan_destination_2:
  4477 0000927A 46                  <1> 	inc	esi  
  4478 0000927B 803E20              <1> 	cmp	byte [esi], 20h
  4479 0000927E 74FA                <1> 	je	short copy_scan_destination_2
  4480                              <1> 	;jb	short loc_copy_nofilename_retn
  4481 00009280 0F8228EBFFFF        <1> 	jb	loc_cmd_failed
  4482                              <1> 
  4483 00009286 8935[48630100]      <1> 	mov	[DestinationFilePath], esi
  4484                              <1> 
  4485                              <1> copy_scan_destination_3:
  4486 0000928C 46                  <1> 	inc	esi  
  4487 0000928D 803E20              <1> 	cmp	byte [esi], 20h
  4488 00009290 77FA                <1> 	ja	short copy_scan_destination_3
  4489 00009292 C60600              <1> 	mov	byte [esi], 0
  4490                              <1> 
  4491                              <1> loc_copy_save_current_drive:
  4492 00009295 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  4493 0000929B 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  4494                              <1> 
  4495                              <1> copy_source_file_to_destination_phase_1:
  4496 000092A1 8B35[44630100]      <1> 	mov	esi, [SourceFilePath]
  4497 000092A7 8B3D[48630100]      <1> 	mov	edi, [DestinationFilePath]
  4498                              <1> 
  4499 000092AD B001                <1> 	mov	al, 1  ; copy procedure Phase 1
  4500 000092AF E83C1D0000          <1> 	call	copy_source_file_to_destination_file
  4501 000092B4 732B                <1> 	jnc	short copy_source_file_to_destination_question
  4502                              <1> 
  4503                              <1> loc_copy_cmd_failed_1:
  4504                              <1> 	; 18/03/2016 (restore current drive and directory)
  4505 000092B6 08C0                <1> 	or	al, al
  4506 000092B8 7507                <1> 	jnz	short loc_copy_cmd_failed_2
  4507                              <1> 
  4508 000092BA FEC0                <1>         inc     al ; mov al, 1 ; Bad command or file name !
  4509 000092BC E918EBFFFF          <1> 	jmp	loc_run_cmd_failed
  4510                              <1> 
  4511                              <1> loc_copy_cmd_failed_2:
  4512 000092C1 3C27                <1> 	cmp	al, 27h ; Insufficient disk space 
  4513 000092C3 740D                <1> 	je	short loc_file_write_insuff_disk_space_msg
  4514                              <1>  
  4515                              <1> 	; 29/12/2017
  4516                              <1> 	;cmp	al, 05h
  4517 000092C5 3C0B                <1> 	cmp	al, ERR_PERM_DENIED
  4518 000092C7 0F850CEBFFFF        <1> 	jne	loc_run_cmd_failed
  4519                              <1> 	
  4520 000092CD E924F4FFFF          <1> 	jmp	loc_permission_denied
  4521                              <1> 
  4522                              <1> loc_file_write_insuff_disk_space_msg:
  4523 000092D2 BE[D4120100]        <1> 	mov	esi, msg_insufficient_disk_space
  4524 000092D7 E8C1D0FFFF          <1> 	call	print_msg
  4525 000092DC E90BF4FFFF          <1>         jmp     loc_file_rw_restore_retn 
  4526                              <1> 
  4527                              <1> copy_source_file_to_destination_question:
  4528 000092E1 57                  <1> 	push	edi ; *
  4529                              <1> 
  4530                              <1> 	; dh = source file attributes
  4531                              <1> 	; dl > 0 -> destination file found
  4532 000092E2 20D2                <1> 	and	dl, dl            
  4533 000092E4 7449                <1> 	jz	short copy_source_file_to_destination_pass_owrq
  4534                              <1> 
  4535                              <1> loc_copy_ask_for_owr_yes_no:
  4536 000092E6 BE[30130100]        <1> 	mov	esi, Msg_DoYouWantOverWriteFile
  4537 000092EB E8ADD0FFFF          <1> 	call	print_msg
  4538 000092F0 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  4539 000092F5 E8A3D0FFFF          <1> 	call	print_msg
  4540 000092FA BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  4541 000092FF E899D0FFFF          <1> 	call	print_msg
  4542                              <1> 
  4543                              <1> loc_copy_ask_for_owr_again:
  4544 00009304 30E4                <1> 	xor	ah, ah
  4545 00009306 E83B79FFFF          <1> 	call	int16h
  4546 0000930B 3C1B                <1> 	cmp	al, 1Bh
  4547                              <1>         ;je     loc_do_not_copy_file
  4548 0000930D 7419                <1>         je      short loc_copy_y_n_escape
  4549 0000930F 24DF                <1> 	and	al, 0DFh
  4550 00009311 A2[C9110100]        <1>         mov     [Y_N_nextline], al
  4551 00009316 3C59                <1> 	cmp	al, 'Y'
  4552 00009318 0F84B1000000        <1>         je      loc_yes_copy_file
  4553 0000931E 3C4E                <1> 	cmp	al, 'N'
  4554 00009320 0F84A9000000        <1>         je      loc_do_not_copy_file
  4555 00009326 EBDC                <1> 	jmp	short loc_copy_ask_for_owr_again
  4556                              <1> 
  4557                              <1> loc_copy_y_n_escape:
  4558 00009328 B04E                <1> 	mov	al, 'N' ; 'no'
  4559 0000932A E9A0000000          <1>         jmp     loc_do_not_copy_file
  4560                              <1> 
  4561                              <1> copy_source_file_to_destination_pass_owrq:
  4562 0000932F A0[4C630100]        <1> 	mov     al, [SourceFile_Drv]
  4563 00009334 0441                <1> 	add	al, 'A'
  4564 00009336 A2[0B130100]        <1> 	mov	[msg_source_file_drv], al
  4565 0000933B A0[CC630100]        <1>         mov     al, [DestinationFile_Drv]
  4566 00009340 0441                <1> 	add	al, 'A'
  4567 00009342 A2[2A130100]        <1> 	mov	[msg_destination_file_drv], al
  4568                              <1> 
  4569 00009347 BE[EF120100]        <1> 	mov	esi, msg_source_file
  4570 0000934C E84CD0FFFF          <1> 	call	print_msg
  4571 00009351 BE[4D630100]        <1> 	mov	esi, SourceFile_Directory
  4572 00009356 803E20              <1> 	cmp	byte [esi], 20h
  4573 00009359 7605                <1> 	jna	short csftdfq_sfn
  4574 0000935B E83DD0FFFF          <1> 	call	print_msg
  4575                              <1> csftdfq_sfn:
  4576 00009360 BE[8E630100]        <1> 	mov	esi, SourceFile_Name
  4577 00009365 E833D0FFFF          <1> 	call	print_msg
  4578 0000936A BE[0E130100]        <1> 	mov	esi, msg_destination_file
  4579 0000936F E829D0FFFF          <1> 	call	print_msg
  4580 00009374 BE[CD630100]        <1> 	mov	esi, DestinationFile_Directory
  4581 00009379 803E20              <1> 	cmp	byte [esi], 20h
  4582 0000937C 7605                <1> 	jna	short csftdfq_dfn
  4583 0000937E E81AD0FFFF          <1> 	call	print_msg
  4584                              <1> csftdfq_dfn:
  4585 00009383 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  4586 00009388 E810D0FFFF          <1> 	call	print_msg
  4587 0000938D BE[2D130100]        <1> 	mov	esi, msg_copy_nextline
  4588 00009392 E806D0FFFF          <1> 	call	print_msg
  4589 00009397 BE[2D130100]        <1> 	mov	esi, msg_copy_nextline
  4590 0000939C E8FCCFFFFF          <1> 	call	print_msg
  4591                              <1> 
  4592                              <1> loc_copy_ask_for_new_file_yes_no:
  4593 000093A1 BE[4F130100]        <1> 	mov	esi, Msg_DoYouWantCopyFile
  4594 000093A6 E8F2CFFFFF          <1> 	call	print_msg
  4595 000093AB BE[BF110100]        <1> 	mov	esi, Msg_YesNo
  4596 000093B0 E8E8CFFFFF          <1> 	call	print_msg
  4597                              <1> 
  4598                              <1> loc_copy_ask_for_new_file_again:
  4599 000093B5 30E4                <1> 	xor	ah, ah
  4600 000093B7 E88A78FFFF          <1> 	call	int16h
  4601 000093BC 3C1B                <1> 	cmp	al, 1Bh
  4602 000093BE 740F                <1> 	je	short loc_do_not_copy_file
  4603 000093C0 24DF                <1> 	and	al, 0DFh
  4604 000093C2 A2[C9110100]        <1>         mov     [Y_N_nextline], al
  4605 000093C7 3C59                <1> 	cmp	al, 'Y'
  4606 000093C9 7404                <1> 	je	short loc_yes_copy_file
  4607 000093CB 3C4E                <1> 	cmp	al, 'N'
  4608 000093CD 75E6                <1> 	jne	short loc_copy_ask_for_new_file_again
  4609                              <1> 
  4610                              <1> loc_do_not_copy_file:
  4611                              <1> loc_yes_copy_file:
  4612 000093CF E851F4FFFF          <1> 	call	y_n_answer ; 29/12/2017
  4613 000093D4 5F                  <1> 	pop	edi ; *
  4614                              <1> 	;cmp	al, 'Y' ; 'yes'
  4615                              <1> 	;cmc
  4616                              <1>         ;jnc	loc_file_rw_restore_retn
  4617 000093D5 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4618 000093D7 0F840FF3FFFF        <1>         je	loc_file_rw_restore_retn
  4619                              <1> 
  4620                              <1> copy_source_file_to_destination_pass_q:
  4621 000093DD B002                <1> 	mov	al, 2  ; copy procedure Phase 2
  4622 000093DF E80C1C0000          <1> 	call	copy_source_file_to_destination_file
  4623                              <1> 	;jc	short loc_file_write_check_disk_space_err
  4624                              <1> 
  4625                              <1> 	; 24/03/2016
  4626                              <1> 	;push	cx
  4627 000093E4 51                  <1> 	push	ecx ; 29/12/2017
  4628 000093E5 BE[2D130100]        <1> 	mov	esi, msg_copy_nextline
  4629 000093EA E8AECFFFFF          <1> 	call	print_msg
  4630 000093EF 58                  <1> 	pop	eax ; 29/12/2017
  4631                              <1> 	;;pop	cx
  4632                              <1> 	;pop	ax
  4633                              <1> 
  4634                              <1> 	;or	cl, cl
  4635 000093F0 08C0                <1> 	or	al, al
  4636 000093F2 7419                <1> 	jz	short copy_source_file_to_destination_OK
  4637                              <1> 	
  4638                              <1> 	; 15/10/2016 (1Dh -> 18)
  4639                              <1> 	; 18/03/2016 (1Dh)
  4640                              <1> 	;cmp	cl, 18 ; write error
  4641 000093F4 3C12                <1> 	cmp	al, 18
  4642 000093F6 7506                <1> 	jne	short copy_source_file_to_destination_not_OK
  4643                              <1> 	;
  4644                              <1> 	;mov	al, cl ; error number (write fault!)
  4645 000093F8 F9                  <1> 	stc
  4646 000093F9 E9EEF2FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4647                              <1> 
  4648                              <1> copy_source_file_to_destination_not_OK:
  4649 000093FE BE[68130100]        <1> 	mov	esi, Msg_read_file_error_before_EOF
  4650 00009403 E895CFFFFF          <1> 	call	print_msg
  4651 00009408 E9DFF2FFFF          <1> 	jmp	loc_file_rw_restore_retn	      
  4652                              <1>  
  4653                              <1> copy_source_file_to_destination_OK:
  4654 0000940D BE[CD110100]        <1> 	mov	esi, Msg_OK
  4655 00009412 E886CFFFFF          <1> 	call	print_msg
  4656                              <1> 
  4657 00009417 E9D0F2FFFF          <1> 	jmp	loc_file_rw_restore_retn
  4658                              <1> 
  4659                              <1> ;loc_file_write_check_disk_space_err:
  4660                              <1> 	;cmp	al, 27h ; Insufficient disk space 
  4661                              <1> 	;je	loc_file_write_insuff_disk_space_msg
  4662                              <1>         ;jb	loc_file_rw_cmd_failed
  4663                              <1> 
  4664                              <1> 	;call	print_misc_error_msg ; 15/03/2016
  4665                              <1>         ;jmp	loc_file_rw_restore_retn 
  4666                              <1> 
  4667                              <1> change_fs_file_attributes:
  4668                              <1> 	; 04/03/2016 ; Temporary
  4669                              <1> 	; AL = File or directory attributes
  4670                              <1> 	; AH = 0 -> Attributes are in MS-DOS format
  4671                              <1> 	; AH > 0 -> Attributes are in SINGLIX format
  4672                              <1> 	;push	ebx
  4673                              <1> 	; ... do somethings here ...
  4674                              <1> 	;pop	ebx
  4675                              <1> 	; BL = File or directory attributes
  4676 0000941C C3                  <1> 	retn
  4677                              <1> 
  4678                              <1> set_get_env:
  4679                              <1> 	; 11/04/2016 (TRDOS 386 = TRDOS v2.0)
  4680                              <1> 	; 02/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_set')
  4681                              <1> 	; 2005 - 28/08/2011 
  4682                              <1> get_setenv_fchar:
  4683                              <1> 	; esi = environment variable/string
  4684 0000941D 8A06                <1> 	mov	al, [esi]
  4685 0000941F 3C20                <1> 	cmp	al, 20h
  4686 00009421 771E                <1> 	ja	short loc_find_env
  4687                              <1> 
  4688 00009423 BE00300900          <1> 	mov	esi, Env_Page
  4689                              <1> loc_print_setline:
  4690 00009428 803E00              <1> 	cmp	byte [esi], 0
  4691 0000942B 7613                <1> 	jna	short loc_setenv_retn
  4692 0000942D E86BCFFFFF          <1> 	call	print_msg
  4693 00009432 56                  <1> 	push	esi
  4694 00009433 BE[D7190100]        <1> 	mov	esi, nextline
  4695 00009438 E860CFFFFF          <1> 	call	print_msg 
  4696 0000943D 5E                  <1> 	pop	esi
  4697 0000943E EBE8                <1> 	jmp	short loc_print_setline   
  4698                              <1> 
  4699                              <1> loc_setenv_retn: 
  4700 00009440 C3                  <1> 	retn
  4701                              <1> 
  4702                              <1> loc_find_env:
  4703 00009441 3C3D                <1> 	cmp	al, '='
  4704 00009443 0F8465E9FFFF        <1> 	je	loc_cmd_failed
  4705                              <1> 
  4706 00009449 56                  <1> 	push	esi
  4707                              <1> loc_repeat_env_equal_check:
  4708 0000944A 46                  <1> 	inc	esi
  4709 0000944B 803E3D              <1> 	cmp	byte [esi], '='
  4710 0000944E 7431                <1> 	je	short pass_env_equal_check
  4711 00009450 803E20              <1> 	cmp	byte [esi], 20h
  4712 00009453 73F5                <1> 	jnb	short loc_repeat_env_equal_check
  4713 00009455 C60600              <1> 	mov	byte [esi], 0 
  4714 00009458 5E                  <1> 	pop	esi
  4715 00009459 BF[6E5A0100]        <1> 	mov	edi, TextBuffer ; out buffer
  4716 0000945E B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
  4717 00009463 30C0                <1> 	xor	al, al ; 0 -> use [ESI]
  4718 00009465 E89E000000          <1> 	call	get_environment_string
  4719 0000946A 72D4                <1> 	jc	short loc_setenv_retn
  4720                              <1> 
  4721 0000946C BE[6E5A0100]        <1> 	mov	esi, TextBuffer
  4722 00009471 E827CFFFFF          <1> 	call	print_msg
  4723 00009476 BE[D7190100]        <1> 	mov	esi, nextline
  4724 0000947B E81DCFFFFF          <1> 	call	print_msg
  4725                              <1> 
  4726 00009480 C3                  <1> 	retn 
  4727                              <1>               
  4728                              <1> pass_env_equal_check:
  4729 00009481 46                  <1> 	inc	esi
  4730 00009482 803E20              <1> 	cmp	byte [esi], 20h
  4731 00009485 73FA                <1> 	jnb	short pass_env_equal_check
  4732 00009487 C60600              <1> 	mov	byte [esi], 0	
  4733                              <1> 
  4734                              <1> loc_call_set_env_string:
  4735 0000948A 5E                  <1> 	pop	esi
  4736 0000948B E83B010000          <1> 	call	set_environment_string
  4737 00009490 73AE                <1> 	jnc	short loc_setenv_retn
  4738                              <1> 
  4739                              <1> loc_set_cmd_failed:
  4740 00009492 3C08                <1> 	cmp	al, 08h
  4741 00009494 0F8514E9FFFF        <1> 	jne	loc_cmd_failed
  4742                              <1> 
  4743 0000949A BE[A8130100]        <1> 	mov	esi, Msg_No_Set_Space
  4744 0000949F E8F9CEFFFF          <1> 	call	print_msg
  4745                              <1> 
  4746 000094A4 C3                  <1> 	retn
  4747                              <1> 
  4748                              <1> set_get_path:
  4749                              <1> 	; 11/04/2016 (TRDOS 386 = TRDOS v2.0)
  4750                              <1> 	; 03/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_path')
  4751                              <1> 	; 2005
  4752                              <1> get_path_fchar:
  4753                              <1>  	; esi = path
  4754 000094A5 803E20              <1> 	cmp	byte [esi], 20h
  4755 000094A8 7737                <1> 	ja	short loc_set_path
  4756                              <1> 
  4757 000094AA BE00300900          <1> 	mov	esi, Env_Page
  4758                              <1> loc_print_path:
  4759 000094AF 803E00              <1> 	cmp	byte [esi], 0
  4760 000094B2 762C                <1> 	jna	short loc_path_retn
  4761                              <1> 
  4762 000094B4 BE[070E0100]        <1> 	mov	esi, Cmd_Path ; 'PATH' address
  4763 000094B9 BF[6E5A0100]        <1> 	mov	edi, TextBuffer ; out buffer
  4764 000094BE 30C0                <1> 	xor	al, al  ; use [ESI]
  4765 000094C0 B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
  4766 000094C5 E83E000000          <1> 	call	get_environment_string
  4767 000094CA 7214                <1> 	jc	short loc_path_retn
  4768                              <1> 
  4769 000094CC BE[6E5A0100]        <1> 	mov	esi, TextBuffer
  4770 000094D1 E8C7CEFFFF          <1> 	call	print_msg
  4771 000094D6 BE[D7190100]        <1> 	mov	esi, nextline
  4772 000094DB E8BDCEFFFF          <1> 	call	print_msg   
  4773                              <1> 
  4774                              <1> loc_path_retn: 
  4775 000094E0 C3                  <1> 	retn
  4776                              <1> 
  4777                              <1> loc_set_path:
  4778 000094E1 56                  <1> 	push	esi 
  4779                              <1> loc_set_path_find_end:
  4780 000094E2 46                  <1> 	inc	esi
  4781 000094E3 803E20              <1> 	cmp	byte [esi], 20h
  4782 000094E6 73FA                <1> 	jnb	short loc_set_path_find_end
  4783 000094E8 C60600              <1> 	mov	byte [esi], 0 
  4784                              <1> loc_set_path_header: 
  4785 000094EB 5E                  <1> 	pop	esi
  4786                              <1> set_path_x: ; 31/12/2017 ('syspath')	  
  4787 000094EC 4E                  <1> 	dec	esi
  4788 000094ED C6063D              <1> 	mov	byte [esi], '='
  4789 000094F0 4E                  <1> 	dec	esi
  4790 000094F1 C60648              <1> 	mov	byte [esi], 'H'
  4791 000094F4 4E                  <1> 	dec	esi
  4792 000094F5 C60654              <1> 	mov	byte [esi], 'T'
  4793 000094F8 4E                  <1> 	dec	esi
  4794 000094F9 C60641              <1> 	mov	byte [esi], 'A'
  4795 000094FC 4E                  <1> 	dec	esi
  4796 000094FD C60650              <1> 	mov	byte [esi], 'P'   
  4797                              <1> 
  4798                              <1> loc_path_call_set_env_string:
  4799 00009500 E8C6000000          <1> 	call	set_environment_string
  4800 00009505 728B                <1>         jc	short loc_set_cmd_failed
  4801                              <1> 
  4802 00009507 C3                  <1> 	retn              
  4803                              <1> 
  4804                              <1> get_environment_string:
  4805                              <1> 	; 12/04/2016
  4806                              <1> 	; 11/04/2016
  4807                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
  4808                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  4809                              <1> 	; 28/08/2011
  4810                              <1> 	; INPUT->
  4811                              <1> 	;	EDI = Output buffer
  4812                              <1> 	;	CX = Buffer length (<= ENV_PAGE_SIZE)
  4813                              <1> 	;
  4814                              <1> 	;	AL > 0 = AL = String sequence number
  4815                              <1> 	;	AL = 0 -> ESI = ASCIIZ Set word 
  4816                              <1> 	;		(environment variable)
  4817                              <1> 	; OUTPUT ->
  4818                              <1> 	;	ESI is not changed
  4819                              <1> 	;	EDI is not changed
  4820                              <1> 	;	EAX = String length (with zero tail)
  4821                              <1> 	;	EDX = Environment variables page address
  4822                              <1> 	;	CF = 1 -> Not found (EAX not valid)
  4823                              <1> 	;
  4824                              <1> 	; (Modified registers: EAX, EDX) 
  4825                              <1> 
  4826 00009508 BA00300900          <1> 	mov	edx, Env_Page
  4827 0000950D 803A00              <1> 	cmp	byte [edx], 0
  4828 00009510 7474                <1> 	jz	short get_env_string_with_word_stc_retn
  4829                              <1> 
  4830 00009512 66890D[D0640100]    <1> 	mov	[env_var_length], cx
  4831                              <1> 
  4832 00009519 51                  <1> 	push	ecx ; *
  4833 0000951A 56                  <1> 	push	esi ; **
  4834                              <1> 
  4835 0000951B 08C0                <1> 	or	al, al
  4836 0000951D 7449                <1> 	jz	short get_env_string_with_word
  4837                              <1> 
  4838                              <1> get_env_string_with_seq_number:
  4839 0000951F B101                <1> 	mov	cl, 1
  4840 00009521 88C5                <1> 	mov	ch, al
  4841 00009523 31C0                <1> 	xor	eax, eax
  4842 00009525 89D6                <1> 	mov	esi, edx ; Env_Page
  4843                              <1> 
  4844                              <1> get_env_string_seq_number_check:
  4845 00009527 38CD                <1> 	cmp	ch, cl
  4846 00009529 7726                <1> 	ja	short get_env_string_seq_number_next
  4847                              <1> 
  4848                              <1> get_env_string_move_to_buff:
  4849 0000952B 57                  <1> 	push	edi ; ***
  4850                              <1> 
  4851 0000952C 29D2                <1> 	sub	edx, edx
  4852                              <1> 
  4853                              <1> get_env_string_seq_number_repeat1:
  4854 0000952E 42                  <1> 	inc	edx
  4855 0000952F AC                  <1> 	lodsb
  4856 00009530 AA                  <1> 	stosb
  4857                              <1> 
  4858 00009531 66FF0D[D0640100]    <1> 	dec	word [env_var_length]
  4859 00009538 7508                <1> 	jnz	short get_env_string_seq_number_repeat3
  4860                              <1> 
  4861                              <1> get_env_string_seq_number_repeat2:
  4862 0000953A 20C0                <1> 	and	al, al
  4863 0000953C 7408                <1> 	jz	short get_env_string_seq_number_ok
  4864 0000953E 42                  <1> 	inc	edx
  4865 0000953F AC                  <1> 	lodsb
  4866 00009540 EBF8                <1> 	jmp	short get_env_string_seq_number_repeat2
  4867                              <1> 
  4868                              <1> get_env_string_seq_number_repeat3:
  4869 00009542 08C0                <1> 	or	al, al
  4870 00009544 75E8                <1> 	jnz	short get_env_string_seq_number_repeat1
  4871                              <1> 
  4872                              <1> get_env_string_seq_number_ok:
  4873 00009546 5F                  <1> 	pop	edi ; ***
  4874 00009547 89D0                <1> 	mov	eax, edx ; Length of the environment string
  4875                              <1> 			 ; (ASCIIZ, includes ZERO tail)
  4876 00009549 BA00300900          <1> 	mov	edx, Env_Page
  4877                              <1> 
  4878                              <1> get_env_string_stc_retn:
  4879 0000954E 5E                  <1> 	pop	esi ; **
  4880 0000954F 59                  <1> 	pop	ecx ; *
  4881 00009550 C3                  <1> 	retn   
  4882                              <1> 	
  4883                              <1> get_env_string_seq_number_next:
  4884 00009551 AC                  <1> 	lodsb
  4885 00009552 08C0                <1> 	or	al, al
  4886 00009554 75FB                <1> 	jnz	short get_env_string_seq_number_next
  4887                              <1> 
  4888 00009556 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; +512 (+4096)
  4889 0000955C F5                  <1> 	cmc
  4890 0000955D 72EF                <1> 	jc	short get_env_string_stc_retn
  4891                              <1> 
  4892 0000955F AC                  <1> 	lodsb
  4893 00009560 3C01                <1> 	cmp	al, 1
  4894 00009562 72EA                <1> 	jb	short get_env_string_stc_retn
  4895 00009564 FEC1                <1> 	inc	cl
  4896 00009566 EBBF                <1> 	jmp	short get_env_string_seq_number_check
  4897                              <1> 
  4898                              <1> get_env_string_with_word:
  4899 00009568 31C9                <1> 	xor	ecx, ecx
  4900                              <1> 
  4901                              <1> get_env_string_calc_word_length:
  4902 0000956A AC                  <1> 	lodsb 
  4903 0000956B 3C20                <1> 	cmp	al, 20h
  4904 0000956D 7211                <1> 	jb	short get_env_string_calc_word_length_ok
  4905                              <1> 	;inc	cx
  4906 0000956F FEC1                <1> 	inc	cl
  4907                              <1> 
  4908 00009571 3C61                <1> 	cmp	al, 'a'
  4909 00009573 72F5                <1> 	jb	short get_env_string_calc_word_length
  4910 00009575 3C7A                <1> 	cmp	al, 'z'
  4911 00009577 77F1                <1> 	ja	short get_env_string_calc_word_length
  4912 00009579 24DF                <1> 	and	al, 0DFh
  4913 0000957B 8846FF              <1> 	mov	[esi-1], al
  4914 0000957E EBEA                <1> 	jmp	short get_env_string_calc_word_length
  4915                              <1> 	
  4916                              <1> get_env_string_calc_word_length_ok:
  4917 00009580 08C9                <1> 	or	cl, cl
  4918 00009582 7506                <1> 	jnz	short get_env_string_calc_word_length_save
  4919                              <1>      
  4920 00009584 5E                  <1> 	pop	esi ; **
  4921                              <1> 
  4922                              <1> get_env_string_stc_retn1:
  4923 00009585 59                  <1> 	pop	ecx ; *
  4924                              <1>         
  4925                              <1> get_env_string_with_word_stc_retn:
  4926 00009586 31C0                <1> 	xor	eax, eax  
  4927 00009588 F9                  <1> 	stc
  4928 00009589 C3                  <1> 	retn
  4929                              <1>   
  4930                              <1> get_env_string_calc_word_length_save:
  4931 0000958A 871C24              <1> 	xchg	ebx, [esp] ; **
  4932 0000958D 89DE                <1> 	mov	esi, ebx 
  4933                              <1> 		; Start of the env string (to be searched)
  4934                              <1> 
  4935 0000958F 57                  <1> 	push	edi ; ***
  4936 00009590 89D7                <1> 	mov	edi, edx ; Env_Page
  4937                              <1> 
  4938                              <1> get_env_string_compare:
  4939 00009592 57                  <1> 	push	edi ; ****
  4940 00009593 51                  <1> 	push	ecx ; ***** ; Variable name length
  4941                              <1> 
  4942                              <1> get_env_string_compare_rep:
  4943 00009594 AC                  <1> 	lodsb
  4944 00009595 AE                  <1> 	scasb
  4945 00009596 7511                <1> 	jne	short get_env_string_compare_next1
  4946 00009598 E2FA                <1> 	loop	get_env_string_compare_rep
  4947                              <1> 	
  4948 0000959A 803F3D              <1> 	cmp	byte [edi], '='
  4949 0000959D 750A                <1> 	jne	short get_env_string_compare_next1
  4950                              <1>  
  4951 0000959F 59                  <1> 	pop	ecx ; *****
  4952 000095A0 5F                  <1> 	pop	edi ; ****
  4953 000095A1 89FE                <1> 	mov	esi, edi
  4954 000095A3 5F                  <1> 	pop	edi ; ***
  4955 000095A4 871C24              <1> 	xchg	ebx, [esp] ; **
  4956 000095A7 EB82                <1> 	jmp	short get_env_string_move_to_buff
  4957                              <1> 
  4958                              <1> get_env_string_compare_next1:
  4959 000095A9 89FE                <1> 	mov	esi, edi
  4960 000095AB 59                  <1> 	pop	ecx ; *****
  4961 000095AC 5F                  <1> 	pop	edi ; ****
  4962                              <1> get_env_string_compare_next2:
  4963 000095AD 81FEFF310900        <1> 	cmp	esi, Env_Page + Env_Page_Size - 1 ; +511 (+4095)
  4964 000095B3 7310                <1> 	jnb	short get_env_string_compare_not_ok
  4965 000095B5 20C0                <1> 	and	al, al
  4966 000095B7 AC                  <1> 	lodsb
  4967 000095B8 75F3                <1> 	jnz	short get_env_string_compare_next2
  4968 000095BA 08C0                <1> 	or	al, al
  4969 000095BC 7407                <1> 	jz	short get_env_string_compare_not_ok
  4970 000095BE 4E                  <1> 	dec	esi ; 12/04/2016
  4971 000095BF 89F7                <1> 	mov	edi, esi
  4972 000095C1 89DE                <1> 	mov	esi, ebx
  4973 000095C3 EBCD                <1> 	jmp	short get_env_string_compare
  4974                              <1> 
  4975                              <1> get_env_string_compare_not_ok:
  4976 000095C5 5F                  <1> 	pop	edi ; ***
  4977 000095C6 89DE                <1> 	mov	esi, ebx
  4978 000095C8 5B                  <1> 	pop	ebx ; **
  4979 000095C9 EBBA                <1> 	jmp	short get_env_string_stc_retn1
  4980                              <1> 
  4981                              <1> set_environment_string:
  4982                              <1> 	; 13/04/2016
  4983                              <1> 	; 12/04/2016
  4984                              <1> 	; 11/04/2016
  4985                              <1> 	; 06/04/2016
  4986                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
  4987                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  4988                              <1> 	; 29/08/2011
  4989                              <1> 	; 29/08/2011
  4990                              <1> 	; INPUT->
  4991                              <1> 	;	ESI = ASCIIZ environment string
  4992                              <1> 	; OUTPUT ->
  4993                              <1> 	;	ESI is not changed
  4994                              <1> 	;	CF = 1 -> Could not set, 
  4995                              <1> 	;	     insufficient environment space
  4996                              <1> 	;
  4997                              <1> 	; (EAX, EDX will be changed) 
  4998                              <1> 	;
  4999                              <1> 	;    (EAX = Start address of the env string if > 0)	
  5000                              <1> 	;    (EDX = Environment string length)	
  5001                              <1> 
  5002 000095CB 56                  <1> 	push 	esi ; *
  5003                              <1> 
  5004 000095CC 31C0                <1> 	xor	eax, eax
  5005                              <1> 
  5006                              <1> set_env_chk_validation1:
  5007 000095CE FEC4                <1> 	inc	ah ; variable (string) length
  5008 000095D0 AC                  <1> 	lodsb
  5009 000095D1 3C3D                <1> 	cmp	al, '='
  5010 000095D3 7415                <1> 	je	short set_env_chk_validation2
  5011 000095D5 3C20                <1> 	cmp	al, 20h
  5012 000095D7 720F                <1> 	jb	short set_env_string_stc
  5013                              <1> 
  5014                              <1> 	; 06/04/2016
  5015 000095D9 3C61                <1> 	cmp	al, 'a'
  5016 000095DB 72F1                <1> 	jb	short set_env_chk_validation1
  5017 000095DD 3C7A                <1> 	cmp	al, 'z'
  5018 000095DF 77ED                <1> 	ja	short set_env_chk_validation1
  5019 000095E1 2C20                <1> 	sub	al, 'a'-'A'
  5020 000095E3 8846FF              <1> 	mov	[esi-1], al
  5021 000095E6 EBE6                <1> 	jmp	short set_env_chk_validation1
  5022                              <1> 
  5023                              <1> set_env_string_stc:
  5024 000095E8 5E                  <1> 	pop	esi ; *
  5025                              <1> 	;stc
  5026 000095E9 C3                  <1> 	retn 
  5027                              <1> 	   
  5028                              <1> set_env_chk_validation2:
  5029 000095EA 51                  <1> 	push	ecx ; **
  5030 000095EB 53                  <1> 	push	ebx ; *** 
  5031 000095EC 57                  <1> 	push	edi ; ****
  5032                              <1> 
  5033                              <1> 	; 12/04/2016
  5034 000095ED 8B5C240C            <1> 	mov	ebx, [esp+12]
  5035                              <1> 
  5036                              <1> set_env_chk_validation2w:
  5037 000095F1 89F7                <1> 	mov	edi, esi
  5038 000095F3 4F                  <1> 	dec	edi
  5039                              <1> 
  5040 000095F4 807FFF20            <1> 	cmp	byte [edi-1], 20h
  5041 000095F8 771A                <1> 	ja	short set_env_chk_validation2z
  5042                              <1> 	
  5043 000095FA 56                  <1> 	push	esi
  5044 000095FB 89FE                <1> 	mov	esi, edi
  5045 000095FD 4E                  <1> 	dec	esi
  5046                              <1> 
  5047                              <1> set_env_chk_validation2x:
  5048 000095FE 4E                  <1> 	dec	esi
  5049                              <1> 
  5050 000095FF 39DE                <1> 	cmp	esi, ebx
  5051 00009601 7207                <1> 	jb	short set_env_chk_validation2y
  5052                              <1> 
  5053 00009603 4F                  <1> 	dec	edi
  5054                              <1> 
  5055 00009604 8A06                <1> 	mov	al, [esi]
  5056 00009606 8807                <1> 	mov	[edi], al
  5057                              <1> 
  5058 00009608 EBF4                <1> 	jmp	short set_env_chk_validation2x
  5059                              <1> 
  5060                              <1> set_env_chk_validation2y:
  5061 0000960A 5E                  <1> 	pop	esi
  5062                              <1> 
  5063                              <1> 	;mov	byte [ebx], 20h
  5064                              <1> 	
  5065 0000960B 43                  <1> 	inc 	ebx
  5066 0000960C 895C240C            <1> 	mov	[esp+12], ebx
  5067                              <1> 
  5068 00009610 FECC                <1> 	dec 	ah ; 13/04/2016
  5069                              <1> 
  5070 00009612 EBDD                <1> 	jmp	short set_env_chk_validation2w
  5071                              <1> 	
  5072                              <1> set_env_chk_validation2z:	
  5073 00009614 BA00300900          <1> 	mov	edx, Env_Page
  5074 00009619 89D7                <1> 	mov	edi, edx
  5075                              <1> 
  5076                              <1> set_env_chk_validation3:
  5077 0000961B AC                  <1> 	lodsb
  5078 0000961C 3C20                <1> 	cmp	al, 20h
  5079 0000961E 74FB                <1> 	je	short set_env_chk_validation3
  5080                              <1> 
  5081 00009620 9C                  <1> 	pushf
  5082                              <1> 
  5083                              <1> 	; 12/04/2016
  5084                              <1> set_env_chk_validation3n:
  5085 00009621 3C61                <1> 	cmp	al, 'a'
  5086 00009623 720C                <1> 	jb	short set_env_chk_validation3c
  5087 00009625 3C7A                <1> 	cmp	al, 'z'
  5088 00009627 7705                <1> 	ja	short set_env_chk_validation3x
  5089 00009629 2C20                <1> 	sub	al, 'a'-'A'
  5090 0000962B 8846FF              <1> 	mov	[esi-1], al
  5091                              <1> 
  5092                              <1> set_env_chk_validation3x:
  5093 0000962E AC                  <1> 	lodsb
  5094 0000962F EBF0                <1> 	jmp	short set_env_chk_validation3n
  5095                              <1> 
  5096                              <1> set_env_chk_validation3c:
  5097 00009631 3C20                <1> 	cmp	al, 20h
  5098 00009633 73F9                <1> 	jnb	short set_env_chk_validation3x
  5099                              <1> 		
  5100 00009635 803F00              <1> 	cmp	byte [edi], 0
  5101 00009638 7731                <1> 	ja	short set_env_chk_validation4
  5102                              <1> 
  5103 0000963A 9D                  <1> 	popf
  5104 0000963B 7228                <1> 	jb	short set_env_string_nothing
  5105                              <1> 
  5106 0000963D B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)
  5107                              <1> 
  5108 00009642 89DE                <1> 	mov	esi, ebx ; 12/04/2016
  5109                              <1> 
  5110                              <1> set_env_string_copy_to_envb:
  5111 00009644 AC                  <1> 	lodsb
  5112 00009645 3C20                <1> 	cmp	al, 20h
  5113 00009647 720A                <1> 	jb	short set_env_string_copy_to_envb_z
  5114 00009649 AA                  <1> 	stosb
  5115 0000964A E2F8                <1> 	loop	set_env_string_copy_to_envb
  5116                              <1> 
  5117                              <1> 	; 11/04/2016
  5118 0000964C 89D7                <1> 	mov	edi, edx ; Env_Page
  5119 0000964E B900020000          <1> 	mov	ecx, Env_Page_Size 
  5120                              <1> 
  5121                              <1> set_env_string_copy_to_envb_z:
  5122 00009653 52                  <1> 	push	edx  ; Start address of the variable
  5123 00009654 BA00020000          <1> 	mov	edx, Env_Page_Size
  5124 00009659 29CA                <1> 	sub	edx, ecx ; variable (string) length
  5125                              <1> 
  5126 0000965B 28C0                <1> 	sub	al, al ; 0
  5127 0000965D F3AA                <1>  	rep	stosb ; clear remain bytes of the env page
  5128                              <1> 
  5129 0000965F 58                  <1> 	pop	eax  ; Start address of the variable
  5130                              <1> 
  5131                              <1> set_env_string_allocate_envb_retn:  ; stc or clc return
  5132 00009660 5F                  <1> 	pop	edi ; ****
  5133 00009661 5B                  <1> 	pop	ebx ; ***
  5134 00009662 59                  <1> 	pop	ecx ; **
  5135 00009663 5E                  <1> 	pop	esi ; *	
  5136 00009664 C3                  <1> 	retn
  5137                              <1> 
  5138                              <1> set_env_string_nothing:
  5139 00009665 31C0                <1> 	xor	eax, eax
  5140 00009667 31D2                <1> 	xor	edx, edx ; 11/04/2016
  5141 00009669 EBF5                <1> 	jmp	short set_env_string_allocate_envb_retn
  5142                              <1> 
  5143                              <1> set_env_chk_validation4:
  5144                              <1> 	; 11/04/2016
  5145 0000966B 9D                  <1> 	popf
  5146                              <1> 
  5147 0000966C 89D6                <1> 	mov	esi, edx  ; Env_Page
  5148                              <1> 
  5149                              <1> set_env_chk_validation5:	
  5150 0000966E 89DF                <1> 	mov	edi, ebx  ; ASCIIZ environment string address	
  5151 00009670 0FB6CC              <1> 	movzx	ecx, ah ; Variable (string) length (with '=')
  5152                              <1> 
  5153                              <1> set_env_chk_validation5_loop:
  5154 00009673 AC                  <1> 	lodsb
  5155 00009674 AE                  <1> 	scasb
  5156 00009675 750A                <1> 	jne	short set_env_chk_validation6
  5157 00009677 E2FA                <1> 	loop	set_env_chk_validation5_loop
  5158                              <1> 
  5159 00009679 3C3D                <1> 	cmp	al, '='
  5160 0000967B 0F8483000000        <1>         je      set_env_change_variable
  5161                              <1> 
  5162                              <1> set_env_chk_validation6:
  5163 00009681 08C0                <1> 	or	al, al ; 0
  5164 00009683 7403                <1> 	jz	short set_env_chk_validation7
  5165                              <1> 
  5166 00009685 AC                  <1> 	lodsb
  5167 00009686 EBF9                <1> 	jmp	short set_env_chk_validation6
  5168                              <1> 
  5169                              <1> set_env_chk_validation7:
  5170 00009688 88E1                <1> 	mov	cl, ah
  5171 0000968A 01F1                <1> 	add	ecx, esi
  5172 0000968C 81F9FF310900        <1> 	cmp	ecx, Env_Page + Env_Page_Size - 1 
  5173                              <1> 		; 511 (4095) 
  5174                              <1> 		; strlen + '=' + 0
  5175 00009692 72DA                <1> 	jb	short set_env_chk_validation5
  5176                              <1> 
  5177                              <1> set_env_chk_validation8: ; variable not found
  5178 00009694 0FB6F4              <1> 	movzx	esi, ah  ; variable name length (with '=') 
  5179 00009697 01DE                <1> 	add	esi, ebx ; position just after of the '='
  5180                              <1> 
  5181                              <1> set_env_chk_validation8_loop:
  5182 00009699 AC                  <1> 	lodsb
  5183 0000969A 3C20                <1> 	cmp	al, 20h
  5184 0000969C 74FB                <1> 	je	short set_env_chk_validation8_loop	
  5185 0000969E 72C5                <1> 	jb	short set_env_string_nothing
  5186                              <1> 
  5187                              <1> set_env_chk_validation9:
  5188 000096A0 AC                  <1> 	lodsb
  5189 000096A1 3C20                <1> 	cmp	al, 20h
  5190 000096A3 73FB                <1> 	jnb	short set_env_chk_validation9
  5191                              <1> 
  5192                              <1> 	; End of ASCIIZ environment string
  5193                              <1> 
  5194                              <1> set_env_add_variable:
  5195 000096A5 29DE                <1> 	sub	esi, ebx ; variable+definition length
  5196                              <1> 	
  5197 000096A7 56                  <1> 	push	esi ; *****
  5198                              <1> 
  5199 000096A8 89D6                <1> 	mov	esi, edx ; Environment page address
  5200                              <1> 
  5201 000096AA B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)	
  5202                              <1> 
  5203                              <1> set_env_add_variable_loop:
  5204 000096AF AC                  <1> 	lodsb
  5205 000096B0 20C0                <1> 	and	al, al		
  5206 000096B2 7406                <1> 	jz	short set_env_add_variable_chk1 ; 0
  5207 000096B4 E2F9                <1> 	loop	set_env_add_variable_loop
  5208                              <1> 
  5209                              <1> 	; 11/04/2016
  5210 000096B6 884EFF              <1> 	mov	[esi-1], cl ; 0
  5211 000096B9 41                  <1> 	inc	ecx
  5212                              <1> 	
  5213                              <1> set_env_add_variable_chk1: 
  5214 000096BA 49                  <1> 	dec	ecx
  5215 000096BB 7408                <1> 	jz	short set_env_add_variable_nspc
  5216 000096BD AC                  <1> 	lodsb
  5217 000096BE 08C0                <1> 	or 	al, al
  5218 000096C0 740C                <1> 	jz	short set_env_add_variable_chk2 ; 00
  5219 000096C2 49                  <1> 	dec	ecx
  5220 000096C3 75EA                <1> 	jnz	short set_env_add_variable_loop
  5221                              <1> 
  5222                              <1> set_env_add_variable_nspc: ; no space on environment page
  5223 000096C5 58                  <1> 	pop	eax ; *****
  5224 000096C6 B808000000          <1> 	mov	eax, 8 ; No space for new environment string
  5225 000096CB F9                  <1> 	stc
  5226 000096CC EB92                <1>         jmp     short set_env_string_allocate_envb_retn
  5227                              <1> 
  5228                              <1> set_env_add_variable_chk2:
  5229 000096CE 8B0C24              <1> 	mov	ecx, [esp] ; *****
  5230 000096D1 4E                  <1> 	dec	esi ; beginning address of the new variable
  5231 000096D2 89F0                <1> 	mov	eax, esi
  5232 000096D4 01C8                <1> 	add	eax, ecx ; string length (with CR)
  5233 000096D6 81C200020000        <1> 	add	edx, Env_Page_Size ; 512 (4096)
  5234 000096DC 39D0                <1> 	cmp	eax, edx 
  5235 000096DE 77E5                <1> 	ja	short set_env_add_variable_nspc
  5236 000096E0 49                  <1> 	dec	ecx ; except CR at the end
  5237 000096E1 89CA                <1> 	mov	edx, ecx ; 12/04/2016
  5238 000096E3 89F7                <1> 	mov	edi, esi
  5239 000096E5 893C24              <1> 	mov	[esp], edi ; ***** ; Start address of new variable
  5240 000096E8 89DE                <1> 	mov	esi, ebx ; ASCIIZ environment string address
  5241 000096EA F3A4                <1> 	rep	movsb
  5242 000096EC 28C0                <1> 	sub	al, al
  5243 000096EE AA                  <1> 	stosb
  5244 000096EF 58                  <1> 	pop	eax ; ***** ; Beginning address of new variable			
  5245 000096F0 81FF00320900        <1>         cmp     edi, Env_Page + Env_Page_Size ; 12/04/2016
  5246 000096F6 0F8364FFFFFF        <1>         jnb     set_env_string_allocate_envb_retn ; OK !
  5247 000096FC 880F                <1> 	mov	[edi], cl ; 0
  5248 000096FE F8                  <1> 	clc	; 13/04/2016
  5249 000096FF E95CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5250                              <1> 
  5251                              <1> set_env_change_variable:
  5252                              <1> 	; 06/04/2016
  5253                              <1> 	; esi = Variable's address in environment page (after '=')
  5254                              <1> 	; edi = ASCIIZ environment string address (after '=')
  5255                              <1> 
  5256                              <1> 	; ah = variable length from start to the '='
  5257 00009704 8825[D0640100]      <1> 	mov	[env_var_length], ah
  5258                              <1> 
  5259 0000970A 28C9                <1> 	sub	cl, cl ; ecx = 0
  5260                              <1> 
  5261 0000970C 57                  <1> 	push	edi ; *****
  5262                              <1> 
  5263 0000970D 89F7                <1> 	mov	edi, esi ; 11/04/2016
  5264                              <1> 
  5265                              <1> set_env_change_variable_calc1:
  5266 0000970F AC                  <1> 	lodsb
  5267 00009710 08C0                <1> 	or	al, al
  5268 00009712 7403                <1> 	jz	short set_env_change_variable_calc2
  5269                              <1> 
  5270 00009714 41                  <1> 	inc	ecx ; length of environment string (after the '=')
  5271                              <1> 
  5272 00009715 EBF8                <1> 	jmp	short set_env_change_variable_calc1	
  5273                              <1> 
  5274                              <1> set_env_change_variable_calc2:
  5275 00009717 8B3424              <1> 	mov	esi, [esp] ; ASCIIZ environment string address
  5276                              <1> 	
  5277 0000971A 29D2                <1> 	sub	edx, edx
  5278                              <1> 
  5279                              <1> set_env_change_variable_calc3:
  5280 0000971C AC                  <1> 	lodsb
  5281 0000971D 3C20                <1> 	cmp	al, 20h
  5282 0000971F 7203                <1> 	jb	short set_env_change_variable_calc4
  5283                              <1> 
  5284 00009721 42                  <1> 	inc	edx ; length of ASCIIZ string (after the '=')
  5285                              <1> 	
  5286 00009722 EBF8                <1> 	jmp	short set_env_change_variable_calc3
  5287                              <1> 	
  5288                              <1> set_env_change_variable_calc4:
  5289 00009724 C646FF00            <1> 	mov	byte [esi-1], 0  ; put ZERO instead of CR
  5290                              <1> 	
  5291 00009728 5E                  <1> 	pop	esi ; ***** ; ASCIIZ string address (after '=')
  5292                              <1> 
  5293                              <1> 	; EDI = Old variable's address (after '=')
  5294                              <1> 	
  5295                              <1> 	; compare the new string with the old string
  5296 00009729 39CA                <1> 	cmp	edx, ecx
  5297 0000972B 7717                <1> 	ja	short set_env_change_variable_calc5 ; longer
  5298 0000972D 0F828F000000        <1>         jb      set_env_change_variable_calc9 ; shorter
  5299                              <1> 	
  5300                              <1> 	;same length (simple copy)
  5301 00009733 0FB6C4              <1> 	movzx	eax, ah
  5302 00009736 01C2                <1> 	add	edx, eax
  5303 00009738 F7D8                <1> 	neg	eax
  5304 0000973A 01F8                <1> 	add	eax, edi
  5305                              <1> 	; EAX = Start address of the variable
  5306                              <1> 	; EDX = Variable length (without ZERO at the end of variable)
  5307                              <1> 
  5308 0000973C F3A4                <1> 	rep	movsb
  5309 0000973E F8                  <1> 	clc	; 13/04/2016
  5310 0000973F E91CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5311                              <1> 
  5312                              <1> set_env_change_variable_calc5:
  5313                              <1> 	; 11/04/2016
  5314 00009744 52                  <1> 	push	edx ; *****
  5315 00009745 29CA                <1> 	sub	edx, ecx ; difference ; (the new string is longer)
  5316 00009747 89F3                <1> 	mov 	ebx, esi
  5317 00009749 89FE                <1> 	mov	esi, edi
  5318                              <1> 
  5319                              <1> set_env_change_variable_calc6:
  5320 0000974B AC                  <1> 	lodsb 
  5321 0000974C 20C0                <1> 	and	al, al
  5322 0000974E 75FB                <1> 	jnz	short set_env_change_variable_calc6
  5323                              <1> 
  5324 00009750 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  5325 00009756 0F8369FFFFFF        <1>         jnb     set_env_add_variable_nspc
  5326                              <1> 
  5327 0000975C 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  5328 0000975E 89F7                <1> 	mov	edi, esi  ; next variable's address 
  5329                              <1> 
  5330 00009760 AC                  <1> 	lodsb
  5331 00009761 08C0                <1> 	or	al, al
  5332 00009763 7416                <1> 	jz	short set_env_change_variable_calc8 ; 00
  5333                              <1> 
  5334                              <1> set_env_change_variable_calc7:
  5335 00009765 AC                  <1> 	lodsb
  5336 00009766 20C0                <1> 	and	al, al
  5337 00009768 75FB                <1> 	jnz	short set_env_change_variable_calc7
  5338                              <1> 
  5339 0000976A 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  5340 00009770 0F834FFFFFFF        <1>         jnb     set_env_add_variable_nspc
  5341                              <1> 
  5342 00009776 AC                  <1> 	lodsb
  5343 00009777 08C0                <1> 	or	al, al
  5344 00009779 75EA                <1> 	jnz	short set_env_change_variable_calc7
  5345                              <1> 
  5346                              <1> set_env_change_variable_calc8:
  5347 0000977B 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  5348                              <1> 
  5349 0000977C 01F2                <1> 	add	edx, esi ; final position of the last 0
  5350                              <1> 
  5351 0000977E 81FA00320900        <1> 	cmp	edx, Env_Page + Env_Page_Size ; 512 (4096)
  5352 00009784 0F833BFFFFFF        <1>         jnb     set_env_add_variable_nspc
  5353                              <1> 
  5354 0000978A 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  5355                              <1> 
  5356 0000978C 89F1                <1> 	mov	ecx, esi 
  5357 0000978E 29F9                <1> 	sub	ecx, edi ; count of bytes to move forward
  5358                              <1> 
  5359                              <1> 	; 13/04/2016
  5360 00009790 C60200              <1> 	mov	byte [edx], 0
  5361 00009793 89D7                <1> 	mov	edi, edx
  5362 00009795 29F2                <1> 	sub	edx, esi ; difference (additional byte count)
  5363 00009797 4F                  <1> 	dec	edi ; the last zero address (first byte of the 00)
  5364 00009798 89FE                <1> 	mov	esi, edi
  5365 0000979A 29D6                <1> 	sub	esi, edx ; - displacement
  5366                              <1> 	
  5367 0000979C FA                  <1> 	cli	; disable interrupts
  5368 0000979D FD                  <1> 	std	; backward
  5369                              <1> 
  5370 0000979E F3A4                <1> 	rep	movsb ; move ECX bytes from DS:ESI to ES:EDI
  5371                              <1> 
  5372 000097A0 FC                  <1> 	cld	; forward (default)
  5373 000097A1 FB                  <1> 	sti	; enable interrupts
  5374                              <1> 	
  5375 000097A2 89C7                <1> 	mov	edi, eax
  5376 000097A4 59                  <1> 	pop	ecx ; ***** ; byte count (after '=')
  5377 000097A5 89CA                <1> 	mov	edx, ecx
  5378 000097A7 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  5379 000097A9 89FB                <1> 	mov	ebx, edi
  5380                              <1> 
  5381 000097AB F3A4                <1> 	rep	movsb
  5382                              <1> 
  5383 000097AD 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  5384                              <1> 
  5385 000097AF 0FB605[D0640100]    <1> 	movzx	eax, byte [env_var_length]
  5386 000097B6 01C2                <1> 	add	edx, eax ; variable length (total)
  5387 000097B8 F7D8                <1> 	neg	eax
  5388 000097BA 01D8                <1> 	add	eax, ebx ; start address of the variable
  5389 000097BC F8                  <1> 	clc	; 13/04/2016
  5390 000097BD E99EFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5391                              <1> 
  5392                              <1> set_env_change_variable_calc9:
  5393                              <1> 	; 11/04/2016
  5394 000097C2 21D2                <1> 	and	edx, edx ; is empty ?
  5395 000097C4 753B                <1> 	jnz	short set_env_change_variable_calc15
  5396                              <1> 	
  5397 000097C6 0FB6DC              <1> 	movzx	ebx, ah
  5398 000097C9 F7DB                <1> 	neg	ebx
  5399 000097CB 01FB                <1> 	add	ebx, edi
  5400                              <1> 
  5401                              <1> 	; EBX = Start address of the variable (in env page)
  5402                              <1> 	; EDX = Variable length = 0
  5403                              <1> 	
  5404 000097CD 89FE                <1> 	mov	esi, edi
  5405                              <1> 
  5406                              <1> set_env_change_variable_calc10:
  5407 000097CF AC                  <1> 	lodsb
  5408 000097D0 08C0                <1> 	or	al, al
  5409 000097D2 75FB                <1> 	jnz	short set_env_change_variable_calc10
  5410                              <1> 
  5411 000097D4 B9FF310900          <1> 	mov	ecx, Env_Page + Env_Page_Size - 1
  5412                              <1> 
  5413 000097D9 39CE                <1> 	cmp	esi, ecx ; +511 (+4095)
  5414 000097DB 7604                <1> 	jna	short set_env_change_variable_calc11
  5415                              <1> 
  5416 000097DD 89CE                <1> 	mov	esi, ecx
  5417 000097DF 8806                <1> 	mov	[esi], al ; 0
  5418                              <1> 
  5419                              <1> set_env_change_variable_calc11:
  5420 000097E1 89DF                <1> 	mov	edi, ebx ; old variable's start address
  5421                              <1> 
  5422                              <1> set_env_change_variable_calc12:
  5423 000097E3 AC                  <1> 	lodsb
  5424 000097E4 AA                  <1> 	stosb
  5425 000097E5 20C0                <1> 	and	al, al
  5426 000097E7 75FA                <1> 	jnz	short set_env_change_variable_calc12
  5427 000097E9 39CE                <1> 	cmp	esi, ecx
  5428 000097EB 7706                <1> 	ja	short set_env_change_variable_calc13
  5429 000097ED AC                  <1> 	lodsb
  5430 000097EE AA                  <1> 	stosb
  5431 000097EF 20C0                <1> 	and	al, al
  5432 000097F1 75F0                <1> 	jnz	short set_env_change_variable_calc12	
  5433                              <1> 
  5434                              <1> set_env_change_variable_calc13:
  5435 000097F3 29F9                <1> 	sub	ecx, edi
  5436 000097F5 7203                <1> 	jb	short set_env_change_variable_calc14
  5437 000097F7 41                  <1> 	inc	ecx ; 1-512 (1-4096)
  5438 000097F8 F3AA                <1> 	rep	stosb ; al = 0	
  5439                              <1> 
  5440                              <1> set_env_change_variable_calc14:
  5441 000097FA 29C0                <1> 	sub	eax, eax ; Start address of the variable
  5442                              <1> 	; EAX = 0 -> Variable is removed
  5443                              <1> 	; EDX = Variable length = 0	
  5444                              <1> 
  5445 000097FC E95FFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5446                              <1> 	    
  5447                              <1> set_env_change_variable_calc15:	
  5448 00009801 52                  <1> 	push	edx ; *****
  5449 00009802 F7DA                <1> 	neg	edx
  5450 00009804 01CA                <1> 	add	edx, ecx ; difference (the old string is longer)
  5451 00009806 89F3                <1> 	mov 	ebx, esi
  5452 00009808 89FE                <1> 	mov	esi, edi
  5453                              <1> 
  5454                              <1> set_env_change_variable_calc16:
  5455 0000980A AC                  <1> 	lodsb 
  5456 0000980B 20C0                <1> 	and	al, al
  5457 0000980D 75FB                <1> 	jnz	short set_env_change_variable_calc16
  5458                              <1> 
  5459 0000980F B900320900          <1> 	mov	ecx, Env_Page + Env_Page_Size
  5460                              <1> 
  5461 00009814 39CE                <1> 	cmp	esi, ecx ; +512 (+4096)
  5462 00009816 7605                <1> 	jna	short set_env_change_variable_calc17
  5463                              <1> 
  5464 00009818 89CE                <1> 	mov	esi, ecx
  5465 0000981A 8846FF              <1> 	mov	[esi-1], al ; 0
  5466                              <1> 
  5467                              <1> set_env_change_variable_calc17:
  5468 0000981D 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  5469 0000981F 89F7                <1> 	mov	edi, esi  ; next variable's address 
  5470                              <1> 
  5471 00009821 AC                  <1> 	lodsb
  5472 00009822 08C0                <1> 	or	al, al
  5473 00009824 741D                <1> 	jz	short set_env_change_variable_calc20
  5474                              <1> 
  5475                              <1> set_env_change_variable_calc18:
  5476 00009826 AC                  <1> 	lodsb
  5477 00009827 20C0                <1> 	and	al, al
  5478 00009829 75FB                <1> 	jnz	short set_env_change_variable_calc18
  5479                              <1> 
  5480 0000982B 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size
  5481 00009831 720B                <1> 	jb	short set_env_change_variable_calc19
  5482 00009833 740E                <1> 	je	short set_env_change_variable_calc20
  5483                              <1> 
  5484 00009835 BEFF310900          <1> 	mov	esi, Env_Page + Env_Page_Size - 1
  5485 0000983A 8806                <1> 	mov	[esi], al ; 0
  5486 0000983C EB06                <1> 	jmp	short set_env_change_variable_calc21
  5487                              <1> 
  5488                              <1> set_env_change_variable_calc19:
  5489 0000983E AC                  <1> 	lodsb
  5490 0000983F 08C0                <1> 	or	al, al
  5491 00009841 75E3                <1> 	jnz	short set_env_change_variable_calc18
  5492                              <1> 
  5493                              <1> set_env_change_variable_calc20:
  5494 00009843 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  5495                              <1> 
  5496                              <1> set_env_change_variable_calc21:
  5497                              <1> 	; edx = difference (byte count)
  5498                              <1> 	
  5499 00009844 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  5500                              <1> 
  5501 00009846 89F1                <1> 	mov	ecx, esi 
  5502 00009848 29F9                <1> 	sub	ecx, edi ; count of bytes to move backward
  5503                              <1> 
  5504 0000984A 89FE                <1> 	mov	esi, edi ; next variable's address
  5505 0000984C 29D7                <1> 	sub	edi, edx ; (displacement)
  5506                              <1> 	
  5507 0000984E F3A4                <1> 	rep	movsb
  5508                              <1> 
  5509 00009850 880F                <1> 	mov	[edi], cl ; 0 ; 00 ; end of environment variables
  5510                              <1> 
  5511 00009852 89C7                <1> 	mov	edi, eax
  5512 00009854 5A                  <1> 	pop	edx ; ***** ; byte count (after '=')
  5513 00009855 89D1                <1> 	mov	ecx, edx
  5514 00009857 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  5515 00009859 89FB                <1> 	mov	ebx, edi
  5516                              <1> 	
  5517 0000985B F3A4                <1> 	rep	movsb
  5518                              <1> 
  5519 0000985D 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  5520                              <1> 
  5521 0000985F 0FB605[D0640100]    <1> 	movzx	eax, byte [env_var_length]
  5522 00009866 01C2                <1> 	add	edx, eax ; variable length (total)
  5523 00009868 F7D8                <1> 	neg	eax
  5524 0000986A 01D8                <1> 	add	eax, ebx ; start address of the variable
  5525 0000986C F8                  <1> 	clc	; 13/04/2016
  5526 0000986D E9EEFDFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  5527                              <1> 
  5528                              <1> mainprog_startup_configuration:
  5529                              <1> 	; 22/11/2017
  5530                              <1> 	; 06/05/2016
  5531                              <1> 	; 14/04/2016 (TRDOS 386 = TRDOS v2.0)
  5532                              <1> 	; 17/09/2011 (TRDOS v1, MAINPROG.ASM)
  5533                              <1> 	;
  5534                              <1> loc_load_mainprog_cfg_file:
  5535 00009872 BE[810D0100]        <1> 	mov	esi, MainProgCfgFile
  5536 00009877 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  5537 0000987B E83EEAFFFF          <1> 	call	find_first_file
  5538 00009880 7256                <1> 	jc	short loc_load_mainprog_cfg_exit
  5539                              <1> 
  5540                              <1> 	;or	eax, eax
  5541                              <1> 	;jz	short loc_load_mainprog_cfg_exit
  5542                              <1> 
  5543                              <1> loc_start_mainprog_configuration:
  5544                              <1> 	; ESI = FindFile_DirEntry Location
  5545                              <1> 	; EAX = File Size
  5546                              <1> 
  5547 00009882 A3[5C590100]        <1> 	mov	[MainProgCfg_FileSize], eax
  5548                              <1> 
  5549 00009887 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  5550 0000988B C1E210              <1> 	shl	edx, 16
  5551 0000988E 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  5552 00009892 8915[84640100]      <1> 	mov	[csftdf_sf_cluster], edx
  5553                              <1> 
  5554 00009898 89C1                <1> 	mov	ecx, eax
  5555 0000989A 29C0                <1> 	sub	eax, eax
  5556                              <1> 
  5557                              <1> 	; TRDOS 386 (TRDOS v2.0)
  5558                              <1> 	; Allocate contiguous memory block for loading the file
  5559                              <1> 	
  5560                              <1> 	; eax = 0 (Allocate memory from the beginning)
  5561                              <1> 	; ecx = File (Allocation) size in bytes
  5562                              <1> 	
  5563 0000989C E8B5BBFFFF          <1> 	call	allocate_memory_block
  5564 000098A1 7235                <1> 	jc	short loc_load_mainprog_cfg_exit
  5565                              <1> 
  5566 000098A3 A3[7C640100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  5567 000098A8 890D[80640100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  5568                              <1> 
  5569 000098AE 31DB                <1> 	xor	ebx, ebx
  5570                              <1> 	;mov	[csftdf_sf_rbytes], ebx ; 0, reset
  5571                              <1> 
  5572 000098B0 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv] ; [FindFile_Drv]
  5573 000098B6 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  5574 000098BB 01DE                <1> 	add	esi, ebx
  5575                              <1> 
  5576 000098BD 8B1D[7C640100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  5577                              <1> 
  5578 000098C3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5579 000098C7 7710                <1>         ja	short loc_mcfg_load_fat_file
  5580                              <1> 
  5581 000098C9 C705[8C640100]0000- <1> 	mov	dword [csftdf_r_size], 65536
  5581 000098D1 0100                <1>
  5582 000098D3 E9A1010000          <1>         jmp     loc_mcfg_load_fs_file
  5583                              <1> 
  5584                              <1> loc_load_mainprog_cfg_exit:
  5585 000098D8 C3                  <1> 	retn 
  5586                              <1> 
  5587                              <1> loc_mcfg_load_fat_file:
  5588 000098D9 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
  5589 000098DD 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  5590 000098E1 F7E1                <1> 	mul	ecx
  5591 000098E3 A3[8C640100]        <1> 	mov	[csftdf_r_size], eax
  5592                              <1> 
  5593                              <1> loc_mcfg_load_fat_file_next:
  5594 000098E8 E822010000          <1> 	call	mcfg_read_fat_file_sectors
  5595 000098ED 0F8206010000        <1>         jc      mcfg_deallocate_mem
  5596                              <1> 
  5597 000098F3 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  5598 000098F5 74F1                <1> 	jz	short loc_mcfg_load_fat_file_next
  5599                              <1> 
  5600                              <1> loc_mcfg_load_fat_file_ok:
  5601                              <1> 	; 06/05/2016
  5602 000098F7 C705[20650100]-     <1> 	mov	dword [mainprog_return_addr], loc_mcfg_ci_return_addr 
  5602 000098FD [BA990000]          <1>
  5603                              <1> 	;
  5604 00009901 8B35[7C640100]      <1> 	mov	esi, [csftdf_sf_mem_addr]
  5605 00009907 8935[60590100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  5606                              <1> 	
  5607 0000990D A1[5C590100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  5608 00009912 89C2                <1> 	mov	edx, eax
  5609 00009914 01F2                <1> 	add	edx, esi
  5610                              <1> 
  5611                              <1> loc_mcfg_process_next_line_check:
  5612 00009916 89C1                <1> 	mov	ecx, eax
  5613                              <1> 
  5614 00009918 803E2A              <1> 	cmp	byte [esi], "*" ; Remark sign
  5615 0000991B 7503                <1> 	jne	short loc_mcfg_process_next_line
  5616 0000991D 46                  <1> 	inc	esi
  5617 0000991E EB17                <1> 	jmp	short loc_move_mainprog_cfg_nl1
  5618                              <1> 
  5619                              <1> loc_mcfg_process_next_line:
  5620 00009920 83F94F              <1> 	cmp	ecx, 79
  5621 00009923 7605                <1> 	jna	short loc_start_mainprog_cfg_process
  5622                              <1> 	
  5623 00009925 B94F000000          <1> 	mov	ecx, 79 
  5624                              <1> 
  5625                              <1> loc_start_mainprog_cfg_process:
  5626 0000992A BF[1E5A0100]        <1> 	mov	edi, CommandBuffer
  5627                              <1> 
  5628                              <1> loc_move_mainprog_cfg_line:
  5629 0000992F AC                  <1> 	lodsb
  5630 00009930 3C20                <1> 	cmp	al, 20h
  5631 00009932 720C                <1> 	jb	short loc_move_mainprog_cfg_nl2
  5632 00009934 AA                  <1> 	stosb
  5633 00009935 E2F8                <1> 	loop	loc_move_mainprog_cfg_line
  5634                              <1> 
  5635                              <1> loc_move_mainprog_cfg_nl1:
  5636 00009937 39D6                <1> 	cmp	esi, edx ; + configuration file size
  5637 00009939 7312                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  5638 0000993B AC                  <1> 	lodsb
  5639 0000993C 3C20                <1> 	cmp	al, 20h
  5640 0000993E 73F7                <1> 	jnb	short loc_move_mainprog_cfg_nl1
  5641                              <1> 
  5642                              <1> loc_move_mainprog_cfg_nl2:
  5643 00009940 39D6                <1> 	cmp	esi, edx
  5644 00009942 7309                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  5645 00009944 8A06                <1> 	mov	al, [esi]
  5646 00009946 3C20                <1> 	cmp	al, 20h
  5647 00009948 7703                <1>  	ja	short loc_end_of_mainprog_cfg_line
  5648 0000994A 46                  <1> 	inc	esi
  5649 0000994B EBF3                <1> 	jmp	short loc_move_mainprog_cfg_nl2	               
  5650                              <1> 
  5651                              <1> loc_end_of_mainprog_cfg_line:
  5652 0000994D C60700              <1> 	mov	byte [edi], 0
  5653                              <1> 
  5654 00009950 8935[60590100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  5655                              <1> 
  5656                              <1> 	; 22/11/2017
  5657 00009956 BE[265A0100]        <1> 	mov	esi, CommandBuffer + 8
  5658 0000995B 29FE                <1> 	sub	esi, edi
  5659 0000995D 7606                <1> 	jna	short loc_move_mainprog_cfg_command
  5660 0000995F 30C0                <1> 	xor	al, al
  5661                              <1> loc_mainprog_cfg_clear_chrs:
  5662 00009961 AA                  <1> 	stosb
  5663 00009962 4E                  <1> 	dec	esi
  5664 00009963 75FC                <1> 	jnz	short loc_mainprog_cfg_clear_chrs	
  5665                              <1> 
  5666                              <1> loc_move_mainprog_cfg_command:
  5667 00009965 BE[1E5A0100]        <1> 	mov	esi, CommandBuffer
  5668 0000996A 89F7                <1> 	mov	edi, esi
  5669 0000996C 31DB                <1> 	xor	ebx, ebx
  5670                              <1> 	;xor	ecx, ecx
  5671 0000996E 30C9                <1> 	xor	cl, cl
  5672                              <1> 
  5673                              <1> loc_move_mcfg_first_cmd_char:
  5674 00009970 8A041E              <1> 	mov	al, [esi+ebx]
  5675 00009973 FEC3                <1> 	inc	bl 
  5676 00009975 3C20                <1> 	cmp	al, 20h
  5677 00009977 7712                <1> 	ja	short loc_move_mcfg_cmd_capitalizing
  5678 00009979 7237                <1> 	jb	short loc_move_mcfg_cmd_arguments_ok
  5679 0000997B 80FB4F              <1> 	cmp	bl, 79
  5680 0000997E 72F0                <1> 	jb	short loc_move_mcfg_first_cmd_char
  5681 00009980 EB30                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  5682                              <1> 
  5683                              <1> loc_move_mcfg_next_cmd_char:
  5684 00009982 8A041E              <1> 	mov	al, [esi+ebx]
  5685 00009985 FEC3                <1> 	inc	bl
  5686 00009987 3C20                <1> 	cmp	al, 20h
  5687 00009989 7614                <1> 	jna	short loc_move_mcfg_cmd_ok
  5688                              <1> 
  5689                              <1> loc_move_mcfg_cmd_capitalizing:
  5690 0000998B 3C61                <1> 	cmp	al, 61h ; 'a'
  5691 0000998D 7206                <1> 	jb	short loc_move_mcfg_cmd_caps_ok
  5692 0000998F 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  5693 00009991 7702                <1> 	ja	short loc_move_mcfg_cmd_caps_ok
  5694 00009993 24DF                <1> 	and	al, 0DFh ; sub	al, 'a'-'A'
  5695                              <1> 
  5696                              <1> loc_move_mcfg_cmd_caps_ok:
  5697 00009995 AA                  <1> 	stosb 
  5698 00009996 FEC1                <1> 	inc	cl
  5699 00009998 80FB4F              <1> 	cmp	bl, 79
  5700 0000999B 72E5                <1> 	jb	short loc_move_mcfg_next_cmd_char
  5701 0000999D EB13                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  5702                              <1> 
  5703                              <1> loc_move_mcfg_cmd_ok:
  5704 0000999F 30C0                <1> 	xor	al, al ; 0
  5705                              <1> 
  5706                              <1> loc_move_mcfg_cmd_arguments:
  5707 000099A1 8807                <1> 	mov	[edi], al
  5708 000099A3 47                  <1> 	inc	edi
  5709 000099A4 80FB4F              <1> 	cmp	bl, 79
  5710 000099A7 7309                <1> 	jnb	short loc_move_mcfg_cmd_arguments_ok
  5711 000099A9 8A041E              <1> 	mov	al, [esi+ebx]
  5712 000099AC FEC3                <1> 	inc	bl
  5713 000099AE 3C20                <1> 	cmp	al, 20h
  5714 000099B0 73EF                <1> 	jnb	short loc_move_mcfg_cmd_arguments
  5715                              <1> 	
  5716                              <1> loc_move_mcfg_cmd_arguments_ok:
  5717 000099B2 C60700              <1> 	mov	byte [edi], 0
  5718                              <1>        
  5719                              <1> loc_mcfg_process_cmd_interpreter:
  5720 000099B5 E825E0FFFF          <1> 	call    command_interpreter
  5721                              <1> 
  5722                              <1> loc_mcfg_ci_return_addr: 
  5723 000099BA A1[5C590100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  5724 000099BF 89C2                <1> 	mov	edx, eax
  5725 000099C1 8B35[60590100]      <1> 	mov	esi, [MainProgCfg_LineOffset]
  5726 000099C7 01F2                <1> 	add	edx, esi
  5727 000099C9 0305[7C640100]      <1> 	add	eax, [csftdf_sf_mem_addr]
  5728 000099CF 29F0                <1> 	sub	eax, esi
  5729 000099D1 0F873FFFFFFF        <1>         ja      loc_mcfg_process_next_line_check
  5730                              <1> 
  5731 000099D7 E81D000000          <1> 	call	mcfg_deallocate_mem
  5732                              <1>  
  5733 000099DC B94F000000          <1>  	mov	ecx, 79 ; 80 ?
  5734 000099E1 BF[1E5A0100]        <1> 	mov	edi, CommandBuffer
  5735 000099E6 30C0                <1> 	xor	al, al
  5736 000099E8 F3AA                <1> 	rep	stosb
  5737                              <1> 
  5738                              <1> 	; 06/05/2016
  5739 000099EA BE[D7190100]        <1> 	mov	esi, nextline
  5740 000099EF E8A9C9FFFF          <1> 	call	print_msg
  5741 000099F4 E963D6FFFF          <1> 	jmp	dos_prompt
  5742                              <1> 
  5743                              <1> mcfg_deallocate_mem:
  5744 000099F9 A1[7C640100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  5745 000099FE 8B0D[80640100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
  5746                              <1> 	;call	deallocate_memory_block
  5747                              <1> 	;retn
  5748 00009A04 E95ABCFFFF          <1> 	jmp	deallocate_memory_block
  5749                              <1> 
  5750                              <1> mcfg_read_file_sectors:
  5751                              <1> 	; 14/04/2016
  5752 00009A09 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5753 00009A0D 7669                <1>         jna	short mcfg_read_fs_file_sectors
  5754                              <1> 
  5755                              <1> mcfg_read_fat_file_sectors:
  5756                              <1> 	; return:
  5757                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  5758                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  5759                              <1> 	;   CF = 1 -> read error (error code in AL)	
  5760                              <1> 
  5761                              <1> mcfg_read_fat_file_secs_0:
  5762 00009A0F 8B15[5C590100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  5763 00009A15 2B15[94640100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  5764 00009A1B 3B15[8C640100]      <1> 	cmp	edx, [csftdf_r_size]	
  5765 00009A21 7306                <1> 	jnb	short mcfg_read_fat_file_secs_1
  5766 00009A23 8915[8C640100]      <1> 	mov	[csftdf_r_size], edx
  5767                              <1> 		
  5768                              <1> mcfg_read_fat_file_secs_1:
  5769 00009A29 A1[8C640100]        <1> 	mov	eax, [csftdf_r_size]
  5770 00009A2E 29D2                <1> 	sub	edx, edx
  5771 00009A30 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  5772 00009A34 01C8                <1> 	add	eax, ecx
  5773 00009A36 48                  <1> 	dec	eax
  5774 00009A37 F7F1                <1> 	div	ecx
  5775 00009A39 89C1                <1> 	mov	ecx, eax ; sector count
  5776 00009A3B A1[84640100]        <1> 	mov	eax, [csftdf_sf_cluster]
  5777                              <1> 
  5778                              <1> 	; EBX = memory block address (current)
  5779                              <1> 	
  5780 00009A40 E88C230000          <1> 	call	read_fat_file_sectors
  5781 00009A45 7230                <1> 	jc	short mcfg_read_fat_file_secs_3
  5782                              <1> 
  5783                              <1> 	; EBX = next memory address
  5784                              <1> 
  5785 00009A47 A1[94640100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  5786 00009A4C 0305[8C640100]      <1> 	add	eax, [csftdf_r_size]
  5787 00009A52 8B15[5C590100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  5788 00009A58 39D0                <1> 	cmp	eax, edx
  5789 00009A5A 731B                <1> 	jnb	short mcfg_read_fat_file_secs_3 ; edx > 0
  5790 00009A5C A3[94640100]        <1> 	mov	[csftdf_sf_rbytes], eax
  5791                              <1> 
  5792 00009A61 53                  <1> 	push	ebx ; *
  5793                              <1> 	; get next cluster (csftdf_r_size! bytes)
  5794 00009A62 A1[84640100]        <1> 	mov	eax, [csftdf_sf_cluster]
  5795 00009A67 E837210000          <1> 	call	get_next_cluster
  5796 00009A6C 5B                  <1> 	pop	ebx ; *
  5797 00009A6D 7301                <1> 	jnc	short mcfg_read_fat_file_secs_2
  5798                              <1> 
  5799                              <1> 	;mov	eax, 17; Read error !
  5800 00009A6F C3                  <1> 	retn
  5801                              <1> 
  5802                              <1> mcfg_read_fat_file_secs_2:
  5803 00009A70 29D2                <1> 	sub	edx, edx ; 0
  5804 00009A72 A3[84640100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  5805                              <1> 
  5806                              <1> mcfg_read_fat_file_secs_3:
  5807 00009A77 C3                  <1> 	retn
  5808                              <1> 
  5809                              <1> mcfg_read_fs_file_sectors:
  5810 00009A78 C3                  <1> 	retn
  5811                              <1> 
  5812                              <1> loc_mcfg_load_fs_file:
  5813 00009A79 C3                  <1> 	retn
  5814                              <1> 
  5815                              <1> load_and_execute_file:
  5816                              <1> 	; 04/01/2017
  5817                              <1> 	; 06/05/2016, 07/05/2016, 11/05/2016
  5818                              <1> 	; 23/04/2016, 24/04/2016
  5819                              <1> 	; 22/04/2016 (TRDOS 386 = TRDOS v2.0)
  5820                              <1> 	; 05/11/2011 
  5821                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'cmp_cmd_run', 'cmp_cmd_external')
  5822                              <1> 	; ('loc_run_check_filename')
  5823                              <1> 	; 29/08/2011
  5824                              <1> 	; 10/09/2011
  5825                              <1> 	; INPUT->
  5826                              <1> 	;	ESI = Path Name address (CommandBuffer address)
  5827                              <1> 	; OUTPUT ->
  5828                              <1> 	;	none (error message will be shown if an error will occur)
  5829                              <1> 	;
  5830                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI, EBP will be changed) 
  5831                              <1> 	;
  5832                              <1> loc_run_check_filename:
  5833 00009A7A 803E20              <1> 	cmp	byte [esi], 20h
  5834 00009A7D 0F822BE3FFFF        <1> 	jb	loc_cmd_failed
  5835 00009A83 7703                <1> 	ja	short loc_run_check_filename_ok
  5836 00009A85 46                  <1> 	inc	esi
  5837 00009A86 EBF2                <1> 	jmp	short loc_run_check_filename
  5838                              <1> 
  5839                              <1> loc_run_check_filename_ok:
  5840 00009A88 C605[CF590100]00    <1> 	mov	byte [CmdArgStart], 0 ; reset
  5841 00009A8F 56                  <1> 	push	esi ; *
  5842                              <1> loc_run_get_first_arg_pos:
  5843 00009A90 46                  <1> 	inc	esi
  5844 00009A91 8A06                <1> 	mov	al, [esi]
  5845 00009A93 3C20                <1> 	cmp	al, 20h
  5846 00009A95 77F9                <1> 	ja	short loc_run_get_first_arg_pos
  5847 00009A97 C60600              <1> 	mov	byte [esi], 0
  5848                              <1> loc_run_get_external_arg_pos:
  5849                              <1> 	; 11/05/2016
  5850 00009A9A 46                  <1> 	inc	esi
  5851 00009A9B 8A06                <1> 	mov	al, [esi]
  5852 00009A9D 3C20                <1> 	cmp	al, 20h
  5853 00009A9F 760C                <1> 	jna	short loc_run_parse_path_name
  5854 00009AA1 89F0                <1> 	mov	eax, esi
  5855 00009AA3 2D[1E5A0100]        <1> 	sub	eax, CommandBuffer
  5856 00009AA8 A2[CF590100]        <1> 	mov	byte [CmdArgStart], al
  5857                              <1> loc_run_parse_path_name:
  5858 00009AAD 5E                  <1> 	pop	esi ; *
  5859 00009AAE BF[06620100]        <1> 	mov	edi, FindFile_Drv
  5860 00009AB3 E8D7090000          <1> 	call	parse_path_name
  5861 00009AB8 0F82F0E2FFFF        <1> 	jc	loc_cmd_failed
  5862                              <1> 
  5863                              <1> loc_run_check_filename_exists:
  5864 00009ABE BE[48620100]        <1> 	mov	esi, FindFile_Name
  5865 00009AC3 803E20              <1> 	cmp	byte [esi], 20h
  5866 00009AC6 0F86E2E2FFFF        <1> 	jna	loc_cmd_failed
  5867                              <1> 
  5868                              <1> loc_run_check_exe_filename_ext:
  5869 00009ACC E890020000          <1> 	call	check_prg_filename_ext
  5870 00009AD1 0F82D7E2FFFF        <1> 	jc	loc_cmd_failed
  5871                              <1> 	
  5872                              <1> loc_run_check_exe_filename_ext_ok:
  5873 00009AD7 66A3[1E650100]      <1> 	mov	word [EXE_ID], ax
  5874                              <1> 
  5875                              <1> loc_run_drv:
  5876 00009ADD C605[1D650100]00    <1> 	mov	byte [Run_Manual_Path], 0
  5877 00009AE4 A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
  5878 00009AE9 A3[18650100]        <1>         mov     [Run_CDirFC], eax
  5879                              <1> 	;
  5880 00009AEE 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  5881 00009AF4 8835[C2600100]      <1> 	mov	[RUN_CDRV], dh
  5882                              <1> 
  5883 00009AFA 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  5884 00009B00 38F2                <1> 	cmp	dl, dh
  5885 00009B02 7412                <1> 	je	short loc_run_change_directory
  5886                              <1>                
  5887 00009B04 8005[1D650100]02    <1> 	add	byte [Run_Manual_Path], 2
  5888                              <1> 
  5889 00009B0B E80BD4FFFF          <1> 	call	change_current_drive
  5890 00009B10 0F82C3E2FFFF        <1> 	jc	loc_run_cmd_failed
  5891                              <1> 
  5892                              <1> loc_run_change_directory:
  5893 00009B16 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  5894 00009B1D 7623                <1> 	jna	short loc_run_find_executable_file
  5895                              <1> 
  5896 00009B1F FE05[1D650100]      <1> 	inc	byte [Run_Manual_Path]
  5897                              <1>      
  5898 00009B25 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  5899                              <1> 
  5900 00009B2B BE[07620100]        <1> 	mov	esi, FindFile_Directory
  5901 00009B30 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  5902 00009B32 E842030000          <1> 	call	change_current_directory
  5903 00009B37 0F829CE2FFFF        <1> 	jc	loc_run_cmd_failed
  5904                              <1> 
  5905                              <1> loc_run_change_prompt_dir_string:
  5906 00009B3D E857020000          <1> 	call	change_prompt_dir_string
  5907                              <1> 
  5908                              <1> loc_run_find_executable_file:
  5909 00009B42 66C705[1C650100]00- <1> 	mov	word [Run_Auto_Path], 0
  5909 00009B4A 00                  <1>
  5910                              <1> 
  5911                              <1> loc_run_find_executable_file_next:
  5912 00009B4B BE[48620100]        <1> 	mov	esi, FindFile_Name
  5913                              <1> loc_run_find_program_file_next:
  5914 00009B50 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  5915 00009B54 E865E7FFFF          <1> 	call	find_first_file
  5916                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  5917                              <1> 	; EDI = Directory Buffer Directory Entry Location
  5918                              <1> 	; EAX = File size
  5919 00009B59 0F835C010000        <1> 	jnc	loc_load_and_run_file
  5920                              <1> 	 
  5921 00009B5F 3C02                <1> 	cmp	al, 2 ; file not found
  5922 00009B61 0F8572E2FFFF        <1> 	jne	loc_run_cmd_failed
  5923                              <1> 
  5924 00009B67 66A1[1E650100]      <1> 	mov	ax, word [EXE_ID]
  5925 00009B6D 80FC2E              <1> 	cmp	ah, '.' ; File name has extension sign
  5926 00009B70 7424                <1> 	je	short loc_run_check_auto_path
  5927                              <1> 
  5928 00009B72 08C0                <1> 	or	al, al
  5929 00009B74 7520                <1> 	jnz	short loc_run_check_auto_path
  5930                              <1> 
  5931 00009B76 80FC08              <1> 	cmp	ah, 8 ; count of file name chars
  5932 00009B79 771B                <1> 	ja	short loc_run_check_auto_path
  5933                              <1> 
  5934                              <1> loc_run_change_file_ext_to_prg:
  5935 00009B7B 0FB6DC              <1> 	movzx	ebx, ah ; count of file name chars
  5936 00009B7E BE[48620100]        <1> 	mov	esi, FindFile_Name
  5937 00009B83 01F3                <1> 	add	ebx, esi	
  5938                              <1> 	; 07/05/2016
  5939 00009B85 C7032E505247        <1> 	mov	dword [ebx],  '.PRG'
  5940 00009B8B 66C705[1E650100]50- <1> 	mov	word [EXE_ID], 'P.'
  5940 00009B93 2E                  <1>
  5941 00009B94 EBBA                <1> 	jmp	short loc_run_find_program_file_next	
  5942                              <1> 
  5943                              <1> loc_run_check_auto_path:
  5944                              <1> 	; NOTE: /// 07/05/2016 ///
  5945                              <1> 	; If the path is given, value of byte [Run_Manual_Path]
  5946                              <1> 	; will not be ZERO. If so, file searching by using
  5947                              <1> 	; Automatic Path (via 'PATH' environment variable)
  5948                              <1> 	; will not be applicable, because the program file 
  5949                              <1> 	; is already/absolutely not found.
  5950                              <1> 
  5951 00009B96 A0[1D650100]        <1> 	mov	al, [Run_Manual_Path]
  5952 00009B9B 08C0                <1> 	or	al, al
  5953 00009B9D 0F850BE2FFFF        <1> 	jnz	loc_cmd_failed
  5954                              <1> 
  5955                              <1> loc_run_check_auto_path_again:
  5956 00009BA3 66833D[1C650100]FF  <1> 	cmp	word [Run_Auto_Path], 0FFFFh		 
  5957                              <1> 		; 0FFFFh = Not a valid run path (in ENV block) 
  5958 00009BAB 0F83FDE1FFFF        <1> 	jnb	loc_cmd_failed
  5959                              <1> 	; xor	al, al 
  5960 00009BB1 BE[070E0100]        <1> 	mov	esi, Cmd_Path ; 'PATH'
  5961 00009BB6 BF[6E5A0100]        <1> 	mov	edi, TextBuffer
  5962 00009BBB E848F9FFFF          <1> 	call	get_environment_string
  5963 00009BC0 730E                <1> 	jnc	short loc_run_chk_filename_ext_again
  5964 00009BC2 66C705[1C650100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; invalid
  5964 00009BCA FF                  <1>
  5965 00009BCB E9DEE1FFFF          <1> 	jmp	loc_cmd_failed
  5966                              <1> 
  5967                              <1> loc_run_chk_filename_ext_again:
  5968 00009BD0 89C1                <1> 	mov	ecx, eax ; string length (with zero tail)
  5969 00009BD2 49                  <1> 	dec	ecx ; without zero tail
  5970 00009BD3 66A1[1E650100]      <1> 	mov	ax, [EXE_ID]
  5971 00009BD9 80FC2E              <1> 	cmp	ah, '.'
  5972 00009BDC 740E                <1> 	je	short loc_run_chk_auto_path_pos
  5973                              <1> 	 
  5974                              <1> loc_run_change_file_ext_to_noext_again:
  5975 00009BDE 0FB6DC              <1> 	movzx	ebx, ah
  5976 00009BE1 BE[48620100]        <1> 	mov	esi, FindFile_Name
  5977 00009BE6 01F3                <1> 	add 	ebx, esi
  5978 00009BE8 29C0                <1> 	sub	eax, eax
  5979 00009BEA 8903                <1> 	mov	[ebx], eax ; 0 ; erase extension (.PRG)
  5980                              <1> 
  5981                              <1> loc_run_chk_auto_path_pos:
  5982                              <1> 	;movzx	eax,  word [Run_Auto_Path]
  5983 00009BEC 66A1[1C650100]      <1> 	mov	ax, [Run_Auto_Path]
  5984 00009BF2 39C8                <1> 	cmp	eax, ecx ; ecx = string length (except zero tail)
  5985 00009BF4 0F83B4E1FFFF        <1> 	jnb	loc_cmd_failed
  5986                              <1> 	;or	eax, eax
  5987 00009BFA 6609C0              <1> 	or	ax, ax
  5988 00009BFD 7502                <1> 	jnz	short loc_run_auto_path_pos_move
  5989 00009BFF B005                <1> 	mov	al, 5
  5990                              <1> 
  5991                              <1> loc_run_auto_path_pos_move:
  5992 00009C01 89FE                <1> 	mov	esi, edi ; offset TextBuffer
  5993 00009C03 01C6                <1> 	add	esi, eax
  5994                              <1> 
  5995                              <1> loc_run_auto_path_pos_space_loop:
  5996 00009C05 AC                  <1> 	lodsb
  5997 00009C06 3C20                <1> 	cmp	al, 20h 
  5998 00009C08 74FB                <1> 	je	short loc_run_auto_path_pos_space_loop
  5999 00009C0A 0F829EE1FFFF        <1> 	jb	loc_cmd_failed 
  6000 00009C10 AA                  <1> 	stosb
  6001                              <1> loc_run_auto_path_pos_move_next: 
  6002 00009C11 AC                  <1> 	lodsb
  6003 00009C12 3C3B                <1> 	cmp	al, ';'
  6004 00009C14 7414                <1> 	je	short loc_run_auto_path_pos_move_last_byte
  6005 00009C16 3C20                <1> 	cmp	al, 20h
  6006 00009C18 74F7                <1> 	je	short loc_run_auto_path_pos_move_next
  6007 00009C1A 7203                <1> 	jb	short loc_byte_ptr_end_of_path
  6008 00009C1C AA                  <1> 	stosb
  6009 00009C1D EBF2                <1> 	jmp	short loc_run_auto_path_pos_move_next 
  6010                              <1> 
  6011                              <1> loc_byte_ptr_end_of_path: 
  6012 00009C1F 66C705[1C650100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; end of path
  6012 00009C27 FF                  <1>
  6013 00009C28 EB0D                <1> 	jmp	short loc_run_auto_path_move_ok 
  6014                              <1> 
  6015                              <1> loc_run_auto_path_pos_move_last_byte:
  6016 00009C2A 89F0                <1> 	mov	eax, esi
  6017 00009C2C 2D[6E5A0100]        <1> 	sub	eax, TextBuffer 
  6018 00009C31 66A3[1C650100]      <1> 	mov	[Run_Auto_Path], ax ; next path position
  6019                              <1> 
  6020                              <1> loc_run_auto_path_move_ok:
  6021 00009C37 4F                  <1> 	dec	edi
  6022 00009C38 B02F                <1> 	mov	al, '/'
  6023 00009C3A 3807                <1> 	cmp	[edi], al
  6024 00009C3C 7403                <1> 	je	short loc_run_auto_path_move_file_name
  6025 00009C3E 47                  <1> 	inc	edi
  6026 00009C3F 8807                <1> 	mov	[edi], al
  6027                              <1> 
  6028                              <1> loc_run_auto_path_move_file_name:
  6029 00009C41 47                  <1> 	inc	edi   
  6030 00009C42 BE[48620100]        <1> 	mov	esi, FindFile_Name
  6031                              <1> 
  6032                              <1> loc_run_auto_path_move_fn_loop:
  6033 00009C47 AC                  <1> 	lodsb
  6034 00009C48 AA                  <1> 	stosb
  6035 00009C49 08C0                <1> 	or	al, al
  6036 00009C4B 75FA                <1> 	jnz	short loc_run_auto_path_move_fn_loop
  6037                              <1> 
  6038 00009C4D BE[6E5A0100]        <1> 	mov	esi, TextBuffer
  6039 00009C52 BF[06620100]        <1> 	mov	edi, FindFile_Drv
  6040 00009C57 E833080000          <1> 	call	parse_path_name
  6041 00009C5C 0F824CE1FFFF        <1> 	jc	loc_cmd_failed
  6042                              <1> 
  6043 00009C62 8A35[6E590100]      <1> 	mov	dh, [Current_Drv]
  6044 00009C68 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  6045 00009C6E 38F2                <1> 	cmp	dl, dh
  6046 00009C70 740B                <1> 	je	short loc_run_change_directory_again
  6047                              <1>                
  6048 00009C72 E8A4D2FFFF          <1> 	call	change_current_drive
  6049 00009C77 0F825CE1FFFF        <1> 	jc	loc_run_cmd_failed
  6050                              <1> 
  6051                              <1> loc_run_change_directory_again:
  6052 00009C7D 803D[07620100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  6053 00009C84 761D                <1> 	jna	short loc_load_executable_cdir_chk_again
  6054                              <1> 
  6055 00009C86 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  6056 00009C8C BE[07620100]        <1> 	mov	esi, FindFile_Directory
  6057 00009C91 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  6058 00009C93 E8E1010000          <1> 	call	change_current_directory
  6059 00009C98 0F823BE1FFFF        <1> 	jc	loc_run_cmd_failed
  6060                              <1> 
  6061                              <1> loc_run_chg_prompt_dir_str_again:
  6062 00009C9E E8F6000000          <1> 	call	change_prompt_dir_string
  6063                              <1> 
  6064                              <1> loc_load_executable_cdir_chk_again:
  6065 00009CA3 A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
  6066 00009CA8 3B05[18650100]      <1> 	cmp	eax, [Run_CDirFC]
  6067 00009CAE 0F8597FEFFFF        <1> 	jne	loc_run_find_executable_file_next
  6068 00009CB4 30C0                <1> 	xor	al, al ; 0
  6069 00009CB6 E9E8FEFFFF          <1> 	jmp	loc_run_check_auto_path_again
  6070                              <1> 
  6071                              <1> loc_load_and_run_file:
  6072                              <1> 	; 13/11/2017
  6073                              <1> 	; 04/01/2017
  6074                              <1> 	; 23/04/2016
  6075 00009CBB BE[48620100]        <1> 	mov	esi, FindFile_Name
  6076 00009CC0 BF[6E5A0100]        <1> 	mov	edi, TextBuffer
  6077                              <1> 
  6078                              <1>  	; 24/04/2016
  6079 00009CC5 31D2                <1> 	xor	edx, edx
  6080 00009CC7 668915[4A040300]    <1> 	mov	word [argc], dx ; 0
  6081 00009CCE 8915[8C030300]      <1> 	mov	dword [u.nread], edx ; 0
  6082                              <1> 
  6083                              <1> loc_load_and_run_file_1:
  6084 00009CD4 AC                  <1> 	lodsb	
  6085 00009CD5 AA                  <1> 	stosb
  6086 00009CD6 FF05[8C030300]      <1> 	inc	dword [u.nread]
  6087 00009CDC 20C0                <1> 	and	al, al
  6088 00009CDE 75F4                <1> 	jnz 	short loc_load_and_run_file_1
  6089                              <1> 	
  6090 00009CE0 A0[CF590100]        <1> 	mov	al, [CmdArgStart]
  6091 00009CE5 20C0                <1> 	and	al, al
  6092 00009CE7 7445                <1> 	jz	short loc_load_and_run_file_7
  6093                              <1> 
  6094 00009CE9 0FB6F0              <1> 	movzx	esi, al ; 11/05/2016
  6095 00009CEC B950000000          <1> 	mov	ecx, 80
  6096 00009CF1 29F1                <1> 	sub	ecx, esi
  6097 00009CF3 81C6[1E5A0100]      <1> 	add	esi, CommandBuffer
  6098                              <1> 
  6099 00009CF9 66FF05[4A040300]    <1> 	inc	word [argc] ; 11/05/2016
  6100                              <1> 
  6101                              <1> loc_load_and_run_file_2:
  6102 00009D00 AC                  <1> 	lodsb
  6103 00009D01 3C20                <1> 	cmp	al, 20h
  6104 00009D03 7717                <1> 	ja	short loc_load_and_run_file_5	
  6105 00009D05 721E                <1> 	jb	short loc_load_and_run_file_6
  6106                              <1> 
  6107                              <1> loc_load_and_run_file_3:
  6108 00009D07 803E20              <1> 	cmp	byte [esi], 20h
  6109 00009D0A 7707                <1> 	ja	short loc_load_and_run_file_4
  6110 00009D0C 7217                <1> 	jb	short loc_load_and_run_file_6
  6111 00009D0E 46                  <1> 	inc	esi
  6112 00009D0F E2F6                <1> 	loop	loc_load_and_run_file_3
  6113 00009D11 EB12                <1> 	jmp	short loc_load_and_run_file_6
  6114                              <1> 
  6115                              <1> loc_load_and_run_file_4:
  6116 00009D13 28C0                <1> 	sub	al, al ; 0
  6117 00009D15 66FF05[4A040300]    <1> 	inc	word [argc]
  6118                              <1> loc_load_and_run_file_5:
  6119 00009D1C AA                  <1> 	stosb
  6120 00009D1D FF05[8C030300]      <1> 	inc	dword [u.nread]
  6121 00009D23 E2DB                <1> 	loop	loc_load_and_run_file_2
  6122                              <1> 			
  6123                              <1> loc_load_and_run_file_6:
  6124 00009D25 30C0                <1> 	xor	al, al ; 0
  6125 00009D27 AA                  <1> 	stosb
  6126 00009D28 FF05[8C030300]      <1> 	inc	dword [u.nread]
  6127                              <1> loc_load_and_run_file_7:
  6128 00009D2E 8807                <1> 	mov 	[edi], al ; 0
  6129 00009D30 66FF05[4A040300]    <1> 	inc	word [argc] ; 24/04/2016
  6130 00009D37 FF05[8C030300]      <1> 	inc	dword [u.nread] ; 24/04/2016
  6131 00009D3D BE[6E5A0100]        <1> 	mov	esi, TextBuffer
  6132 00009D42 8B15[74620100]      <1> 	mov	edx, [FindFile_DirEntry+DirEntry_FileSize]
  6133 00009D48 66A1[6C620100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusHI]
  6134 00009D4E C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  6135 00009D51 66A1[72620100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusLO]
  6136                              <1> 	; EAX = First Cluster number
  6137                              <1> 	; EDX = File Size
  6138                              <1> 	; ESI = Argument list address
  6139                              <1> 	; [argc] = argument count
  6140                              <1> 	; [u.nread] = argument list length
  6141 00009D57 E89D420000          <1> 	call	load_and_run_file ; trdosk6.s
  6142                              <1>         ;jc	loc_run_cmd_failed ; 04/01/2017
  6143                              <1> loc_load_and_run_file_8: ; 06/05/2016
  6144 00009D5C E98BE9FFFF          <1> 	jmp	loc_file_rw_restore_retn
  6145                              <1> 
  6146                              <1> check_prg_filename_ext:
  6147                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
  6148                              <1> 	; 10/09/2011 
  6149                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'proc_check_exe_filename_ext')
  6150                              <1> 	; 14/11/2009
  6151                              <1> 	; INPUT -> 
  6152                              <1> 	;	ESI = Dot File Name
  6153                              <1> 	; OUTPUT ->
  6154                              <1> 	;     cf = 0 -> EXE_ID in AL
  6155                              <1> 	;	ESI = Last char + 1 position
  6156                              <1> 	;     cf = 1 -> Invalid executable file name
  6157                              <1> 	;	or no file name extension if AH<=8
  6158                              <1> 	;	AL = Last file name char     
  6159                              <1> 	;     cf = 0 -> AL='P' (PRG), AL=0 (no extension)
  6160                              <1> 	;
  6161                              <1> 	; (Modified registers: EAX, ESI)
  6162                              <1>   
  6163 00009D61 30E4                <1> 	xor	ah, ah
  6164                              <1> loc_run_check_filename_ext:	
  6165 00009D63 AC                  <1> 	lodsb
  6166 00009D64 3C21                <1> 	cmp	al, 21h
  6167 00009D66 7229                <1> 	jb	short loc_check_exe_fn_retn 
  6168 00009D68 FEC4                <1> 	inc	ah
  6169 00009D6A 3C2E                <1> 	cmp	al, '.'
  6170 00009D6C 75F5                <1> 	jne	short loc_run_check_filename_ext	
  6171                              <1> 		 
  6172                              <1> loc_run_check_filename_ext_dot:
  6173 00009D6E 80FC02              <1> 	cmp	ah, 2 ; .??? is not valid
  6174 00009D71 88C4                <1> 	mov	ah, al ; '.' 
  6175 00009D73 7219                <1> 	jb	short loc_check_prg_fn_retn
  6176                              <1> 
  6177                              <1> loc_run_check_filename_ext_dot_ok:
  6178 00009D75 AC                  <1> 	lodsb
  6179 00009D76 24DF                <1> 	and	al, 0DFh 
  6180                              <1> 
  6181                              <1> loc_run_check_filename_ext_prg:
  6182 00009D78 3C50                <1> 	cmp	al, 'P'
  6183 00009D7A 7212                <1> 	jb	short loc_check_prg_fn_retn
  6184 00009D7C 7711                <1> 	ja	short loc_check_prg_fn_stc
  6185 00009D7E AC                  <1> 	lodsb
  6186 00009D7F 24DF                <1> 	and	al, 0DFh 
  6187 00009D81 3C52                <1> 	cmp	al, 'R'
  6188 00009D83 750A                <1> 	jne	short loc_check_prg_fn_stc
  6189 00009D85 AC                  <1> 	lodsb
  6190 00009D86 24DF                <1> 	and	al, 0DFh
  6191 00009D88 3C47                <1> 	cmp	al, 'G'
  6192 00009D8A 7503                <1> 	jne	short loc_check_prg_fn_stc
  6193                              <1> 
  6194 00009D8C B050                <1> 	mov	al, 'P'
  6195                              <1> loc_check_prg_fn_retn:
  6196 00009D8E C3                  <1> 	retn
  6197                              <1> 
  6198                              <1> loc_check_prg_fn_stc:
  6199 00009D8F F9                  <1> 	stc
  6200 00009D90 C3                  <1> 	retn
  6201                              <1>  
  6202                              <1> loc_check_exe_fn_retn:
  6203 00009D91 28C0                <1> 	sub	al, al ; 0
  6204 00009D93 C3                  <1> 	retn
  6205                              <1>               
  6206                              <1> find_and_list_files:
  6207 00009D94 C3                  <1> 	retn
  6208                              <1> set_exec_arguments:
  6209 00009D95 C3                  <1> 	retn
  6210                              <1> delete_fs_directory:
  6211 00009D96 31C0                <1> 	xor eax, eax
  6212 00009D98 C3                  <1> 	retn
  2308                                  %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: 29/12/2017
     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> 	; 05/10/2016
    20                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
    21                              <1> 	; 27/03/2011
    22                              <1> 	; 09/10/2009
    23                              <1> 	; INPUT/OUTPUT => none
    24                              <1> 	; this procedure changes current directory string/text  
    25                              <1> 	; 2005
    26                              <1> 
    27 00009D99 BE[C3600100]        <1> 	mov	esi, PATH_Array
    28                              <1> change_prompt_dir_str: ; 05/10/2016 (call from 'set_working_path')
    29 00009D9E BF[72590100]        <1> 	mov	edi, Current_Directory
    30 00009DA3 8A25[6C590100]      <1> 	mov	ah, [Current_Dir_Level]
    31 00009DA9 E807000000          <1> 	call	set_current_directory_string
    32 00009DAE 880D[CD590100]      <1> 	mov	[Current_Dir_StrLen], cl
    33                              <1> 
    34 00009DB4 C3                  <1> 	retn
    35                              <1> 
    36                              <1> set_current_directory_string:
    37                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
    38                              <1> 	; 27/03/2011
    39                              <1> 	; 09/10/2009
    40                              <1> 	; INPUT:
    41                              <1> 	;    ESI = Path Array Address 
    42                              <1> 	;    EDI = Current Directory String Buffer
    43                              <1> 	;    AH = Current Directory Level
    44                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
    45                              <1> 	;    EDI will be same with input
    46                              <1> 	;    ECX = Current Directory String Length 
    47                              <1> 
    48 00009DB5 57                  <1> 	push    edi
    49 00009DB6 80FC00              <1> 	cmp     ah, 0
    50 00009DB9 7652                <1> 	jna	short pass_write_path
    51 00009DBB 83C610              <1> 	add	esi, 16
    52 00009DBE 89F3                <1> 	mov	ebx, esi
    53                              <1> loc_write_path:
    54 00009DC0 B908000000          <1> 	mov	ecx, 8
    55                              <1> path_write_dirname1:
    56 00009DC5 AC                  <1> 	lodsb
    57 00009DC6 3C20                <1> 	cmp	al, 20h
    58 00009DC8 7612                <1> 	jna	short pass_write_dirname1
    59 00009DCA AA                  <1> 	stosb
    60 00009DCB 81FF[CC590100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    61 00009DD1 733A                <1> 	jnb	short pass_write_path
    62 00009DD3 E2F0                <1> 	loop	path_write_dirname1
    63 00009DD5 803E20              <1> 	cmp	byte [esi], 20h
    64 00009DD8 7624                <1> 	jna	short pass_write_dirname2
    65 00009DDA EB0A                <1> 	jmp     short loc_put_dot_cont_ext
    66                              <1> pass_write_dirname1:
    67 00009DDC 89DE                <1> 	mov	esi, ebx
    68 00009DDE 83C608              <1> 	add	esi, 8
    69 00009DE1 803E20              <1> 	cmp	byte [esi], 20h
    70 00009DE4 7618                <1> 	jna	short pass_write_dirname2
    71                              <1> loc_put_dot_cont_ext:
    72 00009DE6 C6072E              <1> 	mov	byte [edi], "."
    73                              <1> 	;mov	ecx, 3
    74 00009DE9 B103                <1> 	mov	cl, 3
    75                              <1> loc_check_dir_name_ext:
    76 00009DEB AC                  <1> 	lodsb
    77 00009DEC 47                  <1> 	inc	edi
    78 00009DED 3C20                <1> 	cmp	al, 20h
    79 00009DEF 760D                <1> 	jna	short pass_write_dirname2
    80 00009DF1 8807                <1> 	mov	[edi], al
    81 00009DF3 81FF[CC590100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    82 00009DF9 7312                <1> 	jnb	short pass_write_path
    83 00009DFB E2EE                <1> 	loop    loc_check_dir_name_ext
    84 00009DFD 47                  <1> 	inc	edi
    85                              <1> pass_write_dirname2:
    86 00009DFE FECC                <1> 	dec	ah
    87 00009E00 740B                <1> 	jz      short pass_write_path
    88 00009E02 83C310              <1> 	add	ebx, 16
    89 00009E05 89DE                <1> 	mov	esi, ebx
    90 00009E07 C6072F              <1> 	mov	byte [edi],"/"
    91 00009E0A 47                  <1> 	inc	edi
    92 00009E0B EBB3                <1> 	jmp	short loc_write_path
    93                              <1> pass_write_path:
    94 00009E0D C60700              <1> 	mov	byte [edi], 0
    95 00009E10 47                  <1> 	inc	edi
    96 00009E11 89F9                <1> 	mov	ecx, edi
    97 00009E13 5F                  <1> 	pop	edi
    98 00009E14 29F9                <1> 	sub	ecx, edi
    99                              <1> 	; ECX = Current Directory String Length
   100 00009E16 C3                  <1> 	retn
   101                              <1> 
   102                              <1> get_current_directory:
   103                              <1> 	; 15/10/2016
   104                              <1> 	; 14/02/2016
   105                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
   106                              <1> 	; 27/03/2011
   107                              <1> 	;
   108                              <1> 	; INPUT-> ESI = Current Directory Buffer
   109                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
   110                              <1> 	;              (0= Default/Current Drive)
   111                              <1> 	;           
   112                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
   113                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
   114                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
   115                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
   116                              <1> 	;            CX/CL = Current Directory String Length
   117                              <1> 	;	     DL = Drive Number (0 based)
   118                              <1> 	;            (If input is 0, output is current drv number) 
   119                              <1> 	;            DH = same with input 
   120                              <1> 	;   cf = 0 -> AL = 0
   121                              <1> 	;   cf = 1 -> error code in AL 
   122                              <1>               
   123                              <1> loc_get_current_drive_0:
   124 00009E17 80FA00              <1> 	cmp	dl, 0
   125 00009E1A 7708                <1> 	ja	short loc_get_current_drive_1
   126 00009E1C 8A15[6E590100]      <1> 	mov	dl, [Current_Drv]
   127 00009E22 EB17                <1> 	jmp	short loc_get_current_drive_2
   128                              <1> loc_get_current_drive_1:
   129 00009E24 FECA                <1> 	dec 	dl
   130 00009E26 3A15[3A0D0100]      <1> 	cmp	dl, [Last_DOS_DiskNo]
   131 00009E2C 760D                <1> 	jna	short loc_get_current_drive_2
   132 00009E2E B80F000000          <1> 	mov	eax, 0Fh ; Invalid drive (Drive not ready!)
   133 00009E33 F5                  <1> 	cmc 	; stc
   134 00009E34 C3                  <1> 	retn
   135                              <1> 
   136                              <1> loc_get_current_drive_not_ready_retn:
   137 00009E35 5E                  <1> 	pop	esi
   138                              <1> 	;mov	eax, 15
   139 00009E36 66B80F00            <1> 	mov	ax, 15 ; Drive not ready
   140 00009E3A C3                  <1> 	retn  
   141                              <1>  
   142                              <1> loc_get_current_drive_2:
   143 00009E3B 31C0                <1> 	xor	eax, eax
   144 00009E3D 88D4                <1> 	mov	ah, dl
   145 00009E3F 56                  <1> 	push	esi
   146 00009E40 BE00010900          <1> 	mov	esi, Logical_DOSDisks
   147 00009E45 01C6                <1> 	add	esi, eax
   148 00009E47 8A06                <1> 	mov	al, [esi+LD_Name] 
   149 00009E49 3C41                <1> 	cmp	al, 'A'
   150 00009E4B 72E8                <1> 	jb	short loc_get_current_drive_not_ready_retn
   151                              <1> 
   152 00009E4D 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   153 00009E50 08E4                <1> 	or	ah, ah
   154 00009E52 7506                <1> 	jnz	short loc_get_current_drive_3
   155                              <1> 
   156                              <1> 	;xor	ah, ah ; mov ah, 0
   157 00009E54 8826                <1> 	mov	[esi], ah
   158 00009E56 31C9                <1> 	xor	ecx, ecx
   159 00009E58 EB1C                <1> 	jmp	short loc_get_current_drive_4
   160                              <1> 
   161                              <1> loc_get_current_drive_3:
   162 00009E5A BF[C3600100]        <1>         mov     edi, PATH_Array
   163 00009E5F 57                  <1> 	push	edi
   164 00009E60 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   165 00009E66 B920000000          <1> 	mov	ecx, 32
   166 00009E6B F3A5                <1> 	rep	movsd
   167 00009E6D 5E                  <1> 	pop	esi ; Path Array Address
   168 00009E6E 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset) 
   169                              <1> 	;
   170 00009E6F E841FFFFFF          <1> 	call	set_current_directory_string
   171 00009E74 89FE                <1> 	mov	esi, edi
   172                              <1> 
   173                              <1> loc_get_current_drive_4:
   174 00009E76 30C0                <1> 	xor	al, al
   175 00009E78 C3                  <1> 	retn
   176                              <1> 
   177                              <1> change_current_directory:
   178                              <1> 	; 19/02/2016
   179                              <1> 	; 11/02/2016
   180                              <1> 	; 10/02/2016
   181                              <1> 	; 08/02/2016
   182                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   183                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)	
   184                              <1> 	; 04/10/2009
   185                              <1> 	; 2005
   186                              <1> 	; INPUT -> 
   187                              <1> 	;	ESI = Directory string
   188                              <1> 	;	ah = CD command (CDh = save current dir string)
   189                              <1> 	; OUTPUT -> 
   190                              <1> 	; 	EDI = DOS Drive Description Table
   191                              <1> 	; 	cf = 1 -> error
   192                              <1> 	;	   EAX = Error code
   193                              <1> 	;	cf = 0 -> successful
   194                              <1> 	;	   ESI = PATH_Array
   195                              <1> 	;	   EAX = Current Directory First Cluster
   196                              <1> 	;
   197                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
   198                              <1> 	
   199 00009E79 8825[51610100]      <1> 	mov	[CD_COMMAND], ah
   200 00009E7F 803E2F              <1> 	cmp	byte [esi], '/'
   201 00009E82 7505                <1> 	jne	short loc_ccd_cdir_level
   202 00009E84 46                  <1> 	inc	esi
   203 00009E85 30C0                <1> 	xor	al, al
   204 00009E87 EB05                <1> 	jmp	short loc_ccd_parse_path_name
   205                              <1> loc_ccd_cdir_level:
   206 00009E89 A0[6C590100]        <1> 	mov	al, [Current_Dir_Level]
   207                              <1> loc_ccd_parse_path_name:
   208 00009E8E 88C4                <1> 	mov	ah, al
   209 00009E90 BF[C3600100]        <1> 	mov	edi, PATH_Array
   210                              <1> 
   211                              <1> ; Reset directory levels > cdir level
   212                              <1> 	; is this required !?
   213                              <1> 	;
   214                              <1> 	; Relations:
   215                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
   216                              <1> 	; proc_parse_dir_name,
   217                              <1> 	; proc_change_current_directory (this procedure)
   218                              <1> 	; proc_change_prompt_dir_string 
   219                              <1>  
   220 00009E95 0FB6C8              <1> 	movzx	ecx, al
   221 00009E98 FEC1                <1> 	inc	cl
   222 00009E9A C0E104              <1> 	shl	cl, 4
   223 00009E9D 01CF                <1> 	add	edi, ecx
   224 00009E9F B107                <1> 	mov	cl, 7
   225 00009EA1 28C1                <1> 	sub	cl, al
   226 00009EA3 C0E102              <1> 	shl	cl, 2
   227 00009EA6 89C3                <1> 	mov	ebx, eax
   228 00009EA8 31C0                <1> 	xor	eax, eax ; 0
   229 00009EAA F3AB                <1> 	rep	stosd
   230 00009EAC 89D8                <1> 	mov	eax, ebx
   231                              <1> 
   232 00009EAE BF[C3600100]        <1> 	mov	edi, PATH_Array
   233                              <1> 
   234 00009EB3 803E20              <1> 	cmp	byte [esi], 20h
   235 00009EB6 F5                  <1> 	cmc
   236 00009EB7 7305                <1> 	jnc	short pass_ccd_parse_dir_name
   237                              <1> 
   238                              <1> 		; ESI = Path name
   239                              <1> 		; AL = CCD_Level
   240 00009EB9 E872010000          <1>         call    parse_dir_name
   241                              <1> 		; AL = CCD_Level 
   242                              <1> 		; AH = Last_Dir_Level
   243                              <1> 		; (EDI = PATH_Array)
   244                              <1> 
   245                              <1> pass_ccd_parse_dir_name:
   246 00009EBE 9C                  <1> 	pushf
   247                              <1> 
   248                              <1> 	;mov	[CCD_Level], al
   249                              <1>         ;mov	[Last_Dir_Level], ah
   250 00009EBF 66A3[47610100]      <1> 	mov	[CCD_Level], ax
   251                              <1> 
   252 00009EC5 31DB                <1> 	xor	ebx, ebx
   253 00009EC7 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
   254 00009ECD BE00010900          <1> 	mov	esi, Logical_DOSDisks
   255 00009ED2 01DE                <1> 	add	esi, ebx
   256                              <1> 
   257 00009ED4 9D                  <1> 	popf 
   258 00009ED5 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
   259                              <1> 
   260 00009ED7 8935[43610100]      <1> 	mov	[CCD_DriveDT], esi
   261                              <1> 
   262 00009EDD 3C07                <1> 	cmp	al, 7
   263 00009EDF 7209                <1> 	jb	short loc_ccd_load_child_dir
   264                              <1> 
   265                              <1> loc_ccd_bad_path_name_retn:
   266 00009EE1 87F7                <1> 	xchg	esi, edi
   267 00009EE3 B813000000          <1> 	mov	eax, 19 ; Bad directory/path name 
   268 00009EE8 F9                  <1> 	stc
   269                              <1> loc_ccd_retn_p:
   270 00009EE9 C3                  <1> 	retn
   271                              <1> 
   272                              <1> loc_ccd_load_child_dir:
   273                              <1> 	; AL = CCD_Level
   274 00009EEA 08C0                <1> 	or	al, al
   275 00009EEC 7468                <1> 	jz	short loc_ccd_load_root_dir
   276                              <1> 
   277 00009EEE 6689C1              <1> 	mov	cx, ax
   278 00009EF1 C0E004              <1> 	shl	al, 4
   279 00009EF4 0FB6F0              <1> 	movzx	esi, al
   280 00009EF7 01FE                <1>      	add	esi, edi  ; offset PATH_Array
   281                              <1> 
   282 00009EF9 8B460C              <1> 	mov	eax, [esi+12]
   283 00009EFC 38E9                <1> 	cmp	cl, ch
   284 00009EFE 0F84FA000000        <1>         je      loc_ccd_load_sub_directory
   285 00009F04 A3[68590100]        <1> 	mov	[Current_Dir_FCluster], eax
   286                              <1> 
   287                              <1> loc_ccd_load_child_dir_next:
   288 00009F09 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
   289                              <1> 
   290                              <1>  	; Directory attribute : 10h
   291 00009F0C B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
   292                              <1> 	;mov	ah, 11001000b ; C8h
   293                              <1> 	; Volume name attribute: 8h
   294 00009F0E B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
   295                              <1> 
   296 00009F10 6631C9              <1> 	xor	cx, cx  
   297 00009F13 E8B5010000          <1> 	call	locate_current_dir_file
   298 00009F18 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
   299                              <1> 
   300                              <1> 	 ; 19/02/2016
   301                              <1> 	;mov	edi, [CCD_DriveDT]
   302 00009F1A 8A25[47610100]      <1> 	mov	ah, [CCD_Level]
   303 00009F20 803D[51610100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   304 00009F27 7509                <1> 	jne	short loc_ccd_load_child_dir_err
   305                              <1> 	; It is better to save recent successful part 
   306                              <1> 	; of the (requested) path as current directory.
   307                              <1> 	; (Otherwise the path would be reset to back
   308                              <1> 	; on the next 'CD' command.)
   309 00009F29 88E1                <1> 	mov	cl, ah
   310 00009F2B 50                  <1> 	push	eax
   311 00009F2C E8E3000000          <1> 	call	loc_ccd_save_current_dir
   312 00009F31 58                  <1> 	pop	eax
   313                              <1> loc_ccd_load_child_dir_err:            
   314 00009F32 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
   315 00009F34 7202                <1> 	jb	short loc_ccd_path_not_found_retn
   316 00009F36 F9                  <1> 	stc
   317 00009F37 C3                  <1> 	retn
   318                              <1> 
   319                              <1> loc_ccd_path_not_found_retn:
   320 00009F38 B003                <1> 	mov	al, 3	; Path not found
   321 00009F3A C3                  <1> 	retn
   322                              <1> 
   323                              <1> loc_ccd_load_FAT_root_dir:
   324 00009F3B 803D[6D590100]02    <1> 	cmp	byte [Current_FATType], 2
   325 00009F42 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
   326                              <1> 
   327                              <1> 	;mov	esi, [CCD_DriveDT]
   328                              <1> 	;push	esi
   329 00009F44 E8B51D0000          <1> 	call	load_FAT_root_directory
   330                              <1> 	;pop	edi ; Dos Drv Description Table
   331                              <1> 
   332 00009F49 89F7                <1> 	mov	edi, esi
   333 00009F4B BE[C3600100]        <1> 	mov	esi, PATH_Array
   334 00009F50 7297                <1> 	jc	short loc_ccd_retn_p
   335                              <1> 
   336 00009F52 31C0                <1> 	xor	eax, eax
   337 00009F54 EB78                <1>         jmp	short loc_ccd_set_cdfc
   338                              <1> 
   339                              <1> loc_ccd_load_root_dir:
   340 00009F56 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
   341 00009F5D 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
   342                              <1> 
   343                              <1> loc_ccd_load_FS_root_dir:
   344 00009F5F E8611E0000          <1> 	call	load_FS_root_directory
   345 00009F64 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
   346                              <1> 
   347                              <1> loc_ccd_load_FS_sub_directory_next:
   348 00009F66 E85B1E0000          <1> 	call	load_FS_sub_directory
   349 00009F6B EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr  
   350                              <1> 
   351                              <1> loc_ccd_set_dir_cluster_ptr:
   352                              <1> 	; EDI = Directory Entry
   353 00009F6D 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
   354 00009F71 C1E010              <1> 	shl	eax, 16
   355 00009F74 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
   356                              <1> 
   357 00009F78 8B35[43610100]      <1> 	mov	esi, [CCD_DriveDT]
   358 00009F7E 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
   359 00009F85 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
   360                              <1> 	;push	esi
   361 00009F87 E8FD1D0000          <1> 	call	load_FAT_sub_directory
   362                              <1> 	;pop	edi ; Dos Drv Description Table
   363                              <1> 
   364                              <1> pass_ccd_set_dir_cluster_ptr:
   365                              <1> 	;mov	edi, esi
   366 00009F8C BE[C3600100]        <1> 	mov	esi, PATH_Array
   367 00009F91 7264                <1> 	jc	short loc_ccd_retn_c
   368                              <1> 
   369 00009F93 A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
   370                              <1> 
   371 00009F98 FE05[47610100]      <1> 	inc	byte [CCD_Level]
   372 00009F9E 0FB61D[47610100]    <1> 	movzx	ebx, byte [CCD_Level]
   373 00009FA5 C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)   
   374 00009FA8 01DE                <1> 	add	esi, ebx ; 19/02/2016
   375 00009FAA 89460C              <1> 	mov	[esi+12], eax
   376 00009FAD EB1F                <1> 	jmp	short loc_ccd_set_cdfc
   377                              <1> 
   378                              <1> loc_ccd_load_FAT32_root_dir:
   379 00009FAF BE[C3600100]        <1> 	mov	esi, PATH_Array
   380 00009FB4 8B460C              <1> 	mov	eax, [esi+12]
   381 00009FB7 8B35[43610100]      <1> 	mov	esi, [CCD_DriveDT]
   382                              <1>  
   383                              <1> loc_ccd_load_FAT_sub_directory:
   384                              <1> 	;push	esi
   385 00009FBD E8C71D0000          <1> 	call	load_FAT_sub_directory
   386                              <1> 	;pop	edi ; Dos Drv Description Table
   387                              <1> 
   388                              <1> pass_ccd_load_FAT_sub_directory:
   389                              <1> 	;mov	edi, esi
   390 00009FC2 BE[C3600100]        <1> 	mov	esi, PATH_Array
   391 00009FC7 722E                <1> 	jc	short loc_ccd_retn_c
   392                              <1> 
   393 00009FC9 A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
   394                              <1> 
   395                              <1> loc_ccd_set_cdfc:
   396 00009FCE 8A0D[47610100]      <1> 	mov	cl, [CCD_Level]
   397 00009FD4 880D[6C590100]      <1> 	mov	[Current_Dir_Level], cl
   398 00009FDA A3[68590100]        <1> 	mov	[Current_Dir_FCluster], eax
   399                              <1> 
   400 00009FDF 8A2D[48610100]      <1> 	mov	ch, [Last_Dir_Level]
   401 00009FE5 38E9                <1> 	cmp	cl, ch 
   402 00009FE7 0F821CFFFFFF        <1> 	jb	loc_ccd_load_child_dir_next
   403                              <1> 	
   404 00009FED 803D[51610100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   405 00009FF4 741E                <1> 	je	short loc_ccd_save_current_dir
   406                              <1> 
   407                              <1>         ; jne -> don't save, restore (the previous cdir) later !
   408                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
   409                              <1> 
   410 00009FF6 F8                  <1> 	clc
   411                              <1> 
   412                              <1> loc_ccd_retn_c:
   413 00009FF7 8B3D[43610100]      <1> 	mov	edi, [CCD_DriveDT]
   414 00009FFD C3                  <1> 	retn
   415                              <1> 
   416                              <1> loc_ccd_load_sub_directory:
   417 00009FFE 8B35[43610100]      <1> 	mov	esi, [CCD_DriveDT]
   418 0000A004 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
   419 0000A00B 73B0                <1> 	jnb	short loc_ccd_load_FAT_sub_directory 
   420 0000A00D E8B41D0000          <1> 	call	load_FS_sub_directory
   421 0000A012 EBAE                <1> 	jmp	short pass_ccd_load_FAT_sub_directory 
   422                              <1> 
   423                              <1> loc_ccd_save_current_dir:
   424 0000A014 BE[C3600100]        <1> 	mov	esi, PATH_Array ; 19/02/2016
   425 0000A019 8B3D[43610100]      <1> 	mov	edi, [CCD_DriveDT]
   426 0000A01F 57                  <1> 	push	edi
   427 0000A020 83C77F              <1>         add     edi, LD_CDirLevel
   428 0000A023 880F                <1> 	mov	[edi], cl
   429 0000A025 47                  <1> 	inc	edi ; LD_CurrentDirectory 
   430 0000A026 56                  <1> 	push	esi
   431                              <1> 	;mov	ecx, 32  ; always < 65536 (in this procedure)
   432 0000A027 66B92000            <1> 	mov	cx, 32
   433 0000A02B F3A5                <1> 	rep	movsd
   434                              <1> 	; Current directory has been saved to 
   435                              <1> 	; the DOS drive description table, cdir area !
   436 0000A02D 5E                  <1> 	pop	esi  ; PATH_Array
   437 0000A02E 5F                  <1> 	pop	edi  ; Dos Drv Description Table
   438                              <1> 
   439 0000A02F C3                  <1> 	retn
   440                              <1> 
   441                              <1> parse_dir_name:
   442                              <1> 	; 11/02/2016
   443                              <1> 	; 10/02/2016
   444                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
   445                              <1> 	; 18/09/2011
   446                              <1> 	; 17/10/2009
   447                              <1> 	; INPUT ->
   448                              <1> 	;	ESI = ASCIIZ Directory String Address
   449                              <1> 	;	AL = Current Directory Level
   450                              <1> 	;	EDI = Destination Adress
   451                              <1> 	;	     (8 levels, each one 12+4 byte)
   452                              <1> 	; OUTPUT ->
   453                              <1> 	;	EDI = Dir Entry Formatted Array
   454                              <1> 	;	     with zero cluster pointer at the last level
   455                              <1> 	;	AH = Last Dir Level
   456                              <1> 	;	AL = Current Dir Level
   457                              <1> 	;
   458                              <1> 	; (esi, ebx, ecx will be changed) 
   459                              <1> 
   460                              <1> 	;mov	[PATH_Array_Ptr], edi
   461 0000A030 88C4                <1> 	mov	ah, al
   462 0000A032 66A3[E8610100]      <1> 	mov	[PATH_CDLevel], ax
   463                              <1> repeat_ppdn_check_slash:
   464 0000A038 AC                  <1> 	lodsb
   465 0000A039 3C2F                <1> 	cmp	al, '/'
   466 0000A03B 74FB                <1> 	je	short repeat_ppdn_check_slash
   467 0000A03D 3C21                <1> 	cmp	al, 21h
   468 0000A03F 7219                <1> 	jb	short loc_ppdn_retn
   469 0000A041 57                  <1> 	push	edi
   470                              <1> loc_ppdn_get_dir_name:
   471 0000A042 B90C000000          <1> 	mov	ecx, 12
   472 0000A047 BF[EA610100]        <1> 	mov	edi, Dir_File_Name
   473                              <1> repeat_ppdn_get_dir_name:
   474 0000A04C AA                  <1> 	stosb
   475 0000A04D AC                  <1> 	lodsb
   476 0000A04E 3C2F                <1> 	cmp	al, '/'
   477 0000A050 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
   478 0000A052 3C20                <1> 	cmp	al, 20h
   479 0000A054 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
   480 0000A056 E2F4                <1> 	loop	repeat_ppdn_get_dir_name
   481 0000A058 5F                  <1> 	pop	edi
   482 0000A059 F9                  <1> 	stc
   483                              <1> loc_ppdn_retn:
   484 0000A05A C3                  <1> 	retn
   485                              <1> 
   486                              <1> loc_ppdn_end_of_path_scan:
   487 0000A05B 4E                  <1> 	dec	esi
   488                              <1> loc_check_level_dot_conv_dir_name:
   489 0000A05C 31C0                <1> 	xor	eax, eax
   490 0000A05E AA                  <1> 	stosb
   491 0000A05F 89F3                <1> 	mov	ebx, esi
   492 0000A061 BE[EA610100]        <1> 	mov	esi, Dir_File_Name
   493 0000A066 AC                  <1> 	lodsb
   494                              <1> repeat_ppdn_name_check_dot:
   495 0000A067 3C2E                <1> 	cmp	al, '.'
   496 0000A069 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
   497                              <1> repeat_ppdn_name_dot_dot:
   498 0000A06B AC                  <1> 	lodsb
   499 0000A06C 3C2E                <1> 	cmp	al, '.'
   500 0000A06E 743E                <1> 	je	short loc_ppdn_dot_dot
   501 0000A070 3C21                <1> 	cmp	al, 21h
   502 0000A072 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
   503                              <1> loc_ppdn_convert_sub_dir_name:
   504 0000A074 8A25[E9610100]      <1> 	mov	ah, [PATH_Level]
   505 0000A07A 80FC07              <1> 	cmp	ah, 7
   506 0000A07D 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
   507 0000A07F FEC4                <1> 	inc	ah  
   508 0000A081 8825[E9610100]      <1> 	mov	[PATH_Level], ah
   509 0000A087 BE[EA610100]        <1> 	mov	esi, Dir_File_Name
   510                              <1> 	;mov	edi, [PATH_Array_Ptr]
   511 0000A08C B010                <1> 	mov	al, 16
   512 0000A08E F6E4                <1> 	mul	ah
   513 0000A090 8B3C24              <1> 	mov	edi, [esp]
   514                              <1> 	;push	edi 
   515 0000A093 01C7                <1> 	add	edi, eax
   516 0000A095 E82A030000          <1> 	call	convert_file_name
   517                              <1> 	;pop	edi
   518                              <1> pass_ppdn_convert_sub_dir_name:
   519 0000A09A 89DE                <1> 	mov	esi, ebx
   520                              <1> repeat_ppdn_check_last_slash:
   521 0000A09C AC                  <1> 	lodsb
   522 0000A09D 3C2F                <1> 	cmp	al, '/'
   523 0000A09F 74FB                <1> 	je	short repeat_ppdn_check_last_slash
   524 0000A0A1 3C21                <1> 	cmp	al, 21h
   525 0000A0A3 739D                <1> 	jnb	short loc_ppdn_get_dir_name
   526                              <1> end_of_parse_dir_name:
   527 0000A0A5 5F                  <1> 	pop	edi
   528 0000A0A6 F5                  <1> 	cmc  
   529                              <1> 	;mov	al, [PATH_CDLevel]
   530                              <1> 	;mov	ah, [PATH_Level]
   531 0000A0A7 66A1[E8610100]      <1> 	mov	ax, [PATH_CDLevel]
   532 0000A0AD C3                  <1> 	retn
   533                              <1> 
   534                              <1> loc_ppdn_dot_dot:
   535 0000A0AE AC                  <1> 	lodsb
   536 0000A0AF 3C21                <1> 	cmp	al, 21h
   537 0000A0B1 73F2                <1> 	jnb	short end_of_parse_dir_name 
   538                              <1> loc_ppdn_dot_dot_prev_level:
   539 0000A0B3 66A1[E8610100]      <1> 	mov	ax, [PATH_CDLevel]
   540 0000A0B9 80EC01              <1> 	sub	ah, 1
   541 0000A0BC 80D400              <1> 	adc	ah, 0
   542 0000A0BF 38E0                <1> 	cmp	al, ah
   543 0000A0C1 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
   544 0000A0C3 88E0                <1> 	mov	al, ah
   545                              <1> pass_ppdn_set_al_to_ah:
   546 0000A0C5 66A3[E8610100]      <1> 	mov	[PATH_CDLevel], ax
   547 0000A0CB EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
   548                              <1> 
   549                              <1> locate_current_dir_file:
   550                              <1> 	; 20/11/2017
   551                              <1> 	; 14/02/2016
   552                              <1> 	; 13/02/2016
   553                              <1> 	; 10/02/2016
   554                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   555                              <1> 	; 14/08/2010
   556                              <1> 	; 19/09/2009
   557                              <1>         ; 2005
   558                              <1> 	; INPUT ->
   559                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   560                              <1> 	;	AL = Attributes Mask 
   561                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   562                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   563                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   564                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   565                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   566                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   567                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   568                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
   569                              <1> 	;	     proper entry (which fits with Atributes Masks)
   570                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
   571                              <1> 	;	? = Any One Char
   572                              <1> 	;	* = Every Chars
   573                              <1> 	; OUTPUT ->
   574                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
   575                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   576                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   577                              <1> 	;	DL = Attributes
   578                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   579                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   580                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   581                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   582                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   583                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
   584                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   585                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   586                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   587                              <1> 	;	CF = 0 -> 
   588                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
   589                              <1> 
   590                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
   591                              <1> 
   592 0000A0CD 8935[4B610100]      <1> 	mov	[CDLF_FNAddress], esi
   593 0000A0D3 66A3[49610100]      <1> 	mov	[CDLF_AttributesMask], ax
   594 0000A0D9 66890D[4F610100]    <1> 	mov	[CDLF_DEType], cx
   595                              <1> 
   596 0000A0E0 31DB                <1> 	xor	ebx, ebx
   597 0000A0E2 881D[60610100]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
   598                              <1> 
   599 0000A0E8 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
   600 0000A0EE 381D[8C600100]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
   601 0000A0F4 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
   602 0000A0F6 8A1D[8A600100]      <1>         mov     bl, [DirBuff_DRV]
   603 0000A0FC 80EB41              <1> 	sub	bl, 'A'
   604 0000A0FF 38DF                <1> 	cmp	bh, bl
   605 0000A101 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
   606 0000A103 8B15[91600100]      <1> 	mov	edx, [DirBuff_Cluster]
   607 0000A109 3B15[68590100]      <1> 	cmp	edx, [Current_Dir_FCluster]
   608 0000A10F 7412                <1> 	je	short loc_cdir_locatefile_search
   609                              <1> 
   610                              <1> loc_lcdf_reload_current_dir1:
   611 0000A111 30DB                <1> 	xor	bl, bl
   612                              <1> loc_lcdf_reload_current_dir2:
   613 0000A113 89DE                <1> 	mov	esi, ebx
   614 0000A115 81C600010900        <1>         add     esi, Logical_DOSDisks
   615 0000A11B E874000000          <1> 	call	reload_current_directory 
   616 0000A120 735D                <1> 	jnc	short loc_locatefile_search_again 
   617 0000A122 C3                  <1> 	retn  
   618                              <1> 
   619                              <1> loc_cdir_locatefile_search:
   620 0000A123 31DB                <1> 	xor	ebx, ebx
   621 0000A125 55                  <1> 	push	ebp ; 20/11/2017
   622 0000A126 E8A6000000          <1> 	call	find_directory_entry
   623 0000A12B 5D                  <1> 	pop	ebp ; 20/11/2017
   624 0000A12C 7349                <1> 	jnc	short loc_cdir_locate_file_retn
   625                              <1> 
   626                              <1> loc_locatefile_check_stc_reason:
   627 0000A12E 08ED                <1> 	or	ch, ch
   628 0000A130 7444                <1> 	jz	short loc_cdir_locate_file_stc_retn
   629                              <1> 
   630                              <1> loc_locatefile_check_next_entryblock:
   631 0000A132 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
   632 0000A138 28DB                <1> 	sub	bl, bl
   633 0000A13A 0FB7F3              <1> 	movzx	esi, bx
   634 0000A13D 81C600010900        <1>         add     esi, Logical_DOSDisks
   635                              <1> 
   636 0000A143 803D[6C590100]00    <1> 	cmp	byte [Current_Dir_Level], 0
   637 0000A14A 760A                <1> 	jna	short loc_locatefile_check_FAT_type
   638                              <1>             
   639 0000A14C 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
   640 0000A153 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
   641 0000A155 C3                  <1> 	retn  
   642                              <1> 
   643                              <1> loc_locatefile_check_FAT_type:
   644 0000A156 803D[6D590100]03    <1> 	cmp	byte [Current_FATType], 3
   645 0000A15D 7218                <1> 	jb	short loc_cdir_locate_file_retn
   646                              <1> 
   647                              <1> loc_locatefile_load_subdir_cluster:
   648 0000A15F A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
   649 0000A164 E83A1A0000          <1> 	call	get_next_cluster
   650 0000A169 730D                <1> 	jnc	short loc_locatefile_next_cluster
   651 0000A16B 09C0                <1> 	or	eax, eax
   652 0000A16D 7507                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
   653 0000A16F F9                  <1> 	stc
   654                              <1> loc_locatefile_file_notfound:
   655 0000A170 B802000000          <1> 	mov	eax, 2 ; File/Directory/VolName not found
   656 0000A175 C3                  <1> 	retn
   657                              <1> 
   658                              <1> loc_locatefile_drive_not_ready_read_err:
   659                              <1> 	;mov	eax, 17 ;Drive not ready or read error
   660                              <1> loc_cdir_locate_file_stc_retn:
   661 0000A176 F5                  <1> 	cmc ;stc
   662                              <1> loc_cdir_locate_file_retn:
   663 0000A177 C3                  <1> 	retn
   664                              <1> 
   665                              <1> loc_locatefile_next_cluster:
   666 0000A178 E80C1C0000          <1> 	call	load_FAT_sub_directory
   667                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
   668 0000A17D 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
   669                              <1> 
   670                              <1> loc_locatefile_search_again:
   671 0000A17F 8B35[4B610100]      <1> 	mov	esi, [CDLF_FNAddress] 
   672 0000A185 66A1[49610100]      <1> 	mov	ax, [CDLF_AttributesMask]
   673 0000A18B 668B0D[4F610100]    <1> 	mov	cx, [CDLF_DEType] 
   674 0000A192 EB8F                <1> 	jmp	short loc_cdir_locatefile_search
   675                              <1> 
   676                              <1> reload_current_directory:
   677                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   678                              <1> 	; 13/06/2010
   679                              <1> 	; 22/09/2009
   680                              <1>         ;
   681                              <1> 	; INPUT ->
   682                              <1> 	;	ESI = Dos drive description table address
   683                              <1> 	
   684                              <1> 	;mov	al, [esi+LD_FATType]
   685 0000A194 A0[6D590100]        <1> 	mov	al, [Current_FATType]
   686 0000A199 3C02                <1> 	cmp	al, 2
   687 0000A19B 7729                <1> 	ja	short loc_reload_FAT_sub_directory
   688 0000A19D 8A25[6C590100]      <1> 	mov	ah, [Current_Dir_Level]
   689 0000A1A3 08C0                <1> 	or	al, al
   690 0000A1A5 740A                <1> 	jz	short loc_reload_FS_directory
   691 0000A1A7 08E4                <1> 	or	ah, ah
   692 0000A1A9 751B                <1> 	jnz	short loc_reload_FAT_sub_directory
   693                              <1> loc_reload_FAT_12_16_root_directory:
   694 0000A1AB E84E1B0000          <1> 	call	load_FAT_root_directory
   695 0000A1B0 C3                  <1> 	retn
   696                              <1> loc_reload_FS_directory:
   697 0000A1B1 20E4                <1> 	and	ah, ah
   698 0000A1B3 7506                <1> 	jnz	short loc_reload_FS_sub_directory 
   699                              <1> loc_reload_FS_root_directory: 
   700 0000A1B5 E80B1C0000          <1> 	call	load_FS_root_directory
   701 0000A1BA C3                  <1> 	retn
   702                              <1> loc_reload_FS_sub_directory:
   703 0000A1BB A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
   704 0000A1C0 E8011C0000          <1> 	call	load_FS_sub_directory
   705 0000A1C5 C3                  <1> 	retn 
   706                              <1> loc_reload_FAT_sub_directory:
   707 0000A1C6 A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
   708 0000A1CB E8B91B0000          <1> 	call	load_FAT_sub_directory
   709 0000A1D0 C3                  <1> 	retn
   710                              <1> 
   711                              <1> find_directory_entry:
   712                              <1> 	; 14/02/2016
   713                              <1> 	; 13/02/2016
   714                              <1> 	; 10/02/2016
   715                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   716                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
   717                              <1> 	; 19/09/2009
   718                              <1> 	; 2005
   719                              <1> 	; INPUT ->
   720                              <1> 	;	ESI = Sub Dir or File Name Address
   721                              <1> 	;	AL = Attributes Mask 
   722                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   723                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   724                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   725                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   726                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   727                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   728                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   729                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
   730                              <1> 	;            proper entry (which fits with Atributes Masks)
   731                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
   732                              <1> 	;	? = Any One Char
   733                              <1> 	;	* = Every Chars
   734                              <1> 	;	EBX = Current Dir Entry (BX)
   735                              <1> 	;
   736                              <1> 	; OUTPUT -> 
   737                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
   738                              <1> 	;	ESI = Sub Dir or File Name Address
   739                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   740                              <1> 	;	DL = Attributes
   741                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   742                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   743                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   744                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   745                              <1> 	;	EBX = CurrentDirEntry (BX)
   746                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   747                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
   748                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   749                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   750                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   751                              <1> 	;
   752                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)	 
   753                              <1> 
   754 0000A1D1 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   755 0000A1D8 0F8739010000        <1>         ja      loc_ffde_stc_retn_255
   756                              <1> 
   757                              <1> 	;mov    [DirBuff_CurrentEntry], bx  
   758                              <1> 
   759 0000A1DE BF00000800          <1>   	mov	edi, Directory_Buffer
   760 0000A1E3 66A3[5C610100]      <1> 	mov	[FDE_AttrMask], ax
   761                              <1> 
   762 0000A1E9 29C0                <1> 	sub	eax, eax
   763                              <1>             
   764                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
   765 0000A1EB 66A3[5E610100]      <1> 	mov	[AmbiguousFileName], ax ; 0
   766                              <1> 
   767 0000A1F1 6689D8              <1> 	mov	ax, bx
   768 0000A1F4 66C1E005            <1> 	shl	ax, 5 ; ; * 32 ; Directory entry size
   769 0000A1F8 01C7                <1> 	add     edi, eax
   770                              <1> 
   771 0000A1FA 08ED                <1> 	or	ch, ch
   772 0000A1FC 0F852C010000        <1>         jnz     loc_find_free_deleted_entry_0
   773                              <1> 
   774 0000A202 08C9                <1> 	or      cl, cl
   775 0000A204 0F850D010000        <1>         jnz     loc_ffde_stc_retn_255
   776                              <1>  
   777                              <1> check_find_dir_entry:
   778 0000A20A 66A1[5C610100]      <1> 	mov	ax, [FDE_AttrMask]
   779 0000A210 8A2F                <1> 	mov	ch, [edi]
   780 0000A212 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
   781 0000A215 0F86FF000000        <1> 	jna	loc_find_direntry_stc_retn 
   782 0000A21B 56                  <1> 	push	esi
   783 0000A21C 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
   784 0000A21F 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
   785 0000A222 746D                <1> 	je	short loc_find_dir_next_entry_prevdeleted
   786                              <1> 
   787 0000A224 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
   788 0000A227 7505                <1> 	jne     short loc_check_attributes_mask
   789 0000A229 E8ED010000          <1> 	call	save_longname_sub_component
   790                              <1> 
   791                              <1> loc_check_attributes_mask:
   792 0000A22E 88C6                <1> 	mov	dh, al
   793 0000A230 20D6                <1> 	and	dh, dl    
   794 0000A232 38F0                <1> 	cmp	al, dh
   795 0000A234 0F85BA000000        <1>         jne     loc_find_dir_next_entry
   796 0000A23A 20D4                <1> 	and	ah, dl
   797 0000A23C 0F85B2000000        <1>         jnz     loc_find_dir_next_entry
   798 0000A242 80FA0F              <1> 	cmp	dl, 0Fh
   799 0000A245 751A                <1> 	jne	short pass_direntry_attr_check
   800                              <1> 
   801 0000A247 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
   802 0000A249 0F85A5000000        <1>         jne     loc_find_dir_next_entry
   803                              <1> 
   804 0000A24F 5E                  <1> 	pop	esi
   805 0000A250 6631C0              <1> 	xor	ax, ax
   806 0000A253 8A35[60610100]      <1> 	mov	dh, [PreviousAttr]
   807 0000A259 66891D[8D600100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   808 0000A260 C3                  <1> 	retn
   809                              <1> 
   810                              <1> pass_direntry_attr_check:
   811 0000A261 89FD                <1> 	mov	ebp, edi ; 14/02/2016
   812 0000A263 B908000000          <1> 	mov	ecx, 8
   813                              <1> loc_lodsb_find_dir:
   814 0000A268 AC                  <1> 	lodsb
   815 0000A269 3C2A                <1> 	cmp	al, '*'
   816 0000A26B 7508                <1> 	jne	short pass_fde_ambiguous1_check
   817 0000A26D FE05[5F610100]      <1>         inc     byte [AmbiguousFileName+1]
   818 0000A273 EB28                <1> 	jmp	short loc_check_direntry_extension
   819                              <1> 
   820                              <1> pass_fde_ambiguous1_check:
   821 0000A275 3C3F                <1> 	cmp	al, '?'
   822 0000A277 750D                <1> 	jne	short pass_fde_ambiguous2_check
   823 0000A279 FE05[5E610100]      <1> 	inc	byte [AmbiguousFileName]
   824 0000A27F 803F20              <1> 	cmp	byte [edi], 20h
   825 0000A282 764E                <1> 	jna	short loc_find_dir_next_entry_ebp
   826 0000A284 EB14                <1> 	jmp	short loc_scasb_find_dir_inc_di
   827                              <1> 
   828                              <1> pass_fde_ambiguous2_check:
   829 0000A286 3C20                <1> 	cmp	al, 20h
   830 0000A288 750C                <1> 	jne	short loc_scasb_find_dir
   831 0000A28A 803F20              <1> 	cmp	byte [edi], 20h
   832 0000A28D 7543                <1> 	jne	short loc_find_dir_next_entry_ebp
   833 0000A28F EB0C                <1> 	jmp	short loc_check_direntry_extension
   834                              <1> 
   835                              <1> loc_find_dir_next_entry_prevdeleted:
   836 0000A291 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
   837 0000A294 EB5E                <1> 	jmp	short loc_find_dir_next_entry
   838                              <1> 
   839                              <1> loc_scasb_find_dir:
   840 0000A296 3A07                <1> 	cmp	al, [edi]
   841 0000A298 7538                <1> 	jne	short loc_find_dir_next_entry_ebp
   842                              <1> loc_scasb_find_dir_inc_di:
   843 0000A29A 47                  <1> 	inc	edi
   844 0000A29B E2CB                <1> 	loop	loc_lodsb_find_dir
   845                              <1> 
   846                              <1> loc_check_direntry_extension:
   847 0000A29D BE08000000          <1> 	mov	esi, 8
   848 0000A2A2 89F7                <1> 	mov	edi, esi ; 8
   849 0000A2A4 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
   850 0000A2A7 01EF                <1> 	add	edi, ebp
   851 0000A2A9 B103                <1> 	mov	cl, 3
   852                              <1> loc_lodsb_find_dir_ext:
   853 0000A2AB AC                  <1> 	lodsb
   854 0000A2AC 3C2A                <1> 	cmp	al, '*'
   855 0000A2AE 7508                <1> 	jne	short pass_fde_ambiguous3_check
   856 0000A2B0 FE05[5F610100]      <1> 	inc	byte [AmbiguousFileName+1]
   857 0000A2B6 EB1E                <1> 	jmp	short loc_find_dir_proper_direntry
   858                              <1> 
   859                              <1> pass_fde_ambiguous3_check:
   860 0000A2B8 3C3F                <1> 	cmp	al, '?'
   861 0000A2BA 750D                <1> 	jne	short pass_fde_ambiguous4_check
   862 0000A2BC FE05[5E610100]      <1> 	inc	byte [AmbiguousFileName]
   863 0000A2C2 803F20              <1> 	cmp	byte [edi], 20h
   864 0000A2C5 760B                <1> 	jna	short loc_find_dir_next_entry_ebp
   865 0000A2C7 EB49                <1> 	jmp	short loc_scasb_find_dir_ext_inc_di
   866                              <1> 
   867                              <1> pass_fde_ambiguous4_check:
   868 0000A2C9 3C20                <1> 	cmp	al, 20h
   869 0000A2CB 7541                <1> 	jne	short loc_scasb_find_dir_ext
   870 0000A2CD 803F20              <1> 	cmp	byte [edi], 20h
   871 0000A2D0 7404                <1> 	je	short loc_find_dir_proper_direntry
   872                              <1> 
   873                              <1> loc_find_dir_next_entry_ebp:
   874 0000A2D2 89EF                <1> 	mov	edi, ebp ; 14/02/2016
   875 0000A2D4 EB1E                <1> 	jmp	short loc_find_dir_next_entry
   876                              <1> 
   877                              <1> loc_find_dir_proper_direntry:
   878 0000A2D6 30C9                <1> 	xor	cl, cl
   879                              <1> loc_find_dir_proper_direntry_1:
   880 0000A2D8 5E                  <1> 	pop	esi
   881 0000A2D9 89EF                <1>         mov     edi, ebp
   882 0000A2DB 8A2F                <1> 	mov	ch, [edi]
   883 0000A2DD 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
   884 0000A2E0 66A1[5E610100]      <1> 	mov	ax, [AmbiguousFileName]
   885                              <1> loc_find_dir_proper_direntry_2:
   886 0000A2E6 8A35[60610100]      <1> 	mov     dh, [PreviousAttr]
   887 0000A2EC 66891D[8D600100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   888 0000A2F3 C3                  <1> 	retn
   889                              <1> 
   890                              <1> loc_find_dir_next_entry:
   891 0000A2F4 8815[60610100]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
   892                              <1> loc_find_dir_next_entry_1:
   893 0000A2FA 5E                  <1> 	pop	esi
   894 0000A2FB 83C720              <1> 	add	edi, 32
   895                              <1> 	;inc	word [DirBuff_EntryCounter]
   896 0000A2FE 6643                <1> 	inc	bx
   897 0000A300 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   898 0000A307 770E                <1> 	ja	short loc_ffde_stc_retn_255
   899 0000A309 E9FCFEFFFF          <1>         jmp     check_find_dir_entry 
   900                              <1> 
   901                              <1> loc_scasb_find_dir_ext:
   902 0000A30E 3A07                <1> 	cmp	al, [edi]
   903 0000A310 75C0                <1> 	jne	short loc_find_dir_next_entry_ebp
   904                              <1> loc_scasb_find_dir_ext_inc_di:
   905 0000A312 47                  <1> 	inc	edi
   906 0000A313 E296                <1> 	loop    loc_lodsb_find_dir_ext
   907 0000A315 EBC1                <1> 	jmp	short loc_find_dir_proper_direntry_1
   908                              <1> 
   909                              <1> loc_ffde_stc_retn_255:
   910                              <1> 	;mov	cx, 0FFFFh
   911 0000A317 31C9                <1> 	xor	ecx, ecx
   912 0000A319 49                  <1> 	dec	ecx ; 0FFFFFFFFh
   913                              <1> 	;xor	eax, eax
   914                              <1> loc_find_direntry_stc_retn:
   915                              <1> loc_check_ffde_retn_1:
   916                              <1> 	;mov	ax, 2
   917 0000A31A B802000000          <1> 	mov	eax, 2 ; File Not Found
   918 0000A31F 8A35[60610100]      <1> 	mov	dh, [PreviousAttr]
   919 0000A325 66891D[8D600100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   920 0000A32C F9                  <1> 	stc
   921 0000A32D C3                  <1> 	retn
   922                              <1> 
   923                              <1> loc_find_free_deleted_entry_0:
   924 0000A32E 66A1[5C610100]      <1> 	mov	ax, [FDE_AttrMask]
   925 0000A334 8A2F                <1> 	mov	ch, [edi]
   926 0000A336 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
   927 0000A339 08C9                <1> 	or	cl, cl 
   928 0000A33B 7407                <1> 	jz	short loc_check_ffde_0_repeat
   929                              <1> 	;cmp	cl, 0E5h
   930                              <1> 	;je	short pass_loc_check_ffde_0_err
   931 0000A33D 80F9FF              <1> 	cmp	cl, 0FFh
   932 0000A340 7432                <1> 	je	short loc_find_free_deleted_entry_1
   933 0000A342 EB4D                <1> 	jmp	short pass_loc_check_ffde_0_err
   934                              <1> 
   935                              <1> loc_check_ffde_0_repeat:
   936 0000A344 08ED                <1> 	or	ch, ch
   937 0000A346 7511                <1> 	jnz	short loc_check_ffde_0_next
   938                              <1> 
   939                              <1> loc_check_ffde_retn_2:
   940 0000A348 6629C0              <1> 	sub	ax, ax
   941 0000A34B 8A35[60610100]      <1> 	mov	dh, [PreviousAttr]
   942 0000A351 66891D[8D600100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   943 0000A358 C3                  <1> 	retn
   944                              <1>  
   945                              <1> loc_check_ffde_0_next:
   946 0000A359 6643                <1> 	inc	bx
   947 0000A35B 83C720              <1> 	add	edi, 32
   948                              <1> 	;inc	word [DirBuff_EntryCounter]
   949                              <1> 	 
   950 0000A35E 663B1D[8F600100]    <1>         cmp	bx, [DirBuff_LastEntry]
   951 0000A365 77B0                <1> 	ja	short loc_ffde_stc_retn_255
   952 0000A367 8815[60610100]      <1> 	mov	[PreviousAttr], dl
   953 0000A36D 8A2F                <1> 	mov	ch, [edi]
   954 0000A36F 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
   955 0000A372 EBD0                <1> 	jmp	short loc_check_ffde_0_repeat
   956                              <1> 
   957                              <1> loc_find_free_deleted_entry_1:
   958 0000A374 28D2                <1> 	sub	dl, dl      
   959                              <1> loc_find_free_deleted_entry_2:
   960 0000A376 20ED                <1> 	and	ch, ch  
   961 0000A378 74CE                <1> 	jz	short loc_check_ffde_retn_2
   962 0000A37A 80FDE5              <1> 	cmp	ch, 0E5h
   963 0000A37D 74C9                <1> 	je	short loc_check_ffde_retn_2
   964 0000A37F 6643                <1> 	inc	bx
   965 0000A381 83C720              <1> 	add	edi, 32
   966 0000A384 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   967 0000A38B 778A                <1> 	ja	short loc_ffde_stc_retn_255
   968 0000A38D 8A2F                <1> 	mov	ch, [edi]
   969 0000A38F EBE5                <1> 	jmp	short loc_find_free_deleted_entry_2
   970                              <1> 
   971                              <1> pass_loc_check_ffde_0_err:
   972 0000A391 38CD                <1> 	cmp	ch, cl
   973 0000A393 741F                <1> 	je	short loc_check_ffde_attrib 
   974                              <1> 
   975 0000A395 6643                <1> 	inc	bx
   976 0000A397 83C720              <1> 	add	edi, 32
   977 0000A39A 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   978 0000A3A1 0F8770FFFFFF        <1>         ja      loc_ffde_stc_retn_255
   979 0000A3A7 8815[60610100]      <1> 	mov	[PreviousAttr], dl
   980 0000A3AD 8A2F                <1> 	mov	ch, [edi]
   981 0000A3AF 8A570B              <1> 	mov	dl, [edi+0Bh]
   982 0000A3B2 EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
   983                              <1> 
   984                              <1> loc_check_ffde_attrib:
   985 0000A3B4 88C6                <1> 	mov	dh, al
   986 0000A3B6 20D6                <1> 	and	dh, dl    
   987 0000A3B8 38F0                <1> 	cmp	al, dh
   988 0000A3BA 759D                <1> 	jne	short loc_check_ffde_0_next
   989 0000A3BC 20D4                <1> 	and	ah, dl
   990 0000A3BE 7599                <1> 	jnz	short loc_check_ffde_0_next
   991 0000A3C0 30C9                <1> 	xor	cl, cl 
   992 0000A3C2 EB84                <1>         jmp     loc_check_ffde_retn_2
   993                              <1> 
   994                              <1> convert_file_name:
   995                              <1> 	; 06/03/2016
   996                              <1> 	; 11/02/2016
   997                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
   998                              <1> 	; 06/10/2009
   999                              <1> 	; 2005
  1000                              <1> 	;
  1001                              <1> 	; INPUT  ->
  1002                              <1> 	;	ESI = Dot File Name Location
  1003                              <1> 	;	EDI = Dir Entry Format File Name Location
  1004                              <1> 	; OUTPUT ->
  1005                              <1> 	;	EDI = Dir Entry Format File Name Location
  1006                              <1> 	;	ESI = Dot File Name Location (capitalized)
  1007                              <1> 	;
  1008                              <1> 	; (ECX, AL will be changed) 
  1009                              <1>      
  1010 0000A3C4 56                  <1> 	push	esi  
  1011 0000A3C5 57                  <1> 	push	edi
  1012                              <1> 
  1013 0000A3C6 B90B000000          <1> 	mov	ecx, 11
  1014 0000A3CB B020                <1> 	mov	al, 20h
  1015 0000A3CD F3AA                <1> 	rep	stosb
  1016                              <1> 
  1017 0000A3CF 8B3C24              <1> 	mov	edi, [esp]
  1018                              <1> 
  1019 0000A3D2 B10C                <1> 	mov	cl, 12 ; file name length (max.)
  1020                              <1> 	; 06/03/2016
  1021                              <1> 	; Directory entry name limit (11 bytes) check for
  1022                              <1> 	; 'rename_directory_entry' procedure.
  1023                              <1> 	; (EDI points to Directory Entry)
  1024                              <1> 	; (If the file name would not contain a dot
  1025                              <1> 	; and file name length would be 12, this would cause to
  1026                              <1> 	; overwrite the attributes byte of the directory entry.)
  1027                              <1> 	;
  1028 0000A3D4 B50B                <1> 	mov	ch, 11 ; directory entry's name length
  1029                              <1> loc_check_first_dot:
  1030 0000A3D6 8A06                <1> 	mov	al, [esi]
  1031 0000A3D8 3C2E                <1> 	cmp	al, 2Eh
  1032 0000A3DA 750C                <1> 	jne	short pass_check_first_dot
  1033 0000A3DC 8807                <1> 	mov	[edi], al
  1034 0000A3DE 47                  <1> 	inc	edi
  1035 0000A3DF 46                  <1> 	inc	esi
  1036 0000A3E0 FEC9                <1> 	dec	cl
  1037 0000A3E2 75F2                <1> 	jnz	short loc_check_first_dot
  1038                              <1> 	;;(ecx <= 12)
  1039                              <1> 	;;loop	loc_check_first_dot 
  1040 0000A3E4 EB30                <1> 	jmp	short stop_convert_file
  1041                              <1> 
  1042                              <1> loc_get_fchar:
  1043 0000A3E6 8A06                <1> 	mov	al, [esi]
  1044                              <1> pass_check_first_dot:
  1045 0000A3E8 3C61                <1> 	cmp	al, 61h ; 'a'
  1046 0000A3EA 7208                <1> 	jb	short pass_name_capitalize
  1047 0000A3EC 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  1048 0000A3EE 7704                <1> 	ja	short pass_name_capitalize
  1049 0000A3F0 24DF                <1> 	and	al, 0DFh
  1050 0000A3F2 8806                <1> 	mov	[esi], al
  1051                              <1> pass_name_capitalize:
  1052 0000A3F4 3C21                <1> 	cmp	al, 21h
  1053 0000A3F6 721E                <1> 	jb	short stop_convert_file
  1054 0000A3F8 3C2E                <1> 	cmp	al, 2Eh ; '.'
  1055 0000A3FA 750C                <1> 	jne	short pass_dot_space
  1056                              <1> add_dot_space: 
  1057 0000A3FC 80F904              <1> 	cmp	cl, 4
  1058 0000A3FF 760E                <1> 	jna	short inc_and_loop
  1059 0000A401 47                  <1> 	inc	edi
  1060 0000A402 FECD                <1> 	dec	ch ; 06/03/2016
  1061 0000A404 FEC9                <1> 	dec	cl
  1062 0000A406 EBF4                <1> 	jmp	short add_dot_space
  1063                              <1> 	
  1064                              <1> 	;mov	al, 4
  1065                              <1> 	;cmp	cl, al
  1066                              <1> 	;jna	short inc_and_loop
  1067                              <1> 	;sub	cl, al
  1068                              <1> 	;add	edi, ecx
  1069                              <1> 	;mov	cl, al
  1070                              <1> 	;jmp	short inc_and_loop	
  1071                              <1> 
  1072                              <1> pass_dot_space:
  1073 0000A408 8807                <1> 	mov	[edi], al
  1074                              <1> loc_after_double_dot:
  1075                              <1> 	; 06/03/2016
  1076 0000A40A FECD                <1> 	dec	ch ; count down for 11 bytes dir entry limit
  1077 0000A40C 740A                <1> 	jz	short stop_convert_file_x
  1078 0000A40E 47                  <1> 	inc	edi
  1079                              <1> inc_and_loop:
  1080 0000A40F FEC9                <1> 	dec	cl ; count down for 12 bytes filename limit 
  1081 0000A411 7403                <1> 	jz	short stop_convert_file	
  1082 0000A413 46                  <1> 	inc	esi
  1083                              <1> 	;;(ecx <= 12)
  1084                              <1> 	;;loop	loc_get_fchar
  1085 0000A414 EBD0                <1> 	jmp	short loc_get_fchar
  1086                              <1> 
  1087                              <1> stop_convert_file:
  1088                              <1> 	; 06/03/2016
  1089 0000A416 30ED                <1> 	xor	ch, ch
  1090                              <1> 	; ECX < 256 ; 'find_first_file' -> xor cl, cl
  1091                              <1> stop_convert_file_x:
  1092 0000A418 5F                  <1> 	pop	edi
  1093 0000A419 5E                  <1> 	pop	esi
  1094 0000A41A C3                  <1> 	retn
  1095                              <1>  
  1096                              <1> save_longname_sub_component:
  1097                              <1> 	; 13/02/2016
  1098                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
  1099                              <1> 	; 28/02/2010
  1100                              <1> 	; 17/10/2009
  1101                              <1> 	; INPUT ->
  1102                              <1> 	;	EDI = Directory Entry    
  1103                              <1> 	;     	// This procedure is called
  1104                              <1> 	;	// from 'find_directory_entry' procedure.
  1105                              <1> 	;	// If the last entry returns with
  1106                              <1> 	;	// a non-zero LongnameFound value and
  1107                              <1> 	;	// if LFN_CheckSum value is equal to
  1108                              <1> 	;	// the next shortname checksum,
  1109                              <1> 	;	// long name is valid.
  1110                              <1> 	;	// If a longname is longer than 65 bytes,
  1111                              <1> 	;	// it is invalid for trdos. (>45h)
  1112                              <1>  
  1113 0000A41B 57                  <1> 	push	edi
  1114 0000A41C 56                  <1> 	push	esi
  1115                              <1> 	;push	ebx
  1116                              <1> 	;push	ecx
  1117                              <1> 	;push	edx
  1118 0000A41D 50                  <1> 	push	eax
  1119                              <1>            
  1120 0000A41E 29C9                <1> 	sub	ecx, ecx
  1121                              <1> 	;sub	eax, eax
  1122 0000A420 B11A                <1> 	mov	cl, 26
  1123                              <1> 
  1124 0000A422 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
  1125 0000A425 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
  1126 0000A427 722B                <1> 	jb	short pass_pslnsc_last_long_entry
  1127                              <1> 
  1128 0000A429 88C4                <1> 	mov	ah, al
  1129 0000A42B 80EC40              <1> 	sub	ah, 40h
  1130 0000A42E 8825[62610100]      <1> 	mov	[LFN_EntryLength], ah
  1131                              <1> 	
  1132 0000A434 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
  1133                              <1>  		; Max 130 byte length is usable in TRDOS
  1134                              <1> ; 26*5 = 130
  1135 0000A436 7753                <1> 	ja	short loc_pslnsc_retn
  1136                              <1> 
  1137 0000A438 2407                <1> 	and	al, 07h ; 0Fh
  1138 0000A43A A2[61610100]        <1> 	mov	[LongNameFound], al
  1139                              <1> 
  1140 0000A43F FEC8                <1> 	dec	al
  1141                              <1> 	;mov	cl, 26
  1142 0000A441 F6E1                <1> 	mul	cl
  1143                              <1> 
  1144 0000A443 89C6                <1> 	mov	esi, eax
  1145 0000A445 01CE                <1> 	add	esi, ecx
  1146                              <1> 		; to make is an ASCIIZ string
  1147                              <1> 		; with ax+26 bytes length
  1148 0000A447 81C6[64610100]      <1> 	add	esi, LongFileName
  1149 0000A44D 66C7060000          <1> 	mov	word [esi], 0   
  1150 0000A452 EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2 
  1151                              <1> 
  1152                              <1> pass_pslnsc_last_long_entry:
  1153 0000A454 3C04                <1> 	cmp	al, 04h
  1154 0000A456 7733                <1> 	ja	short loc_pslnsc_retn
  1155 0000A458 FE0D[61610100]      <1> 	dec	byte [LongNameFound]
  1156 0000A45E 3A05[61610100]      <1> 	cmp	al, [LongNameFound]
  1157 0000A464 7525                <1> 	jne	short loc_pslnsc_retn
  1158                              <1> 
  1159                              <1> loc_pslsc_move_ldir_name1:
  1160 0000A466 FEC8                <1> 	dec	al
  1161                              <1> 	;mov	cl, 26
  1162 0000A468 F6E1                <1> 	mul	cl
  1163                              <1> 
  1164                              <1> loc_pslsc_move_ldir_name2:
  1165 0000A46A 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
  1166 0000A46D 880D[63610100]      <1> 	mov	[LFN_CheckSum], cl 
  1167 0000A473 89FE                <1> 	mov	esi, edi ; LDIR_Order
  1168 0000A475 BF[64610100]        <1> 	mov	edi, LongFileName
  1169 0000A47A 01C7                <1> 	add	edi, eax
  1170 0000A47C 46                  <1> 	inc	esi
  1171 0000A47D B105                <1> 	mov	cl, 5 ; chars 1 to 5
  1172 0000A47F F366A5              <1> 	rep	movsw
  1173 0000A482 83C603              <1> 	add	esi, 3
  1174 0000A485 A5                  <1> 	movsd	; char 6 & 7 
  1175 0000A486 A5                  <1> 	movsd	; char 8 & 9
  1176 0000A487 A5                  <1> 	movsd	; char 10 & 11
  1177 0000A488 46                  <1> 	inc	esi
  1178 0000A489 46                  <1> 	inc	esi 
  1179 0000A48A A5                  <1> 	movsd   ; char 12 & 13 
  1180                              <1> 
  1181                              <1> loc_pslnsc_retn:
  1182 0000A48B 58                  <1>  	pop	eax
  1183                              <1> 	;pop	edx
  1184                              <1> 	;pop	ecx
  1185                              <1> 	;pop	ebx
  1186 0000A48C 5E                  <1> 	pop	esi  
  1187 0000A48D 5F                  <1> 	pop	edi
  1188                              <1>  
  1189 0000A48E C3                  <1>     	retn
  1190                              <1> 
  1191                              <1> parse_path_name:
  1192                              <1> 	; 10/02/2016
  1193                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  1194                              <1> 	; 10/009/2011 ('proc_parse_pathname')
  1195                              <1> 	; 27/11/2009
  1196                              <1> 	; 05/12/2004
  1197                              <1> 	;
  1198                              <1> 	; INPUT ->
  1199                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
  1200                              <1> 	;       EDI = Destination Address
  1201                              <1> 	;	      (which is TR-DOS FindFile data buffer)
  1202                              <1> 	; OUTPUT ->
  1203                              <1> 	;	CF = 1 -> Error
  1204                              <1> 	;	     EAX = Error Code (AL)
  1205                              <1> 	;
  1206                              <1> 	; (Modified registers: eax, ecx, esi, edi) 
  1207                              <1> 	
  1208                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer 
  1209 0000A48F 57                  <1> 	push	edi
  1210 0000A490 B914000000          <1> 	mov	ecx, 20  ; 80 bytes
  1211 0000A495 31C0                <1> 	xor	eax, eax
  1212 0000A497 F3AB                <1> 	rep	stosd 
  1213 0000A499 5F                  <1> 	pop	edi
  1214                              <1> 
  1215 0000A49A 668B06              <1> 	mov	ax, [esi]
  1216 0000A49D 80FC3A              <1> 	cmp	ah, ':'
  1217 0000A4A0 741C                <1> 	je	short loc_ppn_change_drive
  1218 0000A4A2 A0[6E590100]        <1> 	mov	al, [Current_Drv]
  1219 0000A4A7 EB33                <1> 	jmp	short pass_ppn_change_drive
  1220                              <1> 
  1221                              <1> pass_ppn_cdir:
  1222 0000A4A9 8B35[86620100]      <1> 	mov	esi, [First_Path_Pos]
  1223 0000A4AF AC                  <1> 	lodsb
  1224                              <1> loc_ppn_get_filename:
  1225 0000A4B0 83C741              <1> 	add	edi, 65 ; FindFile_Name location
  1226                              <1> 	; TRDOS Filename length must not be more than 12 bytes
  1227                              <1> 	;mov	ecx, 12
  1228 0000A4B3 B10C                <1> 	mov	cl, 12
  1229                              <1> loc_ppn_get_fnchar_next:
  1230 0000A4B5 AA                  <1> 	stosb
  1231 0000A4B6 AC                  <1> 	lodsb
  1232 0000A4B7 3C21                <1> 	cmp	al, 21h
  1233 0000A4B9 7274                <1> 	jb	short loc_ppn_clc_return 
  1234 0000A4BB E2F8                <1>         loop    loc_ppn_get_fnchar_next
  1235                              <1> loc_ppn_return:
  1236 0000A4BD C3                  <1> 	retn
  1237                              <1> 
  1238                              <1> loc_ppn_change_drive:
  1239 0000A4BE 24DF                <1> 	and	al, 0DFh
  1240 0000A4C0 2C41                <1> 	sub	al, 'A'; A:
  1241 0000A4C2 726F                <1> 	jc	short loc_ppn_invalid_drive
  1242 0000A4C4 3805[3A0D0100]      <1> 	cmp	[Last_DOS_DiskNo], al
  1243 0000A4CA 7267                <1> 	jb	short loc_ppn_invalid_drive
  1244                              <1> 
  1245 0000A4CC 46                  <1> 	inc	esi
  1246 0000A4CD 46                  <1> 	inc	esi
  1247 0000A4CE 8A26                <1> 	mov	ah, [esi]
  1248 0000A4D0 80FC21              <1> 	cmp	ah, 21h
  1249 0000A4D3 7307                <1> 	jnb	short pass_ppn_change_drive
  1250                              <1> 
  1251                              <1> loc_ppn_cmd_failed:
  1252                              <1> 	; File or directory name is not existing
  1253 0000A4D5 8807                <1> 	mov	[edi], al ; Drv 
  1254 0000A4D7 66B80100            <1> 	mov	ax, 1 ; eax = 1
  1255                              <1> 	; TR-DOS Error Code 01h = Bad Command Argument
  1256                              <1> 	; MS-DOS Error Code 01h : Invalid Function Number
  1257                              <1> 	;stc
  1258                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
  1259 0000A4DB C3                  <1> 	retn
  1260                              <1> 
  1261                              <1> pass_ppn_change_drive:
  1262 0000A4DC 8935[86620100]      <1> 	mov	[First_Path_Pos], esi
  1263 0000A4E2 C705[8A620100]0000- <1> 	mov	dword [Last_Slash_Pos], 0
  1263 0000A4EA 0000                <1>
  1264 0000A4EC AA                  <1> 	stosb
  1265 0000A4ED 8A06                <1> 	mov	al, [esi]
  1266                              <1> loc_scan_ppn_dslash:
  1267 0000A4EF 3C2F                <1> 	cmp	al, '/'
  1268 0000A4F1 7506                <1>   	jne	short loc_scan_next_slash_pos
  1269 0000A4F3 8935[8A620100]      <1> 	mov	[Last_Slash_Pos], esi
  1270                              <1> loc_scan_next_slash_pos:
  1271 0000A4F9 46                  <1> 	inc	esi
  1272 0000A4FA 8A06                <1> 	mov	al, [esi]
  1273 0000A4FC 3C20                <1> 	cmp	al, 20h
  1274 0000A4FE 77EF                <1> 	ja	short loc_scan_ppn_dslash
  1275 0000A500 833D[8A620100]00    <1> 	cmp	dword [Last_Slash_Pos], 0
  1276 0000A507 76A0                <1> 	jna	short pass_ppn_cdir
  1277                              <1> 	
  1278 0000A509 8B0D[8A620100]      <1> 	mov	ecx, [Last_Slash_Pos]
  1279 0000A50F 8B35[86620100]      <1> 	mov	esi, [First_Path_Pos]
  1280 0000A515 29F1                <1> 	sub	ecx, esi
  1281 0000A517 41                  <1> 	inc	ecx
  1282                              <1> 	;cmp	ecx, 64
  1283 0000A518 80F940              <1> 	cmp	cl, 64
  1284 0000A51B 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
  1285                              <1> 
  1286 0000A51D 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 byte)
  1287 0000A51F F3A4                <1> 	rep	movsb
  1288                              <1> 	;mov	[edi], cl ; 0, End of Dir String
  1289 0000A521 8B35[8A620100]      <1> 	mov	esi, [Last_Slash_Pos]
  1290 0000A527 46                  <1> 	inc	esi
  1291 0000A528 89C7                <1> 	mov	edi, eax
  1292 0000A52A AC                  <1> 	lodsb
  1293 0000A52B 3C21                <1> 	cmp	al, 21h
  1294 0000A52D 7381                <1> 	jnb	short loc_ppn_get_filename
  1295                              <1> loc_ppn_clc_return:
  1296                              <1> 	;clc
  1297 0000A52F 31C0                <1> 	xor	eax, eax
  1298 0000A531 C3                  <1> 	retn
  1299                              <1> 
  1300                              <1> loc_ppn_invalid_drive_stc:
  1301 0000A532 F5                  <1> 	cmc	 ; stc
  1302                              <1> loc_ppn_invalid_drive:
  1303                              <1> 	; cf = 1
  1304                              <1> 	; The Drive Letter/Char < "A" or > "Z"
  1305 0000A533 66B80F00            <1> 	mov	ax, 0Fh
  1306                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
  1307                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
  1308 0000A537 C3                  <1> 	retn
  1309                              <1> 
  1310                              <1> find_longname:
  1311                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1312                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
  1313                              <1> 	; 17/10/2009
  1314                              <1> 	
  1315                              <1> 	; INPUT -> 
  1316                              <1> 	;	ESI = DOS short file name address
  1317                              <1> 	; 	for example: "filename.ext"
  1318                              <1> 	;
  1319                              <1> 	; OUTPUT ->
  1320                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
  1321                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
  1322                              <1> 	;	AL = 0 & CF=1 -> longname not found
  1323                              <1> 	;	     the file/directory has no longname
  1324                              <1> 	; 	cf = 0 -> AL = FAT Type 
  1325                              <1>  
  1326                              <1> 	; 17/10/2009
  1327                              <1> 	; ASCIIZ string will be returned
  1328                              <1> 	; as LongFileName
  1329                              <1> 	; clearing/reset is not needed
  1330                              <1> 	;mov	ecx, 33
  1331                              <1> 	;mov	edi, LongFileName
  1332                              <1> 	;sub	ax, ax ; 0
  1333                              <1> 	;rep	stosw
  1334                              <1> 
  1335                              <1> 	;mov	byte [LongNameFound], 0
  1336                              <1> 
  1337                              <1> 	; ESI = ASCIIZ file/directory name address
  1338                              <1> 	;   AL = Attributes AND mask 
  1339                              <1> 	;	(Result of AND must be equal to AL)
  1340                              <1> 	;   AH = Negative attributes mask 
  1341                              <1> 	;	(Result of AND must be ZERO)
  1342 0000A538 66B80008            <1> 	mov	ax, 0800h 
  1343                              <1> 		; it must not be volume name or longname
  1344 0000A53C E87DDDFFFF          <1> 	call	find_first_file
  1345 0000A541 7216                <1> 	jc	short loc_fln_retn
  1346                              <1>  
  1347                              <1> loc_fln_check_FAT_Type:
  1348 0000A543 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
  1349 0000A54A 7306                <1> 	jnb	short loc_fln_check_longname_yes_sign
  1350                              <1> 
  1351 0000A54C E839000000          <1> 	call	get_fs_longname
  1352 0000A551 C3                  <1> 	retn
  1353                              <1> 
  1354                              <1> loc_fln_check_longname_yes_sign:
  1355 0000A552 08FF                <1> 	or	bh, bh
  1356 0000A554 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
  1357                              <1> loc_fln_longname_not_found_retn:
  1358 0000A556 31C0                <1> 	xor	eax, eax 
  1359                              <1> 	; cf = 1 & al = 0 -> longname not found
  1360 0000A558 F9                  <1> 	stc
  1361                              <1> loc_fln_retn:
  1362 0000A559 C3                  <1> 	retn
  1363                              <1> 
  1364                              <1> loc_fln_check_longnamefound_number:
  1365                              <1> 	; 'LongNameFound' is set by
  1366                              <1>         ; by 'save_longname_sub_component'
  1367                              <1> 	; which is called from
  1368                              <1> 	; 'find_directory_entry' 
  1369                              <1> 	; which is called from 
  1370                              <1> 	; 'find_first_file'
  1371                              <1> 	; It must 1 if the longname is valid
  1372 0000A55A 803D[61610100]01    <1>         cmp     byte [LongNameFound], 1
  1373 0000A561 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
  1374                              <1>              
  1375                              <1> loc_fln_calculate_checksum: 
  1376 0000A563 E813000000          <1> 	call	calculate_checksum
  1377                              <1> 	; AL = shortname checksum
  1378                              <1> 
  1379                              <1> loc_fln_longname_validation:
  1380                              <1> 	; 'LFN_CheckSum' has been set already
  1381                              <1> 	; by 'save_longname_sub_component'
  1382                              <1> 	; which is called from
  1383                              <1> 	; 'find_directory_entry' 
  1384                              <1> 	; which is called from 
  1385                              <1> 	; 'find_first_file'
  1386 0000A568 3805[63610100]      <1> 	cmp	[LFN_CheckSum], al
  1387 0000A56E 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
  1388                              <1> 
  1389 0000A570 BE[64610100]        <1> 	mov	esi, LongFileName
  1390 0000A575 A0[6D590100]        <1> 	mov	al, [Current_FATType]
  1391 0000A57A C3                  <1> 	retn
  1392                              <1> 
  1393                              <1> calculate_checksum:
  1394                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1395                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
  1396                              <1>         ;    
  1397                              <1> 	; INPUT ->
  1398                              <1> 	;	ESI = 11 byte DOS File Name location
  1399                              <1> 	;	(in DOS Directory Entry Format)
  1400                              <1> 	; OUTPUT ->
  1401                              <1> 	;	 AL = 8 bit checksum (CRC) value
  1402                              <1> 	;
  1403                              <1> 	; (Modified registers: EAX, ECX, ESI)
  1404                              <1> 
  1405                              <1> 	; Erdogan Tan [ 17-10-2009 ]
  1406                              <1> 	;  'ror al, 1' instruction
  1407                              <1> 
  1408                              <1> 	; Erdogan Tan [ 20-06-2004 ]
  1409                              <1> 	; This 8086 assembly code is an original code
  1410                              <1> 	; which is adapted from C code in
  1411                              <1> 	; Microsoft FAT32 File System Specification
  1412                              <1> 	; Version 1.03, December 6, 2000
  1413                              <1> 	; Page 28
  1414                              <1> 
  1415 0000A57B 30C0                <1> 	xor	al, al
  1416 0000A57D B90B000000          <1> 	mov	ecx, 11
  1417                              <1> loc_next_sum:
  1418                              <1> 	;xor	ah, ah
  1419                              <1> 	;test	al, 1
  1420                              <1> 	;jz	short pass_ah_80h
  1421                              <1> 	;mov	ah, 80h
  1422                              <1> ;pass_ah_80h:
  1423                              <1> 	;shr	al, 1
  1424 0000A582 D0C8                <1> 	ror	al, 1 ; 17/10/2009  
  1425 0000A584 0206                <1> 	add	al, [esi]
  1426 0000A586 46                  <1> 	inc	esi
  1427                              <1> 	;add	al, ah
  1428 0000A587 E2F9                <1> 	loop	loc_next_sum
  1429 0000A589 C3                  <1> 	retn
  1430                              <1> 
  1431                              <1> get_fs_longname:
  1432                              <1> 	; temporary (13/02/2016)
  1433 0000A58A 31C0                <1> 	xor eax, eax
  1434 0000A58C F9                  <1> 	stc
  1435 0000A58D C3                  <1> 	retn
  1436                              <1> 
  1437                              <1> make_sub_directory:
  1438                              <1> 	; 16/10/2016
  1439                              <1> 	; 02/03/2016, 03/03/2016
  1440                              <1> 	; 26/02/2016, 27/02/2016
  1441                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1442                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
  1443                              <1> 	; 10/07/2010
  1444                              <1> 	; INPUT ->
  1445                              <1> 	; 	ESI = ASCIIZ Directory Name
  1446                              <1> 	;	CL = Directory Attributes
  1447                              <1> 	; OUTPUT ->
  1448                              <1> 	;	EAX = New sub dir's first cluster
  1449                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  1450                              <1> 	;	CF = 1 -> error code in AL (EAX)
  1451                              <1> 
  1452                              <1> 	;test	cl, 10h  ; directory
  1453                              <1> 	;jz	short loc_make_directory_access_denied
  1454                              <1> 	;test	cl, 08h ; volume name
  1455                              <1> 	;jnz	short loc_make_directory_access_denied
  1456                              <1> 
  1457 0000A58E 80E107              <1> 	and	cl, 07h
  1458 0000A591 880D[E0620100]      <1> 	mov	byte [mkdir_attrib], cl
  1459                              <1> 
  1460 0000A597 56                  <1> 	push	esi
  1461 0000A598 31DB                <1> 	xor	ebx, ebx
  1462 0000A59A 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  1463 0000A5A0 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1464 0000A5A5 01DE                <1> 	add	esi, ebx
  1465 0000A5A7 5B                  <1> 	pop	ebx
  1466                              <1> 
  1467                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
  1468                              <1> 	; LD_DiskType = 0 for write protection (read only) 
  1469 0000A5A8 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  1470 0000A5AC 730B                <1> 	jnb	short loc_mkdir_check_file_sytem
  1471                              <1> 	; 16/10/2016 (13h -> 30)
  1472 0000A5AE B81E000000          <1> 	mov	eax, 30 ; 'Disk write-protected' error
  1473 0000A5B3 BA00000000          <1> 	mov	edx, 0
  1474                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
  1475                              <1> 	;ESI = Logical DOS drive description table address
  1476 0000A5B8 C3                  <1> 	retn
  1477                              <1> 
  1478                              <1> ;loc_make_directory_access_denied:
  1479                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
  1480                              <1> 	;stc
  1481                              <1> 	;retn
  1482                              <1> 
  1483                              <1> loc_mkdir_check_file_sytem:
  1484 0000A5B9 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  1485 0000A5BD 730B                <1> 	jnb	short loc_mkdir_check_free_sectors
  1486                              <1> 
  1487                              <1> loc_make_fs_directory:
  1488 0000A5BF A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
  1489                              <1> 	; EAX = Parent directory DDT Address
  1490                              <1> 	; ESI = Logical DOS Drive DT Address
  1491                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
  1492 0000A5C4 E8D5150000          <1> 	call	make_fs_directory
  1493 0000A5C9 C3                  <1> 	retn
  1494                              <1> 
  1495                              <1> loc_mkdir_check_free_sectors:
  1496 0000A5CA 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
  1497 0000A5CE 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1498 0000A5D1 39C1                <1> 	cmp	ecx, eax
  1499 0000A5D3 7255                <1> 	jb	short loc_mkdir_insufficient_disk_space
  1500                              <1> 
  1501                              <1> loc_make_fat_directory:
  1502 0000A5D5 891D[D0620100]      <1> 	mov	[mkdir_DirName_Offset], ebx
  1503 0000A5DB 890D[DC620100]      <1> 	mov	[mkdir_FreeSectors], ecx
  1504                              <1> 
  1505                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
  1506 0000A5E1 A2[E2620100]        <1> 	mov	byte [mkdir_SecPerClust], al
  1507                              <1> 
  1508                              <1> loc_mkdir_gffc_1:
  1509 0000A5E6 E80F180000          <1> 	call	get_first_free_cluster
  1510 0000A5EB 722A                <1> 	jc	short loc_mkdir_gffc_retn
  1511                              <1> 
  1512                              <1> ;loc_mkdir_gffc_1_cont: 
  1513                              <1> 	;cmp	eax, 2
  1514                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1515                              <1> 
  1516                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
  1517 0000A5ED A3[D4620100]        <1> 	mov	[mkdir_FFCluster], eax
  1518                              <1> 
  1519                              <1> loc_mkdir_locate_ffe:
  1520                              <1> 	; Current directory fcluster <> Directory buffer cluster
  1521                              <1> 	; Current directory will be reloaded by
  1522                              <1> 	; 'locate_current_dir_file' procedure
  1523                              <1> 	;
  1524                              <1> 	; ESI = Logical DOS Drive Description Table Address 
  1525                              <1> 	;push	esi ; 27/02/2016
  1526 0000A5F2 31C0                <1> 	xor	eax, eax
  1527 0000A5F4 89C1                <1>         mov	ecx, eax
  1528 0000A5F6 6649                <1> 	dec	cx ; FFFFh  
  1529                              <1> 	; CX = FFFFh -> find first deleted or free entry
  1530                              <1> 	; ESI would be ASCIIZ filename address if the call
  1531                              <1> 	; would not be for first free or deleted dir entry
  1532 0000A5F8 E8D0FAFFFF          <1> 	call	locate_current_dir_file
  1533 0000A5FD 734C                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
  1534                              <1> 	;pop	esi 
  1535                              <1> 	; ESI = Logical DOS Drive Description Table Address 
  1536 0000A5FF 83F802              <1> 	cmp	eax, 2  ; cmp al, 2 ; File/Dir not found !
  1537 0000A602 752B                <1> 	jne	short loc_mkdir_stc_return
  1538                              <1> 
  1539                              <1> loc_mkdir_add_new_cluster:
  1540 0000A604 3805[6D590100]      <1> 	cmp	byte [Current_FATType], al ; 2
  1541                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
  1542 0000A60A 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
  1543 0000A60C 803D[6C590100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  1544                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  1545 0000A613 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
  1546                              <1> 
  1547 0000A615 B00C                <1> 	mov	al, 12 ; No more files 
  1548                              <1> loc_mkdir_gffc_retn:
  1549 0000A617 C3                  <1> 	retn
  1550                              <1> 
  1551                              <1> loc_mkdir_add_new_cluster_check_fsc:
  1552 0000A618 8B0D[DC620100]      <1> 	mov	ecx, [mkdir_FreeSectors]
  1553                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
  1554 0000A61E A0[E2620100]        <1> 	mov	al, [mkdir_SecPerClust]
  1555 0000A623 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
  1556 0000A626 39C1                <1> 	cmp	ecx, eax
  1557 0000A628 7350                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
  1558                              <1> 
  1559                              <1> loc_mkdir_insufficient_disk_space:
  1560                              <1> 	;mov	edx, ecx
  1561                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
  1562 0000A62A 66B82700            <1> 	mov	ax, 27h ; MSDOS err => insufficient disk space
  1563                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
  1564                              <1>         ; ESI -> Dos drive description table address
  1565                              <1> 	;; ecx = edx
  1566                              <1> 	;
  1567 0000A62E C3                  <1> 	retn
  1568                              <1> 
  1569                              <1> loc_mkdir_stc_return:
  1570 0000A62F F9                  <1> 	stc
  1571 0000A630 C3                  <1> 	retn 
  1572                              <1> 
  1573                              <1> loc_mkdir_gffc_2:
  1574 0000A631 E8C4170000          <1> 	call	get_first_free_cluster
  1575 0000A636 72DF                <1> 	jc	short loc_mkdir_gffc_retn
  1576                              <1> 
  1577                              <1> ;loc_mkdir_gffc_1_cont: 
  1578                              <1> 	;cmp	eax, 2
  1579                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1580                              <1> 
  1581                              <1> ;loc_mkdir_gffc_2_save_fcluster:  
  1582 0000A638 A3[D4620100]        <1> 	mov	[mkdir_FFCluster], eax
  1583                              <1> 
  1584 0000A63D A1[D8620100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1585                              <1> 
  1586 0000A642 E842170000          <1> 	call	load_FAT_sub_directory 
  1587 0000A647 72CE                <1> 	jc	short loc_mkdir_gffc_retn
  1588                              <1> 
  1589 0000A649 31FF                <1> 	xor	edi, edi
  1590                              <1> loc_mkdir_set_ff_dir_entry_1:
  1591                              <1> 	; 27/02/2016
  1592 0000A64B 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
  1593                              <1> 	; EDI = Directory Entry Address
  1594 0000A64C 8B35[D0620100]      <1> 	mov	esi, [mkdir_DirName_Offset]
  1595 0000A652 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1596                              <1> 
  1597 0000A657 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
  1598                              <1> 			; CH = 0 -> File size is 0
  1599 0000A65B 0A0D[E0620100]      <1> 	or	cl, [mkdir_attrib] ; S, H, R  
  1600 0000A661 E8B0010000          <1> 	call	make_directory_entry
  1601                              <1> 
  1602 0000A666 5E                  <1> 	pop	esi
  1603                              <1> 
  1604 0000A667 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1605 0000A66E E880020000          <1> 	call	save_directory_buffer
  1606 0000A673 0F83DA000000        <1>         jnc     loc_mkdir_set_ff_dir_entry_2
  1607                              <1> 
  1608                              <1> loc_mkdir_return:
  1609 0000A679 C3                  <1> 	retn
  1610                              <1> 
  1611                              <1> loc_mkdir_add_new_subdir_cluster:
  1612 0000A67A 8B15[91600100]      <1> 	mov	edx, [DirBuff_Cluster]
  1613 0000A680 8915[D8620100]      <1> 	mov	[mkdir_LastDirCluster], edx       
  1614                              <1> 
  1615 0000A686 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1616 0000A68B E8F9160000          <1> 	call	load_FAT_sub_directory 
  1617 0000A690 72E7                <1> 	jc	short loc_mkdir_return
  1618                              <1> 	; eax = 0
  1619                              <1> 	; ecx =  directory buffer sector count (<= 128)
  1620                              <1> 
  1621                              <1> pass_mkdir_add_new_subdir_cluster:
  1622 0000A692 29FF                <1> 	sub	edi, edi ; 0
  1623                              <1> 	;mov	al, 128 ; double word
  1624                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
  1625                              <1> 	;mov	ecx, eax
  1626                              <1> 	;shl	cx, 7 ; 128 * sector count	
  1627 0000A694 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1628 0000A698 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1629 0000A69C 66F7E1              <1> 	mul	cx ; max = 128*(512/4) -> 16384 (stosd)
  1630 0000A69F 6689C1              <1> 	mov	cx, ax
  1631 0000A6A2 6629C0              <1> 	sub	ax, ax ; 0
  1632 0000A6A5 F3AB                <1> 	rep	stosd ; clear directory buffer
  1633                              <1> 
  1634 0000A6A7 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1635 0000A6AE E840020000          <1> 	call	save_directory_buffer 
  1636 0000A6B3 72C4                <1> 	jc	short loc_mkdir_return
  1637                              <1> 
  1638                              <1> loc_mkdir_save_added_cluster:
  1639 0000A6B5 A1[D8620100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1640 0000A6BA 8B0D[D4620100]      <1> 	mov	ecx, [mkdir_FFCluster]
  1641                              <1> 	; 01/03/2016
  1642 0000A6C0 31D2                <1> 	xor	edx, edx
  1643 0000A6C2 8915[82600100]      <1> 	mov	[FAT_ClusterCounter], edx ; 0 ; reset
  1644 0000A6C8 E800180000          <1> 	call	update_cluster
  1645 0000A6CD 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
  1646 0000A6CF 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1647 0000A6D1 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
  1648                              <1> 
  1649                              <1> loc_mkdir_save_fat_buffer_0:
  1650 0000A6D3 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1651 0000A6D8 A3[D8620100]        <1> 	mov	[mkdir_LastDirCluster], eax
  1652                              <1> 
  1653 0000A6DD 31C9                <1> 	xor	ecx, ecx
  1654 0000A6DF 49                  <1> 	dec	ecx ; FFFFFFFFh
  1655                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1656 0000A6E0 E8E8170000          <1> 	call	update_cluster
  1657 0000A6E5 731A                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
  1658 0000A6E7 09C0                <1> 	or	eax, eax
  1659 0000A6E9 7416                <1> 	jz	short loc_mkdir_save_fat_buffer_1
  1660                              <1> 
  1661                              <1> loc_mkdir_save_fat_buffer_stc_retn:
  1662                              <1> 	; 01/03/2016
  1663 0000A6EB 803D[82600100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1664 0000A6F2 720C                <1> 	jb	short loc_mkdir_save_fat_buffer_retn
  1665                              <1> 
  1666 0000A6F4 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  1667                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  1668 0000A6F8 50                  <1> 	push	eax
  1669 0000A6F9 E8211B0000          <1> 	call	calculate_fat_freespace
  1670 0000A6FE 58                  <1> 	pop	eax
  1671 0000A6FF F9                  <1> 	stc
  1672                              <1> loc_mkdir_save_fat_buffer_retn:
  1673 0000A700 C3                  <1> 	retn
  1674                              <1> 
  1675                              <1> loc_mkdir_save_fat_buffer_1:
  1676                              <1> 	; byte [FAT_BuffValidData] = 2 
  1677 0000A701 E8841A0000          <1> 	call	save_fat_buffer
  1678 0000A706 72E3                <1> 	jc	short loc_mkdir_save_fat_buffer_stc_retn
  1679                              <1> 
  1680                              <1> 	; 01/03/2016
  1681 0000A708 803D[82600100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1682 0000A70F 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_2
  1683                              <1> 
  1684                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1685 0000A711 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1686 0000A716 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  1687 0000A71A E8001B0000          <1> 	call	calculate_fat_freespace
  1688                              <1> 
  1689                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  1690                              <1> 	;jnz	short loc_mkdir_save_fat_buffer_2
  1691                              <1> 
  1692                              <1> 	; ecx > 0 -> Recalculation is needed
  1693 0000A71F 09C9                <1> 	or	ecx, ecx 
  1694 0000A721 7409                <1> 	jz	short loc_mkdir_save_fat_buffer_2
  1695                              <1> 
  1696 0000A723 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  1697 0000A727 E8F31A0000          <1> 	call	calculate_fat_freespace
  1698                              <1> 
  1699                              <1> loc_mkdir_save_fat_buffer_2:
  1700 0000A72C C605[E3620100]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
  1701 0000A733 E9C4000000          <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
  1702                              <1> 
  1703                              <1> loc_mkdir_update_sub_dir_cluster:
  1704 0000A738 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1705 0000A73D 29C9                <1> 	sub	ecx, ecx ; 0
  1706                              <1> 	; 01/03/2016
  1707 0000A73F 890D[82600100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; Reset
  1708 0000A745 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  1709                              <1> 
  1710                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
  1711 0000A746 E882170000          <1> 	call	update_cluster
  1712 0000A74B 7379                <1> 	jnc	short loc_mkdir_save_fat_buffer_3
  1713 0000A74D 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1714 0000A74F 7475                <1> 	jz	short loc_mkdir_save_fat_buffer_3
  1715                              <1> 	; 01/03/2016
  1716 0000A751 EB98                <1> 	jmp	short loc_mkdir_save_fat_buffer_stc_retn
  1717                              <1> 
  1718                              <1> loc_mkdir_set_ff_dir_entry_2:
  1719                              <1> 	; ESI = Logical DOS Drive Description Table address  
  1720 0000A753 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1721                              <1> 	; Load disk sectors as a directory cluster
  1722 0000A758 E82C160000          <1> 	call	load_FAT_sub_directory 
  1723 0000A75D 7266                <1> 	jc	short retn_make_fat_directory
  1724                              <1> 	
  1725                              <1> 	; eax = 0
  1726                              <1> 	; ecx =  directory buffer sector count (<= 128)
  1727                              <1> 
  1728 0000A75F BF40000800          <1> 	mov	edi, Directory_Buffer + 64 ; 26/02/2016
  1729                              <1> 
  1730                              <1> 	; 02/03/2016
  1731 0000A764 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1732 0000A768 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1733 0000A76C F7E1                <1> 	mul 	ecx
  1734 0000A76E 89C1                <1> 	mov	ecx, eax
  1735 0000A770 6629C0              <1> 	sub	ax, ax
  1736 0000A773 F3AB                <1> 	rep	stosd
  1737                              <1> 
  1738                              <1> 	;;mov	al, 128 ; double word
  1739                              <1> 	;;mul	ecx ; ecx =  directory buffer sector count
  1740                              <1> 	;;mov	ecx, eax
  1741                              <1> 	;shl	cx, 7 ; 128 * sector count	
  1742                              <1> 	;;sub	eax, eax
  1743                              <1> 	;;sub	al, al ; 0
  1744                              <1> 	;rep	stosd ; clear directory buffer
  1745                              <1> 
  1746 0000A775 BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
  1747                              <1> 	
  1748 0000A77A 56                  <1> 	push	esi
  1749                              <1> 
  1750 0000A77B BE[E4620100]        <1> 	mov	esi, mkdir_Name
  1751 0000A780 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
  1752                              <1> 
  1753 0000A785 A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1754 0000A78A 66B91000            <1> 	mov	cx, 10h ; CL = Directory attribute
  1755                              <1> 			; CH = 0 -> File size is 0
  1756 0000A78E E883000000          <1> 	call	make_directory_entry
  1757                              <1> 
  1758 0000A793 BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
  1759                              <1> 
  1760                              <1> 	; 03/03/2016
  1761                              <1> 	; Following modification has been done according to 
  1762                              <1> 	; 'Microsoft Extensible Firmware Initiative
  1763                              <1> 	; FAT32 File System Specification' document,
  1764                              <1> 	; 'FAT: General Overview of On-Disk FormatPage 25'.
  1765                              <1> 	; "Finally, you set DIR_FstClusLO and DIR_FstClusHI
  1766                              <1> 	; for the dotdot entry (the second entry) to the
  1767                              <1> 	; first cluster number of the directory in which you 
  1768                              <1> 	; just created the directory (value is 0 if this directory
  1769                              <1> 	; is the root directory even for FAT32 volumes)."
  1770                              <1> 	; (Correctness of this modification has been verified
  1771                              <1> 	;  by using Windows 98 'scandisk.exe'.)
  1772                              <1> 
  1773 0000A798 29C0                <1> 	sub	eax, eax
  1774 0000A79A 3805[6C590100]      <1> 	cmp	byte [Current_Dir_Level], al ; 0
  1775 0000A7A0 7605                <1> 	jna	short loc_mkdir_set_ff_dir_entry_3
  1776 0000A7A2 A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
  1777                              <1> loc_mkdir_set_ff_dir_entry_3:
  1778 0000A7A7 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
  1779                              <1> 
  1780                              <1> 	;mov	cx, 10h
  1781 0000A7AD E864000000          <1> 	call	make_directory_entry
  1782                              <1> 
  1783 0000A7B2 5E                  <1> 	pop	esi
  1784                              <1> 
  1785 0000A7B3 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1786 0000A7BA E834010000          <1> 	call	save_directory_buffer
  1787 0000A7BF 0F8373FFFFFF        <1>         jnc     loc_mkdir_update_sub_dir_cluster
  1788                              <1>  
  1789                              <1> retn_make_fat_directory:
  1790 0000A7C5 C3                  <1> 	retn
  1791                              <1> 
  1792                              <1> loc_mkdir_save_fat_buffer_3:
  1793                              <1> 	; 01/03/2016
  1794                              <1> 	; byte [FAT_BuffValidData] = 2 
  1795 0000A7C6 E8BF190000          <1> 	call	save_fat_buffer
  1796 0000A7CB 0F821AFFFFFF        <1>         jc      loc_mkdir_save_fat_buffer_stc_retn
  1797                              <1> 
  1798 0000A7D1 803D[82600100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1799 0000A7D8 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_4
  1800                              <1> 
  1801                              <1> 	; ESI = Logical DOS Drive Description Table address 
  1802 0000A7DA A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1803 0000A7DF 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  1804 0000A7E3 E8371A0000          <1> 	call	calculate_fat_freespace
  1805                              <1> 
  1806                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  1807                              <1>         ;jnz    short loc_mkdir_save_fat_buffer_4
  1808                              <1> 
  1809                              <1> 	; ecx > 0 -> Recalculation is needed
  1810 0000A7E8 09C9                <1> 	or	ecx, ecx 
  1811 0000A7EA 7409                <1>         jz      short loc_mkdir_save_fat_buffer_4
  1812                              <1> 
  1813 0000A7EC 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
  1814 0000A7F0 E82A1A0000          <1> 	call	calculate_fat_freespace
  1815                              <1> 
  1816                              <1> loc_mkdir_save_fat_buffer_4:	
  1817 0000A7F5 C605[E3620100]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
  1818                              <1> 
  1819                              <1> loc_mkdir_upd_parent_dir_lmdt:
  1820 0000A7FC E88D010000          <1> 	call	update_parent_dir_lmdt
  1821                              <1> 
  1822                              <1> 	; 01/03/2016
  1823 0000A801 803D[E3620100]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
  1824 0000A808 0F8723FEFFFF        <1>         ja      loc_mkdir_gffc_2
  1825                              <1> 
  1826                              <1> loc_mkdir_retn_new_dir_cluster:
  1827 0000A80E A1[D4620100]        <1> 	mov	eax, [mkdir_FFCluster]
  1828 0000A813 31D2                <1> 	xor	edx, edx
  1829                              <1> loc_mkdir_retn:
  1830 0000A815 C3                  <1> 	retn
  1831                              <1> 
  1832                              <1> make_directory_entry:
  1833                              <1> 	; 02/03/2016
  1834                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1835                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
  1836                              <1> 	; 17/07/2010
  1837                              <1> 	; INPUT ->
  1838                              <1> 	; 	EDI = Directory Entry Address
  1839                              <1> 	;	ESI = Dot File Name Location
  1840                              <1> 	;	EAX = First Cluster
  1841                              <1> 	;	File Size = 0 (Must be set later)
  1842                              <1> 	;	CL = Attributes
  1843                              <1> 	;	CH = 0 (File size = 0) 
  1844                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
  1845                              <1> 	; OUTPUT -> 
  1846                              <1> 	;	EDI = Directory Entry Address
  1847                              <1> 	;	ESI = Dot File Name Location (Capitalized)
  1848                              <1> 	;	If CH input = 0, File Size = 0
  1849                              <1> 	;	Otherwise file size is as dword [EBX] (*)
  1850                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
  1851                              <1> 	;	EBX = same
  1852                              <1> 	;	ECX = same
  1853                              <1> 
  1854 0000A816 51                  <1> 	push	ecx
  1855                              <1> 
  1856 0000A817 884F0B              <1> 	mov	[edi+11], cl ; Attributes
  1857 0000A81A 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
  1858 0000A81E C1E810              <1> 	shr	eax, 16
  1859 0000A821 66894714            <1> 	mov	[edi+20], ax ; FClusterHw, 20
  1860 0000A825 6631C0              <1> 	xor	ax, ax 
  1861 0000A828 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
  1862                              <1> 			     ; CrtTimeTenth, 13
  1863 0000A82C 08ED                <1> 	or	ch, ch
  1864 0000A82E 7402                <1> 	jz	short loc_make_direntry_set_filesize
  1865                              <1> 
  1866 0000A830 8B03                <1> 	mov	eax, [ebx]
  1867                              <1>         
  1868                              <1> loc_make_direntry_set_filesize:
  1869 0000A832 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
  1870                              <1> 	
  1871 0000A835 E88AFBFFFF          <1> 	call	convert_file_name
  1872                              <1> 	;EDI = Dir Entry Format File Name Location
  1873                              <1> 	;ESI = Dot File Name Location (capitalized)
  1874                              <1> 
  1875 0000A83A E816000000          <1> 	call	convert_current_date_time
  1876                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1877                              <1>         ; 	    AX = Time in dos dir entry format
  1878 0000A83F 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
  1879 0000A843 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
  1880 0000A847 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
  1881 0000A84B 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
  1882 0000A84F 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
  1883 0000A853 59                  <1> 	pop	ecx
  1884                              <1> 
  1885 0000A854 C3                  <1> 	retn
  1886                              <1> 
  1887                              <1> convert_current_date_time:
  1888                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1889                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
  1890                              <1> 	; converts date&time to dos dir entry format
  1891                              <1> 	; INPUT -> none
  1892                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1893                              <1> 	;           AX = Time in dos dir entry format
  1894                              <1>  
  1895 0000A855 B404                <1> 	mov	ah, 04h ; Return Current Date
  1896 0000A857 E850B1FFFF          <1> 	call	int1Ah 
  1897                              <1> 
  1898 0000A85C 88E8                <1> 	mov	al, ch ; <- century BCD
  1899 0000A85E 240F                <1> 	and	al, 0Fh
  1900 0000A860 88EC                <1> 	mov	ah, ch
  1901 0000A862 C0EC04              <1> 	shr	ah, 4
  1902 0000A865 D50A                <1> 	aad
  1903 0000A867 88C5                <1> 	mov	ch, al ; -> century 
  1904                              <1> 
  1905 0000A869 88C8                <1> 	mov	al, cl ; <- year BCD
  1906 0000A86B 240F                <1> 	and	al, 0Fh
  1907 0000A86D 88CC                <1> 	mov	ah, cl
  1908 0000A86F C0EC04              <1> 	shr	ah, 4
  1909 0000A872 D50A                <1> 	aad
  1910 0000A874 88C1                <1> 	mov	cl, al ; -> year
  1911                              <1> 
  1912 0000A876 88E8                <1> 	mov	al, ch
  1913 0000A878 B464                <1> 	mov	ah, 100
  1914 0000A87A F6E4                <1> 	mul	ah
  1915 0000A87C 30ED                <1> 	xor	ch, ch
  1916 0000A87E 6601C8              <1> 	add	ax, cx
  1917 0000A881 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
  1918 0000A885 6689C1              <1> 	mov	cx, ax
  1919                              <1> 
  1920 0000A888 88F0                <1> 	mov	al, dh ; <- month in bcd
  1921 0000A88A 240F                <1> 	and	al, 0Fh
  1922 0000A88C 88F4                <1> 	mov	ah, dh
  1923 0000A88E C0EC04              <1> 	shr	ah, 4
  1924 0000A891 D50A                <1> 	aad
  1925 0000A893 88C6                <1> 	mov	dh, al ; -> month
  1926                              <1> 
  1927 0000A895 88D0                <1> 	mov	al, dl ; <- day BCD
  1928 0000A897 240F                <1> 	and	al, 0Fh
  1929 0000A899 88D4                <1> 	mov	ah, dl
  1930 0000A89B C0EC04              <1> 	shr	ah, 4
  1931 0000A89E D50A                <1> 	aad
  1932 0000A8A0 88C2                <1> 	mov	dl, al ; -> day
  1933                              <1> 
  1934 0000A8A2 88C8                <1> 	mov	al, cl ; count of years from 1980
  1935 0000A8A4 66C1E004            <1> 	shl	ax, 4
  1936 0000A8A8 08F0                <1> 	or	al, dh ; month of year, 1 to 12
  1937 0000A8AA 66C1E005            <1> 	shl	ax, 5
  1938 0000A8AE 08D0                <1> 	or	al, dl ; day of year, 1 to 31
  1939                              <1> 	
  1940 0000A8B0 6650                <1> 	push	ax ; push date
  1941                              <1> 
  1942 0000A8B2 B402                <1> 	mov	ah, 02h ; Return Current Time
  1943 0000A8B4 E8F3B0FFFF          <1> 	call	int1Ah
  1944                              <1> 
  1945 0000A8B9 88E8                <1> 	mov	al, ch ; <- hours BCD
  1946 0000A8BB 240F                <1> 	and	al, 0Fh
  1947 0000A8BD 88EC                <1> 	mov	ah, ch
  1948 0000A8BF C0EC04              <1> 	shr	ah, 4
  1949 0000A8C2 D50A                <1> 	aad
  1950 0000A8C4 88C5                <1> 	mov	ch, al ; -> hours
  1951                              <1> 
  1952 0000A8C6 88C8                <1> 	mov	al, cl ; <- minutes BCD
  1953 0000A8C8 240F                <1> 	and	al, 0Fh
  1954 0000A8CA 88CC                <1> 	mov	ah, cl
  1955 0000A8CC C0EC04              <1> 	shr	ah, 4
  1956 0000A8CF D50A                <1> 	aad
  1957 0000A8D1 88C1                <1> 	mov	cl, al ; -> minutes
  1958                              <1> 
  1959 0000A8D3 88F0                <1> 	mov	al, dh ; <- seconds BCD
  1960 0000A8D5 240F                <1> 	and	al, 0Fh
  1961 0000A8D7 88F4                <1> 	mov	ah, dh
  1962 0000A8D9 C0EC04              <1> 	shr	ah, 4
  1963 0000A8DC D50A                <1> 	aad
  1964 0000A8DE 88C6                <1> 	mov	dh, al ; -> seconds
  1965                              <1> 
  1966 0000A8E0 88E8                <1> 	mov	al, ch ; hours
  1967 0000A8E2 66C1E006            <1> 	shl	ax, 6
  1968 0000A8E6 08C8                <1> 	or	al, cl ; minutes
  1969 0000A8E8 66C1E005            <1> 	shl	ax, 5
  1970 0000A8EC D0EE                <1> 	shr	dh, 1 ; 2 seconds
  1971                              <1> 	; There is a bug in TRDOS v1 here !
  1972                              <1> 	; it was 'or al, dl' ! 
  1973 0000A8EE 08F0                <1> 	or	al, dh ; seconds
  1974                              <1> 
  1975 0000A8F0 665A                <1> 	pop	dx ; pop date
  1976                              <1> 	
  1977 0000A8F2 C3                  <1> 	retn
  1978                              <1> 
  1979                              <1> save_directory_buffer:
  1980                              <1> 	; 15/10/2016
  1981                              <1> 	; 23/03/2016
  1982                              <1> 	; 26/02/2016
  1983                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  1984                              <1> 	; 01/08/2011
  1985                              <1> 	; 14/03/2010
  1986                              <1> 	; INPUT ->
  1987                              <1> 	; 	 none
  1988                              <1> 	; OUTPUT ->
  1989                              <1> 	;  cf = 0 -> write OK...
  1990                              <1> 	;  cf = 1 -> error code in AL (EAX)
  1991                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
  1992                              <1> 	;  EBX = Directory Buffer Address
  1993                              <1> 	;
  1994                              <1> 	;  (EAX, ECX, EDX will be modified)
  1995                              <1>  
  1996 0000A8F3 BB00000800          <1> 	mov	ebx, Directory_Buffer
  1997 0000A8F8 803D[8C600100]02    <1> 	cmp	byte [DirBuff_ValidData], 2
  1998 0000A8FF 7403                <1> 	je	short loc_save_dir_buffer
  1999 0000A901 31C0                <1> 	xor	eax, eax
  2000 0000A903 C3                  <1> 	retn            
  2001                              <1> 
  2002                              <1> loc_save_dir_buffer:
  2003 0000A904 56                  <1> 	push	esi
  2004 0000A905 31DB                <1> 	xor	ebx, ebx 
  2005 0000A907 8A3D[8A600100]      <1>         mov     bh, [DirBuff_DRV]
  2006 0000A90D 80EF41              <1> 	sub	bh, 'A'
  2007 0000A910 BE00010900          <1>         mov     esi, Logical_DOSDisks
  2008 0000A915 01DE                <1> 	add	esi, ebx
  2009 0000A917 668B4E03            <1>         mov     cx, [esi+LD_FATType]
  2010                              <1> 	; CH = FS Type (A1h for FS)
  2011                              <1> 	; CL = FAT Type (0 for FS)
  2012 0000A91B 08C9                <1> 	or	cl, cl
  2013 0000A91D 7433                <1> 	jz	short loc_save_dir_buff_stc_retn
  2014                              <1> 
  2015                              <1> loc_save_dir_buffer_check_cluster_no:    
  2016 0000A91F A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
  2017 0000A924 28FF                <1> 	sub	bh, bh ; ebx = 0
  2018 0000A926 09C0                <1> 	or	eax, eax
  2019 0000A928 7540                <1> 	jnz	short loc_save_sub_dir_buffer
  2020 0000A92A 8A25[8B600100]      <1> 	mov	ah, [DirBuff_FATType]
  2021 0000A930 FEC3                <1> 	inc	bl ;  bl = 1
  2022 0000A932 38DC                <1> 	cmp	ah, bl
  2023 0000A934 721D                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2024 0000A936 FEC3                <1> 	inc	bl ; bl = 2
  2025 0000A938 38E3                <1> 	cmp	bl, ah
  2026 0000A93A 7217                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2027                              <1> 
  2028                              <1> loc_save_root_dir_buffer:
  2029 0000A93C 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
  2030 0000A940 6683C30F            <1> 	add	bx, 15
  2031 0000A944 66C1EB04            <1> 	shr	bx, 4 ; 16 dir entries per sector
  2032 0000A948 6609DB              <1> 	or	bx, bx
  2033 0000A94B 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
  2034                              <1> 	;mov	ecx, ebx 
  2035 0000A94D 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
  2036 0000A950 EB23                <1> 	jmp	short loc_write_directory_to_disk
  2037                              <1> 
  2038                              <1> loc_save_dir_buff_stc_retn:
  2039 0000A952 F9                  <1> 	stc
  2040                              <1> loc_save_dir_buff_inv_data_retn:
  2041                              <1> 	; 15/10/2016 (0Dh -> 29)
  2042 0000A953 B01D                <1> 	mov	al, 29 ; Invalid data !
  2043 0000A955 C605[8C600100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2044 0000A95C EB05                <1> 	jmp	short loc_save_dir_buff_retn 
  2045                              <1> 
  2046                              <1> loc_write_directory_to_disk_err:
  2047                              <1> 	; 15/10/2016 (disk write error code, 1Dh -> 18)
  2048 0000A95E B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error 
  2049                              <1> 
  2050                              <1> loc_save_dir_buff_retn:
  2051 0000A963 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2052 0000A968 5E                  <1> 	pop	esi
  2053 0000A969 C3                  <1> 	retn
  2054                              <1>  
  2055                              <1> loc_save_sub_dir_buffer:
  2056                              <1> 	; ebx  = 0
  2057 0000A96A 83E802              <1> 	sub	eax, 2
  2058 0000A96D 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2059 0000A970 F7E3                <1> 	mul	ebx
  2060 0000A972 034668              <1>         add     eax, [esi+LD_DATABegin]
  2061                              <1>  	;mov	ecx, ebx
  2062                              <1> 
  2063                              <1> loc_write_directory_to_disk:
  2064 0000A975 89D9                <1>  	mov	ecx, ebx
  2065 0000A977 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2066 0000A97C E8A34E0000          <1> 	call	disk_write
  2067 0000A981 72DB                <1> 	jc	short loc_write_directory_to_disk_err
  2068                              <1> 
  2069                              <1> loc_save_dir_buff_validate_retn:
  2070 0000A983 C605[8C600100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2071 0000A98A 31C0                <1> 	xor	eax, eax
  2072                              <1> 	; 26/02/2016
  2073 0000A98C EBD5                <1> 	jmp	short loc_save_dir_buff_retn
  2074                              <1> 
  2075                              <1> update_parent_dir_lmdt:
  2076                              <1> 	; 29/12/2017
  2077                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  2078                              <1> 	; 01/08/2011
  2079                              <1> 	; 16/10/2010 
  2080                              <1> 	; 
  2081                              <1> 	; INPUT -> 
  2082                              <1> 	;	none
  2083                              <1>  	; OUTPUT ->
  2084                              <1> 	;	(last modification date & time of the parent dir
  2085                              <1> 	;	will be changed/updated)
  2086                              <1> 	;
  2087                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
  2088                              <1> 
  2089 0000A98E 29C0                <1> 	sub	eax, eax
  2090 0000A990 8A25[6C590100]      <1> 	mov	ah, [Current_Dir_Level]
  2091 0000A996 A0[6D590100]        <1> 	mov	al, [Current_FATType]
  2092 0000A99B 3C01                <1> 	cmp	al, 1
  2093 0000A99D 723A                <1> 	jb	short loc_UPDLMDT_proc_retn
  2094                              <1>     
  2095                              <1> loc_update_parent_dir_lm_date_time:
  2096 0000A99F 08E4                <1> 	or	ah, ah
  2097 0000A9A1 7436                <1> 	jz	short loc_UPDLMDT_proc_retn
  2098                              <1> 
  2099 0000A9A3 56                  <1> 	push	esi ; *
  2100 0000A9A4 8825[04630100]      <1> 	mov	[UPDLMDT_CDirLevel], ah
  2101 0000A9AA 8B15[68590100]      <1> 	mov	edx, [Current_Dir_FCluster]
  2102 0000A9B0 8915[05630100]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
  2103                              <1> 
  2104 0000A9B6 FECC                <1> 	dec	ah
  2105 0000A9B8 B90C000000          <1> 	mov	ecx, 12
  2106 0000A9BD BE[C3600100]        <1>         mov     esi, PATH_Array
  2107                              <1> 
  2108 0000A9C2 8825[6C590100]      <1> 	mov	[Current_Dir_Level], ah
  2109 0000A9C8 08E4                <1> 	or	ah, ah
  2110 0000A9CA 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
  2111 0000A9CC 803D[6D590100]02    <1> 	cmp	byte [Current_FATType], 2
  2112 0000A9D3 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
  2113 0000A9D5 28C0                <1> 	sub	al, al ; eax = 0
  2114 0000A9D7 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
  2115                              <1> 
  2116                              <1> loc_UPDLMDT_proc_retn:
  2117 0000A9D9 C3                  <1> 	retn
  2118                              <1>          
  2119                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
  2120 0000A9DA B010                <1> 	mov	al, 16
  2121 0000A9DC F6E4                <1> 	mul	ah 
  2122 0000A9DE 01C6                <1> 	add	esi, eax
  2123                              <1> 
  2124                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:  
  2125 0000A9E0 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
  2126                              <1> 
  2127                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
  2128 0000A9E3 A3[68590100]        <1> 	mov	[Current_Dir_FCluster], eax
  2129                              <1> 
  2130 0000A9E8 83C610              <1> 	add	esi, 16
  2131 0000A9EB 66BF[EA61]          <1> 	mov	di, Dir_File_Name  
  2132 0000A9EF F3A4                <1> 	rep	movsb
  2133                              <1> 	
  2134 0000A9F1 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2135 0000A9F6 29DB                <1> 	sub	ebx, ebx
  2136 0000A9F8 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  2137 0000A9FE 01DE                <1> 	add	esi, ebx
  2138 0000AA00 E88FF7FFFF          <1> 	call	reload_current_directory
  2139 0000AA05 7230                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2140                              <1> 
  2141                              <1> loc_update_parent_dir_lmdt_locate_dir: 
  2142 0000AA07 BE[EA610100]        <1> 	mov	esi, Dir_File_Name        
  2143 0000AA0C 6631C9              <1> 	xor	cx, cx
  2144 0000AA0F 66B81008            <1> 	mov	ax, 0810h ; Only directories
  2145 0000AA13 E8B5F6FFFF          <1>         call    locate_current_dir_file
  2146                              <1> 	; EDI = DirBuff Directory Entry Address
  2147 0000AA18 721D                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2148                              <1> 
  2149 0000AA1A E836FEFFFF          <1> 	call	convert_current_date_time
  2150 0000AA1F 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
  2151 0000AA23 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
  2152 0000AA27 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
  2153                              <1> 
  2154 0000AA2B C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2155 0000AA32 E8BCFEFFFF          <1> 	call	save_directory_buffer
  2156                              <1> 	; 29/12/2017
  2157                              <1> 	;jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2158                              <1> 	;xor	al, al 
  2159                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
  2160                              <1>  	;current directory level restoration
  2161 0000AA37 8A25[04630100]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
  2162 0000AA3D 8825[6C590100]      <1> 	mov	[Current_Dir_Level], ah
  2163 0000AA43 8B15[05630100]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
  2164 0000AA49 8915[68590100]      <1> 	mov	[Current_Dir_FCluster], edx
  2165                              <1> 
  2166 0000AA4F 5E                  <1> 	pop	esi ; *
  2167 0000AA50 C3                  <1> 	retn
  2168                              <1> 
  2169                              <1> delete_longname:
  2170                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2171                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
  2172                              <1> 	; 14/03/2010
  2173                              <1> 	; INPUT ->
  2174                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
  2175                              <1> 	; OUTPUT ->
  2176                              <1> 	;	cf = 0 -> OK  (EAX = 0)
  2177                              <1> 	; 	cf = 1 -> error code in EAX (AL)
  2178                              <1> 	;
  2179                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
  2180                              <1> 
  2181 0000AA51 66A3[34630100]      <1> 	mov	[DLN_EntryNumber], ax
  2182 0000AA57 C605[36630100]40    <1>         mov     byte [DLN_40h], 40h
  2183                              <1> 
  2184 0000AA5E E858000000          <1> 	call	locate_current_dir_entry
  2185 0000AA63 7308                <1> 	jnc	short loc_dln_check_attributes
  2186 0000AA65 C3                  <1> 	retn
  2187                              <1> 
  2188                              <1> loc_dln_longname_not_found:
  2189 0000AA66 B802000000          <1> 	mov	eax, 2
  2190 0000AA6B F9                  <1> 	stc
  2191 0000AA6C C3                  <1> 	retn
  2192                              <1> 
  2193                              <1> loc_dln_check_attributes:
  2194 0000AA6D B00F                <1> 	mov	al, 0Fh  ; long name
  2195 0000AA6F 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
  2196 0000AA72 38C4                <1> 	cmp	ah, al
  2197 0000AA74 75F0                <1> 	jne	short loc_dln_longname_not_found
  2198 0000AA76 8A27                <1> 	mov	ah, [edi]
  2199 0000AA78 2A25[36630100]      <1> 	sub	ah, [DLN_40h]
  2200 0000AA7E 76E6                <1> 	jna	short loc_dln_longname_not_found         
  2201 0000AA80 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
  2202 0000AA83 77E1                <1> 	ja	short loc_dln_longname_not_found
  2203                              <1>              
  2204 0000AA85 C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
  2205 0000AA88 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
  2206 0000AA8F C605[36630100]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
  2207                              <1> 	  
  2208                              <1> loc_dln_delete_next_ln_entry:
  2209 0000AA96 80FC01              <1> 	cmp	ah, 1
  2210 0000AA99 7616                <1> 	jna	short loc_dln_longname_retn
  2211                              <1> loc_dln_delete_next_ln_entry_0:
  2212 0000AA9B 66FF05[34630100]    <1> 	inc	word [DLN_EntryNumber]
  2213 0000AAA2 0FB705[34630100]    <1> 	movzx	eax, word [DLN_EntryNumber] 
  2214 0000AAA9 E80D000000          <1> 	call	locate_current_dir_entry
  2215 0000AAAE 73BD                <1> 	jnc	short loc_dln_check_attributes
  2216                              <1> 
  2217                              <1> loc_dln_longname_stc_retn:
  2218 0000AAB0 C3                  <1> 	retn 
  2219                              <1> 	   
  2220                              <1> loc_dln_longname_retn:
  2221                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2222                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
  2223 0000AAB1 E83DFEFFFF          <1> 	call	save_directory_buffer
  2224 0000AAB6 72F8                <1> 	jc	short loc_dln_longname_stc_retn
  2225                              <1> 
  2226                              <1> loc_dln_longname_retn_xor_eax:
  2227 0000AAB8 31C0                <1> 	xor	eax, eax
  2228 0000AABA C3                  <1> 	retn
  2229                              <1> 
  2230                              <1> locate_current_dir_entry:
  2231                              <1> 	; 16/10/2016
  2232                              <1> 	; 15/10/2016
  2233                              <1> 	; 23/03/2016
  2234                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2235                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
  2236                              <1> 	; 07/03/2010
  2237                              <1> 	; INPUT ->
  2238                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536) 
  2239                              <1> 	; OUTPUT ->
  2240                              <1> 	;	EDI = Directory Entry Address
  2241                              <1> 	; 	EAX = Cluster Number of Directory Buffer
  2242                              <1> 	;	EBX = Directory Buffer Entry Offset
  2243                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
  2244                              <1> 	;   	If CF = 0 and CL = 2 then
  2245                              <1> 	;	   directory buffer modified and
  2246                              <1> 	;	   must be written to disk.
  2247                              <1> 	; 	If CF = 0  and CL = 1 then
  2248                              <1> 	;	   dir buffer has been written to disk, already.
  2249                              <1> 	;	CF = 1 -> Error code in EAX (AL)
  2250                              <1> 	;
  2251                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
  2252                              <1> 
  2253                              <1> loc_locate_current_dir_entry:
  2254 0000AABB 56                  <1> 	push	esi
  2255 0000AABC 89C1                <1> 	mov	ecx, eax
  2256 0000AABE BA20000000          <1> 	mov	edx, 32
  2257 0000AAC3 F7E2                <1> 	mul	edx 
  2258 0000AAC5 A3[40630100]        <1> 	mov	[LCDE_ByteOffset], eax
  2259 0000AACA 31DB                <1> 	xor	ebx, ebx
  2260 0000AACC 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  2261 0000AAD2 A0[8A600100]        <1>         mov     al, [DirBuff_DRV]
  2262 0000AAD7 2C41                <1> 	sub	al, 'A'
  2263 0000AAD9 BE00010900          <1>         mov     esi, Logical_DOSDisks
  2264 0000AADE 01DE                <1> 	add	esi, ebx
  2265 0000AAE0 38C7                <1> 	cmp	bh, al
  2266 0000AAE2 0F8592000000        <1>         jne     loc_lcde_reload_current_directory
  2267                              <1> loc_lcde_cdl_check:
  2268 0000AAE8 803D[6C590100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2269 0000AAEF 772A                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
  2270                              <1> 	; 27/02/2016
  2271                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2272                              <1> 	; (Root Directory Entries for FAT32 = 0)
  2273 0000AAF1 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2274 0000AAF5 7324                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
  2275                              <1> 
  2276                              <1> loc_lcde_cdl_check_FAT12_16:
  2277 0000AAF7 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
  2278 0000AAFB 6648                <1> 	dec	ax
  2279                              <1> 	;xor	dx, dx  
  2280 0000AAFD 6639C8              <1> 	cmp	ax, cx ; cx = Directory Entry (Index) Number
  2281 0000AB00 720E                <1> 	jb	short loc_lcde_stc_12h_retn
  2282 0000AB02 66890D[38630100]    <1> 	mov	[LCDE_EntryIndex], cx
  2283 0000AB09 31C0                <1> 	xor	eax, eax
  2284 0000AB0B E993000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
  2285                              <1> 
  2286                              <1> loc_lcde_stc_12h_retn:
  2287 0000AB10 5E                  <1> 	pop	esi
  2288 0000AB11 89CB                <1> 	mov	ebx, ecx
  2289 0000AB13 89D1                <1> 	mov	ecx, edx
  2290                              <1> 	; 16/10/2016 (12h -> 12)
  2291 0000AB15 B80C000000          <1> 	mov	eax, 12 ; No more files
  2292 0000AB1A C3                  <1> 	retn 
  2293                              <1> 
  2294                              <1> loc_lcde_calc_dirbuff_cluster_offset:
  2295 0000AB1B 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2296 0000AB1E 30FF                <1> 	xor	bh, bh
  2297 0000AB20 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  2298 0000AB24 66F7E3              <1> 	mul	bx
  2299 0000AB27 6609D2              <1>  	or	dx, dx ; If bytes per cluster > 32KB it is invalid
  2300 0000AB2A 755D                <1> 	jnz	short loc_lcde_invalid_format
  2301                              <1> 	;mov	ecx, eax
  2302 0000AB2C 6689C1              <1> 	mov	cx, ax ; BYTES PER CLUSTER
  2303 0000AB2F A1[40630100]        <1> 	mov	eax, [LCDE_ByteOffset]
  2304                              <1> 	;sub	edx, edx
  2305 0000AB34 F7F1                <1> 	div	ecx
  2306 0000AB36 3DFFFF0000          <1> 	cmp	eax, 65535
  2307 0000AB3B 774C                <1> 	ja	short loc_lcde_invalid_format
  2308                              <1> 
  2309                              <1> 	; cluster sequence number of directory (< 65536)
  2310 0000AB3D 66A3[3A630100]      <1> 	mov	[LCDE_ClusterSN], ax 
  2311                              <1> 
  2312 0000AB43 6689D0              <1> 	mov	ax, dx ; byte offset in cluster (directory buffer)
  2313 0000AB46 66BB2000            <1> 	mov	bx, 32 ; ; 1 dir entry = 32 bytes
  2314 0000AB4A 6629D2              <1>         sub     dx, dx  ; 0
  2315 0000AB4D 66F7F3              <1> 	div	bx 
  2316 0000AB50 66A3[38630100]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
  2317                              <1> 				      ; (in directory buffer/cluster)	  
  2318                              <1> loc_lcde_get_current_sub_dir_fcluster:
  2319 0000AB56 A1[68590100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2320                              <1> 
  2321                              <1> loc_lcde_get_next_cluster:
  2322 0000AB5B 66833D[3A630100]00  <1> 	cmp	word [LCDE_ClusterSN], 0
  2323 0000AB63 763E                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
  2324 0000AB65 A3[3C630100]        <1> 	mov	[LCDE_Cluster], eax
  2325 0000AB6A E834100000          <1> 	call	get_next_cluster
  2326 0000AB6F 7220                <1> 	jc	short loc_lcde_check_gnc_error
  2327 0000AB71 66FF0D[3A630100]    <1>   	dec	word [LCDE_ClusterSN]
  2328 0000AB78 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
  2329                              <1> 
  2330                              <1> loc_lcde_reload_current_directory:
  2331 0000AB7A 51                  <1> 	push	ecx
  2332 0000AB7B E814F6FFFF          <1> 	call	reload_current_directory
  2333 0000AB80 59                  <1> 	pop	ecx
  2334 0000AB81 0F8361FFFFFF        <1>         jnc     loc_lcde_cdl_check
  2335 0000AB87 5E                  <1> 	pop	esi
  2336 0000AB88 C3                  <1> 	retn
  2337                              <1> 
  2338                              <1> loc_lcde_invalid_format:
  2339                              <1> 	; 15/10/2016 (0Bh -> 28)
  2340 0000AB89 B81C000000          <1> 	mov	eax, 28 ; Invalid Format !
  2341                              <1> loc_lcde_drive_not_ready_read_err:
  2342 0000AB8E F9                  <1> 	stc
  2343 0000AB8F 5E                  <1> 	pop	esi 
  2344 0000AB90 C3                  <1> 	retn  
  2345                              <1> 
  2346                              <1> loc_lcde_check_gnc_error:
  2347 0000AB91 09C0                <1> 	or	eax, eax
  2348 0000AB93 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
  2349 0000AB95 66FF0D[3A630100]    <1> 	dec	word [LCDE_ClusterSN]
  2350 0000AB9C 75EB                <1> 	jnz	short loc_lcde_invalid_format 
  2351 0000AB9E A1[3C630100]        <1> 	mov	eax, [LCDE_Cluster]
  2352                              <1> 
  2353                              <1> loc_lcde_check_dir_buffer_cluster:
  2354 0000ABA3 3B05[91600100]      <1> 	cmp	eax, [DirBuff_Cluster]
  2355 0000ABA9 755C                <1> 	jne	short loc_lcde_load_dir_cluster
  2356 0000ABAB 803D[8C600100]00    <1> 	cmp	byte [DirBuff_ValidData], 0
  2357 0000ABB2 7727                <1> 	ja	short lcde_check_dir_buffer_cluster_next
  2358 0000ABB4 803D[6C590100]00    <1> 	cmp	byte [Current_Dir_Level], 0    
  2359 0000ABBB 775F                <1> 	ja	short loc_lcde_load_dir_cluster_0
  2360                              <1> 	; 27/02/2016
  2361                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2362 0000ABBD 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2363 0000ABC1 7359                <1> 	jnb	short loc_lcde_load_dir_cluster_0
  2364                              <1> 	;
  2365 0000ABC3 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
  2366 0000ABC7 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
  2367 0000ABCB 66C1E904            <1> 	shr	cx, 4 ; 1 sector contains 16 dir entries	
  2368                              <1> 
  2369 0000ABCF 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
  2370 0000ABD2 EB54                <1> 	jmp	short loc_lcde_load_dir_cluster_1 
  2371                              <1> 
  2372                              <1> loc_lcde_validate_dirBuff:
  2373 0000ABD4 C605[8C600100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2374                              <1> 
  2375                              <1> lcde_check_dir_buffer_cluster_next:
  2376 0000ABDB 0FB71D[38630100]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
  2377 0000ABE2 663B1D[8F600100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  2378 0000ABE9 779E                <1> 	ja	short loc_lcde_invalid_format 
  2379 0000ABEB B820000000          <1> 	mov	eax, 32
  2380 0000ABF0 F7E3                <1> 	mul	ebx
  2381                              <1> 	;or	edx, edx
  2382                              <1> 	;jnz	short loc_lcde_invalid_format
  2383                              <1> 
  2384 0000ABF2 BF00000800          <1> 	mov	edi, Directory_Buffer  
  2385 0000ABF7 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
  2386                              <1> 
  2387                              <1> loc_lcde_dir_buffer_last_check:
  2388 0000ABF9 A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
  2389 0000ABFE 0FB60D[8C600100]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
  2390                              <1> 
  2391                              <1> loc_lcde_retn:
  2392 0000AC05 5E                  <1> 	pop	esi
  2393 0000AC06 C3                  <1> 	retn
  2394                              <1> 
  2395                              <1> loc_lcde_load_dir_cluster:
  2396                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2397                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
  2398 0000AC07 50                  <1> 	push	eax
  2399 0000AC08 E8E6FCFFFF          <1> 	call	save_directory_buffer
  2400 0000AC0D 58                  <1> 	pop	eax
  2401 0000AC0E 72F5                <1> 	jc	short loc_lcde_retn
  2402                              <1> 
  2403                              <1> loc_lcde_load_dir_cluster_n2:
  2404 0000AC10 C605[8C600100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2405 0000AC17 A3[91600100]        <1> 	mov	[DirBuff_Cluster], eax
  2406                              <1> 
  2407                              <1> loc_lcde_load_dir_cluster_0:
  2408 0000AC1C 83E802              <1> 	sub	eax, 2
  2409 0000AC1F 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  2410 0000AC23 F7E1                <1> 	mul	ecx
  2411 0000AC25 034668              <1>         add     eax, [esi+LD_DATABegin]
  2412                              <1> 
  2413                              <1> loc_lcde_load_dir_cluster_1:
  2414 0000AC28 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2415                              <1> 	; ecx = sector count
  2416 0000AC2D E8014C0000          <1> 	call	disk_read
  2417 0000AC32 73A0                <1> 	jnc	short loc_lcde_validate_dirBuff
  2418                              <1> 
  2419                              <1> 	; 15/10/2016 
  2420                              <1> 	; (Disk read error instead of drv not ready err)
  2421 0000AC34 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
  2422 0000AC39 EBCA                <1> 	jmp	short loc_lcde_retn
  2423                              <1> 
  2424                              <1> 
  2425                              <1> remove_file:
  2426                              <1> 	; 15/10/2016
  2427                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2428                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
  2429                              <1> 	; 09/08/2010
  2430                              <1> 	; INPUT ->
  2431                              <1> 	;	EDI = Directory Buffer Entry Address
  2432                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2433                              <1> 	;	 BL = Longname Entry Length
  2434                              <1> 	;	 BH = Logical DOS Drive Number 
  2435                              <1> 
  2436 0000AC3B 29C0                <1> 	sub	eax, eax
  2437 0000AC3D 88FC                <1> 	mov	ah, bh
  2438 0000AC3F BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2439 0000AC44 01C6                <1> 	add	esi, eax
  2440                              <1> 
  2441 0000AC46 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2442 0000AC4A 7312                <1> 	jnb	short loc_del_fat_file 
  2443                              <1>               
  2444 0000AC4C 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  2445 0000AC50 7406                <1> 	je	short loc_del_fs_file
  2446                              <1> 
  2447                              <1> loc_del_file_invalid_format:
  2448 0000AC52 30E4                <1> 	xor	ah, ah
  2449                              <1> 	; 15/10/2016 (0Bh -> 28)
  2450 0000AC54 B01C                <1> 	mov	al, 28  ; Invalid Format
  2451 0000AC56 F9                  <1> 	stc 
  2452 0000AC57 C3                  <1> 	retn
  2453                              <1> 
  2454                              <1> loc_del_fs_file:
  2455 0000AC58 E83F0F0000          <1> 	call	delete_fs_file
  2456 0000AC5D C3                  <1> 	retn
  2457                              <1> 
  2458                              <1> loc_del_fat_file:
  2459 0000AC5E E808000000          <1> 	call	delete_directory_entry
  2460 0000AC63 7205                <1> 	jc	short loc_del_file_err_retn 
  2461                              <1> 
  2462                              <1> loc_delfile_unlink_cluster_chain:
  2463 0000AC65 E863170000          <1> 	call	truncate_cluster_chain
  2464                              <1> 	;jc	short loc_del_file_err_retn
  2465                              <1> 
  2466                              <1> loc_delfile_return:
  2467                              <1> loc_del_file_err_retn:
  2468 0000AC6A C3                  <1> 	retn
  2469                              <1> 
  2470                              <1> delete_directory_entry:
  2471                              <1> 	; 15/10/2016
  2472                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2473                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
  2474                              <1> 	; 10/04/2011 
  2475                              <1> 	; INPUT ->
  2476                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
  2477                              <1> 	;	EDI = Directory Buffer Entry Address
  2478                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2479                              <1> 	;	 BL = Longname Entry Length
  2480                              <1> 	; OUTPUT ->
  2481                              <1> 	; 	ESI = Logical dos drive descripton table address 
  2482                              <1> 	;	EAX = First cluster to be truncated/unlinked
  2483                              <1> 	;       CF = 1 -> Error code in EAX (AL)
  2484                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
  2485                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
  2486                              <1> 	;
  2487                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
  2488                              <1> 
  2489 0000AC6B 881D[CE620100]      <1> 	mov	[DelFile_LNEL], bl
  2490 0000AC71 66890D[CC620100]    <1> 	mov	[DelFile_EntryCounter], cx
  2491                              <1> 
  2492 0000AC78 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  2493 0000AC7C C1E010              <1> 	shl	eax, 16
  2494 0000AC7F 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  2495                              <1> 
  2496 0000AC83 A3[C8620100]        <1> 	mov	[DelFile_FCluster], eax
  2497                              <1> 
  2498                              <1> loc_del_short_name:
  2499 0000AC88 C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
  2500                              <1> 
  2501 0000AC8B C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2502 0000AC92 E85CFCFFFF          <1> 	call	save_directory_buffer
  2503 0000AC97 723D                <1> 	jc	short loc_delete_direntry_err_return
  2504                              <1>  
  2505                              <1> loc_del_long_name:
  2506 0000AC99 0FB615[CE620100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2507 0000ACA0 08D2                <1> 	or	dl, dl
  2508 0000ACA2 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
  2509                              <1> 
  2510 0000ACA4 8835[CE620100]      <1> 	mov	byte [DelFile_LNEL], dh ; 0              
  2511                              <1>   
  2512 0000ACAA 0FB705[CC620100]    <1> 	movzx	eax,  word [DelFile_EntryCounter]
  2513 0000ACB1 29D0                <1> 	sub	eax, edx
  2514                              <1> 	;jnc	short loc_del_long_name_continue
  2515 0000ACB3 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date   
  2516                              <1> 
  2517                              <1> ;loc_del_direntry_inv_data_return: ; 15/10/2016 (0Dh -> 29)
  2518                              <1> ;	mov	eax, 29 ; 0Dh (TRDOS 8086) ; Invalid data
  2519                              <1> ;	retn
  2520                              <1> 
  2521                              <1> loc_del_long_name_continue: 
  2522                              <1> 	; AX = Directory Entry Number of the long name last entry
  2523 0000ACB5 E897FDFFFF          <1> 	call	delete_longname
  2524                              <1> 	;jc	short loc_delete_direntry_err_return
  2525                              <1> 
  2526                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
  2527 0000ACBA 801D[CE620100]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
  2528                              <1> 
  2529 0000ACC1 E8C8FCFFFF          <1> 	call	update_parent_dir_lmdt
  2530 0000ACC6 B700                <1> 	mov	bh, 0
  2531 0000ACC8 80D700              <1> 	adc	bh, 0
  2532                              <1> 
  2533 0000ACCB 8A1D[CE620100]      <1> 	mov	bl, byte [DelFile_LNEL]
  2534                              <1>  
  2535                              <1> loc_delete_direntry_return:
  2536 0000ACD1 A1[C8620100]        <1> 	mov	eax, [DelFile_FCluster]
  2537                              <1> loc_delete_direntry_err_return:
  2538 0000ACD6 C3                  <1> 	retn
  2539                              <1> 
  2540                              <1> rename_directory_entry:
  2541                              <1> 	; 13/11/2017
  2542                              <1> 	; 15/10/2016
  2543                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
  2544                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_rename_directory_entry')
  2545                              <1> 	; 19/11/2010
  2546                              <1> 	; INPUT -> (Current Directory)
  2547                              <1> 	;	CX = Directory Entry Number
  2548                              <1> 	;      EAX = First Cluster number of file or directory
  2549                              <1> 	;      EBX = Longname Length (dir entry count) (< 256)
  2550                              <1> 	;      ESI = New file (or directory) name (no path).
  2551                              <1> 	;           (ASCIIZ string)  
  2552                              <1> 	; OUTPUT -> 
  2553                              <1> 	;      CF = 0 -> successfull
  2554                              <1> 	;      CF = 1 -> error code in EAX (AL)
  2555                              <1> 	;
  2556                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2557                              <1> 
  2558 0000ACD7 803D[6D590100]00    <1> 	cmp	byte [Current_FATType], 0
  2559 0000ACDE 7706                <1> 	ja	short loc_rename_directory_entry
  2560                              <1> 
  2561 0000ACE0 E8B80E0000          <1> 	call	rename_fs_file_or_directory
  2562 0000ACE5 C3                  <1> 	retn 
  2563                              <1> 	
  2564                              <1> loc_rename_directory_entry:
  2565 0000ACE6 881D[CE620100]      <1> 	mov	[DelFile_LNEL], bl
  2566 0000ACEC 66890D[CC620100]    <1> 	mov	[DelFile_EntryCounter], cx
  2567 0000ACF3 A3[C8620100]        <1> 	mov	[DelFile_FCluster], eax
  2568                              <1> 
  2569 0000ACF8 0FB7C1              <1> 	movzx	eax, cx
  2570 0000ACFB E8BBFDFFFF          <1> 	call	locate_current_dir_entry
  2571 0000AD00 7308                <1> 	jnc	short loc_rename_direntry_check_fcluster
  2572                              <1> 
  2573                              <1> loc_rename_direntry_pop_retn:
  2574 0000AD02 C3                  <1> 	retn
  2575                              <1> 
  2576                              <1> loc_rename_direntry_pop_invd_retn:
  2577 0000AD03 F9                  <1> 	stc
  2578                              <1> loc_rename_direntry_invd_retn:
  2579                              <1> 	; 15/10/2016 (0Dh -> 29)
  2580 0000AD04 B81D000000          <1> 	mov	eax, 29 ; Invalid data
  2581                              <1> loc_rename_retn:
  2582 0000AD09 C3                  <1> 	retn 
  2583                              <1> 
  2584                              <1> loc_rename_direntry_check_fcluster:
  2585 0000AD0A 668B5714            <1> 	mov	dx, [edi+20] ; First Cluster HW
  2586 0000AD0E C1E210              <1> 	shl	edx, 16 ; 13/11/2017
  2587 0000AD11 668B571A            <1> 	mov	dx, [edi+26] ; First Cluster LW
  2588 0000AD15 3B15[C8620100]      <1> 	cmp	edx, [DelFile_FCluster]
  2589 0000AD1B 75E6                <1> 	jne	short loc_rename_direntry_pop_invd_retn
  2590                              <1> 	; ESI = New file (or directory) name. (ASCIIZ string)
  2591                              <1> 	; 06/03/2016
  2592                              <1> 	; TRDOS v2 - NOTE: 'convert_file_name' procedure
  2593                              <1> 	; has been modified for eliminating following situation.
  2594                              <1> 	; 
  2595                              <1> 	; TRDOS v1 - NOTE: If file/dir name is more than 11 bytes
  2596                              <1> 	; without a dot, attributes (edi+11) byte will be overwritten !
  2597                              <1> 	; (Dot file name input must be proper for 11 byte dir entry
  2598                              <1> 	;  type file name output.) 
  2599 0000AD1D E8A2F6FFFF          <1> 	call	convert_file_name
  2600                              <1> 
  2601 0000AD22 C605[8C600100]02    <1>         mov     byte [DirBuff_ValidData], 2
  2602 0000AD29 E8C5FBFFFF          <1> 	call	save_directory_buffer
  2603 0000AD2E 72D9                <1> 	jc	short loc_rename_retn
  2604                              <1> 
  2605                              <1> loc_rename_direntry_del_ln:
  2606 0000AD30 0FB615[CE620100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2607 0000AD37 08D2                <1> 	or	dl, dl
  2608 0000AD39 7410                <1> 	jz	short loc_rename_direntry_update_parent_dir_lm_date
  2609                              <1> 
  2610 0000AD3B 0FB705[CC620100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  2611 0000AD42 29D0                <1> 	sub	eax, edx
  2612 0000AD44 72BE                <1> 	jc	short loc_rename_direntry_invd_retn
  2613                              <1> 
  2614                              <1> loc_rename_direntry_del_ln_continue: 
  2615                              <1> 	; EAX = Directory Entry Number of the long name last entry
  2616 0000AD46 E806FDFFFF          <1> 	call	delete_longname
  2617                              <1> 
  2618                              <1> loc_rename_direntry_update_parent_dir_lm_date:
  2619 0000AD4B E83EFCFFFF          <1> 	call	update_parent_dir_lmdt
  2620 0000AD50 31C0                <1> 	xor	eax, eax 
  2621 0000AD52 C3                  <1> 	retn
  2622                              <1> 
  2623                              <1> move_source_file_to_destination_file:
  2624                              <1> 	; 15/10/2016
  2625                              <1> 	; 11/03/2016
  2626                              <1> 	; 10/03/2016 (TRDOS 386 = TRDOS v2.0)
  2627                              <1> 	; 01/08/2011 (FILE.ASM)
  2628                              <1> 	; 04/08/2010
  2629                              <1> 	;
  2630                              <1> 	;   Phase 1 -> Check destination file, 
  2631                              <1> 	;              'not found' is required
  2632                              <1> 	;   Phase 2 -> Check source file
  2633                              <1> 	;              'found' and proper attributes is required
  2634                              <1> 	;   Phase 3 -> Make destination directory entry,
  2635                              <1> 	;           add new dir cluster or section if it is required
  2636                              <1> 	;   Phase 4 -> Delete source directory entry.
  2637                              <1> 	;       cf = 1 causes to return before the phase 4.
  2638                              <1> 	;    (source file protection against any possible errors)    
  2639                              <1> 	;
  2640                              <1> 	; 08/05/2011 major modification
  2641                              <1> 	;            -> destination file deleting is removed   
  2642                              <1> 	;            for msdos move/rename compatibility.
  2643                              <1> 	;            (Access denied error will return if
  2644                              <1> 	;            the destination file is found...)
  2645                              <1> 	; INPUT ->
  2646                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  2647                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  2648                              <1> 	;        AL = 0 --> Interrupt (System call)
  2649                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  2650                              <1> 	;        AL = 1 --> Question Phase
  2651                              <1> 	;        AL = 2 --> Progress Phase        
  2652                              <1> 	; OUTPUT -> 
  2653                              <1> 	;	 cf = 0 -> OK
  2654                              <1> 	;        EAX = Destination directory first cluster
  2655                              <1> 	;        ESI = Logical DOS drive description table 
  2656                              <1> 	;        EBX = Destination file structure offset
  2657                              <1> 	;        CX = 0 (CX > 0 --> calculate free space error)
  2658                              <1> 	;        cf = 1 -> Error code in EAX (AL) 
  2659                              <1> 	;
  2660                              <1> 	;  (EDX, ECX, EBX, ESI, EDI will be changed)
  2661                              <1> 
  2662 0000AD53 3C02                <1> 	cmp	al, 2
  2663 0000AD55 0F847F010000        <1> 	je	msftdf_df2_check_directory
  2664 0000AD5B A2[4E640100]        <1> 	mov	[move_cmd_phase], al
  2665                              <1> 
  2666                              <1> msftdf_parse_sf_path:
  2667                              <1> 	; ESI = ASCIIZ pathname (Source)
  2668 0000AD60 57                  <1> 	push	edi 
  2669 0000AD61 BF[4C630100]        <1> 	mov	edi, SourceFile_Drv
  2670 0000AD66 E824F7FFFF          <1> 	call	parse_path_name
  2671 0000AD6B 5E                  <1> 	pop	esi
  2672 0000AD6C 7211                <1> 	jc	short msftdf_psf_retn
  2673                              <1> 
  2674                              <1> msftdf_parse_df_path:
  2675                              <1> 	; ESI = ASCIIZ pathname	(Destination)
  2676 0000AD6E BF[CC630100]        <1> 	mov	edi, DestinationFile_Drv
  2677 0000AD73 E817F7FFFF          <1> 	call	parse_path_name
  2678 0000AD78 7306                <1> 	jnc	short msftdf_check_sf_drv
  2679                              <1> 
  2680 0000AD7A 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  2681 0000AD7C 7602                <1> 	jna	short msftdf_check_sf_drv
  2682                              <1> 
  2683                              <1> msftdf_stc_retn:
  2684 0000AD7E F9                  <1> 	stc
  2685                              <1> msftdf_psf_retn:
  2686 0000AD7F C3                  <1> 	retn 
  2687                              <1> 
  2688                              <1> msftdf_check_sf_drv:
  2689 0000AD80 A0[4C630100]        <1> 	mov	al, [SourceFile_Drv]
  2690                              <1> 
  2691                              <1> msftdf_check_df_drv:
  2692 0000AD85 8A15[CC630100]      <1> 	mov	dl, [DestinationFile_Drv]
  2693                              <1> 
  2694                              <1> msftdf_compare_sf_df_drv:
  2695 0000AD8B 29DB                <1> 	sub	ebx, ebx
  2696 0000AD8D 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  2697 0000AD93 38C2                <1> 	cmp	dl, al
  2698 0000AD95 7409                <1> 	je	short msftdf_check_sf_df_drv_ok
  2699                              <1> 
  2700                              <1> msftdf_not_same_drv:
  2701                              <1>         ; DL = source file's drive number
  2702 0000AD97 88C6                <1> 	mov	dh, al ; destination file's drive number
  2703                              <1> 	; 15/10/2016 (11h -> 21)
  2704 0000AD99 B815000000          <1> 	mov	eax, 21 ; Not the same drive
  2705 0000AD9E F9                  <1> 	stc
  2706 0000AD9F C3                  <1> 	retn 
  2707                              <1> 
  2708                              <1> msftdf_check_sf_df_drv_ok:
  2709 0000ADA0 8815[4F640100]      <1> 	mov	[msftdf_sf_df_drv], dl
  2710                              <1> 
  2711 0000ADA6 29C0                <1>         sub	eax, eax
  2712 0000ADA8 88D4                <1> 	mov	ah, dl
  2713 0000ADAA 0500010900          <1> 	add	eax, Logical_DOSDisks
  2714 0000ADAF A3[50640100]        <1> 	mov	[msftdf_drv_offset], eax
  2715                              <1> 
  2716 0000ADB4 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  2717 0000ADB6 7407                <1> 	je	short msftdf_df_check_directory
  2718                              <1> 
  2719                              <1> msftdf_change_drv:
  2720 0000ADB8 E85EC1FFFF          <1> 	call 	change_current_drive
  2721 0000ADBD 726D                <1> 	jc	short msftdf_df_error_retn
  2722                              <1> 	  
  2723                              <1> msftdf_check_destination_file:
  2724                              <1> msftdf_df_check_directory:
  2725 0000ADBF BE[CD630100]        <1> 	mov	esi, DestinationFile_Directory
  2726 0000ADC4 803E20              <1> 	cmp	byte [esi], 20h
  2727 0000ADC7 760F                <1> 	jna	short msftdf_df_find_1
  2728                              <1> 
  2729                              <1> msftdf_df_change_directory:
  2730 0000ADC9 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  2731 0000ADCF 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2732 0000ADD1 E8A3F0FFFF          <1> 	call	change_current_directory
  2733 0000ADD6 7254                <1> 	jc	short msftdf_df_error_retn
  2734                              <1> 
  2735                              <1> ;msftdf_df_change_prompt_dir_string:
  2736                              <1> ;	call 	change_prompt_dir_string
  2737                              <1> 
  2738                              <1> msftdf_df_find_1:
  2739 0000ADD8 BE[0E640100]        <1>         mov     esi, DestinationFile_Name
  2740 0000ADDD 803E20              <1> 	cmp	byte [esi], 20h
  2741 0000ADE0 7631                <1> 	jna	short msftdf_df_copy_sf_name
  2742                              <1> 
  2743                              <1> msftdf_df_find_2:
  2744 0000ADE2 6631C0              <1> 	xor	ax, ax ; DestinationFile_AttributesMask -> any/zero
  2745 0000ADE5 E8D4D4FFFF          <1> 	call	find_first_file
  2746 0000ADEA 0F838D000000        <1> 	jnc	msftdf_permission_denied_retn
  2747                              <1> 
  2748                              <1> msftdf_df_check_error_code:
  2749                              <1> 	;cmp	eax, 2 ; File not found error
  2750 0000ADF0 3C02                <1> 	cmp	al, 2
  2751 0000ADF2 7537                <1> 	jne	short msftdf_df_stc_retn
  2752                              <1>               
  2753                              <1> msftdf_df_check_fname:
  2754                              <1> 	; 15/10/2016
  2755 0000ADF4 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name ; *
  2756 0000ADF9 E87ED8FFFF          <1> 	call	check_filename
  2757 0000ADFE 7307                <1> 	jnc	short msftdf_convert_df_direntry_name
  2758                              <1> 	; invalid file name chars !
  2759 0000AE00 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME  ; 26
  2760 0000AE05 EB24                <1> 	jmp	short msftdf_df_stc_retn
  2761                              <1> 
  2762                              <1> msftdf_convert_df_direntry_name:
  2763                              <1> 	; mov	esi, DestinationFile_Name ; *
  2764 0000AE07 BF[1E640100]        <1> 	mov	edi, DestinationFile_DirEntry
  2765 0000AE0C E8B3F5FFFF          <1> 	call	convert_file_name
  2766 0000AE11 EB1A                <1>   	jmp	short msftdf_restore_current_dir_1
  2767                              <1> 
  2768                              <1> msftdf_df_copy_sf_name:
  2769 0000AE13 89F7                <1> 	mov	edi, esi
  2770 0000AE15 57                  <1> 	push	edi 
  2771 0000AE16 BE[8E630100]        <1>         mov     esi, SourceFile_Name
  2772 0000AE1B B90C000000          <1> 	mov	ecx, 12
  2773                              <1> msftdf_df_copy_sf_name_loop:
  2774 0000AE20 AC                  <1> 	lodsb
  2775 0000AE21 AA                  <1>         stosb
  2776 0000AE22 08C0                <1> 	or	al, al
  2777 0000AE24 7402                <1> 	jz	short msftdf_df_copy_sf_name_ok	
  2778 0000AE26 E2F8                <1>         loop    msftdf_df_copy_sf_name_loop
  2779                              <1> msftdf_df_copy_sf_name_ok:	
  2780 0000AE28 5E                  <1> 	pop	esi  
  2781 0000AE29 EBB7                <1> 	jmp	short msftdf_df_find_2
  2782                              <1> 
  2783                              <1> msftdf_df_stc_retn:
  2784 0000AE2B F9                  <1> 	stc
  2785                              <1> msftdf_restore_cdir_failed:
  2786                              <1> msftdf_df_error_retn:
  2787 0000AE2C C3                  <1> 	retn
  2788                              <1> 
  2789                              <1> msftdf_restore_current_dir_1:
  2790 0000AE2D 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2791 0000AE34 760D                <1> 	jna	short msftdf_sf_check_directory
  2792 0000AE36 8B35[50640100]      <1> 	mov	esi, [msftdf_drv_offset] 
  2793 0000AE3C E891C1FFFF          <1> 	call	restore_current_directory
  2794 0000AE41 72E9                <1> 	jc	short msftdf_restore_cdir_failed
  2795                              <1> 
  2796                              <1> msftdf_sf_check_directory:
  2797 0000AE43 BE[4D630100]        <1> 	mov	esi, SourceFile_Directory
  2798 0000AE48 803E20              <1> 	cmp	byte [esi], 20h
  2799 0000AE4B 760F                <1> 	jna	short msftdf_sf_find
  2800                              <1> msftdf_sf_change_directory:
  2801 0000AE4D FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  2802 0000AE53 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2803 0000AE55 E81FF0FFFF          <1> 	call	change_current_directory
  2804 0000AE5A 7227                <1> 	jc	short msftdf_return
  2805                              <1> 
  2806                              <1> ;msftdf_sf_change_prompt_dir_string:
  2807                              <1> ;	call	change_prompt_dir_string
  2808                              <1> 
  2809                              <1> msftdf_sf_find:
  2810 0000AE5C BE[8E630100]        <1>         mov     esi, SourceFile_Name  ; Offset 66
  2811 0000AE61 66B80018            <1> 	mov	ax, 1800h ; Only files
  2812 0000AE65 E854D4FFFF          <1> 	call	find_first_file
  2813 0000AE6A 7217                <1> 	jc	short msftdf_return
  2814                              <1> 
  2815                              <1> msftdf_sf_ambgfn_check:
  2816 0000AE6C 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  2817 0000AE6F 7407                <1> 	jz	short msftdf_sf_found
  2818                              <1> 
  2819                              <1> msftdf_ambiguous_file_name_error:
  2820 0000AE71 B802000000          <1> 	mov	eax, 2 ; File not found error
  2821 0000AE76 F9                  <1> 	stc
  2822 0000AE77 C3                  <1> 	retn
  2823                              <1> 
  2824                              <1> msftdf_sf_found:
  2825 0000AE78 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
  2826 0000AE7B 7416                <1> 	jz	short msftdf_save_sf_structure
  2827                              <1> 
  2828                              <1> msftdf_permission_denied_retn:
  2829 0000AE7D B805000000          <1> 	mov	eax, 05h ; Access (Permission) denied !
  2830 0000AE82 F9                  <1> 	stc
  2831                              <1> msftdf_rest_cdir_err_retn:
  2832                              <1> msftdf_return:
  2833 0000AE83 C3                  <1> 	retn
  2834                              <1> 
  2835                              <1> msftdf_phase_1_return:
  2836 0000AE84 31C0                <1> 	xor	eax, eax
  2837 0000AE86 A2[4E640100]        <1> 	mov	[move_cmd_phase], al ; 0
  2838 0000AE8B FEC0                <1> 	inc	al ; mov al, 1
  2839 0000AE8D BB[DAAE0000]        <1> 	mov	ebx, msftdf_df2_check_directory
  2840                              <1> 	;mov	edx, 0FFFFFFFFh 
  2841 0000AE92 C3                  <1> 	retn
  2842                              <1> 
  2843                              <1> msftdf_save_sf_structure:
  2844 0000AE93 BE[58620100]        <1> 	mov	esi, FindFile_DirEntry
  2845 0000AE98 BF[9E630100]        <1> 	mov	edi, SourceFile_DirEntry
  2846 0000AE9D B908000000          <1> 	mov	ecx, 8
  2847 0000AEA2 F3A5                <1> 	rep	movsd
  2848                              <1> 
  2849                              <1> msftdf_df_copy_sf_parameters:
  2850 0000AEA4 BE0B000000          <1> 	mov	esi, 11
  2851 0000AEA9 89F7                <1> 	mov	edi, esi
  2852 0000AEAB 81C6[9E630100]      <1> 	add	esi, SourceFile_DirEntry
  2853 0000AEB1 81C7[1E640100]      <1> 	add	edi, DestinationFile_DirEntry
  2854                              <1> 	;mov	ecx, 21
  2855 0000AEB7 B115                <1> 	mov	cl, 21
  2856 0000AEB9 F3A4                <1> 	rep	movsb
  2857                              <1> 
  2858                              <1> msftdf_restore_current_dir_2:
  2859 0000AEBB 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2860 0000AEC2 760D                <1> 	jna	short msftdf_df2_check_move_cmd_phase
  2861 0000AEC4 8B35[50640100]      <1>  	mov	esi, [msftdf_drv_offset]
  2862 0000AECA E803C1FFFF          <1> 	call	restore_current_directory
  2863 0000AECF 72B2                <1> 	jc	short msftdf_rest_cdir_err_retn
  2864                              <1> 
  2865                              <1> msftdf_df2_check_move_cmd_phase:
  2866 0000AED1 803D[4E640100]01    <1> 	cmp	byte [move_cmd_phase], 1
  2867 0000AED8 74AA                <1> 	je	short msftdf_phase_1_return
  2868                              <1> 
  2869                              <1> msftdf_df2_check_directory:
  2870 0000AEDA BE[CD630100]        <1> 	mov	esi, DestinationFile_Directory
  2871 0000AEDF 803E20              <1> 	cmp	byte [esi], 20h
  2872 0000AEE2 760F                <1> 	jna	short msftdf_make_dfde_locate_ffe_on_directory
  2873                              <1> msftdf_df2_change_directory:
  2874 0000AEE4 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  2875 0000AEEA 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2876 0000AEEC E888EFFFFF          <1> 	call	change_current_directory
  2877 0000AEF1 7290                <1> 	jc	short msftdf_return
  2878                              <1> 
  2879                              <1> ;msftdf_df2_change_prompt_dir_string:
  2880                              <1> ;	call	change_prompt_dir_string
  2881                              <1> 
  2882                              <1> msftdf_make_dfde_locate_ffe_on_directory:
  2883                              <1> 	; Current directory fcluster <> Directory buffer cluster
  2884                              <1> 	; Current directory will be reloaded by
  2885                              <1> 	; 'locate_current_dir_file' procedure
  2886                              <1> 	;
  2887                              <1> 	;xor	ax, ax
  2888 0000AEF3 31C0                <1> 	xor	eax, eax
  2889 0000AEF5 89C1                <1> 	mov	ecx, eax
  2890 0000AEF7 6649                <1> 	dec	cx ; FFFFh  
  2891                              <1> 		; CX = FFFFh -> find first deleted or free entry
  2892                              <1> 		; ESI would be ASCIIZ filename address if the call
  2893                              <1> 		; would not be for first free or deleted dir entry  
  2894 0000AEF9 E8CFF1FFFF          <1> 	call	locate_current_dir_file
  2895 0000AEFE 733F                <1> 	jnc	msftdf_make_dfde_set_ff_dir_entry
  2896                              <1> 	
  2897                              <1> 	;cmp	eax, 2
  2898 0000AF00 3C02                <1>         cmp	al, 2
  2899 0000AF02 7537                <1> 	jne	short msftdf_error_retn
  2900                              <1> 
  2901                              <1> msftdf_add_new_dir_entry_check_fs:
  2902 0000AF04 8B35[50640100]      <1> 	mov	esi, [msftdf_drv_offset]
  2903 0000AF0A A1[91600100]        <1> 	mov 	eax, [DirBuff_Cluster]
  2904 0000AF0F 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2905 0000AF13 7711                <1> 	ja	short msftdf_add_new_subdir_cluster
  2906                              <1> 
  2907                              <1> msftdf_add_new_fs_subdir_section:
  2908                              <1> 	;CL=0, CH=E5h --> deleted entry, CH=0 --> free entry
  2909                              <1>         ;xor	cx, cx
  2910 0000AF15 30ED                <1> 	xor	ch, ch ; cx = 0 --> add a new subdir section
  2911 0000AF17 E8830C0000          <1> 	call	add_new_fs_section
  2912 0000AF1C 721E                <1>         jc	short msftdf_dsfde_error_retn
  2913                              <1> 	;mov	[createfile_LastDirCluster], eax
  2914                              <1> 
  2915 0000AF1E E8A30E0000          <1> 	call	load_FS_sub_directory 
  2916                              <1> 	;mov	ebx, Directory_Buffer 
  2917 0000AF23 7318                <1> 	jnc	short msftdf_add_new_fs_subdir_section_ok
  2918 0000AF25 C3                  <1> 	retn	 
  2919                              <1> 
  2920                              <1> msftdf_add_new_subdir_cluster:
  2921 0000AF26 E881150000          <1> 	call	add_new_cluster
  2922 0000AF2B 720F                <1> 	jc	short msftdf_dsfde_error_retn
  2923                              <1> 	
  2924                              <1> 	;mov	[createfile_LastDirCluster], eax
  2925                              <1> 
  2926 0000AF2D E8570E0000          <1> 	call	load_FAT_sub_directory
  2927 0000AF32 7309                <1> 	jnc	short msftdf_add_new_subdir_cluster_ok
  2928                              <1> 	; EBX = Directory buffer address
  2929                              <1> 
  2930                              <1> msftdf_ansdc_update_parent_dir_lmdt:
  2931                              <1> msftdf_make_dfde_err_upd_pdir_lmdt:
  2932 0000AF34 50                  <1> 	push	eax
  2933 0000AF35 E854FAFFFF          <1> 	call	update_parent_dir_lmdt
  2934 0000AF3A 58                  <1> 	pop	eax
  2935                              <1> 
  2936                              <1> msftdf_error_retn:
  2937 0000AF3B F9                  <1> 	stc
  2938                              <1> msftdf_dsfde_restore_cdir_failed:
  2939                              <1> msftdf_dsfde_error_retn:
  2940 0000AF3C C3                  <1> 	retn
  2941                              <1> 
  2942                              <1> msftdf_add_new_fs_subdir_section_ok:
  2943                              <1> msftdf_add_new_subdir_cluster_ok:
  2944 0000AF3D 89DF                <1> 	mov	edi, ebx ; Directory buffer address
  2945                              <1> 
  2946                              <1> msftdf_make_dfde_set_ff_dir_entry:
  2947 0000AF3F 8B15[68590100]      <1> 	mov	edx, [Current_Dir_FCluster]
  2948 0000AF45 8915[B4640100]      <1> 	mov	[createfile_FFCluster], edx
  2949                              <1> 	; EDI = Directory entry offset
  2950 0000AF4B BE[1E640100]        <1> 	mov	esi, DestinationFile_DirEntry
  2951 0000AF50 B908000000          <1> 	mov	ecx, 8
  2952 0000AF55 F3A5                <1> 	rep	movsd
  2953                              <1> 
  2954 0000AF57 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  2955 0000AF5E E890F9FFFF          <1> 	call	save_directory_buffer
  2956 0000AF63 72CF                <1> 	jc	short msftdf_make_dfde_err_upd_pdir_lmdt
  2957                              <1> 
  2958                              <1> msftdf_make_dfde_update_pdir_lmdt:
  2959 0000AF65 E824FAFFFF          <1> 	call	update_parent_dir_lmdt
  2960                              <1> 
  2961                              <1> msftdf_dsfde_restore_current_dir_1:
  2962 0000AF6A 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2963 0000AF71 760D                <1> 	jna	short msftdf_dsfde_check_directory
  2964 0000AF73 8B35[50640100]      <1>  	mov	esi, [msftdf_drv_offset]
  2965 0000AF79 E854C0FFFF          <1> 	call	restore_current_directory
  2966 0000AF7E 72BC                <1> 	jc	short msftdf_dsfde_restore_cdir_failed
  2967                              <1> 
  2968                              <1> msftdf_dsfde_check_directory:
  2969 0000AF80 BE[4D630100]        <1> 	mov	esi, SourceFile_Directory
  2970 0000AF85 803E20              <1> 	cmp	byte [esi], 20h
  2971 0000AF88 760F                <1> 	jna	short msftdf_dsfde_find_file
  2972                              <1> 
  2973                              <1> msftdf_dsfde_change_directory:
  2974 0000AF8A FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  2975 0000AF90 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
  2976 0000AF92 E8E2EEFFFF          <1> 	call	change_current_directory
  2977 0000AF97 72A3                <1> 	jc	short msftdf_dsfde_error_retn
  2978                              <1> 
  2979                              <1> ;msftdf_dsfde_sf_change_prompt_dir_string:
  2980                              <1> ;	call	change_prompt_dir_string
  2981                              <1> 
  2982                              <1> msftdf_dsfde_find_file:
  2983 0000AF99 BE[8E630100]        <1> 	mov	esi, SourceFile_Name  ; Offset 66
  2984 0000AF9E 668B460E            <1> 	mov	ax, [esi+14] ; 80 -> SourceFile_AttributesMask
  2985 0000AFA2 E817D3FFFF          <1> 	call	find_first_file
  2986 0000AFA7 7293                <1> 	jc	short msftdf_dsfde_error_retn
  2987                              <1> 
  2988                              <1> msftdf_dsfde_delete_direntry:
  2989 0000AFA9 8B35[50640100]      <1> 	mov	esi, [msftdf_drv_offset]
  2990                              <1> 	
  2991 0000AFAF 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2992 0000AFB3 770A                <1> 	ja	short msftdf_delete_FAT_direntry
  2993                              <1> 	
  2994 0000AFB5 30DB                <1> 	xor	bl, bl
  2995                              <1> 	; BL = 0 -> File
  2996                              <1> 	; EDI -> Directory buffer entry offset/address 
  2997 0000AFB7 E8E40B0000          <1> 	call	delete_fs_directory_entry
  2998 0000AFBC 7315                <1> 	jnc	short msftdf_dsfde_restore_current_dir_2
  2999 0000AFBE C3                  <1> 	retn
  3000                              <1> 
  3001                              <1> msftdf_delete_FAT_direntry:	
  3002 0000AFBF 8A1D[55620100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  3003 0000AFC5 668B0D[80620100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  3004                              <1> 	; ESI = Logical DOS drive description table address
  3005                              <1> 	; EDI = Directory buffer entry offset/address 
  3006 0000AFCC E89AFCFFFF          <1> 	call	delete_directory_entry
  3007 0000AFD1 721C                <1> 	jc	short msftdf_retn
  3008                              <1> 
  3009                              <1> msftdf_dsfde_restore_current_dir_2:
  3010 0000AFD3 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3011 0000AFDA 7607                <1> 	jna	short msftdf_new_dir_fcluster_retn
  3012                              <1> 	;mov	esi, [msftdf_drv_offset]
  3013 0000AFDC E8F1BFFFFF          <1> 	call	restore_current_directory
  3014 0000AFE1 720C                <1> 	jc	short msftdf_retn
  3015                              <1> 
  3016                              <1> msftdf_new_dir_fcluster_retn:
  3017 0000AFE3 31C9                <1> 	xor	ecx, ecx 
  3018 0000AFE5 A1[B4640100]        <1> 	mov	eax, [createfile_FFCluster]
  3019 0000AFEA BB[CC630100]        <1> 	mov	ebx, DestinationFile_Drv
  3020                              <1> 
  3021                              <1> msftdf_retn:
  3022 0000AFEF C3                  <1> 	retn
  3023                              <1> 
  3024                              <1> 
  3025                              <1> copy_source_file_to_destination_file:
  3026                              <1> 	; 17/10/2016
  3027                              <1> 	; 16/10/2016
  3028                              <1> 	; 15/10/2016
  3029                              <1> 	; 30/03/2016, 31/03/2016
  3030                              <1> 	; 24/03/2016, 25/03/2016, 28/03/2016
  3031                              <1> 	; 21/03/2016, 22/03/2016, 23/03/2016
  3032                              <1> 	; 16/03/2016, 17/03/2016, 18/03/2016
  3033                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
  3034                              <1> 	; 02/09/2011 (FILE.ASM 'copy_source_file_to_destination_file')
  3035                              <1> 	; 01/08/2010 - 18/05/2011
  3036                              <1> 	;
  3037                              <1> 	;   Command Interpreter phase 1 enter ->
  3038                              <1> 	;           AL = 1 -> Caller is command interpreter
  3039                              <1> 	;           AL = 2 -> The second call, re-enter/continue
  3040                              <1> 	;   Phase 1 -> Check source file
  3041                              <1> 	;              'found' is required
  3042                              <1> 	;   Phase 2 -> Check destination file, 
  3043                              <1> 	;              save 'found' or 'not found' status
  3044                              <1> 	;              'permission denied' error will be return
  3045                              <1> 	;              if attributes have not for ordinary file 
  3046                              <1> 	;              without readonly attribute
  3047                              <1> 	;   Command Interpreter phase 1 return ->
  3048                              <1> 	;              DH = Source file attributes
  3049                              <1> 	;              DL = Destination file found status
  3050                              <1> 	;              EAX = 0 
  3051                              <1> 	;   Command Interpreter phase 2 enter ->
  3052                              <1> 	;              AL = 2 -> Continue from the last position
  3053                              <1> 	;              AH = 
  3054                              <1> 	;   Phase 3 -> Load source file or use read/write cluster method
  3055                              <1> 	;   Phase 4 -> Create destination file if it is not found
  3056                              <1> 	;   Phase 5 -> Open destination file
  3057                              <1> 	;   Phase 6 -> Read from source and write to destination
  3058                              <1> 	;   Phase 7 -> Unload source file, if it is loaded at memory
  3059                              <1> 	;       cf = 1 causes to return before the phase 7
  3060                              <1> 	;              but loaded file will be unloaded
  3061                              <1> 	;	       (allocated memory block will be deallocated) 
  3062                              <1> 	;
  3063                              <1> 	; INPUT -> 
  3064                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  3065                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  3066                              <1> 	;        AL = 0 --> Interrupt (System call)
  3067                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  3068                              <1> 	;        AL = 1 --> Question Phase
  3069                              <1> 	;        AL = 2 --> Progress Phase        
  3070                              <1> 	;
  3071                              <1> 	; OUTPUT -> 
  3072                              <1> 	;	cf = 0 -> OK
  3073                              <1> 	;	EAX = Destination file first cluster
  3074                              <1> 	;
  3075                              <1> 	;        CL > 0 if there is file reading error before EOF
  3076                              <1> 	;	        (incomplete copy) 
  3077                              <1> 	;        CH > 0 if file is (full) loaded at memory
  3078                              <1> 	;
  3079                              <1> 	;	cf = 1 -> Error code in AL (EAX) 
  3080                              <1> 	;
  3081                              <1> 	; (EBX, ECX, ESI, EDI register contents will be changed)           
  3082                              <1> 
  3083                              <1> 
  3084 0000AFF0 3C02                <1> 	cmp	al, 2
  3085 0000AFF2 0F845A020000        <1> 	je	csftdf2_check_cdrv
  3086                              <1> 
  3087                              <1> ; Phase 1
  3088                              <1> 
  3089 0000AFF8 A2[74640100]        <1> 	mov	byte [copy_cmd_phase], al
  3090                              <1> 
  3091 0000AFFD 57                  <1> 	push	edi ; *
  3092                              <1> 
  3093                              <1> csftdf_parse_sf_path:
  3094 0000AFFE BF[4C630100]        <1> 	mov	edi, SourceFile_Drv
  3095 0000B003 E887F4FFFF          <1> 	call	parse_path_name
  3096 0000B008 721C                <1> 	jc	short csftdf_parse_sf_path_failed
  3097                              <1> 
  3098                              <1> csftdf_parse_df_path:	
  3099 0000B00A 5E                  <1> 	pop	esi ; * (pushed edi) 
  3100                              <1> 
  3101                              <1> csftdf_sf_check_filename_exists:
  3102 0000B00B 803D[8E630100]21    <1> 	cmp	byte [SourceFile_Name], 21h
  3103 0000B012 7215                <1> 	jb	short csftdf_sf_file_not_found_error
  3104                              <1> 
  3105 0000B014 BF[CC630100]        <1> 	mov	edi, DestinationFile_Drv
  3106 0000B019 E871F4FFFF          <1> 	call	parse_path_name
  3107 0000B01E 7310                <1> 	jnc	short csftdf_check_sf_cdrv
  3108                              <1> 	
  3109 0000B020 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  3110 0000B022 760C                <1> 	jna	short csftdf_check_sf_cdrv
  3111                              <1> 
  3112                              <1> csftdf_parse_df_path_failed:
  3113 0000B024 F9                  <1> 	stc 
  3114                              <1> csftdf_sf_error_retn: 
  3115 0000B025 C3                  <1> 	retn
  3116                              <1> 
  3117                              <1> csftdf_parse_sf_path_failed:	
  3118 0000B026 5F                  <1> 	pop	edi ; *
  3119 0000B027 EBFC                <1> 	jmp	short csftdf_sf_error_retn
  3120                              <1> 
  3121                              <1> csftdf_sf_file_not_found_error:
  3122 0000B029 B802000000          <1> 	mov	eax, 2 ; File not found 
  3123 0000B02E EBF5                <1> 	jmp	short csftdf_sf_error_retn
  3124                              <1> 
  3125                              <1> csftdf_check_sf_cdrv:
  3126 0000B030 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  3127                              <1> 
  3128 0000B036 883D[77640100]      <1> 	mov	[csftdf_cdrv], bh ; 23/03/2016
  3129                              <1> 
  3130 0000B03C 8A15[4C630100]      <1> 	mov	dl, [SourceFile_Drv]
  3131 0000B042 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  3132 0000B044 7407                <1> 	je	short csftdf_sf_check_directory
  3133                              <1> 
  3134 0000B046 E8D0BEFFFF          <1> 	call	change_current_drive
  3135 0000B04B 72D8                <1> 	jc	short csftdf_sf_error_retn
  3136                              <1> 
  3137                              <1> csftdf_sf_check_directory:
  3138 0000B04D BE[4D630100]        <1> 	mov	esi, SourceFile_Directory
  3139 0000B052 803E20              <1> 	cmp	byte [esi], 20h
  3140 0000B055 760F                <1> 	jna	short csftdf_find_sf
  3141                              <1> 
  3142                              <1> csftdf_sf_change_directory:
  3143 0000B057 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3144 0000B05D 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  3145 0000B05F E815EEFFFF          <1> 	call	change_current_directory
  3146 0000B064 72BF                <1> 	jc	short csftdf_sf_error_retn
  3147                              <1> 
  3148                              <1> ;csftdf_sf_change_prompt_dir_string:
  3149                              <1> ;	call	change_prompt_dir_string
  3150                              <1> 
  3151                              <1> csftdf_find_sf:
  3152 0000B066 BE[8E630100]        <1> 	mov	esi, SourceFile_Name
  3153 0000B06B 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  3154 0000B06F E84AD2FFFF          <1> 	call	find_first_file
  3155 0000B074 72AF                <1> 	jc	short csftdf_sf_error_retn
  3156                              <1> 
  3157                              <1> csftdf_sf_ambgfn_check:
  3158 0000B076 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3159 0000B079 7407                <1> 	jz	short csftdf_sf_found
  3160                              <1> 
  3161                              <1> csftdf_ambiguous_file_name_error:
  3162 0000B07B B802000000          <1> 	mov	eax, 2 ; File not found error
  3163 0000B080 F9                  <1> 	stc
  3164 0000B081 C3                  <1> 	retn
  3165                              <1> 
  3166                              <1> csftdf_sf_found:
  3167 0000B082 A3[78640100]        <1> 	mov	[csftdf_filesize], eax
  3168                              <1> 
  3169 0000B087 09C0                <1> 	or	eax, eax
  3170 0000B089 7507                <1> 	jnz	short csftdf_set_source_file_direntry
  3171                              <1> 
  3172                              <1> csftdf_sf_file_size_zero:
  3173 0000B08B B814000000          <1> 	mov	eax, 20 ; TRDOS zero length (file size) error
  3174 0000B090 F9                  <1> 	stc
  3175 0000B091 C3                  <1> 	retn
  3176                              <1> 
  3177                              <1> csftdf_set_source_file_direntry:
  3178 0000B092 BE[58620100]        <1> 	mov	esi, FindFile_DirEntry
  3179 0000B097 BF[9E630100]        <1> 	mov	edi, SourceFile_DirEntry
  3180 0000B09C B908000000          <1> 	mov	ecx, 8
  3181 0000B0A1 F3A5                <1> 	rep	movsd
  3182                              <1> 
  3183                              <1> csftdf_sf_restore_cdrv:
  3184                              <1> 	; 22/03/2016
  3185 0000B0A3 8A15[77640100]      <1> 	mov	dl, [csftdf_cdrv]
  3186 0000B0A9 3A15[6E590100]      <1> 	cmp	dl, [Current_Drv]
  3187 0000B0AF 7407                <1> 	je	short csftdf_sf_restore_cdir
  3188 0000B0B1 E865BEFFFF          <1> 	call	change_current_drive 
  3189 0000B0B6 724F                <1> 	jc	short csftdf_df_error_retn ; 30/03/2016
  3190                              <1> 
  3191                              <1> csftdf_sf_restore_cdir:
  3192 0000B0B8 803D[3B0D0100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3193 0000B0BF 7612                <1> 	jna	short csftdf_df_check_filename_exists
  3194 0000B0C1 29C0                <1> 	sub	eax, eax
  3195 0000B0C3 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3196 0000B0C8 88D4                <1> 	mov	ah, dl ; byte [csftdf_cdrv]
  3197 0000B0CA 01C6                <1> 	add	esi, eax
  3198 0000B0CC E801BFFFFF          <1> 	call	restore_current_directory
  3199 0000B0D1 7234                <1> 	jc	short csftdf_df_error_retn
  3200                              <1>   
  3201                              <1> csftdf_df_check_filename_exists:
  3202 0000B0D3 803D[0E640100]20    <1> 	cmp	byte [DestinationFile_Name], 20h
  3203 0000B0DA 7716                <1> 	ja	short csftdf_check_df_cdrv
  3204                              <1> 
  3205                              <1> csftdf_copy_sf_name:
  3206 0000B0DC BF[0E640100]        <1> 	mov	edi, DestinationFile_Name
  3207 0000B0E1 BE[8E630100]        <1> 	mov	esi, SourceFile_Name
  3208 0000B0E6 B10C                <1> 	mov	cl, 12
  3209                              <1> 
  3210                              <1> csftdf_df_copy_sf_name_loop:
  3211 0000B0E8 AC                  <1> 	lodsb
  3212 0000B0E9 AA                  <1> 	stosb
  3213 0000B0EA 08C0                <1> 	or	al, al
  3214 0000B0EC 7404                <1> 	jz	short csftdf_check_df_cdrv             
  3215 0000B0EE FEC9                <1> 	dec	cl
  3216 0000B0F0 75F6                <1> 	jnz	csftdf_df_copy_sf_name_loop
  3217                              <1> 
  3218                              <1> csftdf_check_df_cdrv:
  3219 0000B0F2 8A15[CC630100]      <1> 	mov	dl, [DestinationFile_Drv]
  3220 0000B0F8 3A15[6E590100]      <1> 	cmp	dl, [Current_Drv]
  3221 0000B0FE 7408                <1> 	je	short csftdf_df_check_directory
  3222                              <1> 
  3223 0000B100 E816BEFFFF          <1> 	call	change_current_drive
  3224 0000B105 7301                <1> 	jnc	short csftdf_df_check_directory
  3225                              <1> 
  3226                              <1> csftdf_df_error_retn:
  3227 0000B107 C3                  <1> 	retn
  3228                              <1> 
  3229                              <1> csftdf_df_check_directory:
  3230 0000B108 BE[CD630100]        <1> 	mov	esi, DestinationFile_Directory
  3231 0000B10D 803E20              <1>         cmp     byte [esi], 20h
  3232 0000B110 760F                <1> 	jna	short csftdf_find_df
  3233                              <1> 
  3234                              <1> csftdf_df_change_directory:
  3235 0000B112 FE05[3B0D0100]      <1> 	inc	byte [Restore_CDIR]
  3236 0000B118 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
  3237 0000B11A E85AEDFFFF          <1> 	call	change_current_directory
  3238 0000B11F 72E6                <1> 	jc	short csftdf_df_error_retn
  3239                              <1> 
  3240                              <1> ;csftdf_df_change_prompt_dir_string:
  3241                              <1> ;	call	change_prompt_dir_string
  3242                              <1> 
  3243                              <1> csftdf_find_df:
  3244                              <1> 	; 23/03/2016
  3245 0000B121 29DB                <1> 	sub	ebx, ebx
  3246 0000B123 8A3D[CC630100]      <1> 	mov	bh,  [DestinationFile_Drv]
  3247 0000B129 81C300010900        <1> 	add	ebx, Logical_DOSDisks
  3248 0000B12F 891D[A4640100]      <1> 	mov	[csftdf_df_drv_dt], ebx
  3249                              <1> 
  3250 0000B135 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  3251 0000B13A 6631C0              <1> 	xor	ax, ax 
  3252                              <1> 		; DestinationFile_AttributesMask -> any/zero
  3253 0000B13D E87CD1FFFF          <1> 	call	find_first_file
  3254 0000B142 7218                <1> 	jc	short csftdf_df_check_error_code
  3255                              <1> 
  3256                              <1> csftdf_df_ambgfn_check:
  3257 0000B144 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3258 0000B147 752A                <1> 	jnz	short csftdf_df_error_inv_fname
  3259                              <1> 	
  3260                              <1> csftdf_df_found:
  3261 0000B149 C605[76640100]01    <1> 	mov	byte [DestinationFileFound], 1
  3262                              <1> 	; 17/10/2016 (cl -> bl)
  3263 0000B150 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
  3264 0000B153 745F                <1> 	jz	short csftdf_df_save_first_cluster
  3265                              <1> 
  3266                              <1> csftdf_df_permission_denied_retn:	 
  3267 0000B155 B805000000          <1> 	mov	eax, 05h ; Access/Permission denied.
  3268                              <1> csftdf_df_error_stc_retn:
  3269 0000B15A F9                  <1> 	stc
  3270 0000B15B C3                  <1> 	retn
  3271                              <1> 
  3272                              <1> csftdf_df_check_error_code:
  3273                              <1> 	;cmp	eax, 2
  3274 0000B15C 3C02                <1> 	cmp	al, 2
  3275 0000B15E 75FA                <1> 	jne	short csftdf_df_error_stc_retn
  3276                              <1> 
  3277 0000B160 C605[76640100]00    <1> 	mov	byte [DestinationFileFound], 0
  3278                              <1> 
  3279                              <1> 	; 15/10/2016
  3280 0000B167 BE[48620100]        <1> 	mov	esi, FindFile_Name ; *
  3281 0000B16C E80BD5FFFF          <1> 	call	check_filename
  3282 0000B171 7307                <1> 	jnc	short csftdf_df_valid_fname
  3283                              <1> csftdf_df_error_inv_fname: ; 'invalid file name !'
  3284 0000B173 B81A000000          <1> 	mov 	eax, ERR_INV_FILE_NAME  ; 26
  3285 0000B178 F9                  <1> 	stc	
  3286 0000B179 C3                  <1> 	retn
  3287                              <1> 
  3288                              <1> csftdf_df_valid_fname:	
  3289                              <1> 	; 21/03/2016
  3290                              <1> 	; (Capitalized file name)
  3291                              <1> 	;mov	esi, FindFile_Name ; * ; 15/10/2016
  3292 0000B17A BF[0E640100]        <1> 	mov	edi, DestinationFile_Name
  3293 0000B17F A5                  <1> 	movsd
  3294 0000B180 A5                  <1> 	movsd	
  3295 0000B181 A5                  <1> 	movsd
  3296                              <1> 	;movsb
  3297                              <1> 
  3298                              <1> csftdf_check_disk_free_size_0:
  3299 0000B182 A1[BA630100]        <1> 	mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3300                              <1> 
  3301                              <1> csftdf_check_disk_free_size_1:
  3302                              <1> 	;sub	ebx, ebx
  3303                              <1> 	;mov 	esi, Logical_DOSDisks
  3304                              <1> 	;mov	bh,  [DestinationFile_Drv]
  3305                              <1> 	;add	esi, ebx
  3306                              <1> 	
  3307 0000B187 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3308                              <1> 
  3309 0000B18D 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3310 0000B191 01C8                <1> 	add	eax, ecx
  3311 0000B193 48                  <1> 	dec	eax  ; file size (additional bytes) + 511 (round up)
  3312                              <1> csftdf_check_disk_free_size_3: ; 16/03/2016
  3313 0000B194 29D2                <1> 	sub	edx, edx
  3314 0000B196 F7F1                <1> 	div	ecx ; bytes per sector
  3315                              <1> 
  3316                              <1> csftdf_check_disk_free_size:
  3317 0000B198 3B4674              <1> 	cmp	eax, [esi+LD_FreeSectors]
  3318 0000B19B 0F8294000000        <1>         jb      csftdf_check_disk_free_size_ok
  3319 0000B1A1 770A                <1> 	ja	short csftdf_df_insufficient_disk_space
  3320                              <1> 
  3321 0000B1A3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0 ; FS needs FDT sector also.
  3322 0000B1A7 0F8788000000        <1>         ja      csftdf_check_disk_free_size_ok 
  3323                              <1> 
  3324                              <1> csftdf_df_insufficient_disk_space:
  3325 0000B1AD B827000000          <1> 	mov	eax, 27h ; insufficient disk space
  3326 0000B1B2 EBA6                <1> 	jmp	short csftdf_df_error_stc_retn
  3327                              <1> 
  3328                              <1> csftdf_df_save_first_cluster:
  3329                              <1> 	; ESI = FindFile_DirEntry (for the old destination file)
  3330                              <1> 	; EAX = Old destination file size
  3331                              <1> 	; 24/03/2016
  3332                              <1> 	; EDI = Directory entry address (within Dir Buffer boundaries)
  3333 0000B1B4 81EF00000800        <1> 	sub	edi, Directory_Buffer  ; (<65536)
  3334 0000B1BA 66C1EF05            <1> 	shr	di, 5 ; Convert entry offset to entry index/number
  3335 0000B1BE 66893D[46640100]    <1> 	mov	[DestinationFile_DirEntryNumber], di ; (<2048)
  3336                              <1> 
  3337                              <1> csftdf_df_check_sf_df_fcluster:
  3338 0000B1C5 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  3339 0000B1C9 C1E210              <1> 	shl	edx, 16
  3340 0000B1CC 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  3341 0000B1D0 8915[88640100]      <1> 	mov	[csftdf_df_cluster], edx
  3342                              <1> csftdf_df_check_sf_df_fcluster_1:
  3343 0000B1D6 668B15[B2630100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3344 0000B1DD C1E210              <1> 	shl	edx, 16
  3345 0000B1E0 668B15[B8630100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3346 0000B1E7 3B15[88640100]      <1> 	cmp	edx, [csftdf_df_cluster]
  3347 0000B1ED 7512                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3348                              <1> csftdf_df_check_sf_df_drv:
  3349 0000B1EF 8A15[4C630100]      <1> 	mov	dl, [SourceFile_Drv]
  3350 0000B1F5 3A15[CC630100]      <1> 	cmp	dl, [DestinationFile_Drv]
  3351 0000B1FB 7504                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3352                              <1> 
  3353                              <1> 	; source and destination files are same !
  3354                              <1> 	; (they have same first cluster value on same logical disk)
  3355                              <1> 
  3356 0000B1FD 31C0                <1> 	xor	eax, eax ; mov eax, 0 -> Bad command or file name !
  3357 0000B1FF F9                  <1> 	stc
  3358 0000B200 C3                  <1> 	retn 
  3359                              <1>    
  3360                              <1> csftdf_df_check_sf_df_fcluster_ok:
  3361                              <1> csftdf_df_move_findfile_struct:
  3362                              <1> 	; mov	esi, FindFile_DirEntry
  3363 0000B201 BF[1E640100]        <1> 	mov	edi, DestinationFile_DirEntry
  3364 0000B206 B908000000          <1> 	mov	ecx, 8
  3365 0000B20B F3A5                <1> 	rep	movsd
  3366                              <1> 	
  3367                              <1> csftdf_check_disk_free_size_2:
  3368 0000B20D 89C2                <1> 	mov	edx, eax ; Old destination file size
  3369                              <1> 
  3370                              <1> 	;mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3371 0000B20F A1[78640100]        <1> 	mov	eax, [csftdf_filesize] ; 23/03/2016
  3372                              <1> 
  3373                              <1> 	;;sub	ecx, ecx ; 0
  3374                              <1> 	;mov 	esi, Logical_DOSDisks
  3375                              <1> 	;mov	ch,  [DestinationFile_Drv]
  3376                              <1> 	;add	esi, ecx
  3377                              <1> 	;
  3378                              <1> 	;mov	[csftdf_df_drv_dt], esi
  3379                              <1> 
  3380 0000B214 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3381                              <1> 
  3382 0000B21A 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3383 0000B21E 01CA                <1> 	add	edx, ecx ; + 512
  3384 0000B220 01C8                <1> 	add	eax, ecx ; + 512
  3385 0000B222 4A                  <1> 	dec	edx ; old file size + 511 (round up)
  3386 0000B223 48                  <1> 	dec	eax ; new file size + 511 (round up)
  3387 0000B224 F7D9                <1> 	neg	ecx ; -512 ; 0FFFFFE00h
  3388 0000B226 21CA                <1> 	and	edx, ecx ; = old sector count * 512 
  3389 0000B228 21C8                <1> 	and	eax, ecx ; = new sector count * 512 
  3390                              <1> 
  3391 0000B22A 29D0                <1> 	sub	eax, edx ; new file size - old file size (on disk)
  3392 0000B22C 7607                <1> 	jna	short csftdf_check_disk_free_size_ok
  3393                              <1> 
  3394 0000B22E F7D9                <1> 	neg	ecx ; 512 (bytes per sector) ; 200h
  3395                              <1> 	; check free space for additional sectors
  3396                              <1> 	; eax = number of additional sectors * bytes per sector
  3397                              <1> 	; esi = Logical DOS drive number (of destination disk)
  3398 0000B230 E95FFFFFFF          <1>         jmp     csftdf_check_disk_free_size_3
  3399                              <1>  
  3400                              <1> csftdf_check_disk_free_size_ok:
  3401                              <1> 	; 18/03/2016
  3402                              <1> csftdf_df_check_copy_cmd_phase:
  3403 0000B235 A0[74640100]        <1> 	mov	al, [copy_cmd_phase]
  3404 0000B23A 3C01                <1> 	cmp	al, 1
  3405 0000B23C 7514                <1> 	jne	short csftdf2_check_cdrv
  3406                              <1> 	
  3407 0000B23E 31C0                <1> 	xor	eax, eax
  3408 0000B240 A2[74640100]        <1> 	mov	[copy_cmd_phase], al ; 0
  3409                              <1> 
  3410 0000B245 8A15[76640100]      <1> 	mov	dl, [DestinationFileFound]            
  3411 0000B24B 8A35[A9630100]      <1> 	mov	dh, [SourceFile_DirEntry+11] ; Attributes
  3412                              <1>  
  3413                              <1> csftdf_return:	
  3414 0000B251 C3                  <1> 	retn
  3415                              <1> 
  3416                              <1> ; Phase 2
  3417                              <1> 
  3418                              <1> csftdf2_check_cdrv:
  3419                              <1> 	; 18/03/2016
  3420                              <1> 	; Here, destination drive and directory are ready !
  3421                              <1> 	; (checking/restoring is not needed)
  3422                              <1> 	; (Since at the end of the phase 1)
  3423                              <1> 
  3424                              <1> ;	mov	dl, [DestinationFile_Drv]
  3425                              <1> ;	cmp	dl, [Current_Drv]
  3426                              <1> ;	je	short csftdf2_df_check_directory
  3427                              <1> ;
  3428                              <1> ;	call	change_current_drive
  3429                              <1> ;	jc	short csftdf2_read_error
  3430                              <1> ;
  3431                              <1> ;csftdf2_df_check_directory:
  3432                              <1> ;	mov	esi, DestinationFile_Directory  
  3433                              <1> ;	cmp	byte [esi], 20h
  3434                              <1> ;	jna	short csftdf2_df_check_found_or_not
  3435                              <1> ;
  3436                              <1> ;csftdf2_df_change_directory:
  3437                              <1> ;	inc	byte [Restore_CDIR]
  3438                              <1> ;	xor	ah, ah ; CD_COMMAND sign -> 0 
  3439                              <1> ;	call	change_current_directory
  3440                              <1> ;	jc	short csftdf2_stc_return
  3441                              <1> ;
  3442                              <1> ;;csftdf2_df_change_prompt_dir_string:
  3443                              <1> ;;	call	change_prompt_dir_string
  3444                              <1> 
  3445                              <1> csftdf2_df_check_found_or_not:
  3446                              <1> 	; 21/03/2016
  3447 0000B252 803D[76640100]00    <1> 	cmp	byte [DestinationFileFound], 0 
  3448 0000B259 7739                <1> 	ja	short csftdf2_set_sf_percentage
  3449                              <1> 
  3450                              <1> csftdf2_create_file:
  3451 0000B25B BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  3452 0000B260 A1[78640100]        <1> 	mov	eax, [csftdf_filesize]
  3453 0000B265 30C9                <1> 	xor	cl, cl ; 0
  3454                              <1> 
  3455 0000B267 31DB                <1> 	xor	ebx, ebx ; 0
  3456 0000B269 4B                  <1> 	dec	ebx ; 0FFFFFFFFh 
  3457                              <1> 
  3458                              <1> 	; INPUT ->
  3459                              <1> 	; 	EAX -> File Size
  3460                              <1> 	; 	ESI = ASCIIZ File name
  3461                              <1> 	;	 CL = File attributes
  3462                              <1> 	;	EBX = FFFFFFFFh -> empty file sign for FAT fs
  3463                              <1> 	;	EBX <> FFFFFFFFh -> use file size for FAT fs 
  3464                              <1> 	;
  3465                              <1> 	; OUTPUT ->
  3466                              <1> 	;	EAX = New file's first cluster
  3467                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  3468                              <1> 	;	EBX = CreateFile_Size address
  3469                              <1> 	;	ECX = Sectors per cluster (<256)
  3470                              <1> 	;	EDX = Directory Entry Index/Number (<65536)
  3471                              <1> 	;		
  3472                              <1> 	;	cf = 1 -> error code in AL (EAX)
  3473                              <1> 
  3474 0000B26A E8EC050000          <1> 	call	create_file
  3475                              <1> 	;pop	esi
  3476 0000B26F 0F82A3050000        <1>         jc      csftdf2_rw_error
  3477                              <1> 
  3478                              <1> csftdf2_create_file_OK:
  3479 0000B275 A3[88640100]        <1> 	mov	[csftdf_df_cluster], eax
  3480                              <1> 	
  3481                              <1> 	; 24/03/2016
  3482 0000B27A 668915[46640100]    <1> 	mov	[DestinationFile_DirEntryNumber], dx 
  3483                              <1> 
  3484                              <1> 	; 21/03/2016
  3485 0000B281 BE00000800          <1> 	mov	esi, Directory_Buffer
  3486 0000B286 C1E205              <1> 	shl	edx, 5 ; 32 * index number
  3487 0000B289 01D6                <1> 	add	esi, edx
  3488 0000B28B BF[1E640100]        <1> 	mov	edi, DestinationFile_DirEntry	
  3489 0000B290 B108                <1> 	mov	cl, 8 ; 32 bytes
  3490 0000B292 F3A5                <1> 	rep	movsd
  3491                              <1> 
  3492                              <1> csftdf2_set_sf_percentage:
  3493                              <1> 	; 17/03/2016
  3494 0000B294 31C0                <1> 	xor	eax, eax	
  3495 0000B296 A2[9C640100]        <1> 	mov 	[csftdf_percentage], al ; 0, reset
  3496                              <1> 
  3497 0000B29B A3[94640100]        <1> 	mov	[csftdf_sf_rbytes], eax ; 0, reset
  3498 0000B2A0 A3[98640100]        <1> 	mov	[csftdf_df_wbytes], eax ; 0, reset
  3499                              <1> 
  3500 0000B2A5 8A25[4C630100]      <1> 	mov	ah, [SourceFile_Drv]	
  3501 0000B2AB BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3502 0000B2B0 01C6                <1> 	add	esi, eax
  3503                              <1> 	
  3504 0000B2B2 8935[A0640100]      <1> 	mov	[csftdf_sf_drv_dt], esi ; 23/03/2016
  3505                              <1> 
  3506 0000B2B8 668B15[B2630100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3507 0000B2BF C1E210              <1> 	shl	edx, 16
  3508 0000B2C2 668B15[B8630100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3509 0000B2C9 8915[84640100]      <1> 	mov	[csftdf_sf_cluster], edx
  3510                              <1> 
  3511                              <1> 	; 16/03/2016
  3512                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3513                              <1> 	;	related calculations) has same offset
  3514                              <1> 	;	values from LD_BPB as in FAT file system.
  3515                              <1> 	;	[esi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3516                              <1> 	;	
  3517 0000B2CF 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  3518 0000B2D3 880D[CA630100]      <1> 	mov	[SourceFile_SecPerClust], cl
  3519                              <1> 
  3520                              <1> 	; 17/03/2016
  3521 0000B2D9 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
  3522 0000B2DC 7707                <1> 	ja	short csftdf2_set_sf_percent_rsize1
  3523                              <1> 
  3524 0000B2DE B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3525 0000B2E3 EB06                <1> 	jmp	short csftdf2_set_sf_percent_rsize2	
  3526                              <1>  
  3527                              <1> csftdf2_set_sf_percent_rsize1:
  3528 0000B2E5 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  3529 0000B2E9 F7E1                <1> 	mul	ecx
  3530                              <1> 	;sub	edx, edx
  3531                              <1> csftdf2_set_sf_percent_rsize2:
  3532 0000B2EB A3[8C640100]        <1> 	mov	[csftdf_r_size], eax
  3533                              <1> 
  3534                              <1> csftdf2_set_df_percentage:
  3535                              <1> 	;sub	eax, eax
  3536                              <1> 	;mov	ah, [DestinationFile_Drv]	
  3537                              <1> 	;mov	edi, Logical_DOSDisks
  3538                              <1> 	;add	edi, eax
  3539                              <1> 	;mov	[csftdf_df_drv_dt], edi ; 17/03/2016
  3540                              <1> 
  3541 0000B2F0 8B3D[A4640100]      <1> 	mov	edi, [csftdf_df_drv_dt] ; 23/03/2016
  3542                              <1> 
  3543                              <1> 	; 16/03/2016
  3544                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3545                              <1> 	;	related calculations) has same offset
  3546                              <1> 	;	values from LD_BPB as in FAT file system.
  3547                              <1> 	;	[edi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3548                              <1> 	;	
  3549                              <1> 	;movzx	ecx, byte [edi+LD_BPB+SecPerClust]
  3550 0000B2F6 8A4F13              <1> 	mov	cl, [edi+LD_BPB+SecPerClust]
  3551 0000B2F9 880D[4A640100]      <1> 	mov	[DestinationFile_SecPerClust], cl
  3552                              <1> 
  3553                              <1> 	; 17/03/2016
  3554 0000B2FF 386F03              <1> 	cmp	[edi+LD_FATType], ch ; 0
  3555 0000B302 7707                <1> 	ja	short csftdf2_set_df_percent_wsize1
  3556                              <1> 	
  3557 0000B304 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3558 0000B309 EB06                <1> 	jmp	short csftdf2_set_df_percent_wsize2	
  3559                              <1> 
  3560                              <1> csftdf2_set_df_percent_wsize1:
  3561 0000B30B 0FB74711            <1> 	movzx	eax, word [edi+LD_BPB+BytesPerSec]
  3562 0000B30F F7E1                <1> 	mul	ecx
  3563                              <1> 	;sub	edx, edx
  3564                              <1> csftdf2_set_df_percent_wsize2:
  3565 0000B311 A3[90640100]        <1> 	mov	[csftdf_w_size], eax
  3566                              <1> 
  3567 0000B316 A1[78640100]        <1> 	mov	eax, [csftdf_filesize]
  3568                              <1> 
  3569 0000B31B 3D00000100          <1> 	cmp	eax, 65536 ; 64KB	; small file
  3570 0000B320 721F                <1> 	jb	short csftdf2_load_file ; do not display percentage
  3571                              <1> 	
  3572                              <1> csftdf2_reset_wf_percent_ptr_chk_64k:
  3573 0000B322 B201                <1> 	mov	dl, 1 ; 25/03/2016
  3574                              <1> 
  3575 0000B324 3D00000400          <1> 	cmp	eax, 65536*4 ; 256KB
  3576 0000B329 7310                <1> 	jnb	short csftdf2_enable_percentage_display ; big file
  3577                              <1> 
  3578                              <1> 	; 64-128KB file size for floppy disks
  3579 0000B32B 3815[4C630100]      <1> 	cmp	byte [SourceFile_Drv], dl ; 1 ; read from floppy disk ?
  3580 0000B331 7608                <1> 	jna	short csftdf2_enable_percentage_display
  3581                              <1> 
  3582 0000B333 3815[CC630100]      <1> 	cmp	byte [DestinationFile_Drv], dl ; 1 ; write to floppy disk ?
  3583 0000B339 7706                <1> 	ja	short csftdf2_load_file
  3584                              <1> 
  3585                              <1> csftdf2_enable_percentage_display:	
  3586 0000B33B 8815[9C640100]      <1> 	mov	[csftdf_percentage], dl ; 1	
  3587                              <1> 	
  3588                              <1> csftdf2_load_file:
  3589                              <1> 	; 13/05/2016
  3590                              <1> 	; 19/03/2016
  3591                              <1> 	; 18/03/2016
  3592                              <1> 	; 17/03/2016
  3593 0000B341 B40F                <1> 	mov	ah, 0Fh
  3594 0000B343 E88261FFFF          <1> 	call	_int10h
  3595                              <1> 	; 13/05/2016
  3596 0000B348 883D[9D640100]      <1> 	mov	[csftdf_videopage], bh ; active video page
  3597 0000B34E B403                <1> 	mov	ah, 03h
  3598 0000B350 E87561FFFF          <1> 	call	_int10h
  3599 0000B355 668915[9E640100]    <1> 	mov	[csftdf_cursorpos], dx
  3600                              <1> 
  3601 0000B35C 29C0                <1> 	sub	eax, eax
  3602 0000B35E A2[75640100]        <1> 	mov	[csftdf_rw_err], al ; 0 
  3603                              <1> 
  3604                              <1> ; ///
  3605                              <1> csftdf_sf_amb: ; 15/03/2016
  3606 0000B363 8B0D[78640100]      <1> 	mov	ecx, [csftdf_filesize]	; 23/03/2016
  3607                              <1> 
  3608                              <1> 	; TRDOS 386 (TRDOS v2.0)
  3609                              <1> 	; Allocate contiguous memory block for loading the file
  3610                              <1> 	
  3611                              <1> 	;mov	ecx, [SourceFile_DirEntry+DirEntry_FileSize]
  3612                              <1> 	
  3613                              <1> 	;sub	eax, eax ; First free memory aperture
  3614                              <1> 	
  3615                              <1> 	; eax = 0 (Allocate memory from the beginning)
  3616                              <1> 	; ecx = File (Allocation) size in bytes
  3617                              <1> 	
  3618 0000B369 E8E8A0FFFF          <1> 	call	allocate_memory_block
  3619 0000B36E 7304                <1> 	jnc	short loc_check_sf_save_loading_parms
  3620                              <1> 
  3621 0000B370 29C0                <1> 	sub	eax, eax
  3622 0000B372 29C9                <1> 	sub	ecx, ecx
  3623                              <1> 	
  3624                              <1> loc_check_sf_save_loading_parms:
  3625 0000B374 A3[7C640100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  3626 0000B379 890D[80640100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  3627                              <1> ; ///   
  3628                              <1> 	; 19/03/2016
  3629 0000B37F 8B35[A0640100]      <1> 	mov	esi, [csftdf_sf_drv_dt] ; logical dos drv desc. tbl.
  3630                              <1> 
  3631                              <1> 	; 17/03/2016
  3632 0000B385 09C0                <1> 	or	eax, eax ; contiguous free memory block address 
  3633 0000B387 0F845B010000        <1>         jz      csftdf2_read_sf_cluster
  3634                              <1> 
  3635                              <1> 	; 18/03/2016
  3636 0000B38D 8B1D[7C640100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  3637                              <1> 
  3638 0000B393 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3639 0000B397 0F8605020000        <1>         jna     csftdf2_load_fs_file
  3640                              <1> 
  3641                              <1> csftdf2_load_fat_file:
  3642 0000B39D 53                  <1> 	push	ebx ; *
  3643                              <1> 
  3644                              <1> csftdf2_load_fat_file_next:
  3645 0000B39E BE[8B130100]        <1> 	mov	esi, msg_reading
  3646 0000B3A3 E8F5AFFFFF          <1> 	call	print_msg
  3647                              <1> 
  3648 0000B3A8 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3649 0000B3AF 7605                <1> 	jna	short csftdf2_load_fat_file_1
  3650                              <1> 	
  3651 0000B3B1 E87C000000          <1> 	call	csftdf2_print_percentage ; 19/03/2016
  3652                              <1> 
  3653                              <1> csftdf2_load_fat_file_1:
  3654 0000B3B6 8B35[A0640100]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
  3655 0000B3BC 5B                  <1> 	pop	ebx ; *
  3656                              <1> 
  3657                              <1> csftdf2_load_fat_file_2:
  3658 0000B3BD E8B8000000          <1> 	call	csftdf2_read_fat_file_sectors ; 19/03/2016
  3659 0000B3C2 0F8250040000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
  3660                              <1> 
  3661 0000B3C8 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3662 0000B3CA 7520                <1> 	jnz	short csftdf2_load_fat_file_ok
  3663                              <1> 
  3664 0000B3CC 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3665 0000B3D3 76E8                <1> 	jna	short csftdf2_load_fat_file_2
  3666                              <1> 
  3667 0000B3D5 53                  <1> 	push	ebx ; *	
  3668                              <1> 
  3669                              <1> 	; Set cursor position
  3670                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3671 0000B3D6 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  3672 0000B3DC 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  3673 0000B3E3 B402                <1> 	mov	ah, 2
  3674 0000B3E5 E8E060FFFF          <1> 	call	_int10h
  3675 0000B3EA EBB2                <1> 	jmp	short csftdf2_load_fat_file_next
  3676                              <1> 	
  3677                              <1> csftdf2_load_fat_file_ok:
  3678 0000B3EC 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3679 0000B3F3 0F8651020000        <1>         jna     csftdf2_save_file ; 25/03/2016
  3680                              <1> 	
  3681                              <1> 	; "Reading... 100%"
  3682 0000B3F9 BF[A3130100]        <1> 	mov	edi, percentagestr
  3683 0000B3FE B031                <1> 	mov	al, '1'
  3684 0000B400 AA                  <1> 	stosb
  3685 0000B401 B030                <1> 	mov	al, '0'
  3686 0000B403 AA                  <1> 	stosb
  3687 0000B404 AA                  <1> 	stosb
  3688                              <1> 
  3689 0000B405 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  3690 0000B40B 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  3691 0000B412 B402                <1> 	mov	ah, 2
  3692 0000B414 E8B160FFFF          <1> 	call	_int10h
  3693                              <1> 
  3694 0000B419 BE[8B130100]        <1> 	mov	esi, msg_reading
  3695 0000B41E E87AAFFFFF          <1> 	call	print_msg
  3696                              <1> 	
  3697 0000B423 BE[A3130100]        <1> 	mov	esi, percentagestr
  3698 0000B428 E870AFFFFF          <1> 	call	print_msg
  3699                              <1> 
  3700 0000B42D E918020000          <1>         jmp     csftdf2_save_file ; 25/03/2016
  3701                              <1> 
  3702                              <1> csftdf2_print_percentage:
  3703                              <1> 	; 09/12/2017
  3704                              <1> 	; 19/03/2016
  3705                              <1> 	; 18/03/2016
  3706 0000B432 B020                <1> 	mov	al, 20h
  3707 0000B434 BF[A3130100]        <1> 	mov	edi, percentagestr
  3708 0000B439 AA                  <1> 	stosb
  3709 0000B43A AA                  <1> 	stosb
  3710 0000B43B A1[94640100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  3711 0000B440 BA64000000          <1> 	mov	edx, 100
  3712 0000B445 F7E2                <1> 	mul	edx
  3713 0000B447 8B0D[78640100]      <1> 	mov	ecx, [csftdf_filesize]	
  3714 0000B44D F7F1                <1> 	div	ecx
  3715 0000B44F B10A                <1> 	mov	cl, 10
  3716 0000B451 F6F1                <1> 	div	cl
  3717 0000B453 80C430              <1> 	add	ah, '0'
  3718 0000B456 8827                <1> 	mov	[edi], ah
  3719 0000B458 20C0                <1> 	and	al, al
  3720 0000B45A 740A                <1> 	jz	short csftdf2_print_percent_1
  3721 0000B45C 4F                  <1> 	dec	edi
  3722                              <1> 	;cbw
  3723 0000B45D 28E4                <1> 	sub	ah, ah ; 09/12/2017
  3724 0000B45F F6F1                <1> 	div	cl
  3725 0000B461 80C430              <1> 	add	ah, '0'
  3726 0000B464 8827                <1> 	mov	[edi], ah
  3727                              <1> 	;and	al, al
  3728                              <1> 	;jz	short csftdf2_print_percent_1
  3729                              <1> 	;dec	edi
  3730                              <1> 	;mov	[edi], '1' ; 100%		
  3731                              <1> 
  3732                              <1> csftdf2_print_percent_1:
  3733 0000B466 BE[A3130100]        <1> 	mov	esi, percentagestr
  3734                              <1> 	;call	print_msg
  3735                              <1> 	;retn
  3736 0000B46B E92DAFFFFF          <1> 	jmp	print_msg
  3737                              <1> 
  3738                              <1> csftdf2_read_file_sectors:
  3739                              <1> 	; 19/03/2016
  3740 0000B470 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3741 0000B474 0F8627070000        <1>         jna     csftdf2_read_fs_file_sectors
  3742                              <1> 
  3743                              <1> csftdf2_read_fat_file_sectors:
  3744                              <1> 	; 19/03/2016
  3745                              <1> 	; 18/03/2016
  3746                              <1> 	; return:
  3747                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  3748                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  3749                              <1> 	;   CF = 1 -> read error (error code in AL)	
  3750                              <1> 
  3751                              <1> csftdf2_read_fat_file_secs_0:
  3752 0000B47A 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  3753 0000B480 2B15[94640100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  3754 0000B486 3B15[8C640100]      <1> 	cmp	edx, [csftdf_r_size]	
  3755 0000B48C 7306                <1> 	jnb	short csftdf2_read_fat_file_secs_1
  3756 0000B48E 8915[8C640100]      <1> 	mov	[csftdf_r_size], edx
  3757                              <1> 		
  3758                              <1> csftdf2_read_fat_file_secs_1:
  3759 0000B494 A1[8C640100]        <1> 	mov	eax, [csftdf_r_size]
  3760 0000B499 29D2                <1> 	sub	edx, edx
  3761 0000B49B 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  3762 0000B49F 01C8                <1> 	add	eax, ecx
  3763 0000B4A1 48                  <1> 	dec	eax
  3764 0000B4A2 F7F1                <1> 	div	ecx
  3765 0000B4A4 89C1                <1> 	mov	ecx, eax ; sector count
  3766 0000B4A6 A1[84640100]        <1> 	mov	eax, [csftdf_sf_cluster]
  3767                              <1> 
  3768                              <1> 	; EBX = memory block address (current)
  3769                              <1> 	
  3770 0000B4AB E821090000          <1> 	call	read_fat_file_sectors
  3771 0000B4B0 7235                <1> 	jc	short csftdf2_read_fat_file_secs_3
  3772                              <1> 
  3773                              <1> 	; EBX = next memory address
  3774                              <1> 
  3775 0000B4B2 A1[94640100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  3776 0000B4B7 0305[8C640100]      <1> 	add	eax, [csftdf_r_size]
  3777 0000B4BD 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  3778 0000B4C3 39D0                <1> 	cmp	eax, edx
  3779 0000B4C5 7320                <1> 	jnb	short csftdf2_read_fat_file_secs_3 ; edx > 0
  3780 0000B4C7 A3[94640100]        <1> 	mov	[csftdf_sf_rbytes], eax
  3781                              <1> 
  3782 0000B4CC 53                  <1> 	push	ebx ; *
  3783                              <1> 	; get next cluster (csftdf_r_size! bytes)
  3784 0000B4CD A1[84640100]        <1> 	mov	eax, [csftdf_sf_cluster]
  3785 0000B4D2 E8CC060000          <1> 	call	get_next_cluster
  3786 0000B4D7 5B                  <1> 	pop	ebx ; *
  3787 0000B4D8 7306                <1> 	jnc	short csftdf2_read_fat_file_secs_2
  3788                              <1> 
  3789                              <1> 	; 15/10/2016
  3790                              <1> 	;Disk read error instad of drv not ready err
  3791 0000B4DA B811000000          <1> 	mov	eax, 17 ; Read error !
  3792 0000B4DF C3                  <1> 	retn
  3793                              <1> 
  3794                              <1> csftdf2_read_fat_file_secs_2:
  3795 0000B4E0 29D2                <1> 	sub	edx, edx ; 0
  3796 0000B4E2 A3[84640100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  3797                              <1> 
  3798                              <1> csftdf2_read_fat_file_secs_3:
  3799 0000B4E7 C3                  <1> 	retn
  3800                              <1> 
  3801                              <1> csftdf2_read_sf_cluster:
  3802                              <1> 	; 19/03/2016
  3803 0000B4E8 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  3804                              <1> 
  3805 0000B4ED 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3806 0000B4F4 760D                <1> 	jna	short csftdf2_read_sf_clust_2
  3807                              <1> 
  3808 0000B4F6 53                  <1> 	push	ebx ; *	
  3809                              <1> 
  3810                              <1> csftdf2_read_sf_clust_next:
  3811 0000B4F7 E836FFFFFF          <1> 	call	csftdf2_print_percentage
  3812                              <1> 
  3813                              <1> csftdf2_read_sf_clust_0:
  3814 0000B4FC 8B35[A0640100]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
  3815                              <1> csftdf2_read_sf_clust_1:
  3816 0000B502 5B                  <1> 	pop	ebx ; *
  3817                              <1> 
  3818                              <1> csftdf2_read_sf_clust_2:
  3819 0000B503 89DA                <1> 	mov	edx, ebx
  3820 0000B505 0315[8C640100]      <1> 	add	edx, [csftdf_r_size]
  3821 0000B50B 81FA00000800        <1> 	cmp	edx, Cluster_Buffer + 65536
  3822 0000B511 772F                <1> 	ja	short csftdf2_write_df_cluster
  3823                              <1> 
  3824 0000B513 E858FFFFFF          <1> 	call	csftdf2_read_file_sectors ; 19/03/2016
  3825 0000B518 0F8280020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
  3826                              <1> 
  3827 0000B51E 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3828 0000B520 7520                <1> 	jnz	short csftdf2_write_df_cluster
  3829                              <1> 
  3830 0000B522 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3831 0000B529 76D8                <1> 	jna	short csftdf2_read_sf_clust_2
  3832                              <1> 
  3833 0000B52B 53                  <1> 	push	ebx ; *	
  3834                              <1> 
  3835                              <1> 	; Set cursor position
  3836                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3837 0000B52C 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  3838 0000B532 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  3839 0000B539 B402                <1> 	mov	ah, 2
  3840 0000B53B E88A5FFFFF          <1> 	call	_int10h
  3841 0000B540 EBB5                <1> 	jmp	short csftdf2_read_sf_clust_next
  3842                              <1> 
  3843                              <1> csftdf2_write_df_cluster:
  3844                              <1> 	; 19/03/2016
  3845 0000B542 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt]	
  3846 0000B548 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  3847                              <1> 
  3848                              <1> csftdf2_write_df_clust_next:
  3849 0000B54D E855000000          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
  3850 0000B552 0F8246020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
  3851                              <1> 
  3852 0000B558 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  3853 0000B55A 750A                <1> 	jnz	short csftdf2_rw_f_clust_ok
  3854                              <1> 
  3855 0000B55C 81FB00000800        <1> 	cmp	ebx, Cluster_Buffer + 65536
  3856 0000B562 72E9                <1> 	jb	short csftdf2_write_df_clust_next
  3857                              <1> 	
  3858 0000B564 EB82                <1> 	jmp	short csftdf2_read_sf_cluster
  3859                              <1>  
  3860                              <1> csftdf2_rw_f_clust_ok:
  3861 0000B566 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3862 0000B56D 0F86B2010000        <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
  3863                              <1> 
  3864                              <1> 	; "100%"
  3865 0000B573 BF[A3130100]        <1> 	mov	edi, percentagestr
  3866 0000B578 B031                <1> 	mov	al, '1'
  3867 0000B57A AA                  <1> 	stosb
  3868 0000B57B B030                <1> 	mov	al, '0'
  3869 0000B57D AA                  <1> 	stosb
  3870 0000B57E AA                  <1> 	stosb
  3871                              <1> 
  3872 0000B57F 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  3873 0000B585 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  3874 0000B58C B402                <1> 	mov	ah, 2
  3875 0000B58E E8375FFFFF          <1> 	call	_int10h
  3876                              <1> 
  3877 0000B593 BE[A3130100]        <1> 	mov	esi, percentagestr
  3878 0000B598 E800AEFFFF          <1> 	call	print_msg
  3879                              <1> 
  3880 0000B59D E983010000          <1>         jmp     csftdf2_save_fat_file_4
  3881                              <1> 
  3882                              <1> csftdf2_load_fs_file:
  3883                              <1> 	; temporary - 18/03/2016
  3884 0000B5A2 E96F020000          <1>         jmp     csftdf2_read_error
  3885                              <1> 
  3886                              <1> csftdf2_write_file_sectors:
  3887                              <1> 	; 19/03/2016
  3888 0000B5A7 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3889 0000B5AB 0F86F1050000        <1>         jna     csftdf2_write_fs_file_sectors
  3890                              <1> 
  3891                              <1> csftdf2_write_fat_file_sectors:
  3892                              <1> 	; 19/03/2016
  3893                              <1> 	; 18/03/2016
  3894                              <1> 	; return:
  3895                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  3896                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  3897                              <1> 	;   CF = 1 -> write error (error code in AL)	
  3898                              <1> 
  3899                              <1> csftdf2_write_fat_file_secs_0:
  3900 0000B5B1 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  3901 0000B5B7 2B15[98640100]      <1> 	sub	edx, [csftdf_df_wbytes]
  3902 0000B5BD 3B15[90640100]      <1> 	cmp	edx, [csftdf_w_size]	
  3903 0000B5C3 7306                <1> 	jnb	short csftdf2_write_fat_file_secs_1
  3904 0000B5C5 8915[90640100]      <1> 	mov	[csftdf_w_size], edx		
  3905                              <1> 
  3906                              <1> csftdf2_write_fat_file_secs_1:
  3907 0000B5CB A1[90640100]        <1> 	mov	eax, [csftdf_w_size]
  3908 0000B5D0 29D2                <1> 	sub	edx, edx
  3909 0000B5D2 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  3910 0000B5D6 01C8                <1> 	add	eax, ecx
  3911 0000B5D8 48                  <1> 	dec	eax
  3912 0000B5D9 F7F1                <1> 	div	ecx
  3913 0000B5DB 89C1                <1> 	mov	ecx, eax ; sector count
  3914 0000B5DD A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster]
  3915                              <1> 
  3916                              <1> 	; EBX = memory block address (current)	
  3917                              <1> 
  3918 0000B5E2 E8A20F0000          <1> 	call	write_fat_file_sectors
  3919 0000B5E7 7259                <1> 	jc	short csftdf2_write_fat_file_secs_4
  3920                              <1> 
  3921                              <1> 	; EBX = next memory address
  3922                              <1> 
  3923 0000B5E9 A1[98640100]        <1> 	mov	eax, [csftdf_df_wbytes]
  3924 0000B5EE 0305[90640100]      <1> 	add	eax, [csftdf_w_size]
  3925 0000B5F4 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  3926 0000B5FA 39D0                <1> 	cmp	eax, edx
  3927 0000B5FC 7344                <1> 	jnb	short csftdf2_write_fat_file_secs_4
  3928 0000B5FE A3[98640100]        <1> 	mov	[csftdf_df_wbytes], eax
  3929                              <1> 	;
  3930 0000B603 A3[3A640100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  3931                              <1> 
  3932 0000B608 53                  <1> 	push	ebx ; *
  3933                              <1> 
  3934 0000B609 803D[76640100]01    <1> 	cmp	byte [DestinationFileFound], 1
  3935 0000B610 7210                <1> 	jb	short csftdf2_write_fat_file_secs_2
  3936                              <1> 
  3937                              <1> 	; get next cluster (csftdf_w_size! bytes)
  3938 0000B612 A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster]
  3939 0000B617 E887050000          <1> 	call	get_next_cluster
  3940 0000B61C 731C                <1> 	jnc	short csftdf2_write_fat_file_secs_3
  3941                              <1> 
  3942 0000B61E 21C0                <1> 	and	eax, eax ; end of cluster chain!?
  3943 0000B620 7521                <1> 	jnz	short csftdf2_write_fat_file_secs_5 ; disk error !
  3944                              <1> 
  3945                              <1> csftdf2_write_fat_file_secs_2:
  3946 0000B622 A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  3947 0000B627 E8800E0000          <1> 	call	add_new_cluster		
  3948 0000B62C 7215                <1> 	jc	short csftdf2_write_fat_file_secs_5
  3949                              <1> 
  3950                              <1> 	; NOTE: Destination file size may be bigger than
  3951                              <1> 	; source file size when the last reading fails after here.
  3952                              <1> 	; (The last -empty- cluster of destination file must be 
  3953                              <1> 	; truncated and LMDT must be current date&time for partial
  3954                              <1> 	; copy result!) 
  3955 0000B62E 8B15[90640100]      <1> 	mov	edx, [csftdf_w_size] ; bytes per cluster
  3956 0000B634 0115[3A640100]      <1> 	add	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  3957                              <1> 
  3958                              <1> csftdf2_write_fat_file_secs_3:
  3959 0000B63A 5B                  <1> 	pop	ebx ; *
  3960 0000B63B 29D2                <1> 	sub	edx, edx ; 0
  3961 0000B63D A3[88640100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  3962                              <1> 
  3963                              <1> csftdf2_write_fat_file_secs_4:
  3964 0000B642 C3                  <1> 	retn
  3965                              <1> 
  3966                              <1> csftdf2_write_fat_file_secs_5:
  3967 0000B643 5B                  <1> 	pop	ebx ; *
  3968                              <1> 	; 16/10/2016 (1Dh -> 18)
  3969 0000B644 B812000000          <1> 	mov	eax, 18 ; Write error !
  3970 0000B649 C3                  <1> 	retn
  3971                              <1> 
  3972                              <1> csftdf2_save_file:
  3973                              <1> 	; 09/12/2017
  3974                              <1> 	; 25/03/2016
  3975                              <1> 	; 19/03/2016
  3976                              <1> 	; 18/03/2016
  3977 0000B64A 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; logical dos drv desc. tbl.
  3978                              <1> 
  3979 0000B650 8B1D[7C640100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  3980                              <1> 
  3981 0000B656 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3982 0000B65A 0F86F4010000        <1>         jna     csftdf2_save_fs_file
  3983                              <1> 
  3984                              <1> csftdf2_save_fat_file:
  3985 0000B660 53                  <1> 	push	ebx; *
  3986                              <1> 
  3987 0000B661 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  3988 0000B668 7724                <1> 	ja	short csftdf2_save_fat_file_0
  3989                              <1> 
  3990                              <1> 	; Set cursor position
  3991                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  3992 0000B66A 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  3993 0000B670 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  3994 0000B677 B402                <1> 	mov	ah, 2
  3995 0000B679 E84C5EFFFF          <1> 	call	_int10h
  3996                              <1> 	
  3997 0000B67E BE[97130100]        <1> 	mov	esi, msg_writing
  3998 0000B683 E815ADFFFF          <1> 	call	print_msg
  3999                              <1> 
  4000                              <1> csftdf2_save_fat_file_next:
  4001 0000B688 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 25/03/2016
  4002                              <1> 
  4003                              <1> csftdf2_save_fat_file_0:
  4004 0000B68E 5B                  <1> 	pop	ebx ; *
  4005                              <1> 
  4006                              <1> csftdf2_save_fat_file_1:
  4007 0000B68F E813FFFFFF          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016	
  4008 0000B694 0F827E010000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
  4009                              <1> 
  4010 0000B69A 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  4011 0000B69C 756D                <1>         jnz     short csftdf2_save_fat_file_3 ; 25/03/2016
  4012                              <1> 
  4013 0000B69E 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4014 0000B6A5 76E8                <1> 	jna	short csftdf2_save_fat_file_1
  4015                              <1> 
  4016 0000B6A7 B020                <1> 	mov	al, 20h
  4017 0000B6A9 BF[A3130100]        <1> 	mov	edi, percentagestr
  4018 0000B6AE AA                  <1> 	stosb
  4019 0000B6AF AA                  <1> 	stosb
  4020 0000B6B0 A1[98640100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4021 0000B6B5 BA64000000          <1> 	mov	edx, 100
  4022 0000B6BA F7E2                <1> 	mul	edx
  4023 0000B6BC 8B0D[78640100]      <1> 	mov	ecx, [csftdf_filesize]	
  4024 0000B6C2 F7F1                <1> 	div	ecx
  4025 0000B6C4 B10A                <1> 	mov	cl, 10
  4026 0000B6C6 F6F1                <1> 	div	cl
  4027 0000B6C8 80C430              <1> 	add	ah, '0'
  4028 0000B6CB 8827                <1> 	mov	[edi], ah
  4029 0000B6CD 20C0                <1> 	and	al, al
  4030 0000B6CF 740A                <1> 	jz	short csftdf2_save_fat_file_2
  4031 0000B6D1 4F                  <1> 	dec	edi
  4032                              <1> 	;cbw
  4033 0000B6D2 30E4                <1> 	xor	ah, ah ; 09/12/2017
  4034 0000B6D4 F6F1                <1> 	div	cl
  4035 0000B6D6 80C430              <1> 	add	ah, '0'
  4036 0000B6D9 8827                <1> 	mov	[edi], ah
  4037                              <1> 	;and	al, al
  4038                              <1> 	;jz	short csftdf2_save_fat_file_2
  4039                              <1> 	;dec	edi
  4040                              <1> 	;mov	[edi], '1' ; 100%		
  4041                              <1> 
  4042                              <1> csftdf2_save_fat_file_2:
  4043 0000B6DB 53                  <1> 	push	ebx ; *
  4044                              <1> 
  4045 0000B6DC E802000000          <1> 	call	csftdf2_print_wr_percentage ; 25/03/2016
  4046                              <1> 
  4047 0000B6E1 EBA5                <1>         jmp     csftdf2_save_fat_file_next
  4048                              <1> 
  4049                              <1> csftdf2_print_wr_percentage:
  4050                              <1> 	; Set cursor position
  4051                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4052 0000B6E3 8A3D[9D640100]      <1> 	mov	bh, [csftdf_videopage]
  4053 0000B6E9 668B15[9E640100]    <1> 	mov	dx, [csftdf_cursorpos]
  4054 0000B6F0 B402                <1> 	mov	ah, 2
  4055 0000B6F2 E8D35DFFFF          <1> 	call	_int10h
  4056                              <1> 
  4057 0000B6F7 BE[97130100]        <1> 	mov	esi, msg_writing
  4058 0000B6FC E89CACFFFF          <1> 	call	print_msg
  4059                              <1> 
  4060 0000B701 BE[A3130100]        <1> 	mov	esi, percentagestr
  4061                              <1> 	;call	print_msg
  4062                              <1> 	;retn
  4063 0000B706 E992ACFFFF          <1> 	jmp	print_msg
  4064                              <1> 
  4065                              <1> csftdf2_save_fat_file_3:
  4066 0000B70B 803D[9C640100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4067 0000B712 7611                <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
  4068                              <1> 
  4069                              <1> 	; "100%"
  4070 0000B714 BF[A3130100]        <1> 	mov	edi, percentagestr
  4071 0000B719 B031                <1> 	mov	al, '1'
  4072 0000B71B AA                  <1> 	stosb
  4073 0000B71C B030                <1> 	mov	al, '0'
  4074 0000B71E AA                  <1> 	stosb
  4075 0000B71F AA                  <1> 	stosb
  4076                              <1> 
  4077 0000B720 E8BEFFFFFF          <1> 	call	csftdf2_print_wr_percentage
  4078                              <1> 
  4079                              <1> csftdf2_save_fat_file_4:
  4080 0000B725 803D[76640100]00    <1> 	cmp	byte [DestinationFileFound], 0
  4081 0000B72C 7647                <1> 	jna	short csftdf2_save_fat_file_6
  4082                              <1> 
  4083 0000B72E 8B35[A4640100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 31/03/2016	
  4084                              <1> 
  4085 0000B734 A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4086 0000B739 E865040000          <1> 	call	get_next_cluster
  4087 0000B73E 7235                <1> 	jc	short csftdf2_save_fat_file_6 ; eocc! or disk error!
  4088                              <1> 
  4089 0000B740 A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4090                              <1> 	;xor	ecx, ecx
  4091                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  4092                              <1> 	;dec	ecx ; 0FFFFFFFFh
  4093                              <1> 	;shr	ecx, 4 ; 28 bit ; 0FFFFFFFh
  4094 0000B745 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
  4095 0000B74A E87E070000          <1> 	call	update_cluster
  4096 0000B74F 7224                <1> 	jc	short csftdf2_save_fat_file_6 ; really last cluster!?
  4097                              <1> 
  4098 0000B751 A3[88640100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  4099                              <1> 	
  4100                              <1> 	; byte [FAT_BuffValidData] = 2 
  4101 0000B756 E82F0A0000          <1> 	call	save_fat_buffer
  4102 0000B75B 730E                <1> 	jnc	short csftdf2_save_fat_file_5
  4103                              <1> 	
  4104 0000B75D 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  4105 0000B763 8915[3A640100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4106 0000B769 EB58                <1> 	jmp	short csftdf2_save_fat_file_err3
  4107                              <1> 
  4108                              <1> csftdf2_save_fat_file_5:
  4109 0000B76B A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster]
  4110                              <1> 
  4111                              <1> 	; EAX = First cluster to be truncated/unlinked
  4112                              <1> 	; ESI = Logical dos drive description table address
  4113 0000B770 E8580C0000          <1> 	call	truncate_cluster_chain
  4114                              <1> 
  4115                              <1> csftdf2_save_fat_file_6:
  4116                              <1> 	; 28/03/2016
  4117 0000B775 BE[A9630100]        <1> 	mov	esi, SourceFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4118 0000B77A BF[29640100]        <1> 	mov	edi, DestinationFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4119 0000B77F A4                  <1> 	movsb ; +11
  4120 0000B780 A5                  <1> 	movsd ; +12 .. +15
  4121 0000B781 66A5                <1> 	movsw ; +16 .. +17
  4122                              <1> 		; + 18
  4123 0000B783 83C604              <1> 	add	esi, 4
  4124 0000B786 83C704              <1> 	add	edi, 4
  4125 0000B789 A5                  <1> 	movsd	; DirEntry_WrtTime ; +22 .. +25
  4126                              <1> 
  4127 0000B78A 8B15[78640100]      <1> 	mov	edx, [csftdf_filesize]
  4128 0000B790 8915[3A640100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4129                              <1> 
  4130 0000B796 E8BAF0FFFF          <1> 	call	convert_current_date_time
  4131                              <1> 	; DX = Date in dos dir entry format
  4132                              <1> 	; AX = Time in dos dir entry format
  4133 0000B79B EB4D                <1> 	jmp	short csftdf2_save_fat_file_7
  4134                              <1> 
  4135                              <1> csftdf2_save_fat_file_err1:
  4136 0000B79D 5B                  <1> 	pop	ebx ; *	
  4137                              <1> csftdf2_save_fat_file_err2:
  4138 0000B79E A1[98640100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4139 0000B7A3 8B15[3A640100]      <1> 	mov	edx, [DestinationFile_DirEntry+DirEntry_FileSize]
  4140 0000B7A9 39C2                <1> 	cmp	edx, eax
  4141 0000B7AB 7616                <1> 	jna	short csftdf2_save_fat_file_err3
  4142 0000B7AD A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster] ; last (empty) cluster
  4143                              <1> 	; ESI = Logical dos drive description table address
  4144 0000B7B2 E8160C0000          <1> 	call	truncate_cluster_chain
  4145 0000B7B7 720A                <1> 	jc	short csftdf2_save_fat_file_err3
  4146 0000B7B9 A1[98640100]        <1> 	mov	eax, [csftdf_df_wbytes]	
  4147 0000B7BE A3[3A640100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  4148                              <1> csftdf2_save_fat_file_err3:
  4149 0000B7C3 E88DF0FFFF          <1> 	call	convert_current_date_time
  4150                              <1> 	; DX = Date in dos dir entry format
  4151                              <1> 	; AX = Time in dos dir entry format
  4152 0000B7C8 C605[2B640100]00    <1> 	mov	byte [DestinationFile_DirEntry+DirEntry_CrtTimeTenth], 0
  4153 0000B7CF 66A3[2C640100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtTime], ax
  4154 0000B7D5 668915[2E640100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtDate], dx		
  4155 0000B7DC 66A3[34640100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtTime], ax
  4156 0000B7E2 668915[36640100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtDate], dx
  4157 0000B7E9 F9                  <1> 	stc
  4158                              <1> csftdf2_save_fat_file_7:
  4159 0000B7EA 9C                  <1> 	pushf
  4160 0000B7EB 668915[30640100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_LastAccDate], dx
  4161 0000B7F2 BE[1E640100]        <1> 	mov	esi, DestinationFile_DirEntry
  4162 0000B7F7 BF00000800          <1> 	mov	edi, Directory_Buffer
  4163 0000B7FC 0FB70D[46640100]    <1> 	movzx	ecx, word [DestinationFile_DirEntryNumber] ; (<2048)
  4164 0000B803 66C1E105            <1> 	shl	cx, 5 ; 32 * directory entry number
  4165 0000B807 01CF                <1> 	add	edi, ecx
  4166                              <1> 	;mov	ecx, 8
  4167 0000B809 66B90800            <1> 	mov	cx, 8
  4168 0000B80D F3A5                <1> 	rep	movsd
  4169 0000B80F 9D                  <1> 	popf
  4170 0000B810 730B                <1> 	jnc	short csftdf2_write_file_OK
  4171                              <1> 	 		
  4172                              <1> csftdf2_write_error:
  4173                              <1> 	; 18/03/2016
  4174 0000B812 B01D                <1> 	mov	al, 1Dh ; write error
  4175 0000B814 EB02                <1> 	jmp	short csftdf2_rw_error
  4176                              <1> 
  4177                              <1> 	; 16/03/2016
  4178                              <1> csftdf2_read_error:
  4179 0000B816 B011                <1> 	mov	al, 17 ; ; Drive not ready or read error!
  4180                              <1> csftdf2_rw_error:
  4181 0000B818 A2[75640100]        <1> 	mov	[csftdf_rw_err], al 
  4182                              <1> 
  4183                              <1> csftdf2_write_file_OK:
  4184                              <1> 	; 18/03/2016
  4185 0000B81D C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  4186 0000B824 E8CAF0FFFF          <1> 	call	save_directory_buffer
  4187                              <1> 
  4188                              <1>  	; Update last modification date&time of destination
  4189                              <1> 	; file's (parent) directory
  4190 0000B829 E860F1FFFF          <1> 	call	update_parent_dir_lmdt
  4191                              <1> 	;
  4192 0000B82E A1[7C640100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  4193                              <1> 
  4194 0000B833 21C0                <1> 	and	eax, eax
  4195 0000B835 750E                <1> 	jnz	short csftdf2_dealloc_mblock
  4196                              <1> 
  4197 0000B837 88C5                <1> 	mov	ch, al ; 0 (Cluster r/w, not full loading)
  4198                              <1> csftdf2_dealloc_retn:
  4199 0000B839 8A0D[75640100]      <1> 	mov	cl, [csftdf_rw_err]
  4200 0000B83F A1[88640100]        <1> 	mov	eax, [csftdf_df_cluster]
  4201 0000B844 C3                  <1> 	retn
  4202                              <1> 
  4203                              <1> csftdf2_dealloc_mblock:
  4204 0000B845 8B0D[80640100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
  4205 0000B84B E8139EFFFF          <1> 	call	deallocate_memory_block
  4206 0000B850 B5FF                <1>         mov     ch, 0FFh ; (File was full loaded at memory)
  4207 0000B852 EBE5                <1> 	jmp	short csftdf2_dealloc_retn
  4208                              <1> 
  4209                              <1> csftdf2_save_fs_file:
  4210                              <1> 	; 16/10/2016 (1Dh -> 18)
  4211                              <1> 	; temporary - (21/03/2016)
  4212 0000B854 B812000000          <1> 	mov	eax, 18 ; write error
  4213 0000B859 F9                  <1> 	stc
  4214 0000B85A C3                  <1> 	retn
  4215                              <1> 
  4216                              <1> create_file:
  4217                              <1> 	; 16/10/2016
  4218                              <1> 	; 24/03/2016, 31/03/2016
  4219                              <1> 	; 20/03/2016, 21/03/2016, 23/03/2016
  4220                              <1> 	; 19/03/2016 (TRDOS 396 = TRDOS v2.0)
  4221                              <1> 	; 03/09/2011 (FILE.ASM, 'proc_create_file')
  4222                              <1> 	; 09/08/2010
  4223                              <1> 	;
  4224                              <1> 	; INPUT ->
  4225                              <1> 	; 	EAX = File Size
  4226                              <1> 	; 	ESI = ASCIIZ File Name
  4227                              <1> 	; 	CL = File Attributes 
  4228                              <1> 	;	EBX = FFFFFFFFh -> create empty file 
  4229                              <1> 	;			 (only for FAT fs) 
  4230                              <1> 	; OUTPUT ->
  4231                              <1> 	;     CF = 0 ->
  4232                              <1> 	;	EAX = New file's first cluster
  4233                              <1> 	; 	ESI = Logical Dos Drv Descr. Table Addr.
  4234                              <1> 	; 	EBX = offset CreateFile_Size
  4235                              <1> 	; 	ECX = Sectors per cluster (<256) 
  4236                              <1> 	; 	EDX = Directory entry index/number (<65536)
  4237                              <1> 	;     CF = 1 -> error code in AL
  4238                              <1> 
  4239                              <1> ;	test	cl, 18h (directory or volume name)
  4240                              <1> ;	jnz	short loc_createfile_access_denied
  4241 0000B85B 80E107              <1> 	and	cl, 07h ; S, H, R
  4242 0000B85E 880D[C4640100]      <1>         mov     [createfile_attrib], cl 
  4243                              <1> 
  4244 0000B864 89D9                <1> 	mov	ecx, ebx
  4245 0000B866 89F3                <1> 	mov	ebx, esi ; ASCIIZ File Name address
  4246 0000B868 29D2                <1> 	sub	edx, edx
  4247 0000B86A 8A35[6E590100]      <1>         mov     dh, [Current_Drv]
  4248 0000B870 BE00010900          <1>         mov     esi, Logical_DOSDisks
  4249 0000B875 01D6                <1> 	add	esi, edx
  4250                              <1> 
  4251 0000B877 8815[CF640100]      <1> 	mov	[createfile_UpdatePDir], dl ; 0 ; 31/03/2016 
  4252                              <1> 
  4253                              <1> 	; LD_DiskType = 0 for write protection (read only) 
  4254 0000B87D 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  4255 0000B881 730A                <1> 	jnb	short loc_createfile_check_file_sytem
  4256                              <1> 	; 16/10/2016 (TRDOS Error code: 30, disk write protected) 
  4257 0000B883 B81E000000          <1> 	mov	eax, 30 ; 13h, MSDOS err : Disk write-protected 
  4258 0000B888 66BA0000            <1> 	mov	dx, 0
  4259                              <1> 	; err retn: EDX = 0, EBX = File name offset
  4260                              <1> 	; ESI -> Dos drive description table address	
  4261 0000B88C C3                  <1> 	retn
  4262                              <1> 
  4263                              <1> ;loc_createfile_access_denied:
  4264                              <1> ;	mov	eax, 05h ; access denied (invalid attributes input)
  4265                              <1> ;	stc
  4266                              <1> ;	retn
  4267                              <1> 
  4268                              <1> loc_createfile_check_file_sytem:
  4269 0000B88D 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  4270 0000B891 730A                <1> 	jnb	short loc_createfile_chk_empty_FAT_file_sign1
  4271                              <1> 
  4272 0000B893 A3[B0640100]        <1> 	mov	[createfile_size], eax
  4273                              <1> 	; ESI = Logical Dos Drive Description Table address
  4274                              <1> 	; EBX = ASCIIZ File Name address
  4275 0000B898 E9FE020000          <1> 	jmp	create_fs_file
  4276                              <1> 
  4277                              <1> loc_createfile_chk_empty_FAT_file_sign1:
  4278                              <1> 	; ECX = FFFFFFFFh -> create empty file if drive has FAT fs
  4279 0000B89D 41                  <1> 	inc	ecx
  4280 0000B89E 7506                <1> 	jnz	short loc_createfile_chk_empty_FAT_file_sign2
  4281 0000B8A0 890D[B0640100]      <1> 	mov	[createfile_size], ecx ; 0 ; empty file
  4282                              <1> 
  4283                              <1> loc_createfile_chk_empty_FAT_file_sign2:
  4284                              <1> 	; 23/03/2016
  4285 0000B8A6 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec]
  4286 0000B8AA 66890D[CC640100]    <1> 	mov	[createfile_BytesPerSec], cx
  4287                              <1> 	
  4288                              <1> 	; EBX = ASCIIZ File Name address
  4289 0000B8B1 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
  4290 0000B8B5 8815[C5640100]      <1> 	mov	[createfile_SecPerClust], dl
  4291 0000B8BB 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  4292 0000B8BE 39D1                <1> 	cmp	ecx, edx ; byte [createfile_SecPerClust]
  4293 0000B8C0 7306                <1> 	jnb	short loc_create_fat_file
  4294                              <1> 	  
  4295                              <1> loc_createfile_insufficient_disk_space:
  4296 0000B8C2 B827000000          <1> 	mov	eax, 27h
  4297                              <1> loc_createfile_gffc_retn:
  4298 0000B8C7 C3                  <1> 	retn
  4299                              <1> 
  4300                              <1> loc_create_fat_file:
  4301 0000B8C8 891D[A8640100]      <1> 	mov	[createfile_Name_Offset], ebx
  4302 0000B8CE 890D[AC640100]      <1> 	mov	[createfile_FreeSectors], ecx
  4303                              <1> 
  4304                              <1> loc_createfile_gffc_1:
  4305 0000B8D4 E821050000          <1> 	call	get_first_free_cluster
  4306 0000B8D9 72EC                <1> 	jc	short loc_createfile_gffc_retn
  4307                              <1> 
  4308 0000B8DB A3[B4640100]        <1> 	mov	[createfile_FFCluster], eax
  4309                              <1> 
  4310                              <1> loc_createfile_locate_ffe_on_directory:
  4311                              <1> 	; Current directory fcluster <> Directory buffer cluster
  4312                              <1> 	; Current directory will be reloaded by
  4313                              <1> 	; 'locate_current_dir_file' procedure
  4314                              <1> 	;
  4315                              <1> 	; ESI = Logical Dos Drv Desc. Table Adress
  4316 0000B8E0 56                  <1> 	push	esi ; *
  4317 0000B8E1 31C0                <1> 	xor	eax, eax
  4318                              <1> 
  4319 0000B8E3 A3[82600100]        <1> 	mov	dword [FAT_ClusterCounter], eax ; 0
  4320                              <1> 	; 21/03/2016
  4321 0000B8E8 A2[CE640100]        <1> 	mov	byte [createfile_wfc], al ; 0 
  4322                              <1> 
  4323 0000B8ED 89C1                <1>  	mov	ecx, eax
  4324 0000B8EF 6649                <1> 	dec	cx ; FFFFh  
  4325                              <1> 	; CX = FFFFh -> find first deleted or free entry
  4326                              <1> 	; ESI would be ASCIIZ filename address if the call
  4327                              <1> 	; would not be for first free or deleted dir entry  
  4328 0000B8F1 E8D7E7FFFF          <1> 	call	locate_current_dir_file
  4329 0000B8F6 0F83EE000000        <1> 	jnc	loc_createfile_set_ff_dir_entry
  4330 0000B8FC 5E                  <1> 	pop	esi ; *
  4331                              <1> 	 ; ESI = Logical DOS Drv. Description Table Address 
  4332 0000B8FD 83F802              <1> 	cmp	eax, 2
  4333 0000B900 7402                <1> 	je	short loc_createfile_add_new_cluster
  4334                              <1> loc_createfile_locate_file_stc_retn:
  4335 0000B902 F9                  <1> 	stc
  4336 0000B903 C3                  <1> 	retn
  4337                              <1> 
  4338                              <1> loc_createfile_add_new_cluster:
  4339 0000B904 803D[6D590100]02    <1> 	cmp	byte [Current_FATType], 2
  4340                              <1> 	;cmp	byte [esi+LD_FATType], 2
  4341 0000B90B 770C                <1> 	ja	short loc_createfile_add_new_cluster_check_fsc
  4342 0000B90D 803D[6C590100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  4343                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  4344 0000B914 7303                <1> 	jnb	short loc_createfile_add_new_cluster_check_fsc
  4345                              <1> 	
  4346                              <1> 	;mov	eax, 12
  4347 0000B916 B00C                <1> 	mov	al, 12 ; No more files 
  4348                              <1> 
  4349                              <1> loc_createfile_anc_retn:
  4350 0000B918 C3                  <1> 	retn
  4351                              <1> 
  4352                              <1> loc_createfile_add_new_cluster_check_fsc:
  4353 0000B919 8B0D[AC640100]      <1> 	mov	ecx, [createfile_FreeSectors]
  4354 0000B91F 0FB605[C5640100]    <1> 	movzx	eax, byte [createfile_SecPerClust]
  4355 0000B926 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
  4356 0000B929 39C1                <1> 	cmp	ecx, eax
  4357 0000B92B 7295                <1>         jb	short loc_createfile_insufficient_disk_space
  4358                              <1> 
  4359                              <1> loc_createfile_add_new_subdir_cluster:
  4360 0000B92D 8B15[91600100]      <1> 	mov	edx, [DirBuff_Cluster]
  4361 0000B933 8915[B8640100]      <1> 	mov	[createfile_LastDirCluster], edx	
  4362                              <1> 
  4363 0000B939 A1[B4640100]        <1> 	mov	eax, [createfile_FFCluster]
  4364 0000B93E E846040000          <1> 	call	load_FAT_sub_directory 
  4365 0000B943 72D3                <1> 	jc	short loc_createfile_anc_retn
  4366                              <1> 
  4367                              <1> pass_createfile_add_new_subdir_cluster:
  4368                              <1> 	;movzx	eax, word [esi+LD_BPB+BytesPerSec]
  4369 0000B945 0FB705[CC640100]    <1> 	movzx	eax, word [createfile_BytesPerSec] ; 23/03/2016
  4370 0000B94C F7E1                <1> 	mul	ecx ; ecx = directory buffer sector count
  4371 0000B94E 89C1                <1> 	mov	ecx, eax
  4372 0000B950 C1E902              <1> 	shr	ecx, 2 ; dword count
  4373 0000B953 29C0                <1> 	sub	eax, eax ; 0
  4374 0000B955 F3AB                <1> 	rep	stosd 
  4375                              <1> 	;
  4376 0000B957 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  4377 0000B95E E890EFFFFF          <1> 	call	save_directory_buffer
  4378 0000B963 72B3                <1> 	jc	short loc_createfile_anc_retn
  4379                              <1> 
  4380                              <1> loc_createfile_save_added_subdir_cluster:
  4381 0000B965 A1[B8640100]        <1> 	mov	eax, [createfile_LastDirCluster]
  4382 0000B96A 8B0D[B4640100]      <1> 	mov	ecx, [createfile_FFCluster]
  4383 0000B970 E858050000          <1> 	call	update_cluster
  4384 0000B975 7304                <1> 	jnc	short loc_createfile_save_fat_buffer_0
  4385 0000B977 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4386 0000B979 751A                <1> 	jnz	short loc_createfile_save_fat_buffer_stc_retn
  4387                              <1> 
  4388                              <1> loc_createfile_save_fat_buffer_0:
  4389 0000B97B A1[B4640100]        <1> 	mov	eax, [createfile_FFCluster]
  4390 0000B980 A3[B8640100]        <1> 	mov	[createfile_LastDirCluster], eax
  4391 0000B985 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh ; 28 bit
  4392 0000B98A E83E050000          <1> 	call	update_cluster
  4393 0000B98F 7306                <1> 	jnc	short loc_createfile_save_fat_buffer_1
  4394 0000B991 09C0                <1> 	or	eax, eax ; Was it free cluster
  4395 0000B993 7402                <1> 	jz	short loc_createfile_save_fat_buffer_1
  4396                              <1> 
  4397                              <1> loc_createfile_save_fat_buffer_stc_retn:
  4398 0000B995 F9                  <1> 	stc
  4399                              <1> loc_createfile_save_fat_buffer_retn:
  4400                              <1> loc_createfile_gffc_2_stc_retn:
  4401 0000B996 C3                  <1> 	retn
  4402                              <1> 
  4403                              <1> loc_createfile_save_fat_buffer_1:
  4404                              <1> 	; byte [FAT_BuffValidData] = 2 
  4405 0000B997 E8EE070000          <1> 	call	save_fat_buffer
  4406 0000B99C 72F8                <1> 	jc	short loc_createfile_save_fat_buffer_retn
  4407                              <1> 
  4408 0000B99E 803D[82600100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  4409 0000B9A5 7222                <1> 	jb	short loc_createfile_save_fat_buffer_2
  4410                              <1> 
  4411                              <1> 	; ESI = Logical DOS Drive Description Table address 
  4412 0000B9A7 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4413                              <1> 
  4414 0000B9AC C605[82600100]00    <1> 	mov	byte [FAT_ClusterCounter], 0 ; 21/03/2016
  4415                              <1> 
  4416 0000B9B3 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  4417 0000B9B7 E863080000          <1> 	call	calculate_fat_freespace
  4418                              <1> 
  4419                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  4420                              <1> 	;jnz	short loc_createfile_save_fat_buffer_2
  4421                              <1> 
  4422                              <1> 	; ecx > 0 -> Recalculation is needed
  4423 0000B9BC 09C9                <1> 	or	ecx, ecx 
  4424 0000B9BE 7409                <1> 	jz	short loc_createfile_save_fat_buffer_2
  4425                              <1> 
  4426 0000B9C0 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  4427 0000B9C4 E856080000          <1> 	call	calculate_fat_freespace
  4428                              <1> 
  4429                              <1> loc_createfile_save_fat_buffer_2:
  4430                              <1> 	;call	update_parent_dir_lmdt
  4431                              <1> 
  4432                              <1> loc_createfile_gffc_2:
  4433 0000B9C9 E82C040000          <1> 	call	get_first_free_cluster
  4434 0000B9CE 72C6                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  4435                              <1> 
  4436 0000B9D0 A3[B4640100]        <1> 	mov	[createfile_FFCluster], eax
  4437                              <1> 
  4438 0000B9D5 A1[B8640100]        <1> 	mov	eax, [createfile_LastDirCluster]
  4439                              <1> 	
  4440 0000B9DA E8AA030000          <1> 	call	load_FAT_sub_directory 
  4441 0000B9DF 72B5                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  4442                              <1> 
  4443 0000B9E1 BF00000800          <1> 	mov	edi, Directory_Buffer
  4444                              <1> 
  4445 0000B9E6 6629DB              <1> 	sub	bx, bx ; directory entry index/number = 0
  4446                              <1> 
  4447 0000B9E9 56                  <1> 	push	esi ; * ; 23/03/2016
  4448                              <1> 
  4449                              <1> loc_createfile_set_ff_dir_entry:
  4450 0000B9EA 66891D[C6640100]    <1> 	mov	[createfile_DirIndex], bx
  4451                              <1> 
  4452                              <1>         ; EDI = Directory entry address
  4453 0000B9F1 8B35[A8640100]      <1> 	mov	esi, [createfile_Name_Offset]
  4454 0000B9F7 A1[B4640100]        <1> 	mov	eax, [createfile_FFCluster]
  4455 0000B9FC A3[BC640100]        <1> 	mov	[createfile_Cluster], eax ; 24/03/2016
  4456 0000BA01 B5FF                <1> 	mov	ch, 0FFh
  4457 0000BA03 8A0D[C4640100]      <1>         mov	cl, [createfile_attrib] ; file attributes
  4458                              <1> 	; CH > 0 -> File size is in [EBX]
  4459 0000BA09 BB[B0640100]        <1> 	mov	ebx, createfile_size
  4460                              <1>   
  4461 0000BA0E E803EEFFFF          <1> 	call	make_directory_entry
  4462                              <1> 	
  4463 0000BA13 5E                  <1> 	pop	esi ; * ; ESI = Logical Dos Drv Desc. Table address
  4464                              <1> 
  4465 0000BA14 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 
  4466 0000BA1B E8D3EEFFFF          <1> 	call	save_directory_buffer
  4467 0000BA20 7221                <1> 	jc	short loc_createfile_set_ff_dir_entry_retn
  4468                              <1> 
  4469 0000BA22 C605[CF640100]01    <1> 	mov	byte [createfile_UpdatePDir], 1 ; 31/03/2016 
  4470                              <1> 
  4471                              <1> loc_createfile_get_set_write_file_cluster:
  4472 0000BA29 A1[B0640100]        <1> 	mov	eax, [createfile_size]
  4473 0000BA2E 09C0                <1> 	or	eax, eax
  4474 0000BA30 7570                <1> 	jnz	short loc_createfile_get_set_wfc_cont
  4475 0000BA32 40                  <1> 	inc	eax
  4476                              <1> 	; 23/03/2016
  4477 0000BA33 0FB61D[C5640100]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
  4478                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
  4479 0000BA3A 0FB70D[CC640100]    <1>         movzx   ecx, word [createfile_BytesPerSec] ; 512
  4480 0000BA41 EB7C                <1> 	jmp	loc_createfile_set_cluster_count 
  4481                              <1> 
  4482                              <1> loc_createfile_set_ff_dir_entry_retn:
  4483 0000BA43 C3                  <1> 	retn
  4484                              <1> 
  4485                              <1> loc_createfile_write_fcluster_to_disk:
  4486 0000BA44 034668              <1> 	add	eax, [esi+LD_DATABegin] ; convert to physical address
  4487 0000BA47 BB00000700          <1> 	mov	ebx, Cluster_Buffer
  4488                              <1> 	; ESI = Logical DOS Drv. Desc. Tbl. address
  4489                              <1> 	; EAX = Disk address
  4490                              <1> 	; EBX = Sector Buffer
  4491                              <1> 	; ECX = sectors per cluster
  4492 0000BA4C E8D33D0000          <1> 	call	disk_write
  4493 0000BA51 7211                <1> 	jc	short loc_createfile_dsk_wr_err
  4494                              <1> 
  4495                              <1> loc_createfile_update_fat_cluster:
  4496                              <1> 	; 21/03/2016	
  4497 0000BA53 803D[CE640100]00    <1> 	cmp	byte [createfile_wfc], 0 
  4498 0000BA5A 7712                <1> 	ja	short loc_createfile_update_fat_cluster_n1
  4499                              <1> 
  4500 0000BA5C FE05[CE640100]      <1> 	inc	byte [createfile_wfc] ; 1
  4501 0000BA62 EB24                <1> 	jmp	short loc_createfile_update_fat_cluster_n2
  4502                              <1> 
  4503                              <1> loc_createfile_dsk_wr_err:
  4504                              <1> 	; 16/10/2016 (1Dh -> 18)
  4505                              <1> 	; 23/03/2016
  4506 0000BA64 B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error !
  4507 0000BA69 E9BD000000          <1> 	jmp	loc_createfile_stc_retn
  4508                              <1> 
  4509                              <1> loc_createfile_update_fat_cluster_n1:
  4510 0000BA6E A1[C0640100]        <1> 	mov	eax, [createfile_PCluster]
  4511 0000BA73 8B0D[BC640100]      <1> 	mov	ecx, [createfile_Cluster]
  4512 0000BA79 E84F040000          <1> 	call	update_cluster
  4513 0000BA7E 7308                <1> 	jnc	short loc_createfile_update_fat_cluster_n2
  4514 0000BA80 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4515 0000BA82 0F85A3000000        <1> 	jnz	loc_createfile_stc_retn
  4516                              <1> 
  4517                              <1> loc_createfile_update_fat_cluster_n2:
  4518 0000BA88 A1[BC640100]        <1>         mov	eax, [createfile_Cluster]
  4519 0000BA8D B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
  4520 0000BA92 E836040000          <1> 	call	update_cluster
  4521 0000BA97 734E                <1> 	jnc	short loc_createfile_save_fat_buffer_3
  4522 0000BA99 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  4523 0000BA9B 744A                <1> 	jz	short loc_createfile_save_fat_buffer_3
  4524                              <1> 
  4525                              <1> loc_createfile_upd_fat_fcluster_stc_retn:
  4526 0000BA9D E989000000          <1> 	jmp	loc_createfile_stc_retn
  4527                              <1> 
  4528                              <1> loc_createfile_get_set_wfc_cont:
  4529                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512	
  4530 0000BAA2 0FB70D[CC640100]    <1> 	movzx	ecx, word [createfile_BytesPerSec] ; 512
  4531 0000BAA9 01C8                <1> 	add	eax, ecx
  4532 0000BAAB 48                  <1> 	dec	eax  ; add eax, 511
  4533 0000BAAC 29D2                <1> 	sub	edx, edx
  4534 0000BAAE F7F1                <1> 	div	ecx
  4535 0000BAB0 0FB61D[C5640100]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
  4536 0000BAB7 01D8                <1> 	add	eax, ebx
  4537 0000BAB9 48                  <1> 	dec	eax  ; add eax, SecPerClust - 1
  4538 0000BABA 6631D2              <1> 	xor	dx, dx
  4539 0000BABD F7F3                <1> 	div	ebx
  4540                              <1> 
  4541                              <1> loc_createfile_set_cluster_count:
  4542 0000BABF A3[C8640100]        <1> 	mov 	[createfile_CCount], eax
  4543                              <1> 	
  4544 0000BAC4 BF00000700          <1> 	mov	edi, Cluster_Buffer
  4545 0000BAC9 89C8                <1> 	mov	eax, ecx ; Bytes per Sector
  4546 0000BACB F7E3                <1> 	mul	ebx ; Sectors per Cluster 
  4547                              <1> 	; EAX = Bytes per Cluster
  4548 0000BACD 89C1                <1> 	mov	ecx, eax
  4549 0000BACF C1E902              <1> 	shr	ecx, 2 ; dword count
  4550 0000BAD2 31C0                <1> 	xor	eax, eax
  4551 0000BAD4 F3AB                <1> 	rep	stosd ; clear cluster buffer
  4552                              <1> 
  4553 0000BAD6 A1[BC640100]        <1> 	mov	eax, [createfile_Cluster] ; 24/03/2016
  4554                              <1> 
  4555 0000BADB 89D9                <1> 	mov	ecx, ebx
  4556                              <1> 
  4557                              <1> loc_createfile_get_set_wf_fclust_cont:
  4558 0000BADD 83E802              <1> 	sub	eax, 2
  4559 0000BAE0 F7E1                <1> 	mul	ecx
  4560                              <1> 	; EAX = Logical DOS disk address (offset)
  4561 0000BAE2 E95DFFFFFF          <1>         jmp     loc_createfile_write_fcluster_to_disk
  4562                              <1> 
  4563                              <1> loc_createfile_save_fat_buffer_3:
  4564                              <1> 	; byte [FAT_BuffValidData] = 2
  4565 0000BAE7 E89E060000          <1> 	call	save_fat_buffer
  4566 0000BAEC 723D                <1> 	jc	loc_createfile_stc_retn
  4567                              <1> 
  4568                              <1> 	; 21/03/2016
  4569 0000BAEE 803D[82600100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  4570 0000BAF5 721B                <1> 	jb	short loc_createfile_save_fat_buffer_4
  4571                              <1> 
  4572                              <1> 	; ESI = Logical DOS Drive Description Table address 
  4573 0000BAF7 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4574 0000BAFC 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  4575 0000BB00 E81A070000          <1> 	call	calculate_fat_freespace
  4576                              <1> 
  4577                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  4578                              <1> 	;jnz	short loc_createfile_save_fat_buffer_4
  4579                              <1> 
  4580                              <1> 	; ecx > 0 -> Recalculation is needed
  4581 0000BB05 09C9                <1> 	or	ecx, ecx 
  4582 0000BB07 7409                <1> 	jz	short loc_createfile_save_fat_buffer_4
  4583                              <1> 
  4584 0000BB09 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  4585 0000BB0D E80D070000          <1> 	call	calculate_fat_freespace
  4586                              <1> 
  4587                              <1> loc_createfile_save_fat_buffer_4:
  4588 0000BB12 FF0D[C8640100]      <1> 	dec	dword [createfile_CCount]
  4589                              <1> 	;jz	short loc_createfile_upd_dir_modif_date_time
  4590 0000BB18 743F                <1> 	jz	short loc_createfile_stc_retn_cc ; 31/03/2016
  4591                              <1> 
  4592                              <1> loc_createfile_get_set_write_next_cluster:
  4593 0000BB1A E8DB020000          <1> 	call	get_first_free_cluster
  4594 0000BB1F 720A                <1> 	jc	short loc_createfile_stc_retn
  4595                              <1> 
  4596                              <1> loc_createfile_get_set_write_next_cluster_1:
  4597 0000BB21 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  4598 0000BB24 7213                <1> 	jb	short loc_createfile_get_set_write_next_cluster_2
  4599                              <1> 
  4600                              <1> loc_createfile_wnc_insufficient_disk_space:	
  4601 0000BB26 B827000000          <1> 	mov	eax, 27h ; Insufficient disk space
  4602                              <1> 
  4603                              <1> loc_createfile_stc_retn:
  4604 0000BB2B 803D[CE640100]01    <1> 	cmp	byte [createfile_wfc], 1
  4605 0000BB32 7324                <1> 	jnb	short loc_createfile_err_retn
  4606 0000BB34 C3                  <1> 	retn
  4607                              <1> 
  4608                              <1> loc_createfile_wnc_inv_format_retn:
  4609                              <1> 	;mov	eax, 28
  4610 0000BB35 B01C                <1> 	mov	al, 28 ; Invalid format
  4611 0000BB37 EBF2                <1> 	jmp	short loc_createfile_stc_retn
  4612                              <1> 	         
  4613                              <1> loc_createfile_get_set_write_next_cluster_2:
  4614 0000BB39 83F802              <1> 	cmp	eax, 2
  4615 0000BB3C 72F7                <1> 	jb	short loc_createfile_wnc_inv_format_retn
  4616                              <1> 
  4617                              <1> loc_createfile_get_set_write_next_cluster_3:
  4618 0000BB3E 8B0D[BC640100]      <1> 	mov	ecx, [createfile_Cluster]
  4619 0000BB44 A3[BC640100]        <1> 	mov	[createfile_Cluster], eax
  4620 0000BB49 890D[C0640100]      <1> 	mov	[createfile_PCluster], ecx
  4621 0000BB4F 0FB60D[C5640100]    <1> 	movzx	ecx, byte [createfile_SecPerClust]
  4622 0000BB56 EB85                <1> 	jmp	short loc_createfile_get_set_wf_fclust_cont
  4623                              <1> 
  4624                              <1> loc_createfile_err_retn:
  4625 0000BB58 F9                  <1> 	stc
  4626                              <1> 
  4627                              <1> ;loc_createfile_upd_dir_modif_date_time:
  4628                              <1> loc_createfile_stc_retn_cc: ; 31/03/2016
  4629 0000BB59 9C                  <1> 	pushf	; cpu is here for an error return or completion 
  4630 0000BB5A 50                  <1> 	push	eax ; error code if cf = 1
  4631                              <1> 
  4632                              <1> 	;call	update_parent_dir_lmdt
  4633                              <1> 
  4634                              <1> ;loc_createfile_stc_retn_cc:
  4635 0000BB5B A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  4636 0000BB60 09C0                <1> 	or	eax, eax
  4637 0000BB62 741A                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  4638 0000BB64 8A3D[6E590100]      <1> 	mov	bh, [Current_Drv]
  4639 0000BB6A B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
  4640                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  4641                              <1> 	; (If EAX value is negative, Free Cluster Count will be decreased)
  4642 0000BB6C E8AE060000          <1>   	call	calculate_fat_freespace
  4643                              <1>         ; ESI = Logical DOS Drive Description Table Address 
  4644                              <1>         ;jc	short loc_createfile_stc_retn_pop_eax_cf
  4645 0000BB71 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  4646 0000BB73 7409                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  4647                              <1> 
  4648                              <1> loc_createfile_stc_retn_recalc_FAT_freespace:
  4649 0000BB75 66BB00FF            <1> 	mov	bx, 0FF00h ; bh = 0FFh -> 
  4650                              <1> 	; ESI = Logical DOS Drv DT Addr
  4651                              <1> 	; BL = 0 -> Recalculate 
  4652 0000BB79 E8A1060000          <1> 	call	calculate_fat_freespace
  4653                              <1> 
  4654                              <1> loc_createfile_stc_retn_pop_eax:
  4655 0000BB7E 58                  <1> 	pop	eax
  4656 0000BB7F 9D                  <1> 	popf
  4657 0000BB80 7218                <1> 	jc	short loc_createfile_retn
  4658                              <1> 
  4659                              <1> loc_createfile_retn_fcluster:
  4660 0000BB82 A1[B4640100]        <1> 	mov	eax, [createfile_FFCluster]
  4661 0000BB87 BB[B0640100]        <1> 	mov	ebx, createfile_size
  4662                              <1> 	;movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  4663 0000BB8C 0FB60D[C5640100]    <1> 	movzx	ecx, byte [createfile_SecPerClust] ; 23/03/2016
  4664 0000BB93 0FB715[C6640100]    <1> 	movzx	edx, word [createfile_DirIndex]
  4665                              <1> 
  4666                              <1> loc_createfile_retn:
  4667 0000BB9A C3                  <1> 	retn
  4668                              <1> 
  4669                              <1> create_fs_file:
  4670                              <1> 	; temporary (21/03/2016)
  4671 0000BB9B C3                  <1> 	retn
  4672                              <1> 
  4673                              <1> delete_fs_file:
  4674                              <1> 	; temporary (28/02/2016)
  4675 0000BB9C C3                  <1> 	retn
  4676                              <1> 
  4677                              <1> rename_fs_file_or_directory:
  4678 0000BB9D C3                  <1> 	retn
  4679                              <1> 
  4680                              <1> make_fs_directory:
  4681                              <1> 	; temporary (21/02/2016)
  4682 0000BB9E C3                  <1> 	retn
  4683                              <1> 
  4684                              <1> add_new_fs_section:
  4685                              <1> 	; temporary (11/03/2016)
  4686 0000BB9F C3                  <1> 	retn
  4687                              <1> 
  4688                              <1> delete_fs_directory_entry:
  4689                              <1> 	; temporary (11/03/2016)
  4690 0000BBA0 C3                  <1> 	retn
  4691                              <1> 
  4692                              <1> csftdf2_read_fs_file_sectors:
  4693                              <1> 	; temporary (19/03/2016)
  4694 0000BBA1 C3                  <1> 	retn
  4695                              <1> 
  4696                              <1> csftdf2_write_fs_file_sectors:
  4697                              <1> 	; temporary (19/03/2016)
  4698 0000BBA2 C3                  <1> 	retn
  2309                                  %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: 23/10/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> 	; 15/10/2016
    17                              <1> 	; 23/03/2016
    18                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
    19                              <1> 	; 05/07/2011
    20                              <1> 	; 07/07/2009
    21                              <1> 	; 2005
    22                              <1> 	; INPUT ->
    23                              <1> 	;	EAX = Cluster Number (32 bit)
    24                              <1> 	;	ESI = Logical DOS Drive Parameters Table
    25                              <1> 	; OUTPUT ->
    26                              <1> 	;	cf = 0 -> No Error, EAX valid
    27                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
    28                              <1> 	;	cf = 1 & EAX > 0 -> Error
    29                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
    30                              <1> 	;	EAX = Next Cluster Number (32 bit)
    31                              <1> 	;
    32                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
    33                              <1> 
    34 0000BBA3 A3[76600100]        <1> 	mov	[FAT_CurrentCluster], eax
    35                              <1> check_next_cluster_fat_type:
    36 0000BBA8 29D2                <1> 	sub	edx, edx ; 0
    37 0000BBAA 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
    38 0000BBAE 7250                <1> 	jb	short get_FAT12_next_cluster
    39 0000BBB0 0F87AF000000        <1>         ja      get_FAT32_next_cluster
    40                              <1> get_FAT16_next_cluster:
    41 0000BBB6 BB00030000          <1> 	mov	ebx, 300h ;768
    42 0000BBBB F7F3                <1> 	div	ebx
    43                              <1> 	; EAX = Count of 3 FAT sectors
    44                              <1> 	; EDX = Cluster Offset (< 768)
    45 0000BBBD 66D1E2              <1> 	shl	dx, 1 ; Multiply by 2
    46 0000BBC0 89D3                <1> 	mov	ebx, edx ; Byte Offset
    47 0000BBC2 81C3001C0900        <1> 	add	ebx, FAT_Buffer
    48 0000BBC8 66BA0300            <1> 	mov	dx, 3
    49 0000BBCC F7E2                <1> 	mul	edx  
    50                              <1> 	; EAX = FAT Sector (<= 256)
    51                              <1> 	; EDX = 0
    52 0000BBCE 8A0E                <1> 	mov	cl, [esi+LD_Name]
    53 0000BBD0 803D[7A600100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
    54 0000BBD7 0F86CC000000        <1>         jna     load_FAT_sectors0
    55 0000BBDD 3A0D[7B600100]      <1> 	cmp	cl, [FAT_BuffDrvName]
    56 0000BBE3 0F85C0000000        <1>         jne     load_FAT_sectors0
    57 0000BBE9 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
    58 0000BBEF 0F85BA000000        <1>         jne     load_FAT_sectors1
    59                              <1> 	;movzx	eax, word [ebx]
    60 0000BBF5 668B03              <1> 	mov	ax, [ebx]
    61                              <1> 	; 01/02/2016
    62                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
    63                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
    64                              <1> 	; (how can i do a such mistake!?)
    65                              <1> 	;cmp	al, 0F7h
    66                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    67                              <1> 	;cmp	ah, 0FFh
    68                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    69 0000BBF8 6683F8F7            <1> 	cmp	ax, 0FFF7h
    70 0000BBFC 725A                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
    71                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
    72 0000BBFE EB56                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
    73                              <1> 
    74                              <1> get_FAT12_next_cluster:
    75 0000BC00 BB00040000          <1> 	mov	ebx, 400h ;1024
    76 0000BC05 F7F3                <1> 	div	ebx
    77                              <1> 	; EAX = Count of 3 FAT sectors
    78                              <1> 	; EDX = Cluster Offset (< 1024)
    79 0000BC07 6650                <1> 	push	ax
    80 0000BC09 66B80300            <1> 	mov	ax, 3	
    81 0000BC0D 66F7E2              <1> 	mul	dx    	; Multiply by 3
    82 0000BC10 66D1E8              <1> 	shr	ax, 1	; Divide by 2
    83 0000BC13 6689C3              <1>         mov	bx, ax 	; Byte Offset
    84 0000BC16 81C3001C0900        <1> 	add	ebx, FAT_Buffer
    85 0000BC1C 6658                <1> 	pop	ax
    86 0000BC1E 66BA0300            <1> 	mov	dx, 3
    87 0000BC22 F7E2                <1> 	mul	edx 
    88                              <1> 	; EAX = FAT Sector (<= 12)
    89                              <1> 	; EDX = 0
    90 0000BC24 8A0E                <1> 	mov	cl, [esi+LD_Name]
    91 0000BC26 803D[7A600100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
    92 0000BC2D 767A                <1> 	jna	short load_FAT_sectors0
    93 0000BC2F 3A0D[7B600100]      <1> 	cmp	cl, [FAT_BuffDrvName]
    94 0000BC35 7572                <1> 	jne	short load_FAT_sectors0
    95 0000BC37 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
    96 0000BC3D 7570                <1> 	jne	short load_FAT_sectors1
    97 0000BC3F A1[76600100]        <1> 	mov	eax, [FAT_CurrentCluster]
    98 0000BC44 66D1E8              <1> 	shr	ax, 1
    99                              <1> 	;movzx	eax, word [ebx]
   100 0000BC47 668B03              <1> 	mov	ax, [ebx]
   101 0000BC4A 7314                <1> 	jnc	short get_FAT12_nc_even
   102 0000BC4C 66C1E804            <1> 	shr	ax, 4
   103                              <1> loc_gnc_fat12_eoc_check:
   104                              <1> 	;cmp	al, 0F7h
   105                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   106                              <1> 	;cmp	ah, 0Fh
   107                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   108 0000BC50 663DF70F            <1> 	cmp	ax, 0FF7h
   109 0000BC54 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
   110                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
   111                              <1> 
   112                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
   113 0000BC56 31C0                <1> 	xor	eax, eax ; 0
   114                              <1> loc_pass_gnc_FAT16_eoc_check:
   115                              <1> loc_pass_gnc_FAT32_eoc_check:
   116 0000BC58 8B0D[76600100]      <1> 	mov	ecx, [FAT_CurrentCluster]
   117 0000BC5E F5                  <1> 	cmc
   118 0000BC5F C3                  <1> 	retn
   119                              <1> 
   120                              <1> get_FAT12_nc_even:
   121 0000BC60 80E40F              <1> 	and	ah, 0Fh
   122 0000BC63 EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
   123                              <1> 
   124                              <1> get_FAT32_next_cluster:
   125 0000BC65 BB80010000          <1> 	mov	ebx, 180h ;384
   126 0000BC6A F7F3                <1> 	div	ebx
   127                              <1> 	; EAX = Count of 3 FAT sectors
   128                              <1> 	; EDX = Cluster Offset (< 384)
   129 0000BC6C 66C1E202            <1> 	shl	dx, 2	; Multiply by 4
   130 0000BC70 89D3                <1> 	mov	ebx, edx ; Byte Offset
   131 0000BC72 81C3001C0900        <1> 	add	ebx, FAT_Buffer
   132 0000BC78 66BA0300            <1> 	mov	dx, 3
   133 0000BC7C F7E2                <1> 	mul	edx	
   134                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
   135                              <1> 	; 	for 32KB cluster size:
   136                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512 	
   137                              <1> 	; EDX = 0
   138 0000BC7E 8A0E                <1> 	mov	cl, [esi+LD_Name]
   139 0000BC80 803D[7A600100]00    <1> 	cmp	byte [FAT_BuffValidData], 0
   140 0000BC87 7620                <1> 	jna	short load_FAT_sectors0
   141 0000BC89 3A0D[7B600100]      <1> 	cmp	cl, [FAT_BuffDrvName]
   142 0000BC8F 7518                <1> 	jne	short load_FAT_sectors0
   143 0000BC91 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
   144 0000BC97 7516                <1> 	jne	short load_FAT_sectors1
   145 0000BC99 8B03                <1> 	mov	eax, [ebx]
   146 0000BC9B 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
   147 0000BCA0 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
   148 0000BCA5 72B1                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
   149                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
   150 0000BCA7 EBAD                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
   151                              <1> 
   152                              <1> load_FAT_sectors0:
   153 0000BCA9 880D[7B600100]      <1> 	mov	[FAT_BuffDrvName], cl
   154                              <1> load_FAT_sectors1:
   155 0000BCAF A3[7E600100]        <1> 	mov	[FAT_BuffSector], eax
   156 0000BCB4 89C3                <1> 	mov	ebx, eax
   157 0000BCB6 034660              <1>         add     eax, [esi+LD_FATBegin]
   158 0000BCB9 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
   159 0000BCBD 7706                <1>         ja      short load_FAT_sectors3
   160 0000BCBF 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
   161 0000BCC3 EB03                <1> 	jmp	short load_FAT_sectors4
   162                              <1> load_FAT_sectors3:
   163 0000BCC5 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
   164                              <1> load_FAT_sectors4:
   165 0000BCC8 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
   166 0000BCCA 83F903              <1>         cmp     ecx, 3
   167 0000BCCD 7605                <1>         jna     short load_FAT_sectors5
   168 0000BCCF B903000000          <1> 	mov	ecx, 3
   169                              <1> load_FAT_sectors5:
   170 0000BCD4 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   171 0000BCD9 E8553B0000          <1> 	call	disk_read
   172 0000BCDE 730D                <1> 	jnc	short load_FAT_sectors_ok
   173                              <1> 	; 15/10/2016 (15h -> 17)
   174                              <1> 	; 23/03/2016 (15h)
   175 0000BCE0 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error
   176 0000BCE5 C605[7A600100]00    <1> 	mov	byte [FAT_BuffValidData], 0
   177 0000BCEC C3                  <1> 	retn
   178                              <1> load_FAT_sectors_ok:
   179 0000BCED C605[7A600100]01    <1> 	mov	byte [FAT_BuffValidData], 1
   180 0000BCF4 A1[76600100]        <1> 	mov	eax, [FAT_CurrentCluster]
   181 0000BCF9 E9AAFEFFFF          <1>         jmp     check_next_cluster_fat_type
   182                              <1> 
   183                              <1> load_FAT_root_directory:
   184                              <1> 	; 23/10/2016
   185                              <1> 	; 15/10/2016
   186                              <1> 	; 07/02/2016
   187                              <1> 	; 02/02/2016
   188                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
   189                              <1> 	; 21/05/2011
   190                              <1> 	; 22/08/2009
   191                              <1> 	;
   192                              <1> 	; INPUT ->
   193                              <1> 	;	ESI = Logical DOS Drive Description Table
   194                              <1> 	; OUTPUT ->
   195                              <1> 	;	cf = 1 -> Root directory could not be loaded
   196                              <1> 	;	    EAX > 0 -> Error number
   197                              <1> 	;	cf = 0 -> EAX = 0
   198                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   199                              <1> 	;	EBX = Directory buffer address
   200                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   201                              <1> 	;
   202                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   203                              <1> 
   204                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
   205                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
   206                              <1> 
   207 0000BCFE 8A1E                <1> 	mov	bl, [esi+LD_Name]
   208 0000BD00 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   209                              <1> 
   210                              <1> 	;mov	[DirBuff_DRV], bl
   211                              <1> 	;mov	[DirBuff_FATType], bh
   212 0000BD03 66891D[8A600100]    <1> 	mov	[DirBuff_DRV], bx
   213                              <1> 	
   214                              <1> 	;cmp	bh, 2
   215                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
   216                              <1> 
   217                              <1> load_FAT_root_dir0: ; 23/10/2016
   218 0000BD0A 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
   219                              <1> 
   220                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
   221                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
   222                              <1> 
   223 0000BD0E 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
   224 0000BD13 7414                <1> 	je	short lrd_mov_ecx_32
   225 0000BD15 89D0                <1> 	mov	eax, edx
   226                              <1> 	; 23/10/2016
   227 0000BD17 89C1                <1> 	mov	ecx, eax
   228 0000BD19 6683C10F            <1> 	add	cx, 15 ; round up 
   229 0000BD1D 66C1E904            <1> 	shr	cx, 4  ; 16 entries per sector (512/32)
   230                              <1> 	; ecx = Root directory size in sectors
   231 0000BD21 66C1E005            <1> 	shl	ax, 5 ; Root directory size in bytes
   232 0000BD25 664A                <1> 	dec	dx    ; Last entry number of root dir
   233                              <1> 	; cx = Dir Buffer sector count             
   234 0000BD27 EB0B                <1> 	jmp	short lrd_check_dir_buffer
   235                              <1> 
   236                              <1> lrd_mov_ecx_32:
   237 0000BD29 B920000000          <1> 	mov	ecx, 32
   238 0000BD2E 664A                <1> 	dec	dx ; 511
   239 0000BD30 66B80040            <1> 	mov	ax, 32*512 
   240                              <1>  
   241                              <1> lrd_check_dir_buffer:
   242 0000BD34 29DB                <1> 	sub	ebx, ebx ; 0
   243 0000BD36 881D[8C600100]      <1> 	mov	[DirBuff_ValidData], bl ; 0
   244 0000BD3C 668915[8F600100]    <1> 	mov	[DirBuff_LastEntry], dx
   245 0000BD43 891D[91600100]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
   246 0000BD49 66A3[95600100]      <1> 	mov	[DirBuffer_Size], ax
   247                              <1> 
   248 0000BD4F 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
   249                              <1> read_directory:
   250 0000BD52 BB00000800          <1> 	mov	ebx, Directory_Buffer
   251 0000BD57 51                  <1> 	push	ecx ; Directory buffer sector count
   252 0000BD58 53                  <1> 	push	ebx
   253 0000BD59 E8D53A0000          <1> 	call	disk_read
   254 0000BD5E 5B                  <1> 	pop	ebx
   255 0000BD5F 720B                <1> 	jc	short load_DirBuff_error
   256                              <1> 
   257                              <1> validate_DirBuff_and_return:
   258 0000BD61 59                  <1> 	pop	ecx ; Number of loaded sectors
   259 0000BD62 C605[8C600100]01    <1> 	mov	byte [DirBuff_ValidData], 1
   260 0000BD69 31C0                <1> 	xor	eax, eax ; 0 = no error
   261 0000BD6B C3                  <1> 	retn
   262                              <1> 
   263                              <1> load_DirBuff_error:
   264 0000BD6C 89C8                <1> 	mov	eax, ecx ; remaining sectors
   265 0000BD6E 59                  <1> 	pop	ecx ; sector count
   266 0000BD6F 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
   267                              <1> 	; 15/10/2016 (15h -> 17)
   268 0000BD71 B811000000          <1> 	mov	eax, 17 ; DRV NOT READY OR READ ERROR !
   269 0000BD76 F9                  <1> 	stc
   270 0000BD77 C3                  <1>         retn
   271                              <1> 
   272                              <1> load_FAT32_root_directory:
   273                              <1> 	; 02/02/2016 (TRDOS 386 =  TRDOS v2.0)
   274                              <1> 	;
   275                              <1> 	; INPUT ->
   276                              <1> 	;	ESI = Logical DOS Drive Description Table
   277                              <1> 	; OUTPUT ->
   278                              <1> 	;	cf = 1 -> Root directory could not be loaded
   279                              <1> 	;	    EAX > 0 -> Error number
   280                              <1> 	;	cf = 0 -> EAX = 0
   281                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   282                              <1> 	;	EBX = Directory buffer address
   283                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   284                              <1> 	;
   285                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   286                              <1> 
   287                              <1> 
   288 0000BD78 8A1E                <1> 	mov	bl, [esi+LD_Name]
   289 0000BD7A 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   290                              <1> 
   291                              <1> 	;mov	[DirBuff_DRV], bl
   292                              <1> 	;mov	[DirBuff_FATType], bh
   293 0000BD7D 66891D[8A600100]    <1> 	mov	[DirBuff_DRV], bx
   294                              <1> 
   295                              <1> load_FAT32_root_dir0:
   296 0000BD84 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   297 0000BD87 EB0C                <1> 	jmp	short load_FAT_sub_dir0
   298                              <1> 	
   299                              <1> load_FAT_sub_directory:
   300                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
   301                              <1> 	; 05/07/2011
   302                              <1> 	; 23/08/2009
   303                              <1> 	;
   304                              <1> 	; INPUT ->
   305                              <1> 	;	ESI = Logical DOS Drive Description Table
   306                              <1> 	;	EAX = Cluster Number
   307                              <1> 	; OUTPUT ->
   308                              <1> 	;	cf = 1 -> Sub directory could not be loaded
   309                              <1> 	;	    EAX > 0 -> Error number
   310                              <1> 	;	cf = 0 -> EAX = 0
   311                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   312                              <1> 	;	EBX = Directory buffer address
   313                              <1> 	;
   314                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   315                              <1> 	;
   316                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   317                              <1> 
   318 0000BD89 8A1E                <1> 	mov	bl, [esi+LD_Name]
   319 0000BD8B 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   320                              <1> 
   321                              <1> 	;mov	[DirBuff_DRV], bl
   322                              <1> 	;mov	[DirBuff_FATType], bh
   323 0000BD8E 66891D[8A600100]    <1> 	mov	[DirBuff_DRV], bx
   324                              <1> 
   325                              <1> load_FAT_sub_dir0:
   326 0000BD95 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
   327                              <1> 
   328 0000BD99 882D[8C600100]      <1> 	mov	[DirBuff_ValidData], ch ; 0
   329 0000BD9F A3[91600100]        <1> 	mov	[DirBuff_Cluster], eax
   330                              <1> 
   331 0000BDA4 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
   332 0000BDA8 F7E1                <1> 	mul	ecx
   333 0000BDAA C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
   334 0000BDAD 6648                <1> 	dec	ax ; last entry
   335 0000BDAF 66A3[8F600100]      <1> 	mov	[DirBuff_LastEntry], ax
   336                              <1> 
   337 0000BDB5 A1[91600100]        <1> 	mov	eax, [DirBuff_Cluster]
   338 0000BDBA 83E802              <1> 	sub	eax, 2
   339 0000BDBD F7E1                <1> 	mul	ecx
   340 0000BDBF 034668              <1> 	add	eax, [esi+LD_DATABegin]
   341                              <1> 	; ecx = sector per cluster (dir buffer size = 32 sectors)
   342 0000BDC2 EB8E                <1> 	jmp	short read_directory
   343                              <1> 
   344                              <1> ; DRV_FS.ASM
   345                              <1> 
   346                              <1> load_current_FS_directory:
   347 0000BDC4 C3                  <1> 	retn
   348                              <1> load_FS_root_directory:
   349 0000BDC5 C3                  <1> 	retn
   350                              <1> load_FS_sub_directory:
   351 0000BDC6 C3                  <1> 	retn
   352                              <1> 
   353                              <1> read_cluster:
   354                              <1> 	; 15/10/2016
   355                              <1> 	; 18/03/2016
   356                              <1> 	; 16/03/2016
   357                              <1> 	; 17/02/2016
   358                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   359                              <1> 	;
   360                              <1> 	; INPUT ->
   361                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
   362                              <1> 	;	ESI = Logical DOS Drive Description Table address
   363                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
   364                              <1> 	;	Only for SINGLIX FS:
   365                              <1> 	;	EDX = File Number (The 1st FDT address) 
   366                              <1> 	; OUTPUT ->
   367                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
   368                              <1> 	;	    EAX > 0 -> Error number
   369                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
   370                              <1> 	;
   371                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   372                              <1> 	
   373 0000BDC7 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
   374                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
   375                              <1> 
   376                              <1> read_file_sectors: ; 16/03/2016
   377 0000BDCB 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
   378 0000BDCF 761C                <1> 	jna	short read_fs_cluster
   379                              <1> 
   380                              <1> read_fat_file_sectors: ; 18/03/2016
   381 0000BDD1 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
   382 0000BDD4 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
   383 0000BDD8 F7E2                <1> 	mul	edx
   384 0000BDDA 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
   385                              <1> 
   386                              <1> 	; EAX = Disk sector address
   387                              <1> 	; ECX = Sector count
   388                              <1> 	; EBX = Buffer address
   389                              <1> 	; (EDX = 0)
   390                              <1> 	; ESI = Logical DOS drive description table address	
   391                              <1> 
   392 0000BDDD E8513A0000          <1> 	call	disk_read
   393 0000BDE2 7306                <1> 	jnc	short rclust_retn
   394                              <1> 	
   395                              <1> 	; 15/10/2016 (15h -> 17)
   396 0000BDE4 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
   397 0000BDE9 C3                  <1> 	retn
   398                              <1> 
   399                              <1> rclust_retn:
   400 0000BDEA 29C0                <1> 	sub	eax, eax ; 0
   401 0000BDEC C3                  <1> 	retn
   402                              <1> 
   403                              <1> read_fs_cluster:
   404                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   405                              <1> 	; Singlix FS
   406                              <1> 	
   407                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
   408                              <1> 	
   409                              <1> 	; EDX = File number is the first File Descriptor Table address 
   410                              <1> 	;	of the file. (Absolute address of the FDT).
   411                              <1> 	
   412                              <1> 	; eax = sector index (0 for the first sector)
   413                              <1> 	; edx = FDT0 address
   414                              <1> 		; 64 KB buffer = 128 sectors (limit) 
   415 0000BDED B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
   416 0000BDF2 E801000000          <1> 	call	read_fs_sectors
   417 0000BDF7 C3                  <1> 	retn
   418                              <1> 
   419                              <1> read_fs_sectors:
   420                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
   421 0000BDF8 F9                  <1> 	stc
   422 0000BDF9 C3                  <1> 	retn
   423                              <1> 
   424                              <1> get_first_free_cluster:
   425                              <1> 	; 02/03/2016
   426                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
   427                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
   428                              <1> 	; 10/07/2010
   429                              <1> 	; INPUT ->
   430                              <1> 	;	ESI = Logical DOS Drive Description Table address
   431                              <1> 	; OUTPUT ->
   432                              <1> 	;	cf = 1 -> Error code in AL (EAX)
   433                              <1> 	;	cf = 0 -> 
   434                              <1> 	;	  EAX = Cluster number 
   435                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
   436                              <1> 	;	If the drive has FAT32 fs:
   437                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
   438                              <1> 
   439 0000BDFA 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
   440 0000BDFD 40                  <1> 	inc	eax ; add eax, 1
   441 0000BDFE A3[14630100]        <1> 	mov	[gffc_last_free_cluster], eax
   442                              <1> 
   443 0000BE03 31DB                <1> 	xor	ebx, ebx ; 0 ; 02/03/2016
   444                              <1> 
   445 0000BE05 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
   446 0000BE09 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
   447                              <1> 
   448                              <1> loc_gffc_get_first_fat32_free_cluster:
   449                              <1> 	; 02/03/2016
   450 0000BE0B E844060000          <1> 	call	get_fat32_fsinfo_sector_parms
   451 0000BE10 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0 
   452                              <1> 
   453                              <1> loc_gffc_check_fsinfo_parms:
   454                              <1> 	;;mov	ebx, DOSBootSectorBuff
   455                              <1> 	;cmp	dword [ebx], 41615252h
   456                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   457                              <1> 	;cmp	dword [ebx+484], 61417272h
   458                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   459                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
   460                              <1> 	;EAX = First free cluster 
   461                              <1> 	;(from FAT32 FSInfo sector)
   462 0000BE12 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
   463 0000BE14 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
   464 0000BE17 7205                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
   465                              <1> 
   466                              <1> 	; Start from the 1st cluster of the FAT(32) file system
   467                              <1> loc_gffc_get_first_fat_free_cluster0:
   468 0000BE19 B802000000          <1> 	mov	eax, 2
   469                              <1> 	;xor	edx, edx
   470                              <1> 
   471                              <1> loc_gffc_get_first_fat_free_cluster1:
   472 0000BE1E 53                  <1> 	push	ebx ; 02/03/2016 
   473                              <1> 
   474                              <1> loc_gffc_get_first_fat_free_cluster2:   
   475 0000BE1F A3[10630100]        <1> 	mov	[gffc_first_free_cluster], eax
   476 0000BE24 A3[0C630100]        <1> 	mov	[gffc_next_free_cluster], eax
   477                              <1> 
   478                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   479                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   480                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   481                              <1> 
   482                              <1> loc_gffc_get_first_fat_free_cluster3:
   483 0000BE29 E875FDFFFF          <1> 	call	get_next_cluster
   484 0000BE2E 7307                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster4
   485 0000BE30 09C0                <1> 	or	eax, eax
   486 0000BE32 740B                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
   487 0000BE34 5B                  <1> 	pop	ebx ; 02/03/2016
   488 0000BE35 F5                  <1> 	cmc 	; stc
   489 0000BE36 C3                  <1> 	retn
   490                              <1> 
   491                              <1> loc_gffc_get_first_fat_free_cluster4:
   492 0000BE37 21C0                <1> 	and	eax, eax ; next cluster value
   493 0000BE39 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
   494 0000BE3B 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
   495 0000BE3D EB22                <1> 	jmp	short loc_gffc_check_for_set
   496                              <1>  
   497                              <1> loc_gffc_first_free_fat_cluster_next:
   498 0000BE3F A1[0C630100]        <1> 	mov	eax, [gffc_next_free_cluster]
   499 0000BE44 3B05[14630100]      <1> 	cmp	eax, [gffc_last_free_cluster]
   500 0000BE4A 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
   501                              <1> pass_gffc_last_cluster_eax_check:
   502 0000BE4C 40                  <1> 	inc	eax ; add eax, 1
   503 0000BE4D A3[0C630100]        <1> 	mov	[gffc_next_free_cluster], eax
   504 0000BE52 EBD5                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster3
   505                              <1> 
   506                              <1> retn_stc_from_get_first_free_cluster:
   507 0000BE54 A1[10630100]        <1> 	mov	eax, [gffc_first_free_cluster]
   508 0000BE59 83F802              <1> 	cmp	eax, 2
   509 0000BE5C 7709                <1> 	ja	short loc_gffc_check_previous_clusters
   510 0000BE5E 29C0                <1> 	sub	eax, eax
   511 0000BE60 48                  <1> 	dec	eax ; FFFFFFFFh
   512                              <1> 
   513                              <1> loc_gffc_check_for_set:
   514                              <1> 	; 02/03/2016
   515 0000BE61 5B                  <1> 	pop	ebx
   516                              <1> 
   517                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   518                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   519                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   520                              <1> 
   521 0000BE62 09DB                <1> 	or	ebx, ebx
   522 0000BE64 750E                <1> 	jnz	short loc_gffc_set_ffree_fat32_cluster
   523                              <1> 
   524                              <1> 	;cmp	byte [esi+LD_FATType], 3
   525                              <1> 	;jnb	short loc_gffc_set_ffree_fat32_cluster
   526                              <1> 
   527                              <1> 	;xor	ebx, ebx ; 0
   528                              <1> 
   529                              <1> loc_gffc_retn:
   530 0000BE66 C3                  <1> 	retn
   531                              <1> 
   532                              <1> loc_gffc_check_previous_clusters:
   533 0000BE67 48                  <1> 	dec	eax ; sub eax, 1
   534 0000BE68 A3[14630100]        <1> 	mov	[gffc_last_free_cluster], eax 
   535 0000BE6D B802000000          <1> 	mov	eax, 2
   536                              <1> 	;xor	edx, edx
   537 0000BE72 EBAB                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
   538                              <1> 
   539                              <1> loc_gffc_set_ffree_fat32_cluster:
   540                              <1> 	;call	set_first_free_cluster
   541                              <1> 	;retn
   542                              <1> 	;jmp	short set_first_free_cluster	
   543                              <1> 
   544                              <1> set_first_free_cluster:
   545                              <1> 	; 15/10/2016
   546                              <1> 	; 23/03/2016
   547                              <1> 	; 02/03/2016
   548                              <1> 	; 29/02/2016
   549                              <1> 	; 26/02/2016
   550                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
   551                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
   552                              <1> 	; 11/07/2010
   553                              <1> 	; INPUT -> 
   554                              <1> 	;	ESI = Logical DOS Drive Description Table address
   555                              <1> 	;	EAX = First free cluster
   556                              <1> 	;	EBX = FSINFO sector buffer address
   557                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
   558                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
   559                              <1> 	; OUTPUT->
   560                              <1> 	;	ESI = Logical DOS Drive Description Table address
   561                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
   562                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
   563                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
   564                              <1> 	;	CF = 0 -> first free cluster is successfully updated 
   565                              <1> 
   566                              <1> 	;cmp	byte [esi+LD_FATType], 3
   567                              <1> 	;jb	short loc_sffc_invalid_drive
   568                              <1> 
   569                              <1> 	; Save First Free Cluster value for 'update_cluster'
   570 0000BE74 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster	
   571                              <1> 
   572                              <1> 	;or	ebx, ebx
   573                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
   574                              <1> 
   575 0000BE77 813B52526141        <1> 	cmp     dword [ebx], 41615252h
   576 0000BE7D 7540                <1> 	jne	short loc_sffc_read_fsinfo_sector
   577 0000BE7F 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
   577 0000BE88 61                  <1>
   578 0000BE89 7534                <1> 	jne	short loc_sffc_read_fsinfo_sector
   579                              <1> 
   580 0000BE8B 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
   581 0000BE91 741F                <1> 	je	short loc_sffc_retn
   582                              <1> 
   583                              <1> loc_sffc_write_fsinfo_sector:
   584                              <1> 	; EBX = FSINFO sector buffer
   585                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
   586 0000BE93 8983EC010000        <1> 	mov	[ebx+492], eax
   587 0000BE99 A1[24630100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC] 
   588 0000BE9E B901000000          <1> 	mov	ecx, 1
   589 0000BEA3 53                  <1> 	push	ebx
   590 0000BEA4 E87B390000          <1> 	call	disk_write
   591 0000BEA9 7208                <1> 	jc      short loc_sffc_read_fsinfo_sector_err1
   592 0000BEAB 5B                  <1> 	pop	ebx
   593                              <1> 
   594 0000BEAC 8B83EC010000        <1> 	mov	eax, [ebx+492] ; First (Next) Free Cluster
   595                              <1> 
   596                              <1> loc_sffc_retn:
   597 0000BEB2 C3                  <1> 	retn
   598                              <1> 
   599                              <1> ;loc_sffc_invalid_drive:
   600                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
   601                              <1> ;	push	edx
   602                              <1> 
   603                              <1> loc_sffc_read_fsinfo_sector_err1:
   604 0000BEB3 BB00000000          <1> 	mov	ebx, 0
   605                              <1> 	; 15/10/2016 (1Dh -> 18)
   606                              <1> 	; 23/03/2016 (1Dh)
   607 0000BEB8 B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error
   608                              <1> 
   609                              <1> loc_sffc_read_fsinfo_sector_err2:
   610 0000BEBD 5A                  <1> 	pop	edx
   611 0000BEBE C3                  <1> 	retn
   612                              <1> 	
   613                              <1> loc_sffc_read_fsinfo_sector:
   614 0000BEBF 50                  <1> 	push	eax
   615                              <1> 
   616 0000BEC0 E88F050000          <1> 	call	get_fat32_fsinfo_sector_parms
   617 0000BEC5 72F6                <1> 	jc	short loc_sffc_read_fsinfo_sector_err2
   618                              <1> 
   619 0000BEC7 58                  <1> 	pop	eax
   620                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
   621                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
   622                              <1> 	; (edx = old value)
   623 0000BEC8 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value) 
   624 0000BECA 75C7                <1> 	jne	short loc_sffc_write_fsinfo_sector
   625                              <1> 
   626 0000BECC C3                  <1> 	retn	
   627                              <1> 
   628                              <1> update_cluster:
   629                              <1> 	; 23/10/2016
   630                              <1> 	; 23/03/2016
   631                              <1> 	; 02/03/2016
   632                              <1> 	; 01/03/2016
   633                              <1> 	; 29/02/2016
   634                              <1> 	; 27/02/2016
   635                              <1> 	; 26/02/2016
   636                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
   637                              <1> 	; 11/08/2011  
   638                              <1> 	; 09/02/2005
   639                              <1> 	; INPUT ->
   640                              <1> 	;	EAX = Cluster Number
   641                              <1> 	;	ECX = New Cluster Value
   642                              <1> 	;	ESI = Logical Dos Drive Parameters Table
   643                              <1> 	;
   644                              <1> 	;	/// dword [FAT_ClusterCounter] ///
   645                              <1> 	;
   646                              <1> 	; OUTPUT ->
   647                              <1> 	;	cf = 0 -> No Error, EAX is valid
   648                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
   649                              <1> 	; 	cf = 1 & EAX > 0 -> Error
   650                              <1> 	;		(ECX -> any value)
   651                              <1> 	; 	EAX = Next Cluster
   652                              <1> 	;	ECX = New Cluster Value
   653                              <1> 	;
   654                              <1> 	;	/// [FAT_ClusterCounter] is updated,
   655                              <1> 	;	/// decreased when a free cluster is assigned,
   656                              <1> 	;	/// increased if an assigned cluster is freed.	
   657                              <1> 	;		
   658                              <1> 	;
   659                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
   660                              <1> 	
   661 0000BECD A3[76600100]        <1> 	mov	[FAT_CurrentCluster], eax
   662 0000BED2 890D[18630100]      <1> 	mov	[ClusterValue], ecx
   663                              <1> 
   664                              <1> loc_update_cluster_check_fat_buffer:
   665 0000BED8 8A1E                <1> 	mov	bl, [esi+LD_Name]
   666 0000BEDA 381D[7B600100]      <1> 	cmp	[FAT_BuffDrvName], bl
   667 0000BEE0 741A                <1> 	je	short loc_update_cluster_check_fat_type
   668 0000BEE2 803D[7A600100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
   669 0000BEE9 0F84C2000000        <1>         je      loc_uc_save_fat_buffer
   670                              <1> 
   671                              <1> loc_uc_reset_fat_buffer_validation:
   672 0000BEEF C605[7A600100]00    <1> 	mov	byte [FAT_BuffValidData], 0
   673                              <1> 
   674                              <1> loc_uc_check_fat_type_reset_drvname:
   675 0000BEF6 881D[7B600100]      <1> 	mov	[FAT_BuffDrvName], bl
   676                              <1> 
   677                              <1> loc_update_cluster_check_fat_type:
   678 0000BEFC 29D2                <1> 	sub	edx, edx ; 26/02/2016
   679 0000BEFE 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
   680 0000BF01 83F802              <1> 	cmp	eax, 2
   681 0000BF04 0F82BE000000        <1>         jb      update_cluster_inv_data
   682 0000BF0A 80FB02              <1> 	cmp	bl, 2 
   683 0000BF0D 0F877A010000        <1>         ja      update_fat32_cluster
   684                              <1> 	;cmp	bl, 1
   685                              <1> 	;jb	short update_cluster_inv_data
   686 0000BF13 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
   687 0000BF16 41                  <1> 	inc	ecx  
   688 0000BF17 890D[86600100]      <1> 	mov	[LastCluster], ecx
   689 0000BF1D 39C8                <1> 	cmp	eax, ecx ; dword [LastCluster]
   690 0000BF1F 0F87A6000000        <1>         ja      return_uc_fat_stc
   691                              <1> 	; TRDOS v1 has a FATal bug here ! 
   692                              <1> 		; or bl, bl ; cmp bl, 0
   693                              <1> 		; jz short update_fat12_cluster
   694                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
   695                              <1> 	; ('A:' disks of TRDOS v1 operating system project
   696                              <1> 	; had 'singlix fs', so, I could not differ this mistake
   697                              <1> 	; on a drive 'A:')
   698 0000BF25 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
   699 0000BF28 0F86A2000000        <1>         jna     update_fat12_cluster 
   700                              <1> 
   701                              <1> update_fat16_cluster:
   702                              <1> pass_uc_fat16_errc:
   703                              <1> 	;sub	edx, edx
   704 0000BF2E BB00030000          <1> 	mov	ebx, 300h ;768
   705 0000BF33 F7F3                <1> 	div	ebx
   706                              <1> 	; EAX = Count of 3 FAT sectors
   707                              <1> 	; DX = Cluster offset in FAT buffer
   708 0000BF35 6689D3              <1> 	mov	bx, dx  
   709 0000BF38 66D1E3              <1> 	shl	bx, 1 ; Multiply by 2
   710 0000BF3B 66BA0300            <1> 	mov	dx, 3
   711 0000BF3F F7E2                <1> 	mul	edx  
   712                              <1> 	; EAX = FAT Sector
   713                              <1> 	; EDX = 0
   714                              <1> 	; EBX = Byte offset in FAT buffer
   715 0000BF41 8A0D[7A600100]      <1> 	mov	cl, [FAT_BuffValidData]
   716 0000BF47 80F902              <1> 	cmp	cl, 2
   717 0000BF4A 750A                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
   718                              <1> 
   719                              <1> loc_uc_check_fat16_buff_sector_save:
   720 0000BF4C 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   721 0000BF52 755D                <1> 	jne	short loc_uc_save_fat_buffer
   722 0000BF54 EB15                <1> 	jmp	short loc_update_fat16_cell
   723                              <1> 
   724                              <1> loc_uc_check_fat16_buff_sector_load:
   725 0000BF56 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
   726 0000BF59 0F85FB010000        <1>         jne     loc_uc_load_fat_sectors
   727 0000BF5F 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   728 0000BF65 0F85EF010000        <1>         jne     loc_uc_load_fat_sectors
   729                              <1> 
   730                              <1> loc_update_fat16_cell:
   731                              <1> loc_update_fat16_buffer:
   732 0000BF6B 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   733                              <1> 	;movzx	eax, word [ebx]
   734 0000BF71 668B03              <1> 	mov	ax, [ebx]
   735                              <1> 	; 01/03/2016
   736 0000BF74 89C2                <1> 	mov	edx, eax ; old value of the cluster
   737 0000BF76 A3[76600100]        <1> 	mov	[FAT_CurrentCluster], eax
   738 0000BF7B 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   739 0000BF81 66890B              <1> 	mov	[ebx], cx ; 16 bits !
   740                              <1> 
   741 0000BF84 C605[7A600100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   742                              <1> 	
   743 0000BF8B 6683F802            <1> 	cmp	ax, 2
   744 0000BF8F 723A                <1> 	jb	short return_uc_fat_stc
   745 0000BF91 3B05[86600100]      <1> 	cmp	eax, [LastCluster]
   746 0000BF97 7732                <1> 	ja	short return_uc_fat_stc
   747                              <1> 
   748                              <1> loc_fat_buffer_updated:
   749                              <1> 	; 01/03/2016
   750 0000BF99 F8                  <1> 	clc
   751                              <1> loc_fat_buffer_stc_1:
   752 0000BF9A 9C                  <1> 	pushf
   753 0000BF9B 21C9                <1> 	and	ecx, ecx
   754 0000BF9D 7506                <1> 	jnz	short loc_fat_buffer_updated_1
   755                              <1> 
   756                              <1> 	; 01/03/2016 
   757                              <1> 	; new value of the cluster = 0 (free)
   758                              <1> 	; increase free(d) cluster count
   759 0000BF9F FF05[82600100]      <1> 	inc	dword [FAT_ClusterCounter]
   760                              <1> 
   761                              <1> loc_fat_buffer_updated_1: ; new value of the cluster > 0
   762 0000BFA5 09D2                <1> 	or	edx, edx ; 02/03/2016
   763 0000BFA7 7506                <1> 	jnz	short loc_fat_buffer_updated_2
   764                              <1> 	; old value of the cluster = 0 (it was free cluster)
   765                              <1> 	; decrease free(d) cluster count
   766 0000BFA9 FF0D[82600100]      <1> 	dec	dword [FAT_ClusterCounter] ; it may be negative number
   767                              <1> 
   768                              <1> loc_fat_buffer_updated_2:
   769 0000BFAF 9D                  <1> 	popf
   770 0000BFB0 C3                  <1> 	retn
   771                              <1> 
   772                              <1> loc_uc_save_fat_buffer:
   773                              <1> 	; byte [FAT_BuffValidData] = 2 
   774 0000BFB1 E8D4010000          <1> 	call	save_fat_buffer
   775 0000BFB6 0F8297010000        <1>         jc      loc_fat_sectors_rw_error2
   776                              <1> 	;mov	byte [FAT_BuffValidData], 1
   777 0000BFBC A1[76600100]        <1> 	mov	eax, [FAT_CurrentCluster]
   778                              <1> 	;mov	ecx, [ClusterValue]
   779                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
   780 0000BFC1 8A1E                <1> 	mov	bl, [esi+LD_Name] ; 01/03/2016
   781 0000BFC3 E927FFFFFF          <1>         jmp     loc_uc_reset_fat_buffer_validation
   782                              <1> 
   783                              <1> update_cluster_inv_data:
   784                              <1> 	;mov	eax, 0Dh
   785 0000BFC8 B00D                <1> 	mov	al, 0Dh  ; Invalid Data
   786 0000BFCA C3                  <1> 	retn 
   787                              <1> 
   788                              <1> return_uc_fat_stc:
   789                              <1> 	; 01/03/2016
   790 0000BFCB 31C0                <1> 	xor	eax, eax
   791 0000BFCD F9                  <1> 	stc
   792 0000BFCE EBCA                <1> 	jmp	short loc_fat_buffer_stc_1
   793                              <1> 
   794                              <1> update_fat12_cluster:
   795                              <1> pass_uc_fat12_errc:
   796                              <1> 	;sub	edx, edx
   797 0000BFD0 BB00040000          <1> 	mov	ebx, 400h ;1024
   798 0000BFD5 F7F3                <1> 	div	ebx
   799                              <1> 	; EAX = Count of 3 FAT sectors
   800                              <1> 	; DX = Cluster offset in FAT buffer
   801 0000BFD7 66B90300            <1> 	mov	cx, 3
   802 0000BFDB 6689C3              <1> 	mov	bx, ax
   803 0000BFDE 6689C8              <1> 	mov	ax, cx ; 3
   804 0000BFE1 66F7E2              <1> 	mul	dx     ; Multiply by 3
   805 0000BFE4 66D1E8              <1> 	shr	ax, 1  ; Divide by 2
   806 0000BFE7 6693                <1> 	xchg	bx, ax
   807                              <1> 	; EAX = Count of 3 FAT sectors
   808                              <1> 	; EBX = Byte Offset in FAT buffer   
   809 0000BFE9 66F7E1              <1> 	mul	cx  ; 3 * AX
   810                              <1> 	; EAX = FAT Beginning Sector
   811                              <1> 	; EDX = 0
   812 0000BFEC 8A0D[7A600100]      <1> 	mov	cl, [FAT_BuffValidData]
   813                              <1> 	; TRDOS v1 has a FATal bug here ! 
   814                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
   815                              <1> 	;  while 'jne' is existing !)
   816 0000BFF2 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
   817 0000BFF5 750A                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
   818                              <1> 
   819                              <1> loc_uc_check_fat12_buff_sector_save:
   820 0000BFF7 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   821 0000BFFD 75B2                <1>         jne     short loc_uc_save_fat_buffer
   822 0000BFFF EB15                <1> 	jmp	short loc_update_fat12_cell
   823                              <1> 
   824                              <1> loc_uc_check_fat12_buff_sector_load:
   825 0000C001 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
   826 0000C004 0F8550010000        <1>         jne     loc_uc_load_fat_sectors
   827 0000C00A 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   828 0000C010 0F8544010000        <1>         jne     loc_uc_load_fat_sectors
   829                              <1> 
   830                              <1> loc_update_fat12_cell:
   831 0000C016 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   832 0000C01C 668B0D[76600100]    <1> 	mov	cx, [FAT_CurrentCluster]
   833 0000C023 66D1E9              <1> 	shr	cx, 1
   834 0000C026 668B03              <1> 	mov	ax, [ebx]
   835 0000C029 6689C2              <1> 	mov	dx, ax
   836 0000C02C 7344                <1> 	jnc	short uc_fat12_nc_even
   837                              <1> 
   838 0000C02E 6683E00F            <1> 	and	ax, 0Fh
   839 0000C032 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   840 0000C038 66C1E104            <1> 	shl	cx, 4
   841 0000C03C 6609C1              <1> 	or	cx, ax
   842 0000C03F 6689D0              <1> 	mov	ax, dx
   843 0000C042 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
   844 0000C045 66C1E804            <1> 	shr	ax, 4 ; al(bit4..7)+ah(bit0..7)
   845                              <1> 
   846                              <1> update_fat12_buffer:
   847 0000C049 A3[76600100]        <1> 	mov	[FAT_CurrentCluster], eax
   848 0000C04E 89C2                <1> 	mov	edx, eax ; 01/03/2016
   849 0000C050 C605[7A600100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   850 0000C057 6683F802            <1> 	cmp	ax, 2
   851 0000C05B 0F826AFFFFFF        <1>         jb      return_uc_fat_stc
   852 0000C061 3B05[86600100]      <1> 	cmp	eax, [LastCluster]
   853 0000C067 0F875EFFFFFF        <1>         ja      return_uc_fat_stc
   854 0000C06D E927FFFFFF          <1>         jmp     loc_fat_buffer_updated
   855                              <1> 
   856                              <1> uc_fat12_nc_even:
   857 0000C072 662500F0            <1> 	and	ax, 0F000h
   858 0000C076 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   859 0000C07C 80E50F              <1> 	and	ch, 0Fh
   860 0000C07F 6609C1              <1> 	or	cx, ax
   861 0000C082 6689D0              <1> 	mov	ax, dx
   862 0000C085 66890B              <1> 	mov	[ebx], cx ; 16 bits !
   863 0000C088 80E40F              <1> 	and	ah, 0Fh ; al(bit0..7)+ah(bit0..3)
   864 0000C08B EBBC                <1> 	jmp	short update_fat12_buffer
   865                              <1> 
   866                              <1> update_fat32_cluster:
   867 0000C08D 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
   868 0000C090 41                  <1> 	inc	ecx
   869 0000C091 890D[86600100]      <1> 	mov	[LastCluster], ecx
   870                              <1> 
   871 0000C097 39C8                <1> 	cmp	eax, ecx
   872 0000C099 0F872CFFFFFF        <1>         ja      return_uc_fat_stc
   873                              <1> 
   874                              <1> pass_uc_fat32_errc:
   875                              <1> 	;sub	edx, edx
   876 0000C09F BB80010000          <1> 	mov	ebx, 180h ;384
   877 0000C0A4 F7F3                <1> 	div	ebx
   878                              <1> 	; EAX = Count of 3 FAT sectors
   879                              <1> 	; DX = Cluster offset in FAT buffer
   880 0000C0A6 89D3                <1> 	mov	ebx, edx
   881 0000C0A8 C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
   882 0000C0AB BA03000000          <1> 	mov	edx, 3	
   883 0000C0B0 F7E2                <1> 	mul	edx
   884                              <1> 	; EBX = Cluster Offset in FAT buffer
   885                              <1> 	; EAX = FAT Sector
   886                              <1> 	; EDX = 0
   887 0000C0B2 8A0D[7A600100]      <1> 	mov	cl, [FAT_BuffValidData]
   888 0000C0B8 80F902              <1> 	cmp	cl, 2
   889 0000C0BB 750E                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
   890                              <1> 
   891                              <1> loc_uc_check_fat32_buff_sector_save:
   892 0000C0BD 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   893 0000C0C3 0F85E8FEFFFF        <1>         jne     loc_uc_save_fat_buffer
   894 0000C0C9 EB11                <1> 	jmp	short loc_update_fat32_cell
   895                              <1> 
   896                              <1> loc_uc_check_fat32_buff_sector_load:
   897 0000C0CB 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
   898 0000C0CE 0F8586000000        <1>         jne     loc_uc_load_fat_sectors
   899 0000C0D4 3B05[7E600100]      <1> 	cmp	eax, [FAT_BuffSector]
   900 0000C0DA 757E                <1>         jne     loc_uc_load_fat_sectors
   901                              <1> 
   902                              <1> loc_update_fat32_cell:
   903                              <1> loc_update_fat32_buffer:
   904 0000C0DC 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   905 0000C0E2 8B03                <1> 	mov	eax, [ebx]
   906 0000C0E4 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
   907                              <1> 	
   908 0000C0E9 8B15[76600100]      <1> 	mov	edx, [FAT_CurrentCluster] ; 01/03/2016
   909                              <1> 
   910 0000C0EF A3[76600100]        <1> 	mov 	[FAT_CurrentCluster], eax
   911 0000C0F4 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue]
   912 0000C0FA 890B                <1> 	mov	[ebx], ecx ; 29/02/2016 
   913                              <1> 
   914 0000C0FC C605[7A600100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   915                              <1> 
   916                              <1> 	; 01/03/2016
   917 0000C103 21C0                <1> 	and	eax, eax ; was it free cluster ?
   918 0000C105 7514                <1> 	jnz	short loc_upd_fat32_c0
   919                              <1> 
   920                              <1> 	;or	ecx, ecx ; it will be left free ?!
   921                              <1> 	;jz	short loc_upd_fat32_c3
   922                              <1> 
   923 0000C107 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
   924 0000C10A 7520                <1> 	jne	short loc_upd_fat32_c3
   925                              <1> 
   926 0000C10C 3B15[86600100]      <1> 	cmp	edx, [LastCluster]
   927 0000C112 7207                <1> 	jb	short loc_upd_fat32_c0
   928                              <1> 
   929 0000C114 BA02000000          <1> 	mov	edx, 2 ; rewind !
   930 0000C119 EB0E                <1> 	jmp	short loc_upd_fat32_c2
   931                              <1> 
   932                              <1> loc_upd_fat32_c0:
   933 0000C11B FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set it to next cluster		
   934 0000C11E EB0C                <1> 	jmp	short loc_upd_fat32_c3
   935                              <1> 
   936                              <1> loc_upd_fat32_c1:
   937 0000C120 09C9                <1> 	or	ecx, ecx ; will it be free cluster ?
   938 0000C122 7508                <1> 	jnz	short loc_upd_fat32_c3
   939                              <1> 
   940 0000C124 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
   941 0000C127 7303                <1> 	jnb	short loc_upd_fat32_c3
   942                              <1> 
   943                              <1> loc_upd_fat32_c2:	
   944 0000C129 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx			
   945                              <1> 
   946                              <1> loc_upd_fat32_c3:
   947 0000C12C 89C2                <1> 	mov	edx, eax
   948                              <1> 
   949                              <1> loc_upd_fat32_c4:
   950 0000C12E 83F802              <1> 	cmp	eax, 2
   951 0000C131 0F8294FEFFFF        <1>         jb      return_uc_fat_stc
   952                              <1> 
   953                              <1> pass_uc_fat32_c_zero_check_2:
   954 0000C137 3B05[86600100]      <1> 	cmp	eax, [LastCluster]
   955 0000C13D 0F8788FEFFFF        <1>         ja      return_uc_fat_stc
   956                              <1> 	
   957 0000C143 E951FEFFFF          <1> 	jmp     loc_fat_buffer_updated
   958                              <1> 
   959                              <1> loc_fat_sectors_rw_error1:
   960                              <1> 	;mov	byte [FAT_BuffValidData], 0
   961                              <1> 	; 23/10/2016 (15h -> 17)
   962                              <1> 	; 23/03/2016
   963 0000C148 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error
   964 0000C14D 8825[7A600100]      <1> 	mov	[FAT_BuffValidData], ah ; 0
   965                              <1> 
   966                              <1> loc_fat_sectors_rw_error2:
   967                              <1> 	;mov	eax, error code
   968                              <1> 	;mov	edx, 0
   969 0000C153 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue]
   970 0000C159 C3                  <1> 	retn
   971                              <1> 
   972                              <1> loc_uc_load_fat_sectors:
   973 0000C15A A3[7E600100]        <1> 	mov	[FAT_BuffSector], eax
   974                              <1> 
   975                              <1> load_uc_fat_sectors_zero:
   976 0000C15F 034660              <1> 	add	eax, [esi+LD_FATBegin]
   977 0000C162 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   978 0000C167 B903000000          <1> 	mov	ecx, 3
   979 0000C16C E8C2360000          <1> 	call	disk_read
   980 0000C171 72D5                <1> 	jc	short loc_fat_sectors_rw_error1
   981                              <1> 
   982 0000C173 C605[7A600100]01    <1>         mov     byte [FAT_BuffValidData], 1
   983 0000C17A A1[76600100]        <1> 	mov 	eax, [FAT_CurrentCluster]
   984 0000C17F 8B0D[18630100]      <1> 	mov	ecx, [ClusterValue]
   985 0000C185 E972FDFFFF          <1>         jmp     loc_update_cluster_check_fat_type
   986                              <1> 
   987                              <1> save_fat_buffer:
   988                              <1> 	; 15/10/2016
   989                              <1> 	; 01/03/2016
   990                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
   991                              <1> 	; 11/08/2011
   992                              <1> 	; 09/02/2005 
   993                              <1> 	; INPUT ->
   994                              <1> 	;	None
   995                              <1> 	; OUTPUT ->
   996                              <1> 	;	cf = 0 -> OK.
   997                              <1> 	;	cf = 1 -> error code in AL (EAX)
   998                              <1> 	;
   999                              <1> 	;	EBX = FAT_Buffer address
  1000                              <1> 	;
  1001                              <1> 	; (EAX, EDX, ECX will be modified)
  1002                              <1> 
  1003                              <1> 	;cmp	byte [FAT_BuffValidData], 2 
  1004                              <1> 	;je	short loc_save_fat_buff
  1005                              <1> 
  1006                              <1> ;loc_save_fat_buffer_retn:
  1007                              <1> ;	xor	eax, eax
  1008                              <1> ;	retn
  1009                              <1> 
  1010                              <1> loc_save_fat_buff:
  1011 0000C18A 31D2                <1> 	xor	edx, edx
  1012 0000C18C 8A35[7B600100]      <1> 	mov	dh, [FAT_BuffDrvName]
  1013 0000C192 80FE41              <1> 	cmp	dh, 'A'
  1014 0000C195 722E                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
  1015 0000C197 80EE41              <1> 	sub	dh, 'A'
  1016 0000C19A 56                  <1> 	push	esi ; *
  1017 0000C19B BE00010900          <1>         mov     esi, Logical_DOSDisks
  1018 0000C1A0 01D6                <1> 	add	esi, edx
  1019                              <1> 	
  1020 0000C1A2 8A5603              <1> 	mov	dl, [esi+LD_FATType]
  1021 0000C1A5 20D2                <1> 	and	dl, dl
  1022 0000C1A7 741B                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn 
  1023                              <1> 
  1024 0000C1A9 A1[7E600100]        <1> 	mov	eax, [FAT_BuffSector]
  1025 0000C1AE 80FA02              <1> 	cmp	dl, 2
  1026 0000C1B1 770A                <1> 	ja	short loc_save_fat32_buff
  1027                              <1> 
  1028                              <1> loc_save_fat_12_16_buff:
  1029                              <1> 	; 01/03/2016
  1030                              <1> 	; TRDOS v1 has a FATal bug here!
  1031                              <1> 	; Correct code: mov dx, word ptr [FAT_BuffSector]+2
  1032                              <1> 	; (DX:AX in TRDOS v1 -> EAX in TRDOS v2)
  1033                              <1> 	;
  1034 0000C1B3 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs] 
  1035 0000C1B7 29C1                <1> 	sub	ecx, eax
  1036                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
  1037                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
  1038 0000C1B9 7609                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
  1039 0000C1BB EB15                <1> 	jmp	short loc_save_fat_buffer_check_rs3
  1040                              <1> 
  1041                              <1> loc_save_fat32_buff:
  1042 0000C1BD 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
  1043 0000C1C0 29C1                <1> 	sub	ecx, eax
  1044 0000C1C2 770E                <1> 	ja	short loc_save_fat_buffer_check_rs3
  1045                              <1> 
  1046                              <1> loc_save_fat_buffer_inv_data_pop_retn:
  1047 0000C1C4 5E                  <1> 	pop	esi ; *
  1048                              <1> loc_save_fat_buffer_inv_data_retn:
  1049 0000C1C5 B80D000000          <1> 	mov	eax, 0Dh ; Invalid DATA
  1050 0000C1CA C3                  <1> 	retn
  1051                              <1> 
  1052                              <1> loc_save_fat_buff_remain_sectors_3:
  1053 0000C1CB B903000000          <1> 	mov	ecx, 3
  1054 0000C1D0 EB05                <1> 	jmp	short loc_save_fat_buff_continue
  1055                              <1> 
  1056                              <1> loc_save_fat_buffer_check_rs3:
  1057 0000C1D2 83F903              <1> 	cmp	ecx, 3
  1058 0000C1D5 77F4                <1> 	ja	short loc_save_fat_buff_remain_sectors_3
  1059                              <1> 
  1060                              <1> loc_save_fat_buff_continue:
  1061 0000C1D7 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1062 0000C1DC 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1063 0000C1DF 51                  <1> 	push	ecx
  1064 0000C1E0 E83F360000          <1> 	call	disk_write
  1065 0000C1E5 59                  <1> 	pop	ecx
  1066 0000C1E6 722B                <1> 	jc	short loc_save_FAT_buff_write_err
  1067                              <1> 	
  1068 0000C1E8 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1069 0000C1EC 7605                <1> 	jna	short loc_calc_2nd_fat12_16_addr
  1070                              <1> 
  1071                              <1> loc_calc_2nd_fat32_addr:
  1072 0000C1EE 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
  1073 0000C1F1 EB04                <1> 	jmp	short loc_calc_2nd_fat_addr
  1074                              <1> 
  1075                              <1> loc_calc_2nd_fat12_16_addr:
  1076 0000C1F3 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
  1077                              <1> 
  1078                              <1> loc_calc_2nd_fat_addr:
  1079 0000C1F7 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1080 0000C1FA 0305[7E600100]      <1> 	add	eax, [FAT_BuffSector]
  1081 0000C200 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1082                              <1> 	; ecx = 1 to 3
  1083 0000C205 E81A360000          <1> 	call	disk_write
  1084 0000C20A 7207                <1> 	jc	short loc_save_FAT_buff_write_err
  1085                              <1>  	; Valid  buffer (1 = valid but do not save)
  1086 0000C20C C605[7A600100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1087                              <1> 
  1088                              <1> loc_save_FAT_buff_write_err:
  1089 0000C213 5E                  <1> 	pop	esi ; *
  1090 0000C214 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1091                              <1> 	; 15/10/2016 (1Dh -> 18)
  1092                              <1> 	; 23/03/2016 (1Dh)
  1093 0000C219 B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error
  1094 0000C21E C3                  <1> 	retn
  1095                              <1> 
  1096                              <1> calculate_fat_freespace:
  1097                              <1> 	; 23/03/2016
  1098                              <1> 	; 02/03/2016
  1099                              <1> 	; 01/03/2016
  1100                              <1> 	; 29/02/2016
  1101                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1102                              <1> 	; 30/04/2011
  1103                              <1> 	; 03/04/2010
  1104                              <1> 	; 2005
  1105                              <1> 	; INPUT ->
  1106                              <1> 	;	EAX = Cluster count to be added or subtracted
  1107                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
  1108                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
  1109                              <1> 	; 	BL: 
  1110                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
  1111                              <1> 	; OUTPUT ->
  1112                              <1> 	;	EAX = Free Space in sectors
  1113                              <1> 	;	ESI = Logical Dos Drive Description Table address
  1114                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
  1115                              <1> 	;	BL = Type of operation (same with input value of BL)
  1116                              <1> 	;	ECX = 0 -> valid
  1117                              <1> 	;	ECX > 0 -> error or invalid
  1118                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
  1119                              <1> 	;			          sign due to r/w error   
  1120                              <1> 
  1121 0000C21F 66891D[1E630100]    <1> 	mov	[CFS_OPType], bx
  1122 0000C226 A3[20630100]        <1> 	mov	[CFS_CC], eax
  1123                              <1> 	
  1124 0000C22B 80FFFF              <1> 	cmp	bh, 0FFh
  1125 0000C22E 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
  1126                              <1> 
  1127                              <1> loc_calculate_freespace_get_drive_dt_offset:     
  1128 0000C230 31C0                <1> 	xor	eax, eax
  1129 0000C232 88FC                <1>         mov     ah, bh
  1130 0000C234 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1131 0000C239 01C6                <1>         add     esi, eax
  1132                              <1> 
  1133                              <1> pass_calculate_freespace_get_drive_dt_offset:
  1134 0000C23B 08DB                <1> 	or	bl, bl
  1135 0000C23D 7435                <1> 	jz	short loc_reset_fcc
  1136                              <1> 	
  1137                              <1> loc_get_free_sectors:
  1138 0000C23F 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1139                              <1> 
  1140                              <1> 	;xor	ecx, ecx
  1141                              <1> 	;dec	ecx ; 0FFFFFFFFh
  1142                              <1> 	;cmp	eax, ecx ; 29/02/2016
  1143                              <1> 	;je	short loc_get_free_sectors_retn ; recalculation is needed!
  1144                              <1> 	
  1145                              <1> 	; 23/03/2016
  1146 0000C242 8B4E70              <1> 	mov	ecx, [esi+LD_TotalSectors]
  1147 0000C245 39C1                <1> 	cmp	ecx, eax ; Total sectors must be greater than Free sectors !
  1148 0000C247 7707                <1> 	ja	short loc_get_free_sectors_check_optype
  1149                              <1> 	
  1150 0000C249 31C0                <1> 	xor	eax, eax
  1151 0000C24B 48                  <1> 	dec	eax ; 0FFFFFFFFh  ; recalculation is needed!
  1152 0000C24C 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; reset (for recalculation)
  1153                              <1> 		
  1154                              <1> loc_get_free_sectors_retn:
  1155 0000C24F C3                  <1> 	retn
  1156                              <1> 	
  1157                              <1> loc_get_free_sectors_check_optype:
  1158 0000C250 80FB03              <1> 	cmp	bl, 3
  1159 0000C253 7203                <1> 	jb	short loc_set_fcc
  1160                              <1> 
  1161 0000C255 29C9                <1> 	sub	ecx, ecx ; 0
  1162                              <1> 
  1163 0000C257 C3                  <1> 	retn	
  1164                              <1> 
  1165                              <1> loc_set_fcc:
  1166 0000C258 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1167 0000C25C 0F87DF000000        <1>         ja      loc_update_FAT32_fs_info_fcc
  1168                              <1> 
  1169                              <1> 	;mov	eax, [esi+LD_FreeSectors]
  1170 0000C262 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  1171 0000C266 29D2                <1> 	sub	edx, edx
  1172 0000C268 F7F1                <1> 	div	ecx
  1173                              <1> 	;or	dx, dx 
  1174                              <1> 	;	; DX -> Remain sectors < SecPerClust
  1175                              <1> 	;	; DX > 0 -> invalid free sector count
  1176                              <1> 	;jnz	short loc_reset_fcc 
  1177                              <1> 
  1178                              <1> ;pass_set_fcc_div32:
  1179 0000C26A A3[97600100]        <1> 	mov	[FreeClusterCount], eax
  1180 0000C26F E988000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
  1181                              <1> 
  1182                              <1> loc_reset_fcc:
  1183 0000C274 31C0                <1> 	xor	eax, eax
  1184 0000C276 A3[97600100]        <1> 	mov	[FreeClusterCount], eax ; 0
  1185 0000C27B 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
  1186 0000C27E 42                  <1> 	inc	edx
  1187 0000C27F 8915[86600100]      <1> 	mov	[LastCluster], edx
  1188                              <1> 
  1189 0000C285 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1190 0000C289 7647                <1> 	jna	short loc_count_free_fat_clusters_0  
  1191                              <1> 
  1192 0000C28B 48                  <1> 	dec	eax ; FFFFFFFFh
  1193 0000C28C A3[28630100]        <1> 	mov	[CFS_FAT32FC], eax
  1194                              <1> 
  1195                              <1> 	; 29/02/2016
  1196 0000C291 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
  1197 0000C294 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
  1198                              <1> 	
  1199 0000C297 B802000000          <1> 	mov 	eax, 2
  1200                              <1> 
  1201                              <1> loc_count_fc_next_cluster_0:
  1202 0000C29C 50                  <1> 	push	eax
  1203 0000C29D E801F9FFFF          <1> 	call	get_next_cluster
  1204 0000C2A2 7310                <1> 	jnc	short loc_check_fat32_ff_cluster
  1205 0000C2A4 09C0                <1> 	or	eax, eax
  1206 0000C2A6 741E                <1> 	jz	short pass_inc_cfs_fcc_0
  1207                              <1> 
  1208                              <1> loc_put_fcc_unknown_sign:
  1209 0000C2A8 58                  <1> 	pop	eax
  1210                              <1> 	; "Free count is Unknown" sign
  1211                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
  1212                              <1> 
  1213                              <1> 	; 29/02/2016
  1214                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
  1215                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
  1216 0000C2A9 8B15[28630100]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
  1217                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
  1218 0000C2AF 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
  1219                              <1> 	
  1220 0000C2B2 EB7D                <1>         jmp     loc_put_fcc_invalid_sign
  1221                              <1> 
  1222                              <1> loc_check_fat32_ff_cluster:
  1223 0000C2B4 09C0                <1> 	or	eax, eax
  1224 0000C2B6 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
  1225 0000C2B8 58                  <1> 	pop	eax
  1226 0000C2B9 A3[28630100]        <1> 	mov	[CFS_FAT32FC], eax
  1227                              <1> 	;mov	dword [FreeClusterCount], 1
  1228 0000C2BE FF05[97600100]      <1> 	inc	dword [FreeClusterCount]
  1229 0000C2C4 EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
  1230                              <1> 
  1231                              <1> pass_inc_cfs_fcc_0:
  1232 0000C2C6 58                  <1> 	pop	eax
  1233                              <1> 
  1234                              <1> pass_inc_cfs_fcc_0c:
  1235 0000C2C7 40                  <1> 	inc	eax ; add eax, 1
  1236 0000C2C8 3B05[86600100]      <1> 	cmp	eax, [LastCluster]
  1237 0000C2CE 76CC                <1> 	jna 	short loc_count_fc_next_cluster_0
  1238 0000C2D0 EB6F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
  1239                              <1> 
  1240                              <1> loc_count_free_fat_clusters_0:
  1241                              <1> 	;mov	eax, 2
  1242 0000C2D2 B002                <1> 	mov	al, 2
  1243                              <1> 
  1244                              <1> loc_count_fc_next_cluster:
  1245 0000C2D4 50                  <1> 	push	eax
  1246 0000C2D5 E8C9F8FFFF          <1> 	call	get_next_cluster
  1247 0000C2DA 720C                <1> 	jc	short loc_count_fcc_stc
  1248                              <1> 
  1249                              <1> loc_count_free_clusters_1:
  1250 0000C2DC 21C0                <1> 	and	eax, eax
  1251 0000C2DE 750C                <1> 	jnz	short pass_inc_cfs_fcc
  1252                              <1> 
  1253 0000C2E0 FF05[97600100]      <1> 	inc	dword [FreeClusterCount]
  1254 0000C2E6 EB04                <1> 	jmp	short pass_inc_cfs_fcc
  1255                              <1> 
  1256                              <1> loc_count_fcc_stc:
  1257 0000C2E8 09C0                <1> 	or	eax, eax
  1258 0000C2EA 75BC                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
  1259                              <1> 
  1260                              <1> pass_inc_cfs_fcc:
  1261 0000C2EC 58                  <1> 	pop	eax
  1262                              <1> 
  1263                              <1> pass_inc_cfs_fcc_1:
  1264 0000C2ED 40                  <1> 	inc	eax ; add eax, 1
  1265 0000C2EE 3B05[86600100]      <1> 	cmp	eax, [LastCluster]
  1266 0000C2F4 76DE                <1> 	jna	short loc_count_fc_next_cluster
  1267                              <1> 
  1268                              <1> loc_set_free_sectors:
  1269 0000C2F6 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1270 0000C2FA 7745                <1> 	ja	short loc_update_FAT32_fs_info_fcc
  1271                              <1> 
  1272                              <1> loc_set_free_sectors_FAT12_FAT16:
  1273 0000C2FC 803D[1E630100]00    <1> 	cmp	byte [CFS_OPType], 0
  1274 0000C303 761C                <1> 	jna	short pass_FAT_add_sub_fcc
  1275 0000C305 A1[20630100]        <1> 	mov	eax, [CFS_CC]
  1276 0000C30A 803D[1E630100]01    <1> 	cmp	byte [CFS_OPType], 1
  1277 0000C311 7708                <1> 	ja	short pass_FAT_add_fcc
  1278 0000C313 0105[97600100]      <1> 	add 	[FreeClusterCount], eax
  1279 0000C319 EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
  1280                              <1> 
  1281                              <1> pass_FAT_add_fcc:
  1282 0000C31B 2905[97600100]      <1> 	sub	[FreeClusterCount], eax
  1283                              <1> 
  1284                              <1> pass_FAT_add_sub_fcc:
  1285 0000C321 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1286 0000C325 8B15[97600100]      <1> 	mov	edx, [FreeClusterCount]
  1287 0000C32B F7E2                <1> 	mul	edx
  1288                              <1> 
  1289 0000C32D 31C9                <1> 	xor	ecx, ecx 
  1290 0000C32F EB05                <1> 	jmp	short loc_cfs_retn_params
  1291                              <1> 
  1292                              <1> loc_put_fcc_invalid_sign:
  1293 0000C331 29C0                <1>        	sub	eax, eax ; 0
  1294 0000C333 48                  <1> 	dec	eax ; FFFFFFFFh
  1295                              <1> loc_fat32_ffc_recalc_needed:
  1296 0000C334 89C1                <1> 	mov	ecx, eax
  1297                              <1> 
  1298                              <1> loc_cfs_retn_params:
  1299 0000C336 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
  1300 0000C339 0FB71D[1E630100]    <1> 	movzx	ebx, word [CFS_OPType]
  1301 0000C340 C3                  <1> 	retn
  1302                              <1> 
  1303                              <1> loc_update_FAT32_fs_info_fcc:
  1304                              <1> loc_check_fcc_FSINFO_op:
  1305                              <1> 	; 29/02/2016
  1306                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
  1307                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
  1308 0000C341 803D[1E630100]01    <1> 	cmp	byte [CFS_OPType], 1
  1309 0000C348 7221                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
  1310 0000C34A 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
  1311                              <1> loc_check_fcc_FSINFO_op2: ; subtract
  1312 0000C34C F71D[20630100]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
  1313                              <1> loc_check_fcc_FSINFO_op1:
  1314                              <1> 	; 01/03/2016
  1315 0000C352 31D2                <1> 	xor	edx, edx ; 0
  1316 0000C354 4A                  <1> 	dec	edx ; 0FFFFFFFFh
  1317 0000C355 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved]
  1318 0000C358 39D0                <1> 	cmp	eax, edx
  1319 0000C35A 73D5                <1> 	jnb	short loc_put_fcc_invalid_sign
  1320 0000C35C 0305[20630100]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
  1321 0000C362 72CD                <1> 	jc	short loc_put_fcc_invalid_sign
  1322                              <1> 	
  1323 0000C364 A3[97600100]        <1> 	mov	[FreeClusterCount], eax
  1324 0000C369 EB0E                <1> 	jmp	short loc_cfs_write_FSINFO_sector
  1325                              <1> 
  1326                              <1> loc_cfs_FAT32_get_rcalc_parms:
  1327 0000C36B 8B15[28630100]      <1> 	mov	edx, [CFS_FAT32FC]
  1328 0000C371 A1[97600100]        <1> 	mov	eax, [FreeClusterCount]
  1329 0000C376 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
  1330                              <1> loc_cfs_write_FSINFO_sector:
  1331 0000C379 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
  1332                              <1> 	; 01/03/2016
  1333 0000C37C E8AA000000          <1> 	call	set_fat32_fsinfo_sector_parms
  1334 0000C381 72AE                <1>         jc      short loc_put_fcc_invalid_sign
  1335                              <1> 
  1336                              <1> loc_set_FAT32_free_sectors:
  1337                              <1> 	; 29/02/2016
  1338                              <1> 	;mov	eax, [FreeClusterCount]
  1339                              <1> 	;mov	ecx, eax
  1340                              <1> 	;cmp	eax, 0FFFFFFFFh ; Invalid !
  1341                              <1> 	;je	short loc_cfs_retn_params
  1342                              <1> 	;
  1343 0000C383 8B0D[97600100]      <1> 	mov	ecx, [FreeClusterCount]
  1344 0000C389 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1345 0000C38D F7E1                <1> 	mul	ecx
  1346                              <1> 	; 29/02/2016
  1347 0000C38F 31C9                <1> 	xor	ecx, ecx ; 0
  1348 0000C391 09D2                <1> 	or	edx, edx ; 0 ?
  1349 0000C393 759C                <1>         jnz     loc_put_fcc_invalid_sign
  1350 0000C395 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
  1351 0000C398 7697                <1>         jna     short loc_put_fcc_invalid_sign
  1352                              <1> 	;
  1353                              <1> loc_set_FAT32_free_sectors_ok:
  1354 0000C39A 31D2                <1> 	xor	edx, edx ; 0
  1355 0000C39C EB98                <1>         jmp     short loc_cfs_retn_params 
  1356                              <1> 	;
  1357                              <1> 
  1358                              <1> get_last_cluster:
  1359                              <1> 	; 22/10/2016
  1360                              <1> 	; 27/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1361                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
  1362                              <1> 	; 06/06/2010
  1363                              <1> 	; INPUT ->
  1364                              <1> 	;	EAX = First Cluster Number
  1365                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
  1366                              <1> 	; OUTPUT ->
  1367                              <1> 	;	cf = 0 -> No Error, EAX is valid
  1368                              <1> 	;	cf = 1 -> EAX > 0 -> Error
  1369                              <1> 	;	EAX = Last Cluster Number
  1370                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
  1371                              <1> 	;       ; 22/10/2016
  1372                              <1> 	;	[glc_index] = cluster index number of the last cluster	
  1373                              <1> 	;
  1374                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  1375                              <1> 
  1376 0000C39E 89C1                <1> 	mov	ecx, eax
  1377                              <1> 
  1378 0000C3A0 C705[30630100]FFFF- <1> 	mov	dword [glc_index], 0FFFFFFFFh ; 22/10/2016	
  1378 0000C3A8 FFFF                <1>
  1379                              <1> 
  1380                              <1> loc_glc_get_next_cluster_1:
  1381 0000C3AA 890D[2C630100]      <1> 	mov	[glc_prevcluster], ecx
  1382                              <1>  	; 22/10/2016
  1383 0000C3B0 FF05[30630100]      <1> 	inc	dword [glc_index]
  1384                              <1> 
  1385                              <1> loc_glc_get_next_cluster_2:
  1386 0000C3B6 E8E8F7FFFF          <1> 	call	get_next_cluster
  1387                              <1> 	; ecx = current/previous cluster 
  1388                              <1> 	; eax = next/last cluster
  1389 0000C3BB 73ED                <1> 	jnc	short loc_glc_get_next_cluster_1
  1390                              <1> 
  1391 0000C3BD 09C0                <1> 	or	eax, eax
  1392 0000C3BF 7509                <1> 	jnz	short loc_glc_stc_retn
  1393                              <1> 
  1394                              <1> 	; ecx = previous cluster
  1395 0000C3C1 89C8                <1>         mov	eax, ecx
  1396                              <1> 
  1397                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
  1398                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
  1399                              <1> 
  1400                              <1> loc_glc_prev_cluster_retn:
  1401 0000C3C3 8B0D[2C630100]      <1> 	mov	ecx, [glc_prevcluster] 
  1402 0000C3C9 C3                  <1> 	retn
  1403                              <1> 
  1404                              <1> loc_glc_stc_retn:
  1405 0000C3CA F5                  <1> 	cmc	;stc
  1406 0000C3CB EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
  1407                              <1> 
  1408                              <1> truncate_cluster_chain:
  1409                              <1> 	; 01/03/2016
  1410                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1411                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
  1412                              <1> 	; 11/09/2010
  1413                              <1> 	; INPUT ->
  1414                              <1> 	;	ESI = Logical dos drive description table address
  1415                              <1> 	;	EAX = First cluster to be truncated/unlinked 
  1416                              <1> 	; OUTPUT ->
  1417                              <1> 	;	ESI = Logical dos drive description table address
  1418                              <1> 	; 	ECX = Count of truncated/removed clusters
  1419                              <1> 	; 	CF = 0 -> EAX = Free sectors
  1420                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1421                              <1> 
  1422                              <1> 	; NOTE: This procedure does not update lm date&time ! 
  1423                              <1> 
  1424                              <1> loc_truncate_cc:	
  1425 0000C3CD 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
  1426                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1427 0000C3CF 890D[82600100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  1428                              <1> 
  1429                              <1> loc_tcc_unlink_clusters:
  1430 0000C3D5 E8F3FAFFFF          <1> 	call	update_cluster
  1431                              <1> 	; EAX = Next Cluster
  1432                              <1> 	; ECX = Cluster Value
  1433                              <1> 	; Note:
  1434                              <1> 	; Returns count of unlinked clusters in
  1435                              <1> 	; dword ptr FAT_ClusterCounter
  1436 0000C3DA 73F9                <1> 	jnc short loc_tcc_unlink_clusters
  1437                              <1> 
  1438                              <1> pass_tcc_unlink_clusters:
  1439 0000C3DC A2[37630100]        <1> 	mov	byte [TCC_FATErr], al
  1440 0000C3E1 803D[7A600100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  1441 0000C3E8 750E                <1> 	jne	short loc_tcc_calculate_FAT_freespace
  1442 0000C3EA E89BFDFFFF          <1> 	call	save_fat_buffer
  1443 0000C3EF 7307                <1> 	jnc	short loc_tcc_calculate_FAT_freespace
  1444 0000C3F1 A2[37630100]        <1> 	mov	byte [TCC_FATErr], al ; Error
  1445                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1446                              <1> 
  1447                              <1> 	; 01/03/2016
  1448 0000C3F6 EB12                <1> 	jmp	short loc_tcc_recalculate_FAT_freespace
  1449                              <1> 
  1450                              <1> loc_tcc_calculate_FAT_freespace:
  1451 0000C3F8 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter] ; signed (+-) number
  1452 0000C3FD 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
  1453                              <1> 			   ; BL = 1 -> add cluster
  1454 0000C401 E819FEFFFF          <1> 	call	calculate_fat_freespace
  1455 0000C406 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  1456 0000C408 7409                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
  1457                              <1> 
  1458                              <1> loc_tcc_recalculate_FAT_freespace:
  1459 0000C40A 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate !
  1460 0000C40E E80CFEFFFF          <1> 	call	calculate_fat_freespace
  1461                              <1>               
  1462                              <1> loc_tcc_calculate_FAT_freespace_err:
  1463                              <1> pass_truncate_cc_recalc_FAT_freespace:
  1464 0000C413 8B0D[82600100]      <1> 	mov	ecx, [FAT_ClusterCounter]
  1465                              <1> 
  1466 0000C419 803D[37630100]00    <1> 	cmp	byte [TCC_FATErr], 0
  1467 0000C420 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
  1468                              <1> 
  1469                              <1> loc_tcc_unlink_clusters_error:
  1470 0000C422 0FB605[37630100]    <1> 	movzx	eax, byte [TCC_FATErr]
  1471 0000C429 F9                  <1> 	stc
  1472                              <1> loc_tcc_unlink_clusters_retn:
  1473 0000C42A C3                  <1> 	retn
  1474                              <1> 
  1475                              <1> set_fat32_fsinfo_sector_parms:
  1476                              <1> 	; 15/10/2016
  1477                              <1> 	; 23/03/2016
  1478                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1479                              <1> 	; INPUT ->
  1480                              <1> 	;	ESI = Logical dos drive description table address
  1481                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
  1482                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First Free Cluster 
  1483                              <1> 	; OUTPUT ->
  1484                              <1> 	;	ESI = Logical dos drive description table address
  1485                              <1> 	; 	CF = 0 -> OK..
  1486                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1487                              <1> 	;
  1488                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1489                              <1> 
  1490 0000C42B E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
  1491 0000C430 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
  1492                              <1> 
  1493 0000C432 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
  1494 0000C435 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
  1495                              <1> 
  1496                              <1>         ;mov	ebx, DOSBootSectorBuff
  1497 0000C438 8983E8010000        <1> 	mov	[ebx+488], eax
  1498 0000C43E 8993EC010000        <1> 	mov	[ebx+492], edx	
  1499                              <1> 
  1500 0000C444 A1[24630100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1501 0000C449 B901000000          <1> 	mov	ecx, 1
  1502 0000C44E E8D1330000          <1> 	call	disk_write
  1503                              <1> 	;jnc     short update_fat32_fsinfo_sector_retn
  1504                              <1> 
  1505                              <1> 	; 15/10/2016 (1Dh -> 18)
  1506                              <1> 	; 23/03/2016 (1Dh)
  1507                              <1> 	;mov	eax, 18 ; Drive not ready or write error
  1508                              <1> 
  1509                              <1> update_fat32_fsinfo_sector_retn:
  1510 0000C453 C3                  <1> 	retn
  1511                              <1> 
  1512                              <1> get_fat32_fsinfo_sector_parms:
  1513                              <1> 	; 15/10/2016
  1514                              <1> 	; 23/03/2016
  1515                              <1> 	; 01/03/2016
  1516                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
  1517                              <1> 	; INPUT ->
  1518                              <1> 	;	ESI = Logical dos drive description table address
  1519                              <1> 	; OUTPUT ->
  1520                              <1> 	;	ESI = Logical dos drive description table address
  1521                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
  1522                              <1> 	;	CF = 0 -> OK..
  1523                              <1> 	;	   EAX = FsInfo sector address
  1524                              <1> 	;	   ECX = Free cluster count
  1525                              <1> 	;	   EDX = First free cluster 	
  1526                              <1> 	;	CF = 1 -> Error code in AL (EAX)
  1527                              <1> 	;	   EBX = 0
  1528                              <1> 	;	
  1529                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
  1530                              <1>         ;
  1531                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1532                              <1> 
  1533 0000C454 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
  1534 0000C458 03466C              <1> 	add	eax, [esi+LD_StartSector]
  1535 0000C45B A3[24630100]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
  1536                              <1> 	
  1537 0000C460 BB[765E0100]        <1>         mov     ebx, DOSBootSectorBuff
  1538 0000C465 B901000000          <1> 	mov	ecx, 1
  1539 0000C46A E8C4330000          <1> 	call	disk_read
  1540 0000C46F 7232                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
  1541                              <1> 
  1542 0000C471 BB[765E0100]        <1> 	mov	ebx, DOSBootSectorBuff
  1543                              <1> 
  1544 0000C476 813B52526141        <1> 	cmp	dword [ebx], 41615252h
  1545 0000C47C 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1546                              <1> 
  1547 0000C47E 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
  1547 0000C487 61                  <1>
  1548 0000C488 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1549                              <1> 
  1550 0000C48A A1[24630100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1551 0000C48F 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
  1552 0000C495 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
  1553                              <1> 
  1554 0000C49B C3                  <1> 	retn
  1555                              <1> 
  1556                              <1> loc_read_FAT32_fsinfo_sec_stc: 
  1557                              <1> 	; 15/10/2016 (0Bh -> 28)
  1558 0000C49C B81C000000          <1> 	mov	eax, 28 ; Invalid format!
  1559 0000C4A1 EB05                <1> 	jmp	short loc_read_FAT32_fsinfo_sec_stc_retn
  1560                              <1> 
  1561                              <1> loc_read_FAT32_fsinfo_sec_err:
  1562                              <1> 	; 15/10/2016 (15h -> 17)
  1563                              <1> 	; 23/03/2016 (15h)
  1564 0000C4A3 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error
  1565                              <1> 
  1566                              <1> loc_read_FAT32_fsinfo_sec_stc_retn:
  1567 0000C4A8 29DB                <1> 	sub	ebx, ebx ; 0
  1568 0000C4AA F9                  <1> 	stc
  1569 0000C4AB C3                  <1> 	retn
  1570                              <1> 
  1571                              <1> add_new_cluster:
  1572                              <1> 	; 15/10/2016
  1573                              <1> 	; 16/05/2016
  1574                              <1> 	; 18/03/2016, 24/03/2016
  1575                              <1> 	; 11/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1576                              <1> 	; 30/07/2011 (DRV_FAT.ASM)
  1577                              <1> 	; 11/09/2010
  1578                              <1> 	; INPUT ->
  1579                              <1> 	;	ESI = Logical dos drv desc. table address
  1580                              <1> 	;	EAX = Last cluster
  1581                              <1> 	; OUTPUT ->
  1582                              <1> 	;	ESI = Logical dos drv desc. table address
  1583                              <1> 	;	EAX = New Last cluster (next cluster)
  1584                              <1> 	;	cf = 1 -> error code in EAX (AL)
  1585                              <1> 	;	cf = 1 -> DX = sectors per cluster
  1586                              <1> 	;	ECX = Free sectors
  1587                              <1> 	; NOTE:
  1588                              <1> 	; This procedure does not update lm date&time !
  1589                              <1> 	;
  1590                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, EDI)
  1591                              <1> 	;
  1592                              <1> 
  1593 0000C4AC A3[54640100]        <1> 	mov	[FAT_anc_LCluster], eax
  1594                              <1> 	
  1595 0000C4B1 E844F9FFFF          <1> 	call	get_first_free_cluster
  1596 0000C4B6 720B                <1> 	jc	short loc_add_new_cluster_retn
  1597                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
  1598                              <1> 
  1599 0000C4B8 89C2                <1> 	mov	edx, eax
  1600                              <1> 
  1601 0000C4BA 42                  <1> 	inc	edx
  1602                              <1> 	;jnz	short loc_add_new_cluster_check_ffc_eax
  1603 0000C4BB 7516                <1> 	jnz	short loc_add_new_cluster_save_fcc
  1604                              <1> 
  1605                              <1> loc_add_new_cluster_no_disk_space_retn:
  1606 0000C4BD B827000000          <1> 	mov	eax, 27h ; MSDOS err => insufficient disk space
  1607                              <1> loc_add_new_cluster_stc_retn:
  1608 0000C4C2 F9                  <1> 	stc
  1609                              <1> loc_add_new_cluster_retn:
  1610 0000C4C3 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  1611 0000C4C7 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1612                              <1> 	;xor	edx, edx
  1613                              <1> 	;stc
  1614 0000C4CA C3                  <1> 	retn
  1615                              <1> 
  1616                              <1> loc_anc_invalid_format_stc_retn:
  1617 0000C4CB F9                  <1> 	stc
  1618                              <1> loc_add_new_cluster_invalid_format_retn:
  1619                              <1> 	; 15/10/2016 (0Bh -> 28)
  1620 0000C4CC B81C000000          <1> 	mov	eax, 28 ; Invalid format
  1621 0000C4D1 EBF0                <1> 	jmp	short loc_add_new_cluster_retn 
  1622                              <1> 
  1623                              <1> ;loc_add_new_cluster_check_ffc_eax:
  1624                              <1> ;	cmp	eax, 2
  1625                              <1> ;	jb	short loc_add_new_cluster_invalid_format_retn
  1626                              <1> 
  1627                              <1> loc_add_new_cluster_save_fcc:  
  1628 0000C4D3 A3[58640100]        <1> 	mov	[FAT_anc_FFCluster], eax
  1629                              <1> 
  1630 0000C4D8 83E802              <1> 	sub	eax, 2
  1631 0000C4DB 0FB65E13            <1>         movzx   ebx, byte [esi+LD_BPB+SecPerClust]
  1632 0000C4DF F7E3                <1> 	mul	ebx
  1633 0000C4E1 09D2                <1> 	or	edx, edx
  1634 0000C4E3 75E6                <1> 	jnz	short loc_anc_invalid_format_stc_retn
  1635                              <1> 
  1636                              <1> loc_add_new_cluster_allocate_cluster:
  1637                              <1> 	; 18/03/2016
  1638 0000C4E5 92                  <1> 	xchg	edx, eax ; eax = 0
  1639                              <1> 	; 16/05/2016
  1640                              <1> 	;cmp	[ClusterBuffer_Valid], al ; 0
  1641                              <1> 	;jna	short loc_anc_clear_cluster_buffer
  1642                              <1> 	;; 'copy' command, 
  1643                              <1> 	;; writing destination file clust after reading source file clust
  1644                              <1> 	;mov	[ClusterBuffer_Valid], al ; 0 ; reset
  1645                              <1> 	;jmp	short loc_add_new_cluster_write_nc_to_disk
  1646                              <1> 
  1647                              <1> loc_anc_clear_cluster_buffer:
  1648                              <1> 	; 11/03/2016
  1649                              <1> 	; Clear buffer
  1650 0000C4E6 BF00000700          <1> 	mov	edi, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  1651 0000C4EB 89D9                <1> 	mov	ecx, ebx ; sector count
  1652 0000C4ED C1E107              <1> 	shl	ecx, 7 ; 1 sector = 512 bytes -> 128 double words
  1653                              <1> 	;xor	eax, eax ; 0
  1654 0000C4F0 F3AB                <1> 	rep	stosd
  1655                              <1> 
  1656                              <1> loc_add_new_cluster_write_nc_to_disk:
  1657                              <1> 	; 11/03/2016
  1658                              <1> 	;xchg	eax, edx ; edx = 0, eax = sector offset
  1659 0000C4F2 89D0                <1> 	mov	eax, edx
  1660 0000C4F4 034668              <1>         add     eax, [esi+LD_DATABegin]
  1661 0000C4F7 72D3                <1> 	jc	short loc_add_new_cluster_invalid_format_retn 
  1662                              <1> 		
  1663 0000C4F9 89D9                <1> 	mov	ecx, ebx ; ECX = sectors per cluster (<256)
  1664 0000C4FB BB00000700          <1> 	mov	ebx, Cluster_Buffer
  1665 0000C500 E81F330000          <1> 	call	disk_write
  1666 0000C505 7307                <1> 	jnc	short loc_add_new_cluster_update_fat_nlc
  1667                              <1> 	
  1668                              <1> 	; 15/10/2016 (1Dh -> 18)
  1669 0000C507 B812000000          <1> 	mov	eax, 18 ; Write Error
  1670 0000C50C EBB4                <1> 	jmp	short loc_add_new_cluster_stc_retn
  1671                              <1> 
  1672                              <1> loc_add_new_cluster_update_fat_nlc:
  1673 0000C50E A1[58640100]        <1> 	mov	eax, [FAT_anc_FFCluster]
  1674 0000C513 31C9                <1> 	xor	ecx, ecx
  1675 0000C515 890D[82600100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  1676 0000C51B 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  1677 0000C51C E8ACF9FFFF          <1> 	call	update_cluster
  1678 0000C521 7304                <1> 	jnc	short loc_add_new_cluster_update_fat_plc
  1679 0000C523 09C0                <1> 	or	eax, eax ;EAX = 0 -> cluster value is 0 or eocc
  1680 0000C525 759B                <1> 	jnz	short loc_add_new_cluster_stc_retn
  1681                              <1> 
  1682                              <1> loc_add_new_cluster_update_fat_plc:
  1683 0000C527 A1[54640100]        <1> 	mov	eax, [FAT_anc_LCluster]
  1684 0000C52C 8B0D[58640100]      <1> 	mov	ecx, [FAT_anc_FFCluster]
  1685 0000C532 E896F9FFFF          <1> 	call	update_cluster
  1686 0000C537 7314                <1> 	jnc	short loc_add_new_cluster_save_fat_buffer
  1687 0000C539 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1688 0000C53B 7410                <1> 	jz	short loc_add_new_cluster_save_fat_buffer
  1689                              <1> 
  1690                              <1> loc_anc_save_fat_buffer_err_retn:
  1691                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
  1692                              <1> 	;jb	short loc_add_new_cluster_retn
  1693                              <1> 
  1694 0000C53D 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  1695                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  1696 0000C541 50                  <1> 	push	eax
  1697 0000C542 E8D8FCFFFF          <1> 	call	calculate_fat_freespace
  1698 0000C547 58                  <1> 	pop	eax
  1699 0000C548 E975FFFFFF          <1>         jmp     loc_add_new_cluster_stc_retn
  1700                              <1> 
  1701                              <1> loc_add_new_cluster_save_fat_buffer:
  1702                              <1> 	;cmp	byte [FAT_BuffValidData], 2
  1703                              <1> 	;jne	short loc_add_new_cluster_calc_FAT_freespace 
  1704                              <1> 	;Byte [FAT_BuffValidData] =  2 
  1705 0000C54D E838FCFFFF          <1> 	call	save_fat_buffer
  1706 0000C552 72E9                <1> 	jc	short loc_anc_save_fat_buffer_err_retn
  1707                              <1> 
  1708                              <1> loc_add_new_cluster_calc_FAT_freespace:
  1709                              <1> 	;mov	eax, 1 ; Only one Cluster
  1710 0000C554 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1711 0000C559 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI -> Dos drv desc. table
  1712                              <1> 		; BL = 1 -> add cluster
  1713 0000C55D B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
  1714                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  1715                              <1> 	; (Free Cluster Count is decreased when EAX value is negative)
  1716 0000C55F E8BBFCFFFF          <1>         call    calculate_fat_freespace
  1717                              <1> 	;ECX = 0 -> no error, ECX > 0 -> error or invalid return
  1718 0000C564 21C9                <1> 	and	ecx, ecx ; ECX = 0 -> valid free sector count
  1719 0000C566 7409                <1> 	jz	short loc_add_new_cluster_return_cluster_number
  1720                              <1> 
  1721                              <1> loc_add_new_cluster_recalc_FAT_freespace:
  1722 0000C568 66BB00FF            <1> 	mov	bx, 0FF00h  ; recalculate free space
  1723 0000C56C E8AEFCFFFF          <1>         call    calculate_fat_freespace
  1724                              <1> 	; cf = 0
  1725                              <1> loc_add_new_cluster_return_cluster_number:
  1726 0000C571 89C1                <1> 	mov	ecx, eax ; Free sector count
  1727 0000C573 A1[58640100]        <1> 	mov	eax, [FAT_anc_FFCluster]
  1728 0000C578 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  1729                              <1> 	;mov	edi, Cluster_Buffer
  1730 0000C57C 31D2                <1> 	xor	edx, edx
  1731 0000C57E C3                  <1>         retn
  1732                              <1> 
  1733                              <1> write_cluster:
  1734                              <1> 	; 15/10/2016
  1735                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1736                              <1> 	;
  1737                              <1> 	; INPUT ->
  1738                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
  1739                              <1> 	;	ESI = Logical DOS Drive Description Table address
  1740                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
  1741                              <1> 	;	Only for SINGLIX FS:
  1742                              <1> 	;	EDX = File Number (The 1st FDT address) 
  1743                              <1> 	; OUTPUT ->
  1744                              <1> 	;	cf = 1 -> Cluster can not be written onto disk
  1745                              <1> 	;	    EAX > 0 -> Error number
  1746                              <1> 	;	cf = 0 -> Cluster has been written successfully
  1747                              <1> 	;
  1748                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  1749                              <1> 	
  1750 0000C57F 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
  1751                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  1752                              <1> 
  1753                              <1> write_file_sectors: ; 16/03/2016
  1754 0000C583 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  1755 0000C587 761C                <1> 	jna	short write_fs_cluster
  1756                              <1> 
  1757                              <1> write_fat_file_sectors: 
  1758 0000C589 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
  1759 0000C58C 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
  1760 0000C590 F7E2                <1> 	mul	edx
  1761 0000C592 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
  1762                              <1> 
  1763                              <1> 	; EAX = Disk sector address
  1764                              <1> 	; ECX = Sector count
  1765                              <1> 	; EBX = Buffer address
  1766                              <1> 	; (EDX = 0)
  1767                              <1> 	; ESI = Logical DOS drive description table address	
  1768                              <1> 
  1769 0000C595 E88A320000          <1> 	call	disk_write
  1770 0000C59A 7306                <1> 	jnc	short wclust_retn
  1771                              <1> 	
  1772                              <1> 	; 15/10/2016 (1Dh -> 18)
  1773 0000C59C B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error !
  1774 0000C5A1 C3                  <1> 	retn
  1775                              <1> 
  1776                              <1> wclust_retn:
  1777 0000C5A2 29C0                <1> 	sub	eax, eax ; 0
  1778 0000C5A4 C3                  <1> 	retn
  1779                              <1> 
  1780                              <1> write_fs_cluster:
  1781                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1782                              <1> 	; Singlix FS
  1783                              <1> 	
  1784                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
  1785                              <1> 	
  1786                              <1> 	; EDX = File number is the first File Descriptor Table address 
  1787                              <1> 	;	of the file. (Absolute address of the FDT).
  1788                              <1> 	
  1789                              <1> 	; eax = sector index (0 for the first sector)
  1790                              <1> 	; edx = FDT0 address
  1791                              <1> 		; 64 KB buffer = 128 sectors (limit) 
  1792 0000C5A5 B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
  1793 0000C5AA E801000000          <1> 	call	write_fs_sectors
  1794 0000C5AF C3                  <1> 	retn
  1795                              <1> 
  1796                              <1> write_fs_sectors:
  1797                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
  1798 0000C5B0 F9                  <1> 	stc
  1799 0000C5B1 C3                  <1> 	retn
  1800                              <1> 
  1801                              <1> get_cluster_by_index:
  1802                              <1> 	; 29/04/2016 (TRDOS 386 =  TRDOS v2.0)
  1803                              <1> 	; INPUT ->
  1804                              <1> 	; 	EAX = Beginning cluster
  1805                              <1> 	; 	EDX = Sector index in disk/file section
  1806                              <1> 	;	      (Only for SINGLIX file system!)
  1807                              <1> 	; 	ECX = Cluster sequence number after the beginning cluster
  1808                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  1809                              <1> 	; OUTPUT ->
  1810                              <1> 	;	EAX = Cluster number 
  1811                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  1812                              <1> 	;
  1813                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  1814                              <1> 	;	
  1815 0000C5B2 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  1816 0000C5B6 721E                <1>         jb      short get_fs_section_by_index 
  1817                              <1> 
  1818 0000C5B8 3B4E78              <1> 	cmp	ecx, [esi+LD_Clusters]
  1819 0000C5BB 7207                <1> 	jb	short gcbi_1
  1820                              <1> gcbi_0:
  1821 0000C5BD F9                  <1> 	stc
  1822 0000C5BE B823000000          <1> 	mov	eax, 23h ; Cluster not available ! 
  1823                              <1> 			 ; MSDOS error code: FCB unavailable
  1824 0000C5C3 C3                  <1> 	retn
  1825                              <1> gcbi_1:
  1826 0000C5C4 51                  <1> 	push	ecx
  1827 0000C5C5 E8D9F5FFFF          <1> 	call	get_next_cluster
  1828 0000C5CA 59                  <1> 	pop	ecx
  1829 0000C5CB 7203                <1> 	jc	short gcbi_3
  1830 0000C5CD E2F5                <1> 	loop	gcbi_1
  1831                              <1> gcbi_2:
  1832 0000C5CF C3                  <1> 	retn
  1833                              <1> gcbi_3:
  1834 0000C5D0 09C0                <1> 	or	eax, eax
  1835 0000C5D2 74E9                <1> 	jz	short gcbi_0
  1836 0000C5D4 F5                  <1> 	cmc 	; stc
  1837 0000C5D5 C3                  <1> 	retn
  1838                              <1> 
  1839                              <1> get_fs_section_by_index:
  1840                              <1> 	; 29/04/2016 (TRDOS 386 =  TRDOS v2.0)
  1841                              <1> 	; INPUT ->
  1842                              <1> 	; 	EAX = Beginning FDT number/address
  1843                              <1> 	; 	EDX = Sector index in disk/file section
  1844                              <1> 	; 	ECX = Sector sequence number after the beginning FDT
  1845                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  1846                              <1> 	; OUTPUT ->
  1847                              <1> 	; 	EAX = FDT number/address
  1848                              <1> 	; 	EDX = Sector index of the section (0,1,2,3,4...)
  1849                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  1850                              <1> 	;
  1851                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  1852                              <1> 	;
  1853 0000C5D6 B8FFFFFFFF          <1> 	mov	eax, 0FFFFFFFFh
  1854 0000C5DB C3                  <1> 	retn
  1855                              <1> 
  1856                              <1> get_last_section:
  1857                              <1> 	; 22/10/2016 (TRDOS 386 =  TRDOS v2.0)	
  1858                              <1> 	; INPUT ->
  1859                              <1> 	; 	EAX = (The 1st) FDT number/address
  1860                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  1861                              <1> 	; OUTPUT ->
  1862                              <1> 	; 	EAX = FDT number/address of the last section
  1863                              <1> 	; 	EDX = Last sector of the section (0,1,2,3,4...)
  1864                              <1> 	;	[glc_index] = sector index number of the last sector
  1865                              <1> 	;		      (for file, not for the last section)  	
  1866                              <1> 	;		   	
  1867                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  1868                              <1> 	;
  1869                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  1870                              <1> 	;
  1871 0000C5DC B800000000          <1> 	mov	eax, 0
  1872 0000C5E1 BA00000000          <1> 	mov	edx, 0
  1873 0000C5E6 C3                  <1> 	retn
  2310                                  %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: 31/12/2017
     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> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    14                              <1> ; TRDOS2.ASM (09/11/2011)
    15                              <1> ; ----------------------------------------------------------------------------
    16                              <1> ; INT_21H.ASM (c) 2009-2011 Erdogan TAN  [14/11/2009] Last Update: 08/11/2011
    17                              <1> 
    18                              <1> sysent: ; < enter to system call >
    19                              <1> 	; 17/03/2017
    20                              <1> 	; 03/03/2017
    21                              <1> 	; 19/02/2017
    22                              <1> 	; 13/01/2017
    23                              <1> 	; 06/06/2016
    24                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
    25                              <1> 	; 16/04/2015 - 19/10/2015 (Retro UNIX 386 v1)
    26                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
    27                              <1> 	;
    28                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
    29                              <1> 	; The trap type is determined and an indirect jump is made to 
    30                              <1> 	; the appropriate system call handler. If there is a trap inside
    31                              <1> 	; the system a jump to panic is made. All user registers are saved 
    32                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
    33                              <1> 	; instructor is decoded to get the the system code part (see
    34                              <1> 	; trap instruction in the PDP-11 handbook) and from this 
    35                              <1> 	; the indirect jump address is calculated. If a bad system call is
    36                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
    37                              <1> 	; is called. If the call is legitimate control passes to the
    38                              <1> 	; appropriate system routine.
    39                              <1> 	;
    40                              <1> 	; Calling sequence:
    41                              <1> 	;	Through a trap caused by any sys call outside the system.
    42                              <1> 	; Arguments:
    43                              <1> 	;	Arguments of particular system call.	
    44                              <1> 	; ...............................................................
    45                              <1> 	;	
    46                              <1> 	; Retro UNIX 8086 v1 modification: 
    47                              <1> 	;       System call number is in EAX register.
    48                              <1> 	;
    49                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
    50                              <1> 	;	registers depending of function details.
    51                              <1>   	;
    52                              <1> 	; 16/04/2015
    53 0000C5E7 368925[5C030300]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
    54                              <1> 
    55                              <1> 	; save user registers
    56 0000C5EE 1E                  <1> 	push	ds
    57 0000C5EF 06                  <1> 	push	es
    58 0000C5F0 0FA0                <1> 	push	fs
    59 0000C5F2 0FA8                <1> 	push	gs
    60 0000C5F4 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
    61                              <1> 	;
    62                              <1> 	; ESPACE = [ss:u.sp] - esp ; 4*12 = 48 ; 17/09/2015 ; 06/06/2016
    63                              <1> 	; 	(ESPACE is size of space in kernel stack 
    64                              <1> 	;	for saving/restoring user registers.)
    65                              <1> 	;
    66 0000C5F5 50                  <1> 	push	eax ; 01/07/2015
    67 0000C5F6 66B81000            <1> 	mov     ax, KDATA
    68 0000C5FA 8ED8                <1>         mov     ds, ax
    69 0000C5FC 8EC0                <1>         mov     es, ax
    70 0000C5FE 8EE0                <1>         mov     fs, ax
    71 0000C600 8EE8                <1>         mov     gs, ax
    72 0000C602 A1[A8580100]        <1> 	mov	eax, [k_page_dir]
    73 0000C607 0F22D8              <1> 	mov	cr3, eax
    74 0000C60A 58                  <1> 	pop	eax ; 01/07/2015
    75                              <1> 	; 19/10/2015
    76 0000C60B FC                  <1> 	cld
    77                              <1> 	;
    78 0000C60C FE05[5B030300]      <1> 	inc	byte [sysflg]
    79                              <1> 		; incb sysflg / indicate a system routine is in progress
    80 0000C612 FB                  <1>         sti 	; 18/01/2014
    81 0000C613 0F85D89DFFFF        <1> 	jnz     panic ; 24/05/2013
    82                              <1> 		; beq 1f
    83                              <1> 		; jmp panic ; / called if trap inside system
    84                              <1> ;1:
    85                              <1> 	; 17/03/2017
    86 0000C619 80642438FE          <1> 	and	byte [esp+ESPACE+8], ~1 ; clear carry flag
    87                              <1> 
    88                              <1> 	; 16/04/2015
    89 0000C61E A3[64030300]        <1> 	mov	[u.r0], eax
    90 0000C623 8925[60030300]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
    91                              <1> 
    92                              <1> 	; 13/01/2017 (TRDOS 386 Feaure only !)
    93 0000C629 803D[D4030300]00    <1> 	cmp	byte [u.t_lock], 0 ; timer interrupt lock ?
    94 0000C630 0F879D010000        <1> 	ja	sysrele		   ; yes, sys release only !!!
    95                              <1> 
    96                              <1> 		; mov $s.syst+2,clockp
    97                              <1> 		; mov r0,-(sp) / save user registers 
    98                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack 
    99                              <1> 			   ; / in u.r0
   100                              <1> 		; mov r1,-(sp)
   101                              <1> 		; mov r2,-(sp)
   102                              <1> 		; mov r3,-(sp)
   103                              <1> 		; mov r4,-(sp)
   104                              <1> 		; mov r5,-(sp)
   105                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
   106                              <1> 		             ; / arithmetic unit
   107                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
   108                              <1> 		             ; / extended arithmetic unit
   109                              <1> 		; mov sc,-(sp) / "step count" register for the extended
   110                              <1> 		             ; / arithmetic unit
   111                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
   112                              <1> 		; mov 18.(sp),r0 / store pc in r0
   113                              <1> 		; mov -(r0),r0 / sys inst in r0      10400xxx
   114                              <1> 		; sub $sys,r0 / get xxx code
   115 0000C636 C1E002              <1> 	shl	eax, 2
   116                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
   117 0000C639 3DB8000000          <1> 	cmp	eax, end_of_syscalls - syscalls
   118                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
   119                              <1> 	;jnb	short badsys
   120                              <1> 		; bhis badsys / yes, bad system call
   121 0000C63E F5                  <1> 	cmc
   122 0000C63F 9C                  <1> 	pushf	
   123 0000C640 50                  <1> 	push	eax
   124 0000C641 8B2D[5C030300]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
   125 0000C647 B0FE                <1> 	mov	al, 0FEh ; 11111110b
   126 0000C649 1400                <1> 	adc	al, 0 ; al = al + cf
   127 0000C64B 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
   128                              <1> 		; bic $341,20.(sp) / set users processor priority to 0 
   129                              <1> 				 ; / and clear carry bit
   130 0000C64E 5D                  <1> 	pop	ebp ; eax
   131 0000C64F 9D                  <1> 	popf
   132 0000C650 0F8208020000        <1>         jc      badsys
   133 0000C656 A1[64030300]        <1> 	mov	eax, [u.r0]
   134                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
   135 0000C65B FFA5[61C60000]      <1> 	jmp	dword [ebp+syscalls]
   136                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
   137                              <1> 		            ; / to proper system routine.
   138                              <1> syscalls: ; 1:
   139                              <1> 	; 31/12/2017
   140                              <1> 	; 28/02/2017
   141                              <1> 	; 20/02/2017
   142                              <1> 	; 19/02/2017
   143                              <1> 	; 15/10/2016
   144                              <1> 	; 20/05/2016
   145                              <1> 	; 19/05/2016
   146                              <1> 	; 16/05/2016
   147                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   148                              <1> 	; 21/09/2015
   149                              <1> 	; 01/07/2015
   150                              <1> 	; 16/04/2015 (32 bit address modification) 
   151 0000C661 [18E70000]          <1> 	dd sysver	; 0 ; Get TRDOS 386 version number (v2.0)	
   152 0000C665 [C0C80000]          <1> 	dd sysexit 	; 1
   153 0000C669 [95CA0000]          <1> 	dd sysfork 	; 2
   154 0000C66D [C8CE0000]          <1> 	dd sysread 	; 3
   155 0000C671 [E7CE0000]          <1> 	dd syswrite 	; 4
   156 0000C675 [7ECC0000]          <1> 	dd sysopen 	; 5
   157 0000C679 [9FCE0000]          <1> 	dd sysclose 	; 6
   158 0000C67D [17CA0000]          <1> 	dd syswait 	; 7
   159 0000C681 [ADCB0000]          <1> 	dd syscreat 	; 8
   160 0000C685 [6CF50000]          <1> 	dd sysrename	; 9  ; TRDOS 386, Rename File (31/12/2017)
   161 0000C689 [E7F00000]          <1> 	dd sysdelete	; 10 ; TRDOS 386, Delete File (29/12/2017)
   162 0000C68D [FBDA0000]          <1> 	dd sysexec 	; 11
   163 0000C691 [11F20000]          <1> 	dd syschdir 	; 12
   164 0000C695 [D6F30000]          <1> 	dd systime 	; 13 ; TRDOS 386, Get Sys Date&Time (30/12/2017)
   165 0000C699 [61CE0000]          <1> 	dd sysmkdir 	; 14
   166 0000C69D [45F20000]          <1> 	dd syschmod 	; 15 ; TRDOS 386, Change Attributes (30/12/2017) 
   167 0000C6A1 [4EF10000]          <1> 	dd sysrmdir 	; 16 ; TRDOS 386, Remove Directory (29/12/2017)
   168 0000C6A5 [D6DD0000]          <1> 	dd sysbreak 	; 17
   169 0000C6A9 [2BF30000]          <1> 	dd sysdrive 	; 18 ; TRDOS 386, Get/Set Current Drv (30/12/2017) 
   170 0000C6AD [17DE0000]          <1> 	dd sysseek 	; 19
   171 0000C6B1 [29DE0000]          <1> 	dd systell 	; 20
   172 0000C6B5 [8DF60000]          <1> 	dd sysmem 	; 21 ; TRDOS 386, Get Total&Free Mem (31/12/2017)
   173 0000C6B9 [C3F60000]          <1> 	dd sysprompt 	; 22 ; TRDOS 386, Change Cmd Prompt (31/12/2017)
   174 0000C6BD [05F70000]          <1> 	dd syspath 	; 23 ; TRDOS 386, Get/Set Run Path (31/12/2017)
   175 0000C6C1 [72F70000]          <1> 	dd sysenv 	; 24 ; TRDOS 386, Get/Set Env Vars (31/12/2017)
   176 0000C6C5 [57F40000]          <1> 	dd sysstime 	; 25 ; TRDOS 386, Set Sys Date&Time (30/12/2017)
   177 0000C6C9 [8FDE0000]          <1> 	dd sysquit 	; 26
   178 0000C6CD [83DE0000]          <1> 	dd sysintr 	; 27
   179 0000C6D1 [7AF30000]          <1> 	dd sysdir 	; 28 ; TRDOS 386, Get Curr Drive&Dir (30/12/2017) 
   180 0000C6D5 [7ECF0000]          <1> 	dd sysemt 	; 29
   181 0000C6D9 [B5F30000]          <1> 	dd sysldrvt	; 30 ; TRDOS 386, Get Logical DOS DDT (30/12/2017)
   182 0000C6DD [2FD10000]          <1> 	dd sysvideo 	; 31 ; TRDOS 386 Video Functions (16/05/2016)
   183 0000C6E1 [44010100]          <1> 	dd sysaudio 	; 32 ; TRDOS 386 Audio Functions (16/05/2016)
   184 0000C6E5 [97CF0000]          <1> 	dd systimer 	; 33 ; TRDOS 386 Timer Functions (18/05/2016)
   185 0000C6E9 [D0DE0000]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
   186                              <1> 			     ; 11/06/2014
   187 0000C6ED [FFDE0000]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
   188                              <1> 			     ; 01/07/2015
   189 0000C6F1 [D6DF0000]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
   190                              <1> 			     ; 21/09/2015 - get last error number
   191 0000C6F5 [BEF00000]          <1> 	dd sysfpstat	; 37 ; TRDOS 386 FPU state option (28/02/2017)
   192 0000C6F9 [27E70000]          <1> 	dd syspri 	; 38 ; change priority - TRDOS 386 (20/05/2016)
   193 0000C6FD [D3C70000]          <1> 	dd sysrele	; 39 ; TRDOS 386 (19/05/2016) (0 -> 39)
   194 0000C701 [5AE80000]          <1> 	dd sysfff	; 40 ; Find First File - TRDOS 386 (15/10/2016)
   195 0000C705 [39E90000]          <1> 	dd sysfnf	; 41 ; Find Next File - TRDOS 386 (15/10/2016)
   196 0000C709 [A9EF0000]          <1> 	dd sysalloc	; 42 ; Allocate contiguous memory block/pages
   197                              <1> 			     ; TRDOS 386 (19/02/2017) DMA buff fuctions		
   198 0000C70D [67F00000]          <1> 	dd sysdalloc	; 43 ; Deallocate contiguous memory block/pages
   199                              <1> 			     ; TRDOS 386 (19/02/2017) DMA buff fuctions
   200 0000C711 [A2F00000]          <1> 	dd syscalbac	; 44 ; IRQ Callback and Signal Response Byte
   201                              <1> 			     ; service setup - TRDOS 386 (20/02/2017)
   202                              <1> 			     ; 28/08/2017 (20/08/2017)	
   203 0000C715 [D5090100]          <1> 	dd sysdma	; 45 ; TRDOS 386 - (ISA) DMA service
   204                              <1> 	
   205                              <1> end_of_syscalls:
   206                              <1> 
   207                              <1> error:
   208                              <1> 	; 18/05/2016
   209                              <1> 	; 13/05/2016
   210                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   211                              <1> 	; 16/04/2015 - 17/09/2015 (Retro UNIX 386 v1)
   212                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
   213                              <1> 	;
   214                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
   215                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
   216                              <1> 	;
   217                              <1> 	; INPUTS -> none
   218                              <1> 	; OUTPUTS ->
   219                              <1> 	;	processor status - carry (c) bit is set (means error)
   220                              <1> 	;
   221                              <1> 	; 26/05/2013 (Stack pointer must be reset here! 
   222                              <1> 	; 	      Because, jumps to error procedure
   223                              <1> 	;	      disrupts push-pop nesting balance)
   224                              <1> 	;
   225 0000C719 8B2D[5C030300]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
   226 0000C71F 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
   227                              <1> 				 ; (system call will return with cf = 1)
   228                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
   229                              <1> 		               ; / users stack
   230                              <1> 	; 17/09/2015
   231 0000C723 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
   232                              <1> 				 ; for saving/restoring user registers	
   233                              <1> 	;cmp	ebp, [u.usp]
   234                              <1> 	;je	short err0	
   235 0000C726 892D[60030300]      <1> 	mov	[u.usp], ebp
   236                              <1> ;err0:
   237                              <1> 	; 01/09/2015
   238 0000C72C 8B25[60030300]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
   239                              <1> 				    ; 10/04/2013
   240                              <1> 				    ; (If an I/O error occurs during disk I/O,
   241                              <1> 				    ; related procedures will jump to 'error'
   242                              <1> 				    ; procedure directly without returning to 
   243                              <1> 				    ; the caller procedure. So, stack pointer
   244                              <1>                                     ; must be restored here.)
   245                              <1> 	; 13/05/2016
   246                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
   247                              <1> 	;	'get last error' system call later. 	
   248                              <1> 
   249                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
   250 0000C732 C605[C6030300]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
   251                              <1> 
   252                              <1> sysret: ; < return from system call>
   253                              <1> 	; 01/03/2017
   254                              <1> 	; 28/02/2017
   255                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   256                              <1> 	; 16/04/2015 - 10/09/2015 (Retro UNIX 386 v1)
   257                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
   258                              <1> 	;
   259                              <1> 	; 'sysret' first checks to see if process is about to be 
   260                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
   261                              <1> 	; If not, following happens:	 
   262                              <1> 	; 	1) The user's stack pointer is restored.
   263                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
   264                              <1> 	;	   i-node has been modified. If it has, it is written out
   265                              <1> 	;	   via 'ppoke'.
   266                              <1> 	;	3) If the super block has been modified, it is written out
   267                              <1> 	;	   via 'ppoke'.				
   268                              <1> 	;	4) If the dismountable file system's super block has been
   269                              <1> 	;	   modified, it is written out to the specified device
   270                              <1> 	;	   via 'ppoke'.
   271                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
   272                              <1> 	;	   during his execution. If so, 'tswap' is called to give
   273                              <1> 	;	   another user a chance to run.
   274                              <1> 	;	6) 'sysret' now goes into 'sysrele'. 
   275                              <1> 	;	    (See 'sysrele' for conclusion.)		
   276                              <1> 	;
   277                              <1> 	; Calling sequence:
   278                              <1> 	;	jump table or 'br sysret'
   279                              <1> 	; Arguments: 
   280                              <1> 	;	-	
   281                              <1> 	; ...............................................................
   282                              <1> 	;	
   283                              <1> 	; ((AX=r1 for 'iget' input))
   284                              <1> 	;	
   285 0000C739 31C0                <1> 	xor	eax, eax ; 28/02/2017
   286                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
   287 0000C73B FEC0                <1> 	inc	al ; 04/05/2013
   288 0000C73D 3805[B2030300]      <1> 	cmp	[u.bsys], al ; 1
   289                              <1> 		; tstb u.bsys / is a process about to be terminated because
   290 0000C743 0F8377010000        <1>         jnb     sysexit ; 04/05/2013
   291                              <1> 		; bne sysexit / of an error? yes, go to sysexit
   292                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
   293                              <1> 		; mov u.sp,sp / no point stack to users stack
   294 0000C749 FEC8                <1> 	dec 	al ; mov ax, 0
   295                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
   296 0000C74B E8CD300000          <1> 	call	iget
   297                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
   298                              <1> 		            ; / it is written out
   299                              <1> 	; 10/01/2017
   300                              <1> 	; 09/01/2017
   301                              <1> ;sysrele: ; < release >
   302                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   303                              <1> 	; 16/04/2015 - 14/10/2015 (Retro UNIX 386 v1)
   304                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
   305                              <1> 	;
   306                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
   307                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
   308                              <1> 	; turns off the system flag. It then checked to see if there is
   309                              <1> 	; an interrupt from the user by calling 'isintr'. If there is, 
   310                              <1> 	; the output gets flashed (see isintr) and interrupt action is
   311                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
   312                              <1> 	; the user, a rti is made.
   313                              <1> 	;
   314                              <1> 	; Calling sequence:
   315                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
   316                              <1> 	; Arguments:
   317                              <1> 	;	-	
   318                              <1> 	; ...............................................................
   319                              <1> 	;	
   320                              <1> 	; 23/02/2014 (swapret)
   321                              <1> 	; 22/09/2013
   322                              <1> sysrel0: ;1:
   323 0000C750 803D[A8030300]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
   324                              <1> 		; tstb uquant / is the time quantum 0?
   325 0000C757 7705                <1>         ja      short swapret
   326                              <1> 		; bne 1f / no, don't swap it out
   327                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
   328 0000C759 E8821E0000          <1> 	call	tswap
   329                              <1> 		; jsr r0,tswap / yes, swap it out
   330                              <1> 	
   331                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
   332                              <1> swapret: ;1:
   333                              <1> 	; 10/09/2015
   334                              <1> 	; 01/09/2015
   335                              <1> 	; 14/05/2015
   336                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
   337                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
   338                              <1> 	; cli
   339                              <1> 	; 24/07/2015
   340                              <1> 	;
   341                              <1> 	;; 'esp' must be already equal to '[u.usp]' here ! 
   342                              <1> 	;; mov	esp, [u.usp]
   343                              <1> 
   344                              <1> 	; 22/09/2013
   345 0000C75E E8BB300000          <1> 	call	isintr
   346                              <1> 	; 20/10/2013
   347 0000C763 7405                <1> 	jz	short sysrel1
   348 0000C765 E83F010000          <1> 	call	intract
   349                              <1> 		; jsr r0,isintr / is there an interrupt from the user
   350                              <1> 		;     br intract / yes, output gets flushed, take interrupt
   351                              <1> 		               ; / action
   352                              <1> sysrel1:
   353 0000C76A FA                  <1> 	cli	; 14/10/2015
   354                              <1> sysrel2:
   355                              <1> 	; 28/02/2017
   356                              <1> 	; Check if there is a (delayed) callback for current user/process
   357 0000C76B A0[D7030300]        <1> 	mov	al, [u.irqwait]
   358 0000C770 240F                <1> 	and	al, 0Fh ; is there a waiting IRQ callback service ?
   359 0000C772 7444                <1> 	jz	short sysrel8 ; no
   360                              <1> 
   361                              <1> 	; Set return to IRQ callback service and return from the service
   362 0000C774 0FB6D8              <1> 	movzx	ebx, al
   363 0000C777 883D[D7030300]      <1> 	mov 	[u.irqwait], bh ; 0 ; reset
   364 0000C77D 8A9B[70160100]      <1> 	mov	bl, [ebx+IRQenum] ; (available) IRQ index +1 (1 to 9)
   365                              <1> 	; 01/03/2017
   366 0000C783 FECB                <1> 	dec	bl ; IRQ index number, 0 to 8
   367 0000C785 7831                <1> 	js	short sysrel8 ; 0 -> FFh (not in use!?) 
   368                              <1> 	;
   369 0000C787 A0[B3030300]        <1> 	mov 	al, [u.uno] ; current process (user) number 
   370 0000C78C 3883[D26A0100]      <1> 	cmp	[ebx+IRQ.owner], al
   371 0000C792 7524                <1> 	jne	short sysrel8 ; it is not the current user/process !?
   372 0000C794 F683[E46A0100]01    <1> 	test	byte [ebx+IRQ.method], 1 ; callback ?
   373 0000C79B 741B                <1> 	jz	short sysrel8 ; not a callback method !?
   374                              <1> 
   375 0000C79D 8B93[F66A0100]      <1> 	mov	edx, [ebx+IRQ.addr] ; IRQ callback service address (virtual)
   376 0000C7A3 C605[D8030300]01    <1> 	mov	byte [u.r_lock], 1 ; IRQ callback service in progress flag
   377                              <1> 
   378 0000C7AA E8D91E0000          <1> 	call	wswap ; save user's registers & status 
   379                              <1> 		      ;	(for return from IRQ callback service)
   380                              <1> 
   381 0000C7AF 8B2D[5C030300]      <1> 	mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
   382 0000C7B5 895500              <1> 	mov	[ebp], edx ; IRQ call back service address
   383                              <1> sysrel8:
   384 0000C7B8 FE0D[5B030300]      <1> 	dec	byte [sysflg]
   385                              <1> 		; decb sysflg / turn system flag off
   386                              <1> 	
   387 0000C7BE A1[B8030300]        <1> 	mov	eax, [u.pgdir]	
   388 0000C7C3 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
   389                              <1> 			  ; (others are different than kernel page tables) 
   390                              <1> 	; 10/09/2015
   391 0000C7C6 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
   392                              <1> 		; mov (sp)+,sc / restore user registers
   393                              <1> 		; mov (sp)+,mq
   394                              <1> 		; mov (sp)+,ac
   395                              <1> 		; mov (sp)+,r5
   396                              <1> 		; mov (sp)+,r4
   397                              <1> 		; mov (sp)+,r3
   398                              <1> 		; mov (sp)+,r2
   399                              <1> 	;
   400 0000C7C7 A1[64030300]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
   401 0000C7CC 0FA9                <1> 	pop	gs
   402 0000C7CE 0FA1                <1> 	pop	fs
   403 0000C7D0 07                  <1> 	pop	es
   404 0000C7D1 1F                  <1> 	pop	ds
   405                              <1> 	;or	word [esp+8], 200h ; 22/01/2017 ; force enabling interrupts
   406 0000C7D2 CF                  <1> 	iretd	
   407                              <1> 		; rti / no, return from interrupt
   408                              <1> 
   409                              <1> sysrele:
   410                              <1> 	; 24/03/2017
   411                              <1> 	; 28/02/2017
   412                              <1> 	; 27/02/2017
   413                              <1> 	; 29/01/2017
   414                              <1> 	; 14/01/2017
   415                              <1> 	; 13/01/2017
   416                              <1> 	; 09/01/2017, 10/01/2017, 12/01/2017
   417                              <1> 	; Major modification for TRDOS 386 (CallBack return)
   418                              <1> 	;
   419                              <1> 	; 'sysrele' system call restores previously saved
   420                              <1> 	; registers and addresses of the process
   421                              <1> 	; (Main purpose -in TRDOS 386- is to return from
   422                              <1> 	; timer callback service routine in ring 3 -user mode-.)
   423                              <1> 	;
   424                              <1> 	; check if the process is in timer callback phase
   425 0000C7D3 803D[D4030300]00    <1> 	cmp	byte [u.t_lock], 0 ; TIMER INT LOCK
   426                              <1> 	;je	short sysrel0 ; classic (Retro UNIX 386 type) sysrele
   427 0000C7DA 7734                <1> 	ja	short sysrel3
   428                              <1> 	; 27/02/2017
   429 0000C7DC 803D[D8030300]00    <1> 	cmp	byte [u.r_lock], 0 ; IRQ callback lock	
   430 0000C7E3 0F8667FFFFFF        <1> 	jna	sysrel0 ; classic sysrele ; 24/03/2017
   431 0000C7E9 E859000000          <1> 	call	sysrel7
   432 0000C7EE 803D[D8030300]00    <1> 	cmp	byte [u.r_lock], 0 ; IRQ callback service lock
   433 0000C7F5 7628                <1> 	jna	short sysrel4
   434 0000C7F7 C605[D8030300]00    <1> 	mov	byte [u.r_lock], 0 ; reset
   435                              <1> 	;mov	byte [u.irqwait], 0 ; reset ; 28/02/2017
   436 0000C7FE A0[D9030300]        <1> 	mov	al, [u.r_mode]
   437 0000C803 08C0                <1> 	or	al, al
   438 0000C805 7518                <1> 	jnz	short sysrel4
   439 0000C807 FEC8                <1> 	dec	al
   440 0000C809 A2[D9030300]        <1> 	mov	[u.r_mode], al ; 0FFh ; not necessary !?
   441 0000C80E EB32                <1> 	jmp	short sysrel6		
   442                              <1> sysrel3:
   443                              <1> 	; 27/02/2017
   444 0000C810 E832000000          <1> 	call	sysrel7
   445                              <1> 	; 14/01/2017
   446 0000C815 28C0                <1> 	sub	al, al
   447 0000C817 3805[D4030300]      <1> 	cmp	[u.t_lock], al ; 0 ; TIMER INT LOCK
   448 0000C81D 770E                <1> 	ja	short sysrel5 ; yes
   449                              <1> sysrel4:
   450                              <1> 	; 29/01/2017
   451 0000C81F 8B44241C            <1> 	mov	eax, [esp+28] ; eax
   452 0000C823 A3[64030300]        <1> 	mov	[u.r0], eax
   453 0000C828 E93EFFFFFF          <1> 	jmp	sysrel2
   454                              <1> sysrel5:
   455 0000C82D A2[D4030300]        <1> 	mov	[u.t_lock], al ; 0 ; reset
   456 0000C832 A0[D5030300]        <1> 	mov	al, [u.t_mode]
   457 0000C837 20C0                <1> 	and	al, al
   458                              <1> 	;jnz	short sysrel2 ; 0FFh ; user mode
   459 0000C839 75E4                <1> 	jnz	short sysrel4 ; 29/01/2017
   460 0000C83B FEC8                <1> 	dec	al
   461 0000C83D A2[D5030300]        <1> 	mov	[u.t_mode], al ; 0FFh ; not necessary !?
   462                              <1> sysrel6:
   463                              <1> 	; cpu will continue from the interrupted sytem call addr
   464 0000C842 61                  <1> 	popad		; edi, esi, ebp, esp, ebx, edx, ecx, eax
   465 0000C843 83C410              <1> 	add	esp, 16	; pass segment segisters: ds, es, fs, gs		
   466 0000C846 CF                  <1> 	iretd		; eip, cs, eflags
   467                              <1> 
   468                              <1> sysrel7:
   469 0000C847 0FB61D[B3030300]    <1> 	movzx	ebx, byte [u.uno] ; current process number
   470 0000C84E 66C1E302            <1> 	shl	bx, 2
   471                              <1> 	;cmp	[ebx+p.tcb-4], eax ; 0 ; is there callback address ?
   472                              <1> 	;jna	short sysrel0 
   473                              <1> 	; yes, reset callback address then restore process registers 
   474                              <1> 	;mov	[ebx+p.tcb-4], eax ; 0 ; reset
   475 0000C852 8B83[BC000300]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address
   476 0000C858 FA                  <1> 	cli	; disable interrupts till 'iretd'
   477 0000C859 E9621E0000          <1> 	jmp	rswap ; restore process 'u' structure
   478                              <1>  
   479                              <1> badsys:
   480                              <1> 	; 25/12/2016
   481                              <1> 	; 18/04/2016 (TRDOS 386 = TRDOS v2.0)
   482                              <1> 	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
   483                              <1> 	; 03/02/2011 ('trdos_ifc_routine')
   484                              <1> 	;
   485                              <1> 	; 16/04/2015 (Retro UNIX 386 v1, 'badsys')
   486                              <1> 	; (EIP, EAX values will be shown on screen with error message)
   487                              <1> 	; (EIP = 'CD 40h' instruction address -INT 40h-)
   488                              <1> 	; (EAX = Function number)  
   489                              <1> 	;
   490 0000C85E FE05[B2030300]      <1> 	inc	byte [u.bsys]
   491                              <1> 	;
   492 0000C864 8B1D[5C030300]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
   493 0000C86A 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
   494 0000C86C 83E802              <1> 	sub	eax, 2 ; CDh, ##h
   495 0000C86F E8C56AFFFF          <1> 	call	dwordtohex
   496 0000C874 8915[49140100]      <1> 	mov	[eip_str], edx
   497 0000C87A A3[4D140100]        <1> 	mov	[eip_str+4], eax
   498 0000C87F A1[64030300]        <1> 	mov	eax, [u.r0]
   499 0000C884 E8B06AFFFF          <1> 	call	dwordtohex
   500 0000C889 8915[38140100]      <1> 	mov	[eax_str], edx
   501 0000C88F A3[3C140100]        <1> 	mov	[eax_str+4], eax
   502                              <1> 
   503 0000C894 66C705[2D140100]34- <1> 	mov	word [int_num_str], SYSCALL_INT_NUM ; 25/12/2016
   503 0000C89C 30                  <1>
   504                              <1> 
   505 0000C89D BE[FF130100]        <1> 	mov	esi, ifc_msg ; "invalid funtion call !" msg (trdosk9.s)
   506 0000C8A2 E8F69AFFFF          <1> 	call	print_msg
   507                              <1> 
   508 0000C8A7 EB17                <1> 	jmp	sysexit
   509                              <1> 
   510                              <1> intract: ; / interrupt action
   511                              <1> 	; 14/10/2015
   512                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
   513                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
   514                              <1> 	;
   515                              <1> 	; Retro UNIX 8086 v1 modification !
   516                              <1> 	; (Process/task switching and quit routine by using
   517                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
   518                              <1> 	;
   519                              <1> 	; input -> 'u.quit'  (also value of 'u.intr' > 0)
   520                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
   521                              <1> 	;		'intract' will jump to 'sysexit'.
   522                              <1> 	;	    Intract will return to the caller 
   523                              <1> 	;		if value of 'u.quit' <> FFFFh. 	 
   524                              <1> 	; 14/10/2015
   525 0000C8A9 FB                  <1> 	sti
   526                              <1> 	; 07/12/2013	
   527 0000C8AA 66FF05[AC030300]    <1> 	inc 	word [u.quit]
   528 0000C8B1 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
   529 0000C8B3 66FF0D[AC030300]    <1> 	dec	word [u.quit]
   530                              <1> 	; 16/04/2015
   531 0000C8BA C3                  <1> 	retn
   532                              <1> intrct0:	
   533 0000C8BB 58                  <1> 	pop	eax ; call intract -> retn
   534                              <1> 	;
   535 0000C8BC 31C0                <1> 	xor 	eax, eax
   536 0000C8BE FEC0                <1> 	inc	al  ; mov ax, 1
   537                              <1> ;;;
   538                              <1> 	; UNIX v1 original 'intract' routine... 
   539                              <1> 	; / interrupt action
   540                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
   541                              <1> 		; bne 1f / no, 1f
   542                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
   543                              <1> 	; 1: / now in user area
   544                              <1> 		; mov r1,-(sp) / save r1
   545                              <1> 		; mov u.ttyp,r1 
   546                              <1> 			; / pointer to tty buffer in control-to r1
   547                              <1> 		; cmpb 6(r1),$177
   548                              <1> 			; / is the interrupt char equal to "del"
   549                              <1> 		; beq 1f / yes, 1f
   550                              <1> 		; clrb 6(r1) 
   551                              <1> 		        ; / no, clear the byte 
   552                              <1> 			; / (must be a quit character)
   553                              <1> 		; mov (sp)+,r1 / restore r1
   554                              <1> 		; clr u.quit / clear quit flag
   555                              <1> 		; bis $20,2(sp) 
   556                              <1> 		    	; / set trace for quit (sets t bit of 
   557                              <1> 			; / ps-trace trap)
   558                              <1> 		; rti   ;  / return from interrupt
   559                              <1> 	; 1: / interrupt char = del
   560                              <1> 		; clrb 6(r1) / clear the interrupt byte 
   561                              <1> 			   ; / in the buffer
   562                              <1> 		; mov (sp)+,r1 / restore r1
   563                              <1> 		; cmp u.intr,$core / should control be 
   564                              <1> 				; / transferred to loc core?
   565                              <1> 		; blo 1f
   566                              <1> 		; jmp *u.intr / user to do rti yes, 
   567                              <1> 				; / transfer to loc core
   568                              <1> 	; 1:
   569                              <1> 		; sys 1 / exit
   570                              <1> 
   571                              <1> sysexit: ; <terminate process>
   572                              <1> 	; 14/11/2017
   573                              <1> 	; 27/05/2017
   574                              <1> 	; 10/04/2017
   575                              <1> 	; 26/02/2017, 28/02/2017
   576                              <1> 	; 02/01/2017, 23/01/2017
   577                              <1> 	; 06/06/2016, 10/06/2016
   578                              <1> 	; 19/05/2016, 23/05/2016
   579                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   580                              <1> 	; 16/04/2015 - 01/09/2015 (Retro UNIX 386 v1)
   581                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
   582                              <1> 	;
   583                              <1> 	; 'sysexit' terminates a process. First each file that
   584                              <1> 	; the process has opened is closed by 'flose'. The process
   585                              <1> 	; status is then set to unused. The 'p.pid' table is then
   586                              <1> 	; searched to find children of the dying process. If any of
   587                              <1> 	; children are zombies (died by not waited for), they are
   588                              <1> 	; set free. The 'p.pid' table is then searched to find the
   589                              <1> 	; dying process's parent. When the parent is found, it is
   590                              <1> 	; checked to see if it is free or it is a zombie. If it is
   591                              <1> 	; one of these, the dying process just dies. If it is waiting
   592                              <1> 	; for a child process to die, it notified that it doesn't 
   593                              <1> 	; have to wait anymore by setting it's status from 2 to 1
   594                              <1> 	; (waiting to active). It is awakened and put on runq by
   595                              <1> 	; 'putlu'. The dying process enters a zombie state in which
   596                              <1> 	; it will never be run again but stays around until a 'wait'
   597                              <1> 	; is completed by it's parent process. If the parent is not
   598                              <1> 	; found, process just dies. This means 'swap' is called with
   599                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
   600                              <1> 	; to write out the process and 'rswap' reads the new process
   601                              <1> 	; over the one that dies..i.e., the dying process is 
   602                              <1> 	; overwritten and destroyed.	
   603                              <1>  	;
   604                              <1> 	; Calling sequence:
   605                              <1> 	;	sysexit or conditional branch.
   606                              <1> 	; Arguments:
   607                              <1> 	;	-	
   608                              <1> 	; ...............................................................
   609                              <1> 	;	
   610                              <1> 	; Retro UNIX 8086 v1 modification: 
   611                              <1> 	;       System call number (=1) is in EAX register.
   612                              <1> 	;
   613                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
   614                              <1> 	;       registers depending of function details.
   615                              <1> 	;
   616                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
   617                              <1> 	;
   618                              <1> ; / terminate process
   619                              <1> 	; AX = 1
   620 0000C8C0 6648                <1> 	dec 	ax ; 0
   621 0000C8C2 66A3[AA030300]      <1> 	mov	[u.intr], ax ; 0
   622                              <1> 		; clr u.intr / clear interrupt control word
   623                              <1> 		; clr r1 / clear r1
   624                              <1> sysexit_0:
   625                              <1> 	; 23/01/2017
   626                              <1> 	; 02/01/2017
   627                              <1> 	; 10/06/2016
   628                              <1> 	; 06/06/2016
   629                              <1> 	; 23/05/2016
   630                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   631                              <1> 	; Check and stop/clear timer event(s) of this (dying) process
   632                              <1> 	; if there is.
   633                              <1> 
   634                              <1> 	; 02/01/2017 
   635 0000C8C8 FA                  <1> 	cli	; disable interrupts
   636                              <1> 	; 23/01/2017 - reset timer frequency (to 18.2Hz)
   637 0000C8C9 B036                <1> 	mov	al, 00110110b ; 36h
   638 0000C8CB E643                <1>  	out	43h, al
   639 0000C8CD 28C0                <1> 	sub	al, al ; 0
   640 0000C8CF E640                <1> 	out	40h, al ; LB
   641 0000C8D1 E640                <1> 	out	40h, al ; HB
   642                              <1>  	; 
   643 0000C8D3 0FB61D[B3030300]    <1> 	movzx	ebx, byte [u.uno]
   644                              <1> 	;mov	bl, [u.uno] ; process number of dying process
   645 0000C8DA 3883[FF000300]      <1> 	cmp	byte [ebx+p.timer-1], al ; 0
   646 0000C8E0 763A                <1> 	jna	short sysexit_12 ; no timer events for this process
   647 0000C8E2 8883[FF000300]      <1> 	mov	byte [ebx+p.timer-1], al ; 0 ; reset
   648                              <1> 	;mov	al, [timer_events]
   649                              <1> 	;or	al, al
   650                              <1>  	;jz	short sysexit_12 ; no timer events
   651                              <1> 	;mov	cl, al
   652 0000C8E8 8A0D[33650100]      <1> 	mov	cl, [timer_events] ; 14/11/2017
   653                              <1> 	;cli	; disable interrupts 
   654 0000C8EE B410                <1> 	mov	ah, 16 ; number of available timer events
   655 0000C8F0 BE[60040300]        <1> 	mov	esi, timer_set ; beginning address of timer events
   656                              <1> sysexit_7:
   657 0000C8F5 8A06                <1> 	mov	al, [esi] ; process number (of timer event)
   658 0000C8F7 38D8                <1> 	cmp	al, bl ; process number comparison
   659 0000C8F9 7411                <1> 	je	short sysexit_10
   660 0000C8FB 20C0                <1> 	and	al, al
   661 0000C8FD 7404                <1> 	jz	short sysexit_9
   662                              <1> sysexit_8:
   663 0000C8FF FEC9                <1> 	dec	cl
   664 0000C901 7416                <1> 	jz	short sysexit_11
   665                              <1> sysexit_9:
   666 0000C903 FECC                <1> 	dec	ah
   667 0000C905 7415                <1> 	jz	short sysexit_12
   668 0000C907 83C610              <1> 	add	esi, 16
   669 0000C90A EBE9                <1> 	jmp	short sysexit_7
   670                              <1> 
   671                              <1> sysexit_10:
   672                              <1> 	;mov	byte [esi], 0
   673 0000C90C 66C7060000          <1> 	mov	word [esi], 0
   674                              <1> 	;mov	dword [esi+12], 0
   675                              <1> 	;
   676 0000C911 FE0D[33650100]      <1> 	dec	byte [timer_events] ; 02/01/2017
   677                              <1> 	;
   678 0000C917 EBE6                <1> 	jmp	short sysexit_8
   679                              <1> 
   680                              <1> sysexit_11:
   681 0000C919 6629C0              <1> 	sub	ax, ax ; 0 ; 26/02/2017
   682                              <1> sysexit_12:
   683                              <1> 	; 26/02/2017 (Unlink IRQ callbacks belong to the user)
   684 0000C91C 803D[D6030300]00    <1> 	cmp	byte [u.irqc], 0 ; Count of IRQ callbacks
   685 0000C923 7E2E                <1> 	jng	short sysexit_16 ; zero or invalid
   686                              <1> 	; 28/02/2017
   687                              <1> 	; clear IRQ callback flags (for 'sysrele' and 'sysret')
   688 0000C925 A2[D7030300]        <1> 	mov	[u.irqwait], al ; 0 ; force to clear waiting flag
   689 0000C92A A2[D8030300]        <1> 	mov	[u.r_lock], al ; 0 ; force to clear busy flag
   690 0000C92F BE[D26A0100]        <1> 	mov	esi, IRQ.owner
   691                              <1> sysexit_13:	
   692 0000C934 AC                  <1> 	lodsb
   693 0000C935 3A05[B3030300]      <1> 	cmp	al, [u.uno] ; owner  = current user ?
   694 0000C93B 750C                <1> 	jne	short sysexit_14
   695 0000C93D C646FF00            <1> 	mov	byte [esi-1], 0 ; owner = 0 : Free
   696 0000C941 FE0D[D6030300]      <1> 	dec	byte [u.irqc]
   697 0000C947 7408                <1> 	jz	short sysexit_15
   698                              <1> sysexit_14:
   699 0000C949 81FE[DA6A0100]      <1> 	cmp	esi, IRQ.owner + 8 ; the last IRQ index number ?
   700 0000C94F 76E3                <1> 	jna	short sysexit_13 ; no
   701                              <1> sysexit_15:
   702 0000C951 30C0                <1> 	xor	al, al ; 0
   703                              <1> sysexit_16: ; 2:
   704 0000C953 FB                  <1> 	sti	; enable interrupts 
   705                              <1> 	;
   706                              <1> 	; AX = 0
   707                              <1> sysexit_1: ; 1:
   708                              <1> 	; AX = File descriptor
   709                              <1> 		; / r1 has file descriptor (index to u.fp list)
   710                              <1> 		; / Search the whole list
   711 0000C954 E89A130000          <1> 	call	fclose
   712                              <1> 		; jsr r0,fclose / close all files the process opened
   713                              <1> 	;; ignore error return
   714                              <1> 		; br .+2 / ignore error return
   715                              <1> 	;inc	ax
   716 0000C959 FEC0                <1> 	inc	al
   717                              <1> 		; inc r1 / increment file descriptor
   718                              <1> 	;cmp	ax, 10
   719 0000C95B 3C0A                <1> 	cmp	al, 10
   720                              <1> 		; cmp r1,$10. / end of u.fp list?
   721 0000C95D 72F5                <1> 	jb	short sysexit_1
   722                              <1> 		; blt 1b / no, go back
   723                              <1> 	;movzx	ebx, byte [u.uno]
   724 0000C95F 8A1D[B3030300]      <1> 	mov	bl, [u.uno] ; 02/01/2017
   725                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
   726 0000C965 88A3[AF000300]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   727                              <1> 		; clrb p.stat-1(r1) / free the process
   728                              <1> 	; 10/04/2017
   729 0000C96B 381D[496B0100]      <1> 	cmp	[audio_user], bl
   730 0000C971 7518                <1> 	jne	short sysexit_17
   731                              <1> 	; reset audio device (current) owner and 'initializated' flag
   732 0000C973 883D[496B0100]      <1> 	mov	[audio_user], bh ; 0
   733                              <1> 	; 27/05/2017
   734 0000C979 8B0D[346B0100]      <1> 	mov	ecx,  [audio_buffer]
   735 0000C97F 09C9                <1> 	or	ecx, ecx
   736 0000C981 7408                <1> 	jz	short sysexit_17
   737                              <1> 	; 'deallocate_user_pages' is not necessary in sysexit !!!
   738                              <1> 	;push	ebx
   739                              <1> 	;mov	ebx, ecx
   740                              <1> 	;mov	ecx, [audio_buff_size]
   741                              <1> 	;call	deallocate_user_pages
   742                              <1> 	;; (Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP)
   743 0000C983 29C9                <1> 	sub	ecx, ecx
   744 0000C985 890D[346B0100]      <1> 	mov	[audio_buffer], ecx ; 0
   745                              <1> 	;pop	ebx
   746                              <1> sysexit_17:
   747                              <1> 	;shl	bx, 1
   748 0000C98B D0E3                <1> 	shl	bl, 1
   749                              <1> 		; asl r1 / use r1 for index into the below tables
   750 0000C98D 668B8B[1E000300]    <1> 	mov	cx, [ebx+p.pid-2]
   751                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
   752 0000C994 668B93[3E000300]    <1> 	mov	dx, [ebx+p.ppid-2]
   753                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
   754                              <1> 	; xor 	bx, bx ; 0
   755 0000C99B 30DB                <1> 	xor	bl, bl ; 0
   756                              <1> 		; clr r2
   757 0000C99D 31F6                <1> 	xor	esi, esi ; 0
   758                              <1> 		; clr r5 / initialize reg
   759                              <1> sysexit_2: ; 1:
   760                              <1> 	        ; / find children of this dying process, 
   761                              <1> 		; / if they are zombies, free them
   762                              <1> 	;add	bx, 2
   763 0000C99F 80C302              <1> 	add	bl, 2
   764                              <1> 		; add $2,r2 / search parent process table 
   765                              <1> 		          ; / for dying process's name
   766 0000C9A2 66398B[3E000300]    <1> 	cmp	[ebx+p.ppid-2], cx
   767                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
   768 0000C9A9 7513                <1> 	jne	short sysexit_4
   769                              <1> 		; bne 3f / no
   770                              <1> 	;shr	bx, 1
   771 0000C9AB D0EB                <1> 	shr	bl, 1
   772                              <1> 		; asr r2 / yes, it is a parent
   773 0000C9AD 80BB[AF000300]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB
   774                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this 
   775                              <1> 				     ; / dying process a zombie
   776 0000C9B4 7506                <1> 	jne	short sysexit_3 
   777                              <1> 		; bne 2f / no
   778 0000C9B6 88A3[AF000300]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   779                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
   780                              <1> sysexit_3: ; 2:
   781                              <1> 	;shr	bx, 1
   782 0000C9BC D0E3                <1> 	shl	bl, 1
   783                              <1> 		; asl r2
   784                              <1> sysexit_4: ; 3:
   785                              <1> 		; / search the process name table 
   786                              <1> 		; / for the dying process's parent
   787 0000C9BE 663993[1E000300]    <1> 	cmp	[ebx+p.pid-2], dx
   788                              <1> 		; cmp p.pid-2(r2),r4 / found it?
   789 0000C9C5 7502                <1> 	jne	short sysexit_5
   790                              <1> 		; bne 3f / no
   791 0000C9C7 89DE                <1> 	mov	esi, ebx
   792                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
   793                              <1> 		          ; / process # x2) in r5
   794                              <1> sysexit_5: ; 3:
   795                              <1> 	;cmp	bx, nproc + nproc
   796 0000C9C9 80FB20              <1> 	cmp	bl, nproc + nproc
   797                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
   798 0000C9CC 72D1                <1> 	jb	short sysexit_2
   799                              <1> 		; blt 1b / no, go back
   800                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
   801 0000C9CE 21F6                <1> 	and	esi, esi ; r5=r1
   802 0000C9D0 7436                <1> 	jz	short sysexit_6
   803                              <1> 		; beq 2f / no parent has been found. 
   804                              <1> 		       ; / The process just dies
   805 0000C9D2 66D1EE              <1> 	shr	si, 1
   806                              <1> 		; asr r1 / set up index to p.stat
   807 0000C9D5 8A86[AF000300]      <1> 	mov	al, [esi+p.stat-1]
   808                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
   809 0000C9DB 20C0                <1> 	and	al, al
   810 0000C9DD 7429                <1> 	jz	short sysexit_6
   811                              <1> 		; beq 2f / if its been freed, 2f
   812 0000C9DF 3C03                <1> 	cmp	al, 3
   813                              <1> 		; cmp r2,$3 / is parent a zombie?
   814 0000C9E1 7425                <1> 	je	short sysexit_6
   815                              <1> 		; beq 2f / yes, 2f
   816                              <1> 	; BH = 0
   817 0000C9E3 8A1D[B3030300]      <1> 	mov	bl, [u.uno]
   818                              <1> 		; movb u.uno,r3 / move dying process's number to r3
   819 0000C9E9 C683[AF000300]03    <1> 	mov	byte [ebx+p.stat-1], 3  ; SZOMB
   820                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
   821 0000C9F0 3C01                <1> 	cmp	al, 1 ; SRUN
   822 0000C9F2 7414                <1> 	je	short sysexit_6
   823                              <1> 	;cmp	al, 2
   824                              <1> 		; cmp r2,$2 / is the parent waiting for 
   825                              <1> 			  ; / this child to die
   826                              <1> 	;jne	short sysexit_6	
   827                              <1> 		; bne 2f / yes, notify parent not to wait any more
   828                              <1> 	; p.stat = 2 --> waiting
   829                              <1> 	; p.stat = 4 --> sleeping
   830 0000C9F4 C686[AF000300]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN
   831                              <1> 	;dec	byte [esi+p.stat-1]
   832                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
   833 0000C9FB 6689F0              <1> 	mov	ax, si ; r1  (process number in AL)
   834                              <1> 	; 
   835                              <1> 	;mov	ebx, runq + 4
   836                              <1> 		; mov $runq+4,r2 / on the runq
   837 0000C9FE BB[54030300]        <1> 	mov	ebx, runq+2 ; normal run queue ; 02/01/2017
   838 0000CA03 E8F01C0000          <1> 	call	putlu
   839                              <1> 		; jsr r0, putlu
   840                              <1> sysexit_6: 
   841                              <1> 		; / the process dies
   842 0000CA08 C605[B3030300]00    <1> 	mov	byte [u.uno], 0
   843                              <1> 		; clrb u.uno / put zero as the process number, 
   844                              <1> 	           ; / so "swap" will
   845 0000CA0F E8E61B0000          <1> 	call	swap
   846                              <1> 		; jsr r0,swap / overwrite process with another process
   847                              <1> 
   848                              <1> hlt_sys:
   849                              <1> 	;sti
   850                              <1> hlts0:
   851 0000CA14 F4                  <1> 	hlt
   852 0000CA15 EBFD                <1> 	jmp	short hlts0
   853                              <1> 		; 0 / and thereby kill it; halt?
   854                              <1> 
   855                              <1> syswait: ; < wait for a processs to die >
   856                              <1> 	; 17/09/2015
   857                              <1> 	; 02/09/2015
   858                              <1> 	; 01/09/2015
   859                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
   860                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
   861                              <1> 	;
   862                              <1> 	; 'syswait' waits for a process die. 
   863                              <1> 	; It works in following way:
   864                              <1> 	;    1) From the parent process number, the parent's 
   865                              <1> 	; 	process name is found. The p.ppid table of parent
   866                              <1> 	;	names is then searched for this process name.
   867                              <1> 	;	If a match occurs, r2 contains child's process
   868                              <1> 	;	number. The child status is checked to see if it is
   869                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
   870                              <1> 	;	If it is, the child process is freed and it's name
   871                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
   872                              <1> 	;	If the child is not a zombie, nothing happens and
   873                              <1> 	;	the search goes on through the p.ppid table until
   874                              <1> 	;	all processes are checked or a zombie is found.
   875                              <1> 	;    2) If no zombies are found, a check is made to see if
   876                              <1> 	;	there are any children at all. If there are none,
   877                              <1> 	;	an error return is made. If there are, the parent's
   878                              <1> 	;	status is set to 2 (waiting for child to die),
   879                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
   880                              <1> 	;	is made to wait on the next process.
   881                              <1> 	;
   882                              <1> 	; Calling sequence:
   883                              <1> 	;	?
   884                              <1> 	; Arguments:
   885                              <1> 	;	-
   886                              <1> 	; Inputs: - 
   887                              <1> 	; Outputs: if zombie found, it's name put in u.r0.	
   888                              <1> 	; ...............................................................
   889                              <1> 	;				
   890                              <1> 	
   891                              <1> ; / wait for a process to die
   892                              <1> 
   893                              <1> syswait_0:
   894 0000CA17 0FB61D[B3030300]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
   895                              <1> 		; movb u.uno,r1 / put parents process number in r1
   896 0000CA1E D0E3                <1> 	shl	bl, 1
   897                              <1> 	;shl	bx, 1
   898                              <1> 		; asl r1 / x2 to get index into p.pid table
   899 0000CA20 668B83[1E000300]    <1> 	mov	ax, [ebx+p.pid-2]
   900                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
   901 0000CA27 31F6                <1> 	xor	esi, esi
   902                              <1> 		; clr r2
   903 0000CA29 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
   904                              <1> 	;xor 	cl, cl
   905                              <1> 		; clr r3 / initialize reg 3
   906                              <1> syswait_1: ; 1:
   907 0000CA2B 6683C602            <1> 	add	si, 2
   908                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
   909                              <1> 			  ; / search table of parent processes 
   910                              <1> 			  ; / for this process name
   911 0000CA2F 663B86[3E000300]    <1> 	cmp	ax, [esi+p.ppid-2]
   912                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs 
   913                              <1> 			            ; / process number
   914 0000CA36 7535                <1> 	jne	short syswait_3
   915                              <1> 		;bne 3f / branch if no match of parent process name
   916                              <1> 	;inc	cx
   917 0000CA38 FEC1                <1> 	inc	cl
   918                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
   919 0000CA3A 66D1EE              <1> 	shr	si, 1
   920                              <1> 		; asr r2 / r2/2 to get index to p.stat table
   921                              <1> 	; The possible states ('p.stat' values) of a process are:
   922                              <1> 	;	0 = free or unused
   923                              <1> 	;	1 = active
   924                              <1> 	;	2 = waiting for a child process to die
   925                              <1> 	;	3 = terminated, but not yet waited for (zombie).	
   926 0000CA3D 80BE[AF000300]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
   927                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
   928 0000CA44 7524                <1> 	jne	short syswait_2
   929                              <1> 		; bne 2f / no, skip it
   930 0000CA46 88BE[AF000300]      <1> 	mov	[esi+p.stat-1], bh ; 0
   931                              <1> 		; clrb p.stat-1(r2) / yes, free it
   932 0000CA4C 66D1E6              <1> 	shl	si, 1
   933                              <1> 		; asl r2 / r2x2 to get index into p.pid table
   934 0000CA4F 0FB786[1E000300]    <1> 	movzx	eax, word [esi+p.pid-2]
   935 0000CA56 A3[64030300]        <1> 	mov	[u.r0], eax
   936                              <1> 		; mov p.pid-2(r2),*u.r0 
   937                              <1> 			      ; / put childs process name in (u.r0)
   938                              <1> 	;
   939                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
   940                              <1> 	;
   941                              <1> 	; Parent process ID -p.ppid- field (of the child process)
   942                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
   943                              <1> 	; system call loop from the application/program if it calls
   944                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
   945                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
   946                              <1> 	;
   947                              <1> 	; Note: syswait will return with error if there is not a
   948                              <1> 	;       zombie or running process to wait.	
   949                              <1> 	;
   950 0000CA5B 6629C0              <1> 	sub	ax, ax
   951 0000CA5E 668986[3E000300]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
   952 0000CA65 E9D1FCFFFF          <1> 	jmp	sysret0 ; ax = 0
   953                              <1> 	;
   954                              <1> 	;jmp	sysret
   955                              <1> 		; br sysret1 / return cause child is dead
   956                              <1> syswait_2: ; 2:
   957 0000CA6A 66D1E6              <1> 	shl	si, 1
   958                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
   959                              <1> syswait_3: ; 3:
   960 0000CA6D 6683FE20            <1> 	cmp	si, nproc+nproc
   961                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
   962 0000CA71 72B8                <1> 	jb	short syswait_1
   963                              <1> 		; blt 1b / no, continue search
   964                              <1> 	;and	cx, cx
   965 0000CA73 20C9                <1> 	and	cl, cl
   966                              <1> 		; tst r3 / one gets here if there are no children 
   967                              <1> 		       ; / or children that are still active
   968                              <1> 	; 30/10/2013
   969 0000CA75 750B                <1> 	jnz	short syswait_4
   970                              <1> 	;jz	error
   971                              <1> 		; beq error1 / there are no children, error
   972 0000CA77 890D[64030300]      <1> 	mov	[u.r0], ecx ; 0
   973 0000CA7D E997FCFFFF          <1> 	jmp	error
   974                              <1> syswait_4:
   975 0000CA82 8A1D[B3030300]      <1> 	mov	bl, [u.uno]
   976                              <1> 		; movb u.uno,r1 / there are children so put 
   977                              <1> 			      ; / parent process number in r1
   978 0000CA88 FE83[AF000300]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
   979                              <1> 		; incb p.stat-1(r1) / it is waiting for 
   980                              <1> 				  ; / other children to die
   981                              <1> 	; 04/11/2013
   982 0000CA8E E8671B0000          <1> 	call	swap
   983                              <1> 		; jsr r0,swap / swap it out, because it's waiting
   984 0000CA93 EB82                <1> 	jmp	syswait_0
   985                              <1> 		; br syswait / wait on next process
   986                              <1> 
   987                              <1> sysfork: ; < create a new process >
   988                              <1> 	; 02/01/2017 (TRDOS 386 modification)
   989                              <1> 	; 04/09/2015, 18/05/2015
   990                              <1> 	; 28/08/2015, 01/09/2015, 02/09/2015
   991                              <1> 	; 09/05/2015, 10/05/2015, 14/05/2015
   992                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
   993                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
   994                              <1> 	;
   995                              <1> 	; 'sysfork' creates a new process. This process is referred
   996                              <1> 	; to as the child process. This new process core image is
   997                              <1> 	; a copy of that of the caller of 'sysfork'. The only
   998                              <1> 	; distinction is the return location and the fact that (u.r0)
   999                              <1> 	; in the old process (parent) contains the process id (p.pid)
  1000                              <1> 	; of the new process (child). This id is used by 'syswait'.
  1001                              <1> 	; 'sysfork' works in the following manner: 	
  1002                              <1> 	;    1) The process status table (p.stat) is searched to find
  1003                              <1> 	;	a process number that is unused. If none are found
  1004                              <1> 	;	an error occurs.
  1005                              <1> 	;    2) when one is found, it becomes the child process number
  1006                              <1> 	;	and it's status (p.stat) is set to active.
  1007                              <1> 	;    3) If the parent had a control tty, the interrupt 
  1008                              <1> 	;	character in that tty buffer is cleared.
  1009                              <1> 	;    4) The child process is put on the lowest priority run 
  1010                              <1> 	;	queue via 'putlu'.
  1011                              <1> 	;    5) A new process name is gotten from 'mpid' (actually 
  1012                              <1> 	;	it is a unique number) and is put in the child's unique
  1013                              <1> 	;	identifier; process id (p.pid).
  1014                              <1> 	;    6) The process name of the parent is then obtained and
  1015                              <1> 	;	placed in the unique identifier of the parent process
  1016                              <1> 	;	name is then put in 'u.r0'.	
  1017                              <1> 	;    7) The child process is then written out on disk by
  1018                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
  1019                              <1> 	;	and the child is born. (The child process is written 
  1020                              <1> 	;	out on disk/drum with 'u.uno' being the child process
  1021                              <1> 	;	number.)
  1022                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
  1023                              <1> 	;    9) The child process name is put in 'u.r0'.
  1024                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
  1025                              <1> 	;	create the return address for the parent process.
  1026                              <1> 	;   11) The 'u.fp' list as then searched to see what files
  1027                              <1> 	;	the parent has opened. For each file the parent has
  1028                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
  1029                              <1> 	;	to indicate that the child process also has opened
  1030                              <1> 	;	the file. A branch to 'sysret' is then made.	 			 				
  1031                              <1> 	;
  1032                              <1> 	; Calling sequence:
  1033                              <1> 	;	from shell ?
  1034                              <1> 	; Arguments:
  1035                              <1> 	;	-
  1036                              <1> 	; Inputs: -
  1037                              <1> 	; Outputs: *u.r0 - child process name
  1038                              <1> 	; ...............................................................
  1039                              <1> 	;	
  1040                              <1> 	; Retro UNIX 8086 v1 modification: 
  1041                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
  1042                              <1> 	;	= process id of child a parent process returns
  1043                              <1> 	;	= process id of parent when a child process returns
  1044                              <1> 	;
  1045                              <1> 	;       In original UNIX v1, sysfork is called and returns as
  1046                              <1> 	;	in following manner: (with an example: c library, fork)
  1047                              <1> 	;	
  1048                              <1> 	;	1:
  1049                              <1> 	;		sys	fork
  1050                              <1> 	;			br 1f  / child process returns here
  1051                              <1> 	;		bes	2f     / parent process returns here
  1052                              <1> 	;		/ pid of new process in r0
  1053                              <1> 	;		rts	pc
  1054                              <1> 	;	2: / parent process condionally branches here
  1055                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
  1056                              <1> 	;		rts	pc
  1057                              <1> 	;
  1058                              <1> 	;	1: / child process brances here
  1059                              <1> 	;		clr	r0   / pid = 0 in child process
  1060                              <1> 	;		rts	pc
  1061                              <1> 	;
  1062                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
  1063                              <1> 	;		// pid = fork();
  1064                              <1> 	;		//
  1065                              <1> 	;		// pid == 0 in child process; 
  1066                              <1> 	;		// pid == -1 means error return
  1067                              <1> 	;		// in child, 
  1068                              <1> 	;		//	parents id is in par_uid if needed
  1069                              <1> 	;		
  1070                              <1> 	;		_fork:
  1071                              <1> 	;			mov	$.fork,eax
  1072                              <1> 	;			int	$0x30
  1073                              <1> 	;			jmp	1f
  1074                              <1> 	;			jnc	2f
  1075                              <1> 	;			jmp	cerror
  1076                              <1> 	;		1:
  1077                              <1> 	;			mov	eax,_par_uid
  1078                              <1> 	;			xor	eax,eax
  1079                              <1> 	;		2:
  1080                              <1> 	;			ret
  1081                              <1> 	;
  1082                              <1> 	;	In Retro UNIX 8086 v1,
  1083                              <1> 	;	'sysfork' returns in following manner:
  1084                              <1> 	;	
  1085                              <1> 	;		mov	ax, sys_fork
  1086                              <1> 	;		mov	bx, offset @f ; routine for child
  1087                              <1> 	;		int	20h
  1088                              <1> 	;		jc	error
  1089                              <1> 	;		
  1090                              <1> 	;	; Routine for parent process here (just after 'jc')
  1091                              <1> 	;		mov	word ptr [pid_of_child], ax
  1092                              <1> 	;		jmp	next_routine_for_parent	
  1093                              <1> 	;
  1094                              <1> 	;	@@: ; routine for child process here				
  1095                              <1> 	;		....	
  1096                              <1> 	;	NOTE: 'sysfork' returns to specified offset
  1097                              <1> 	;	       for child process by using BX input.
  1098                              <1> 	;	      (at first, parent process will return then 
  1099                              <1> 	;	      child process will return -after swapped in-
  1100                              <1> 	;	      'syswait' is needed in parent process
  1101                              <1> 	;	      if return from child process will be waited for.)
  1102                              <1> 	;	  				
  1103                              <1> 	
  1104                              <1> ; / create a new process
  1105                              <1> 	; EBX = return address for child process 
  1106                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
  1107 0000CA95 31F6                <1> 	xor 	esi, esi
  1108                              <1> 		; clr r1
  1109                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
  1110 0000CA97 46                  <1> 	inc	esi
  1111                              <1> 		; inc r1
  1112 0000CA98 80BE[AF000300]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
  1113                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
  1114 0000CA9F 760B                <1> 	jna	short sysfork_2	
  1115                              <1> 		; beq 1f / it's unused so branch
  1116 0000CAA1 6683FE10            <1> 	cmp	si, nproc
  1117                              <1> 		; cmp r1,$nproc / all processes checked
  1118 0000CAA5 72F0                <1> 	jb	short sysfork_1
  1119                              <1> 		; blt 1b / no, branch back
  1120                              <1> 	;
  1121                              <1> 	; Retro UNIX 8086 v1. modification:
  1122                              <1> 	;	Parent process returns from 'sysfork' to address 
  1123                              <1> 	;	which is just after 'sysfork' system call in parent
  1124                              <1> 	;	process. Child process returns to address which is put
  1125                              <1> 	;	in BX register by parent process for 'sysfork'. 
  1126                              <1> 	;
  1127                              <1> 		;add $2,18.(sp) / add 2 to pc when trap occured, points
  1128                              <1> 		             ; / to old process return
  1129                              <1> 		; br error1 / no room for a new process
  1130 0000CAA7 E96DFCFFFF          <1> 	jmp	error
  1131                              <1> sysfork_2: ; 1:
  1132 0000CAAC E8FB80FFFF          <1> 	call	allocate_page
  1133 0000CAB1 0F8262FCFFFF        <1> 	jc	error
  1134 0000CAB7 50                  <1> 	push	eax   ; UPAGE (user structure page) address
  1135                              <1> 	; Retro UNIX 386 v1 modification!
  1136 0000CAB8 E8FE82FFFF          <1> 	call	duplicate_page_dir
  1137                              <1> 		; EAX = New page directory 
  1138 0000CABD 730B                <1> 	jnc	short sysfork_3
  1139 0000CABF 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
  1140 0000CAC0 E8C582FFFF          <1> 	call 	deallocate_page
  1141 0000CAC5 E94FFCFFFF          <1> 	jmp	error
  1142                              <1> sysfork_3:
  1143                              <1> 	; Retro UNIX 386 v1 modification !
  1144 0000CACA 56                  <1> 	push	esi
  1145 0000CACB E8B81B0000          <1> 	call	wswap ; save current user (u) structure, user registers
  1146                              <1> 		      ; and interrupt return components (for IRET)
  1147 0000CAD0 8705[B8030300]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
  1148 0000CAD6 A3[BC030300]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
  1149 0000CADB 5E                  <1> 	pop	esi
  1150 0000CADC 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
  1151                              <1> 		; [u.usp] = esp
  1152 0000CADD 89F7                <1> 	mov	edi, esi
  1153 0000CADF 66C1E702            <1> 	shl	di, 2
  1154 0000CAE3 8987[BC000300]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
  1155 0000CAE9 A3[B4030300]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
  1156                              <1> 	; 28/08/2015
  1157 0000CAEE 0FB605[B3030300]    <1> 	movzx	eax, byte [u.uno] ; parent process number
  1158                              <1> 		; movb u.uno,-(sp) / save parent process number
  1159 0000CAF5 89C7                <1> 	mov	edi, eax
  1160 0000CAF7 50                  <1>         push	eax ; ** 
  1161 0000CAF8 8A87[7F000300]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
  1162                              <1> 	; 18/09/2015
  1163                              <1> 	;mov     [esi+p.ttyc-1], al ; set child's console tty
  1164                              <1> 	;mov     [esi+p.waitc-1], ah ; 0 ; reset child's wait channel
  1165 0000CAFE 668986[7F000300]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
  1166                              <1> 				   ; ah - reset child's wait channel	
  1167 0000CB05 89F0                <1> 	mov	eax, esi
  1168 0000CB07 A2[B3030300]        <1> 	mov	[u.uno], al ; child process number
  1169                              <1> 		;movb r1,u.uno / set child process number to r1
  1170 0000CB0C FE86[AF000300]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
  1171                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
  1172                              <1> 				; / process to active status
  1173                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
  1174                              <1> 			      ; / control tty buffer in r2
  1175                              <1>                 ; beq 2f / branch, if no such tty assigned
  1176                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
  1177                              <1> 	; 2:
  1178 0000CB12 53                  <1> 	push	ebx  ; * return address for the child process
  1179                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
  1180                              <1> 	; (Retro UNIX 8086 v1 modification!)
  1181                              <1> 		; mov $runq+4,r2
  1182 0000CB13 BB[54030300]        <1> 	mov	ebx, runq+2 ; normal run queue ; 02/01/2017  
  1183 0000CB18 E8DB1B0000          <1> 	call	putlu
  1184                              <1>  		; jsr r0,putlu / put child process on lowest priority 
  1185                              <1> 			   ; / run queue
  1186 0000CB1D 66D1E6              <1> 	shl	si, 1
  1187                              <1> 		; asl r1 / multiply r1 by 2 to get index 
  1188                              <1> 		       ; / into p.pid table
  1189 0000CB20 66FF05[4E030300]    <1> 	inc	word [mpid]
  1190                              <1> 		; inc mpid / increment m.pid; get a new process name
  1191 0000CB27 66A1[4E030300]      <1> 	mov	ax, [mpid]
  1192 0000CB2D 668986[1E000300]    <1> 	mov	[esi+p.pid-2], ax
  1193                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
  1194                              <1> 				    ; / in child process' name slot
  1195 0000CB34 5A                  <1> 	pop	edx  ; * return address for the child process
  1196                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
  1197 0000CB35 5B                  <1>   	pop	ebx  ; **
  1198                              <1> 	;mov	ebx, [esp] ; ** parent process number
  1199                              <1> 		; movb (sp),r2 / put parent process number in r2
  1200 0000CB36 66D1E3              <1> 	shl 	bx, 1
  1201                              <1> 		;asl r2 / multiply by 2 to get index into below tables
  1202                              <1> 	;movzx eax, word [ebx+p.pid-2]
  1203 0000CB39 668B83[1E000300]    <1> 	mov	ax, [ebx+p.pid-2]
  1204                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
  1205                              <1> 				   ; / process
  1206 0000CB40 668986[3E000300]    <1> 	mov	[esi+p.ppid-2], ax
  1207                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name 
  1208                              <1> 			  ; / in parent process slot for child
  1209 0000CB47 A3[64030300]        <1> 	mov	[u.r0], eax	
  1210                              <1> 		; mov r2,*u.r0 / put parent process name on stack 
  1211                              <1> 			     ; / at location where r0 was saved
  1212 0000CB4C 8B2D[5C030300]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
  1213 0000CB52 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
  1214                              <1> 			   ; * return address for the child process
  1215                              <1> 		; mov $sysret1,-(sp) /
  1216                              <1> 		; mov sp,u.usp / contents of sp at the time when 
  1217                              <1> 			      ; / user is swapped out
  1218                              <1> 		; mov $sstack,sp / point sp to swapping stack space
  1219                              <1> 	; 04/09/2015 - 01/09/2015
  1220                              <1> 	; [u.usp] = esp
  1221 0000CB55 68[39C70000]        <1> 	push	sysret ; ***
  1222 0000CB5A 8925[60030300]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
  1223                              <1> 			     ; (for child process)	
  1224 0000CB60 31C0                <1> 	xor 	eax, eax
  1225 0000CB62 66A3[94030300]      <1> 	mov 	[u.ttyp], ax ; 0
  1226                              <1> 	;
  1227 0000CB68 E81B1B0000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
  1228                              <1> 		;jsr r0,wswap / put child process out on drum
  1229                              <1> 		;jsr r0,unpack / unpack user stack
  1230                              <1> 		;mov u.usp,sp / restore user stack pointer
  1231                              <1> 		; tst (sp)+ / bump stack pointer
  1232                              <1> 	; Retro UNIX 386 v1 modification !
  1233 0000CB6D 58                  <1> 	pop	eax ; ***
  1234 0000CB6E 66D1E3              <1> 	shl	bx, 1
  1235 0000CB71 8B83[BC000300]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
  1236 0000CB77 E8441B0000          <1> 	call	rswap ; restore parent process 'u' structure, 
  1237                              <1> 		      ; registers and return address (for IRET)
  1238                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
  1239 0000CB7C 0FB705[4E030300]    <1>         movzx   eax, word [mpid]
  1240 0000CB83 A3[64030300]        <1> 	mov	[u.r0], eax
  1241                              <1> 		; mov mpid,*u.r0 / put child process name on stack 
  1242                              <1> 			       ; / where r0 was saved
  1243                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
  1244                              <1> 			          ; / process return
  1245                              <1> 	;xor	ebx, ebx
  1246 0000CB88 31F6                <1> 	xor     esi, esi
  1247                              <1> 		;clr r1
  1248                              <1> sysfork_4: ; 1: / search u.fp list to find the files 
  1249                              <1> 	      ; / opened by the parent process
  1250                              <1> 	; 01/09/2015
  1251                              <1> 	;xor	bh, bh
  1252                              <1> 	;mov 	bl, [esi+u.fp]
  1253 0000CB8A 8A86[6A030300]      <1> 	mov 	al, [esi+u.fp]
  1254                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
  1255                              <1>         ;or      bl, bl
  1256 0000CB90 08C0                <1> 	or	al, al
  1257 0000CB92 740D                <1> 	jz	short sysfork_5	
  1258                              <1> 		; beq 2f / file has not been opened by parent, 
  1259                              <1> 		       ; / so branch
  1260 0000CB94 B40A                <1> 	mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
  1261 0000CB96 F6E4                <1> 	mul	ah
  1262                              <1> 	;movzx	ebx, ax
  1263 0000CB98 6689C3              <1> 	mov	bx, ax
  1264                              <1> 	;shl     bx, 3
  1265                              <1> 		; asl r2 / multiply by 8
  1266                              <1>        		; asl r2 / to get index into fsp table
  1267                              <1>        		; asl r2
  1268 0000CB9B FE83[4E010300]      <1>   	inc     byte [ebx+fsp-2]
  1269                              <1> 		; incb fsp-2(r2) / increment number of processes
  1270                              <1> 			     ; / using file, because child will now be
  1271                              <1> 			     ; / using this file
  1272                              <1> sysfork_5: ; 2:
  1273 0000CBA1 46                  <1>         inc     esi
  1274                              <1> 		; inc r1 / get next open file
  1275 0000CBA2 6683FE0A            <1>         cmp     si, 10
  1276                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
  1277                              <1> 			  ; / can be opened
  1278 0000CBA6 72E2                <1> 	jb	short sysfork_4	
  1279                              <1> 		; blt 1b / check next entry
  1280 0000CBA8 E98CFBFFFF          <1> 	jmp	sysret
  1281                              <1> 		; br sysret1
  1282                              <1> 
  1283                              <1> syscreat: ; < create file >
  1284                              <1> 	; 13/11/2017
  1285                              <1> 	; 27/10/2016
  1286                              <1> 	; 25/10/2016, 26/10/2016
  1287                              <1> 	; 15/10/2016, 16/10/2016, 17/10/2016
  1288                              <1> 	; 10/10/2016 (TRDOS 386 = TRDOS v2.0) 
  1289                              <1> 	;	     -derived from INT_21H.ASM-
  1290                              <1> 	;            ("loc_INT21h_create_file")
  1291                              <1>         ; 	10/07/2011 (12/03/2011)
  1292                              <1>         ;	INT 21h Function AH = 3Ch
  1293                              <1>         ;	Create File
  1294                              <1>         ;	INPUT
  1295                              <1>         ;	   CX = Attributes
  1296                              <1>         ;          DS:DX= Address of zero terminaned path name
  1297                              <1>         ;
  1298                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
  1299                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1300                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
  1301                              <1> 	;
  1302                              <1> 	; 'syscreat' called with two arguments; name and mode.
  1303                              <1> 	; u.namep points to name of the file and mode is put
  1304                              <1> 	; on the stack. 'namei' is called to get i-number of the file.		
  1305                              <1> 	; If the file aready exists, it's mode and owner remain 
  1306                              <1> 	; unchanged, but it is truncated to zero length. If the file
  1307                              <1> 	; did not exist, an i-node is created with the new mode via
  1308                              <1> 	; 'maknod' whether or not the file already existed, it is
  1309                              <1> 	; open for writing. The fsp table is then searched for a free
  1310                              <1> 	; entry. When a free entry is found, proper data is placed
  1311                              <1> 	; in it and the number of this entry is put in the u.fp list.
  1312                              <1> 	; The index to the u.fp (also know as the file descriptor)
  1313                              <1> 	; is put in the user's r0. 			
  1314                              <1> 	;
  1315                              <1> 	; Calling sequence:
  1316                              <1> 	;	syscreate; name; mode
  1317                              <1> 	; Arguments:
  1318                              <1> 	;	name - name of the file to be created
  1319                              <1> 	;	mode - mode of the file to be created
  1320                              <1> 	; Inputs: (arguments)
  1321                              <1> 	; Outputs: *u.r0 - index to u.fp list 
  1322                              <1> 	;		   (the file descriptor of new file)
  1323                              <1> 	; ...............................................................
  1324                              <1> 	;				
  1325                              <1> 	; Retro UNIX 8086 v1 modification: 
  1326                              <1> 	;       'syscreate' system call has two arguments; so,
  1327                              <1> 	;	* 1st argument, name is pointed to by BX register
  1328                              <1> 	;	* 2nd argument, mode is in CX register
  1329                              <1> 	;
  1330                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1331                              <1> 	;	to the user with the file descriptor/number 
  1332                              <1> 	;	(index to u.fp list).
  1333                              <1> 	;
  1334                              <1> 	;call	arg2
  1335                              <1> 	; * name - 'u.namep' points to address of file/path name
  1336                              <1> 	;          in the user's program segment ('u.segmnt')
  1337                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1338                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1339                              <1> 	;          which is on top of stack.
  1340                              <1> 	;
  1341                              <1> 	; TRDOS 386 (10/10/2016)
  1342                              <1> 	;	
  1343                              <1>         ; INPUT ->
  1344                              <1>         ;	   CL = File Attributes
  1345                              <1> 	;     	      bit 0 (1) - Read only file (R)
  1346                              <1> 	;             bit 1 (1) - Hidden file (H)
  1347                              <1>         ;             bit 2 (1) - System file (R)
  1348                              <1> 	;             bit 3 (1) - Volume label/name (V)
  1349                              <1>         ;             bit 4 (1) - Subdirectory (D)
  1350                              <1> 	;	      bit 5 (1) - File has been archived (A)	 	
  1351                              <1>         ;          EBX = Pointer to filename (ASCIIZ) -path-
  1352                              <1> 	;	
  1353                              <1> 	; OUTPUT ->
  1354                              <1> 	;          eax = File/Device Handle/Number (index) (AL)
  1355                              <1> 	;          cf = 1 -> Error code in AL
  1356                              <1> 	;
  1357                              <1> 	; Modified Registers: EAX (at the return of system call)
  1358                              <1> 	;  
  1359                              <1> 	; Note: If the file is existing and it has not any one
  1360                              <1> 	;	of S,H,R,V,D attributes, it will be truncated 
  1361                              <1> 	;	to zero length; otherwise, access error will be 
  1362                              <1> 	;	returned. 
  1363                              <1> 
  1364                              <1> sysmkdir_0:
  1365 0000CBAD F6C108              <1> 	test	cl, 08h ; Volume name 
  1366 0000CBB0 740A                <1> 	jz	short syscreat_0
  1367                              <1> 
  1368                              <1> 	; Volume name or long name creation
  1369                              <1> 	; is not permitted (in TRDOS 386)!
  1370 0000CBB2 B80B000000          <1> 	mov	eax, ERR_FILE_ACCESS  ; 11 ; 'permission denied !'
  1371 0000CBB7 E926020000          <1>         jmp	sysopen_dev_err
  1372                              <1> 
  1373                              <1> syscreat_0:
  1374                              <1>         ;mov	[u.namep], ebx
  1375 0000CBBC 51                  <1> 	push	ecx
  1376 0000CBBD 89DE                <1> 	mov	esi, ebx
  1377                              <1> 	; file name is forced, change directory as temporary
  1378                              <1> 	;mov	ax, 1
  1379                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
  1380                              <1> 	;call	set_working_path 
  1381 0000CBBF E892300000          <1> 	call	set_working_path_x ; 17/10/2016	
  1382 0000CBC4 0F82D7000000        <1> 	jc	syscreat_err
  1383                              <1> 
  1384                              <1> 	; 16/10/2016
  1385 0000CBCA 803D[57650100]00    <1> 	cmp	byte [SWP_inv_fname], 0
  1386 0000CBD1 776C                <1> 	ja	short  syscreat_inv_fname ; invalid file name !
  1387                              <1> 
  1388                              <1> 	; Here, we have a valid path and also a valid file name
  1389                              <1> 	; (Working dir has been changed if the path
  1390                              <1> 	;  -file name string- had contained a dir name.)
  1391                              <1> 
  1392 0000CBD3 6631C0              <1> 	xor	ax, ax 
  1393                              <1> 	;mov	esi, FindFile_Name
  1394 0000CBD6 E8E3B6FFFF          <1> 	call	find_first_file
  1395 0000CBDB 59                  <1> 	pop	ecx
  1396                              <1> 		; ESI = Directory Entry (FindFile_DirEntry) Location
  1397                              <1> 		; EDI = Directory Buffer Directory Entry Location
  1398                              <1> 		; EAX = File Size
  1399                              <1> 		;  BL = Attributes of The File/Directory
  1400                              <1> 		;  BH = Long Name Yes/No Status (>0 is YES)
  1401                              <1> 		;  DX > 0 : Ambiguous filename chars are used
  1402 0000CBDC 7269                <1> 	jc	short syscreat_1 ; file not found (the good!) 
  1403                              <1> 				 ; or another error (the bad') 
  1404                              <1> 
  1405                              <1> 	; (& the uggly!) truncate file to zero length before open
  1406                              <1> 
  1407                              <1> 	;'*' and '?' already checked at 'set_working_path' stage
  1408                              <1> 	;and	dx, dx
  1409                              <1> 	;jnz	short sysmkdir_err ; permission denied 
  1410                              <1> 				   ; invalid filename chars
  1411                              <1> 
  1412                              <1> 	;test	cl, 10h ; subdirectory ?
  1413                              <1> 	;jnz	short sysmkdir_err	
  1414                              <1> 
  1415                              <1> 	; BL = File Attributes:	
  1416                              <1> 	;     	      bit 0 (1) - Read only file (R)
  1417                              <1> 	;             bit 1 (1) - Hidden file (H)
  1418                              <1>         ;             bit 2 (1) - System file (R)
  1419                              <1> 	;             bit 3 (1) - Volume label/name (V)
  1420                              <1>         ;             bit 4 (1) - Subdirectory (D)
  1421                              <1> 	;	      bit 5 (1) - File has been archived	 	
  1422                              <1> 
  1423                              <1> 	; * existing directory must not be truncated
  1424                              <1> 	;   (we don't know it is empty or not, at this stage) 
  1425                              <1> 	; * existing volume name (or a long name) can not be
  1426                              <1> 	;   re-created or truncated by 'syscreat' 	
  1427                              <1> 	; * A file with S, H, R attributes must not be truncated
  1428                              <1> 	;   (change attributes to normal, if you need truncate it)
  1429                              <1> 
  1430 0000CBDE F6C31F              <1> 	test	bl, 00011111b  ; check attributes of existing file
  1431 0000CBE1 754E                <1> 	jnz	short sysmkdir_err
  1432                              <1> 
  1433                              <1> 	;; normal file, OK to continue...
  1434                              <1> 
  1435                              <1> 	; ESI = FindFile_DirEntry
  1436 0000CBE3 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI] ; 20
  1437 0000CBE7 C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  1438 0000CBEA 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO] ; 26 
  1439                              <1> 	; EAX = First cluster to be truncated/unlinked
  1440 0000CBEE 57                  <1> 	push	edi
  1441 0000CBEF 51                  <1> 	push	ecx
  1442 0000CBF0 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1443 0000CBF5 29C9                <1> 	sub	ecx, ecx
  1444 0000CBF7 8A2D[6E590100]      <1> 	mov	ch, [Current_Drv]
  1445 0000CBFD 01CE                <1> 	add	esi, ecx
  1446                              <1> 	; ESI = Logical dos drive description table address
  1447 0000CBFF E8C9F7FFFF          <1> 	call	truncate_cluster_chain
  1448 0000CC04 59                  <1> 	pop	ecx
  1449 0000CC05 5F                  <1> 	pop	edi
  1450 0000CC06 7230                <1> 	jc	short syscreate_truncate_err
  1451                              <1> 
  1452                              <1> 	; 26/10/2016
  1453                              <1> 	; EDI = Directory entry address in directory buffer
  1454                              <1> 	; Update directory entry
  1455 0000CC08 E848DCFFFF          <1> 	call	convert_current_date_time
  1456                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1457                              <1>         ; 	    AX = Time in dos dir entry format	
  1458 0000CC0D 66894716            <1> 	mov	[edi+DirEntry_WrtTime], ax
  1459 0000CC11 66895718            <1> 	mov	[edi+DirEntry_WrtDate], dx	
  1460 0000CC15 66895712            <1> 	mov	[edi+DirEntry_LastAccDate], dx
  1461 0000CC19 31C0                <1> 	xor	eax, eax ; file size = 0 
  1462 0000CC1B 89471C              <1> 	mov	[edi+DirEntry_FileSize], eax ; 0
  1463 0000CC1E C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; data changed sign	
  1464 0000CC25 BE[58620100]        <1> 	mov	esi, FindFile_DirEntry
  1465 0000CC2A B201                <1> 	mov	dl, 1 ; open file for writing
  1466 0000CC2C E9AA000000          <1> 	jmp	sysopen_2
  1467                              <1> 
  1468                              <1> sysmkdir_err:
  1469                              <1> 	; 1 = write, 2 = read & write, >2 = invalid
  1470 0000CC31 B80B000000          <1>         mov	eax, ERR_FILE_ACCESS  ; 11 ; 'permission denied !'
  1471 0000CC36 EB73                <1>         jmp	short sysopen_err
  1472                              <1> 
  1473                              <1> syscreate_truncate_err:
  1474 0000CC38 B812000000          <1> 	mov	eax, ERR_DRV_WRITE ; 18 ; 'disk write error !'
  1475 0000CC3D EB6C                <1>         jmp	short sysopen_err
  1476                              <1> 
  1477                              <1> syscreat_inv_fname:  ; invalid file name chars 
  1478                              <1> 	; 16/10/2016
  1479 0000CC3F B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME  ; 26 ; invalid file name chars 
  1480 0000CC44 59                  <1> 	pop	ecx
  1481 0000CC45 EB64                <1> 	jmp	sysopen_err
  1482                              <1> 
  1483                              <1> syscreat_1:
  1484                              <1> 	; Error code in EAX
  1485 0000CC47 3C02                <1>         cmp	al, 02h ; 'File not found' error
  1486 0000CC49 7560                <1>         jne	sysopen_err
  1487                              <1> 
  1488 0000CC4B F6C110              <1> 	test	cl, 10h ; Directory
  1489 0000CC4E 0F852C020000        <1> 	jnz	sysmkdir_2
  1490                              <1> 
  1491                              <1> syscreat_2:
  1492 0000CC54 BE[48620100]        <1> 	mov	esi, FindFile_Name 
  1493                              <1>         ;xor	edx, edx
  1494 0000CC59 31C0                <1>         xor	eax, eax ; File Size  = 0
  1495 0000CC5B 31DB                <1> 	xor	ebx, ebx
  1496 0000CC5D 4B                  <1> 	dec 	ebx ; FFFFFFFFh -> create empty file 
  1497                              <1> 	            ;              (only for FAT fs) 
  1498                              <1> 	; CL = File Attributes
  1499 0000CC5E E8F8EBFFFF          <1> 	call	create_file
  1500 0000CC63 7246                <1> 	jc	sysopen_err
  1501                              <1> 		; EAX = New file's first cluster
  1502                              <1> 		; ESI = Logical Dos Drv Descr. Table Addr.
  1503                              <1> 		; EBX = offset CreateFile_Size
  1504                              <1> 		; ECX = Sectors per cluster (<256) 
  1505                              <1> 		; EDX = Directory entry index/number (<65536)
  1506                              <1> 	; 26/10/2016
  1507                              <1> 	;mov	esi, Directory_Buffer
  1508                              <1> 	;shl	dx, 5 ; *32
  1509                              <1> 	;add	esi, edx
  1510                              <1> 	;; esi = directory entry address in directory buffer
  1511                              <1> 
  1512                              <1> 	; Here, directory entry has been created but last
  1513                              <1> 	; modification date & time of the parent dir has not
  1514                              <1> 	; been updated, yet! 
  1515                              <1> 	; (Note: Directory and FAT buffers have been updated...)
  1516                              <1>  	
  1517 0000CC65 E824DDFFFF          <1> 	call	update_parent_dir_lmdt ; now, it is OK too!
  1518                              <1> 
  1519                              <1> 	; 25/10/2016
  1520 0000CC6A 66B80018            <1> 	mov	ax, 1800h
  1521 0000CC6E BE[48620100]        <1> 	mov	esi, FindFile_Name
  1522 0000CC73 E846B6FFFF          <1> 	call	find_first_file
  1523 0000CC78 7231                <1> 	jc	short sysopen_err
  1524                              <1> 
  1525                              <1> 	; Only possible error after here is 
  1526                              <1> 	; "too many open files !" error.
  1527                              <1> 	;
  1528                              <1> 	; If "syscreat" will return with that error,
  1529                              <1> 	; (the file has been created but it could not be opened)
  1530                              <1> 	; the user must retry to open this file again
  1531                              <1> 	; or must close another file before using 
  1532                              <1> 	; "sysopen" system call.
  1533                              <1> 
  1534 0000CC7A B201                <1> 	mov	dl, 1 ; open file for writing
  1535                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  1536                              <1> 	; EAX = File Size (= 0)
  1537 0000CC7C EB5D                <1> 	jmp	short sysopen_2
  1538                              <1> 
  1539                              <1> sysopen: ;<open file>
  1540                              <1> 	; 26/10/2016
  1541                              <1> 	; 24/10/2016
  1542                              <1> 	; 17/10/2016
  1543                              <1> 	; 15/10/2016
  1544                              <1> 	; 06/10/2016, 07/10/2016, 08/10/2016
  1545                              <1> 	; 05/10/2016 (TRDOS 386 = TRDOS v2.0) 
  1546                              <1> 	;	     -derived from INT_21H.ASM-
  1547                              <1> 	;            ("loc_INT21h_open_file")
  1548                              <1>         ; 	26/02/2011 
  1549                              <1>         ;	INT 21h Function AH = 3Dh
  1550                              <1>         ;	Open File
  1551                              <1>         ;	INPUT
  1552                              <1>         ;	   AL= File Access Value
  1553                              <1> 	;     	     0- Open for reading
  1554                              <1> 	;            1- Open for writing
  1555                              <1>         ;            2- Open for reading and writing
  1556                              <1>         ;          DS:DX= Pointer to filename (ASCIIZ)
  1557                              <1>         ;
  1558                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1559                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
  1560                              <1> 	;
  1561                              <1> 	; 'sysopen' opens a file in following manner:
  1562                              <1> 	;    1) The second argument in a sysopen says whether to
  1563                              <1> 	;	open the file ro read (0) or write (>0).
  1564                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
  1565                              <1> 	;    3) The file is opened by 'iopen'.
  1566                              <1> 	;    4) Next housekeeping is performed on the fsp table
  1567                              <1> 	;	and the user's open file list - u.fp.
  1568                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
  1569                              <1> 	;	b) An entry for the file is created in the fsp table.
  1570                              <1> 	;	c) The number of this entry is put on u.fp list.
  1571                              <1> 	;	d) The file descriptor index to u.fp list is pointed
  1572                              <1> 	;	   to by u.r0.
  1573                              <1> 	;
  1574                              <1> 	; Calling sequence:
  1575                              <1> 	;	sysopen; name; mode
  1576                              <1> 	; Arguments:
  1577                              <1> 	;	name - file name or path name
  1578                              <1> 	;	mode - 0 to open for reading
  1579                              <1> 	;	       1 to open for writing
  1580                              <1> 	; Inputs: (arguments)
  1581                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
  1582                              <1> 	;		  is put into r0's location on the stack.	
  1583                              <1> 	; ...............................................................
  1584                              <1> 	;				
  1585                              <1> 	; Retro UNIX 8086 v1 modification: 
  1586                              <1> 	;       'sysopen' system call has two arguments; so,
  1587                              <1> 	;	* 1st argument, name is pointed to by BX register
  1588                              <1> 	;	* 2nd argument, mode is in CX register
  1589                              <1> 	;
  1590                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1591                              <1> 	;	to the user with the file descriptor/number 
  1592                              <1> 	;	(index to u.fp list).
  1593                              <1> 	;
  1594                              <1> 	;call	arg2
  1595                              <1> 	; * name - 'u.namep' points to address of file/path name
  1596                              <1> 	;          in the user's program segment ('u.segmnt')
  1597                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1598                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1599                              <1> 	;          which is on top of stack.
  1600                              <1> 	;
  1601                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
  1602                              <1> 	;
  1603                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
  1604                              <1> 	;
  1605                              <1> 	; TRDOS 386 (05/10/2016)
  1606                              <1> 	;	
  1607                              <1>         ; INPUT ->
  1608                              <1>         ;	   CL = File Access Value (Open Mode)
  1609                              <1> 	;     	      0 - Open file for reading
  1610                              <1> 	;             1 - Open file for writing
  1611                              <1>         ;             2 - Open device for reading
  1612                              <1> 	;	      3 - Open device for writing
  1613                              <1>         ;          EBX = Pointer to filename/devicename (ASCIIZ)
  1614                              <1> 	; OUTPUT ->
  1615                              <1> 	;          eax = File/Device Handle/Number (index) (AL)
  1616                              <1> 	;          cf = 1 -> Error code in AL
  1617                              <1> 	;
  1618                              <1> 	; Modified Registers: EAX (at the return of system call)
  1619                              <1> 	;  
  1620                              <1> 
  1621 0000CC7E 80F901              <1> 	cmp	cl, 1 ; read file (0), write file (1)
  1622 0000CC81 7614                <1> 	jna	short sysopen_0
  1623                              <1> 
  1624 0000CC83 80F903              <1> 	cmp	cl, 3
  1625 0000CC86 0F8640010000        <1> 	jna	sysopen_device
  1626                              <1> 
  1627                              <1> 	; Invalid access code
  1628 0000CC8C B817000000          <1> 	mov	eax, ERR_INV_PARAMETER
  1629 0000CC91 0F874B010000        <1> 	ja	sysopen_dev_err
  1630                              <1> 
  1631                              <1> sysopen_0:
  1632                              <1> 	;mov	[u.namep], ebx
  1633 0000CC97 51                  <1> 	push	ecx
  1634 0000CC98 89DE                <1> 	mov	esi, ebx
  1635                              <1> 	; file name is forced, change directory as temporary
  1636                              <1> 	;mov	ax, 1
  1637                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
  1638                              <1> 	;call	set_working_path 
  1639 0000CC9A E8B72F0000          <1> 	call	set_working_path_x ; 17/10/2016	
  1640 0000CC9F 731E                <1> 	jnc	short sysopen_1
  1641                              <1> 
  1642                              <1> syscreat_err: ; ecx = file attributes (for 'syscreat')
  1643 0000CCA1 59                  <1> 	pop	ecx ; open mode  
  1644 0000CCA2 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  1645 0000CCA4 7505                <1> 	jnz	short sysopen_err
  1646                              <1> 	; eax = 0
  1647 0000CCA6 B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
  1648                              <1> sysopen_err:
  1649 0000CCAB A3[64030300]        <1> 	mov	[u.r0], eax
  1650 0000CCB0 A3[C8030300]        <1> 	mov	[u.error], eax
  1651 0000CCB5 E871300000          <1> 	call 	reset_working_path
  1652 0000CCBA E95AFAFFFF          <1> 	jmp	error
  1653                              <1> 
  1654                              <1> sysopen_1:
  1655                              <1> 	;mov	esi, FindFile_Name
  1656 0000CCBF 66B80018            <1>         mov	ax, 1800h ; Only files 
  1657 0000CCC3 E8F6B5FFFF          <1> 	call	find_first_file
  1658 0000CCC8 5A                  <1> 	pop	edx
  1659 0000CCC9 72E0                <1> 	jc	short sysopen_err ; eax = 2 (File not found !)
  1660                              <1> 
  1661                              <1> 	; check_open_file_attr_access_code
  1662                              <1> 
  1663 0000CCCB F6C307              <1>         test	bl, 7  ; system, hidden, readonly 
  1664 0000CCCE 740B                <1>         jz	short sysopen_2
  1665                              <1> 
  1666 0000CCD0 20D2                <1> 	and	dl, dl ; 0 = read mode
  1667 0000CCD2 7407                <1> 	jz	short sysopen_2
  1668                              <1> 
  1669                              <1> 	; 1 = write, 2 = read & write, >2 = invalid
  1670 0000CCD4 B80B000000          <1>         mov	eax, ERR_FILE_ACCESS  ; 11 = 'permission denied !'
  1671 0000CCD9 EBD0                <1>         jmp	short sysopen_err
  1672                              <1> 
  1673                              <1> sysopen_2:
  1674                              <1> 	; esi = Directory Entry (FindFile_DirEntry) Location
  1675 0000CCDB 89F3                <1> 	mov	ebx, esi
  1676 0000CCDD 31F6                <1>         xor     esi, esi ; 0
  1677 0000CCDF 31FF                <1>         xor     edi, edi ; 0
  1678                              <1> sysopen_3: ; scan the list of entries in fsp table
  1679 0000CCE1 80BE[6A030300]00    <1>         cmp     byte [esi+u.fp], 0
  1680 0000CCE8 760F                <1>         jna     short sysopen_4 ; empty slot
  1681 0000CCEA 6646                <1>         inc     si
  1682 0000CCEC 6683FE0A            <1>         cmp     si, 10
  1683 0000CCF0 72EF                <1> 	jb	short sysopen_3
  1684                              <1> toomanyf:
  1685 0000CCF2 B80D000000          <1> 	mov	eax, ERR_TOO_MANY_FILES ; too many open files !
  1686 0000CCF7 EBB2                <1> 	jmp	short sysopen_err
  1687                              <1> 
  1688                              <1> sysopen_4: 
  1689 0000CCF9 80BF[C6680100]00    <1>         cmp     byte [edi+OF_MODE], 0 ; Scan open files table 
  1690 0000CD00 760A                <1> 	jna     short sysopen_5
  1691 0000CD02 6647                <1> 	inc	di
  1692 0000CD04 6683FF0A            <1> 	cmp     di, OPENFILES ; max. number of open files (=10)
  1693 0000CD08 72EF                <1> 	jb	short sysopen_4
  1694 0000CD0A EBE6                <1> 	jmp	short toomanyf
  1695                              <1> 
  1696                              <1> sysopen_5:
  1697 0000CD0C FEC2                <1> 	inc	dl
  1698 0000CD0E 8897[C6680100]      <1>         mov     [edi+OF_MODE], dl
  1699 0000CD14 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  1700 0000CD1A 8897[BC680100]      <1>         mov     [edi+OF_DRIVE], dl ; Logical DOS drive number
  1701 0000CD20 66C1E702            <1> 	shl	di, 2 ; *4 (dword offset)
  1702                              <1> 
  1703 0000CD24 8987[0C690100]      <1> 	mov	[edi+OF_SIZE], eax ; File size in bytes
  1704                              <1> 
  1705 0000CD2A 668B4314            <1>         mov 	ax, [ebx+DirEntry_FstClusHI]
  1706 0000CD2E C1E010              <1> 	shl	eax, 16
  1707 0000CD31 668B431A            <1> 	mov 	ax, [ebx+DirEntry_FstClusLO]
  1708 0000CD35 8987[94680100]      <1> 	mov     [edi+OF_FCLUSTER], eax ; First cluster
  1709 0000CD3B 8987[AC690100]      <1> 	mov     [edi+OF_CCLUSTER], eax ; Current cluster
  1710                              <1> 
  1711 0000CD41 31DB                <1>         xor	ebx, ebx
  1712 0000CD43 899F[E4680100]      <1>         mov     [edi+OF_POINTER], ebx ; offset pointer (0)
  1713 0000CD49 899F[D4690100]      <1>         mov     [edi+OF_CCINDEX], ebx ; cluster index (0)
  1714                              <1> 
  1715 0000CD4F A1[78620100]        <1> 	mov	eax, [FindFile_DirFirstCluster]
  1716 0000CD54 8987[34690100]      <1> 	mov	[edi+OF_DIRFCLUSTER], eax
  1717                              <1> 
  1718 0000CD5A A1[7C620100]        <1> 	mov	eax, [FindFile_DirCluster]
  1719 0000CD5F 8987[5C690100]      <1> 	mov	[edi+OF_DIRCLUSTER], eax
  1720                              <1> 
  1721                              <1> 	; Get (& Save) Volume ID 
  1722                              <1> 	; Important for files of removable drives
  1723                              <1> 	; (In order to check the drive has same volume/disk)
  1724 0000CD65 88D7                <1> 	mov	bh, dl
  1725 0000CD67 81C300010900        <1>         add	ebx, Logical_DOSDisks
  1726 0000CD6D 8A4303              <1>         mov	al, [ebx+LD_FATType]
  1727 0000CD70 3C01                <1>         cmp	al, 1
  1728 0000CD72 7209                <1>         jb	short sysopen_6_fs
  1729 0000CD74 3C02                <1>         cmp	al, 2
  1730 0000CD76 770A                <1>         ja	short sysopen_6_fat32
  1731                              <1> sysopen_6_fat:
  1732 0000CD78 8B432D              <1>         mov	eax, [ebx+LD_BPB+VolumeID]
  1733 0000CD7B EB08                <1>         jmp	short sysopen_7
  1734                              <1> sysopen_6_fs:
  1735 0000CD7D 8B4328              <1>         mov	eax, [ebx+LD_FS_VolumeSerial]
  1736 0000CD80 EB03                <1>         jmp	short sysopen_7
  1737                              <1> sysopen_6_fat32:
  1738 0000CD82 8B4349              <1>         mov	eax, [ebx+LD_BPB+FAT32_VolID]
  1739                              <1> sysopen_7:
  1740 0000CD85 A3[64590100]        <1>         mov	[Current_VolSerial], eax
  1741                              <1> 
  1742 0000CD8A 8987[84690100]      <1> 	mov	[edi+OF_VOLUMEID], eax
  1743                              <1> 
  1744                              <1> 	; 24/10/2016
  1745 0000CD90 66D1EF              <1> 	shr	di, 1 ; 4/2, word offset
  1746 0000CD93 668B1D[80620100]    <1> 	mov	bx, [FindFile_DirEntryNumber]
  1747 0000CD9A 66899F[FC690100]    <1> 	mov	[edi+OF_DIRENTRY], bx
  1748                              <1> 
  1749 0000CDA1 31D2                <1> 	xor	edx, edx
  1750                              <1> 	;shr	di, 2 ; /4 (byte offset)
  1751 0000CDA3 66D1EF              <1> 	shr	di, 1 ; 2/2, byte offset
  1752 0000CDA6 8897[DA680100]      <1> 	mov	byte [edi+OF_OPENCOUNT], dl ; 0
  1753 0000CDAC 8897[D0680100]      <1> 	mov	byte [edi+OF_STATUS], dl ; 0
  1754                              <1> 
  1755 0000CDB2 89FB                <1> 	mov	ebx, edi
  1756 0000CDB4 FEC3                <1> 	inc	bl
  1757                              <1> 
  1758 0000CDB6 889E[6A030300]      <1>         mov     [esi+u.fp], bl ; Open File Entry Number
  1759 0000CDBC 8935[64030300]      <1> 	mov     [u.r0], esi ; move index to u.fp list 
  1760                              <1> 			    ; into eax on stack
  1761                              <1> 
  1762 0000CDC2 E8642F0000          <1>         call 	reset_working_path
  1763                              <1>         
  1764 0000CDC7 E96DF9FFFF          <1> 	jmp	sysret
  1765                              <1> 
  1766                              <1> 	; (Retro UNIX 386 v1.0)
  1767                              <1> 	; 'fsp' table (10 bytes/entry)
  1768                              <1> 	; bit 15				   bit 0
  1769                              <1> 	; ---|-------------------------------------------
  1770                              <1> 	; r/w|		i-number of open file
  1771                              <1> 	; ---|-------------------------------------------
  1772                              <1> 	;		   device number
  1773                              <1> 	; -----------------------------------------------
  1774                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
  1775                              <1> 	; -----------------------------------------------
  1776                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
  1777                              <1> 	; ----------------------|------------------------
  1778                              <1> 	;  flag that says file 	| number of processes
  1779                              <1> 	;   has been deleted	| that have file open 
  1780                              <1> 	; ----------------------|------------------------
  1781                              <1> 
  1782                              <1> sysopen_device:
  1783                              <1> 	; 15/10/2016
  1784                              <1> 	; 08/10/2016
  1785                              <1> 	; 07/10/2016 (TRDOS 386 = TRDOS v2.0)
  1786 0000CDCC 51                  <1> 	push	ecx ; open mode
  1787 0000CDCD 89E5                <1> 	mov	ebp, esp
  1788 0000CDCF B910000000          <1> 	mov	ecx, 16 ; transfer length = 16 bytes 
  1789 0000CDD4 29CC                <1> 	sub	esp, ecx
  1790 0000CDD6 89E7                <1> 	mov	edi, esp ; destination address 
  1791 0000CDD8 89DE                <1> 	mov 	esi, ebx ; dev name in user's memory space
  1792 0000CDDA E83F1A0000          <1> 	call	transfer_from_user_buffer
  1793 0000CDDF 7310                <1> 	jnc	short sysopen_dev_0
  1794                              <1> 	; eax = ERR_OUT_OF_MEMORY = 4 = ERR_MINOR_IM
  1795 0000CDE1 59                  <1> 	pop	ecx
  1796                              <1> sysopen_dev_err:
  1797 0000CDE2 A3[64030300]        <1> 	mov	[u.r0], eax
  1798 0000CDE7 A3[C8030300]        <1> 	mov	[u.error], eax
  1799 0000CDEC E928F9FFFF          <1> 	jmp	error
  1800                              <1> sysopen_dev_0:
  1801 0000CDF1 89FE                <1> 	mov	esi, edi ; Device name addr (max. 16 bytes, ASCIIZ) 
  1802                              <1> 			 ; for example: "tty, TTY, /dev/tty"
  1803 0000CDF3 E8DB310000          <1> 	call	get_device_number
  1804 0000CDF8 89EC                <1> 	mov	esp, ebp
  1805 0000CDFA 59                  <1> 	pop	ecx
  1806 0000CDFB 7307                <1> 	jnc	short sysopen_dev_1
  1807 0000CDFD B818000000          <1> 	mov	eax, ERR_INV_DEV_NAME ; 24 ; 'invalid device name !'
  1808 0000CE02 EBDE                <1> 	jmp	short sysopen_dev_err
  1809                              <1> sysopen_dev_1:
  1810                              <1> 	; eax = Device Number (AL)
  1811                              <1> 	;  cl = Open mode (2 = device read, 3 = device write)
  1812 0000CE04 31DB                <1>         xor     ebx, ebx ; 0
  1813                              <1> sysopen_dev_2: ; scan the list of entries
  1814 0000CE06 389B[6A030300]      <1>         cmp     [ebx+u.fp], bl ; 0
  1815 0000CE0C 760E                <1>         jna     short sysopen_dev_3 ; empty slot
  1816 0000CE0E FEC3                <1>         inc     bl
  1817 0000CE10 80FB0A              <1>         cmp     bl, 10
  1818 0000CE13 72F1                <1> 	jb	short sysopen_dev_2
  1819                              <1> 	;
  1820 0000CE15 B80D000000          <1> 	mov	eax, ERR_TOO_MANY_FILES ; too many open files !
  1821 0000CE1A EBC6                <1> 	jmp	short sysopen_dev_err
  1822                              <1> sysopen_dev_3:
  1823 0000CE1C 891D[64030300]      <1> 	mov 	[u.r0], ebx ; File/Device index/handle/descriptor
  1824                              <1> 	; eax = device number (entry offset)
  1825 0000CE22 8AA8[58660100]      <1> 	mov	ch, [eax+DEV_ACCESS] ; bit 0 = accessable by users
  1826                              <1> 				     ; bit 1 = read access perm
  1827                              <1> 				     ; bit 2 = write access perm
  1828                              <1> 				     ; bit 3 = IOCTL permit to users
  1829                              <1> 				     ; bit 4 = block device if set
  1830                              <1> 				     ; bit 5 = 16 bit or 1024 byte
  1831                              <1> 				     ; bit 6 = 32 bit or 2048 byte
  1832                              <1> 				     ; bit 7 = installable device drv
  1833 0000CE28 F6C501              <1> 	test 	ch, 1 ; accessable by normal users (except root)
  1834 0000CE2B 7510                <1> 	jnz	short sysopen_dev_4 ; yes, permission has been given
  1835 0000CE2D 803D[B0030300]00    <1> 	cmp	byte [u.uid], 0 ; root?
  1836 0000CE34 7607                <1> 	jna	short sysopen_dev_4 ; superuser can open all devices
  1837                              <1> sysopen_dev_perm_err:
  1838 0000CE36 B80B000000          <1> 	mov	eax, ERR_DEV_ACCESS  ; 11 = 'permission denied !'
  1839 0000CE3B EBA5                <1> 	jmp	short sysopen_dev_err
  1840                              <1> sysopen_dev_4:
  1841 0000CE3D D0ED                <1> 	shr	ch, 1 ; result: 1 = read, 2 = write, 3 = r & w 
  1842 0000CE3F FEC9                <1> 	dec	cl  ; result: 1 = read, 2 = write
  1843 0000CE41 84E9                <1> 	test	cl, ch
  1844 0000CE43 74F1                <1> 	jz	short sysopen_dev_perm_err 
  1845                              <1> 
  1846 0000CE45 D0E5                <1> 	shl	ch, 1 ; bit 0 = 0
  1847                              <1> 	; eax = device number (entry offset)
  1848 0000CE47 E8A3320000          <1> 	call	device_open
  1849 0000CE4C 72E8                <1> 	jc	short sysopen_dev_perm_err 
  1850                              <1> 
  1851                              <1> 	; eax = device number (entry offset)
  1852 0000CE4E 0C80                <1> 	or	al, 80h ; set device bit (set bit 7 to 1)
  1853 0000CE50 8B1D[64030300]      <1> 	mov	ebx, [u.r0]
  1854 0000CE56 8883[6A030300]      <1> 	mov	[ebx+u.fp], al	; bit 7 (=1) points to device	
  1855                              <1> 	
  1856 0000CE5C E9D8F8FFFF          <1> 	jmp	sysret
  1857                              <1> 
  1858                              <1> sysmkdir: ; < make directory >
  1859                              <1> 	; 15/10/2016
  1860                              <1> 	; 10/10/2016 (TRDOS 386 = TRDOS v2.0) 
  1861                              <1> 	;	     -derived from INT_21H.ASM-
  1862                              <1> 	;            ("loc_INT21h_create_file")
  1863                              <1>         ; 	10/07/2011 (12/03/2011)
  1864                              <1>         ;	INT 21h Function AH = 3Ch
  1865                              <1>         ;	Create File
  1866                              <1>         ;	INPUT
  1867                              <1>         ;	   CX = Attributes
  1868                              <1>         ;          DS:DX= Address of zero terminaned path name
  1869                              <1>         ;
  1870                              <1>         ;
  1871                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1872                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  1873                              <1> 	;
  1874                              <1> 	; 'sysmkdir' creates an empty directory whose name is
  1875                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.	
  1876                              <1> 	; The special entries '.' and '..' are not present.
  1877                              <1> 	; Errors are indicated if the directory already exists or		
  1878                              <1> 	; user is not the super user. 
  1879                              <1> 	;
  1880                              <1> 	; Calling sequence:
  1881                              <1> 	;	sysmkdir; name; mode
  1882                              <1> 	; Arguments:
  1883                              <1> 	;	name - points to the name of the directory
  1884                              <1> 	;	mode - mode of the directory
  1885                              <1> 	; Inputs: (arguments)
  1886                              <1> 	; Outputs: -
  1887                              <1> 	;    (sets 'directory' flag to 1; 
  1888                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
  1889                              <1> 	; ...............................................................
  1890                              <1> 	;				
  1891                              <1> 	; Retro UNIX 8086 v1 modification: 
  1892                              <1> 	;       'sysmkdir' system call has two arguments; so,
  1893                              <1> 	;	* 1st argument, name is pointed to by BX register
  1894                              <1> 	;	* 2nd argument, mode is in CX register
  1895                              <1> 	;
  1896                              <1> 	; TRDOS 386 (10/10/2016)
  1897                              <1> 	;	
  1898                              <1>         ; INPUT ->
  1899                              <1>         ;	   CL = Directory Attributes
  1900                              <1> 	;     	      bit 0 (1) - Read only file/dir (R)
  1901                              <1> 	;             bit 1 (1) - Hidden file/dir (H)
  1902                              <1>         ;             bit 2 (1) - System file/dir (R)
  1903                              <1> 	;             bit 3 (1) - Volume label/name (V)
  1904                              <1>         ;             bit 4 (1) - Subdirectory (D)
  1905                              <1> 	;	      bit 5 (1) - File/Dir has been archived (A)
  1906                              <1> 	;	   CX = 0 -> create normal directory	 	
  1907                              <1>         ;          EBX = Pointer to directory name (ASCIIZ) -path-
  1908                              <1> 	;	
  1909                              <1> 	; OUTPUT ->
  1910                              <1> 	;          eax = First cluster of the new directory
  1911                              <1> 	;          cf = 1 -> Error code in AL
  1912                              <1> 	;
  1913                              <1> 	; Modified Registers: EAX (at the return of system call)
  1914                              <1> 	;  
  1915                              <1> 	; Note: If the file or directory is existing
  1916                              <1> 	;	an access error will be returned. 
  1917                              <1> 
  1918 0000CE61 6621C9              <1> 	and	cx, cx ; if cx = 0 -> create a normal subdir
  1919 0000CE64 7413                <1> 	jz	short sysmkdir_1
  1920                              <1> 
  1921 0000CE66 F6C110              <1> 	test	cl, 10h ; if dir flags set, also use other flags
  1922 0000CE69 0F853EFDFFFF        <1> 	jnz	sysmkdir_0 ; jump to head of 'syscreat'
  1923                              <1> 
  1924                              <1> 	; CX has wrong flags
  1925 0000CE6F B817000000          <1> 	mov 	eax, ERR_INV_FLAGS
  1926 0000CE74 E969FFFFFF          <1> 	jmp	sysopen_dev_err
  1927                              <1> 
  1928                              <1> sysmkdir_1:
  1929 0000CE79 B110                <1> 	mov	cl, 10h ; set subdir flag and reset other flags
  1930 0000CE7B E92DFDFFFF          <1> 	jmp	sysmkdir_0 ; jump to head of 'syscreat'
  1931                              <1> sysmkdir_2: 
  1932                              <1> 	; jump from 'syscreat' ; from 'syscreat_1'
  1933                              <1> 	;  CL = Directory attributes/flags  
  1934 0000CE80 BE[48620100]        <1> 	mov	esi, FindFile_Name 
  1935 0000CE85 E804D7FFFF          <1> 	call	make_sub_directory
  1936 0000CE8A 0F821BFEFFFF        <1> 	jc	sysopen_err       ; NOTE: Old type (TRDOS 8086)
  1937                              <1> 				  ; error codes must be modified
  1938                              <1> 				  ; for next TRDOS 386 versions
  1939                              <1> 				  ; (10/10/2016)
  1940                              <1> 				  ; Old (MSDOS type)
  1941                              <1> 				  ; error codes (2011):
  1942                              <1> 				  ;  2 = file not found
  1943                              <1> 				  ;  3 = directory not found
  1944                              <1> 				  ;  5 = access denied
  1945                              <1> 				  ; 12 = no more files
  1946                              <1> 			          ; 19 = disk write protected   
  1947                              <1> 				  ; 39 = insufficient disk space
  1948                              <1> 				  ; 'sysdefs.s' ; 10/10/2016  	
  1949                              <1> 	
  1950 0000CE90 A3[64030300]        <1> 	mov	[u.r0], eax ; New sub dir's first cluster
  1951                              <1> 
  1952 0000CE95 E8912E0000          <1>         call 	reset_working_path
  1953                              <1> 
  1954 0000CE9A E99AF8FFFF          <1> 	jmp	sysret	
  1955                              <1> 
  1956                              <1> sysclose: ;<close file>
  1957                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0) 
  1958                              <1> 	;
  1959                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1960                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
  1961                              <1> 	;
  1962                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
  1963                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
  1964                              <1> 	; is put in r1 and 'fclose' is called.
  1965                              <1> 	;
  1966                              <1> 	; Calling sequence:
  1967                              <1> 	;	sysclose
  1968                              <1> 	; Arguments:
  1969                              <1> 	;	-  
  1970                              <1> 	; Inputs: *u.r0 - file descriptor
  1971                              <1> 	; Outputs: -
  1972                              <1> 	; ...............................................................
  1973                              <1> 	;				
  1974                              <1> 	; Retro UNIX 8086 v1 modification:
  1975                              <1> 	;	 The user/application program puts file descriptor
  1976                              <1> 	;        in BX register as 'sysclose' system call argument.
  1977                              <1> 	; 	 (argument transfer method 1)
  1978                              <1> 
  1979                              <1> 	; TRDOS 386 (06/10/2016)
  1980                              <1> 	;	
  1981                              <1>         ; INPUT ->
  1982                              <1>         ;	   EBX = File Handle/Number (file index) (AL)
  1983                              <1> 	; OUTPUT ->
  1984                              <1> 	;          cf = 0 -> EAX = 0
  1985                              <1> 	;          cf = 1 -> Error code in EAX (ERR_FILE_NOT_OPEN)
  1986                              <1> 	;
  1987                              <1> 	; Modified Registers: EAX (at the return of system call)
  1988                              <1> 	;  
  1989                              <1> 
  1990 0000CE9F 89D8                <1> 	mov 	eax, ebx
  1991 0000CEA1 31DB                <1> 	xor	ebx, ebx	
  1992 0000CEA3 891D[64030300]      <1> 	mov	[u.r0], ebx ; 0  ; return value of EAX
  1993 0000CEA9 E8450E0000          <1> 	call 	fclose
  1994 0000CEAE 0F8385F8FFFF        <1> 	jnc	sysret
  1995 0000CEB4 B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN ; file not open !
  1996 0000CEB9 A3[C8030300]        <1> 	mov	[u.error], eax ;
  1997 0000CEBE A3[64030300]        <1> 	mov	[u.r0], eax ; ! invalid handle !
  1998 0000CEC3 E951F8FFFF          <1> 	jmp	error
  1999                              <1> 
  2000                              <1> sysread: ; < read from file >
  2001                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0) 
  2002                              <1> 	;	     -derived from INT_21H.ASM-
  2003                              <1> 	;            ("loc_INT21h_read_file")
  2004                              <1>         ; 	13/03/2011 (05/03/2011)
  2005                              <1>         ;	INT 21h Function AH = 3Fh
  2006                              <1>         ;	Read from a File
  2007                              <1>         ;	INPUT
  2008                              <1> 	;	   BX = File Handle
  2009                              <1>         ;	   CX = Number of bytes to read
  2010                              <1>         ;          DS:DX= Buffer address
  2011                              <1>         ;
  2012                              <1> 	; Note: TRDOS 386 'sysread' has been derived from 
  2013                              <1> 	;	Retro UNIX 386 v1 'sysread', except a few 
  2014                              <1> 	;	code modifications.
  2015                              <1> 	;
  2016                              <1> 	; 13/05/2015 (Retro UNIX 386 v1)
  2017                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2018                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  2019                              <1> 	;
  2020                              <1> 	; 'sysread' is given a buffer to read into and the number of
  2021                              <1> 	; characters to be read. If finds the file from the file
  2022                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
  2023                              <1> 	; is returned from a successful open call (sysopen).
  2024                              <1> 	; The i-number of file is obtained via 'rw1' and the data
  2025                              <1> 	; is read into core via 'readi'.
  2026                              <1> 	;
  2027                              <1> 	; Calling sequence:
  2028                              <1> 	;	sysread; buffer; nchars
  2029                              <1> 	; Arguments:
  2030                              <1> 	;	buffer - location of contiguous bytes where 
  2031                              <1> 	;		 input will be placed.
  2032                              <1> 	;	nchars - number of bytes or characters to be read.
  2033                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  2034                              <1> 	; Outputs: *u.r0 - number of bytes read.	
  2035                              <1> 	; ...............................................................
  2036                              <1> 	;				
  2037                              <1> 	; Retro UNIX 8086 v1 modification: 
  2038                              <1> 	;       'sysread' system call has three arguments; so,
  2039                              <1> 	;	* 1st argument, file descriptor is in BX register
  2040                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  2041                              <1> 	;	* 3rd argument, number of bytes is in DX register
  2042                              <1> 	;
  2043                              <1> 	;	AX register (will be restored via 'u.r0') will return
  2044                              <1> 	;	to the user with number of bytes read. 
  2045                              <1> 	;
  2046                              <1> 	; TRDOS 386 (05/10/2016)
  2047                              <1> 	;	
  2048                              <1>         ; INPUT ->
  2049                              <1>         ;	   EBX = File handle (descriptor/index)
  2050                              <1> 	;	   ECX = Buffer address		
  2051                              <1>         ;          EDX = Number of bytes
  2052                              <1> 	; OUTPUT ->
  2053                              <1> 	;          EAX = Number of bytes have been read
  2054                              <1> 	;          cf = 1 -> Error code in AL
  2055                              <1> 	;
  2056                              <1> 	; Modified Registers: EAX (at the return of system call)
  2057                              <1> 	; 
  2058                              <1> 
  2059                              <1> 	; EBX = File descriptor
  2060 0000CEC8 E8740E0000          <1> 	call	getf1 
  2061 0000CECD 7277                <1> 	jc	short device_read ; read data from device
  2062                              <1> 	; EAX = First cluster of the file
  2063                              <1> 
  2064 0000CECF E83F000000          <1> 	call	rw1
  2065 0000CED4 730A                <1> 	jnc	short sysread_0
  2066                              <1> 
  2067 0000CED6 A3[64030300]        <1> 	mov	[u.r0], eax ; error code
  2068 0000CEDB E939F8FFFF          <1> 	jmp	error
  2069                              <1> 	 
  2070                              <1> sysread_0:
  2071 0000CEE0 E825140000          <1> 	call	readi
  2072 0000CEE5 EB1D                <1> 	jmp	short rw0
  2073                              <1> 
  2074                              <1> syswrite: ; < write to file >
  2075                              <1> 	; 23/10/2016
  2076                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0) 
  2077                              <1> 	;	     -derived from INT_21H.ASM-
  2078                              <1> 	;            ("loc_INT21h_write_file")
  2079                              <1>         ; 	13/03/2011 (05/03/2011)
  2080                              <1>         ;	INT 21h Function AH = 40h
  2081                              <1>         ;	Write to a File
  2082                              <1>         ;	INPUT
  2083                              <1> 	;	   BX = File Handle
  2084                              <1>         ;	   CX = Number of bytes to write
  2085                              <1>         ;          DS:DX= Buffer address
  2086                              <1>         ;
  2087                              <1> 	; Note: TRDOS 386 'sysrwrite' has been derived from 
  2088                              <1> 	;	Retro UNIX 386 v1 'syswrite', except a few 
  2089                              <1> 	;	code modifications.
  2090                              <1> 	;
  2091                              <1> 
  2092                              <1> 	; 13/05/2015 (Retro UNIX 386 v1)
  2093                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2094                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  2095                              <1> 	;
  2096                              <1> 	; 'syswrite' is given a buffer to write onto an output file
  2097                              <1> 	; and the number of characters to write. If finds the file
  2098                              <1> 	; from the file descriptor located in *u.r0 (r0). This file 
  2099                              <1> 	; descriptor is returned from a successful open or create call
  2100                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
  2101                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
  2102                              <1> 	;
  2103                              <1> 	; Calling sequence:
  2104                              <1> 	;	syswrite; buffer; nchars
  2105                              <1> 	; Arguments:
  2106                              <1> 	;	buffer - location of contiguous bytes to be writtten.
  2107                              <1> 	;	nchars - number of characters to be written.
  2108                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  2109                              <1> 	; Outputs: *u.r0 - number of bytes written.	
  2110                              <1> 	; ...............................................................
  2111                              <1> 	;				
  2112                              <1> 	; Retro UNIX 8086 v1 modification: 
  2113                              <1> 	;       'syswrite' system call has three arguments; so,
  2114                              <1> 	;	* 1st argument, file descriptor is in BX register
  2115                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  2116                              <1> 	;	* 3rd argument, number of bytes is in DX register
  2117                              <1> 	;
  2118                              <1> 	;	AX register (will be restored via 'u.r0') will return
  2119                              <1> 	;	to the user with number of bytes written. 
  2120                              <1> 	;
  2121                              <1> 	; INPUT ->
  2122                              <1>         ;	   EBX = File handle (descriptor/index)
  2123                              <1> 	;	   ECX = Buffer address		
  2124                              <1>         ;          EDX = Number of bytes
  2125                              <1> 	; OUTPUT ->
  2126                              <1> 	;          EAX = Number of bytes have been written
  2127                              <1> 	;          cf = 1 -> Error code in AL
  2128                              <1> 	;
  2129                              <1> 	; Modified Registers: EAX (at the return of system call)
  2130                              <1> 	;  
  2131                              <1> 
  2132                              <1> 	; EBX = File descriptor
  2133 0000CEE7 E8550E0000          <1> 	call	getf1 
  2134 0000CEEC 7274                <1> 	jc	short device_write ; write data to device
  2135                              <1> 	; EAX = First cluster of the file
  2136                              <1> 	; EBX = File number  (Open file number) ; 23/10/2016
  2137                              <1> 
  2138 0000CEEE E820000000          <1> 	call	rw1
  2139 0000CEF3 730A                <1> 	jnc	short syswrite_0
  2140 0000CEF5 A3[64030300]        <1> 	mov	[u.r0], eax ; error code
  2141 0000CEFA E91AF8FFFF          <1> 	jmp	error
  2142                              <1> 	 
  2143                              <1> syswrite_0:
  2144 0000CEFF E8321B0000          <1> 	call	writei
  2145                              <1> rw0: ; 1:
  2146 0000CF04 A1[8C030300]        <1>         mov	eax, [u.nread]
  2147 0000CF09 A3[64030300]        <1> 	mov	[u.r0], eax
  2148 0000CF0E E926F8FFFF          <1> 	jmp	sysret
  2149                              <1> 
  2150                              <1> rw1:	
  2151                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0) 
  2152                              <1> 	; 14/05/2015 (Retro UNIX 386 v1)
  2153                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2154                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
  2155                              <1> 	; System call registers: ebx, ecx, edx (through 'sysenter')
  2156                              <1> 	;
  2157                              <1> 	; EBX = File descriptor
  2158                              <1> 	;call	getf1 ; calling point in 'getf' from 'rw1'
  2159                              <1> 	;jc	short device_rw ; read/write data from/to device
  2160                              <1> 	; EAX = First cluster of the file
  2161                              <1> 
  2162 0000CF13 83F802              <1> 	cmp 	eax, 2
  2163 0000CF16 7217                <1> 	jb	short rw2
  2164                              <1> 	;
  2165 0000CF18 890D[84030300]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
  2166                              <1> 				;(in the user's virtual memory space)
  2167 0000CF1E 8915[88030300]      <1> 	mov	[u.count], edx 
  2168                              <1> 
  2169 0000CF24 C705[C8030300]0000- <1>         mov     dword [u.error], 0 ; reset the last error code
  2169 0000CF2C 0000                <1>
  2170 0000CF2E C3                  <1> 	retn
  2171                              <1> 
  2172                              <1> rw2:
  2173 0000CF2F B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN ; file not open !
  2174 0000CF34 A3[C8030300]        <1> 	mov	dword [u.error], eax
  2175 0000CF39 C3                  <1> 	retn
  2176                              <1> rw3: 
  2177 0000CF3A B80B000000          <1> 	mov	eax, ERR_FILE_ACCESS ; permission denied !
  2178 0000CF3F A3[C8030300]        <1> 	mov	dword [u.error], eax
  2179 0000CF44 F9                  <1> 	stc
  2180 0000CF45 C3                  <1> 	retn
  2181                              <1> 
  2182                              <1> device_read:
  2183                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2184                              <1> 	; cl = DEV_OPENMODE ; open mode
  2185                              <1> 	; ch = DEV_ACCESS   ; access flags   
  2186                              <1> 	; al = DEV_DRIVER   ; device number (eax)
  2187                              <1> 
  2188 0000CF46 F6C101              <1> 	test	cl, 1 ; 1 = read, 2 = write, 3 = read&write
  2189 0000CF49 74EF                <1> 	jz	short rw3
  2190                              <1> 
  2191 0000CF4B 89C3                <1> 	mov	ebx, eax
  2192 0000CF4D 66C1E302            <1> 	shl	bx, 2 ; *4
  2193                              <1> 
  2194 0000CF51 F6C580              <1> 	test	ch, 80h ; bit 7, installable device driver flag
  2195 0000CF54 7406                <1> 	jz	short d_read_2 ; Kernel device
  2196                              <1> 	; installable device
  2197                              <1> d_read_1:
  2198 0000CF56 FFA3[14660100]      <1>         jmp	dword [ebx+IDEV_RADDR-4]
  2199                              <1> d_read_2:
  2200 0000CF5C FFA3[B8150100]      <1> 	jmp	dword [ebx+KDEV_RADDR-4]
  2201                              <1> 
  2202                              <1> device_write:
  2203                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2204                              <1> 	; cl = DEV_OPENMODE ; open mode
  2205                              <1> 	; ch = DEV_ACCESS   ; access flags   
  2206                              <1> 	; al = DEV_DRIVER   ; device number (eax)
  2207                              <1> 
  2208 0000CF62 F6C102              <1> 	test	cl, 2 ; 1 = read, 2 = write, 3 = read&write
  2209 0000CF65 74D3                <1> 	jz	short rw3	
  2210                              <1> 
  2211 0000CF67 89C3                <1> 	mov	ebx, eax
  2212 0000CF69 66C1E302            <1> 	shl	bx, 2 ; *4
  2213                              <1> 
  2214 0000CF6D F6C580              <1> 	test	ch, 80h ; bit 7, installable device driver flag
  2215 0000CF70 7406                <1> 	jz	short d_write_2 ; Kernel device
  2216                              <1> 	; installable device
  2217                              <1> d_write_1:
  2218 0000CF72 FFA3[34660100]      <1>         jmp	dword [ebx+IDEV_WADDR-4]
  2219                              <1> d_write_2:
  2220 0000CF78 FFA3[08160100]      <1> 	jmp	dword [ebx+KDEV_WADDR-4]
  2221                              <1> 
  2222                              <1> 
  2223                              <1> sysemt: ; enable (or disable) multi tasking -time sharing-
  2224                              <1> 	;
  2225                              <1> 	; 23/05/2016 - TRDOS 386 (TRDOS v2.0)
  2226                              <1> 	; 14/05/2015 (Retro UNIX 386 v1)
  2227                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
  2228                              <1> 	;
  2229                              <1> 	; Retro UNIX 8086 v1 modification: 
  2230                              <1> 	;	'Enable Multi Tasking'  system call instead 
  2231                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
  2232                              <1> 	;
  2233                              <1> 	; Retro UNIX 8086 v1 feature only!
  2234                              <1> 	;	Using purpose: Kernel will start without time-out
  2235                              <1> 	;	(internal clock/timer) functionality.
  2236                              <1> 	;	Then etc/init will enable clock/timer for
  2237                              <1> 	;	multi tasking. 
  2238                              <1> 	;
  2239                              <1> 	; INPUT ->
  2240                              <1> 	;	BL = 0 -> disable multi tasking
  2241                              <1> 	;	BL > 1 -> enable multi tasking (time sharing) 
  2242                              <1> 	; OUTPUT ->
  2243                              <1> 	;	none	
  2244                              <1> 	;
  2245                              <1> 	;  Note: Multi tasking is disabled during system
  2246                              <1> 	;	 initialization, it must be enabled by using
  2247                              <1> 	;	 this system call. (Otherwise, running proces 
  2248                              <1> 	;	 will not be changed by another process within
  2249                              <1> 	;	 run time sequence/schedule, if running process
  2250                              <1> 	;	 will not 'release' itself. Only 'wakeup' procedure
  2251                              <1> 	;	 for waiting processes and programmed timer events
  2252                              <1> 	;	 for other processes can change running process 
  2253                              <1> 	;	 while multi tasking is disabled.) ** 23/05/2016 **
  2254                              <1> 
  2255 0000CF7E 803D[B0030300]00    <1> 	cmp	byte [u.uid], 0 ; root ?
  2256                              <1> 	;ja	error
  2257 0000CF85 0F87D3F8FFFF        <1> 	ja	badsys ; 14/05/2015
  2258                              <1> 	;
  2259 0000CF8B FA                  <1> 	cli
  2260 0000CF8C 881D[32650100]      <1> 	mov	[multi_tasking], bl ; 0 to disable, >0 to enable
  2261 0000CF92 E9A2F7FFFF          <1> 	jmp	sysret
  2262                              <1> 
  2263                              <1> systimer:
  2264                              <1> 	; 02/01/2017
  2265                              <1> 	; 21/12/2016
  2266                              <1> 	; 19/12/2016
  2267                              <1> 	; 10/12/2016 (callback)
  2268                              <1> 	; 10/06/2016
  2269                              <1> 	; 07/06/2016
  2270                              <1> 	; 06/06/2016
  2271                              <1> 	; 21/05/2016
  2272                              <1> 	; 19/05/2016
  2273                              <1> 	; 18/05/2016 - TRDOS 386 (TRDOS v2.0)
  2274                              <1> 	; (TRDOS 386 feature only!)
  2275                              <1> 	;
  2276                              <1> 	; (start or stop timer event(s))	
  2277                              <1> 	;
  2278                              <1> 	; INPUT ->
  2279                              <1> 	;	BL = Signal return byte (response byte)
  2280                              <1> 	;	     (Any requested value between 0 and 255)
  2281                              <1> 	;	     (Kernel will put it at the requested address)    	
  2282                              <1> 	;	BH = Time count unit
  2283                              <1> 	;	     0 = Stop timer event
  2284                              <1> 	;	     1 = 18.2 ticks per second
  2285                              <1> 	;	     2 = 10 milliseconds  		
  2286                              <1> 	;	     3 = 1 second (for real time clock interrupt) 	 
  2287                              <1> 	;	     4 = time/tick count in current time count unit
  2288                              <1> 	;	    // 10/12/2016			
  2289                              <1> 	;	    80h = Stop timer event (callback method)
  2290                              <1> 	;	    81h = 18.2 ticks per second, callback method
  2291                              <1> 	;	    82h = 10 milliseconds, callback method 	
  2292                              <1> 	;	    83h = 1 second (for RTC int), callback method 	
  2293                              <1> 	;	    84h = current time count unit, callback method
  2294                              <1> 	;
  2295                              <1> 	;	    Note: Only 03h or 83h will set real time clock
  2296                              <1> 	;		  (RTC) events (Others are for PIT events)! 	
  2297                              <1> 	;	
  2298                              <1> 	;	NOTE: If callback (user service) method is used,
  2299                              <1> 	;	    EDX will point to the return address (of service
  2300                              <1> 	;	    procedure) in user's space instead of signal 
  2301                              <1> 	;	    response byte address. (TRDOS 386 kernel will
  2302                              <1> 	;	    direct the cpu to that address -in user's space-
  2303                              <1> 	;	    at the return of system call or interrupt 
  2304                              <1> 	;	    just after the adjusted count/time is elapsed.)
  2305                              <1> 	;	    User's sevice routine must be ended with a
  2306                              <1> 	;	    'iret'. Normal return addresses from system 
  2307                              <1> 	;	    calls or and interrupts will be kept same except
  2308                              <1> 	;	    the timer returns. 			
  2309                              <1>      	;
  2310                              <1> 	;	BH = 0 -> Stop timer event
  2311                              <1> 	;	BL = Timer event number (1 to 255) if BH = 0     	
  2312                              <1> 	;	     If BL = 0, all timer events (which are belongs
  2313                              <1> 	;	      to running process) will be stopped 		    
  2314                              <1> 	;	ECX = Time/Tick count (depending on time count unit)
  2315                              <1> 	;	EDX = Signal return (Response) byte address
  2316                              <1> 	;	      (virtual address in user's memory space)
  2317                              <1> 	; OUTPUT ->
  2318                              <1> 	;	AL = Timer event number	(1 to 255) (max. value = 16)
  2319                              <1> 	;	IF BH Input = 0 & CF = 0 & AL = 0 -> 
  2320                              <1> 	;	     timer event(s) has/have been stopped/finished
  2321                              <1> 	;	CF = 1 & AL = 0 -> no timer setting space to set
  2322                              <1> 	;	CF = 1 & AL > 0 -> timer count unit is not usable
  2323                              <1> 	;
  2324                              <1> 	;	NOTE: To modify a time count for a user function,
  2325                              <1> 	;	      at first, current timer event must be stopped
  2326                              <1> 	;	      then a new timer event (which is related with
  2327                              <1> 	;	      same user function) must be started.
  2328                              <1> 	;		
  2329                              <1> 	;	      Signal return (response) byte may be used for 
  2330                              <1> 	;	      several purposes. Kernel will put this value 
  2331                              <1> 	;	      to requested address during timer interrupt,
  2332                              <1> 	;	      program/user can check this value to understand
  2333                              <1> 	;	      which event has been occurred and what is changed.
  2334                              <1> 	;	      (Multi timer events can share same signal address)
  2335                              <1> 	;	
  2336                              <1> 	;	NOTE: If the process is running while the time count
  2337                              <1> 	;	      is reached, kernel will put signal return (response)
  2338                              <1> 	;	      byte value at requested address during timer
  2339                              <1> 	;	      interrupt and the process will continue to run.
  2340                              <1> 	;	      Program/process must call (jump to) it's timer event
  2341                              <1> 	;	      function as required, for checking the timer event
  2342                              <1> 	;	      status via signal return (response) byte address. 
  2343                              <1> 	;
  2344                              <1> 	;	      If the process is not running (waiting or sleeping
  2345                              <1> 	;	      or released) while the time count is reached,
  2346                              <1> 	;	      it is restarted from where it left, to ensure
  2347                              <1> 	;	      proper multi media (video, audio, clock, timer)
  2348                              <1> 	;	      functionality.
  2349                              <1> 	;
  2350                              <1> 	;	      (It is better to use 'syswait' or 'syssleep',
  2351                              <1> 	;	      or 'sysrele' system call just after the timer
  2352                              <1> 	;	      function. Otherwise, timer events may block other
  2353                              <1> 	;	      processes which are not using timer events.)  	 		 			 		 	
  2354                              <1> 	;	     	      		 			
  2355                              <1> 	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  2356                              <1> 	;       Owner:	        resb 1 ; 0 = free
  2357                              <1> 	;		  	       ;>0 = process number (u.uno)
  2358                              <1> 	;	Calback:	resb 1 ; 1 = callback, 0 = response byte
  2359                              <1> 	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  2360                              <1> 	;		   	       ; 1 = Real Time Clock interrupt 
  2361                              <1> 	;	Response:       resb 1 ; 0 to 255, signal return value
  2362                              <1> 	;	Count Limit:	resd 1 ; count of ticks (total/set)
  2363                              <1> 	;	Current Count: 	resd 1 ; count of ticks (current)
  2364                              <1> 	;	Response Addr:  resd 1 ; response byte (pointer) address
  2365                              <1> 	;
  2366                              <1> 
  2367                              <1> 	; 19/12/2016 (timer callback)
  2368 0000CF97 C605[706A0100]00    <1> 	mov	byte [tcallback], 0 
  2369 0000CF9E C605[716A0100]00    <1> 	mov	byte [trtc], 0
  2370 0000CFA5 C705[D0030300]0000- <1> 	mov	dword [u.tcb], 0 ; this is not necessary...
  2370 0000CFAD 0000                <1>
  2371                              <1> 
  2372 0000CFAF 80FF80              <1> 	cmp	bh, 80h
  2373 0000CFB2 7225                <1> 	jb	short systimer_cb2
  2374 0000CFB4 7704                <1> 	ja	short systimer_cb0
  2375                              <1> 
  2376 0000CFB6 31D2                <1> 	xor	edx, edx ; 0, reset callback address
  2377 0000CFB8 EB0B                <1> 	jmp	short systimer_cb1
  2378                              <1> 
  2379                              <1> systimer_cb0:
  2380 0000CFBA 80FF84              <1> 	cmp	bh, 84h	
  2381 0000CFBD 7764                <1> 	ja	short systimer_5 ;  undefined, error
  2382                              <1> 
  2383                              <1> 	;mov	byte [tcallback], 1 ; 19/12/2016
  2384 0000CFBF FE05[706A0100]      <1> 	inc	byte [tcallback]
  2385                              <1> 
  2386                              <1> systimer_cb1:
  2387 0000CFC5 0FB635[B3030300]    <1> 	movzx	esi, byte [u.uno] ; process number
  2388 0000CFCC 66C1E602            <1> 	shl	si, 2	
  2389 0000CFD0 8996[0C010300]      <1> 	mov	[esi+p.tcb-4], edx ; set process timer callback address
  2390                              <1> 				   ; (overwrite prev value if it is set!)
  2391 0000CFD6 80E77F              <1> 	and	bh, 7Fh
  2392                              <1> 
  2393                              <1> systimer_cb2:
  2394 0000CFD9 80FF02              <1> 	cmp	bh, 2
  2395 0000CFDC 7445                <1>         je      short systimer_5  ; only 18.2 ticks per second is usable
  2396                              <1> 				  ; 10 milliseconds (100 Hertz) timer 
  2397                              <1> 				  ; will be set later (18/05/2016)
  2398 0000CFDE 774B                <1>         ja      short systimer_6 
  2399                              <1> 
  2400 0000CFE0 20FF                <1> 	and	bh, bh
  2401 0000CFE2 0F84BA000000        <1>         jz      systimer_9        ; stop timer event(s)
  2402                              <1> 
  2403                              <1> 	; bh = 1 (timer interrupt, 18.2 Hz, IBM PC/AT ROMBIOS default)
  2404                              <1> 
  2405                              <1> systimer_19:
  2406 0000CFE8 B00A                <1> 	mov	al, 10 ; (*)
  2407                              <1> 
  2408                              <1> systimer_0:
  2409 0000CFEA B710                <1> 	mov	bh, 16
  2410                              <1> 	;
  2411 0000CFEC 383D[33650100]      <1> 	cmp	[timer_events], bh ; 16 ; 07/06/2016
  2412 0000CFF2 7319                <1> 	jnb 	short systimer_3  ; max. 16 timer events
  2413                              <1> 	;
  2414 0000CFF4 50                  <1> 	push	eax ; (*)
  2415                              <1> 
  2416 0000CFF5 BF[60040300]        <1> 	mov	edi, timer_set  ; beginning address of timer events
  2417                              <1> 				; setting space
  2418 0000CFFA 30C0                <1> 	xor	al, al ; 0
  2419                              <1> systimer_1:
  2420 0000CFFC FEC0                <1> 	inc	al
  2421 0000CFFE 803F00              <1> 	cmp	byte [edi], 0 	; is it free space ?
  2422 0000D001 7639                <1> 	jna	short systimer_7 ; yes
  2423 0000D003 FECF                <1> 	dec	bh
  2424 0000D005 7405                <1> 	jz	short systimer_2
  2425 0000D007 83C710              <1> 	add	edi, 16
  2426 0000D00A EBF0                <1> 	jmp	short  systimer_1 ; next event space
  2427                              <1> 
  2428                              <1> systimer_2:
  2429 0000D00C 58                  <1> 	pop	eax ; (*) discard
  2430                              <1> systimer_3:
  2431 0000D00D C605[64030300]00    <1> 	mov	byte [u.r0], 0
  2432                              <1> systimer_4:
  2433 0000D014 C705[C8030300]1B00- <1>         mov     dword [u.error], ERR_MISC
  2433 0000D01C 0000                <1>
  2434                              <1>                                 ; one of miscellaneous/other errors
  2435 0000D01E E9F6F6FFFF          <1> 	jmp	error ; cf -> 1
  2436                              <1> 
  2437                              <1> systimer_5:
  2438 0000D023 883D[64030300]      <1> 	mov	[u.r0], bh ; Time count unit (=2 or >3)
  2439 0000D029 EBE9                <1> 	jmp	short systimer_4 ; 07/06/2016
  2440                              <1> 
  2441                              <1> systimer_6:
  2442 0000D02B 80FF04              <1> 	cmp	bh, 4
  2443 0000D02E 77F3                <1>         ja      short systimer_5  ; undefined time count unit
  2444                              <1> 	;jb	short systimer_16	
  2445                              <1> 
  2446                              <1> 	;mov	al, 1	; default (use current timer unit)
  2447                              <1> 			; countdown value is in ECX ! 
  2448                              <1> 			; max. value of ecx = 4294967296/10
  2449                              <1>         ;jmp    short systimer_0
  2450                              <1> 	;jmp	short systimer_19	
  2451 0000D030 74B6                <1> 	je	short systimer_19
  2452                              <1> 
  2453                              <1> systimer_16:
  2454                              <1> 	; bh = 3
  2455                              <1> 	; timer event via real time clock interrupt
  2456                              <1> 	; interrupt/update frequency: 1 Hz (1 tick per second)
  2457                              <1> 	
  2458 0000D032 B0B6                <1> 	mov	al, 182 ; (*) ; 18.2 * 10
  2459 0000D034 FE05[716A0100]      <1> 	inc	byte [trtc] ; timer event via real time clock
  2460 0000D03A EBAE                <1>         jmp     short systimer_0
  2461                              <1> 
  2462                              <1> systimer_7:
  2463 0000D03C A2[64030300]        <1> 	mov	[u.r0], al ; timer event number
  2464                              <1> 	;
  2465                              <1> 	; edi = address of empty timer event area
  2466 0000D041 A0[B3030300]        <1> 	mov	al, [u.uno]
  2467 0000D046 FA                  <1> 	cli 	; disable interrupts 
  2468 0000D047 AA                  <1> 	stosb	; process number
  2469 0000D048 A0[706A0100]        <1> 	mov	al, [tcallback] ; timer callback flag
  2470 0000D04D AA                  <1> 	stosb 	; 1= callback method, 0= signal response byte method
  2471 0000D04E A0[716A0100]        <1> 	mov	al, [trtc] ; timer interrupt type
  2472 0000D053 AA                  <1> 	stosb	; 1= real time clock, 0= programmable interval timer
  2473 0000D054 88D8                <1> 	mov	al, bl ; Signal return (Response) value
  2474 0000D056 AA                  <1> 	stosb   ; response byte
  2475 0000D057 58                  <1> 	pop	eax ; (*) ; 10 or 182
  2476 0000D058 89D3                <1> 	mov	ebx, edx ; virtual address for response/signal byte
  2477 0000D05A F7E1                <1> 	mul	ecx
  2478                              <1> 	; (eax = 10 * count of 18.2 Hz timer ticks)
  2479                              <1> 	; (count down step = 10)
  2480 0000D05C AB                  <1> 	stosd  ; count limit (reset value)
  2481 0000D05D AB                  <1> 	stosd  ; current count value
  2482                              <1> 
  2483                              <1> 	; 19/12/2016
  2484 0000D05E 803D[706A0100]00    <1> 	cmp	byte [tcallback], 0 ; timer callback method ?
  2485 0000D065 7604                <1> 	jna	short systimer_17 ; no	
  2486 0000D067 89D8                <1> 	mov	eax, ebx ; virtual address for callback routine 
  2487 0000D069 EB0D                <1> 	jmp	short systimer_18
  2488                              <1> 
  2489                              <1> systimer_17: ; signal response byte method
  2490                              <1> 	; ebx = virtual address
  2491                              <1> 	; [u.pgdir] = page directory's physical address
  2492                              <1> 	; 20/02/2017
  2493 0000D06B FE05[726A0100]      <1> 	inc	 byte [no_page_swap] ; 1 
  2494                              <1> 			; Do not add this page to swap queue
  2495                              <1> 			; and remove it from swap queue if it is
  2496                              <1> 			; on the queue.
  2497 0000D071 E84B82FFFF          <1> 	call	get_physical_addr
  2498 0000D076 721A                <1> 	jc	short systimer_8 ; 07/06/2016
  2499                              <1> 	; eax = physical address of the virtual address in user's space
  2500                              <1> systimer_18:
  2501 0000D078 AB                  <1> 	stosd	; response addr (physical) or callback addr (virtual)
  2502 0000D079 FE05[33650100]      <1> 	inc	byte [timer_events] ; 07/06/201
  2503                              <1> 	; 02/01/2017
  2504 0000D07F 0FB605[B3030300]    <1> 	movzx	eax, byte [u.uno]
  2505 0000D086 FE80[FF000300]      <1> 	inc	byte [eax+p.timer-1]	
  2506                              <1> 	;
  2507 0000D08C FB                  <1> 	sti 	; enable interrupts
  2508 0000D08D E9A7F6FFFF          <1> 	jmp	sysret
  2509                              <1> 
  2510                              <1> systimer_8:
  2511                              <1> 	; 10/06/2016
  2512                              <1> 	; 07/06/2016
  2513 0000D092 28C0                <1> 	sub	al, al ; 0
  2514 0000D094 8847F4              <1> 	mov	[edi-12], al ; clear process number (free timer event)
  2515                              <1> 	;mov	dword [edi], eax ; 0
  2516 0000D097 FB                  <1> 	sti
  2517 0000D098 A2[64030300]        <1> 	mov	[u.r0], al ; 0
  2518 0000D09D E977F6FFFF          <1> 	jmp	error
  2519                              <1> 
  2520                              <1> systimer_9:
  2521                              <1> 	; 10/06/2016
  2522                              <1> 	; 07/06/2016
  2523 0000D0A2 28C0                <1> 	sub	al, al
  2524 0000D0A4 A2[64030300]        <1> 	mov	byte [u.r0], al ; 0
  2525 0000D0A9 3805[33650100]      <1> 	cmp     byte [timer_events], al ;  0
  2526 0000D0AF 7631                <1> 	jna	short systimer_12
  2527                              <1> 
  2528                              <1> 	; Note: ecx and edx are undefined here
  2529                              <1> 	;	(for stop timer function)
  2530                              <1> 
  2531 0000D0B1 BE[60040300]        <1> 	mov	esi, timer_set  ; beginning address of timer events
  2532                              <1> 				; setting space	 
  2533 0000D0B6 A0[B3030300]        <1> 	mov	al, [u.uno]
  2534                              <1> 	
  2535 0000D0BB B710                <1> 	mov	bh, 16
  2536                              <1> 
  2537 0000D0BD 08DB                <1> 	or	bl, bl
  2538 0000D0BF 7544                <1> 	jnz	short systimer_15
  2539                              <1> 
  2540                              <1> 	; clear timer event areas belong to current process
  2541                              <1> 	; (for stopping all timer events belong to current process) 
  2542 0000D0C1 FA                  <1> 	cli 	; disable interrupts
  2543                              <1> systimer_10:
  2544                              <1> 	; 10/06/2016
  2545                              <1> 	; 07/06/2016 	
  2546 0000D0C2 8A26                <1> 	mov	ah, [esi]
  2547 0000D0C4 08E4                <1> 	or	ah, ah ; 0 ?
  2548 0000D0C6 7411                <1> 	jz	short systimer_11
  2549 0000D0C8 38C4                <1> 	cmp	ah, al ; is the process number (owner) same ?
  2550 0000D0CA 750D                <1>         jne     short systimer_11 ; no
  2551                              <1> 
  2552                              <1> 	;mov	byte [esi], 0
  2553 0000D0CC 66C7060000          <1> 	mov	word [esi], 0 ; clear
  2554                              <1> 	;mov	dword [esi+12], 0 ; clear
  2555                              <1> 
  2556 0000D0D1 FE0D[33650100]      <1> 	dec	byte [timer_events]
  2557 0000D0D7 7409                <1> 	jz	short systimer_12
  2558                              <1> 
  2559                              <1> systimer_11:
  2560 0000D0D9 FECF                <1> 	dec	bh
  2561 0000D0DB 7405                <1> 	jz	short systimer_12
  2562 0000D0DD 83C610              <1> 	add	esi, 16
  2563 0000D0E0 EBE0                <1> 	jmp	short systimer_10
  2564                              <1> 
  2565                              <1> systimer_12:
  2566 0000D0E2 0FB635[B3030300]    <1> 	movzx	esi, byte [u.uno]
  2567 0000D0E9 08DB                <1> 	or	bl, bl ; all timer events or one timer event ?
  2568 0000D0EB 740C                <1> 	jz	short systimer_13
  2569 0000D0ED 8A9E[FF000300]      <1> 	mov	bl, [esi+p.timer-1]
  2570 0000D0F3 20DB                <1> 	and	bl, bl	; previous number of timer events for the process
  2571 0000D0F5 7408                <1> 	jz	short systimer_14
  2572 0000D0F7 FECB                <1> 	dec	bl  ; previous number of timer events for the process - 1
  2573                              <1> systimer_13:
  2574 0000D0F9 889E[FF000300]      <1> 	mov	[esi+p.timer-1], bl ; 0 ; no timer events for process
  2575                              <1> systimer_14:
  2576 0000D0FF FB                  <1> 	sti	; enable interrupts
  2577 0000D100 E934F6FFFF          <1> 	jmp	sysret
  2578                              <1> 
  2579                              <1> systimer_15:
  2580 0000D105 38FB                <1> 	cmp	bl, bh ; 16
  2581 0000D107 0F8707FFFFFF        <1>         ja      systimer_4      ; max. 16 timer events !
  2582                              <1> 	;
  2583 0000D10D 88DA                <1> 	mov	dl, bl
  2584 0000D10F FECA                <1> 	dec	dl  ; 16 -> 15 ... 1 -> 0 
  2585 0000D111 C0E204              <1> 	shl	dl, 4 ; * 16
  2586 0000D114 0FB6FA              <1> 	movzx	edi, dl
  2587 0000D117 01F7                <1> 	add	edi, esi ; timer_set 
  2588                              <1> 	
  2589 0000D119 3A07                <1> 	cmp	al, [edi] ; process number
  2590 0000D11B 0F85F3FEFFFF        <1>         jne     systimer_4
  2591                              <1> 	
  2592                              <1> 	; same process ID
  2593 0000D121 FA                  <1> 	cli	; disable interrupts
  2594                              <1>  	; 10/06/2016 ; 02/01/2017
  2595                              <1> 	;mov	byte [edi], 0 
  2596 0000D122 66C7070000          <1> 	mov	word [edi], 0 ; clear
  2597                              <1> 	;mov	dword [edi+12], 0 ; clear
  2598 0000D127 FE0D[33650100]      <1> 	dec	byte [timer_events]
  2599 0000D12D EBB3                <1> 	jmp	short systimer_12
  2600                              <1> 
  2601                              <1> sysvideo: ; VIDEO DATA TRANSFER FUNCTIONS
  2602                              <1> 	; 12/05/2017
  2603                              <1> 	; 11/07/2016
  2604                              <1> 	; 13/06/2016
  2605                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  2606                              <1> 	;
  2607                              <1> 	;
  2608                              <1> 	; VIDEO DATA TRANSFER FUNCTIONS:
  2609                              <1> 	;
  2610                              <1> 	; Inputs:
  2611                              <1> 	;	BH = 0 = VIDEO BIOS Mode 3, tty/text mode data transfers
  2612                              <1> 	;	     BL = 
  2613                              <1> 	;		Bits 0&1, Transfer direction
  2614                              <1> 	;	     	 	0 - System to system
  2615                              <1> 	;			1 - User to system
  2616                              <1> 	;			2 - System to user
  2617                              <1> 	;			3 - User to user
  2618                              <1> 	;		Bits 2&3, Transfer Type
  2619                              <1> 	;			0 - Display page transfer	
  2620                              <1> 	;	     		1 - Display page window transfer
  2621                              <1> 	;	     		2 - Frame/Viewport/Window address transfer
  2622                              <1> 	;			3 - Window handle transfer		
  2623                              <1> 	;
  2624                              <1> 	;	     /// BL = 0 -> System to system (display page) transfer
  2625                              <1> 	;		 CL = Source page 
  2626                              <1> 	;		 DL = Destination page
  2627                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2628                              <1> 	;		 ECX = User buffer
  2629                              <1> 	;		 DL = Video page
  2630                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2631                              <1> 	;		(window in current display page and in current mode)	 	 		
  2632                              <1> 	;		 ESI = User's buffer address
  2633                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2634                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2635                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2636                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2637                              <1>         ;                If BL = 5 ->
  2638                              <1> 	;		 EDI = Swap address (in user's memory space)
  2639                              <1> 	;		 (If swap address > 0, previous content of the window
  2640                              <1> 	;		 will be saved into swap area in user's memory space)		
  2641                              <1> 	;	     /// BL = 4 -> system to system transfer 
  2642                              <1> 	;		 ESI = System's source buffer (video page) address
  2643                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2644                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2645                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2646                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2647                              <1> 	;		 EDI = System's destination buffer (video page) address
  2648                              <1> 	;
  2649                              <1> 	;	BH = 1 = CGA Graphics (0B8000h) data transfers
  2650                              <1> 	;	     BL = 
  2651                              <1> 	;	     	0 = Fill color (color in CL] (32K)
  2652                              <1> 	;		1 = User to system display page transfer
  2653                              <1> 	;		2 = System to user display page transfer
  2654                              <1> 	;		3 = NOT bits in window (ECX, EDX)
  2655                              <1> 	;		4 = Window copy (system to system)	
  2656                              <1> 	;	     	5 = User to system window transfer
  2657                              <1> 	;	     	6 = System to user window transfer
  2658                              <1> 	;		7 = AND display page bytes with CL
  2659                              <1> 	;		8 = OR display page bytes with CL
  2660                              <1> 	;		9 = XOR display page bytes with CL
  2661                              <1> 	;
  2662                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2663                              <1> 	;		 CL = Color value 
  2664                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2665                              <1> 	;		 ECX = User buffer
  2666                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2667                              <1> 	;		(window in current display page and in current mode)	 	 		
  2668                              <1> 	;		 ESI = User's buffer address
  2669                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2670                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2671                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2672                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2673                              <1>         ;	     /// BL = 4 -> system to system (window) transfer 
  2674                              <1> 	;		 ESI = System's source buffer (video page) address
  2675                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2676                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2677                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2678                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2679                              <1> 	;		 EDI = System's destination buffer (video page) address
  2680                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2681                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2682                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2683                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2684                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2685                              <1> 	;
  2686                              <1> 	;	BH = 2 = VGA Graphics (0A0000h) data transfers
  2687                              <1> 	;	     BL = 
  2688                              <1> 	;	     	x0h = Fill color (color in CL] (64K)
  2689                              <1> 	;		x1h = User to system display page transfer
  2690                              <1> 	;		x2h = System to user display page transfer
  2691                              <1> 	;		x3h = NOT bits in window (ECX, EDX)
  2692                              <1> 	;		x4h = Window copy (system to system)	
  2693                              <1> 	;	     	x5h = User to system window transfer
  2694                              <1> 	;	     	x6h = System to user window transfer
  2695                              <1> 	;		x7h = AND display page bytes with CL
  2696                              <1> 	;		x8h = OR display page bytes with CL
  2697                              <1> 	;		x9h = XOR display page bytes with CL
  2698                              <1> 	;		x = 0 -> screen width = 320
  2699                              <1> 	;		x = 1 -> screen width = 640
  2700                              <1> 	;		x = 2 -> screen width = 800
  2701                              <1> 	;
  2702                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2703                              <1> 	;		 CL = Color value 
  2704                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2705                              <1> 	;		 ECX = User buffer
  2706                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2707                              <1> 	;		(window in current display page and in current mode)	 	 		
  2708                              <1> 	;		 ESI = User's buffer address
  2709                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2710                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2711                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2712                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2713                              <1>        	;	     /// BL = 4 -> system to system (window) transfer 
  2714                              <1> 	;		 ESI = System's source buffer (video page) address
  2715                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2716                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2717                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2718                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2719                              <1> 	;		 EDI = System's destination buffer (video page) address
  2720                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2721                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2722                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2723                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2724                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2725                              <1> 	;
  2726                              <1> 	;	BH = 3 = Super VGA, LINEAR FRAME BUFFER data transfers
  2727                              <1> 	;	     BL = 
  2728                              <1> 	;	     	0 = Fill color (color in ECX] (Frame buffer size)
  2729                              <1> 	;		1 = User to system display page transfer
  2730                              <1> 	;		2 = System to user display page transfer
  2731                              <1> 	;		3 = NOT bits in window (ECX, EDX)
  2732                              <1> 	;		4 = Window copy (system to system)	
  2733                              <1> 	;	     	5 = User to system window transfer
  2734                              <1> 	;	     	6 = System to user window transfer
  2735                              <1> 	;		7 = AND display page bytes with ECX
  2736                              <1> 	;		8 = OR display page bytes with ECX
  2737                              <1> 	;		9 = XOR display page bytes with ECX
  2738                              <1> 	;
  2739                              <1> 	;	     /// BL = 0 -> Fill color  (all screen pixels)
  2740                              <1> 	;		 CL = Color value 
  2741                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  2742                              <1> 	;		 ECX = User buffer
  2743                              <1> 	;	     /// BL = 5&6 -> user to system, system to user transfer 
  2744                              <1> 	;		(window in current display page and in current mode)	 	 		
  2745                              <1> 	;		 ESI = User's buffer address
  2746                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2747                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2748                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2749                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2750                              <1> 	;	     /// BL = 4 -> system to system (window) transfer 
  2751                              <1> 	;		 ESI = System's source buffer (video page) address
  2752                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2753                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2754                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2755                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2756                              <1> 	;		 EDI = System's destination buffer (video page) address
  2757                              <1> 	;	     /// BL = 3 -> NOT byte in display page/memory 
  2758                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  2759                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  2760                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  2761                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  2762                              <1> 	;
  2763                              <1> 	; Outputs:
  2764                              <1> 	;	EAX = transfer/byte count
  2765                              <1> 	;
  2766                              <1> 	;	NOTE: If the source or destination address passes out of
  2767                              <1> 	;	video pages (display memory limits), data will not be transferred
  2768                              <1> 	;	and EAX will return as 0.
  2769                              <1> 	;
  2770                              <1> 	;
  2771                              <1> 	; DIRECT (STANDARD VGA/CGA) DISPLAY MEMORY ACCESS FUNCTIONS:
  2772                              <1> 	;
  2773                              <1> 	;	BH = 4 = CGA direct video memory (0B8000h, 32K) access
  2774                              <1> 	;		Page directory & page tables of the user's
  2775                              <1> 	;		program will be updated to direct access to
  2776                              <1> 	;		0B8000h (32K) video (CGA, color) memory; if
  2777                              <1> 	;		there is not a permission  conflict or lock!  
  2778                              <1> 	;	        (User's program/process will have permision to
  2779                              <1> 	;		access locked display memory if the owner is
  2780                              <1> 	;		it's parent.)
  2781                              <1>         ;
  2782                              <1> 	;	    Screen width = 320	
  2783                              <1> 	;
  2784                              <1> 	;	BH = 5 = VGA direct video memory (0A0000h, 64K) access
  2785                              <1> 	;		Page directory & page tables of the user's
  2786                              <1> 	;		program will be updated to direct access to
  2787                              <1> 	;		0A0000h (64K) video (VGA) memory; if there is not
  2788                              <1> 	;		a permission conflict or lock!  
  2789                              <1> 	;	        (User's program/process will have permision to
  2790                              <1> 	;		access locked display memory if the owner is
  2791                              <1> 	;		it's parent.)
  2792                              <1> 	;		
  2793                              <1> 	;	    BL = Screen width (320, 640, 800) 
  2794                              <1> 	;			
  2795                              <1> 	; Outputs:
  2796                              <1> 	;	EAX = Display mmory address for direct access
  2797                              <1> 	;	      0A0000h for VGA, 0B8000h for CGA	
  2798                              <1> 	;	(Display memory size: 32K for CGA, 64K for VGA)
  2799                              <1> 	; 	EAX = 0 if display page access permission has been denied. 
  2800                              <1> 	;	      (Locked!) 	
  2801                              <1> 	;	      	 	
  2802                              <1> 	; LINEAR FRAME BUFFER ACCESS FUNCTIONS:
  2803                              <1> 	;
  2804                              <1> 	;	BH = 6 = Linear Frame Buffer direct video memory access
  2805                              <1> 	;
  2806                              <1> 	;		Page directory & page tables of the user's
  2807                              <1> 	;		program will be updated to direct access to
  2808                              <1> 	;		the configured LFB (Linear Frame Buffer) address,
  2809                              <1> 	;		if there is not a permission conflict or lock!  
  2810                              <1> 	;	        (User's program/process will have permision to
  2811                              <1> 	;		access locked display memory if the owner is
  2812                              <1> 	;		it's parent.)
  2813                              <1> 	;			
  2814                              <1> 	;		Return: EAX = Linear Frame Buffer address
  2815                              <1> 	;			EDX = Frame Buffer Size in bytes	
  2816                              <1> 	;	
  2817                              <1> 	;	BH = 7 = Get Linear Frame Buffer info (for current mode)
  2818                              <1> 	;		
  2819                              <1> 	;		Return:
  2820                              <1> 	;		EAX = Frame Buffer Address (0 = is not in use)
  2821                              <1> 	;		EDX = Frame Buffer Size in bytes
  2822                              <1> 	;		BL = Current Video Mode
  2823                              <1> 	;		     BL = 0FFh -> Super VGA (Extended VGA)
  2824                              <1> 	;		     If BL = 0FFh, 
  2825                              <1>         ;                       BH = 0 = 16 colors
  2826                              <1> 	;			BH = 1 = 256 colors
  2827                              <1> 	;			BH = 2 = 66536 colors
  2828                              <1> 	;			BH = 3 = 24 bits TRUE (16M) colors
  2829                              <1> 	;			BH = 4 = 32 bits TRUE (16M) colors
  2830                              <1> 	;		ECX = Pixel resolution
  2831                              <1> 	;		      CX = Width (640, 800, 1024, 1366, 1920)
  2832                              <1> 	;		      High 16 bits of ECX = Height  
  2833                              <1> 	;
  2834                              <1> 	;	NOTE: Each process will have it's own frame buffer
  2835                              <1> 	;	      address and resolution parameters in 'u' area.
  2836                              <1> 	;	      Then, if the current frame buffer & resolution
  2837                              <1> 	;	      is different, frame buffer r/w functions
  2838                              <1> 	;	      will use scale factor to convert process's
  2839                              <1>         ;             pixel coordinates to actual screen coordinates.                            
  2840                              <1> 	;	      resolution -> dimensional scale
  2841                              <1> 	;	      color size -> color scale
  2842                              <1> 	;	     * RGB (TRUE) colors to 256 colors conversion:	
  2843                              <1>         ;             TRUE Colors -> 8,8,8 (R,G,B; byte 0 is R)            
  2844                              <1> 	;	      256 colors -> 2,2,2,2 (R,G,B,L; bit 0&1 is R)
  2845                              <1> 	; 		  bit 6&7 -> luminosity base level (0,1,2,3)
  2846                              <1> 	;		  bit 4&5 -> blue level (0,1,2,3)
  2847                              <1> 	;		  bit 2%3 -> green level (0,1,2,3)
  2848                              <1> 	;		  bit 0&1 -> red level (0,1,2,3)
  2849                              <1> 	;	      Example: total red level : luminosity + red level   				
  2850                              <1> 	;	      Luminosity base level: 0 -> 16
  2851                              <1> 	;		 		     1 -> 32
  2852                              <1> 	;				     2 -> 64
  2853                              <1> 	;				     3 -> 128
  2854                              <1> 	;	      Color level:	
  2855                              <1> 	;				    0 -> 0
  2856                              <1> 	;				    1 -> luminosity level
  2857                              <1> 	;				    2 -> luminosity level + 64
  2858                              <1> 	;				    3 -> 255
  2859                              <1> 	;	     Luminosity base level = min (R,G,B)
  2860                              <1> 	;			if it is <16, it will be set to 16
  2861                              <1> 	;	     Color levels: Color values are fixed to (nearest) 
  2862                              <1> 	;		   one of all possible set level (step) values
  2863                              <1> 	;		   (according to luminosity base level); then
  2864                              <1> 	;		   color levels are set to R-L, G-L, B-L.
  2865                              <1> 	;	 For example: If luminosity base level is 32
  2866                              <1> 	;		  all possible set values are 0, 32, 96, 255. 	 			
  2867                              <1> 	;
  2868                              <1> 	;	    * RGB (TRUE) colors to 16 colors conversion:
  2869                              <1> 	;	    16 colors: R, B,G, L bits (4 bits)
  2870                              <1> 	;	    	   If any one of R,G,B >= 128 L = 1 		     	
  2871                              <1>  	;		   If max. value of (R,G,B) >= 32, it is 1
  2872                              <1> 	;		      else all color bits (R&G&B&L) are 0
  2873                              <1> 	;		   If the second value >= max. value / 2
  2874                              <1> 	;		      it is 1
  2875                              <1> 	;		   If third value value >= max. value / 2
  2876                              <1> 	;		      it is 1
  2877                              <1> 	;	    Example: R = 132, G = 64, B = 78
  2878                              <1> 	;		     L = 1, R = 1
  2879                              <1> 	;		     G < 66 --> G = 0
  2880                              <1> 	;		     B >= 66 --> B = 1	 		 	  								 	 					
  2881                              <1> 
  2882                              <1> 	; 16/05/2016
  2883 0000D12F 31C0                <1> 	xor	eax, eax
  2884 0000D131 A3[64030300]        <1> 	mov	[u.r0], eax
  2885                              <1> 
  2886 0000D136 20FF                <1> 	and	bh, bh
  2887 0000D138 0F8572020000        <1> 	jnz	sysvideo_13 ; 11/07/2016
  2888                              <1> 	
  2889                              <1> 	; Video mode 0, 80*25 text mode, CGA 16 colors  ; [CRT_MODE] = 3
  2890 0000D13E 88DF                <1> 	mov	bh, bl
  2891 0000D140 C0EF02              <1> 	shr	bh, 2
  2892 0000D143 20FF                <1> 	and	bh, bh
  2893 0000D145 0F8598000000        <1>         jnz     sysvideo_4
  2894 0000D14B BF00800B00          <1> 	mov	edi, 0B8000h
  2895 0000D150 20D2                <1> 	and	dl, dl
  2896 0000D152 7413                <1> 	jz	short sysvideo_1
  2897 0000D154 80FA07              <1> 	cmp	dl, 7
  2898 0000D157 0F87DCF5FFFF        <1> 	ja	sysret
  2899                              <1> sysvideo_0:
  2900 0000D15D 81C7A00F0000        <1> 	add	edi, 80*25*2
  2901 0000D163 FECA                <1> 	dec	dl
  2902 0000D165 75F6                <1> 	jnz	short sysvideo_0	
  2903                              <1> sysvideo_1:	
  2904 0000D167 80E303              <1> 	and	bl, 3
  2905 0000D16A 7530                <1> 	jnz	short sysvideo_2
  2906 0000D16C 80F907              <1> 	cmp	cl, 7
  2907 0000D16F 0F87C4F5FFFF        <1> 	ja	sysret
  2908                              <1> 	; system to system video/display page transfer (mode 0)
  2909 0000D175 BE00800B00          <1> 	mov	esi, 0B8000h
  2910 0000D17A 0FB6C1              <1> 	movzx	eax, cl
  2911 0000D17D BAA00F0000          <1> 	mov	edx, 80*25*2
  2912 0000D182 F7E2                <1> 	mul	edx
  2913 0000D184 01C6                <1> 	add	esi, eax
  2914 0000D186 B9A00F0000          <1> 	mov	ecx, (80*25*2)
  2915 0000D18B 890D[64030300]      <1> 	mov	[u.r0], ecx
  2916 0000D191 66C1E902            <1> 	shr	cx, 2 ; /4
  2917 0000D195 F3A5                <1> 	rep	movsd
  2918 0000D197 E99DF5FFFF          <1> 	jmp	sysret	
  2919                              <1> sysvideo_2:  
  2920 0000D19C 80FB02              <1> 	cmp	bl, 2
  2921 0000D19F 0F8794F5FFFF        <1>         ja      sysret
  2922 0000D1A5 721F                <1> 	jb	short sysvideo_3
  2923                              <1> 	; system to user video/display page transfer (mode 0)
  2924 0000D1A7 89FE                <1> 	mov	esi, edi
  2925 0000D1A9 89CF                <1> 	mov	edi, ecx ; user buffer
  2926 0000D1AB B9A00F0000          <1> 	mov	ecx, 80*25*2
  2927 0000D1B0 E81F160000          <1> 	call	transfer_to_user_buffer ; fast transfer
  2928 0000D1B5 0F827EF5FFFF        <1> 	jc	sysret
  2929 0000D1BB 890D[64030300]      <1> 	mov	[u.r0], ecx
  2930 0000D1C1 E973F5FFFF          <1> 	jmp	sysret 	
  2931                              <1> sysvideo_3: 
  2932                              <1> 	; user to system video/display page transfer (mode 0)	
  2933 0000D1C6 89CE                <1> 	mov	esi, ecx ; user buffer
  2934                              <1> 	; edi = video page address
  2935 0000D1C8 B9A00F0000          <1> 	mov	ecx, 80*25*2
  2936 0000D1CD E84C160000          <1> 	call	transfer_from_user_buffer ; fast transfer
  2937 0000D1D2 0F8261F5FFFF        <1> 	jc	sysret
  2938 0000D1D8 890D[64030300]      <1> 	mov	[u.r0], ecx		
  2939 0000D1DE E956F5FFFF          <1> 	jmp	sysret
  2940                              <1> sysvideo_4:
  2941 0000D1E3 80E303              <1> 	and	bl, 3
  2942 0000D1E6 0F85F6000000        <1>         jnz     sysvideo_9
  2943 0000D1EC 80F907              <1> 	cmp	cl, 7
  2944 0000D1EF 0F8744F5FFFF        <1> 	ja	sysret
  2945                              <1> 	; system to system video/display page window transfer (mode 0)
  2946 0000D1F5 81FE00800B00        <1> 	cmp	esi, 0B8000h
  2947 0000D1FB 0F8238F5FFFF        <1> 	jb	sysret
  2948 0000D201 81FE00FD0B00        <1> 	cmp	esi, 0B8000h+(80*25*2*8)
  2949 0000D207 0F832CF5FFFF        <1> 	jnb	sysret
  2950 0000D20D 81FF00800B00        <1> 	cmp	edi, 0B8000h
  2951 0000D213 0F8220F5FFFF        <1> 	jb	sysret
  2952 0000D219 81FF00FD0B00        <1>         cmp     edi, 0B8000h+(80*25*2*8)
  2953 0000D21F 0F8314F5FFFF        <1> 	jnb	sysret
  2954                              <1> 	;
  2955 0000D225 51                  <1> 	push	ecx
  2956 0000D226 52                  <1> 	push	edx
  2957 0000D227 0FB7C1              <1> 	movzx	eax, cx ; top left column
  2958 0000D22A 50                  <1> 	push	eax
  2959 0000D22B C1E910              <1> 	shr	ecx, 16 ; top row
  2960 0000D22E 66B8A000            <1> 	mov	ax, 80*2 ; 80 colums, 160 bytes per row
  2961 0000D232 F7E1                <1> 	mul	ecx
  2962 0000D234 01C6                <1> 	add	esi, eax
  2963 0000D236 01C7                <1> 	add	edi, eax
  2964 0000D238 58                  <1> 	pop	eax
  2965 0000D239 66D1E0              <1> 	shl	ax, 1 ; *2 	
  2966 0000D23C 01C6                <1> 	add	esi, eax
  2967 0000D23E 01C7                <1> 	add	edi, eax
  2968 0000D240 5A                  <1> 	pop	edx
  2969 0000D241 59                  <1> 	pop	ecx
  2970 0000D242 B800FD0B00          <1> 	mov	eax, 0B8000h+(80*25*2*8)
  2971 0000D247 39C6                <1> 	cmp	esi, eax
  2972 0000D249 0F83EAF4FFFF        <1> 	jnb	sysret
  2973 0000D24F 39C6                <1> 	cmp	esi, eax
  2974 0000D251 0F83E2F4FFFF        <1> 	jnb	sysret	
  2975                              <1> 
  2976 0000D257 56                  <1> 	push	esi ; ****
  2977 0000D258 57                  <1> 	push	edi ; ***
  2978 0000D259 52                  <1> 	push	edx ; **
  2979 0000D25A 51                  <1> 	push	ecx ; *
  2980 0000D25B C1E910              <1> 	shr	ecx, 16 ; top row
  2981 0000D25E C1EA10              <1> 	shr	edx, 16 ; bottom row
  2982 0000D261 83F918              <1> 	cmp	ecx, 24 ; max. 25 rows
  2983 0000D264 7773                <1> 	ja	short sysvideo_6
  2984 0000D266 83FA18              <1> 	cmp	edx, 24 ; max. 25 rows
  2985 0000D269 776E                <1> 	ja	short sysvideo_6		
  2986 0000D26B 28CA                <1> 	sub	dl, cl
  2987 0000D26D 726A                <1> 	jc	short sysvideo_6
  2988 0000D26F 50                  <1> 	push	eax ; *****
  2989 0000D270 89D3                <1> 	mov	ebx, edx ; row count - 1
  2990 0000D272 B8A0000000          <1> 	mov	eax, 80*2
  2991 0000D277 F7E0                <1> 	mul	eax
  2992 0000D279 01C6                <1> 	add	esi, eax
  2993 0000D27B 01C7                <1> 	add	edi, eax
  2994 0000D27D 58                  <1> 	pop	eax ; *****
  2995 0000D27E 39C6                <1> 	cmp	esi, eax
  2996 0000D280 7757                <1> 	ja	short sysvideo_6
  2997 0000D282 39C7                <1> 	cmp	edi, eax
  2998 0000D284 7753                <1> 	ja	short sysvideo_6
  2999 0000D286 59                  <1> 	pop	ecx ; *
  3000 0000D287 5A                  <1> 	pop	edx ; **
  3001 0000D288 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  3002 0000D28E 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  3003 0000D294 83F94F              <1> 	cmp	ecx, 79 ; max. 80 columns
  3004 0000D297 7742                <1> 	ja	short sysvideo_7
  3005 0000D299 83FA4F              <1> 	cmp	edx, 79 ; max. 80 columns
  3006 0000D29C 773D                <1> 	ja	short sysvideo_7
  3007 0000D29E 28CA                <1> 	sub	dl, cl
  3008 0000D2A0 7639                <1> 	jna	short sysvideo_7
  3009                              <1> 	; edx = column count (width) - 1
  3010 0000D2A2 D0E2                <1> 	shl	dl, 1
  3011 0000D2A4 01D6                <1> 	add	esi, edx
  3012 0000D2A6 01D7                <1> 	add	edi, edx
  3013 0000D2A8 39C6                <1> 	cmp	esi, eax
  3014 0000D2AA 772F                <1> 	ja	short sysvideo_7
  3015 0000D2AC 39C7                <1> 	cmp	edi, eax
  3016 0000D2AE 772B                <1> 	ja	short sysvideo_7
  3017 0000D2B0 5F                  <1> 	pop	edi ; ***
  3018 0000D2B1 5E                  <1> 	pop	esi ; ****
  3019 0000D2B2 FEC3                <1> 	inc	bl
  3020 0000D2B4 FEC2                <1> 	inc	dl ; column count
  3021 0000D2B6 88D7                <1> 	mov	bh, dl
  3022 0000D2B8 D0E2                <1> 	shl	dl, 1
  3023 0000D2BA B8A0000000          <1> 	mov	eax, 80*2
  3024 0000D2BF 28D0                <1> 	sub	al, dl ; (80 - columns) * 2
  3025                              <1> sysvideo_5:	
  3026 0000D2C1 88F9                <1> 	mov	cl, bh
  3027 0000D2C3 0115[64030300]      <1> 	add	[u.r0], edx
  3028 0000D2C9 F366A5              <1> 	rep	movsw
  3029 0000D2CC 01C6                <1> 	add	esi, eax ; next row
  3030 0000D2CE 01C7                <1> 	add	edi, eax ; next row
  3031 0000D2D0 FECB                <1> 	dec	bl
  3032 0000D2D2 75ED                <1> 	jnz	short sysvideo_5
  3033 0000D2D4 E960F4FFFF          <1> 	jmp	sysret
  3034                              <1> 
  3035                              <1> sysvideo_6:
  3036 0000D2D9 59                  <1> 	pop	ecx ; *
  3037 0000D2DA 5A                  <1> 	pop	edx ; **
  3038                              <1> sysvideo_7:	
  3039 0000D2DB 5F                  <1> 	pop	edi ; ***
  3040 0000D2DC 5E                  <1> 	pop	esi ; ****
  3041 0000D2DD E957F4FFFF          <1> 	jmp	sysret
  3042                              <1> 
  3043                              <1> sysvideo_9:  
  3044 0000D2E2 80FB02              <1> 	cmp	bl, 2
  3045 0000D2E5 0F874EF4FFFF        <1>         ja      sysret
  3046                              <1> 
  3047 0000D2EB 56                  <1> 	push	esi ; ****
  3048 0000D2EC 57                  <1> 	push	edi ; ***
  3049 0000D2ED 52                  <1> 	push	edx ; **
  3050 0000D2EE 51                  <1> 	push	ecx ; *
  3051                              <1> 
  3052 0000D2EF C1E910              <1> 	shr	ecx, 16 ; top row
  3053 0000D2F2 C1EA10              <1> 	shr	edx, 16 ; bottom row
  3054 0000D2F5 83F918              <1> 	cmp	ecx, 24 ; max. 25 rows
  3055 0000D2F8 77DF                <1> 	ja	short sysvideo_6
  3056 0000D2FA 83FA18              <1> 	cmp	edx, 24 ; max. 25 rows
  3057 0000D2FD 77DA                <1> 	ja	short sysvideo_6		
  3058 0000D2FF 28CA                <1> 	sub	dl, cl
  3059 0000D301 72D6                <1> 	jc	short sysvideo_6
  3060                              <1> 
  3061 0000D303 88CD                <1> 	mov	ch, cl ; top row
  3062 0000D305 8A0D[D6580100]      <1> 	mov	cl, [ACTIVE_PAGE]
  3063 0000D30B BFA00F0000          <1> 	mov	edi, 80*25*2
  3064 0000D310 D3E7                <1> 	shl	edi, cl 
  3065 0000D312 81C760700B00        <1> 	add	edi, 0B8000h - 80*25*2
  3066                              <1> 
  3067 0000D318 88D7                <1> 	mov	bh, dl ; row count - 1
  3068 0000D31A 88EA                <1> 	mov	dl, ch ; top row
  3069 0000D31C B8A0000000          <1> 	mov	eax, 80*2
  3070 0000D321 F7E2                <1> 	mul	edx
  3071 0000D323 01C7                <1> 	add	edi, eax
  3072                              <1> 
  3073 0000D325 59                  <1> 	pop	ecx ; *
  3074 0000D326 5A                  <1> 	pop	edx ; **
  3075 0000D327 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  3076 0000D32D 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  3077 0000D333 83F94F              <1> 	cmp	ecx, 79 ; max. 80 columns
  3078 0000D336 77A3                <1> 	ja	short sysvideo_7
  3079 0000D338 83FA4F              <1> 	cmp	edx, 79 ; max. 80 columns
  3080 0000D33B 779E                <1> 	ja	short sysvideo_7
  3081                              <1> 	
  3082 0000D33D 28CA                <1> 	sub	dl, cl
  3083 0000D33F 769A                <1> 	jna	short sysvideo_7
  3084                              <1> 	
  3085 0000D341 0FB6C1              <1> 	movzx	eax, cl ; left column
  3086 0000D344 D0E0                <1> 	shl	al, 1  ; column * 2
  3087 0000D346 01C7                <1> 	add	edi, eax
  3088                              <1> 
  3089 0000D348 FEC2                <1> 	inc	dl ; column count
  3090 0000D34A D0E2                <1> 	shl	dl, 1
  3091 0000D34C 88D1                <1> 	mov	cl, dl ; column count * 2
  3092 0000D34E B2A0                <1> 	mov	dl, 80*2
  3093 0000D350 58                  <1> 	pop	eax ; *** (swap address)
  3094 0000D351 5E                  <1> 	pop	esi ; ****
  3095 0000D352 FEC7                <1> 	inc	bh
  3096                              <1> 	
  3097                              <1> 	;mov	edx, 80*2
  3098 0000D354 B2A0                <1> 	mov	dl, 80*2
  3099                              <1> 	;
  3100 0000D356 80FB01              <1> 	cmp	bl, 1
  3101 0000D359 7735                <1> 	ja	short sysvideo_11
  3102                              <1> 
  3103                              <1> 	; user to system video/display page window transfer (mode 0)	
  3104 0000D35B 21C0                <1> 	and	eax, eax ; swap address
  3105 0000D35D 7413                <1> 	jz	short sysvideo_10 ; no window swap
  3106                              <1> 	; save previous window content in user's buffer (swap address)
  3107 0000D35F 56                  <1> 	push	esi ; user buffer
  3108 0000D360 57                  <1> 	push	edi ; beginning address of the window
  3109 0000D361 89FE                <1> 	mov	esi, edi
  3110 0000D363 89C7                <1> 	mov	edi, eax
  3111 0000D365 E86A140000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3112 0000D36A 5F                  <1> 	pop	edi
  3113 0000D36B 5E                  <1> 	pop	esi
  3114 0000D36C 0F82C7F3FFFF        <1> 	jc	sysret
  3115                              <1> sysvideo_10: 
  3116                              <1> 	; user to system video/display page window transfer (mode 0)	
  3117                              <1> 	; esi =	user buffer
  3118 0000D372 E8A7140000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3119 0000D377 0F82BCF3FFFF        <1> 	jc	sysret
  3120 0000D37D 010D[64030300]      <1> 	add	[u.r0], ecx
  3121 0000D383 01D7                <1> 	add	edi, edx ; next row
  3122 0000D385 01CE                <1> 	add	esi, ecx
  3123 0000D387 FECF                <1> 	dec	bh
  3124 0000D389 75E7                <1> 	jnz	short sysvideo_10
  3125 0000D38B E9A9F3FFFF          <1> 	jmp	sysret
  3126                              <1> 	
  3127                              <1> sysvideo_11:
  3128                              <1> 	; system to user video/display page window transfer (mode 0)
  3129 0000D390 87FE                <1> 	xchg	edi, esi
  3130                              <1> sysvideo_12:
  3131                              <1> 	; esi = beginning address of the window
  3132                              <1> 	; edi =	user buffer	
  3133 0000D392 E83D140000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3134 0000D397 0F829CF3FFFF        <1> 	jc	sysret
  3135 0000D39D 010D[64030300]      <1> 	add	[u.r0], ecx
  3136 0000D3A3 01D6                <1> 	add	esi, edx ; next row
  3137 0000D3A5 01CF                <1> 	add	edi, ecx
  3138 0000D3A7 FECF                <1> 	dec	bh
  3139 0000D3A9 75E7                <1> 	jnz	short sysvideo_12
  3140 0000D3AB E989F3FFFF          <1> 	jmp	sysret
  3141                              <1> 
  3142                              <1> sysvideo_13:
  3143 0000D3B0 80FF01              <1> 	cmp	bh, 1
  3144 0000D3B3 0F871F030000        <1>         ja      sysvideo_38
  3145                              <1> 	; BH = 1 = CGA Graphics (0B8000h) data transfers
  3146                              <1> 
  3147 0000D3B9 20DB                <1> 	and	bl, bl
  3148 0000D3BB 751A                <1> 	jnz	short sysvideo_14
  3149                              <1> 
  3150                              <1> 	; BL =	0 = Fill color (color in CL] (32K)
  3151                              <1> 
  3152 0000D3BD 88C8                <1> 	mov	al, cl
  3153 0000D3BF B900800000          <1> 	mov	ecx, 32768
  3154 0000D3C4 66890D[64030300]    <1> 	mov	[u.r0], cx
  3155 0000D3CB BF00800B00          <1> 	mov	edi, 0B8000h
  3156 0000D3D0 F3AB                <1> 	rep	stosd
  3157 0000D3D2 E962F3FFFF          <1> 	jmp	sysret
  3158                              <1> 
  3159                              <1> sysvideo_14:
  3160 0000D3D7 80FB01              <1> 	cmp	bl, 1
  3161 0000D3DA 7723                <1> 	ja	short sysvideo_16
  3162                              <1> 
  3163 0000D3DC 89CE                <1> 	mov	esi, ecx ; user buffer
  3164                              <1> 	; BL = 1 = user to system video/display page transfer
  3165                              <1> sysvideo_15:	
  3166 0000D3DE BF00800B00          <1> 	mov	edi, 0B8000h
  3167                              <1> 	; edi = video page address
  3168 0000D3E3 B900800000          <1> 	mov	ecx, 32768
  3169 0000D3E8 E831140000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3170 0000D3ED 0F8246F3FFFF        <1> 	jc	sysret ; [u.r0] = 0
  3171 0000D3F3 66890D[64030300]    <1> 	mov	[u.r0], cx		
  3172 0000D3FA E93AF3FFFF          <1> 	jmp	sysret
  3173                              <1> 
  3174                              <1> sysvideo_16:
  3175 0000D3FF 80FB02              <1> 	cmp	bl, 2	
  3176 0000D402 7723                <1> 	ja	short sysvideo_18
  3177                              <1> 
  3178 0000D404 89CF                <1> 	mov	edi, ecx ; user buffer
  3179                              <1> 	; BL = 2 = system to user video/display page transfer
  3180                              <1> sysvideo_17:	
  3181 0000D406 BE00800B00          <1> 	mov	esi, 0B8000h
  3182 0000D40B B900800000          <1> 	mov	ecx, 32768
  3183 0000D410 E8BF130000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3184 0000D415 0F821EF3FFFF        <1> 	jc	sysret ; [u.r0] = 0
  3185 0000D41B 66890D[64030300]    <1> 	mov	[u.r0], cx
  3186 0000D422 E912F3FFFF          <1> 	jmp	sysret 	
  3187                              <1> 
  3188                              <1> sysvideo_18:
  3189 0000D427 80FB03              <1> 	cmp	bl, 3
  3190 0000D42A 777E                <1> 	ja	short sysvideo_23
  3191                              <1> 
  3192                              <1> 	; BL = 3 = NOT bits in window (ECX, EDX)
  3193                              <1> 
  3194 0000D42C BF00800B00          <1> 	mov	edi, 0B8000h
  3195 0000D431 89FE                <1> 	mov	esi, edi
  3196                              <1> 	
  3197 0000D433 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3198 0000D435 7716                <1> 	ja	short sysvideo_20 ; window
  3199                              <1> 	; full screen (update)
  3200 0000D437 B900800000          <1> 	mov	ecx, 32768
  3201 0000D43C 66890D[64030300]    <1> 	mov	[u.r0], cx
  3202                              <1> sysvideo_19:
  3203 0000D443 F616                <1> 	not	byte [esi] ; NOT operation
  3204 0000D445 46                  <1> 	inc	esi
  3205 0000D446 E2FB                <1> 	loop	sysvideo_19
  3206 0000D448 E9ECF2FFFF          <1> 	jmp	sysret
  3207                              <1> sysvideo_20:
  3208 0000D44D 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3209 0000D450 6629C8              <1> 	sub	ax, cx  ; - top left column
  3210 0000D453 0F82E0F2FFFF        <1>         jb      sysret ; invalid
  3211 0000D459 6640                <1> 	inc	ax ; same column no == 1 column	 
  3212 0000D45B 50                  <1> 	push	eax ; byte count per window row
  3213 0000D45C 52                  <1> 	push	edx
  3214 0000D45D BB40010000          <1> 	mov	ebx, 320 ; screen width
  3215 0000D462 89C8                <1> 	mov	eax, ecx
  3216 0000D464 C1E810              <1> 	shr	eax, 16  ; top row
  3217 0000D467 F7E3                <1> 	mul	ebx
  3218 0000D469 6689CA              <1> 	mov	dx, cx ; top left column
  3219 0000D46C 01D0                <1> 	add	eax, edx
  3220 0000D46E 01C6                <1> 	add	esi, eax ; start address 
  3221 0000D470 59                  <1> 	pop	ecx ; edx
  3222 0000D471 89C8                <1> 	mov	eax, ecx
  3223 0000D473 C1E810              <1> 	shr	eax, 16 ; bottom row
  3224 0000D476 F7E3                <1> 	mul	ebx
  3225 0000D478 6689CA              <1> 	mov	dx, cx ; bottom right column
  3226 0000D47B 01D0                <1> 	add	eax, edx
  3227 0000D47D 01C7                <1> 	add	edi, eax ; stop address (included)
  3228 0000D47F 5A                  <1> 	pop	edx ; byte count per window row
  3229 0000D480 81FFFFFF0B00        <1> 	cmp	edi, 0BFFFFh
  3230 0000D486 0F87ADF2FFFF        <1> 	ja	sysret	
  3231 0000D48C 56                  <1> 	push	esi
  3232 0000D48D 4E                  <1> 	dec	esi
  3233                              <1> sysvideo_21:
  3234 0000D48E 89D1                <1> 	mov	ecx, edx
  3235                              <1> sysvideo_22:
  3236 0000D490 46                  <1> 	inc	esi
  3237 0000D491 F616                <1> 	not	byte [esi]
  3238 0000D493 E2FB                <1> 	loop	sysvideo_22
  3239 0000D495 01DE                <1> 	add	esi, ebx ; bytes per screen row
  3240                              <1> 	;
  3241 0000D497 39FE                <1> 	cmp	esi, edi ; stop address (included in loop)
  3242 0000D499 76F3                <1> 	jna	short sysvideo_21
  3243 0000D49B 5E                  <1> 	pop	esi
  3244 0000D49C 29F7                <1> 	sub	edi, esi
  3245 0000D49E 66893D[64030300]    <1> 	mov	[u.r0], di
  3246 0000D4A5 E98FF2FFFF          <1> 	jmp	sysret
  3247                              <1> 
  3248                              <1> sysvideo_23:
  3249 0000D4AA 80FB04              <1> 	cmp	bl, 4
  3250 0000D4AD 0F87A7000000        <1>         ja      sysvideo_26
  3251                              <1> 
  3252                              <1> 	; BL = 4 = window copy (system to system)
  3253                              <1> 
  3254 0000D4B3 B800800B00          <1> 	mov	eax, 0B8000h
  3255 0000D4B8 39C6                <1> 	cmp	esi, eax
  3256 0000D4BA 0F8279F2FFFF        <1> 	jb	sysret
  3257 0000D4C0 39C7                <1> 	cmp	edi, eax
  3258 0000D4C2 0F8271F2FFFF        <1> 	jb	sysret
  3259 0000D4C8 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  3260 0000D4CC 39C6                <1> 	cmp	esi, eax
  3261 0000D4CE 0F8765F2FFFF        <1> 	ja	sysret
  3262 0000D4D4 39C7                <1> 	cmp	edi, eax
  3263 0000D4D6 0F875DF2FFFF        <1> 	ja	sysret
  3264                              <1> 	
  3265 0000D4DC 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3266 0000D4DE 7714                <1> 	ja	short sysvideo_24 ; window
  3267                              <1> 	; full screen copy
  3268 0000D4E0 89C1                <1> 	mov	ecx, eax
  3269 0000D4E2 29F9                <1> 	sub	ecx, edi
  3270 0000D4E4 6641                <1> 	inc	cx
  3271 0000D4E6 66890D[64030300]    <1> 	mov	[u.r0], cx
  3272 0000D4ED F3A4                <1> 	rep	movsb
  3273 0000D4EF E945F2FFFF          <1> 	jmp	sysret
  3274                              <1> sysvideo_24:
  3275 0000D4F4 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3276 0000D4F7 6629C8              <1> 	sub	ax, cx  ; - top left column
  3277 0000D4FA 0F8239F2FFFF        <1>         jb      sysret ; invalid
  3278 0000D500 6640                <1> 	inc	ax ; same column no == 1 column	 
  3279 0000D502 50                  <1> 	push	eax ; byte count per window row
  3280                              <1> 	;
  3281 0000D503 52                  <1> 	push	edx
  3282 0000D504 BB40010000          <1> 	mov	ebx, 320 ; screen width
  3283 0000D509 89C8                <1> 	mov	eax, ecx
  3284 0000D50B C1E810              <1> 	shr	eax, 16	; top row
  3285 0000D50E F7E3                <1> 	mul	ebx
  3286 0000D510 6689CA              <1> 	mov	dx, cx ; top left column
  3287 0000D513 01D0                <1> 	add	eax, edx
  3288 0000D515 01C7                <1> 	add	edi, eax ; start address 
  3289 0000D517 01C6                <1> 	add	esi, eax
  3290 0000D519 59                  <1> 	pop	ecx ; edx
  3291 0000D51A 89C8                <1> 	mov	eax, ecx
  3292 0000D51C C1E810              <1> 	shr	eax, 16 ; bottom row
  3293 0000D51F F7E3                <1> 	mul	ebx
  3294 0000D521 6689CA              <1> 	mov	dx, cx ; bottom right column
  3295 0000D524 01D0                <1> 	add	eax, edx
  3296 0000D526 5A                  <1> 	pop	edx ; byte count per window row
  3297 0000D527 0500800B00          <1> 	add	eax, 0B8000h
  3298 0000D52C 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  3299 0000D531 0F8702F2FFFF        <1> 	ja	sysret
  3300 0000D537 57                  <1> 	push	edi ; start address 
  3301 0000D538 50                  <1> 	push	eax ; stop address (included)
  3302                              <1> sysvideo_25:
  3303 0000D539 89D1                <1> 	mov	ecx, edx
  3304 0000D53B F3A4                <1> 	rep	movsb
  3305 0000D53D 4F                  <1> 	dec	edi
  3306 0000D53E 4E                  <1> 	dec	esi
  3307 0000D53F 01DF                <1> 	add	edi, ebx ; bytes per screen row
  3308 0000D541 01DE                <1> 	add	esi, ebx
  3309                              <1> 	;
  3310 0000D543 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3311 0000D546 76F1                <1> 	jna	short sysvideo_25
  3312 0000D548 5B                  <1> 	pop	ebx ; stop address
  3313 0000D549 5F                  <1> 	pop	edi ; start address
  3314 0000D54A 29FB                <1> 	sub	ebx, edi
  3315 0000D54C 6643                <1> 	inc	bx
  3316 0000D54E 66891D[64030300]    <1> 	mov	[u.r0], bx	
  3317 0000D555 E9DFF1FFFF          <1> 	jmp	sysret
  3318                              <1> 
  3319                              <1> sysvideo_26:
  3320 0000D55A 80FB05              <1> 	cmp	bl, 5
  3321 0000D55D 0F8795000000        <1>         ja      sysvideo_29
  3322                              <1> 
  3323                              <1> 	; BL = 5 = window copy (user to system)
  3324                              <1> 
  3325 0000D563 B800800B00          <1> 	mov	eax, 0B8000h
  3326 0000D568 39C7                <1> 	cmp	edi, eax
  3327 0000D56A 0F82C9F1FFFF        <1> 	jb	sysret
  3328 0000D570 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  3329 0000D574 39C7                <1> 	cmp	edi, eax
  3330 0000D576 0F87BDF1FFFF        <1> 	ja	sysret
  3331                              <1> 
  3332                              <1> 	; esi = user buffer (in user's memory space)
  3333 0000D57C 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3334 0000D57E 0F865AFEFFFF        <1>         jna     sysvideo_15 ; full screen copy
  3335                              <1> 
  3336 0000D584 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3337 0000D587 6629C8              <1> 	sub	ax, cx  ; - top left column
  3338 0000D58A 0F82A9F1FFFF        <1>         jb      sysret ; invalid
  3339 0000D590 6640                <1> 	inc	ax ; same column no == 1 column	 
  3340 0000D592 50                  <1> 	push	eax ; byte count per window row
  3341                              <1> 
  3342 0000D593 52                  <1> 	push	edx
  3343 0000D594 BB40010000          <1> 	mov	ebx, 320 ; screen width
  3344 0000D599 89C8                <1> 	mov	eax, ecx
  3345 0000D59B C1E810              <1> 	shr	eax, 16	; top row
  3346 0000D59E F7E3                <1> 	mul	ebx
  3347 0000D5A0 6689CA              <1> 	mov	dx, cx ; top left column
  3348 0000D5A3 01D0                <1> 	add	eax, edx
  3349 0000D5A5 01C7                <1> 	add	edi, eax ; start address 
  3350 0000D5A7 59                  <1> 	pop	ecx ; edx
  3351 0000D5A8 89C8                <1> 	mov	eax, ecx
  3352 0000D5AA C1E810              <1> 	shr	eax, 16 ; bottom row
  3353 0000D5AD F7E3                <1> 	mul	ebx
  3354 0000D5AF 6689CA              <1> 	mov	dx, cx ; bottom right column
  3355 0000D5B2 01D0                <1> 	add	eax, edx
  3356 0000D5B4 5A                  <1> 	pop	edx ; byte count per window row
  3357 0000D5B5 0500800B00          <1> 	add	eax, 0B8000h
  3358 0000D5BA 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  3359 0000D5BF 0F8774F1FFFF        <1> 	ja	sysret
  3360 0000D5C5 57                  <1> 	push	edi ; start address 
  3361 0000D5C6 50                  <1> 	push	eax ; stop address (included)
  3362                              <1> sysvideo_27:
  3363 0000D5C7 89D1                <1> 	mov	ecx, edx ; byte count
  3364                              <1> 	; user to system video/display page window transfer
  3365                              <1> 	; esi =	user buffer
  3366 0000D5C9 E850120000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3367 0000D5CE 7221                <1> 	jc	short sysvideo_28
  3368 0000D5D0 010D[64030300]      <1> 	add	[u.r0], ecx
  3369 0000D5D6 01DF                <1> 	add	edi, ebx ; next row
  3370 0000D5D8 01CE                <1> 	add	esi, ecx
  3371 0000D5DA 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3372 0000D5DD 76E8                <1> 	jna	short sysvideo_27
  3373 0000D5DF 5B                  <1> 	pop	ebx ; stop address
  3374 0000D5E0 5F                  <1> 	pop	edi ; start address
  3375 0000D5E1 29FB                <1> 	sub	ebx, edi
  3376 0000D5E3 6643                <1> 	inc	bx
  3377 0000D5E5 66891D[64030300]    <1> 	mov	[u.r0], bx	
  3378 0000D5EC E948F1FFFF          <1> 	jmp	sysret
  3379                              <1> sysvideo_28:
  3380 0000D5F1 58                  <1> 	pop	eax
  3381 0000D5F2 5A                  <1> 	pop	edx
  3382 0000D5F3 E941F1FFFF          <1> 	jmp	sysret
  3383                              <1> 
  3384                              <1> sysvideo_29:
  3385 0000D5F8 80FB06              <1> 	cmp	bl, 6
  3386 0000D5FB 0F8797000000        <1>         ja      sysvideo_32
  3387                              <1> 
  3388                              <1> 	; BL = 6 = window copy (system to user)
  3389                              <1> 
  3390 0000D601 89F7                <1> 	mov	edi, esi ; user buffer
  3391                              <1> 
  3392 0000D603 B800800B00          <1> 	mov	eax, 0B8000h
  3393 0000D608 39C6                <1> 	cmp	esi, eax
  3394 0000D60A 0F8229F1FFFF        <1> 	jb	sysret
  3395 0000D610 6605FF7F            <1> 	add	ax, 7FFFh ; 32767
  3396 0000D614 39C6                <1> 	cmp	esi, eax
  3397 0000D616 0F871DF1FFFF        <1> 	ja	sysret
  3398                              <1> 
  3399                              <1> 	; edi = user buffer (in user's memory space)
  3400 0000D61C 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3401 0000D61E 0F86E2FDFFFF        <1>         jna     sysvideo_17 ; full screen copy
  3402                              <1> 
  3403 0000D624 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3404 0000D627 6629C8              <1> 	sub	ax, cx  ; - top left column
  3405 0000D62A 0F8209F1FFFF        <1>         jb      sysret ; invalid
  3406 0000D630 6640                <1> 	inc	ax ; same column no == 1 column	 
  3407 0000D632 50                  <1> 	push	eax ; byte count per window row
  3408                              <1> 
  3409 0000D633 52                  <1> 	push	edx
  3410 0000D634 BB40010000          <1> 	mov	ebx, 320 ; screen width
  3411 0000D639 89C8                <1> 	mov	eax, ecx
  3412 0000D63B C1E810              <1> 	shr	eax, 16	; top row
  3413 0000D63E F7E3                <1> 	mul	ebx
  3414 0000D640 6689CA              <1> 	mov	dx, cx ; top left column
  3415 0000D643 01D0                <1> 	add	eax, edx
  3416 0000D645 01C6                <1> 	add	esi, eax ; start address 
  3417 0000D647 59                  <1> 	pop	ecx ; edx
  3418 0000D648 89C8                <1> 	mov	eax, ecx
  3419 0000D64A C1E810              <1> 	shr	eax, 16 ; bottom row
  3420 0000D64D F7E3                <1> 	mul	ebx
  3421 0000D64F 6689CA              <1> 	mov	dx, cx ; bottom right column
  3422 0000D652 01D0                <1> 	add	eax, edx
  3423 0000D654 5A                  <1> 	pop	edx ; byte count per window row
  3424 0000D655 0500800B00          <1> 	add	eax, 0B8000h
  3425 0000D65A 3DFFFF0B00          <1> 	cmp	eax, 0BFFFFh
  3426 0000D65F 0F87D4F0FFFF        <1> 	ja	sysret
  3427 0000D665 56                  <1> 	push	esi ; start address 
  3428 0000D666 50                  <1> 	push	eax ; stop address (included)
  3429                              <1> sysvideo_30:
  3430 0000D667 89D1                <1> 	mov	ecx, edx ; byte count
  3431                              <1> 	; user to system video/display page window transfer
  3432                              <1> 	; esi =	user buffer
  3433 0000D669 E866110000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3434 0000D66E 7221                <1> 	jc	short sysvideo_31
  3435 0000D670 010D[64030300]      <1> 	add	[u.r0], ecx
  3436 0000D676 01DF                <1> 	add	edi, ebx ; next row
  3437 0000D678 01CE                <1> 	add	esi, ecx
  3438 0000D67A 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3439 0000D67D 76E8                <1> 	jna	short sysvideo_30
  3440 0000D67F 5B                  <1> 	pop	ebx ; stop address
  3441 0000D680 5F                  <1> 	pop	edi ; start address
  3442 0000D681 29FB                <1> 	sub	ebx, edi
  3443 0000D683 6643                <1> 	inc	bx
  3444 0000D685 66891D[64030300]    <1> 	mov	[u.r0], bx	
  3445 0000D68C E9A8F0FFFF          <1> 	jmp	sysret
  3446                              <1> sysvideo_31:
  3447 0000D691 58                  <1> 	pop	eax
  3448 0000D692 5A                  <1> 	pop	edx
  3449 0000D693 E9A1F0FFFF          <1> 	jmp	sysret
  3450                              <1> 
  3451                              <1> sysvideo_32:
  3452 0000D698 80FB07              <1> 	cmp	bl, 7
  3453 0000D69B 770F                <1> 	ja	short sysvideo_34
  3454                              <1> 
  3455                              <1> 	; BL = 7 = AND display page bytes with CL
  3456                              <1> 
  3457 0000D69D BE00800B00          <1> 	mov	esi, 0B8000h
  3458 0000D6A2 B900800000          <1> 	mov	ecx, 32768
  3459                              <1> sysvideo_33:
  3460 0000D6A7 200E                <1> 	and	byte [esi], cl
  3461 0000D6A9 46                  <1> 	inc	esi
  3462 0000D6AA E2FB                <1> 	loop	sysvideo_33
  3463                              <1> 
  3464                              <1> sysvideo_34:
  3465 0000D6AC 80FB08              <1> 	cmp	bl, 8
  3466 0000D6AF 770F                <1> 	ja	short sysvideo_36
  3467                              <1> 
  3468                              <1> 	; BL = 8 = OR display page bytes with CL
  3469                              <1> 
  3470 0000D6B1 BE00800B00          <1> 	mov	esi, 0B8000h
  3471 0000D6B6 B900800000          <1> 	mov	ecx, 32768
  3472                              <1> sysvideo_35:
  3473 0000D6BB 080E                <1> 	or	byte [esi], cl
  3474 0000D6BD 46                  <1> 	inc	esi
  3475 0000D6BE E2FB                <1> 	loop	sysvideo_35	
  3476                              <1> 
  3477                              <1> sysvideo_36:
  3478 0000D6C0 80FB09              <1> 	cmp	bl, 9
  3479 0000D6C3 0F8770F0FFFF        <1>         ja      sysret ; nothing to do
  3480                              <1> 
  3481                              <1> 	; BL = 9 = XOR display page bytes with CL
  3482                              <1> 
  3483 0000D6C9 BE00800B00          <1> 	mov	esi, 0B8000h
  3484 0000D6CE B900800000          <1> 	mov	ecx, 32768
  3485                              <1> sysvideo_37:
  3486 0000D6D3 300E                <1> 	xor	byte [esi], cl
  3487 0000D6D5 46                  <1> 	inc	esi
  3488 0000D6D6 E2FB                <1> 	loop	sysvideo_37
  3489                              <1> 
  3490                              <1> sysvideo_38:
  3491 0000D6D8 80FF02              <1> 	cmp	bh, 2
  3492 0000D6DB 0F8733030000        <1>         ja      sysvideo_64
  3493                              <1> 	; BH = 2 = VGA Graphics (0A0000h) data transfers
  3494                              <1> 
  3495 0000D6E1 88DC                <1> 	mov	ah, bl
  3496 0000D6E3 80E30F              <1> 	and	bl, 0Fh	
  3497 0000D6E6 C0EC04              <1> 	shr	ah, 4
  3498 0000D6E9 C1E310              <1> 	shl	ebx, 16
  3499 0000D6EC 66BB4001            <1> 	mov	bx, 320 ; 320*200, 320*240
  3500 0000D6F0 20E4                <1> 	and	ah, ah
  3501 0000D6F2 7413                <1> 	jz	short sysvideo_39
  3502 0000D6F4 66D1E3              <1> 	shl	bx, 1 ; 640*200, 640 * 400, 640*480
  3503 0000D6F7 80FC02              <1> 	cmp	ah, 2
  3504 0000D6FA 720B                <1> 	jb	short sysvideo_39 		
  3505 0000D6FC 0F8737F0FFFF        <1> 	ja	sysret ; invalid
  3506                              <1> 	; 800*600
  3507 0000D702 6681C3A000          <1> 	add	bx, 160 ; 800
  3508                              <1> sysvideo_39:
  3509 0000D707 C1CB10              <1> 	ror	ebx, 16
  3510                              <1> 		
  3511 0000D70A 20DB                <1>  	and	bl, bl
  3512 0000D70C 7519                <1> 	jnz	short sysvideo_40
  3513                              <1> 
  3514                              <1> 	; BL =	0 = Fill color (color in CL] (64K)
  3515                              <1> 
  3516 0000D70E 88C8                <1> 	mov	al, cl
  3517 0000D710 B900000100          <1> 	mov	ecx, 65536
  3518 0000D715 890D[64030300]      <1> 	mov	[u.r0], ecx
  3519 0000D71B BF00000A00          <1> 	mov	edi, 0A0000h
  3520 0000D720 F3AB                <1> 	rep	stosd
  3521 0000D722 E912F0FFFF          <1> 	jmp	sysret
  3522                              <1> 
  3523                              <1> sysvideo_40:
  3524 0000D727 80FB01              <1> 	cmp	bl, 1
  3525 0000D72A 7722                <1> 	ja	short sysvideo_42
  3526                              <1> 
  3527 0000D72C 89CE                <1> 	mov	esi, ecx ; user buffer
  3528                              <1> 	; BL = 1 = user to system video/display page transfer
  3529                              <1> sysvideo_41:	
  3530 0000D72E BF00000A00          <1> 	mov	edi, 0A0000h
  3531                              <1> 	; edi = video page address
  3532 0000D733 B900000100          <1> 	mov	ecx, 65536
  3533 0000D738 E8E1100000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3534 0000D73D 0F82F6EFFFFF        <1> 	jc	sysret ; [u.r0] = 0
  3535 0000D743 890D[64030300]      <1> 	mov	[u.r0], ecx		
  3536 0000D749 E9EBEFFFFF          <1> 	jmp	sysret
  3537                              <1> 
  3538                              <1> sysvideo_42:
  3539 0000D74E 80FB02              <1> 	cmp	bl, 2	
  3540 0000D751 7722                <1> 	ja	short sysvideo_44
  3541                              <1> 
  3542 0000D753 89CF                <1> 	mov	edi, ecx ; user buffer
  3543                              <1> 	; BL = 2 = system to user video/display page transfer
  3544                              <1> sysvideo_43:	
  3545 0000D755 BE00000A00          <1> 	mov	esi, 0A0000h
  3546 0000D75A B900000100          <1> 	mov	ecx, 65536
  3547 0000D75F E870100000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3548 0000D764 0F82CFEFFFFF        <1> 	jc	sysret ; [u.r0] = 0
  3549 0000D76A 890D[64030300]      <1> 	mov	[u.r0], ecx
  3550 0000D770 E9C4EFFFFF          <1> 	jmp	sysret 	
  3551                              <1> 
  3552                              <1> sysvideo_44:
  3553 0000D775 80FB03              <1> 	cmp	bl, 3
  3554 0000D778 777A                <1> 	ja	short sysvideo_49
  3555                              <1> 
  3556                              <1> 	; BL = 3 = NOT bits in window (ECX, EDX)
  3557                              <1> 
  3558 0000D77A BF00000A00          <1> 	mov	edi, 0A0000h
  3559 0000D77F 89FE                <1> 	mov	esi, edi
  3560                              <1> 	
  3561 0000D781 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3562 0000D783 770B                <1> 	ja	short sysvideo_45 ; window
  3563                              <1> 	; full screen (update)
  3564 0000D785 B900000100          <1> 	mov	ecx, 65536
  3565 0000D78A 890D[64030300]      <1> 	mov	[u.r0], ecx
  3566                              <1> sysvideo_45:
  3567 0000D790 F616                <1> 	not	byte [esi] ; NOT operation
  3568 0000D792 46                  <1> 	inc	esi
  3569 0000D793 E2FB                <1> 	loop	sysvideo_45
  3570 0000D795 E99FEFFFFF          <1> 	jmp	sysret
  3571                              <1> sysvideo_46:
  3572 0000D79A 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3573 0000D79D 6629C8              <1> 	sub	ax, cx  ; - top left column
  3574 0000D7A0 0F8293EFFFFF        <1>         jb      sysret ; invalid
  3575 0000D7A6 6640                <1> 	inc	ax ; same column no == 1 column	 
  3576 0000D7A8 50                  <1> 	push	eax ; byte count per window row
  3577 0000D7A9 52                  <1> 	push	edx
  3578 0000D7AA C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  3579 0000D7AD 89C8                <1> 	mov	eax, ecx
  3580 0000D7AF C1E810              <1> 	shr	eax, 16  ; top row
  3581 0000D7B2 F7E3                <1> 	mul	ebx
  3582 0000D7B4 6689CA              <1> 	mov	dx, cx ; top left column
  3583 0000D7B7 01D0                <1> 	add	eax, edx
  3584 0000D7B9 01C6                <1> 	add	esi, eax ; start address 
  3585 0000D7BB 59                  <1> 	pop	ecx ; edx
  3586 0000D7BC 89C8                <1> 	mov	eax, ecx
  3587 0000D7BE C1E810              <1> 	shr	eax, 16 ; bottom row
  3588 0000D7C1 F7E3                <1> 	mul	ebx
  3589 0000D7C3 6689CA              <1> 	mov	dx, cx ; bottom right column
  3590 0000D7C6 01D0                <1> 	add	eax, edx
  3591 0000D7C8 01C7                <1> 	add	edi, eax ; stop address (included)
  3592 0000D7CA 5A                  <1> 	pop	edx ; byte count per window row
  3593 0000D7CB 81FFFFFF0A00        <1> 	cmp	edi, 0AFFFFh
  3594 0000D7D1 0F8762EFFFFF        <1> 	ja	sysret	
  3595 0000D7D7 56                  <1> 	push	esi
  3596 0000D7D8 4E                  <1> 	dec	esi
  3597                              <1> sysvideo_47:
  3598 0000D7D9 89D1                <1> 	mov	ecx, edx
  3599                              <1> sysvideo_48:
  3600 0000D7DB 46                  <1> 	inc	esi
  3601 0000D7DC F616                <1> 	not	byte [esi]
  3602 0000D7DE E2FB                <1> 	loop	sysvideo_48
  3603 0000D7E0 01DE                <1> 	add	esi, ebx ; bytes per screen row
  3604                              <1> 	;
  3605 0000D7E2 39FE                <1> 	cmp	esi, edi ; stop address (included in loop)
  3606 0000D7E4 76F3                <1> 	jna	short sysvideo_47
  3607 0000D7E6 5E                  <1> 	pop	esi
  3608 0000D7E7 29F7                <1> 	sub	edi, esi
  3609 0000D7E9 893D[64030300]      <1> 	mov	[u.r0], edi
  3610 0000D7EF E945EFFFFF          <1> 	jmp	sysret
  3611                              <1> 
  3612                              <1> sysvideo_49:
  3613 0000D7F4 80FB04              <1> 	cmp	bl, 4
  3614 0000D7F7 0F87A1000000        <1>         ja      sysvideo_52
  3615                              <1> 
  3616                              <1> 	; BL = 4 = window copy (system to system)
  3617                              <1> 
  3618 0000D7FD B800000A00          <1> 	mov	eax, 0A0000h
  3619 0000D802 39C6                <1> 	cmp	esi, eax
  3620 0000D804 0F822FEFFFFF        <1> 	jb	sysret
  3621 0000D80A 39C7                <1> 	cmp	edi, eax
  3622 0000D80C 0F8227EFFFFF        <1> 	jb	sysret
  3623 0000D812 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3624 0000D816 39C6                <1> 	cmp	esi, eax
  3625 0000D818 0F871BEFFFFF        <1> 	ja	sysret
  3626 0000D81E 39C7                <1> 	cmp	edi, eax
  3627 0000D820 0F8713EFFFFF        <1> 	ja	sysret
  3628                              <1> 	
  3629 0000D826 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3630 0000D828 7712                <1> 	ja	short sysvideo_50 ; window
  3631                              <1> 	; full screen copy
  3632 0000D82A 89C1                <1> 	mov	ecx, eax
  3633 0000D82C 29F9                <1> 	sub	ecx, edi
  3634 0000D82E 41                  <1> 	inc	ecx
  3635 0000D82F 890D[64030300]      <1> 	mov	[u.r0], ecx
  3636 0000D835 F3A4                <1> 	rep	movsb
  3637 0000D837 E9FDEEFFFF          <1> 	jmp	sysret
  3638                              <1> sysvideo_50:
  3639 0000D83C 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3640 0000D83F 6629C8              <1> 	sub	ax, cx  ; - top left column
  3641 0000D842 0F82F1EEFFFF        <1>         jb      sysret ; invalid
  3642 0000D848 6640                <1> 	inc	ax ; same column no == 1 column	 
  3643 0000D84A 50                  <1> 	push	eax ; byte count per window row
  3644                              <1> 	;
  3645 0000D84B 52                  <1> 	push	edx
  3646 0000D84C C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  3647 0000D84F 89C8                <1> 	mov	eax, ecx
  3648 0000D851 C1E810              <1> 	shr	eax, 16	; top row
  3649 0000D854 F7E3                <1> 	mul	ebx
  3650 0000D856 6689CA              <1> 	mov	dx, cx ; top left column
  3651 0000D859 01D0                <1> 	add	eax, edx
  3652 0000D85B 01C7                <1> 	add	edi, eax ; start address 
  3653 0000D85D 01C6                <1> 	add	esi, eax
  3654 0000D85F 59                  <1> 	pop	ecx ; edx
  3655 0000D860 89C8                <1> 	mov	eax, ecx
  3656 0000D862 C1E810              <1> 	shr	eax, 16 ; bottom row
  3657 0000D865 F7E3                <1> 	mul	ebx
  3658 0000D867 6689CA              <1> 	mov	dx, cx ; bottom right column
  3659 0000D86A 01D0                <1> 	add	eax, edx
  3660 0000D86C 5A                  <1> 	pop	edx ; byte count per window row
  3661 0000D86D 0500000A00          <1> 	add	eax, 0A0000h
  3662 0000D872 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3663 0000D877 0F87BCEEFFFF        <1> 	ja	sysret
  3664 0000D87D 57                  <1> 	push	edi ; start address 
  3665 0000D87E 50                  <1> 	push	eax ; stop address (included)
  3666                              <1> sysvideo_51:
  3667 0000D87F 89D1                <1> 	mov	ecx, edx
  3668 0000D881 F3A4                <1> 	rep	movsb
  3669 0000D883 4F                  <1> 	dec	edi
  3670 0000D884 4E                  <1> 	dec	esi
  3671 0000D885 01DF                <1> 	add	edi, ebx ; bytes per screen row
  3672 0000D887 01DE                <1> 	add	esi, ebx
  3673                              <1> 	;
  3674 0000D889 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3675 0000D88C 76F1                <1> 	jna	short sysvideo_51
  3676 0000D88E 5B                  <1> 	pop	ebx ; stop address
  3677 0000D88F 5F                  <1> 	pop	edi ; start address
  3678 0000D890 29FB                <1> 	sub	ebx, edi
  3679 0000D892 43                  <1> 	inc	ebx
  3680 0000D893 891D[64030300]      <1> 	mov	[u.r0], ebx	
  3681 0000D899 E99BEEFFFF          <1> 	jmp	sysret
  3682                              <1> 
  3683                              <1> sysvideo_52:
  3684 0000D89E 80FB05              <1> 	cmp	bl, 5
  3685 0000D8A1 0F8791000000        <1>         ja      sysvideo_55
  3686                              <1> 
  3687                              <1> 	; BL = 5 = window copy (user to system)
  3688                              <1> 
  3689 0000D8A7 B800000A00          <1> 	mov	eax, 0A0000h
  3690 0000D8AC 39C7                <1> 	cmp	edi, eax
  3691 0000D8AE 0F8285EEFFFF        <1> 	jb	sysret
  3692 0000D8B4 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3693 0000D8B8 39C7                <1> 	cmp	edi, eax
  3694 0000D8BA 0F8779EEFFFF        <1> 	ja	sysret
  3695                              <1> 
  3696                              <1> 	; esi = user buffer (in user's memory space)
  3697 0000D8C0 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3698 0000D8C2 0F8666FEFFFF        <1>         jna     sysvideo_41 ; full screen copy
  3699                              <1> 
  3700 0000D8C8 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3701 0000D8CB 6629C8              <1> 	sub	ax, cx  ; - top left column
  3702 0000D8CE 0F8265EEFFFF        <1>         jb      sysret ; invalid
  3703 0000D8D4 6640                <1> 	inc	ax ; same column no == 1 column	 
  3704 0000D8D6 50                  <1> 	push	eax ; byte count per window row
  3705                              <1> 
  3706 0000D8D7 52                  <1> 	push	edx
  3707 0000D8D8 C1EB10              <1> 	shr	ebx, 16 ; 320,640,800 : screen width
  3708 0000D8DB 89C8                <1> 	mov	eax, ecx
  3709 0000D8DD C1E810              <1> 	shr	eax, 16	; top row
  3710 0000D8E0 F7E3                <1> 	mul	ebx
  3711 0000D8E2 6689CA              <1> 	mov	dx, cx ; top left column
  3712 0000D8E5 01D0                <1> 	add	eax, edx
  3713 0000D8E7 01C7                <1> 	add	edi, eax ; start address 
  3714 0000D8E9 59                  <1> 	pop	ecx ; edx
  3715 0000D8EA 89C8                <1> 	mov	eax, ecx
  3716 0000D8EC C1E810              <1> 	shr	eax, 16 ; bottom row
  3717 0000D8EF F7E3                <1> 	mul	ebx
  3718 0000D8F1 6689CA              <1> 	mov	dx, cx ; bottom right column
  3719 0000D8F4 01D0                <1> 	add	eax, edx
  3720 0000D8F6 5A                  <1> 	pop	edx ; byte count per window row
  3721 0000D8F7 0500000A00          <1> 	add	eax, 0A0000h
  3722 0000D8FC 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3723 0000D901 0F8732EEFFFF        <1> 	ja	sysret
  3724 0000D907 57                  <1> 	push	edi ; start address 
  3725 0000D908 50                  <1> 	push	eax ; stop address (included)
  3726                              <1> sysvideo_53:
  3727 0000D909 89D1                <1> 	mov	ecx, edx ; byte count
  3728                              <1> 	; user to system video/display page window transfer
  3729                              <1> 	; esi =	user buffer
  3730 0000D90B E80E0F0000          <1> 	call	transfer_from_user_buffer ; fast transfer
  3731 0000D910 721F                <1> 	jc	short sysvideo_54
  3732 0000D912 010D[64030300]      <1> 	add	[u.r0], ecx
  3733 0000D918 01DF                <1> 	add	edi, ebx ; next row
  3734 0000D91A 01CE                <1> 	add	esi, ecx
  3735 0000D91C 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3736 0000D91F 76E8                <1> 	jna	short sysvideo_53
  3737 0000D921 5B                  <1> 	pop	ebx ; stop address
  3738 0000D922 5F                  <1> 	pop	edi ; start address
  3739 0000D923 29FB                <1> 	sub	ebx, edi
  3740 0000D925 43                  <1> 	inc	ebx
  3741 0000D926 891D[64030300]      <1> 	mov	[u.r0], ebx	
  3742 0000D92C E908EEFFFF          <1> 	jmp	sysret
  3743                              <1> sysvideo_54:
  3744 0000D931 58                  <1> 	pop	eax
  3745 0000D932 5A                  <1> 	pop	edx
  3746 0000D933 E901EEFFFF          <1> 	jmp	sysret
  3747                              <1> 
  3748                              <1> sysvideo_55:
  3749 0000D938 80FB06              <1> 	cmp	bl, 6
  3750 0000D93B 0F8793000000        <1>         ja      sysvideo_58
  3751                              <1> 
  3752                              <1> 	; BL = 6 = window copy (system to user)
  3753                              <1> 
  3754 0000D941 89F7                <1> 	mov	edi, esi ; user buffer
  3755                              <1> 
  3756 0000D943 B800000A00          <1> 	mov	eax, 0A0000h
  3757 0000D948 39C6                <1> 	cmp	esi, eax
  3758 0000D94A 0F82E9EDFFFF        <1> 	jb	sysret
  3759 0000D950 6683C0FF            <1> 	add	ax, 0FFFFh ; 65535
  3760 0000D954 39C6                <1> 	cmp	esi, eax
  3761 0000D956 0F87DDEDFFFF        <1> 	ja	sysret
  3762                              <1> 
  3763                              <1> 	; edi = user buffer (in user's memory space)
  3764 0000D95C 39CA                <1> 	cmp	edx, ecx ; bottom-right > top-left ?
  3765 0000D95E 0F86A2FAFFFF        <1>         jna     sysvideo_17 ; full screen copy
  3766                              <1> 
  3767 0000D964 0FB7C2              <1> 	movzx	eax, dx ; bottom right column
  3768 0000D967 6629C8              <1> 	sub	ax, cx  ; - top left column
  3769 0000D96A 0F82C9EDFFFF        <1>         jb      sysret ; invalid
  3770 0000D970 6640                <1> 	inc	ax ; same column no == 1 column	 
  3771 0000D972 50                  <1> 	push	eax ; byte count per window row
  3772                              <1> 
  3773 0000D973 52                  <1> 	push	edx
  3774 0000D974 C1EB10              <1> 	shr	ebx, 16 ; 320, 640,800 ; screen width
  3775 0000D977 89C8                <1> 	mov	eax, ecx
  3776 0000D979 C1E810              <1> 	shr	eax, 16	; top row
  3777 0000D97C F7E3                <1> 	mul	ebx
  3778 0000D97E 6689CA              <1> 	mov	dx, cx ; top left column
  3779 0000D981 01D0                <1> 	add	eax, edx
  3780 0000D983 01C6                <1> 	add	esi, eax ; start address 
  3781 0000D985 59                  <1> 	pop	ecx ; edx
  3782 0000D986 89C8                <1> 	mov	eax, ecx
  3783 0000D988 C1E810              <1> 	shr	eax, 16 ; bottom row
  3784 0000D98B F7E3                <1> 	mul	ebx
  3785 0000D98D 6689CA              <1> 	mov	dx, cx ; bottom right column
  3786 0000D990 01D0                <1> 	add	eax, edx
  3787 0000D992 5A                  <1> 	pop	edx ; byte count per window row
  3788 0000D993 0500000A00          <1> 	add	eax, 0A0000h
  3789 0000D998 3DFFFF0A00          <1> 	cmp	eax, 0AFFFFh
  3790 0000D99D 0F8796EDFFFF        <1> 	ja	sysret
  3791 0000D9A3 56                  <1> 	push	esi ; start address 
  3792 0000D9A4 50                  <1> 	push	eax ; stop address (included)
  3793                              <1> sysvideo_56:
  3794 0000D9A5 89D1                <1> 	mov	ecx, edx ; byte count
  3795                              <1> 	; user to system video/display page window transfer
  3796                              <1> 	; esi =	user buffer
  3797 0000D9A7 E8280E0000          <1> 	call	transfer_to_user_buffer ; fast transfer
  3798 0000D9AC 721F                <1> 	jc	short sysvideo_57
  3799 0000D9AE 010D[64030300]      <1> 	add	[u.r0], ecx
  3800 0000D9B4 01DF                <1> 	add	edi, ebx ; next row
  3801 0000D9B6 01CE                <1> 	add	esi, ecx
  3802 0000D9B8 3B3C24              <1> 	cmp	edi, [esp] ; stop addr(included in loop)
  3803 0000D9BB 76E8                <1> 	jna	short sysvideo_56
  3804 0000D9BD 5B                  <1> 	pop	ebx ; stop address
  3805 0000D9BE 5F                  <1> 	pop	edi ; start address
  3806 0000D9BF 29FB                <1> 	sub	ebx, edi
  3807 0000D9C1 43                  <1> 	inc	ebx
  3808 0000D9C2 891D[64030300]      <1> 	mov	[u.r0], ebx	
  3809 0000D9C8 E96CEDFFFF          <1> 	jmp	sysret
  3810                              <1> sysvideo_57:
  3811 0000D9CD 58                  <1> 	pop	eax
  3812 0000D9CE 5A                  <1> 	pop	edx
  3813 0000D9CF E965EDFFFF          <1> 	jmp	sysret
  3814                              <1> 
  3815                              <1> sysvideo_58:
  3816 0000D9D4 80FB07              <1> 	cmp	bl, 7
  3817 0000D9D7 770F                <1> 	ja	short sysvideo_60
  3818                              <1> 
  3819                              <1> 	; BL = 7 = AND display page bytes with CL
  3820                              <1> 
  3821 0000D9D9 BE00000A00          <1> 	mov	esi, 0A0000h
  3822 0000D9DE B900000100          <1> 	mov	ecx, 65536
  3823                              <1> sysvideo_59:
  3824 0000D9E3 200E                <1> 	and	byte [esi], cl
  3825 0000D9E5 46                  <1> 	inc	esi
  3826 0000D9E6 E2FB                <1> 	loop	sysvideo_59
  3827                              <1> 
  3828                              <1> sysvideo_60:
  3829 0000D9E8 80FB08              <1> 	cmp	bl, 8
  3830 0000D9EB 770F                <1> 	ja	short sysvideo_62
  3831                              <1> 
  3832                              <1> 	; BL = 8 = OR display page bytes with CL
  3833                              <1> 
  3834 0000D9ED BE00000A00          <1> 	mov	esi, 0A0000h
  3835 0000D9F2 B900000100          <1> 	mov	ecx, 65536
  3836                              <1> sysvideo_61:
  3837 0000D9F7 080E                <1> 	or	byte [esi], cl
  3838 0000D9F9 46                  <1> 	inc	esi
  3839 0000D9FA E2FB                <1> 	loop	sysvideo_61	
  3840                              <1> 
  3841                              <1> sysvideo_62:
  3842 0000D9FC 80FB09              <1> 	cmp	bl, 9
  3843 0000D9FF 0F8734EDFFFF        <1>         ja      sysret ; nothing to do
  3844                              <1> 
  3845                              <1> 	; BL = 9 = XOR display page bytes with CL
  3846                              <1> 
  3847 0000DA05 BE00000A00          <1> 	mov	esi, 0A0000h
  3848 0000DA0A B900000100          <1> 	mov	ecx, 65536
  3849                              <1> sysvideo_63:
  3850 0000DA0F 300E                <1> 	xor	byte [esi], cl
  3851 0000DA11 46                  <1> 	inc	esi
  3852 0000DA12 E2FB                <1> 	loop	sysvideo_63
  3853                              <1> 
  3854                              <1> sysvideo_64:
  3855 0000DA14 80FF03              <1> 	cmp	bh, 3
  3856 0000DA17 7464                <1> 	je	short sysvideo_68
  3857 0000DA19 80FF04              <1> 	cmp	bh, 4
  3858 0000DA1C 7721                <1> 	ja	short sysvideo_65
  3859                              <1> 	
  3860                              <1> 	; BH = 4
  3861                              <1> 	; Direct User Access for CGA video memory.
  3862                              <1> 	; Setup user's page tables for direct access to 0B8000h.
  3863                              <1> 	;
  3864                              <1> 	; Permission checks are not implemented yet !
  3865                              <1> 	; (11/07/2016)
  3866                              <1> 
  3867 0000DA1E B800800B00          <1> 	mov	eax, 0B8000h
  3868 0000DA23 B908000000          <1> 	mov	ecx, 8 ; 8 pages (8*4K=32K)
  3869 0000DA28 89C3                <1> 	mov	ebx, eax ; 12/05/2017 ; virtual = physical
  3870 0000DA2A E8A47CFFFF          <1> 	call	direct_memory_access	
  3871 0000DA2F 0F8204EDFFFF        <1> 	jc	sysret
  3872                              <1> 	; eax = 0B8000h if there is not an error
  3873 0000DA35 A3[64030300]        <1> 	mov	[u.r0], eax
  3874 0000DA3A E9FAECFFFF          <1> 	jmp	sysret
  3875                              <1> 
  3876                              <1> sysvideo_65:
  3877 0000DA3F 80FF05              <1> 	cmp	bh, 5
  3878 0000DA42 7721                <1> 	ja	short sysvideo_66
  3879                              <1> 
  3880                              <1> 	; BH = 5
  3881                              <1> 	; Direct User Access for VGA video memory.
  3882                              <1> 	; Setup user's page tables for direct access to 0A0000h.
  3883                              <1> 	;
  3884                              <1> 	; Permission checks are not implemented yet !
  3885                              <1> 	; (11/07/2016)
  3886                              <1> 
  3887 0000DA44 B800000A00          <1> 	mov	eax, 0A0000h
  3888 0000DA49 B910000000          <1> 	mov	ecx, 16 ; 16 pages (16*4K=64K)
  3889 0000DA4E 89C3                <1> 	mov	ebx, eax ; 12/05/2017 ; virtual = physical
  3890 0000DA50 E87E7CFFFF          <1> 	call	direct_memory_access	
  3891 0000DA55 0F82DEECFFFF        <1> 	jc	sysret
  3892                              <1> 	; eax = 0A0000h if there is not an error
  3893 0000DA5B A3[64030300]        <1> 	mov	[u.r0], eax
  3894 0000DA60 E9D4ECFFFF          <1> 	jmp	sysret
  3895                              <1> 
  3896                              <1> sysvideo_66:
  3897 0000DA65 80FF06              <1> 	cmp	bh, 6
  3898 0000DA68 7705                <1> 	ja	short sysvideo_67
  3899                              <1> 	; BH = 6
  3900                              <1> 	; Direct User Access for (Super VGA) Linear Frame Buffer.
  3901                              <1> 	; Setup user's page tables for direct access to LFB.
  3902                              <1> 	;
  3903                              <1> 	; Not implemented yet !
  3904                              <1> 	; (11/07/2016)
  3905 0000DA6A E9CAECFFFF          <1> 	jmp	sysret
  3906                              <1> 
  3907                              <1> sysvideo_67:
  3908 0000DA6F 80FF07              <1> 	cmp	bh, 7
  3909 0000DA72 0F87C1ECFFFF        <1> 	ja	sysret ; invalid !
  3910                              <1> 
  3911                              <1> 	; BH = 7
  3912                              <1> 	; Get (Super/Extended VGA) Linear Frame Buffer info.
  3913                              <1> 	;
  3914                              <1> 	; Not implemented yet !
  3915                              <1> 	; (11/07/2016)
  3916 0000DA78 E9BCECFFFF          <1> 	jmp	sysret
  3917                              <1> 
  3918                              <1> sysvideo_68:
  3919                              <1> 	; BH = 3
  3920                              <1> 	; Super VGA, LINEAR FRAME BUFFER data transfers
  3921                              <1> 	; Not implemented for yet ! (11/07/2016)
  3922 0000DA7D E9B7ECFFFF          <1> 	jmp	sysret
  3923                              <1> 
  3924                              <1> mkdir:
  3925                              <1> 	; 04/12/2015 (14 byte directory names)
  3926                              <1> 	; 12/10/2015
  3927                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
  3928                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
  3929                              <1> 	;
  3930                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
  3931                              <1> 	; by u.namep into the current directory.
  3932                              <1> 	;
  3933                              <1> 	; INPUTS ->
  3934                              <1> 	;    u.namep - points to a file name 
  3935                              <1> 	;	           that is about to be a directory entry.
  3936                              <1> 	;    ii - current directory's i-number.	
  3937                              <1> 	; OUTPUTS ->
  3938                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name. 
  3939                              <1> 	;    u.off - points to entry to be filled 
  3940                              <1> 	;	     in the current directory		
  3941                              <1> 	;    u.base - points to start of u.dirbuf.
  3942                              <1> 	;    r1 - contains i-number of current directory 
  3943                              <1> 	;	
  3944                              <1> 	; ((AX = R1)) output
  3945                              <1> 	;
  3946                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
  3947                              <1>         ;    ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
  3948                              <1> 	;
  3949                              <1> 
  3950                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
  3951 0000DA82 31C0                <1> 	xor 	eax, eax
  3952 0000DA84 BF[9A030300]        <1> 	mov     edi, u.dirbuf+2
  3953 0000DA89 89FE                <1> 	mov	esi, edi
  3954 0000DA8B AB                  <1> 	stosd
  3955 0000DA8C AB                  <1> 	stosd
  3956                              <1> 	; 04/12/2015 (14 byte directory names)
  3957 0000DA8D AB                  <1> 	stosd
  3958 0000DA8E 66AB                <1> 	stosw
  3959                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
  3960 0000DA90 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
  3961                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
  3962                              <1> 	;mov 	ebp, [u.namep]
  3963 0000DA92 E80D030000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
  3964                              <1> 		; esi = physical address (page start + offset)
  3965                              <1> 		; ecx = byte count in the page (1 - 4096)
  3966                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
  3967                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
  3968                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
  3969                              <1> mkdir_1: ; 1: 
  3970 0000DA97 45                  <1> 	inc	ebp ; 12/10/2015
  3971                              <1> 	;
  3972                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
  3973                              <1> 	 ; 01/08/2013
  3974 0000DA98 AC                  <1> 	lodsb
  3975                              <1> 		; movb (r2)+,r1 / move character in name to r1
  3976 0000DA99 20C0                <1> 	and 	al, al
  3977 0000DA9B 7427                <1> 	jz 	short mkdir_3 	  
  3978                              <1> 		; beq 1f / if null, done
  3979 0000DA9D 3C2F                <1> 	cmp	al, '/'
  3980                              <1> 		; cmp r1,$'/ / is it a "/"?
  3981 0000DA9F 7414                <1> 	je	short mkdir_err
  3982                              <1> 	;je	error
  3983                              <1> 		; beq error9 / yes, error
  3984                              <1> 	; 12/10/2015
  3985 0000DAA1 6649                <1> 	dec	cx
  3986 0000DAA3 7505                <1> 	jnz	short mkdir_2
  3987                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
  3988 0000DAA5 E800030000          <1> 	call	trans_addr_nm ; convert virtual address to physical
  3989                              <1> 		; esi = physical address (page start + offset)
  3990                              <1> 		; ecx = byte count in the page
  3991                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
  3992                              <1> mkdir_2:
  3993 0000DAAA 81FF[A8030300]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16) 
  3994                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
  3995                              <1> 				     ; / a char?
  3996 0000DAB0 74E5                <1> 	je	short mkdir_1
  3997                              <1> 		; beq 1b / yes, go back
  3998 0000DAB2 AA                  <1> 	stosb
  3999                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
  4000 0000DAB3 EBE2                <1> 	jmp 	short mkdir_1
  4001                              <1> 		; br 1b / get next char
  4002                              <1> mkdir_err:
  4003                              <1> 	; 17/06/2015
  4004 0000DAB5 C705[C8030300]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
  4004 0000DABD 0000                <1>
  4005 0000DABF E955ECFFFF          <1> 	jmp	error
  4006                              <1> 
  4007                              <1> mkdir_3: ; 1:
  4008 0000DAC4 A1[78030300]        <1> 	mov	eax, [u.dirp]
  4009 0000DAC9 A3[80030300]        <1> 	mov	[u.off], eax
  4010                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
  4011                              <1> 				 ; / slot to u.off
  4012                              <1> wdir: ; 29/04/2013
  4013 0000DACE C705[84030300]-     <1>         mov     dword [u.base], u.dirbuf
  4013 0000DAD4 [98030300]          <1>
  4014                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
  4015 0000DAD8 C705[88030300]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
  4015 0000DAE0 0000                <1>
  4016                              <1> 		; mov $10.,u.count / u.count = 10
  4017 0000DAE2 66A1[51040300]      <1> 	mov	ax, [ii] 
  4018                              <1> 		; mov ii,r1 / r1 has i-number of current directory
  4019 0000DAE8 B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
  4020 0000DAEA E8331D0000          <1> 	call 	access
  4021                              <1> 		; jsr r0,access; 1 / get i-node and set its file up 
  4022                              <1> 				 ; / for writing
  4023                              <1> 	; AX = i-number of current directory
  4024                              <1> 	; 01/08/2013
  4025 0000DAEF FE05[C6030300]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign	
  4026 0000DAF5 E83C0F0000          <1> 	call	writei
  4027                              <1> 		; jsr r0,writei / write into directory
  4028 0000DAFA C3                  <1> 	retn	
  4029                              <1> 		; rts r0
  4030                              <1> 
  4031                              <1> sysexec:
  4032                              <1> 	; 18/11/2017
  4033                              <1> 	; 14/11/2017
  4034                              <1> 	; 13/11/2017
  4035                              <1> 	; 24/10/2016, 04/01/2017
  4036                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
  4037                              <1> 	; 23/06/2015 - 23/10/2015 (Retro UNIX 386 v1)
  4038                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
  4039                              <1> 	;
  4040                              <1> 	; 'sysexec' initiates execution of a file whose path name if
  4041                              <1> 	; pointed to by 'name' in the sysexec call. 
  4042                              <1> 	; 'sysexec' performs the following operations:
  4043                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
  4044                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
  4045                              <1> 	;    3. sets trap vectors to system routines.
  4046                              <1> 	;    4. loads arguments to be passed to executing file into
  4047                              <1> 	;	highest locations of user's core
  4048                              <1> 	;    5. puts pointers to arguments in locations immediately
  4049                              <1> 	;	following arguments.
  4050                              <1> 	;    6.	saves number of arguments in next location.
  4051                              <1> 	;    7. intializes user's stack area so that all registers
  4052                              <1> 	;	will be zeroed and the PS is cleared and the PC set
  4053                              <1> 	;	to core when 'sysret' restores registers 
  4054                              <1> 	;	and does an rti.
  4055                              <1> 	;    8. inializes u.r0 and u.sp
  4056                              <1> 	;    9. zeros user's core down to u.r0
  4057                              <1> 	;   10.	reads executable file from storage device into core
  4058                              <1> 	;	starting at location 'core'.
  4059                              <1> 	;   11.	sets u.break to point to end of user's code with
  4060                              <1> 	;	data area appended.
  4061                              <1> 	;   12.	calls 'sysret' which returns control at location
  4062                              <1> 	;	'core' via 'rti' instruction. 		  		
  4063                              <1> 	;
  4064                              <1> 	; Calling sequence:
  4065                              <1> 	;	sysexec; namep; argp
  4066                              <1> 	; Arguments:
  4067                              <1> 	;	namep - points to pathname of file to be executed
  4068                              <1> 	;	argp  - address of table of argument pointers
  4069                              <1> 	;	argp1... argpn - table of argument pointers
  4070                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
  4071                              <1> 	; Inputs: (arguments)
  4072                              <1> 	; Outputs: -	
  4073                              <1> 	; ...............................................................
  4074                              <1> 	;
  4075                              <1> 	; Retro UNIX 386 v1 modification: 
  4076                              <1> 	;	User application runs in it's own virtual space 
  4077                              <1> 	;	which is izolated from kernel memory (and other
  4078                              <1> 	;	memory pages) via 80386	paging in ring 3 
  4079                              <1> 	;	privilige mode. Virtual start address is always 0.
  4080                              <1> 	;	User's core memory starts at linear address 400000h
  4081                              <1> 	;	(the end of the 1st 4MB).
  4082                              <1> 	;
  4083                              <1> 	; Retro UNIX 8086 v1 modification: 
  4084                              <1> 	;	user/application segment and system/kernel segment
  4085                              <1> 	;	are different and sysenter/sysret/sysrele routines
  4086                              <1> 	;	are different (user's registers are saved to 
  4087                              <1> 	;	and then restored from system's stack.)
  4088                              <1> 	;
  4089                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
  4090                              <1> 	;	      arguments which were in these registers;
  4091                              <1> 	;	      but, it returns by putting the 1st argument
  4092                              <1> 	;	      in 'u.namep' and the 2nd argument
  4093                              <1> 	;	      on top of stack. (1st argument is offset of the
  4094                              <1> 	;	      file/path name in the user's program segment.)		 	
  4095                              <1> 	
  4096                              <1> 	;call	arg2
  4097                              <1> 	; * name - 'u.namep' points to address of file/path name
  4098                              <1> 	;          in the user's program segment ('u.segmnt')
  4099                              <1> 	;          with offset in BX register (as sysopen argument 1).
  4100                              <1> 	; * argp - sysexec argument 2 is in CX register 
  4101                              <1> 	;          which is on top of stack.
  4102                              <1> 	;
  4103                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
  4104                              <1> 
  4105                              <1> 	; 23/06/2015 (32 bit modifications)
  4106                              <1> 
  4107                              <1> 	;; 13/11/2017
  4108                              <1> 	;;mov	[u.namep], ebx ; argument 1
  4109                              <1>         ; 18/10/2015
  4110 0000DAFB 890D[4C040300]      <1> 	mov     [argv], ecx  ; * ; argument 2
  4111                              <1> 
  4112                              <1> 	; 13/11/2017
  4113 0000DB01 89DE                <1> 	mov	esi, ebx
  4114 0000DB03 E84E210000          <1> 	call	set_working_path_x
  4115 0000DB08 7319                <1> 	jnc	short sysexec_0
  4116                              <1> 
  4117                              <1> 	;; 'bad command or file name'
  4118                              <1> 	;mov	eax, ERR_BAD_CMD_ARG ; 01h ; TRDOS 8086
  4119                              <1> 	
  4120                              <1> 	; 'file not found !' error
  4121 0000DB0A B802000000          <1> 	mov	eax, ERR_NOT_FOUND ; 02h ; TRDOS 8086
  4122                              <1> sysexec_not_found_err:
  4123                              <1> sysexec_access_error:
  4124                              <1> sysexec_ext_error:
  4125 0000DB0F A3[64030300]        <1> 	mov	[u.r0], eax
  4126 0000DB14 A3[C8030300]        <1> 	mov	[u.error], eax
  4127 0000DB19 E80D220000          <1> 	call 	reset_working_path
  4128 0000DB1E E9F6EBFFFF          <1> 	jmp	error
  4129                              <1> 
  4130                              <1> sysexec_0:
  4131                              <1> 	; 13/11/2017
  4132                              <1> 	;mov	esi, FindFile_Name
  4133 0000DB23 66B80018            <1>         mov	ax, 1800h ; Only files 
  4134 0000DB27 E892A7FFFF          <1> 	call	find_first_file
  4135 0000DB2C 72E1                <1> 	jc	short sysexec_not_found_err ; eax = 2
  4136                              <1> 
  4137                              <1> 	; check_ file attributes
  4138                              <1> 	; (attribute bits = 00ADVSHR) ; 18h = Directory+Volume
  4139                              <1> 	; BL = Attributes byte
  4140                              <1> 	
  4141 0000DB2E F6C306              <1>         test	bl, 6  ; system file or hidden file (S+H) 
  4142                              <1> 	;jz	short sysexec_0ext
  4143 0000DB31 7417                <1> 	jz	short sysexec_1 ; yes
  4144                              <1> 
  4145                              <1> 	; 13/11/2017 
  4146                              <1> 	; /// TRDOS386 permission check for multiuser mode ///
  4147                              <1> 	; SYSTEM file or HIDDEN file !!
  4148                              <1> 	; (Only super user has permission to run this file.)
  4149                              <1> 	
  4150                              <1> 	; ([u.uid]=0 for super user or root in multiuser mode)  
  4151                              <1> 	; ([u.uid]=0 for any users in singleuser mode) 
  4152 0000DB33 803D[B0030300]00    <1> 	cmp 	byte [u.uid], 0 ; Super User ([u.uid]=0) ?
  4153                              <1> 	;jna	short sysexec_0ext
  4154 0000DB3A 760E                <1> 	jna	short sysexec_1 ; yes 
  4155                              <1> 
  4156                              <1> 	; 'permission denied !' error  
  4157 0000DB3C B80B000000          <1>         mov	eax, ERR_FILE_ACCESS  ; 11 = ERR_PERM_DENIED
  4158 0000DB41 EBCC                <1>         jmp	short sysexec_access_error
  4159                              <1> 
  4160                              <1> sysexec_not_exf:
  4161                              <1> 	; 'not executable file !' error
  4162 0000DB43 B816000000          <1> 	mov	eax, ERR_NOT_EXECUTABLE
  4163 0000DB48 EBC5                <1> 	jmp	sysexec_ext_error
  4164                              <1> 
  4165                              <1> ;sysexec_0ext:
  4166                              <1> sysexec_1:
  4167                              <1> 	; 18/11/2017
  4168 0000DB4A BE[48620100]        <1> 	mov	esi, FindFile_Name
  4169                              <1> 	; 13/11/2017
  4170                              <1> 	; check program file name extension
  4171                              <1> 	; ('.PRG' for current TRDOS version)
  4172 0000DB4F E80DC2FFFF          <1> 	call	check_prg_filename_ext
  4173 0000DB54 72ED                <1> 	jc	short sysexec_not_exf
  4174                              <1> 	
  4175                              <1> 	; 18/11/2017
  4176 0000DB56 3C50                <1> 	cmp	al, 'P'
  4177 0000DB58 75E9                <1> 	jne	short sysexec_not_exf	
  4178                              <1> 
  4179                              <1> 	; '.PRG' extension is OK.
  4180                              <1> 	; Only '.PRG' files are valid program files
  4181                              <1> 	; for current TRDOS 386 version.
  4182                              <1> 
  4183 0000DB5A 8B15[74620100]      <1> 	mov	edx, [FindFile_DirEntry+DirEntry_FileSize]
  4184 0000DB60 66A1[6C620100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusHI]
  4185 0000DB66 C1E010              <1> 	shl	eax, 16
  4186 0000DB69 66A1[72620100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusLO]
  4187                              <1> 	; EAX = First Cluster number
  4188                              <1> 	; EDX = File Size
  4189                              <1> 
  4190 0000DB6F A3[51040300]        <1> 	mov	[ii], eax
  4191 0000DB74 8915[55040300]      <1> 	mov	[i.size], edx
  4192                              <1> 
  4193                              <1> ;sysexec_1:
  4194                              <1> 	; 13/11/2017 - TRDOS 386 (TRDOS v2.0)
  4195                              <1> 	; 24/06/2015 - 23/10/2015 (Retro UNIX 386 v1)
  4196                              <1>         ; Moving arguments to the end of [u.upage]
  4197                              <1> 	; (by regarding page borders in user's memory space)
  4198                              <1> 	;
  4199                              <1> 	; 10/10/2015
  4200                              <1> 	; 21/07/2015
  4201 0000DB7A 89E5                <1> 	mov	ebp, esp ; (**)
  4202                              <1> 	; 18/10/2015
  4203 0000DB7C 89EF                <1> 	mov 	edi, ebp
  4204 0000DB7E B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
  4205                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
  4206 0000DB83 29CF                <1> 	sub	edi, ecx
  4207 0000DB85 89FC                <1> 	mov	esp, edi ; *!*
  4208 0000DB87 31C0                <1> 	xor	eax, eax
  4209 0000DB89 A3[8C030300]        <1> 	mov 	[u.nread], eax ; 0
  4210 0000DB8E 66A3[4A040300]      <1> 	mov	[argc], ax ; 0 ; 13/11/2017
  4211 0000DB94 49                  <1> 	dec	ecx ; 256 - 1
  4212 0000DB95 890D[88030300]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
  4213                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
  4214                              <1> sysexec_2:
  4215 0000DB9B 8B35[4C040300]      <1> 	mov	esi, [argv] ; 18/10/2015 
  4216 0000DBA1 E866000000          <1> 	call	get_argp
  4217 0000DBA6 B904000000          <1> 	mov	ecx, 4 ; mov ecx, 4
  4218                              <1> sysexec_3:
  4219 0000DBAB 21C0                <1> 	and	eax, eax
  4220 0000DBAD 0F8429050000        <1>         jz      sysexec_6
  4221                              <1> 	; 18/10/2015
  4222 0000DBB3 010D[4C040300]      <1> 	add	[argv], ecx ; 4
  4223 0000DBB9 66FF05[4A040300]    <1> 	inc	word [argc]
  4224                              <1> 	;
  4225 0000DBC0 A3[84030300]        <1> 	mov	[u.base], eax
  4226                              <1>  	; 23/10/2015
  4227 0000DBC5 66C705[C4030300]00- <1> 	mov	word [u.pcount], 0
  4227 0000DBCD 00                  <1>
  4228                              <1> sysexec_4:
  4229 0000DBCE E8A10B0000          <1> 	call	cpass ; get a character from user's core memory
  4230 0000DBD3 750E                <1>         jnz	short sysexec_5
  4231                              <1> 		; (max. 255 chars + null)
  4232                              <1> 	; 18/10/2015
  4233 0000DBD5 28C0                <1> 	sub 	al, al
  4234 0000DBD7 AA                  <1> 	stosb
  4235 0000DBD8 FF05[8C030300]      <1> 	inc	dword [u.nread]
  4236 0000DBDE E9F9040000          <1> 	jmp	sysexec_6 ; 24/04/2016
  4237                              <1> sysexec_5:
  4238 0000DBE3 AA                  <1> 	stosb
  4239 0000DBE4 20C0                <1> 	and 	al, al
  4240 0000DBE6 75E6                <1> 	jnz	short sysexec_4
  4241 0000DBE8 B904000000          <1> 	mov	ecx, 4
  4242 0000DBED 390D[48040300]      <1> 	cmp	[ncount], ecx ; 4
  4243 0000DBF3 72A6                <1> 	jb	short sysexec_2
  4244 0000DBF5 8B35[44040300]      <1> 	mov	esi, [nbase]
  4245 0000DBFB 010D[44040300]      <1> 	add	[nbase], ecx ; 4	
  4246 0000DC01 66290D[48040300]    <1> 	sub	[ncount], cx 
  4247 0000DC08 8B06                <1> 	mov	eax, [esi]
  4248 0000DC0A EB9F                <1> 	jmp	short sysexec_3
  4249                              <1> 
  4250                              <1> get_argp:
  4251                              <1> 	; 14/11/2017 - TRDOS 386 (TRDOS v2.0)
  4252                              <1> 	; 18/10/2015 (nbase, ncount)
  4253                              <1> 	; 21/07/2015
  4254                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
  4255                              <1> 	; Get (virtual) address of argument from user's core memory
  4256                              <1> 	;
  4257                              <1> 	; INPUT:
  4258                              <1> 	;	esi = virtual address of argument pointer
  4259                              <1> 	; OUTPUT:
  4260                              <1> 	;	eax = virtual address of argument
  4261                              <1> 	;
  4262                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
  4263                              <1> 	;
  4264 0000DC0C 833D[BC030300]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
  4265                              <1> 				    ; (the caller is kernel)
  4266 0000DC13 7667                <1>         jna     short get_argpk 
  4267                              <1> 	;
  4268 0000DC15 89F3                <1>      	mov	ebx, esi
  4269 0000DC17 E8A576FFFF          <1> 	call	get_physical_addr ; get physical address
  4270 0000DC1C 0F8289000000        <1>         jc      get_argp_err
  4271 0000DC22 A3[44040300]        <1> 	mov 	[nbase], eax ; physical address	
  4272 0000DC27 66890D[48040300]    <1> 	mov	[ncount], cx ; remain byte count in page (1-4096)
  4273 0000DC2E B804000000          <1> 	mov	eax, 4 ; 21/07/2015
  4274 0000DC33 6639C1              <1> 	cmp	cx, ax ; 4
  4275 0000DC36 735D                <1> 	jnb	short get_argp2
  4276 0000DC38 89F3                <1> 	mov	ebx, esi
  4277 0000DC3A 01CB                <1> 	add	ebx, ecx
  4278 0000DC3C E88076FFFF          <1> 	call	get_physical_addr ; get physical address
  4279 0000DC41 7268                <1> 	jc	short get_argp_err
  4280                              <1> 	;push	esi
  4281 0000DC43 89C6                <1> 	mov	esi, eax
  4282 0000DC45 66870D[48040300]    <1> 	xchg	cx, [ncount]
  4283 0000DC4C 8735[44040300]      <1> 	xchg	esi, [nbase]
  4284 0000DC52 B504                <1> 	mov	ch, 4
  4285 0000DC54 28CD                <1> 	sub	ch, cl
  4286                              <1> get_argp0:
  4287 0000DC56 AC                  <1> 	lodsb
  4288 0000DC57 6650                <1> 	push	ax
  4289 0000DC59 FEC9                <1> 	dec	cl
  4290 0000DC5B 75F9                <1>         jnz     short get_argp0
  4291 0000DC5D 8B35[44040300]      <1> 	mov	esi, [nbase]
  4292                              <1> 	; 21/07/2015
  4293 0000DC63 0FB6C5              <1> 	movzx	eax, ch
  4294 0000DC66 0105[44040300]      <1> 	add	[nbase], eax
  4295 0000DC6C 662905[48040300]    <1> 	sub	[ncount], ax
  4296                              <1> get_argp1:
  4297 0000DC73 AC                  <1> 	lodsb
  4298 0000DC74 FECD                <1> 	dec	ch
  4299 0000DC76 7447                <1>         jz      short get_argp3
  4300 0000DC78 6650                <1>         push	ax
  4301 0000DC7A EBF7                <1> 	jmp     short get_argp1
  4302                              <1> get_argpk:
  4303                              <1> 	; Argument is in kernel's memory space
  4304 0000DC7C 66C705[48040300]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
  4304 0000DC84 10                  <1>
  4305 0000DC85 8935[44040300]      <1> 	mov	[nbase], esi
  4306 0000DC8B 8305[44040300]04    <1> 	add	dword [nbase], 4
  4307 0000DC92 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physcal addr.
  4308 0000DC94 C3                  <1> 	retn
  4309                              <1> get_argp2:
  4310                              <1> 	; 21/07/2015
  4311                              <1> 	;mov	eax, 4
  4312 0000DC95 8B15[44040300]      <1> 	mov 	edx, [nbase] ; 18/10/2015
  4313 0000DC9B 0105[44040300]      <1> 	add	[nbase], eax
  4314 0000DCA1 662905[48040300]    <1> 	sub	[ncount], ax
  4315                              <1> 	;
  4316 0000DCA8 8B02                <1> 	mov	eax, [edx]
  4317 0000DCAA C3                  <1> 	retn
  4318                              <1> get_argp_err:
  4319 0000DCAB A3[C8030300]        <1> 	mov	[u.error], eax
  4320                              <1> 	; 14/11/2017
  4321 0000DCB0 B801000000          <1> 	mov	eax, ERR_BAD_CMD_ARG ; 01h ; TRDOS 8086
  4322 0000DCB5 A3[64030300]        <1> 	mov	[u.r0], eax
  4323 0000DCBA E95AEAFFFF          <1> 	jmp	error
  4324                              <1> get_argp3:
  4325 0000DCBF B103                <1> 	mov	cl, 3
  4326                              <1> get_argp4:
  4327 0000DCC1 C1E008              <1> 	shl	eax, 8
  4328 0000DCC4 665A                <1> 	pop	dx
  4329 0000DCC6 88D0                <1> 	mov 	al, dl
  4330 0000DCC8 E2F7                <1>         loop    get_argp4
  4331                              <1> 	;pop	esi
  4332 0000DCCA C3                  <1> 	retn	
  4333                              <1> 
  4334                              <1> sysstat: 
  4335                              <1> 	; 13/01/2017 - TRDOS 386 (TRDOS v2.0)
  4336                              <1> 	; temporary !
  4337 0000DCCB B801000000          <1> 	mov	eax, ERR_INV_FNUMBER ; 'invalid function number !'
  4338 0000DCD0 A3[C8030300]        <1>         mov     [u.error], eax
  4339 0000DCD5 A3[64030300]        <1>         mov     [u.r0], eax 
  4340 0000DCDA E93AEAFFFF          <1> 	jmp	error
  4341                              <1> 
  4342                              <1> sysfstat: 
  4343                              <1> 	; 13/01/2017 - TRDOS 386 (TRDOS v2.0)
  4344                              <1> 	; temporary !
  4345 0000DCDF B801000000          <1> 	mov	eax, ERR_INV_FNUMBER ; 'invalid function number !'
  4346 0000DCE4 A3[C8030300]        <1>         mov     [u.error], eax
  4347 0000DCE9 A3[64030300]        <1>         mov     [u.r0], eax 
  4348 0000DCEE E926EAFFFF          <1> 	jmp	error
  4349                              <1> 
  4350                              <1> fclose:
  4351                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
  4352                              <1> 	;
  4353                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
  4354                              <1> 	;            (32 bit offset pointer modification)
  4355                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
  4356                              <1> 	;
  4357                              <1> 	; Given the file descriptor (index to the u.fp list)
  4358                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
  4359                              <1> 	; If i-node is active (i-number > 0) the entry in 
  4360                              <1> 	; u.fp list is cleared. If all the processes that opened
  4361                              <1> 	; that file close it, then fsp etry is freed and the file
  4362                              <1> 	; is closed. If not a return is taken. 
  4363                              <1> 	; If the file has been deleted while open, 'anyi' is called
  4364                              <1> 	; to see anyone else has it open, i.e., see if it is appears
  4365                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
  4366                              <1> 	; a check is made to see if the file is special.	
  4367                              <1> 	;
  4368                              <1> 	; INPUTS ->
  4369                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
  4370                              <1> 	;    u.fp - list of entries in the fsp table
  4371                              <1> 	;    fsp - table of entries (4 words/entry) of open files.	 
  4372                              <1> 	; OUTPUTS ->
  4373                              <1> 	;    r1 - contains the same file descriptor
  4374                              <1> 	;    r2 - contains i-number
  4375                              <1> 	;
  4376                              <1> 	; ((AX = R1))
  4377                              <1> 	; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))
  4378                              <1> 	;
  4379                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
  4380                              <1> 	;              if i-number of the file is 0. (error)  	
  4381                              <1> 	;
  4382                              <1> 	; TRDOS 386 (06/10/2016)
  4383                              <1> 	; 
  4384                              <1> 	; INPUT:
  4385                              <1> 	;	EAX = File Handle (File Descriptor, File Index)
  4386                              <1> 	;
  4387                              <1> 	; OUTPUT:
  4388                              <1> 	;	CF = 1 -> File not open !
  4389                              <1> 	;	CF = 0 -> OK!
  4390                              <1> 	;	     EBX = File Number (System)
  4391                              <1> 	;	     [cdev] = Logical DOS Drive Number
  4392                              <1> 	;	     EAX = File Handle/Number (user) 	
  4393                              <1> 	;
  4394                              <1> 	; Modified Registers: EBX
  4395                              <1> 
  4396 0000DCF3 50                  <1> 	push	eax ; File handle
  4397                              <1> 	
  4398 0000DCF4 E846000000          <1> 	call	getf
  4399 0000DCF9 0F8207240000        <1> 	jc	device_close ; eax = device number
  4400                              <1> 
  4401 0000DCFF 80BB[C6680100]01    <1> 	cmp	byte [ebx+OF_MODE], 1 ; open mode ; 0 = empty entry
  4402 0000DD06 722E                <1> 	jb	short fclose_1	      ; 1 = read, 2 = write
  4403                              <1> 	
  4404 0000DD08 83F801              <1> 	cmp	eax, 1 ; is the first cluster number > 0
  4405 0000DD0B 7229                <1> 	jb	short fclose_1 ; no, this is empty entry
  4406                              <1> 
  4407                              <1> fclose_0:
  4408 0000DD0D FE8B[DA680100]      <1> 	dec	byte [ebx+OF_OPENCOUNT] ; decrement the number of processes 
  4409                              <1> 			                ; that have opened the file
  4410 0000DD13 7921                <1> 	jns	short fclose_1 ; jump if not negative (jump if bit 7 is 0)	 
  4411                              <1> 			; if all processes haven't closed the file, return
  4412                              <1> 	;
  4413                              <1> 	; eax ; First cluster
  4414 0000DD15 31C0                <1> 	xor	eax, eax ; 0
  4415 0000DD17 8883[C6680100]      <1> 	mov	[ebx+OF_MODE], al ; 0 = empty entry
  4416                              <1> 	;mov	[ebx+OF_STATUS], al ; 0 = empty entry
  4417 0000DD1D 66C1E302            <1> 	shl	bx, 2 
  4418 0000DD21 8983[94680100]      <1> 	mov	[ebx+OF_FCLUSTER], eax ; 0
  4419 0000DD27 8983[AC690100]      <1> 	mov	[ebx+OF_CCLUSTER], eax ; 0
  4420                              <1> 	;mov	[ebx+OF_CCINDEX], eax ; 0
  4421 0000DD2D A3[74030300]        <1> 	mov	[u.fofp], eax ; 0
  4422 0000DD32 66C1EB02            <1> 	shr	bx, 2
  4423                              <1> fclose_1: ; 1:
  4424 0000DD36 58                  <1> 	pop	eax ; File handle (File Descriptor, File Index)
  4425 0000DD37 C680[6A030300]00    <1> 	mov	byte [eax+u.fp], 0 ; clear that entry in the u.fp list
  4426 0000DD3E C3                  <1> 	retn
  4427                              <1> 
  4428                              <1> getf:
  4429                              <1> 	; 12/10/2016
  4430                              <1> 	; 11/10/2016
  4431                              <1> 	; 08/10/2016
  4432                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
  4433                              <1> 	; / get the device number and the i-number of an open file
  4434                              <1> 	; 13/05/2015
  4435                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  4436                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
  4437                              <1> 	;
  4438 0000DD3F 89C3                <1> 	mov	ebx, eax
  4439                              <1> getf1: 
  4440 0000DD41 83FB0A              <1> 	cmp	ebx, 10
  4441 0000DD44 730A                <1>         jnb	short getf2
  4442 0000DD46 8A9B[6A030300]      <1> 	mov	bl, [ebx+u.fp]
  4443 0000DD4C 08DB                <1> 	or	bl, bl
  4444 0000DD4E 7503                <1> 	jnz	short getf3
  4445                              <1> getf2:
  4446                              <1> 	; 'File not open !' error (ax=0)
  4447 0000DD50 29C0                <1> 	sub	eax, eax
  4448 0000DD52 C3                  <1> 	retn
  4449                              <1> getf3:	
  4450 0000DD53 F6C380              <1> 	test	bl, 80h
  4451 0000DD56 7530                <1> 	jnz	short getf5 ; device
  4452 0000DD58 FECB                <1> 	dec	bl ; 0 based
  4453 0000DD5A 8A83[BC680100]      <1> 	mov	al, [ebx+OF_DRIVE]
  4454 0000DD60 A2[46030300]        <1> 	mov	[cdev], al
  4455 0000DD65 C0E302              <1> 	shl	bl, 2 ; *4 (dword offset)
  4456 0000DD68 8B83[0C690100]      <1> 	mov	eax, [ebx+OF_SIZE]
  4457 0000DD6E A3[55040300]        <1> 	mov	[i.size], eax ; file size
  4458 0000DD73 8D83[E4680100]      <1> 	lea	eax, [ebx+OF_POINTER] ;12/10/2016
  4459 0000DD79 A3[74030300]        <1> 	mov	[u.fofp], eax
  4460 0000DD7E 8B83[94680100]      <1> 	mov	eax, [ebx+OF_FCLUSTER]
  4461 0000DD84 C0EB02              <1> 	shr	bl, 2 ; /4 (byte offset) 
  4462                              <1> getf4:
  4463 0000DD87 C3                  <1> 	retn
  4464                              <1> getf5: 
  4465                              <1> 	; get device number
  4466 0000DD88 80E37F              <1> 	and	bl, 7Fh ; 1 to 7Fh
  4467 0000DD8B FECB                <1> 	dec	bl ; 0 based (0 to 7Eh)
  4468 0000DD8D 8A83[EE660100]      <1> 	mov	al, [ebx+DEV_DRIVER]
  4469 0000DD93 8AAB[58660100]      <1> 	mov	ch, [ebx+DEV_ACCESS]
  4470 0000DD99 8A8B[0C670100]      <1> 	mov	cl, [ebx+DEV_OPENMODE]
  4471 0000DD9F 80E5FE              <1> 	and	ch, 0FEh ; reset bit 0 ; dev_close
  4472 0000DDA2 F9                  <1> 	stc ; cf = 1 
  4473 0000DDA3 C3                  <1> 	retn	
  4474                              <1> 
  4475                              <1> trans_addr_nmbp:
  4476                              <1> 	; 18/10/2015
  4477                              <1> 	; 12/10/2015
  4478 0000DDA4 8B2D[7C030300]      <1> 	mov 	ebp, [u.namep]
  4479                              <1> trans_addr_nm: 
  4480                              <1> 	; Convert virtual (pathname) address to physical address
  4481                              <1> 	; (Retro UNIX 386 v1 feature only !)
  4482                              <1> 	; 18/10/2015
  4483                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
  4484                              <1> 	; 02/07/2015
  4485                              <1> 	; 17/06/2015
  4486                              <1> 	; 16/06/2015
  4487                              <1> 	;
  4488                              <1> 	; INPUTS: 
  4489                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
  4490                              <1> 	;	[u.pgdir] = user's page directory
  4491                              <1> 	; OUTPUT:
  4492                              <1> 	;       esi = physical address of the pathname
  4493                              <1> 	;	ecx = remain byte count in the page
  4494                              <1> 	;
  4495                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
  4496                              <1> 	;
  4497 0000DDAA 833D[BC030300]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
  4498 0000DDB1 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
  4499                              <1> 				     ; it is already physical address
  4500 0000DDB3 50                  <1>    	push	eax	
  4501 0000DDB4 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
  4502 0000DDB6 E80675FFFF          <1>        	call	get_physical_addr ; get physical address
  4503 0000DDBB 7204                <1> 	jc	short tr_addr_nm_err
  4504                              <1> 	; 18/10/2015
  4505                              <1> 	; eax = physical address 
  4506                              <1> 	; cx = remain byte count in page (1-4096) 
  4507                              <1> 		; 12/10/2015 (cx = [u.pncount])
  4508 0000DDBD 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
  4509 0000DDBF 58                  <1> 	pop	eax 
  4510 0000DDC0 C3                  <1> 	retn
  4511                              <1> 
  4512                              <1> tr_addr_nm_err:
  4513 0000DDC1 A3[C8030300]        <1> 	mov	[u.error], eax
  4514                              <1> 	;pop 	eax
  4515 0000DDC6 E94EE9FFFF          <1> 	jmp	error
  4516                              <1> 
  4517                              <1> trans_addr_nmk:
  4518                              <1> 	; 12/10/2015
  4519                              <1> 	; 02/07/2015
  4520 0000DDCB 8B35[7C030300]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
  4521 0000DDD1 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
  4522 0000DDD5 C3                  <1> 	retn
  4523                              <1> 
  4524                              <1> 
  4525                              <1> sysbreak:
  4526                              <1> 	; 18/10/2015
  4527                              <1> 	; 07/10/2015
  4528                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  4529                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
  4530                              <1> 	;
  4531                              <1> 	; 'sysbreak' sets the programs break points. 
  4532                              <1> 	; It checks the current break point (u.break) to see if it is
  4533                              <1> 	; between "core" and the stack (sp). If it is, it is made an
  4534                              <1> 	; even address (if it was odd) and the area between u.break
  4535                              <1> 	; and the stack is cleared. The new breakpoint is then put
  4536                              <1> 	; in u.break and control is passed to 'sysret'.
  4537                              <1> 	;
  4538                              <1> 	; Calling sequence:
  4539                              <1> 	;	sysbreak; addr
  4540                              <1> 	; Arguments: -
  4541                              <1> 	;	
  4542                              <1> 	; Inputs: u.break - current breakpoint
  4543                              <1> 	; Outputs: u.break - new breakpoint 
  4544                              <1> 	;	area between old u.break and the stack (sp) is cleared.
  4545                              <1> 	; ...............................................................
  4546                              <1> 	;	
  4547                              <1> 	; Retro UNIX 8086 v1 modification:
  4548                              <1> 	;	The user/application program puts breakpoint address
  4549                              <1> 	;       in BX register as 'sysbreak' system call argument.
  4550                              <1> 	; 	(argument transfer method 1)
  4551                              <1> 	;
  4552                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
  4553                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
  4554                              <1> 	;  NOTE:
  4555                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
  4556                              <1> 	;	'u.break' address) of user's memory for original unix's
  4557                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
  4558                              <1> 
  4559                              <1> 		; mov u.break,r1 / move users break point to r1
  4560                              <1> 		; cmp r1,$core / is it the same or lower than core?
  4561                              <1> 		; blos 1f / yes, 1f
  4562                              <1> 	; 23/06/2015
  4563 0000DDD6 8B2D[90030300]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
  4564                              <1> 	;and	ebp, ebp
  4565                              <1> 	;jz	short sysbreak_3 
  4566                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
  4567                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
  4568 0000DDDC 8B15[5C030300]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
  4569 0000DDE2 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
  4570                              <1> 	; 07/10/2015
  4571 0000DDE5 891D[90030300]      <1> 	mov	[u.break], ebx ; virtual address !!!
  4572                              <1> 	;
  4573 0000DDEB 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
  4574                              <1> 			   ; with top of user's stack (virtual!)
  4575 0000DDED 7323                <1> 	jnb	short sysbreak_3
  4576                              <1> 		; cmp r1,sp / is it the same or higher 
  4577                              <1> 			  ; / than the stack?
  4578                              <1> 		; bhis 1f / yes, 1f
  4579 0000DDEF 89DE                <1> 	mov	esi, ebx
  4580 0000DDF1 29EE                <1> 	sub	esi, ebp ; new break point - old break point
  4581 0000DDF3 761D                <1> 	jna	short sysbreak_3 
  4582                              <1> 	;push	ebx
  4583                              <1> sysbreak_1:
  4584 0000DDF5 89EB                <1> 	mov	ebx, ebp  
  4585 0000DDF7 E8C574FFFF          <1> 	call	get_physical_addr ; get physical address
  4586 0000DDFC 72C3                <1> 	jc	tr_addr_nm_err
  4587                              <1> 	; 18/10/2015
  4588 0000DDFE 89C7                <1> 	mov	edi, eax 
  4589 0000DE00 29C0                <1> 	sub	eax, eax ; 0
  4590                              <1> 		 ; ECX = remain byte count in page (1-4096)
  4591 0000DE02 39CE                <1> 	cmp	esi, ecx
  4592 0000DE04 7302                <1> 	jnb	short sysbreak_2
  4593 0000DE06 89F1                <1> 	mov	ecx, esi
  4594                              <1> sysbreak_2:
  4595 0000DE08 29CE                <1> 	sub	esi, ecx
  4596 0000DE0A 01CD                <1> 	add	ebp, ecx
  4597 0000DE0C F3AA                <1> 	rep 	stosb
  4598 0000DE0E 09F6                <1> 	or	esi, esi
  4599 0000DE10 75E3                <1> 	jnz	short sysbreak_1
  4600                              <1> 	;
  4601                              <1> 		; bit $1,r1 / is it an odd address
  4602                              <1> 		; beq 2f / no, its even
  4603                              <1> 		; clrb (r1)+ / yes, make it even
  4604                              <1> 	; 2: / clear area between the break point and the stack
  4605                              <1> 		; cmp r1,sp / is it higher or same than the stack
  4606                              <1> 		; bhis 1f / yes, quit
  4607                              <1> 		; clr (r1)+ / clear word
  4608                              <1> 		; br 2b / go back
  4609                              <1> 	;pop	ebx
  4610                              <1> sysbreak_3: ; 1:
  4611                              <1> 	;mov	[u.break], ebx ; virtual address !!!
  4612                              <1> 		; jsr r0,arg; u.break / put the "address" 
  4613                              <1> 			; / in u.break (set new break point)
  4614                              <1> 		; br sysret4 / br sysret
  4615 0000DE12 E922E9FFFF          <1> 	jmp	sysret
  4616                              <1> 
  4617                              <1> sysseek: ; / moves read write pointer in an fsp entry
  4618                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0)
  4619                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4620                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  4621                              <1> 	;
  4622                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
  4623                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
  4624                              <1> 	; The file descriptor refers to a file open for reading or
  4625                              <1> 	; writing. The read (or write) pointer is set as follows:
  4626                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
  4627                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
  4628                              <1> 	;	  current location plus offset.
  4629                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
  4630                              <1> 	;	  size of file plus offset.
  4631                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
  4632                              <1> 	;
  4633                              <1> 	; Calling sequence:
  4634                              <1> 	;	sysseek; offset; ptrname
  4635                              <1> 	; Arguments:
  4636                              <1> 	;	offset - number of bytes desired to move 
  4637                              <1> 	;		 the r/w pointer
  4638                              <1> 	;	ptrname - a switch indicated above
  4639                              <1> 	;
  4640                              <1> 	; Inputs: r0 - file descriptor 
  4641                              <1> 	; Outputs: -
  4642                              <1> 	; ...............................................................
  4643                              <1> 	;	
  4644                              <1> 	; Retro UNIX 8086 v1 modification: 
  4645                              <1> 	;       'sysseek' system call has three arguments; so,
  4646                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
  4647                              <1> 	;	* 2nd argument, offset is in CX register
  4648                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register	
  4649                              <1> 
  4650 0000DE17 E821000000          <1> 	call	seektell
  4651                              <1> 	; EAX = Current R/W pointer of the file
  4652                              <1> 	; EBX = [u.fofp]
  4653                              <1> 	; [u.base] = offset (ECX input)
  4654                              <1> 
  4655 0000DE1C 0305[84030300]      <1> 	add	eax, [u.base]
  4656 0000DE22 8903                <1> 	mov	[ebx], eax
  4657 0000DE24 E910E9FFFF          <1> 	jmp	sysret
  4658                              <1> 
  4659                              <1> systell: ; / get the r/w pointer
  4660                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0) - temporary !-
  4661                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4662                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  4663                              <1> 	;
  4664                              <1> 	; Retro UNIX 8086 v1 modification:
  4665                              <1> 	; ! 'systell' does not work in original UNIX v1,
  4666                              <1> 	; 	    it returns with error !
  4667                              <1> 	; Inputs: r0 - file descriptor 
  4668                              <1> 	; Outputs: r0 - file r/w pointer
  4669                              <1> 
  4670                              <1> 	;xor	ecx, ecx ; 0
  4671 0000DE29 BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
  4672                              <1> 	;call 	seektell
  4673 0000DE2E E810000000          <1> 	call 	seektell0 ; 05/08/2013
  4674                              <1> 	;; 06/11/2016
  4675                              <1> 	;; mov	eax, [ebx]
  4676 0000DE33 A3[64030300]        <1> 	mov	[u.r0], eax
  4677 0000DE38 E9FCE8FFFF          <1> 	jmp	sysret
  4678                              <1> 
  4679                              <1> ; Original unix v1 'systell' system call:
  4680                              <1> 		; jsr r0,seektell
  4681                              <1> 		; br error4
  4682                              <1> 
  4683                              <1> seektell:
  4684                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0)
  4685                              <1> 	; 03/01/2016
  4686                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4687                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
  4688                              <1> 	;
  4689                              <1> 	; 'seektell' puts the arguments from sysseek and systell
  4690                              <1> 	; call in u.base and u.count. It then gets the i-number of
  4691                              <1> 	; the file from the file descriptor in u.r0 and by calling
  4692                              <1> 	; getf. The i-node is brought into core and then u.count
  4693                              <1> 	; is checked to see it is a 0, 1, or 2.
  4694                              <1> 	; If it is 0 - u.count stays the same
  4695                              <1> 	;          1 - u.count = offset (u.fofp)
  4696                              <1> 	;	   2 - u.count = i.size (size of file)
  4697                              <1> 	; 	 		
  4698                              <1> 	; !! Retro UNIX 8086 v1 modification:
  4699                              <1> 	;	Argument 1, file descriptor is in BX;
  4700                              <1> 	;	Argument 2, offset is in CX;
  4701                              <1> 	;	Argument 3, ptrname/switch is in DX register.	
  4702                              <1> 	;
  4703                              <1> 	; ((Return -> eax = base for offset (position= base+offset))
  4704                              <1> 	;
  4705 0000DE3D 890D[84030300]      <1> 	mov 	[u.base], ecx ; offset
  4706                              <1> seektell0:
  4707 0000DE43 8915[88030300]      <1> 	mov 	[u.count], edx
  4708                              <1> 	; EBX = file descriptor (file number)
  4709 0000DE49 E8F3FEFFFF          <1> 	call	getf1
  4710                              <1> 	; EAX = First cluster of the file
  4711                              <1> 	; EBX = File number (Open file number)
  4712                              <1> 	; [u.fofp] = Pointer to File pointer
  4713                              <1> 	; [i.size] = File size
  4714                              <1> 
  4715 0000DE4E 09C0                <1> 	or	eax, eax
  4716 0000DE50 7514                <1> 	jnz	short seektell1
  4717                              <1> 
  4718 0000DE52 B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN
  4719 0000DE57 A3[64030300]        <1> 	mov	[u.r0], eax 
  4720 0000DE5C A3[C8030300]        <1> 	mov	dword [u.error], eax ; 'file not open !'
  4721 0000DE61 E9B3E8FFFF          <1> 	jmp	error
  4722                              <1> 
  4723                              <1> seektell1:
  4724 0000DE66 8B1D[74030300]      <1>         mov     ebx, [u.fofp]
  4725 0000DE6C 803D[88030300]01    <1> 	cmp	byte [u.count], 1
  4726 0000DE73 7705                <1> 	ja	short seektell2
  4727 0000DE75 7409                <1> 	je	short seektell3
  4728 0000DE77 31C0                <1> 	xor	eax, eax
  4729 0000DE79 C3                  <1> 	retn
  4730                              <1> 
  4731                              <1> seektell2:
  4732 0000DE7A A1[55040300]        <1>         mov   	eax, [i.size]
  4733 0000DE7F C3                  <1> 	retn
  4734                              <1> 
  4735                              <1> seektell3:
  4736 0000DE80 8B03                <1> 	mov	eax, [ebx]
  4737 0000DE82 C3                  <1> 	retn
  4738                              <1> 
  4739                              <1> sysintr: ; / set interrupt handling
  4740                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4741                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
  4742                              <1> 	;
  4743                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
  4744                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
  4745                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
  4746                              <1> 	; If one does the interrupt character in the tty buffer is
  4747                              <1> 	; cleared and 'sysret'is called. If one does not exits
  4748                              <1> 	; 'sysret' is just called.	
  4749                              <1> 	;
  4750                              <1> 	; Calling sequence:
  4751                              <1> 	;	sysintr; arg
  4752                              <1> 	; Argument:
  4753                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
  4754                              <1> 	;	    - if 1, intterupts cause their normal result
  4755                              <1> 	;		 i.e force an exit.
  4756                              <1> 	;	    - if arg is a location within the program,
  4757                              <1> 	;		control is passed to that location when
  4758                              <1> 	;		an interrupt occurs.	
  4759                              <1> 	; Inputs: -
  4760                              <1> 	; Outputs: -
  4761                              <1> 	; ...............................................................
  4762                              <1> 	;	
  4763                              <1> 	; Retro UNIX 8086 v1 modification: 
  4764                              <1> 	;       'sysintr' system call sets u.intr to value of BX
  4765                              <1> 	;	then branches into sysquit.
  4766                              <1> 	;
  4767 0000DE83 66891D[AA030300]    <1> 	mov	[u.intr], bx
  4768                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
  4769                              <1> 		; br 1f / go into quit routine
  4770 0000DE8A E9AAE8FFFF          <1> 	jmp	sysret
  4771                              <1> 
  4772                              <1> sysquit:
  4773                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4774                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
  4775                              <1> 	;
  4776                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
  4777                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
  4778                              <1> 	; tty exists. If one does the interrupt character in the tty
  4779                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
  4780                              <1> 	; 'sysret' is just called.	
  4781                              <1> 	;
  4782                              <1> 	; Calling sequence:
  4783                              <1> 	;	sysquit; arg
  4784                              <1> 	; Argument:
  4785                              <1> 	;	arg - if 0, this call diables quit signals from the
  4786                              <1> 	;		typewriter (ASCII FS)
  4787                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
  4788                              <1> 	;		cease and a core image to be produced.
  4789                              <1> 	;		 i.e force an exit.
  4790                              <1> 	;	    - if arg is an addres in the program,
  4791                              <1> 	;		a quit causes control to sent to that
  4792                              <1> 	;		location.	
  4793                              <1> 	; Inputs: -
  4794                              <1> 	; Outputs: -
  4795                              <1> 	; ...............................................................
  4796                              <1> 	;	
  4797                              <1> 	; Retro UNIX 8086 v1 modification: 
  4798                              <1> 	;       'sysquit' system call sets u.quit to value of BX
  4799                              <1> 	;	then branches into 'sysret'.
  4800                              <1> 	;
  4801 0000DE8F 66891D[AC030300]    <1> 	mov	[u.quit], bx
  4802 0000DE96 E99EE8FFFF          <1> 	jmp	sysret
  4803                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
  4804                              <1> 	;1:
  4805                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
  4806                              <1> 			      ; / to r1
  4807                              <1> 		; beq sysret4 / return to user
  4808                              <1> 		; clrb 6(r1) / clear the interrupt character 
  4809                              <1> 			   ; / in the tty buffer
  4810                              <1> 		; br sysret4 / return to user
  4811                              <1> 
  4812                              <1> anyi: 
  4813                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
  4814                              <1> 	; Major Modification!
  4815                              <1> 	; TRDOS 386 does not permit to delete a file while it is open 
  4816                              <1> 	; The role of 'anyi' procedure has beeen changed to ensure that.
  4817                              <1> 	; 	
  4818                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
  4819                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
  4820                              <1> 	;
  4821                              <1> 	; 'anyi' is called if a file deleted while open.
  4822                              <1> 	; "anyi" checks to see if someone else has opened this file.
  4823                              <1> 	;
  4824                              <1> 	; INPUTS ->
  4825                              <1> 	;    r1 - contains an i-number
  4826                              <1> 	;    fsp - start of table containing open files
  4827                              <1> 	;
  4828                              <1> 	; OUTPUTS ->
  4829                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
  4830                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
  4831                              <1> 	;    if file not found - bit in i-node map is cleared
  4832                              <1> 	;    			 (i-node is freed)
  4833                              <1> 	;               all blocks related to i-node are freed
  4834                              <1> 	;	        all flags in i-node are cleared
  4835                              <1> 	; ((AX = R1)) input
  4836                              <1> 	;
  4837                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
  4838                              <1>         ;    ((Modified registers: eDX, eCX, eBX, eSI, eDI, eBP))  
  4839                              <1> 	;
  4840                              <1> 	; / r1 contains an i-number
  4841                              <1> 
  4842                              <1> 	; TRDOS 386 (06/10/2016)
  4843                              <1> 	; 
  4844                              <1> 	; INPUT:
  4845                              <1> 	;	EAX = First Cluster
  4846                              <1> 	;	 DL = Logical DOS Drive Number
  4847                              <1> 	;
  4848                              <1> 	; OUTPUT:
  4849                              <1> 	;	CF = 1 -> EBX = File Handle/Number/Index
  4850                              <1> 	;	CF = 0 -> EBX = 0
  4851                              <1> 	;
  4852                              <1> 	; Modified Registers: EBX
  4853                              <1> 
  4854 0000DE9B 31DB                <1> 	xor	ebx, ebx
  4855                              <1> anyi_0: 
  4856 0000DE9D 80BB[C6680100]00    <1> 	cmp	byte [ebx+OF_MODE], 0 ; 0 = empty entry
  4857 0000DEA4 770A                <1> 	ja	short anyi_2 ; 1 (r), 2 (w) or 3 (r&w)
  4858                              <1> anyi_1:
  4859 0000DEA6 FEC3                <1> 	inc	bl
  4860 0000DEA8 80FB0A              <1> 	cmp	bl, OPENFILES ; max. count of open files
  4861 0000DEAB 72F0                <1> 	jb	short anyi_0
  4862 0000DEAD 31C0                <1> 	xor	eax, eax
  4863 0000DEAF C3                  <1> 	retn 
  4864                              <1> anyi_2:
  4865 0000DEB0 3A93[BC680100]      <1> 	cmp	dl, [ebx+OF_DRIVE]
  4866 0000DEB6 75EE                <1> 	jne	short anyi_1
  4867 0000DEB8 66C1E302            <1> 	shl	bx, 2 ; *4 (dword offset)
  4868 0000DEBC 3B83[94680100]      <1> 	cmp	eax, [ebx+OF_FCLUSTER]
  4869 0000DEC2 7406                <1> 	je	short anyi_3
  4870 0000DEC4 66C1EB02            <1> 	shr	bx, 2 ; /4 (byte offset)
  4871 0000DEC8 EBDC                <1> 	jmp	short anyi_1 	
  4872                              <1> anyi_3:
  4873 0000DECA 66C1EB02            <1> 	shr	bx, 2 ; /4 (bytes offset) (index)
  4874 0000DECE F9                  <1> 	stc
  4875 0000DECF C3                  <1> 	retn
  4876                              <1> 
  4877                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
  4878                              <1> ; Last Modification: 09/12/2015
  4879                              <1> 
  4880                              <1> syssleep:
  4881                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
  4882                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
  4883                              <1> 	;
  4884                              <1> 	; Retro UNIX 8086 v1 feature only
  4885                              <1> 	; (INPUT -> none)
  4886                              <1> 	;
  4887 0000DED0 0FB61D[B3030300]    <1> 	movzx	ebx, byte [u.uno] ; process number
  4888 0000DED7 8AA3[7F000300]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
  4889 0000DEDD E841190000          <1> 	call	sleep
  4890 0000DEE2 E952E8FFFF          <1> 	jmp	sysret
  4891                              <1> 
  4892                              <1> _vp_clr:
  4893                              <1> 	; Reset/Clear Video Page
  4894                              <1> 	;
  4895                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
  4896                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
  4897                              <1> 	;
  4898                              <1> 	; Retro UNIX 8086 v1 feature only !
  4899                              <1> 	;
  4900                              <1> 	; INPUTS -> 
  4901                              <1> 	;   BH = video page number	 
  4902                              <1> 	;
  4903                              <1> 	; OUTPUT ->
  4904                              <1> 	;   none
  4905                              <1> 	; ((Modified registers: eAX, BH, eCX, eDX, eSI, eDI))
  4906                              <1> 	;
  4907                              <1> 	; 04/12/2013
  4908 0000DEE7 28C0                <1> 	sub	al, al
  4909                              <1> 	; al = 0 (clear video page)
  4910                              <1> 	; bh = video page ; 13/05/2016
  4911 0000DEE9 B407                <1> 	mov	ah, 07h
  4912                              <1> 	; ah = 7 (attribute/color)
  4913 0000DEEB 6631C9              <1> 	xor 	cx, cx ; 0, left upper column (cl) & row (cl)
  4914 0000DEEE 66BA4F18            <1> 	mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
  4915 0000DEF2 E8433BFFFF          <1> 	call	_scroll_up
  4916                              <1> 	; bh = video page
  4917 0000DEF7 6631D2              <1> 	xor	dx, dx ; 0 (cursor position) 
  4918 0000DEFA E9793EFFFF          <1> 	jmp 	_set_cpos
  4919                              <1> 
  4920                              <1> sysmsg:
  4921                              <1> 	; 13/05/2016
  4922                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  4923                              <1> 	; 01/07/2015 - 11/11/2015 (Retro UNIX 386 v1)
  4924                              <1> 	; Print user-application message on user's console tty
  4925                              <1> 	;
  4926                              <1> 	; Input -> EBX = Message address
  4927                              <1> 	;	   ECX = Message length (max. 255)
  4928                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
  4929                              <1> 	;
  4930 0000DEFF 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
  4931 0000DF05 0F872EE8FFFF        <1> 	ja	sysret ; nothing to do with big message size
  4932 0000DF0B 08C9                <1> 	or	cl, cl
  4933 0000DF0D 0F8426E8FFFF        <1> 	jz	sysret
  4934 0000DF13 20D2                <1> 	and	dl, dl
  4935 0000DF15 7502                <1> 	jnz	short sysmsg0
  4936 0000DF17 B207                <1> 	mov	dl, 07h ; default color
  4937                              <1> 		; (black background, light gray character) 
  4938                              <1> sysmsg0:
  4939 0000DF19 891D[84030300]      <1> 	mov	[u.base], ebx
  4940 0000DF1F 8815[D7580100]      <1> 	mov	[ccolor], dl ; color attributes
  4941 0000DF25 89E5                <1> 	mov	ebp, esp
  4942 0000DF27 31DB                <1> 	xor	ebx, ebx ; 0
  4943 0000DF29 891D[8C030300]      <1> 	mov	[u.nread], ebx ; 0
  4944                              <1> 	;
  4945 0000DF2F 381D[C6030300]      <1> 	cmp	[u.kcall], bl ; 0
  4946 0000DF35 7769                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
  4947                              <1> 	;
  4948 0000DF37 890D[88030300]      <1> 	mov	[u.count], ecx
  4949 0000DF3D 41                  <1> 	inc	ecx ; + 00h ; ASCIIZ
  4950 0000DF3E 29CC                <1> 	sub	esp, ecx
  4951 0000DF40 89E7                <1> 	mov	edi, esp
  4952 0000DF42 89E6                <1> 	mov	esi, esp
  4953 0000DF44 66891D[C4030300]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
  4954                              <1> 	; 11/11/2015
  4955 0000DF4B 8A25[94030300]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
  4956                              <1> 	; 0 = none
  4957 0000DF51 FECC                <1> 	dec	ah
  4958 0000DF53 790C                <1> 	jns	short sysmsg1 
  4959 0000DF55 8A1D[B3030300]      <1> 	mov	bl, [u.uno] ; process number	
  4960 0000DF5B 8AA3[7F000300]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
  4961                              <1> sysmsg1:
  4962 0000DF61 8825[96030300]      <1> 	mov	[u.ttyn], ah
  4963                              <1> sysmsg2:
  4964 0000DF67 E808080000          <1> 	call	cpass
  4965 0000DF6C 7416                <1> 	jz	short sysmsg5
  4966 0000DF6E AA                  <1> 	stosb
  4967 0000DF6F 20C0                <1> 	and	al, al
  4968 0000DF71 75F4                <1> 	jnz	short sysmsg2
  4969                              <1> sysmsg3:
  4970 0000DF73 80FC07              <1> 	cmp	ah, 7 ; tty number
  4971 0000DF76 7711                <1> 	ja	short sysmsg6 ; serial port
  4972 0000DF78 E83E000000          <1> 	call	print_cmsg
  4973                              <1> sysmsg4:
  4974 0000DF7D 89EC                <1> 	mov	esp, ebp	
  4975 0000DF7F E9B5E7FFFF          <1> 	jmp	sysret
  4976                              <1> sysmsg5:
  4977 0000DF84 C60700              <1> 	mov	byte [edi], 0
  4978 0000DF87 EBEA                <1> 	jmp	short sysmsg3
  4979                              <1> sysmsg6:
  4980 0000DF89 8A06                <1> 	mov	al, [esi]
  4981 0000DF8B E891180000          <1> 	call	sndc
  4982 0000DF90 72EB                <1> 	jc	short sysmsg4
  4983 0000DF92 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
  4984 0000DF95 76E6                <1> 	jna	short sysmsg4
  4985 0000DF97 46                  <1> 	inc 	esi
  4986 0000DF98 8A25[96030300]      <1> 	mov	ah, [u.ttyn]
  4987 0000DF9E EBE9                <1> 	jmp	short sysmsg6
  4988                              <1> 
  4989                              <1> sysmsgk: ; Temporary (01/07/2015)
  4990                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
  4991                              <1> 	; (ECX -character count- will not be considered)
  4992 0000DFA0 8B35[84030300]      <1> 	mov	esi, [u.base]
  4993 0000DFA6 8A25[D6580100]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
  4994 0000DFAC 8825[96030300]      <1> 	mov	[u.ttyn], ah
  4995 0000DFB2 C605[C6030300]00    <1> 	mov	byte [u.kcall], 0
  4996 0000DFB9 EBB8                <1> 	jmp	short sysmsg3
  4997                              <1> 	
  4998                              <1> print_cmsg: 
  4999                              <1> 	; 18/11/2017
  5000                              <1> 	; 13/05/2016 - TRDOS 386 (TRDOS v2.0)
  5001                              <1> 	; 01/07/2015 (Retro UNIX 386 v1)
  5002                              <1> 	;
  5003                              <1> 	; print message (on user's console tty) 
  5004                              <1> 	;	with requested color
  5005                              <1> 	;
  5006                              <1> 	; INPUTS:
  5007                              <1> 	;	esi = message address
  5008                              <1> 	;	[u.ttyn] = tty number (0 to 7)
  5009                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
  5010                              <1> 	
  5011                              <1> 	;mov	bh, ah
  5012 0000DFBB 8A3D[96030300]      <1> 	mov	bh, [u.ttyn]
  5013                              <1> 	;mov	bl, [ccolor] ; *
  5014                              <1> pcmsg1:
  5015 0000DFC1 AC                  <1> 	lodsb
  5016 0000DFC2 20C0                <1> 	and 	al, al  ; 0
  5017 0000DFC4 740F                <1> 	jz 	short pcmsg2
  5018 0000DFC6 56                  <1> 	push 	esi
  5019 0000DFC7 8A1D[D7580100]      <1> 	mov	bl, [ccolor]  ; * (video.s 'u11'&'beep' change BL)
  5020                              <1> 	;mov	bh, [u.ttyn]
  5021 0000DFCD E8103DFFFF          <1> 	call 	_write_tty 
  5022 0000DFD2 5E                  <1> 	pop	esi
  5023 0000DFD3 EBEC                <1> 	jmp	short pcmsg1
  5024                              <1> pcmsg2:
  5025 0000DFD5 C3                  <1> 	retn
  5026                              <1> 
  5027                              <1> sysgeterr:
  5028                              <1> 	; 09/12/2015
  5029                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
  5030                              <1> 	; Get last error number or page fault count
  5031                              <1> 	; (for debugging)
  5032                              <1> 	;
  5033                              <1> 	; Input -> EBX = return type
  5034                              <1> 	;	   0 = last error code (which is in 'u.error')	
  5035                              <1> 	;	   FFFFFFFFh = page fault count for running process
  5036                              <1> 	;	   FFFFFFFEh = total page fault count
  5037                              <1> 	;	   1 .. FFFFFFFDh = undefined 
  5038                              <1> 	;
  5039                              <1> 	; Output -> EAX = last error number or page fault count
  5040                              <1> 	;	   (depending on EBX input)
  5041                              <1> 	; 	
  5042 0000DFD6 21DB                <1> 	and 	ebx, ebx
  5043 0000DFD8 750B                <1> 	jnz	short glerr_2
  5044                              <1> glerr_0:
  5045 0000DFDA A1[C8030300]        <1> 	mov	eax, [u.error]
  5046                              <1> glerr_1:
  5047 0000DFDF A3[64030300]        <1> 	mov	[u.r0], eax
  5048 0000DFE4 C3                  <1>  	retn
  5049                              <1> glerr_2:
  5050 0000DFE5 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
  5051 0000DFE6 74FD                <1> 	jz	short glerr_2 ; page fault count for process
  5052 0000DFE8 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
  5053 0000DFE9 75EF                <1> 	jnz	short glerr_0
  5054 0000DFEB A1[80050300]        <1> 	mov	eax, [PF_Count] ; total page fault count
  5055 0000DFF0 EBED                <1>         jmp     short glerr_1
  5056                              <1> glerr_3:
  5057 0000DFF2 A1[CC030300]        <1> 	mov 	eax, [u.pfcount]
  5058 0000DFF7 EBE6                <1> 	jmp	short glerr_1
  5059                              <1> 
  5060                              <1> load_and_run_file:
  5061                              <1> 	; 18/11/2017
  5062                              <1> 	; 22/01/2017
  5063                              <1> 	; 04/01/2017, 07/01/2017
  5064                              <1> 	; 24/10/2016
  5065                              <1> 	; 24/04/2016, 02/05/2016, 03/05/2016, 06/05/2016
  5066                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
  5067                              <1> 	; 23/10/2015 (Retro UNIX 386 v1, 'sysexec')
  5068                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
  5069                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
  5070                              <1> 	; EAX = First Cluster number
  5071                              <1> 	; EDX = File Size
  5072                              <1> 	; ESI = Argument list address
  5073                              <1> 	; [argc] = argument count
  5074                              <1> 	; [u.nread] = argument list length
  5075                              <1> 	; [esp] = return address to the caller (*)
  5076                              <1> 	;
  5077 0000DFF9 8935[4C040300]      <1> 	mov	[argv], esi
  5078 0000DFFF 8915[55040300]      <1> 	mov	[i.size], edx
  5079 0000E005 A3[51040300]        <1> 	mov	[ii], eax
  5080                              <1> 
  5081                              <1> 	;sti	; 07/01/2017
  5082                              <1> 	;mov	eax, [k_page_dir]
  5083                              <1> 	;mov	[u.pgdir], eax
  5084 0000E00A 31C0                <1> 	xor 	eax, eax ; clc ; *** ; 04/01/2017
  5085                              <1> 	;mov	[u.r0], eax ; 0 ; 07/01/2017
  5086                              <1> 
  5087                              <1> 	; 06/05/2016
  5088                              <1> 	; Set 'sysexit' return order to MainProg
  5089                              <1> 	;
  5090 0000E00C 58                  <1> 	pop	eax ; * 'loc_load_and_run_file_8:' address
  5091                              <1> 	;; 22/01/2017
  5092                              <1> 	;;cli ; 07/01/2017
  5093 0000E00D 8B25[44580100]      <1> 	mov	esp, [tss.esp0]
  5094                              <1> 	;
  5095                              <1> 	; 'loc_load_run_file_8' address has 
  5096                              <1> 	; 'jmp loc_file_rw_restore_retn' instruction
  5097                              <1> 	; 'loc_file_rw_restore_retn:' will return to
  5098                              <1> 	; [mainprog_return_addr] 
  5099                              <1> 	; just after 'call command_interpreter'
  5100                              <1> 	;
  5101 0000E013 68[7B630000]        <1> 	push	_end_of_mainprog ; we must not return to here !
  5102 0000E018 FF35[20650100]      <1> 	push	dword [mainprog_return_addr]
  5103 0000E01E 89E5                <1> 	mov	ebp, esp ; **
  5104                              <1> 	;	
  5105 0000E020 9C                  <1> 	pushfd  ; EFLAGS      ; IRETD ; ***
  5106 0000E021 6A08                <1> 	push	KCODE ; cs    ; IRETD
  5107 0000E023 50                  <1> 	push	eax ; * (eip) ; IRETD
  5108 0000E024 8925[5C030300]      <1> 	mov	[u.sp], esp
  5109                              <1> 	;mov	byte [u.quant], time_count
  5110 0000E02A 1E                  <1> 	push	ds
  5111 0000E02B 06                  <1> 	push	es
  5112 0000E02C 0FA0                <1> 	push	fs
  5113 0000E02E 0FA8                <1> 	push	gs	
  5114                              <1> 	;mov	eax, [u.r0]
  5115 0000E030 29C0                <1> 	sub	eax, eax
  5116 0000E032 60                  <1> 	pushad
  5117 0000E033 68[39C70000]        <1> 	push	sysret
  5118                              <1> 	;push	sysrel1 ; 07/01/2017
  5119 0000E038 8925[60030300]      <1> 	mov	[u.usp], esp
  5120                              <1> 	;
  5121 0000E03E E845060000          <1> 	call	wswap ; Save MainProg (process 1) 'u' structure
  5122                              <1> 		      ; and registers for return (from program)	
  5123 0000E043 89EC                <1> 	mov	esp, ebp ; **
  5124                              <1> 	;;22/01/2017
  5125                              <1> 	;;sti ; 07/01/2017
  5126 0000E045 50                  <1> 	push	eax  ; * 'loc_load_and_run_file_8:' address
  5127                              <1> 	;
  5128                              <1> 	;;; 02/05/2016
  5129                              <1> 	;;; Create a new process (parent: MainProg)	
  5130 0000E046 31F6                <1> 	xor 	esi, esi
  5131                              <1> cnpm_1: ; search p.stat table for unused process number
  5132 0000E048 46                  <1> 	inc	esi
  5133 0000E049 80BE[AF000300]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE
  5134                              <1> 				; is process active, unused, dead
  5135 0000E050 760B                <1> 	jna	short cnpm_2	; it's unused so branch
  5136 0000E052 6683FE10            <1> 	cmp	si, nproc 	; all processes checked
  5137 0000E056 72F0                <1> 	jb	short cnpm_1    ; no, branch back
  5138 0000E058 E99483FFFF          <1> 	jmp	panic 
  5139                              <1> cnpm_2:
  5140 0000E05D A1[B8030300]        <1> 	mov	eax, [u.pgdir] ; page directory of MainProg
  5141 0000E062 A3[BC030300]        <1> 	mov	[u.ppgdir], eax ; parent's page directory
  5142 0000E067 E8406BFFFF          <1> 	call	allocate_page
  5143 0000E06C 0F827F83FFFF        <1> 	jc	panic
  5144                              <1> 	; EAX = UPAGE (user structure page) address
  5145 0000E072 A3[B4030300]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
  5146 0000E077 89F7                <1> 	mov	edi, esi
  5147 0000E079 66C1E702            <1> 	shl	di, 2
  5148 0000E07D 8987[BC000300]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
  5149 0000E083 E89E6BFFFF          <1> 	call	clear_page ; 03/05/2016
  5150                              <1> 	;movzx	eax, byte [p.ttyc] ; console tty (for MainProg)
  5151 0000E088 6629C0              <1> 	sub	ax, ax ; 0
  5152 0000E08B 668986[7F000300]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
  5153                              <1> 				   ; ah - reset child's wait channel	
  5154 0000E092 89F0                <1> 	mov	eax, esi
  5155 0000E094 A2[B3030300]        <1> 	mov	[u.uno], al ; child process number
  5156 0000E099 FE86[AF000300]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN
  5157 0000E09F 66D1E6              <1> 	shl	si, 1 ; multiply si by 2 to get index into p.pid table
  5158 0000E0A2 66FF05[4E030300]    <1> 	inc	word [mpid] ; increment m.pid; get a new process name
  5159 0000E0A9 66A1[4E030300]      <1> 	mov	ax, [mpid]
  5160 0000E0AF 668986[1E000300]    <1> 	mov	[esi+p.pid-2], ax ; put new process name 
  5161                              <1> 				  ; in child process' name slot
  5162                              <1> 	;mov	ax, [p.pid]  ; get process name of MainProg
  5163 0000E0B6 66B80100            <1> 	mov	ax, 1
  5164 0000E0BA 668986[3E000300]    <1> 	mov	[esi+p.ppid-2], ax ; put parent process name 
  5165                              <1> 			           ; in parent process slot for child
  5166 0000E0C1 6648                <1> 	dec	ax ; 0
  5167 0000E0C3 66A3[94030300]      <1> 	mov 	[u.ttyp], ax ; 0
  5168                              <1> 	;;;
  5169 0000E0C9 A1[51040300]        <1> 	mov 	eax,  [ii]
  5170                              <1> 	; Retro UNIX 386 v1, 'sysexec' (u2.s)
  5171 0000E0CE E84C170000          <1> 	call	iopen
  5172                              <1> 	; 06/06/2016
  5173 0000E0D3 C605[A9030300]01    <1> 	mov	byte [u.pri], 1 ; normal priority
  5174                              <1> 	;
  5175 0000E0DA EB16                <1> 	jmp	short sysexec_7 ; 02/05/2016
  5176                              <1> 
  5177                              <1> sysexec_6:
  5178                              <1> 	; 19/11/2017
  5179                              <1> 	; 18/11/2017
  5180                              <1> 	; 14/11/2017
  5181                              <1> 	; 13/11/2017
  5182 0000E0DC 8925[4C040300]      <1> 	mov	[argv], esp ; *!* ; start address of argument list 
  5183                              <1> 
  5184                              <1> 	; 04/01/2017
  5185                              <1> 	; 24/10/2016
  5186                              <1> 	;;02/05/2016
  5187                              <1> 	; 23/04/2016 (TRDOS 386)
  5188                              <1> 	; 18/10/2015 ('sysexec_6')
  5189                              <1> 	; 23/06/2015
  5190 0000E0E2 A1[B8030300]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
  5191                              <1> 	;cmp 	eax, [k_page_dir] ; TRDOS MainProg ? 
  5192                              <1> 	;je	short sysexec_7
  5193                              <1> 	; 19/11/2017
  5194 0000E0E7 8B1D[BC030300]      <1> 	mov	ebx, [u.ppgdir] ; phy addr of the parent's page dir
  5195 0000E0ED E8F36BFFFF          <1> 	call	deallocate_page_dir
  5196                              <1> sysexec_7:
  5197 0000E0F2 E8236BFFFF          <1> 	call	make_page_dir
  5198 0000E0F7 0F82F482FFFF        <1> 	jc	panic  ; allocation error 
  5199                              <1> 		       ; after a deallocation would be nonsence !?
  5200                              <1> 	; 24/07/2015
  5201                              <1> 	; map kernel pages (1st 4MB) to PDE 0
  5202                              <1> 	;     of the user's page directory
  5203                              <1> 	;     (It is needed for interrupts!)
  5204                              <1> 	; 18/10/2015
  5205 0000E0FD 8B15[A8580100]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
  5206 0000E103 8B02                <1> 	mov	eax, [edx] ; physical address of
  5207                              <1> 			   ; kernel's first page table (1st 4 MB)
  5208                              <1> 			   ; (PDE 0 of kernel's page directory)
  5209 0000E105 8B15[B8030300]      <1> 	mov 	edx, [u.pgdir]
  5210 0000E10B 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
  5211                              <1> 	;
  5212                              <1> 	; 20/07/2015
  5213 0000E10D BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
  5214                              <1> 	; 18/10/2015
  5215 0000E112 BE[3C040300]        <1> 	mov	esi, pcore ; physical start address
  5216                              <1> sysexec_8:	
  5217 0000E117 B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
  5218 0000E11C E8176BFFFF          <1> 	call	make_page_table
  5219 0000E121 0F82CA82FFFF        <1> 	jc	panic
  5220                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
  5221 0000E127 E81A6BFFFF          <1> 	call	make_page ; make new page, clear and set the pte 
  5222 0000E12C 0F82BF82FFFF        <1> 	jc	panic
  5223                              <1> 	;
  5224 0000E132 8906                <1> 	mov	[esi], eax ; 24/06/2015
  5225                              <1> 	; ebx = virtual address (24/07/2015)
  5226 0000E134 E8B270FFFF          <1> 	call 	add_to_swap_queue
  5227                              <1> 	; 18/10/2015
  5228 0000E139 81FE[40040300]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
  5229 0000E13F 740C                <1> 	je	short sysexec_9 ; yes
  5230 0000E141 BE[40040300]        <1> 	mov	esi, ecore  ; physical address of the last page 
  5231                              <1> 	; 20/07/2015
  5232 0000E146 BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
  5233                              <1> 	; ebx = virtual end address + segment base address - 4K
  5234 0000E14B EBCA                <1>         jmp     short sysexec_8
  5235                              <1> sysexec_9:
  5236                              <1> 	; 19/11/2017 
  5237                              <1> 	; 24/04/2016 (TRDOS 386 = TRDOS v2.0)
  5238                              <1> 	; 25/06/2015, 26/08/2015, 18/10/2015
  5239                              <1> 	; move arguments from kernel stack to [ecore]
  5240                              <1> 	; (argument list/line will be copied from kernel stack
  5241                              <1> 	; frame to the last (stack) page of user's core memory)
  5242                              <1> 	; 18/10/2015
  5243 0000E14D 8B3D[40040300]      <1> 	mov	edi, [ecore]
  5244 0000E153 81C700100000        <1> 	add	edi, PAGE_SIZE
  5245                              <1> 	; 19/11/2017
  5246 0000E159 83EF04              <1> 	sub	edi, 4
  5247 0000E15C C70700000000        <1> 	mov	dword [edi], 0 
  5248 0000E162 89FB                <1> 	mov	ebx, edi
  5249                              <1> 	;
  5250 0000E164 0FB705[4A040300]    <1> 	movzx	eax, word [argc]
  5251 0000E16B 09C0                <1> 	or	eax, eax
  5252 0000E16D 7445                <1> 	jz	short sysexec_13 ; 19/11/2017
  5253                              <1> 	;jnz	short sysexec_10
  5254                              <1> 	;mov 	ebx, edi
  5255                              <1> 	;sub	ebx, 4 
  5256                              <1> 	;mov	[ebx], eax ; 0
  5257                              <1> 	;jmp 	short sysexec_13
  5258                              <1> sysexec_10:
  5259 0000E16F 8B0D[8C030300]      <1> 	mov	ecx, [u.nread]
  5260                              <1> 	; 13/11/2017
  5261                              <1> 	;mov	esi, TextBuffer ; 'load_and_execute_file'
  5262                              <1> 	;mov	esi, esp  	; 'sysexec'
  5263 0000E175 8B35[4C040300]      <1> 	mov	esi, [argv] ; 24/04/2016 (TRDOS 386  = TRDOS v2.0)
  5264                              <1> 	;sub	edi, ecx ; page end address - argument list length
  5265 0000E17B 29CB                <1> 	sub	ebx, ecx ; 19/11/2017
  5266 0000E17D 89C2                <1> 	mov	edx, eax
  5267 0000E17F FEC2                <1> 	inc	dl ; argument count + 1 for argc value  
  5268 0000E181 C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
  5269                              <1> 	;mov	ebx, edi
  5270 0000E184 89DF                <1> 	mov	edi, ebx ; 19//11/2017
  5271 0000E186 80E3FC              <1> 	and	bl, 0FCh ; 32 bit (dword) alignment
  5272 0000E189 29D3                <1> 	sub 	ebx, edx
  5273 0000E18B 89FA                <1> 	mov	edx, edi
  5274 0000E18D F3A4                <1> 	rep	movsb
  5275 0000E18F 89D6                <1> 	mov 	esi, edx
  5276 0000E191 89DF                <1> 	mov 	edi, ebx
  5277 0000E193 BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
  5278 0000E198 2B15[40040300]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical) 
  5279 0000E19E AB                  <1> 	stosd	; eax = argument count	
  5280                              <1> sysexec_11:
  5281 0000E19F 89F0                <1> 	mov	eax, esi
  5282 0000E1A1 01D0                <1> 	add	eax, edx
  5283 0000E1A3 AB                  <1> 	stosd  ; eax = virtual address
  5284                              <1> 	;dec	byte [argc]
  5285 0000E1A4 66FF0D[4A040300]    <1> 	dec	word [argc] ; 14/11/2017
  5286 0000E1AB 7407                <1> 	jz	short sysexec_13
  5287                              <1> sysexec_12:
  5288 0000E1AD AC                  <1> 	lodsb
  5289 0000E1AE 20C0                <1> 	and	al, al
  5290 0000E1B0 75FB                <1> 	jnz	short sysexec_12
  5291 0000E1B2 EBEB                <1> 	jmp	short sysexec_11
  5292                              <1> sysexec_13:
  5293                              <1> 	; 24/10/2016
  5294                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
  5295                              <1> 	; 23/06/2015 - 19/10/2015 (Retro UNIX 386 v1, 'sysexec_13')
  5296                              <1> 	;
  5297                              <1> 	; moving arguments to [ecore] is OK here..
  5298                              <1> 	;
  5299                              <1> 	; ebx = beginning addres of argument list pointers
  5300                              <1> 		;	in user's stack
  5301 0000E1B4 2B1D[40040300]      <1> 	sub 	ebx, [ecore]
  5302 0000E1BA 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
  5303                              <1> 			; end of core - 4096 (last page)
  5304                              <1> 			; (virtual address)
  5305 0000E1C0 891D[4C040300]      <1> 	mov	[argv], ebx
  5306 0000E1C6 891D[90030300]      <1> 	mov	[u.break], ebx ; available user memory
  5307                              <1> 	;
  5308 0000E1CC 29C0                <1> 	sub	eax, eax
  5309 0000E1CE C705[88030300]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
  5309 0000E1D6 0000                <1>
  5310 0000E1D8 C705[74030300]-     <1> 	mov	dword [u.fofp], u.off
  5310 0000E1DE [80030300]          <1>
  5311 0000E1E2 A3[80030300]        <1> 	mov	[u.off], eax ; 0
  5312 0000E1E7 A3[84030300]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
  5313                              <1> 	; 24/10/2016
  5314 0000E1EC A0[6E590100]        <1> 	mov	al, [Current_Drv]
  5315 0000E1F1 A2[46030300]        <1> 	mov	[cdev], al
  5316                              <1> 	;
  5317 0000E1F6 A1[51040300]        <1> 	mov	eax, [ii] ; Fist Cluster of the Program (PRG) file
  5318                              <1> 	; EAX = First cluster of the executable file
  5319 0000E1FB E80A010000          <1> 	call	readi
  5320                              <1> 
  5321 0000E200 8B0D[90030300]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
  5322 0000E206 890D[88030300]      <1> 	mov	[u.count], ecx ; save for overrun check
  5323                              <1> 	;
  5324 0000E20C 8B0D[8C030300]      <1> 	mov	ecx, [u.nread]
  5325 0000E212 890D[90030300]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
  5326 0000E218 80F920              <1> 	cmp	cl, 32
  5327 0000E21B 7540                <1>         jne     short sysexec_15
  5328                              <1> 	;:
  5329                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
  5330 0000E21D 8B35[3C040300]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
  5331                              <1> 		             ; (phys. start addr. of the exec. file)
  5332 0000E223 AD                  <1> 	lodsd
  5333 0000E224 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
  5334 0000E228 7533                <1> 	jne	short sysexec_15
  5335 0000E22A AD                  <1> 	lodsd
  5336 0000E22B 89C1                <1> 	mov	ecx, eax ; text (code) section size
  5337 0000E22D AD                  <1> 	lodsd
  5338 0000E22E 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
  5339 0000E230 89CB                <1> 	mov	ebx, ecx
  5340 0000E232 AD                  <1> 	lodsd	
  5341 0000E233 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
  5342 0000E235 3B1D[88030300]      <1> 	cmp	ebx, [u.count]
  5343 0000E23B 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
  5344                              <1> 	;
  5345                              <1> 	; add bss section size to [u.break]
  5346 0000E23D 0105[90030300]      <1> 	add 	[u.break], eax
  5347                              <1> 	;
  5348 0000E243 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
  5349                              <1> 	;cmp	ecx, [u.count]
  5350                              <1> 	;jnb	short sysexec_16
  5351 0000E246 890D[88030300]      <1> 	mov	[u.count], ecx ; required read count
  5352 0000E24C EB29                <1> 	jmp	short sysexec_16
  5353                              <1> sysexec_14:
  5354                              <1> 	; insufficient (out of) memory
  5355 0000E24E C705[C8030300]0400- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
  5355 0000E256 0000                <1>
  5356 0000E258 E9BCE4FFFF          <1> 	jmp	error
  5357                              <1> sysexec_15:
  5358 0000E25D 8B15[55040300]      <1>         mov	edx, [i.size] ; file size
  5359 0000E263 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
  5360 0000E265 7626                <1> 	jna	short sysexec_17 ; no need to next read
  5361 0000E267 01D1                <1> 	add	ecx, edx ; [i.size]
  5362 0000E269 3B0D[88030300]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
  5363 0000E26F 77DD                <1> 	ja	short sysexec_14
  5364 0000E271 8915[88030300]      <1> 	mov	[u.count], edx
  5365                              <1> sysexec_16:
  5366 0000E277 A1[51040300]        <1> 	mov	eax, [ii] ; first cluster
  5367 0000E27C E889000000          <1> 	call	readi
  5368 0000E281 8B0D[8C030300]      <1> 	mov	ecx, [u.nread]
  5369 0000E287 010D[90030300]      <1> 	add	[u.break], ecx
  5370                              <1> sysexec_17:
  5371 0000E28D A1[51040300]        <1> 	mov	eax, [ii] ; first cluster
  5372 0000E292 E889150000          <1> 	call	iclose
  5373 0000E297 31C0                <1> 	xor     eax, eax
  5374 0000E299 FEC0                <1> 	inc	al
  5375 0000E29B 66A3[AA030300]      <1> 	mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
  5376 0000E2A1 66A3[AC030300]      <1> 	mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled) 
  5377 0000E2A7 833D[BC030300]00    <1>         cmp	dword [u.ppgdir], 0  ; is the caller MainProg (kernel) ?
  5378 0000E2AE 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
  5379                              <1> 	; If the caller is kernel (MainProg), 'sysexec' will come here
  5380 0000E2B0 8B15[A8580100]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
  5381 0000E2B6 8915[BC030300]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here 
  5382                              <1> sysexec_18:
  5383                              <1> 	; 02/05/2016
  5384                              <1> 	; 24/04/2016 (TRDOS 386 = TRDOS v2.0)
  5385                              <1> 	; 18/10/2015 (Retro UNIX 386 v1)
  5386                              <1> 	; 05/08/2015
  5387                              <1> 	; 29/07/2015
  5388                              <1> 
  5389                              <1> ;	; **** arguments list test start - 19/11/2017
  5390                              <1> ;	mov	ebp, [argv]
  5391                              <1> ;	sub	ebp, ECORE - 4096
  5392                              <1> ;	add	ebp, [ecore]
  5393                              <1> ;
  5394                              <1> ;	mov	ebx, [ebp]
  5395                              <1> ;	mov	[argc], bx
  5396                              <1> ;	add	ebp, 4
  5397                              <1> ;	mov	byte [ccolor], 1Fh
  5398                              <1> ;_zx0:
  5399                              <1> ;	cmp	word [argc], 0
  5400                              <1> ;	jna	short _zx2	
  5401                              <1> ;_zx1:
  5402                              <1> ;	push	ebp
  5403                              <1> ;	mov	esi, [ebp]
  5404                              <1> ;
  5405                              <1> ;	sub	esi, ECORE - 4096
  5406                              <1> ;	add	esi, [ecore]
  5407                              <1> ;
  5408                              <1> ;	call	print_cmsg
  5409                              <1> ;
  5410                              <1> ;	dec	word [argc]
  5411                              <1> ;	jz	short _zx2
  5412                              <1> ;
  5413                              <1> ;	mov	al, '.'
  5414                              <1> ;	mov	bl, 07h
  5415                              <1> ;	mov	bh, [u.ttyn]
  5416                              <1> ;	call 	_write_tty 
  5417                              <1> ;
  5418                              <1> ;	pop	ebp
  5419                              <1> ;	add	ebp, 4
  5420                              <1> ;	jmp	short _zx1			
  5421                              <1> ;_zx2:
  5422                              <1> ;	pop	ebp
  5423                              <1> ;	mov	byte [ccolor], 07h
  5424                              <1> ;	mov	eax, 1
  5425                              <1> ;	; **** arguments list test stop
  5426                              <1> ;	Test result is OK! (there is not a wrong thing) - 19/11/2017
  5427                              <1> 
  5428 0000E2BC 8B2D[4C040300]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
  5429                              <1> 			    ; list pointers (argument count)
  5430 0000E2C2 FA                  <1> 	cli
  5431 0000E2C3 8B25[44580100]      <1>         mov     esp, [tss.esp0] ; ring 0 (kernel) stack pointer
  5432                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
  5433                              <1> 			    ; for this process	 
  5434                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
  5435                              <1> 	;xor	eax, eax ; 0
  5436 0000E2C9 FEC8                <1> 	dec	al ; eax = 0
  5437                              <1> 	;mov	edx, UDATA
  5438                              <1> 	; 18/11/2017
  5439 0000E2CB 6A23                <1> 	push	UDATA ; user's stack segment
  5440                              <1> 	;push	edx
  5441 0000E2CD 55                  <1> 	push	ebp ; user's stack pointer
  5442                              <1> 		    ; (points to number of arguments)
  5443                              <1> 	
  5444                              <1> 	; 04/01/2017
  5445                              <1> 	; MainProg comes here while [sysflg]= 0FFh
  5446                              <1> 	; (but sysexec comes here while [sysflg]= 0)
  5447 0000E2CE C605[5B030300]00    <1> 	mov	byte [sysflg], 0 ; 04/01/2017
  5448                              <1> 				 ; (timer_int sysflg control)
  5449 0000E2D5 FB                  <1> 	sti
  5450 0000E2D6 9C                  <1> 	pushfd	; EFLAGS
  5451                              <1> 		; Set IF for enabling interrupts in user mode	
  5452                              <1> 	;or	dword [esp], 200h 
  5453                              <1> 	;
  5454                              <1> 	;mov	bx, UCODE
  5455                              <1> 	;push	bx ; user's code segment
  5456 0000E2D7 6A1B                <1> 	push	UCODE
  5457                              <1> 	;push	0
  5458 0000E2D9 50                  <1> 	push	eax ; EIP (=0) - start address -	
  5459 0000E2DA 8925[5C030300]      <1> 	mov	[u.sp], esp ; 29/07/2015
  5460                              <1> 	; 05/08/2015
  5461                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
  5462                              <1> 	; ('push dx' would cause to general protection fault, 
  5463                              <1> 	; after 'pop ds' etc.)
  5464                              <1> 	;
  5465                              <1> 	;; push dx ; ds (UDATA)
  5466                              <1> 	;; push dx ; es (UDATA)
  5467                              <1> 	;; push dx ; fs (UDATA)
  5468                              <1> 	;; push dx ; gs (UDATA)
  5469                              <1> 	;
  5470                              <1> 	; This is a trick to prevent general protection fault
  5471                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
  5472 0000E2E0 66BA2300            <1> 	mov	dx, UDATA ; 19/11/2017
  5473 0000E2E4 8EC2                <1> 	mov 	es, dx ; UDATA
  5474 0000E2E6 06                  <1> 	push 	es ; ds (UDATA)
  5475 0000E2E7 06                  <1> 	push 	es ; es (UDATA)
  5476 0000E2E8 06                  <1> 	push 	es ; fs (UDATA)
  5477 0000E2E9 06                  <1> 	push	es ; gs (UDATA)
  5478 0000E2EA 66BA1000            <1> 	mov	dx, KDATA
  5479 0000E2EE 8EC2                <1> 	mov	es, dx
  5480                              <1> 	;
  5481                              <1> 	;; pushad simulation
  5482 0000E2F0 89E5                <1> 	mov	ebp, esp ; esp before pushad
  5483 0000E2F2 50                  <1> 	push	eax ; eax (0)
  5484 0000E2F3 50                  <1> 	push	eax ; ecx (0)
  5485 0000E2F4 50                  <1> 	push	eax ; edx (0)
  5486 0000E2F5 50                  <1> 	push	eax ; ebx (0)
  5487 0000E2F6 55                  <1> 	push	ebp ; esp before pushad
  5488 0000E2F7 50                  <1> 	push	eax ; ebp (0)
  5489 0000E2F8 50                  <1> 	push	eax ; esi (0)		
  5490 0000E2F9 50                  <1> 	push	eax ; edi (0)	
  5491                              <1> 	;
  5492 0000E2FA A3[64030300]        <1> 	mov	[u.r0], eax ; eax = 0
  5493 0000E2FF 8925[60030300]      <1> 	mov	[u.usp], esp
  5494                              <1> 
  5495                              <1> 	; 14/11/2017
  5496 0000E305 E931E4FFFF          <1> 	jmp	sysret0
  5497                              <1> 
  5498                              <1> ;	; 02/05/2016
  5499                              <1> ;	;inc	byte [sysflg] ; 0FFh -> 0
  5500                              <1> ;	;mov	byte [sysflg], 0 ; 04/01/2017
  5501                              <1> ;	movzx	ebx, byte [u.uno]
  5502                              <1> ;	shl	bl, 1 ; 13/11/2017 	
  5503                              <1> ;	cmp	word [ebx+p.ppid-2], 1 ; MainProg
  5504                              <1> ;	ja	sysret0 ; 03/05/2016
  5505                              <1> ;	push	sysret ; * 
  5506                              <1> ;	mov	[u.usp], esp
  5507                              <1> ;	call	wswap ; save child process 'u' structure and
  5508                              <1> ;		      ; registers
  5509                              <1> ;	add	dword [u.usp], 4 ; 03/05/2016 
  5510                              <1> ;sysexec_19: ; 02/05/2016
  5511                              <1> ;	retn ; * 'sysret' ; byte [sysflg] -> 0FFh
  5512                              <1> 
  5513                              <1> readi:
  5514                              <1> 	; 01/05/2016
  5515                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  5516                              <1> 	; 20/05/2015 - Retro UNIX 386 v1
  5517                              <1> 	; 11/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  5518                              <1> 	;
  5519                              <1> 	; Reads from a file whose the first cluster number in EAX
  5520                              <1> 	; 
  5521                              <1> 	; INPUTS ->
  5522                              <1> 	;    EAX - First cluster number of the file
  5523                              <1> 	;    u.count - byte count user desires
  5524                              <1> 	;    u.base - points to user buffer
  5525                              <1> 	;    u.fofp - points to dword with current file offset
  5526                              <1> 	;    i.size - file size
  5527                              <1> 	;    cdev - logical dos drive number of the file
  5528                              <1> 	; OUTPUTS ->
  5529                              <1> 	;    u.count - cleared
  5530                              <1> 	;    u.nread - accumulates total bytes passed back
  5531                              <1> 	;
  5532                              <1> 	; ((EAX)) input/output
  5533                              <1> 	; (Retro UNIX Prototype : 14/12/2012 - 01/03/2013, UNIXCOPY.ASM)
  5534                              <1>         ; ((Modified registers: edx, ebx, ecx, esi, edi))  
  5535                              <1> 
  5536 0000E30A 31D2                <1> 	xor	edx, edx ; 0
  5537 0000E30C 8915[8C030300]      <1> 	mov 	[u.nread], edx ; 0
  5538 0000E312 668915[C4030300]    <1> 	mov	[u.pcount], dx ; 19/05/2015
  5539 0000E319 3915[88030300]      <1> 	cmp 	[u.count], edx ; 0
  5540 0000E31F 7701                <1> 	ja 	short readi_1
  5541 0000E321 C3                  <1> 	retn
  5542                              <1> readi_1:
  5543                              <1> dskr:
  5544                              <1> 	; 01/05/2016
  5545                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  5546                              <1> 	; 24/05/2015 - 12/10/2015 (Retro UNIX 386 v1)
  5547                              <1> 	; 26/04/2013 - 03/08/2013 (Retro UNIX 8086 v1)
  5548                              <1> dskr_0:
  5549 0000E322 8B15[55040300]      <1>         mov	edx, [i.size]
  5550 0000E328 8B1D[74030300]      <1> 	mov	ebx, [u.fofp]
  5551 0000E32E 2B13                <1> 	sub	edx, [ebx]
  5552 0000E330 7647                <1> 	jna	short dskr_4
  5553                              <1> 	;
  5554 0000E332 50                  <1> 	push	eax ; 01/05/2016
  5555 0000E333 3B15[88030300]      <1> 	cmp     edx, [u.count] 
  5556 0000E339 7306                <1> 	jnb	short dskr_1
  5557 0000E33B 8915[88030300]      <1> 	mov	[u.count], edx
  5558                              <1> dskr_1:
  5559                              <1> 	; EAX = First Cluster
  5560                              <1> 	; [Current_Drv] = Physical drive number 
  5561 0000E341 E83B000000          <1> 	call	mget_r
  5562                              <1> 	; NOTE: in 'mget_r', relevant sector will be read in buffer
  5563                              <1> 	; if it is not already in buffer !
  5564 0000E346 BB[8C050300]        <1> 	mov	ebx, readi_buffer
  5565 0000E34B 803D[C6030300]00    <1> 	cmp	byte [u.kcall], 0 ; the caller is 'namei' sign (=1)
  5566 0000E352 770F                <1> 	ja	short dskr_3	  ; zf=0 -> the caller is 'namei'
  5567 0000E354 66833D[C4030300]00  <1> 	cmp	word [u.pcount], 0
  5568 0000E35C 7705                <1> 	ja	short dskr_3
  5569                              <1> dskr_2:
  5570                              <1> 	; [u.base] = virtual address to transfer (as destination address)
  5571 0000E35E E894010000          <1> 	call	trans_addr_w ; translate virtual address to physical (w)
  5572                              <1> dskr_3:
  5573                              <1> 	; EBX (r5) = system (I/O) buffer address -physical-
  5574 0000E363 E8F7010000          <1> 	call	sioreg
  5575 0000E368 87F7                <1> 	xchg	esi, edi
  5576                              <1> 	; EDI = file (user data) offset
  5577                              <1> 	; ESI = sector (I/O) buffer offset
  5578                              <1> 	; ECX = byte count
  5579 0000E36A F3A4                <1> 	rep	movsb
  5580                              <1> 	; eax = remain bytes in buffer
  5581                              <1>         ;       (check if remain bytes in the buffer > [u.pcount])
  5582 0000E36C 09C0                <1> 	or	eax, eax
  5583 0000E36E 75EE                <1> 	jnz	short dskr_2 ; (page end before system buffer end!)		
  5584 0000E370 58                  <1> 	pop	eax  ; (first cluster number)
  5585 0000E371 390D[88030300]      <1> 	cmp	[u.count], ecx ; 0
  5586 0000E377 77A9                <1> 	ja	short dskr_0
  5587                              <1> dskr_4:
  5588 0000E379 C605[C6030300]00    <1> 	mov	byte [u.kcall], 0
  5589 0000E380 C3                  <1> 	retn
  5590                              <1> 
  5591                              <1> mget_r:
  5592                              <1> 	; 24/10/2016
  5593                              <1> 	; 22/10/2016
  5594                              <1> 	; 12/10/2016
  5595                              <1> 	; 29/04/2016
  5596                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
  5597                              <1> 	; 03/06/2015 (Retro UNIX 386 v1, 'mget', u.5s)
  5598                              <1> 	; 22/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  5599                              <1> 	;
  5600                              <1> 	; Get existing or (allocate) a new disk block for file
  5601                              <1> 	; 
  5602                              <1> 	; INPUTS ->
  5603                              <1> 	;    [u.fofp] = file offset pointer
  5604                              <1> 	;    EAX = First Cluster
  5605                              <1> 	;    [cdev] = Logical dos drive number 	  
  5606                              <1> 	;    ([u.off] = file offset)
  5607                              <1> 	; OUTPUTS ->
  5608                              <1> 	;    EAX = logical sector number
  5609                              <1> 	;    ESI = Logical Dos Drive Description Table address	
  5610                              <1> 	;
  5611                              <1> 	; Modified registers: EDX, EBX, ECX, ESI, EDI
  5612                              <1> 
  5613 0000E381 8B35[74030300]      <1> 	mov     esi, [u.fofp]
  5614 0000E387 8B1E                <1> 	mov	ebx, [esi] ; (u.off)
  5615                              <1> 
  5616 0000E389 29C9                <1> 	sub	ecx, ecx
  5617 0000E38B 8A2D[46030300]      <1> 	mov	ch, [cdev]
  5618                              <1> 
  5619 0000E391 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  5620 0000E396 01CE                <1> 	add	esi, ecx
  5621                              <1> 
  5622 0000E398 380D[D4640100]      <1> 	cmp	[readi.valid], cl ; 0
  5623 0000E39E 7649                <1> 	jna	short mget_r_0
  5624                              <1> 	
  5625 0000E3A0 3A2D[D5640100]      <1> 	cmp	ch, [readi.drv]
  5626 0000E3A6 7541                <1> 	jne	short mget_r_0
  5627                              <1> 
  5628 0000E3A8 3B05[E8640100]      <1> 	cmp	eax, [readi.fclust]
  5629 0000E3AE 7565                <1> 	jne	short mget_r_3
  5630                              <1> 	
  5631 0000E3B0 89D8                <1> 	mov	eax, ebx ; file offset
  5632 0000E3B2 668B0D[DC640100]    <1> 	mov	cx, [readi.bpc]
  5633 0000E3B9 41                  <1> 	inc	ecx ; <= 65536
  5634 0000E3BA 29D2                <1> 	sub	edx, edx
  5635 0000E3BC F7F1                <1> 	div	ecx
  5636                              <1> 
  5637 0000E3BE 8B3D[E4640100]      <1> 	mov	edi, [readi.c_index] ; cluster index
  5638                              <1> 
  5639 0000E3C4 39F8                <1> 	cmp	eax, edi
  5640 0000E3C6 757A                <1>         jne     short mget_r_4  ; (*)
  5641                              <1> 
  5642                              <1> 	; edx = byte offset in cluster (<= 65535)
  5643 0000E3C8 668915[DE640100]    <1> 	mov	[readi.offset], dx
  5644 0000E3CF 66C1EA09            <1> 	shr	dx, 9 ; / 512
  5645 0000E3D3 8815[D7640100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
  5646                              <1> 	
  5647 0000E3D9 A1[E0640100]        <1> 	mov	eax, [readi.cluster]  ; > 0 if [readi.valid] = 1
  5648 0000E3DE 8B15[EC640100]      <1> 	mov	edx, [readi.fs_index]
  5649 0000E3E4 E99A000000          <1>         jmp     mget_r_7
  5650                              <1> 	
  5651                              <1> mget_r_0:
  5652 0000E3E9 882D[D5640100]      <1> 	mov	[readi.drv], ch ; physical drive number
  5653 0000E3EF 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5654 0000E3F3 7707                <1> 	ja	short mget_r_1
  5655 0000E3F5 8A4E12              <1> 	mov	cl, [esi+LD_FS_BytesPerSec+1]
  5656 0000E3F8 D0E9                <1> 	shr	cl, 1 ;  ; 1 for 512 bytes, 4 for 2048 bytes
  5657 0000E3FA EB03                <1> 	jmp	short mget_r_2	
  5658                              <1> mget_r_1:
  5659 0000E3FC 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]
  5660                              <1> mget_r_2:
  5661 0000E3FF 880D[D6640100]      <1> 	mov	[readi.spc], cl  ; sectors per cluster
  5662                              <1> 	; NOTE: readi bytes per sector value is always 512 ! 
  5663 0000E405 66C1E109            <1> 	shl	cx, 9 ; * 512
  5664 0000E409 6649                <1> 	dec	cx ; bytes per cluster - 1
  5665 0000E40B 66890D[DC640100]    <1> 	mov	[readi.bpc], cx
  5666 0000E412 6629C9              <1> 	sub	cx, cx
  5667                              <1> mget_r_3:
  5668 0000E415 A3[E8640100]        <1> 	mov	[readi.fclust], eax ; first cluster (or FDT address)
  5669 0000E41A 880D[D4640100]      <1> 	mov	[readi.valid], cl ; 0 
  5670                              <1> 	;mov	[readi.s_index], cl ; 0
  5671                              <1> 	;mov	[readi.offset], cx ; 0
  5672 0000E420 890D[E4640100]      <1> 	mov	[readi.c_index], ecx ; 0
  5673 0000E426 890D[E0640100]      <1> 	mov	[readi.cluster], ecx ; 0
  5674 0000E42C 890D[D8640100]      <1> 	mov	[readi.sector], ecx ; 0
  5675                              <1> 	
  5676 0000E432 89D8                <1> 	mov	eax, ebx ; file offset
  5677 0000E434 668B0D[DC640100]    <1> 	mov	cx, [readi.bpc]
  5678 0000E43B 41                  <1> 	inc	ecx ; <= 65536
  5679 0000E43C 29D2                <1> 	sub	edx, edx
  5680 0000E43E F7F1                <1> 	div	ecx
  5681                              <1> 	;mov	edi, [readi.c_index] ; previous cluster index
  5682 0000E440 29FF                <1> 	sub	edi, edi
  5683                              <1> mget_r_4:
  5684 0000E442 A3[E4640100]        <1> 	mov	[readi.c_index], eax ; cluster index
  5685                              <1> 	; edx = byte offset in cluster (<= 65535)
  5686 0000E447 668915[DE640100]    <1> 	mov	[readi.offset], dx
  5687 0000E44E 66C1EA09            <1> 	shr	dx, 9 ; / 512
  5688 0000E452 8815[D7640100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
  5689                              <1> 
  5690 0000E458 89C1                <1> 	mov	ecx, eax ; current cluster index
  5691 0000E45A A1[E8640100]        <1> 	mov	eax, [readi.fclust]
  5692 0000E45F 09C9                <1> 	or	ecx, ecx ; cluster index
  5693 0000E461 741B                <1> 	jz	short mget_r_6
  5694                              <1> 
  5695 0000E463 39CF                <1> 	cmp	edi, ecx
  5696 0000E465 7710                <1> 	ja	short mget_r_5 ; old cluster index is higher
  5697 0000E467 8B15[E0640100]      <1> 	mov	edx, [readi.cluster]
  5698 0000E46D 21D2                <1> 	and	edx, edx
  5699 0000E46F 7406                <1> 	jz	short mget_r_5
  5700                              <1> 	; valid 'readi' parameters (*)
  5701 0000E471 89D0                <1> 	mov	eax, edx
  5702 0000E473 29F9                <1> 	sub	ecx, edi
  5703 0000E475 740C                <1> 	jz	short mget_r_7
  5704                              <1> mget_r_5:
  5705                              <1> 	; EAX = Beginning cluster
  5706                              <1> 	; EDX = Sector index in disk/file section
  5707                              <1> 	;	(Only for SINGLIX file system!)
  5708                              <1> 	; ECX = Cluster sequence number after the beginning cluster
  5709                              <1> 	; ESI = Logical DOS Drive Description Table address
  5710 0000E477 E836E1FFFF          <1> 	call	get_cluster_by_index
  5711 0000E47C 724E                <1> 	jc	short mget_r_err
  5712                              <1> 	; EAX = Cluster number		
  5713                              <1> mget_r_6:
  5714 0000E47E A3[E0640100]        <1> 	mov	[readi.cluster], eax ; FDT number for Singlix File System
  5715                              <1> mget_r_7:
  5716 0000E483 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  5717 0000E487 765F                <1> 	jna	short mget_r_12
  5718                              <1> 
  5719 0000E489 83E802              <1> 	sub	eax, 2
  5720 0000E48C 0FB615[D6640100]    <1> 	movzx	edx, byte [readi.spc]
  5721 0000E493 F7E2                <1> 	mul	edx
  5722                              <1> 
  5723 0000E495 034668              <1> 	add	eax, [esi+LD_DATABegin]
  5724 0000E498 8A15[D7640100]      <1> 	mov	dl, [readi.s_index]
  5725 0000E49E 01D0                <1> 	add	eax, edx
  5726                              <1> mget_r_8:
  5727                              <1> 	; eax = logical sector number
  5728 0000E4A0 803D[D4640100]00    <1> 	cmp	byte [readi.valid], 0
  5729 0000E4A7 7608                <1> 	jna	short mget_r_9
  5730 0000E4A9 3B05[D8640100]      <1> 	cmp	eax, [readi.sector]
  5731 0000E4AF 7436                <1> 	je	short mget_r_11 ; sector is already in 'readi' buffer
  5732                              <1> mget_r_9:
  5733 0000E4B1 A3[D8640100]        <1> 	mov	[readi.sector], eax
  5734 0000E4B6 BB[8C050300]        <1> 	mov	ebx, readi_buffer ; buffer address
  5735 0000E4BB B901000000          <1> 	mov	ecx, 1
  5736                              <1> 	; 29/04/2016
  5737                              <1> 	;xor	dl, dl
  5738                              <1> 
  5739                              <1> 	; EAX = Logical sector number
  5740                              <1> 	; ECX = Sector count
  5741                              <1> 	; EBX = Buffer address
  5742                              <1> 	; (EDX = 0)
  5743                              <1> 	; ESI = Logical DOS drive description table address	
  5744                              <1> 
  5745 0000E4C0 E86E130000          <1> 	call	disk_read
  5746 0000E4C5 7314                <1> 	jnc	short mget_r_10
  5747                              <1> 
  5748                              <1> 	; 22/10/2016 (15h -> 17)
  5749 0000E4C7 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
  5750                              <1> mget_r_err:
  5751 0000E4CC A3[C8030300]        <1> 	mov	[u.error], eax
  5752                              <1> 	; 12/10/2016
  5753 0000E4D1 A3[64030300]        <1> 	mov	[u.r0], eax
  5754 0000E4D6 E93EE2FFFF          <1> 	jmp	error
  5755                              <1> mget_r_10:
  5756 0000E4DB C605[D4640100]01    <1> 	mov	byte [readi.valid], 1 ; 24/10/2016
  5757 0000E4E2 A1[D8640100]        <1> 	mov	eax, [readi.sector]
  5758                              <1> mget_r_11:
  5759 0000E4E7 C3                  <1> 	retn
  5760                              <1> mget_r_12:
  5761                              <1> 	; EAX = FDT number
  5762                              <1> 	; EDX = Sector index from FDT sector (0,1,2,3,4...)
  5763 0000E4E8 40                  <1> 	inc	eax ; the first data sector in FS disk section	
  5764 0000E4E9 8915[EC640100]      <1> 	mov	[readi.fs_index], edx
  5765 0000E4EF 01D0                <1> 	add	eax, edx
  5766 0000E4F1 EBAD                <1> 	jmp	short mget_r_8
  5767                              <1> 
  5768                              <1> trans_addr_r:
  5769                              <1> 	; 12/10/2016
  5770                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
  5771                              <1> 	; Translate virtual address to physical address 
  5772                              <1> 	; for reading from user's memory space
  5773                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
  5774                              <1> 
  5775 0000E4F3 31D2                <1> 	xor	edx, edx ; 0 (read access sign)
  5776 0000E4F5 EB04                <1> 	jmp 	short trans_addr_rw
  5777                              <1> 
  5778                              <1> trans_addr_w:
  5779                              <1> 	; 12/10/2016
  5780                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  5781                              <1> 	; Translate virtual address to physical address 
  5782                              <1> 	; for writing to user's memory space
  5783                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
  5784                              <1> 	
  5785 0000E4F7 29D2                <1> 	sub	edx, edx
  5786 0000E4F9 FEC2                <1> 	inc	dl ; 1 (write access sign)
  5787                              <1> trans_addr_rw:
  5788 0000E4FB 50                  <1> 	push	eax
  5789 0000E4FC 53                  <1> 	push	ebx
  5790 0000E4FD 52                  <1> 	push 	edx ; r/w sign (in DL)
  5791                              <1> 	;
  5792 0000E4FE 8B1D[84030300]      <1> 	mov	ebx, [u.base]
  5793 0000E504 E8B86DFFFF          <1> 	call	get_physical_addr ; get physical address
  5794 0000E509 730F                <1> 	jnc	short passc_0
  5795 0000E50B A3[C8030300]        <1> 	mov	[u.error], eax
  5796 0000E510 A3[64030300]        <1> 	mov	[u.r0], eax ; 12/10/2016
  5797                              <1> 	;pop	edx
  5798                              <1> 	;pop 	ebx
  5799                              <1> 	;pop	eax
  5800 0000E515 E9FFE1FFFF          <1> 	jmp	error
  5801                              <1> passc_0:
  5802 0000E51A F6C202              <1> 	test	dl, PTE_A_WRITE ; writable page
  5803 0000E51D 5A                  <1> 	pop	edx
  5804 0000E51E 751C                <1> 	jnz	short passc_1
  5805                              <1> 	
  5806 0000E520 20D2                <1> 	and 	dl, dl
  5807 0000E522 7418                <1> 	jz	short passc_1
  5808                              <1> 	; read only (duplicated) page -must be copied to a new page-
  5809                              <1> 	; EBX = linear address
  5810 0000E524 51                  <1> 	push 	ecx
  5811 0000E525 E8306AFFFF          <1> 	call 	copy_page
  5812 0000E52A 59                  <1> 	pop	ecx
  5813 0000E52B 721E                <1> 	jc	short passc_2
  5814 0000E52D 50                  <1> 	push	eax ; physical address of the new/allocated page
  5815 0000E52E E8B86CFFFF          <1> 	call	add_to_swap_queue	
  5816 0000E533 58                  <1> 	pop	eax
  5817 0000E534 81E3FF0F0000        <1> 	and 	ebx, PAGE_OFF ; 0FFFh
  5818                              <1> 	;mov 	ecx, PAGE_SIZE
  5819                              <1> 	;sub	ecx, ebx 
  5820 0000E53A 01D8                <1> 	add	eax, ebx  
  5821                              <1> passc_1: 
  5822 0000E53C A3[C0030300]        <1> 	mov 	[u.pbase], eax ; physical address	
  5823 0000E541 66890D[C4030300]    <1> 	mov	[u.pcount], cx ; remain byte count in page (1-4096)
  5824 0000E548 5B                  <1> 	pop	ebx
  5825 0000E549 58                  <1> 	pop	eax
  5826 0000E54A C3                  <1> 	retn
  5827                              <1> passc_2:
  5828 0000E54B B804000000          <1> 	mov	eax, ERR_MINOR_IM ; "Insufficient memory !" error
  5829 0000E550 A3[64030300]        <1> 	mov	[u.r0], eax ; 12/10/2016
  5830 0000E555 A3[C8030300]        <1> 	mov	dword [u.error], eax
  5831                              <1> 	;pop 	ebx
  5832                              <1> 	;pop	eax
  5833 0000E55A E9BAE1FFFF          <1> 	jmp	error
  5834                              <1> 
  5835                              <1> sioreg: 
  5836                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  5837                              <1> 	; 19/05/2015 - 25/07/2015 (Retro UNIX 386 v1)
  5838                              <1> 	; 12/03/2013 - 22/07/2013 (Retro UNIX 8086 v1)
  5839                              <1> 	; INPUTS -> 
  5840                              <1> 	;     EBX = system buffer (data) address (r5)
  5841                              <1> 	;     [u.fofp] = pointer to file offset pointer
  5842                              <1> 	;     [u.base] = virtual address of the user buffer
  5843                              <1> 	;     [u.pbase] = physical address of the user buffer
  5844                              <1> 	;     [u.count] = byte count
  5845                              <1> 	;     [u.pcount] = byte count within page frame 			
  5846                              <1> 	; OUTPUTS -> 
  5847                              <1> 	;     ESI = user data offset (r1)
  5848                              <1> 	;     EDI = system (I/O) buffer offset (r2)
  5849                              <1> 	;     ECX = byte count (r3)
  5850                              <1> 	;     EAX = remain bytes after byte count within page frame
  5851                              <1> 	;	(If EAX > 0, transfer will continue from the next page)
  5852                              <1>         ;
  5853                              <1> 	; ((Modified registers:  EDX))
  5854                              <1>  
  5855 0000E55F 8B35[74030300]      <1>         mov     esi, [u.fofp]
  5856 0000E565 8B3E                <1>         mov     edi, [esi]
  5857 0000E567 89F9                <1> 	mov	ecx, edi
  5858 0000E569 81C900FEFFFF        <1> 	or	ecx, 0FFFFFE00h
  5859 0000E56F 81E7FF010000        <1> 	and	edi, 1FFh
  5860 0000E575 01DF                <1> 	add	edi, ebx ; EBX = system buffer (data) address
  5861 0000E577 F7D9                <1> 	neg	ecx
  5862 0000E579 3B0D[88030300]      <1> 	cmp	ecx, [u.count]
  5863 0000E57F 7606                <1> 	jna	short sioreg_0
  5864 0000E581 8B0D[88030300]      <1> 	mov	ecx, [u.count]
  5865                              <1> sioreg_0:
  5866 0000E587 803D[C6030300]00    <1> 	cmp	byte [u.kcall], 0 
  5867 0000E58E 7613                <1> 	jna	short sioreg_1
  5868                              <1> 	 ; the caller is 'mkdir' or 'namei'
  5869 0000E590 A1[84030300]        <1> 	mov	eax, [u.base]
  5870 0000E595 A3[C0030300]        <1> 	mov 	[u.pbase], eax ; physical address = virtual address
  5871 0000E59A 66890D[C4030300]    <1> 	mov	word [u.pcount], cx ; remain bytes in buffer (1 sector)
  5872 0000E5A1 EB0B                <1> 	jmp	short sioreg_2
  5873                              <1> sioreg_1:
  5874 0000E5A3 0FB715[C4030300]    <1> 	movzx	edx, word [u.pcount]
  5875 0000E5AA 39D1                <1> 	cmp	ecx, edx	
  5876 0000E5AC 772A                <1> 	ja	short sioreg_4 ; transfer count > [u.pcount]
  5877                              <1> sioreg_2: ; 2:
  5878 0000E5AE 31C0                <1> 	xor 	eax, eax
  5879                              <1> sioreg_3:
  5880 0000E5B0 010D[8C030300]      <1> 	add 	[u.nread], ecx
  5881 0000E5B6 290D[88030300]      <1> 	sub 	[u.count], ecx
  5882 0000E5BC 010D[84030300]      <1> 	add 	[u.base], ecx
  5883 0000E5C2 010E                <1>         add 	[esi], ecx 
  5884 0000E5C4 8B35[C0030300]      <1> 	mov	esi, [u.pbase]
  5885 0000E5CA 66290D[C4030300]    <1> 	sub	[u.pcount], cx
  5886 0000E5D1 010D[C0030300]      <1> 	add	[u.pbase], ecx
  5887 0000E5D7 C3                  <1>         retn
  5888                              <1> sioreg_4:
  5889                              <1> 	; transfer count > [u.pcount] 
  5890                              <1> 	; (ecx > edx)
  5891 0000E5D8 89C8                <1> 	mov	eax, ecx
  5892 0000E5DA 29D0                <1> 	sub	eax, edx ; remain bytes for 1 sector (block) transfer 
  5893 0000E5DC 89D1                <1> 	mov	ecx, edx ; current transfer count = [u.pcount]
  5894 0000E5DE EBD0                <1> 	jmp	short sioreg_3
  5895                              <1> 
  5896                              <1> tswitch: ; Retro UNIX 386 v1
  5897                              <1> tswap:
  5898                              <1> 	; 16/01/2017
  5899                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0)
  5900                              <1> 	; 10/05/2015 - 01/09/2015 (Retro UNIX 386 v1)
  5901                              <1> 	; 14/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
  5902                              <1> 	; time out swap, called when a user times out.
  5903                              <1> 	; the user is put on the low priority queue.
  5904                              <1> 	; This is done by making a link from the last user
  5905                              <1> 	; on the low priority queue to him via a call to 'putlu'.
  5906                              <1> 	; then he is swapped out.
  5907                              <1> 
  5908                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 21/05/2016 **
  5909                              <1> 	;     * when a high priority (event) process will be stopped
  5910                              <1> 	;	(swapped out, swithched out/off), 'tswap/tswitch' will
  5911                              <1> 	;	not add it to a run queue. 
  5912                              <1> 	;	/// What for: Process may be already in a run queue, 
  5913                              <1> 	;	it is unspeficied state because process might be started
  5914                              <1> 	;	by a timer event which does not regard previous priority
  5915                              <1> 	;	level and run queue of the process (for fast executing!).
  5916                              <1> 	;	After the 'run for event', process will be sequenced
  5917                              <1> 	;	to run by it's actual run queue. ///
  5918                              <1> 	;
  5919                              <1> 	; Retro UNIX 386 v1 modification ->
  5920                              <1> 	;       swap (software task switch) is performed by changing
  5921                              <1> 	;	user's page directory (u.pgdir) instead of segment change
  5922                              <1> 	;	as in Retro UNIX 8086 v1.
  5923                              <1> 	;
  5924                              <1> 	; RETRO UNIX 8086 v1 modification ->
  5925                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  5926                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  5927                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  5928                              <1> 	;	compatibles was using 1MB segmented memory 
  5929                              <1> 	;	in 8086/8088 times.
  5930                              <1> 	;
  5931                              <1> 	; INPUTS ->
  5932                              <1> 	;    u.uno - users process number
  5933                              <1> 	;    runq+4 - lowest priority queue
  5934                              <1> 	; OUTPUTS ->
  5935                              <1> 	;    r0 - users process number
  5936                              <1> 	;    r2 - lowest priority queue address
  5937                              <1> 	;
  5938                              <1> 	; ((AX = R0, BX = R2)) output
  5939                              <1> 	; ((Modified registers: EDX, EBX, ECX, ESI, EDI))  	
  5940                              <1> 	;
  5941                              <1> 
  5942                              <1> 	NOTE:
  5943                              <1> 	;* [u.pri] priority level is specified by run queue which is process 
  5944                              <1> 	;  comes to run from.
  5945                              <1> 	;* Initial [u.pri] is 1 ('normal/regular') for programs 
  5946                              <1> 	;  (which are launched by MainProg or 'sysexec'), it is changed
  5947                              <1> 	;  to 2 ('high') by timer event, if program uses 'systimer' system call.
  5948                              <1> 	;* Program (Process) also can change it's running priority 
  5949                              <1> 	;  from 1 to 0 or up to 2 by using 'syspri' system call; but,
  5950                              <1> 	;  if program selects priority level 2 (high) for running, next time 
  5951                              <1> 	;  it is reduced to 1 (normal/regular) because 'syspri' adds this
  5952                              <1> 	;  program to 'run for normal' queue while running duration is a bit
  5953                              <1> 	;  protected from swap/switch out immediate, behalf of other high 
  5954                              <1> 	;  priority process in sequence. Program (with high priority) will not 
  5955                              <1> 	;  be swapped/switched out (by timer event) before it's time quantum 
  5956                              <1> 	;  will be elapsed, but, this will be temporary if program is not using 
  5957                              <1> 	;  timer event function.	  			 	
  5958                              <1> 
  5959                              <1> 	;For example:
  5960                              <1> 	;If a process frequently gets a timer event, it runs at high priority
  5961                              <1> 	;level but when it returns from running it returns to actual run queue,
  5962                              <1> 	;not to 'run for event' queue again.
  5963                              <1> 	;'tswap' will not change the sequence at return/stop(swap out) stage.
  5964                              <1> 	;But if priority level not high (=2, 'run for event'), 'tswap/tswitch'
  5965                              <1> 	;will add the stopping process to relevant run queue according to
  5966                              <1> 	;[u.pri] priority level.
  5967                              <1> 
  5968                              <1> 	; 16/01/2017
  5969 0000E5E0 BB[54030300]        <1> 	mov	ebx, runq+2 	; 'runq_normal' ; normal/regular priority
  5970                              <1> 	; 21/05/2016
  5971                              <1> 	;cmp	byte [u.pri], 2	; high priority (run for event) ?
  5972                              <1> 	;jnb	short swap
  5973                              <1> 	; 16/01/2017
  5974                              <1> 	; (Normal and also high/event priority processes will be added to
  5975                              <1> 	; normal priority run queue for ensuring circular running sequence!)
  5976                              <1> 	; (Timer interrupt or 'syspri' system call may change priority and run
  5977                              <1> 	; queue to high/event level.)
  5978 0000E5E5 803D[A9030300]00    <1> 	cmp	byte [u.pri], 0
  5979 0000E5EC 7702                <1> 	ja	short tswap_1	; normal priority run queue
  5980                              <1> 	;
  5981 0000E5EE 43                  <1> 	inc	ebx
  5982 0000E5EF 43                  <1> 	inc	ebx		; runq+4, 'runq_background', low priority
  5983                              <1> tswap_1:
  5984 0000E5F0 A0[B3030300]        <1> 	mov 	al, [u.uno]
  5985                              <1> 	       	; movb u.uno,r1 / move users process number to r1
  5986                              <1> 		; mov  $runq+4,r2 
  5987                              <1> 			; / move lowest priority queue address to r2
  5988                              <1>       	; ebx = run queue
  5989 0000E5F5 E8FE000000          <1> 	call 	putlu
  5990                              <1> 		; jsr r0,putlu / create link from last user on Q to 
  5991                              <1> 		             ; / u.uno's user
  5992                              <1> 
  5993                              <1> switch: ; Retro UNIX 386 v1
  5994                              <1> swap:
  5995                              <1> 	; 02/01/2017
  5996                              <1> 	; 21/05/2016
  5997                              <1> 	; 20/05/2016
  5998                              <1> 	; 02/05/2016
  5999                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6000                              <1> 	; 10/05/2015 - 02/09/2015 (Retro UNIX 386 v1)
  6001                              <1> 	; 14/04/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6002                              <1> 	;
  6003                              <1> 	; 'swap' is routine that controls the swapping of processes
  6004                              <1> 	; in and out of core.
  6005                              <1> 	;
  6006                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 20/05/2016 **
  6007                              <1> 	;     * 3 different priority level is applied 
  6008                              <1> 	;	(just as original unix v1)
  6009                              <1> 	;	1) high priority (event) run queue, 'runq_event'
  6010                              <1> 	;	2) normal priority (regular) run queue, 'runq_normal'
  6011                              <1> 	;	3) low priority (background) run queue, 'runq_backgroud'
  6012                              <1> 	;	'swap' code will run a process which has max. priority
  6013                              <1>         ;       (for earliest event at first)
  6014                              <1> 	;
  6015                              <1> 	; Retro UNIX 386 v1 modification ->
  6016                              <1> 	;       swap (software task switch) is performed by changing
  6017                              <1> 	;	user's page directory (u.pgdir) instead of segment change
  6018                              <1> 	;	as in Retro UNIX 8086 v1.
  6019                              <1> 	;
  6020                              <1> 	; RETRO UNIX 8086 v1 modification ->
  6021                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6022                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6023                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6024                              <1> 	;	compatibles was using 1MB segmented memory 
  6025                              <1> 	;	in 8086/8088 times.
  6026                              <1> 	;
  6027                              <1> 	; INPUTS ->
  6028                              <1> 	;    runq table - contains processes to run.
  6029                              <1> 	;    p.link - contains next process in line to be run.
  6030                              <1> 	;    u.uno - process number of process in core	
  6031                              <1> 	;    s.stack - swap stack used as an internal stack for swapping.	
  6032                              <1> 	; OUTPUTS ->
  6033                              <1> 	;    (original unix v1 -> present process to its disk block)
  6034                              <1> 	;    (original unix v1 -> new process into core -> 
  6035                              <1> 	;	   Retro Unix 8086 v1 -> segment registers changed 
  6036                              <1> 	;	   for new process)
  6037                              <1> 	;    u.quant = 3 (Time quantum for a process)
  6038                              <1> 	; 	((INT 1Ch count down speed -> 18.2 times per second)	 	
  6039                              <1> 	;    RETRO UNIX 8086 v1 will use INT 1Ch (18.2 times per second)
  6040                              <1> 	;	 for now, it will swap the process if there is not
  6041                              <1> 	;	 a keyboard event (keystroke) (Int 15h, function 4Fh)
  6042                              <1> 	;	 or will count down from 3 to 0 even if there is a
  6043                              <1> 	;        keyboard event locking due to repetitive key strokes.
  6044                              <1> 	;	 u.quant will be reset to 3 for RETRO UNIX 8086 v1.
  6045                              <1> 	;
  6046                              <1> 	; ((Modified registers: EAX, EDX, EBX, ECX, ESI, EDI))  	
  6047                              <1> 
  6048                              <1> 	;NOTE:
  6049                              <1> 	;High priority queue is the first for selecting a process to run.
  6050                              <1> 	;If there is not a process in high priority level run queue,
  6051                              <1> 	;a process in normal priority run queue will be selected
  6052                              <1> 	;or a proces in low priority run queue will be selected if normal
  6053                              <1> 	;priority level run queue is empty.
  6054                              <1> 	
  6055                              <1> 	; 21/05/2016 -(3 priority levels, 3 run queues)
  6056 0000E5FA BE[52030300]        <1> 	mov	esi, runq ; 'runq_event' ; high priority, 'run for event'
  6057 0000E5FF C605[30650100]03    <1> 	mov	byte [priority], 3 ; high priority + 1
  6058 0000E606 31DB                <1> 	xor	ebx, ebx ; 02/01/2017
  6059                              <1> swap_0: ; 1: / search runq table for highest priority process
  6060 0000E608 66AD                <1> 	lodsw  ; mov ax, [esi], add esi+2
  6061                              <1> 	;xor	ebx, ebx ; 02/05/2016
  6062 0000E60A 6621C0              <1> 	and 	ax, ax ; are there any processes to run in this Q entry
  6063 0000E60D 750E                <1> 	jnz	short swap_2 
  6064                              <1> 	; 21/05/2026
  6065                              <1> 	; runq_normal = runq+2, runq_background = runq+4
  6066 0000E60F FE0D[30650100]      <1> 	dec	byte [priority] ; 3 -> 3, 2 -> 1, 1-> 0
  6067 0000E615 75F1                <1> 	jnz	short swap_0	
  6068                              <1> 	;cmp	esi, runq+6  ; if zero compare address to end of table
  6069                              <1> 	;jb	short swap_0 ; if not at end, go back
  6070                              <1> swap_1:
  6071                              <1> 	; 02/05/2016
  6072                              <1> 	; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  6073                              <1> 	; No user process to run...
  6074                              <1> 	; Run the kernel process... MainProg: Internal Command Interpreter  
  6075 0000E617 FEC0                <1> 	inc	al ; mov al, 1  ; process number of MainProg
  6076 0000E619 FEC3                <1> 	inc	bl ; mov bl, al ; 1
  6077 0000E61B EB1E                <1> 	jmp	short swap_4
  6078                              <1> swap_2:
  6079                              <1> 	; 21/05/2016
  6080 0000E61D FE0D[30650100]      <1> 	dec	byte [priority] ; priority level of present user/process
  6081                              <1> 			        ; 0, 1, 2	   
  6082 0000E623 4E                  <1> 	dec	esi
  6083 0000E624 4E                  <1>         dec     esi
  6084                              <1> 	;
  6085 0000E625 88C3                <1> 	mov	bl, al
  6086 0000E627 38E0                <1> 	cmp	al, ah ; is there only 1 process in the queue to be run
  6087 0000E629 740A                <1> 	je	short swap_3 ; yes
  6088 0000E62B 8AA3[9F000300]      <1> 	mov	ah, [ebx+p.link-1] 
  6089 0000E631 8826                <1>        	mov	[esi], ah ; move next process in line into run queue
  6090 0000E633 EB06                <1> 	jmp	short swap_4
  6091                              <1> swap_3: 
  6092 0000E635 6631D2              <1> 	xor	dx, dx
  6093 0000E638 668916              <1> 	mov	[esi], dx ; zero the entry; no processes on the Q
  6094                              <1> swap_4: 
  6095 0000E63B 8A25[B3030300]      <1> 	mov 	ah, [u.uno]
  6096 0000E641 38C4                <1> 	cmp	ah, al ; is this process the same as the process in core?
  6097 0000E643 743B                <1>        	je	short swap_8 ; yes, don't have to swap
  6098 0000E645 08E4                <1> 	or	ah, ah  ; is the process # = 0
  6099 0000E647 740D                <1>        	jz	short swap_6 ; 'sysexit'
  6100                              <1> 	;cmp	ah, al ;is this process the same as the process in core?
  6101                              <1>        	;je	short swap_8 ; yes, don't have to swap
  6102 0000E649 8925[60030300]      <1> 	mov	[u.usp], esp ; return  address for 'syswait' & 'sleep'
  6103 0000E64F E834000000          <1> 	call	wswap   ; write out core to disk
  6104 0000E654 EB1C                <1> 	jmp 	short swap_7
  6105                              <1> swap_6:
  6106                              <1> 	; Deallocate memory pages belong to the process
  6107                              <1> 	; which is being terminated.
  6108                              <1> 	; (Retro UNIX 386 v1 modification !)
  6109                              <1> 	;
  6110 0000E656 53                  <1> 	push	ebx
  6111 0000E657 A1[B8030300]        <1> 	mov 	eax, [u.pgdir]  ; page directory of the process
  6112 0000E65C 8B1D[BC030300]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  6113 0000E662 E87E66FFFF          <1> 	call	deallocate_page_dir
  6114 0000E667 A1[B4030300]        <1> 	mov	eax, [u.upage] ; 'user' structure page of the process
  6115 0000E66C E81967FFFF          <1> 	call	deallocate_page
  6116 0000E671 5B                  <1> 	pop	ebx
  6117                              <1> swap_7: 
  6118 0000E672 C0E302              <1> 	shl	bl, 2 ; * 4 
  6119 0000E675 8B83[BC000300]      <1> 	mov	eax, [ebx+p.upage-4] ; the 'u' page of the new process
  6120 0000E67B E840000000          <1> 	call	rswap ; read new process into core
  6121                              <1> swap_8: 
  6122                              <1> 	; Retro UNIX  8086 v1 modification !
  6123 0000E680 C605[A8030300]04    <1> 	mov	byte [u.quant], time_count 
  6124 0000E687 C3                  <1> 	retn
  6125                              <1> 
  6126                              <1> wswap:  ; < swap out, swap to disk >
  6127                              <1> 	; 28/02/2017 (fnsave)
  6128                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6129                              <1> 	; 09/05/2015 (Retro UNIX 386 v1)
  6130                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6131                              <1> 	; 'wswap' writes out the process that is in core onto its 
  6132                              <1> 	; appropriate disk area.
  6133                              <1> 	;
  6134                              <1> 	; Retro UNIX 386 v1 modification ->
  6135                              <1> 	;       User (u) structure content and the user's register content
  6136                              <1> 	;	will be copied to the process's/user's UPAGE (a page for
  6137                              <1> 	;	saving 'u' structure and user registers for task switching).
  6138                              <1> 	;	u.usp - points to kernel stack address which contains
  6139                              <1> 	;		user's registers while entering system call.  
  6140                              <1> 	;	u.sp  - points to kernel stack address 
  6141                              <1> 	;		to return from system call -for IRET-.
  6142                              <1> 	;	[u.usp]+32+16 = [u.sp] 
  6143                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx, 
  6144                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
  6145                              <1> 	;
  6146                              <1> 	; Retro UNIX 8086 v1 modification ->
  6147                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6148                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6149                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6150                              <1> 	;	compatibles was using 1MB segmented memory 
  6151                              <1> 	;	in 8086/8088 times.
  6152                              <1> 	;
  6153                              <1> 	; INPUTS ->
  6154                              <1> 	;    u.break - points to end of program
  6155                              <1> 	;    u.usp - stack pointer at the moment of swap
  6156                              <1> 	;    core - beginning of process program		
  6157                              <1> 	;    ecore - end of core 	
  6158                              <1> 	;    user - start of user parameter area		
  6159                              <1> 	;    u.uno - user process number	
  6160                              <1> 	;    p.dska - holds block number of process	
  6161                              <1> 	; OUTPUTS ->
  6162                              <1> 	;    swp I/O queue
  6163                              <1> 	;    p.break - negative word count of process 
  6164                              <1> 	;    r1 - process disk address	
  6165                              <1> 	;    r2 - negative word count
  6166                              <1> 	;
  6167                              <1> 	; RETRO UNIX 8086 v1 input/output:
  6168                              <1> 	;
  6169                              <1> 	; INPUTS ->
  6170                              <1> 	;    u.uno - process number (to be swapped out)
  6171                              <1> 	; OUTPUTS ->
  6172                              <1> 	;    none
  6173                              <1> 	;
  6174                              <1> 	;   ((Modified registers: ECX, ESI, EDI))  
  6175                              <1> 	;
  6176                              <1> 
  6177                              <1> 	; 28/02/2017
  6178                              <1> 	;cmp	byte [multi_tasking], 0  ; Musti tasking mode ?
  6179                              <1> 	;jna	short wswp
  6180 0000E688 803D[DA030300]00    <1> 	cmp	byte [u.fpsave], 0 ; 28/02/2017
  6181 0000E68F 7606                <1> 	jna	short wswp
  6182 0000E691 DD35[DC030300]      <1> 	fnsave	[u.fpregs] ; save floating point registers (94 bytes)
  6183                              <1> wswp:
  6184 0000E697 8B3D[B4030300]      <1> 	mov	edi, [u.upage] ; process's user (u) structure page addr
  6185 0000E69D B938000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
  6186 0000E6A2 BE[5C030300]        <1> 	mov	esi, user ; active user (u) structure	
  6187 0000E6A7 F3A5                <1> 	rep	movsd
  6188                              <1> 	;
  6189 0000E6A9 8B35[60030300]      <1> 	mov	esi, [u.usp] ; esp (system stack pointer, 
  6190                              <1> 			     ;      points to user registers)
  6191 0000E6AF 8B0D[5C030300]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
  6192                              <1> 			     ; (for IRET)
  6193                              <1> 			     ; [u.sp] -> EIP (user)
  6194                              <1> 			     ; [u.sp+4]-> CS (user)
  6195                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
  6196                              <1> 			     ; [u.sp+12] -> ESP (user)
  6197                              <1> 			     ; [u.sp+16] -> SS (user)	
  6198 0000E6B5 29F1                <1> 	sub	ecx, esi     ; required space for user registers
  6199 0000E6B7 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
  6200                              <1> 			     ; (for IRET) 	
  6201 0000E6BA C1E902              <1> 	shr	ecx, 2	     		
  6202 0000E6BD F3A5                <1> 	rep	movsd
  6203 0000E6BF C3                  <1> 	retn
  6204                              <1> 
  6205                              <1> rswap:  ; < swap in, swap from disk >
  6206                              <1> 	; 28/02/2017 (frstor)
  6207                              <1> 	; 15/01/2017
  6208                              <1> 	; 14/01/2017
  6209                              <1> 	; 21/05/2016
  6210                              <1> 	; 03/05/2016
  6211                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6212                              <1> 	; 09/05/2015 - 15/09/2015 (Retro UNIX 386 v1)
  6213                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
  6214                              <1> 	; 'rswap' reads a process whose number is in r1, 
  6215                              <1> 	; from disk into core.
  6216                              <1> 	;
  6217                              <1> 	; Retro UNIX 386 v1 modification ->
  6218                              <1> 	;       User (u) structure content and the user's register content
  6219                              <1> 	;	will be restored from process's/user's UPAGE (a page for
  6220                              <1> 	;	saving 'u' structure and user registers for task switching).
  6221                              <1> 	;	u.usp - points to kernel stack address which contains
  6222                              <1> 	;		user's registers while entering system call.  
  6223                              <1> 	;	u.sp  - points to kernel stack address 
  6224                              <1> 	;		to return from system call -for IRET-.
  6225                              <1> 	;	[u.usp]+32+16 = [u.sp] 
  6226                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx, 
  6227                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
  6228                              <1> 	;
  6229                              <1> 	; RETRO UNIX 8086 v1 modification ->
  6230                              <1> 	;       'swap to disk' is replaced with 'change running segment'
  6231                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
  6232                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
  6233                              <1> 	;	compatibles was using 1MB segmented memory 
  6234                              <1> 	;	in 8086/8088 times.
  6235                              <1> 	;
  6236                              <1> 	; INPUTS ->
  6237                              <1> 	;    r1 - process number of process to be read in
  6238                              <1> 	;    p.break - negative of word count of process 
  6239                              <1> 	;    p.dska - disk address of the process		
  6240                              <1> 	;    u.emt - determines handling of emt's 	
  6241                              <1> 	;    u.ilgins - determines handling of illegal instructions		
  6242                              <1> 	; OUTPUTS ->
  6243                              <1> 	;    8 = (u.ilgins)
  6244                              <1> 	;    24 = (u.emt)
  6245                              <1> 	;    swp - bit 10 is set to indicate read 
  6246                              <1> 	;		(bit 15=0 when reading is done)	
  6247                              <1> 	;    swp+2 - disk block address
  6248                              <1> 	;    swp+4 - negative word count 	
  6249                              <1> 	;      ((swp+6 - address of user structure)) 
  6250                              <1> 	;
  6251                              <1> 	; RETRO UNIX 8086 v1 input/output:
  6252                              <1> 	;
  6253                              <1> 	; INPUTS ->
  6254                              <1> 	;    AL	- new process number (to be swapped in)	 
  6255                              <1> 	; OUTPUTS ->
  6256                              <1> 	;    none
  6257                              <1> 	;
  6258                              <1> 	;   ((Modified registers: EAX, ECX, ESI, EDI, ESP)) 
  6259                              <1> 	;
  6260                              <1> 	; Retro UNIX 386 v1 - modification ! 14/05/2015
  6261 0000E6C0 89C6                <1> 	mov	esi, eax  ; process's user (u) structure page addr
  6262 0000E6C2 B938000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
  6263 0000E6C7 BF[5C030300]        <1> 	mov	edi, user ; active user (u) structure	
  6264 0000E6CC F3A5                <1> 	rep	movsd
  6265 0000E6CE 58                  <1> 	pop	eax	; 'rswap' return address
  6266                              <1> 	; 
  6267                              <1> 	;cli
  6268 0000E6CF 8B3D[60030300]      <1> 	mov	edi, [u.usp] ; esp (system stack pointer, 
  6269                              <1> 			     ;     points to user registers)
  6270 0000E6D5 89FC                <1> 	mov	esp, edi     ; 14/01/2017
  6271 0000E6D7 8B0D[5C030300]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
  6272                              <1> 			     ; (for IRET)
  6273                              <1> 			     ; [u.sp] -> EIP (user)
  6274                              <1> 			     ; [u.sp+4]-> CS (user)
  6275                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
  6276                              <1> 			     ; [u.sp+12] -> ESP (user)
  6277                              <1> 			     ; [u.sp+16] -> SS (user)		
  6278 0000E6DD 29F9                <1> 	sub	ecx, edi     ; required space for user registers
  6279 0000E6DF 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
  6280                              <1> 			     ; (for IRET) 	
  6281 0000E6E2 C1E902              <1> 	shr	ecx, 2	       		
  6282 0000E6E5 F3A5                <1> 	rep	movsd
  6283                              <1> 	;mov	esp, [u.usp] ; 15/09/2015
  6284                              <1> 	;sti
  6285                              <1> 	; 28/02/2017
  6286                              <1> 	;cmp	byte [multi_tasking], 0  ; Musti tasking mode ?
  6287                              <1> 	;jna	short rswp_retn
  6288 0000E6E7 803D[DA030300]00    <1> 	cmp	byte [u.fpsave], 0
  6289 0000E6EE 7606                <1> 	jna	short rswp_retn
  6290 0000E6F0 DD25[DC030300]      <1> 	frstor	[u.fpregs] ; restore floating point regs (94 bytes)
  6291                              <1> rswp_retn:
  6292 0000E6F6 50                  <1> 	push	eax	; 'rswap' return address
  6293 0000E6F7 C3                  <1> 	retn
  6294                              <1> 
  6295                              <1> putlu: 
  6296                              <1> 	; 20/05/2016
  6297                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6298                              <1> 	; 10/05/2015 - 12/09/2015 (Retro UNIX 386 v1)
  6299                              <1> 	; 15/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
  6300                              <1> 	; 'putlu' is called with a process number in r1 and a pointer
  6301                              <1> 	; to lowest priority Q (runq+4) in r2. A link is created from
  6302                              <1> 	; the last process on the queue to process in r1 by putting
  6303                              <1> 	; the process number in r1 into the last process's link.
  6304                              <1> 	;
  6305                              <1> 	; INPUTS ->
  6306                              <1> 	;    r1 - user process number
  6307                              <1> 	;    r2 - points to lowest priority queue 
  6308                              <1> 	;    p.dska - disk address of the process		
  6309                              <1> 	;    u.emt - determines handling of emt's 	
  6310                              <1> 	;    u.ilgins - determines handling of illegal instructions		
  6311                              <1> 	; OUTPUTS ->
  6312                              <1> 	;    r3 - process number of last process on the queue upon
  6313                              <1> 	;	  entering putlu
  6314                              <1> 	;    p.link-1 + r3 - process number in r1
  6315                              <1> 	;    r2 - points to lowest priority queue
  6316                              <1> 	;
  6317                              <1> 	; ((Modified registers: EDX, EBX)) 
  6318                              <1> 	;
  6319                              <1> 	; / r1 = user process no.; r2 points to lowest priority queue
  6320                              <1> 
  6321                              <1> 	; EBX = r2
  6322                              <1> 	; EAX = r1 (AL=r1b)
  6323                              <1> 
  6324                              <1> 	; 20/05/2016
  6325                              <1> 	; AL = process number (1 to 16) // Retro UNIX 8086, 386 v1 // 
  6326                              <1> 	;     (max. 16 processes available for current kernel version) 
  6327                              <1> 	; EBX = run queue address ; 20/05/2016 (TRDOS 386)
  6328                              <1> 		; which is one of following addresses:
  6329                              <1> 		;  1) 'runq_event' high priority run queue	 	
  6330                              <1> 		;  2) 'runq_normal' normal/regular priority run queue
  6331                              <1> 		;  3) 'runq_background' low priority run queue
  6332                              <1> 
  6333                              <1> 	;mov	ebx, runq
  6334 0000E6F8 0FB613              <1> 	movzx  	edx, byte [ebx]
  6335 0000E6FB 43                  <1> 	inc	ebx
  6336 0000E6FC 20D2                <1> 	and	dl, dl
  6337                              <1> 		; tstb (r2)+ / is queue empty?
  6338 0000E6FE 740A                <1>        	jz	short putlu_1
  6339                              <1> 		; beq 1f / yes, branch
  6340 0000E700 8A13                <1> 	mov 	dl, [ebx] ; 12/09/2015
  6341                              <1> 		; movb (r2),r3 / no, save the "last user" process number
  6342                              <1> 			     ; / in r3
  6343 0000E702 8882[9F000300]      <1>        	mov	[edx+p.link-1], al
  6344                              <1> 		; movb r1,p.link-1(r3) / put pointer to user on 
  6345                              <1> 			     ; / "last users" link
  6346 0000E708 EB03                <1> 	jmp	short putlu_2
  6347                              <1> 		; br 2f /
  6348                              <1> putlu_1: ; 1:
  6349 0000E70A 8843FF              <1> 	mov	[ebx-1], al
  6350                              <1>        		; movb r1,-1(r2) / user is only user; 
  6351                              <1> 			    ; / put process no. at beginning and at end
  6352                              <1> putlu_2: ; 2: 
  6353 0000E70D 8803                <1> 	mov	[ebx], al
  6354                              <1>        		; movb r1,(r2) / user process in r1 is now the last entry
  6355                              <1> 			     ; / on the queue
  6356 0000E70F 88C2                <1> 	mov	dl, al
  6357 0000E711 88B2[9F000300]      <1>         mov     [edx+p.link-1], dh ; 0
  6358                              <1> 		; dec r2 / restore r2
  6359 0000E717 C3                  <1>         retn
  6360                              <1> 		; rts r0
  6361                              <1> 
  6362                              <1> sysver:
  6363                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  6364 0000E718 C705[64030300]0002- <1> 	mov	dword [u.r0], 200h ; AH = major version, AL = minor version 
  6364 0000E720 0000                <1>
  6365 0000E722 E912E0FFFF          <1> 	jmp	sysret
  6366                              <1> 
  6367                              <1> 
  6368                              <1> syspri: ; change running priority (of the process)
  6369                              <1> 	; 21/05/2016
  6370                              <1> 	; 20/05/2026 - TRDOS 386 (TRDOS v2.0)
  6371                              <1> 	; INPUT ->
  6372                              <1> 	;	BL = priority level
  6373                              <1> 	;	   0 = low running priority (running on background)
  6374                              <1> 	;	   1 = normal/regular priority (running as regular)
  6375                              <1> 	;	   2 = high/event priority (running for event)
  6376                              <1> 	;	   >2 = invalid, it will accepted as 2 (event)
  6377                              <1> 	;	   0FFh = get/return current running priority only	
  6378                              <1> 	; OUTPUT -> 	
  6379                              <1> 	;	* if current [u.pri] < 2
  6380                              <1> 	;	  if BL input < 0FFh ->
  6381                              <1> 	;	     [u.pri] is updated as in BL input (0,1,2)
  6382                              <1> 	;	  if BL input = 0FFh -> AL = [u.pri] (current)
  6383                              <1> 	;	      
  6384                              <1> 	;	* if current [u.pri] = 2
  6385                              <1> 	;	  if BL input < 0FFh -> cf = 1 & AL = 2
  6386                              <1> 	;	  if BL input = 0FFh -> cf = 0 & AL = 2  
  6387                              <1> 	;	
  6388                              <1> 	;	NOTE: 	
  6389                              <1> 	;	If [u.pri] = 2, it can not be changed to 1 or 0;
  6390                              <1> 	;	because, run queue of the running process is unspecified
  6391                              <1> 	;	at this	stage. Process might be started by a timer event
  6392                              <1> 	;	or priority might be changed to high by previous
  6393                              <1> 	;	'syspri' system	call. In both cases, the process is in
  6394                              <1> 	;	'runq_normal' or 'runq_background' queue.
  6395                              <1> 	;	As result of this fact, when the [u.quant] time quantum
  6396                              <1> 	;	of the process is elapsed or 'sysrele' system call is
  6397                              <1> 	;	instructed by the process, 'tswap' ('tswitch') procedure
  6398                              <1> 	;	will be called (to 'swap' or 'switch' out the procedure)
  6399                              <1> 	;	and it will not call 'putlu' to add the (stopping)
  6400                              <1> 	;	process to relevant run queue when [u.pri] = 2.
  6401                              <1> 	;	(Otherwise, it would be possible to add process to
  6402                              <1> 	;	a run queue while it is already in a run queue, wrongly.)
  6403                              <1>   	;
  6404                              <1> 	;	If [u.pri]< 2, 'tswap/tswitch' procedure will call 
  6405                              <1> 	;	'putlu' to add process to relevant run queue
  6406                              <1> 	;	according to [u.pri] value. ('runq_normal' for 1, 
  6407                              <1> 	;	'runq_background' for 0).
  6408                              <1> 	;
  6409                              <1> 	;	If BL input >= 2 and < 0FFh while [u.pri] < 2,
  6410                              <1> 	;	process will be added to 'runq_normal' queue and
  6411                              <1> 	;	[u.pri] will be set to 2. (in 'syspri' system call)
  6412                              <1> 	;
  6413                              <1> 
  6414 0000E727 29C0                <1> 	sub	eax, eax ; 0
  6415 0000E729 A3[C8030300]        <1> 	mov	[u.error], eax
  6416                              <1> 
  6417 0000E72E A0[A9030300]        <1> 	mov	al, [u.pri]
  6418 0000E733 A3[64030300]        <1> 	mov	[u.r0], eax
  6419                              <1> 
  6420 0000E738 FEC3                <1> 	inc	bl
  6421 0000E73A 0F84F9DFFFFF        <1> 	jz	sysret ; 0FFh -> 0, get priority level
  6422                              <1> 	
  6423 0000E740 3C02                <1> 	cmp	al, 2
  6424 0000E742 0F83D1DFFFFF        <1> 	jnb	error ; CF = 1 & AL = 2 (& last error = 0)
  6425                              <1> 
  6426 0000E748 FECB                <1> 	dec	bl
  6427 0000E74A 80FB02              <1> 	cmp	bl, 2
  6428 0000E74D 7602                <1> 	jna	short syspri_1
  6429 0000E74F B302                <1> 	mov	bl, 2
  6430                              <1> syspri_1:
  6431 0000E751 881D[A9030300]      <1> 	mov	[u.pri], bl
  6432 0000E757 80FB02              <1> 	cmp	bl, 2
  6433 0000E75A 0F82D9DFFFFF        <1>         jb      sysret
  6434                              <1> 
  6435                              <1> 	; here...
  6436                              <1> 	; Priority of current process has been changed to high
  6437                              <1> 	; ('run for event') but current process will be added to
  6438                              <1> 	; 'run as normal' queue. ('run for event' high priority
  6439                              <1> 	; queue is under control of timer -& RTC- interrupt only!) 
  6440                              <1> 	;
  6441                              <1> 	; (Otherwise, process can fall into black hole!
  6442                              <1> 	; e.g. if it is not in waiting list and it has not got 
  6443                              <1> 	; a timer event and it is not in a run queue!
  6444                              <1> 	; Because, when [u.pri] is 2, 'tswap/tswitch' will not 
  6445                              <1> 	; add the stopping process to a run queue.)
  6446                              <1> 
  6447 0000E760 A0[B3030300]        <1> 	mov	al, [u.uno]
  6448 0000E765 BB[54030300]        <1> 	mov	ebx, runq_normal ; normal priority !
  6449                              <1> 				 ; [u.pri] is set to high
  6450                              <1> 				 ; but 'runq_event' queue is set
  6451                              <1> 				 ; only by the kernel's timer
  6452                              <1> 				 ; event function (timer interrupt). 
  6453 0000E76A E889FFFFFF          <1> 	call	putlu
  6454 0000E76F E9C5DFFFFF          <1> 	jmp	sysret
  6455                              <1> 
  6456                              <1> cpass: ; / get next character from user area of core and put it in AL (r1)
  6457                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
  6458                              <1> 	; 19/05/2015 - 18/10/2015 (Retro UNIX 386 v1)
  6459                              <1> 	; 14/08/2013 - 20/09/2013 (Retro UNIX 8086 v1)
  6460                              <1> 	; INPUTS -> 
  6461                              <1> 	;     [u.base] = virtual address in user area
  6462                              <1> 	;     [u.count] = byte count (max.)
  6463                              <1> 	;     [u.pcount] = byte count in page (0 = reset)		
  6464                              <1> 	; OUTPUTS -> 
  6465                              <1> 	;     AL = the character which is pointed by [u.base]
  6466                              <1> 	;     zf = 1 -> transfer count has been completed	
  6467                              <1>         ;
  6468                              <1> 	; ((Modified registers:  EAX, EDX, ECX))
  6469                              <1> 	;
  6470 0000E774 833D[88030300]00    <1> 	cmp 	dword [u.count], 0  ; have all the characters been transferred
  6471                              <1> 			    	    ; i.e., u.count, # of chars. left
  6472 0000E77B 763F                <1> 	jna	short cpass_3	    ; to be transferred = 0?) yes, branch
  6473 0000E77D FF0D[88030300]      <1> 	dec	dword [u.count]	    ; no, decrement u.count
  6474                              <1>         ; 19/05/2015 
  6475                              <1> 	;(Retro UNIX 386 v1 - translation from user's virtual address
  6476                              <1> 	;		      to physical address
  6477 0000E783 66833D[C4030300]00  <1> 	cmp	word [u.pcount], 0 ; byte count in page = 0 (initial value)
  6478                              <1> 			     ; 1-4095 --> use previous physical base address
  6479                              <1> 			     ; in [u.pbase]
  6480 0000E78B 770E                <1> 	ja	short cpass_1
  6481 0000E78D 833D[BC030300]00    <1> 	cmp     dword [u.ppgdir], 0 ; is the caller os kernel
  6482 0000E794 7427                <1>         je      short cpass_k       ; (sysexec, '/etc/init') ?  (MainProg)
  6483 0000E796 E858FDFFFF          <1> 	call	trans_addr_r
  6484                              <1> cpass_1:
  6485 0000E79B 66FF0D[C4030300]    <1> 	dec	word [u.pcount]
  6486                              <1> cpass_2: 
  6487 0000E7A2 8B15[C0030300]      <1> 	mov	edx, [u.pbase]
  6488 0000E7A8 8A02                <1> 	mov	al, [edx]	; take the character pointed to 
  6489                              <1> 				; by u.base and put it in r1
  6490 0000E7AA FF05[8C030300]      <1> 	inc	dword [u.nread] ; increment no. of bytes transferred
  6491 0000E7B0 FF05[84030300]      <1> 	inc	dword [u.base]  ; increment the buffer address to point to the
  6492                              <1> 			        ; next byte
  6493 0000E7B6 FF05[C0030300]      <1> 	inc	dword [u.pbase]
  6494                              <1> cpass_3:
  6495 0000E7BC C3                  <1> 	retn
  6496                              <1> cpass_k:
  6497                              <1> 	; 02/07/2015
  6498                              <1> 	; The caller is os kernel 
  6499                              <1> 	; (get sysexec arguments from kernel's memory space)
  6500 0000E7BD 8B1D[84030300]      <1> 	mov	ebx, [u.base]
  6501 0000E7C3 66C705[C4030300]00- <1>         mov     word [u.pcount], PAGE_SIZE ; 4096
  6501 0000E7CB 10                  <1>
  6502 0000E7CC 891D[C0030300]      <1> 	mov	[u.pbase], ebx
  6503 0000E7D2 EBCE                <1> 	jmp	short cpass_2
  6504                              <1> 
  6505                              <1> transfer_to_user_buffer: ; fast transfer
  6506                              <1> 	; 27/05/2016
  6507                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  6508                              <1> 	;
  6509                              <1> 	; INPUT ->
  6510                              <1> 	;	ESI = source address in system space
  6511                              <1> 	;	EDI = user's buffer address
  6512                              <1> 	;	ECX = transfer (byte) count
  6513                              <1> 	;	[u.pgdir] = user's page directory
  6514                              <1> 	; OUTPUT ->
  6515                              <1> 	;	ECX = actual transfer count
  6516                              <1> 	;	cf = 1 -> error
  6517                              <1> 	;	[u.count] = remain byte count
  6518                              <1> 	;
  6519                              <1> 	; Modified registers: eax, ecx
  6520                              <1> 	;
  6521                              <1> 
  6522 0000E7D4 21C9                <1> 	and	ecx, ecx
  6523 0000E7D6 743B                <1> 	jz	short ttub_4
  6524                              <1> 
  6525 0000E7D8 890D[88030300]      <1> 	mov	[u.count], ecx
  6526                              <1> 	
  6527 0000E7DE 57                  <1> 	push	edi
  6528 0000E7DF 56                  <1> 	push	esi
  6529 0000E7E0 53                  <1> 	push	ebx
  6530 0000E7E1 52                  <1> 	push	edx
  6531 0000E7E2 51                  <1> 	push	ecx
  6532                              <1> 
  6533 0000E7E3 89FB                <1> 	mov	ebx, edi
  6534 0000E7E5 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
  6535                              <1> ttub_1:
  6536                              <1> 	; ebx = virtual (linear) address
  6537                              <1> 	; [u.pgdir] = user's page directory
  6538 0000E7EB E8D76AFFFF          <1>        	call	get_physical_addr_x ; get physical address
  6539 0000E7F0 7222                <1> 	jc	short ttub_5
  6540                              <1> 	; eax = physical address 
  6541                              <1> 	; ecx = remain byte count in page (1-4096)
  6542 0000E7F2 89C7                <1> 	mov	edi, eax
  6543 0000E7F4 A1[88030300]        <1> 	mov	eax, [u.count]
  6544 0000E7F9 39C1                <1> 	cmp	ecx, eax
  6545 0000E7FB 7602                <1> 	jna	short ttub_2
  6546 0000E7FD 89C1                <1> 	mov	ecx, eax
  6547                              <1> ttub_2:	
  6548 0000E7FF 29C8                <1> 	sub	eax, ecx
  6549 0000E801 01CB                <1> 	add	ebx, ecx
  6550 0000E803 F3A4                <1> 	rep	movsb
  6551 0000E805 A3[88030300]        <1> 	mov	[u.count], eax
  6552 0000E80A 09C0                <1> 	or	eax, eax
  6553 0000E80C 75DD                <1> 	jnz	short ttub_1
  6554                              <1> ttub_retn:
  6555                              <1> tfub_retn:
  6556 0000E80E 59                  <1> 	pop	ecx ; transfer count = actual transfer count
  6557                              <1> ttub_3:
  6558 0000E80F 5A                  <1> 	pop	edx
  6559 0000E810 5B                  <1> 	pop	ebx
  6560 0000E811 5E                  <1> 	pop	esi
  6561 0000E812 5F                  <1> 	pop	edi
  6562                              <1> ttub_4:
  6563 0000E813 C3                  <1> 	retn
  6564                              <1> ttub_5:
  6565 0000E814 59                  <1> 	pop	ecx
  6566 0000E815 2B0D[88030300]      <1> 	sub	ecx, [u.count] ; actual transfer count
  6567 0000E81B F9                  <1> 	stc
  6568 0000E81C EBF1                <1> 	jmp	short ttub_3
  6569                              <1> 
  6570                              <1> transfer_from_user_buffer: ; fast transfer
  6571                              <1> 	; 27/05/2016
  6572                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  6573                              <1> 	;
  6574                              <1> 	; INPUT ->
  6575                              <1> 	;	ESI = user's buffer address
  6576                              <1> 	;	EDI = destination address in system space
  6577                              <1> 	;	ECX = transfer (byte) count
  6578                              <1> 	;	[u.pgdir] = user's page directory
  6579                              <1> 	; OUTPUT ->
  6580                              <1> 	;	ecx = actual transfer count
  6581                              <1> 	;	cf = 1 -> error
  6582                              <1> 	;	[u.count] = remain byte count
  6583                              <1> 	;
  6584                              <1> 	; Modified registers: eax, ecx
  6585                              <1> 	;
  6586                              <1> 
  6587 0000E81E 21C9                <1> 	and	ecx, ecx
  6588                              <1> 	;jz	short tfub_4
  6589 0000E820 74F1                <1> 	jz	short ttub_4
  6590                              <1> 
  6591 0000E822 890D[88030300]      <1> 	mov	[u.count], ecx
  6592                              <1> 	
  6593 0000E828 57                  <1> 	push	edi
  6594 0000E829 56                  <1> 	push	esi
  6595 0000E82A 53                  <1> 	push	ebx
  6596 0000E82B 52                  <1> 	push	edx
  6597 0000E82C 51                  <1> 	push	ecx
  6598                              <1> 
  6599 0000E82D 89F3                <1> 	mov	ebx, esi
  6600 0000E82F 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
  6601                              <1> tfub_1:
  6602                              <1> 	; ebx = virtual (linear) address
  6603                              <1> 	; [u.pgdir] = user's page directory
  6604 0000E835 E88D6AFFFF          <1>        	call	get_physical_addr_x ; get physical address
  6605                              <1> 	;jc	short tfub_5
  6606 0000E83A 72D8                <1> 	jc	short ttub_5
  6607                              <1> 	; eax = physical address 
  6608                              <1> 	; ecx = remain byte count in page (1-4096)
  6609 0000E83C 89C6                <1> 	mov	esi, eax
  6610 0000E83E A1[88030300]        <1> 	mov	eax, [u.count]
  6611 0000E843 39C1                <1> 	cmp	ecx, eax
  6612 0000E845 7602                <1> 	jna	short tfub_2
  6613 0000E847 89C1                <1> 	mov	ecx, eax
  6614                              <1> tfub_2:	
  6615 0000E849 29C8                <1> 	sub	eax, ecx
  6616 0000E84B 01CB                <1> 	add	ebx, ecx
  6617 0000E84D F3A4                <1> 	rep	movsb
  6618 0000E84F A3[88030300]        <1> 	mov	[u.count], eax
  6619 0000E854 09C0                <1> 	or	eax, eax
  6620 0000E856 75DD                <1> 	jnz	short tfub_1
  6621                              <1> 
  6622 0000E858 EBB4                <1> 	jmp	short tfub_retn
  6623                              <1> 
  6624                              <1> ;tfub_retn:
  6625                              <1> ;	pop	ecx ; transfer count = actual transfer count
  6626                              <1> ;tfub_3:
  6627                              <1> ;	pop	edx
  6628                              <1> ;	pop	ebx
  6629                              <1> ;	pop	esi
  6630                              <1> ;	pop	edi
  6631                              <1> ;tfub_4:
  6632                              <1> ;	retn
  6633                              <1> ;tfub_5:
  6634                              <1> ;	pop	ecx
  6635                              <1> ;	sub	ecx, [u.count] ; actual transfer count
  6636                              <1> ;	stc
  6637                              <1> ;	jmp	short tfub_3
  6638                              <1> 
  6639                              <1> sysfff: ; <Find First File>
  6640                              <1> 	; 17/10/2016
  6641                              <1> 	; 16/10/2016
  6642                              <1> 	; 15/10/2016 TRDOS 386 (TRDOS v2.0) feature only ! 
  6643                              <1> 	;           -derived from TRDOS v1.0, INT_21H.ASM-
  6644                              <1> 	;            ("loc_INT21h_find_first_file")
  6645                              <1> 	; TRDOS 8086 (v1.0)
  6646                              <1>         ; 	07/08/2011 
  6647                              <1>         ;	Find First File
  6648                              <1> 	;	INPUT:
  6649                              <1>         ;	    CX= Attributes
  6650                              <1>         ;	    DS:DX= Pointer to filename
  6651                              <1> 	;	MSDOS OUTPUT:
  6652                              <1> 	;	    DTA: (Default address: PSP offset 80h)
  6653                              <1> 	;	    Offset  Descrription
  6654                              <1> 	;	    0	    Reserved for use find next file
  6655                              <1> 	;	    21	    Attribute of file found
  6656                              <1> 	;	    22	    Time stamp of file
  6657                              <1> 	;	    24	    Date stamp of file
  6658                              <1> 	;	    26	    File size in bytes
  6659                              <1> 	;	    30	    Filename and extension (zero terminated)
  6660                              <1> 	;	If cf = 1:
  6661                              <1> 	;	    Error Codes: (in AX)
  6662                              <1> 	;	    	2 - File not found
  6663                              <1> 	;	       18 - No more files  			
  6664                              <1>         ;
  6665                              <1> 	; TRDOS 386 (v2.0) 
  6666                              <1> 	; 15/10/2016
  6667                              <1> 	;	
  6668                              <1>         ; INPUT ->
  6669                              <1>         ;	   CL = File attributes
  6670                              <1> 	;     	      bit 0 (1) - Read only file (R)
  6671                              <1> 	;             bit 1 (1) - Hidden file (H)
  6672                              <1>         ;             bit 2 (1) - System file (R)
  6673                              <1> 	;             bit 3 (1) - Volume label/name (V)
  6674                              <1>         ;             bit 4 (1) - Subdirectory (D)
  6675                              <1> 	;	      bit 5 (1) - File has been archived (A)
  6676                              <1> 	;	   CH = 0 -> Return basic parameters (24 bytes)
  6677                              <1> 	;	   CH > 0 -> Return FindFile structure/table (128 bytes)
  6678                              <1>         ;          EBX = Pointer to filename (ASCIIZ) -path-
  6679                              <1> 	;	   EDX = File parameters buffer address
  6680                              <1> 	;		(buffer size = 24 bytes if CH input = 0)
  6681                              <1> 	;		(buffer size = 128 bytes if CH input > 0)
  6682                              <1> 	;		 
  6683                              <1> 	; OUTPUT ->
  6684                              <1> 	;	   EAX = 0 if CH input > 0
  6685                              <1> 	;	   EAX = First cluster number of file if CH input = 0	
  6686                              <1> 	;	   EDX = File parameters table/structure address
  6687                              <1> 	;	   Basic Parameters:
  6688                              <1> 	;		Offset  Description
  6689                              <1> 	;		------	---------------
  6690                              <1> 	;		0	File Attributes
  6691                              <1> 	;		1	Ambiguous filename chars are used sign
  6692                              <1> 	;			(0 = filename fits exactly with request)
  6693                              <1> 	;			(>0 = ambiguous filename chars are used)
  6694                              <1> 	;	      	2	Time stamp of file
  6695                              <1> 	;		4	Date stamp of file
  6696                              <1> 	;		6	File size in bytes
  6697                              <1> 	;		10	Short Filename (ASCIIZ, max. 13 bytes)
  6698                              <1> 	;		23	Longname Length (1-255) if existing 
  6699                              <1> 	;  
  6700                              <1> 	;          cf = 1 -> Error code in AL
  6701                              <1> 	;
  6702                              <1> 	; Modified Registers: EAX (at the return of system call)
  6703                              <1> 	;  
  6704                              <1> 	; TR-DOS FindFile (FFF) Structure (128 bytes):
  6705                              <1> 	; 09/10/2011 (DIR.ASM) - 10/02/2016 (trdoskx.s)
  6706                              <1> 	;	
  6707                              <1> 	; Offset	Parameter		Size
  6708                              <1> 	; ------	------------------	-------- 
  6709                              <1> 	; 0		FindFile_Drv		1 byte
  6710                              <1> 	; 1		FindFile_Directory	65 bytes
  6711                              <1> 	; 66		FindFile_Name		13 bytes
  6712                              <1> 	; 79		FindFile_LongNameEntryLength 1 byte
  6713                              <1> 	;Above 80 bytes form
  6714                              <1> 	;TR-DOS Source/Destination File FullName Format/Structure
  6715                              <1> 	; 80		FindFile_AttributesMask 1 word
  6716                              <1> 	; 82		FindFile_DirEntry	32 bytes (*)
  6717                              <1> 	; 114		FindFile_DirFirstCluster 1 double word
  6718                              <1> 	; 118		FindFile_DirCluster	1 double word
  6719                              <1> 	; 122		FindFile_DirEntryNumber 1 word
  6720                              <1> 	; 124		FindFile_MatchCounter	1 word
  6721                              <1> 	; 126		FindFile_Reserved	1 word
  6722                              <1>    	; (*) MS-DOS, FAT 12-16-32 classic directory entry (32 bytes)
  6723                              <1> 
  6724                              <1> 	;mov	[u.namep], ebx
  6725                              <1> 	; 16/10/2016
  6726 0000E85A 8915[50650100]      <1> 	mov	[FFF_UBuffer], edx
  6727 0000E860 66890D[55650100]    <1> 	mov	[FFF_Attrib], cx ; [FFF_RType] = ch
  6728                              <1> 		    ; Attributes in CL, return data type in CH
  6729 0000E867 89DE                <1> 	mov	esi, ebx
  6730                              <1> 	; file name is forced, change directory as temporary
  6731                              <1> 	;mov	ax, 1
  6732                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
  6733                              <1> 	;call	set_working_path 
  6734 0000E869 E8E8130000          <1> 	call	set_working_path_x ; 17/10/2016	
  6735 0000E86E 731D                <1> 	jnc	short sysfff_0
  6736                              <1>  
  6737 0000E870 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  6738 0000E872 7505                <1> 	jnz	short sysfff_err
  6739                              <1> 
  6740                              <1> 	; eax = 0
  6741 0000E874 B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
  6742                              <1> sysfff_err:
  6743 0000E879 A3[64030300]        <1> 	mov	[u.r0], eax
  6744 0000E87E A3[C8030300]        <1> 	mov	[u.error], eax
  6745 0000E883 E8A3140000          <1>         call 	reset_working_path
  6746 0000E888 E98CDEFFFF          <1> 	jmp	error
  6747                              <1> 
  6748                              <1> sysfff_0:
  6749                              <1> 	;sub	ah, ah ; ah = 0
  6750 0000E88D 8A0424              <1> 	mov	al, [esp]
  6751 0000E890 08C0                <1> 	or	al, al
  6752 0000E892 7412                <1> 	jz	short sysfff_2
  6753 0000E894 B410                <1> 	mov	ah, 10h
  6754 0000E896 A808                <1> 	test	al, 08h
  6755 0000E898 7503                <1> 	jnz	short sysfff_1
  6756 0000E89A 80CC08              <1> 	or	ah, 08h
  6757                              <1> sysfff_1:
  6758 0000E89D 2410                <1> 	and	al, 10h ; Directory
  6759 0000E89F 7405                <1> 	jz	short sysfff_2
  6760 0000E8A1 80E408              <1> 	and	ah, 08h
  6761 0000E8A4 30C0                <1> 	xor	al, al ; When a directory is searched,
  6762                              <1> 		       ; filename will be returned even if
  6763                              <1> 		       ; it is not a directory!
  6764                              <1> 		       ; Because: (in order to prevent
  6765                              <1> 		       ; creating a dir with existing file name)
  6766                              <1> 		       ; Dir and file names must not be same!
  6767                              <1> 		       ; (return attribute must be checked)  	  	 	
  6768                              <1> sysfff_2:
  6769                              <1> 	; AX = Attributes mask 
  6770                              <1> 		; AL = AND mask (result must be equal to AL)
  6771                              <1> 		; AH = Negative AND mask (result must be ZERO)			
  6772                              <1>  	; ESI = FindFile_Name address
  6773                              <1> 
  6774 0000E8A6 E8139AFFFF          <1> 	call	find_first_file
  6775 0000E8AB 72CC                <1> 	jc	short sysfff_err ; eax = 2 (File not found !)
  6776                              <1> 
  6777                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  6778                              <1> 	; EDI = Directory Buffer Directory Entry Location
  6779                              <1> 	; EAX = File Size
  6780                              <1> 	;  BL = Attributes of The File/Directory
  6781                              <1> 	;  BH = Long Name Yes/No Status (>0 is YES)
  6782                              <1> 	;  DX > 0 : Ambiguous filename chars are used
  6783                              <1> 
  6784                              <1> sysfff_3:
  6785                              <1> 	; 16/10/2016
  6786 0000E8AD 668B0D[55650100]    <1> 	mov	cx, [FFF_Attrib]
  6787                              <1> 	; Attribs in CL, return data type in CH
  6788                              <1> 
  6789                              <1> 	;or	cl, cl
  6790                              <1> 	;jz	short sysfff_4 ; 0 = No filter
  6791 0000E8B4 80F1FF              <1> 	xor	cl, 0FFh
  6792 0000E8B7 20D9                <1> 	and	cl, bl
  6793 0000E8B9 7409                <1> 	jz	short sysfff_4
  6794                              <1> 
  6795                              <1> 	;mov	eax, 2 ; 'file not found !' error
  6796                              <1> 	;jmp	short sysfff_err_1
  6797                              <1> 
  6798                              <1> 	; 16/10/2016
  6799 0000E8BB E8AD9AFFFF          <1> 	call	find_next_file
  6800 0000E8C0 72B7                <1> 	jc	short sysfff_err ; eax = 12 (no more files !)
  6801 0000E8C2 EBE9                <1> 	jmp	short sysfff_3
  6802                              <1> 
  6803                              <1> sysfff_4:
  6804 0000E8C4 20ED                <1> 	and	ch, ch ; [FFF_RType]
  6805 0000E8C6 7412                <1> 	jz	short sysfff_5
  6806 0000E8C8 B980000000          <1> 	mov	ecx, 128 ; ; transfer length
  6807 0000E8CD 880D[54650100]      <1> 	mov	[FFF_Valid], cl
  6808                              <1> sysfnf_11:
  6809 0000E8D3 BE[06620100]        <1> 	mov	esi, FindFile_Drv
  6810 0000E8D8 EB44                <1> 	jmp	short sysfff_6	
  6811                              <1> sysfff_5:
  6812                              <1> 	;mov	esi, FindFile_DirEntry
  6813 0000E8DA B918000000          <1> 	mov	ecx, 24  ; transfer length
  6814 0000E8DF 880D[54650100]      <1> 	mov	[FFF_Valid], cl
  6815                              <1> sysfnf_12:
  6816 0000E8E5 BF[106A0100]        <1> 	mov	edi, DTA ; FFF data transfer address
  6817                              <1> 	;mov	al, [esi+DirEntry_Attr] ; 11
  6818 0000E8EA 88D8                <1> 	mov	al, bl ; File/Dir Attributes
  6819 0000E8EC 887F17              <1> 	mov	[edi+23], bh ; Longname length (0= none)
  6820 0000E8EF AA                  <1> 	stosb
  6821 0000E8F0 88D0                <1> 	mov	al, dl ; DL is for '?'
  6822 0000E8F2 00F0                <1> 	add	al, dh ; DH is for '*'
  6823                              <1> 	; AL > 0 if ambiguous file name wildcards are used
  6824 0000E8F4 AA                  <1> 	stosb
  6825 0000E8F5 8B4616              <1> 	mov	eax, [esi+DirEntry_WrtTime] ; 22	
  6826 0000E8F8 AB                  <1>         stosd	; DirEntry_WrtTime & DirEntry_WrtDate
  6827 0000E8F9 8B461C              <1>         mov	eax, [esi+DirEntry_FileSize] ; 28
  6828 0000E8FC AB                  <1>         stosd
  6829 0000E8FD 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI] ; 20
  6830 0000E901 66C1E010            <1> 	shl	ax, 16
  6831 0000E905 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO] ; 26 
  6832 0000E909 A3[64030300]        <1> 	mov	[u.r0], eax ; First Cluster
  6833                              <1> 
  6834                              <1>         ;mov	esi, FindFile_DirEntry
  6835 0000E90E E855140000          <1> 	call	get_file_name
  6836                              <1> 
  6837 0000E913 8A0D[54650100]      <1> 	mov	cl, [FFF_Valid]
  6838 0000E919 BE[106A0100]        <1>        	mov	esi, DTA ; FFF data transfer address
  6839                              <1> sysfff_6:
  6840 0000E91E 8B3D[50650100]      <1> 	mov	edi, [FFF_UBuffer] ; user's buffer address (edx)
  6841 0000E924 E8ABFEFFFF          <1> 	call	transfer_to_user_buffer
  6842                              <1> 
  6843 0000E929 890D[64030300]      <1> 	mov	[u.r0], ecx ; actual transfer count
  6844 0000E92F E8F7130000          <1>         call 	reset_working_path
  6845 0000E934 E900DEFFFF          <1> 	jmp	sysret
  6846                              <1> 
  6847                              <1> sysfnf: ; <Find Next File>
  6848                              <1> 	; 16/10/2016 TRDOS 386 (TRDOS v2.0) feature only ! 
  6849                              <1> 	;           -derived from TRDOS v1.0, INT_21H.ASM-
  6850                              <1> 	;            ("loc_INT21h_find_next_file")
  6851                              <1> 	; TRDOS 8086 (v1.0)
  6852                              <1>         ; 	07/08/2011 
  6853                              <1>         ;	Find First File
  6854                              <1> 	;	INPUT:
  6855                              <1>         ;	    none
  6856                              <1> 	;	MSDOS OUTPUT:
  6857                              <1> 	;	    DTA: (Default address: PSP offset 80h)
  6858                              <1> 	;	    Offset  Descrription
  6859                              <1> 	;	    0	    Reserved for use find next file
  6860                              <1> 	;	    21	    Attribute of file found
  6861                              <1> 	;	    22	    Time stamp of file
  6862                              <1> 	;	    24	    Date stamp of file
  6863                              <1> 	;	    26	    File size in bytes
  6864                              <1> 	;	    30	    Filename and extension (zero terminated)
  6865                              <1> 	;	If cf = 1:
  6866                              <1> 	;	    Error Codes: (in AX)
  6867                              <1> 	;	       18 - No more files  			
  6868                              <1>         ;
  6869                              <1> 	; TRDOS 386 (v2.0) 
  6870                              <1> 	; 16/10/2016
  6871                              <1> 	;	
  6872                              <1>         ; INPUT ->
  6873                              <1>        	; 	   none
  6874                              <1> 	; OUTPUT ->
  6875                              <1> 	;	   EAX = 0 if CH input of 'Find First File' > 0
  6876                              <1> 	;	   EAX = First cluster number of file
  6877                              <1> 	;		 if CH input of 'Find First File' = 0	
  6878                              <1> 	;	   EDX = File parameters table/structure address
  6879                              <1> 	;
  6880                              <1> 	;          cf = 1 -> Error code in AL
  6881                              <1> 	;
  6882                              <1>  	; Modified Registers: EAX (at the return of system call)	
  6883                              <1> 
  6884                              <1> 	;	
  6885                              <1> 	; Note: If byte [FFF_Valid] = 0
  6886                              <1> 	;	'sysfnf' will return with 'no more files' error.
  6887                              <1> 	;	If byte [FFF_Valid] = 24
  6888                              <1> 	;	'sysfnf' will return with 32 bytes basic parameters
  6889                              <1> 	;	at the address which is in EDX.
  6890                              <1> 	;	If byte [FFF_Valid] = 128
  6891                              <1> 	;	'sysfnf' will return with 128 bytes Find File 
  6892                              <1> 	;	Structure/Table at the address which is in EDX.
  6893                              <1> 	
  6894 0000E939 803D[54650100]00    <1> 	cmp	byte [FFF_Valid], 0
  6895 0000E940 7714                <1> 	ja	short stsfnf_0
  6896                              <1>  	; 'no more files !' error 
  6897 0000E942 B80C000000          <1> 	mov	eax, ERR_NO_MORE_FILES ; 12
  6898 0000E947 A3[64030300]        <1> 	mov	[u.r0], eax
  6899 0000E94C A3[C8030300]        <1> 	mov	[u.error], eax
  6900 0000E951 E9C3DDFFFF          <1> 	jmp	error
  6901                              <1> stsfnf_0:
  6902                              <1> 	;cmp	byte [FFF_Valid], 128
  6903                              <1> 	;je	short stsfnf_1
  6904                              <1> 	;cmp	byte [FFF_Valid], 24
  6905                              <1> 	;je	short stsfnf_1
  6906                              <1> 	;mov	[FFF_Valid], 24 ; Default
  6907                              <1> stsfnf_1:
  6908 0000E956 0FB61D[6E590100]    <1> 	movzx	ebx, byte [Current_Drv]
  6909 0000E95D 66891D[5A650100]    <1> 	mov	[SWP_DRV], bx
  6910 0000E964 8A15[06620100]      <1> 	mov	dl, [FindFile_Drv]
  6911 0000E96A 38DA                <1> 	cmp	dl, bl
  6912 0000E96C 750B                <1> 	jne	short stsfnf_2
  6913 0000E96E 86FB                <1> 	xchg	bh, bl
  6914 0000E970 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  6915 0000E975 01DE                <1> 	add	esi, ebx
  6916 0000E977 EB0D                <1> 	jmp	short sysfnf_3
  6917                              <1> 
  6918                              <1> stsfnf_2:
  6919 0000E979 FE05[5B650100]      <1> 	inc	byte [SWP_DRV_chg]
  6920                              <1> 
  6921 0000E97F E89785FFFF          <1> 	call	change_current_drive
  6922 0000E984 7245                <1> 	jc	short sysfnf_err_1 ; read error ! 
  6923                              <1> 				   ; (do not stop, because
  6924                              <1> 				   ; we don't have a
  6925                              <1> 				   ; 'no more files'
  6926                              <1> 				   ; -file not found- error,	
  6927                              <1> 				   ; next sysfnf system call
  6928                              <1> 				   ; may solve the problem,
  6929                              <1> 				   ; after re-placing the disk)				
  6930                              <1> sysfnf_3:
  6931 0000E986 A1[7C620100]        <1> 	mov	eax, [FindFile_DirCluster]
  6932 0000E98B 21C0                <1> 	and	eax, eax
  6933 0000E98D 7550                <1> 	jnz	short sysfnf_6
  6934                              <1>         
  6935 0000E98F 803D[6D590100]02    <1> 	cmp	byte [Current_FATType], 2
  6936 0000E996 772C                <1> 	ja	short sysfnf_err_0 ; invalid, we neeed to stop !?
  6937 0000E998 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
  6938 0000E99F 7223                <1> 	jb	short sysfnf_err_0 ; invalid, we neeed to stop !?
  6939                              <1> 
  6940 0000E9A1 3805[8C600100]      <1> 	cmp	byte [DirBuff_ValidData], al ; 0
  6941 0000E9A7 7608                <1> 	jna	short sysfnf_4 
  6942                              <1> 
  6943 0000E9A9 3B05[91600100]      <1> 	cmp	eax, [DirBuff_Cluster] ; 0 ?
  6944 0000E9AF 745E                <1> 	je	short sysfnf_9
  6945                              <1> 
  6946                              <1> 	;cmp	byte [Current_Dir_Level], 0
  6947                              <1>         ;ja	short sysfnf_4  
  6948                              <1>         ;jna	short sysfnf_9 
  6949                              <1> 
  6950                              <1> sysfnf_4:
  6951 0000E9B1 FE05[5B650100]      <1> 	inc	byte [SWP_DRV_chg]
  6952 0000E9B7 E842D3FFFF          <1> 	call 	load_FAT_root_directory
  6953 0000E9BC 7351                <1> 	jnc	short sysfnf_9
  6954                              <1> 	; eax = error code (17, 'drv not ready or read error')
  6955 0000E9BE EB0B                <1> 	jmp	short sysfnf_err_1 ; read error ! (no FNF stop)
  6956                              <1> 				   ; (if you want, try again, 
  6957                              <1> 				   ;  after re-placing the disk)
  6958                              <1> sysfnf_5:	
  6959 0000E9C0 3C0C                <1> 	cmp	al, 12 ; 'no more files' error
  6960 0000E9C2 7507                <1> 	jne	short sysfnf_err_1 ; (no FNF stop -sysfnf will try
  6961                              <1> 				   ;  to read the directory again,
  6962                              <1> 				   ;  if the user calls sysfnf
  6963                              <1> 				   ;  just after this error return-)
  6964                              <1> 	; (FNF stop -sysfnf will not try
  6965                              <1> 	;  to read the directory again-)	
  6966                              <1> 
  6967                              <1> sysfnf_err_0:
  6968 0000E9C4 C605[54650100]00    <1> 	mov	byte [FFF_Valid], 0 ; FNF stop sign
  6969                              <1> sysfnf_err_1:
  6970 0000E9CB A3[64030300]        <1> 	mov	[u.r0], eax
  6971 0000E9D0 A3[C8030300]        <1> 	mov	[u.error], eax
  6972 0000E9D5 E851130000          <1> 	call	reset_working_path
  6973 0000E9DA E93ADDFFFF          <1> 	jmp	error
  6974                              <1> 	  
  6975                              <1> sysfnf_6:
  6976 0000E9DF 803D[8C600100]00    <1> 	cmp	byte [DirBuff_ValidData], 0
  6977 0000E9E6 7608                <1> 	jna	short sysfnf_7
  6978                              <1> 
  6979 0000E9E8 3B05[91600100]      <1> 	cmp	eax, [DirBuff_Cluster]
  6980 0000E9EE 741F                <1> 	je	short sysfnf_9
  6981                              <1> 
  6982                              <1> sysfnf_7:
  6983 0000E9F0 FE05[5B650100]      <1> 	inc	byte [SWP_DRV_chg]
  6984 0000E9F6 803D[6D590100]01    <1> 	cmp	byte [Current_FATType], 1
  6985 0000E9FD 7309                <1> 	jnb	short sysfnf_8
  6986                              <1> 
  6987                              <1> 	; Singlix (TRFS) File System 
  6988                              <1> 	; (access via compatibility buffer)
  6989 0000E9FF E8C2D3FFFF          <1> 	call	load_FS_sub_directory
  6990 0000EA04 7309                <1> 	jnc	short sysfnf_9
  6991                              <1> 
  6992 0000EA06 EBC3                <1> 	jmp	short sysfnf_err_1 ; read error (no FNF stop)
  6993                              <1> 
  6994                              <1> sysfnf_8:
  6995 0000EA08 E87CD3FFFF          <1> 	call	load_FAT_sub_directory	 
  6996 0000EA0D 72BC                <1> 	jc	short sysfnf_err_1 ; read error (no FNF stop)
  6997                              <1> 
  6998                              <1> sysfnf_9:
  6999 0000EA0F E85999FFFF          <1> 	call	find_next_file
  7000 0000EA14 72AA                <1> 	jc	short sysfnf_5
  7001                              <1> 
  7002 0000EA16 A0[55650100]        <1> 	mov	al, [FFF_Attrib]
  7003                              <1> 	;or	al, al
  7004                              <1> 	;jz	short sysfnf_10 ; 0 = No filter
  7005 0000EA1B 34FF                <1> 	xor	al, 0FFh
  7006 0000EA1D 20D8                <1> 	and	al, bl
  7007 0000EA1F 75EE                <1> 	jnz	short sysfnf_9 ; search for next file until
  7008                              <1> 			       ; an error return from
  7009                              <1> 			       ; find_next_file procedure	
  7010                              <1> sysfnf_10:
  7011 0000EA21 0FB60D[54650100]    <1>         movzx	ecx, byte [FFF_Valid]
  7012 0000EA28 80F980              <1> 	cmp	cl, 128 ; complete FindFile structure/table 
  7013 0000EA2B 0F84A2FEFFFF        <1> 	je	sysfnf_11
  7014                              <1> 	;cmp	cl, 24  ; basic parameters
  7015                              <1> 	;je	sysfnf_12       
  7016 0000EA31 E9AFFEFFFF          <1> 	jmp	sysfnf_12
  7017                              <1> 
  7018                              <1> writei:
  7019                              <1> 	; 26/10/2016
  7020                              <1> 	; 25/10/2016
  7021                              <1> 	; 23/10/2016
  7022                              <1> 	; 22/10/2016
  7023                              <1> 	; 19/10/2016 - TRDOS 386 (TRDOS v2.0)
  7024                              <1> 	; 19/05/2015 - 20/05/2015 (Retro UNIX 386 v1)
  7025                              <1> 	; 12/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  7026                              <1> 	;
  7027                              <1> 	; Write data to file with first cluster number in EAX
  7028                              <1> 	; 
  7029                              <1> 	; INPUTS ->
  7030                              <1> 	;    EAX - First cluster number of the file
  7031                              <1> 	;    EBX - File number (Open file index number)
  7032                              <1> 	;    u.count - byte count to be written
  7033                              <1> 	;    u.base - points to user buffer
  7034                              <1> 	;    u.fofp - points to dword with current file offset
  7035                              <1> 	;    i.size - file size
  7036                              <1> 	;    cdev - logical dos drive number of the file
  7037                              <1> 	; OUTPUTS ->
  7038                              <1> 	;    u.count - cleared
  7039                              <1> 	;    u.nread - accumulates total bytes passed back
  7040                              <1> 	;    i.size - new file size (if file byte offset overs file size)
  7041                              <1> 	;    u.fofp - points to u.off (with new offset value)	
  7042                              <1> 	;
  7043                              <1> 	; (Retro UNIX Prototype : 11/11/2012 - 18/11/2012, UNIXCOPY.ASM)
  7044                              <1> 	; ((Modified registers: eax, edx, ebx, ecx, esi, edi, ebp)) 	
  7045                              <1> 
  7046 0000EA36 31C9                <1> 	xor	ecx, ecx
  7047 0000EA38 890D[8C030300]      <1> 	mov 	[u.nread], ecx  ; 0
  7048 0000EA3E 66890D[C4030300]    <1> 	mov	[u.pcount], cx ; 19/05/2015
  7049 0000EA45 390D[88030300]      <1> 	cmp 	[u.count], ecx
  7050 0000EA4B 7701                <1> 	ja 	short writei_1 
  7051 0000EA4D C3                  <1> 	retn
  7052                              <1> writei_1:
  7053 0000EA4E 881D[14650100]      <1> 	mov	[writei.ofn], bl ; Open file number
  7054 0000EA54 880D[4F650100]      <1> 	mov	[setfmod], cl ; 0 ; reset 'update lm date&time' sign
  7055                              <1> dskw_0: 
  7056                              <1> 	; 26/10/2016
  7057                              <1> 	; 22/10/2016, 23/10/2016, 25/10/2016
  7058                              <1> 	; 19/10/2016 - TRDOS 386 (TRDOS v2.0)
  7059                              <1> 	; 31/05/2015 - 25/07/2015 (Retro UNIX 386 v1)
  7060                              <1> 	; 26/04/2013 - 20/09/2013 (Retro UNIX 8086 v1)
  7061                              <1> 	;
  7062                              <1> 	; 01/08/2013 (mkdir_w check)
  7063 0000EA5A E8D7000000          <1>  	call	mget_w
  7064                              <1> 	; eax = sector/block number
  7065                              <1> 
  7066 0000EA5F 8B1D[74030300]      <1> 	mov     ebx, [u.fofp]
  7067 0000EA65 8B13                <1> 	mov	edx, [ebx]
  7068 0000EA67 81E2FF010000        <1> 	and	edx, 1FFh  ; / test the lower 9 bits of the file offset
  7069 0000EA6D 750C                <1> 	jnz	short dskw_1 ; / if its non-zero, branch
  7070                              <1> 			     ; if zero, file offset = 0,
  7071                              <1> 		       	     ; / 512, 1024,...(i.e., start of new block)
  7072 0000EA6F 813D[88030300]0002- <1> 	cmp	dword [u.count], 512
  7072 0000EA77 0000                <1>
  7073                              <1> 				; / if zero, is there enough data to fill
  7074                              <1> 				; / an entire block? (i.e., no. of
  7075 0000EA79 7337                <1> 	jnb	short dskw_2 ; / bytes to be written greater than 512.? 
  7076                              <1> 			     ; / Yes, branch. Don't have to read block
  7077                              <1> dskw_1: ; in as no past info. is to be saved 
  7078                              <1> 	; (the entire block will be overwritten).
  7079                              <1> 	; 23/10/2016
  7080                              <1> 
  7081 0000EA7B BB[94070300]        <1> 	mov	ebx, writei_buffer
  7082                              <1> 	; esi = logical dos drive description table address
  7083                              <1> 	; eax = sector number
  7084                              <1> 	; ebx = buffer address (in kernel's memory space)
  7085                              <1> 	; ecx = sector count
  7086 0000EA80 B901000000          <1> 	mov	ecx, 1
  7087 0000EA85 E8A90D0000          <1> 	call	disk_read
  7088                              <1> 	;call	dskrd 	; / no, must retain old info.. 
  7089                              <1> 		       	; / Hence, read block 'r1' into an I/O buffer
  7090 0000EA8A 7326                <1> 	jnc	short dskw_2
  7091                              <1> 
  7092                              <1> 	; disk read error
  7093 0000EA8C B811000000          <1> 	mov	eax, 17 ; drive not ready or READ ERROR !
  7094                              <1> dskw_err: ; jump from disk write error
  7095 0000EA91 A3[64030300]        <1> 	mov	[u.r0], eax
  7096 0000EA96 A3[C8030300]        <1> 	mov	[u.error], eax
  7097                              <1> 
  7098 0000EA9B 803D[4F650100]00    <1> 	cmp	byte [setfmod], 0
  7099 0000EAA2 0F8671DCFFFF        <1> 	jna	error
  7100                              <1> 
  7101 0000EAA8 E8AF030000          <1> 	call	update_file_lmdt ; update last modif. date&time of the file
  7102                              <1> 	;mov	byte [setfmod], 0	
  7103                              <1> 
  7104 0000EAAD E967DCFFFF          <1> 	jmp	error
  7105                              <1> 
  7106                              <1> dskw_2: ; 3:
  7107                              <1> 	; 23/10/2016
  7108 0000EAB2 C605[F0640100]01    <1> 	mov	byte [writei.valid], 1 ; writei buffer contains valid data
  7109 0000EAB9 56                  <1> 	push	esi ; logical dos drive description table address
  7110                              <1> 	; EAX (r1) = block/sector number
  7111                              <1> 	;call	wslot
  7112                              <1> 		; jsr r0,wslot / set write and inhibit bits in I/O queue, 
  7113                              <1> 			   ; / proc. status=0, r5 points to 1st word of data
  7114 0000EABA 803D[C6030300]00    <1> 	cmp	byte [u.kcall], 0
  7115 0000EAC1 770F                <1> 	ja	short dskw_4 ; zf=0 -> the caller is 'mkdir'
  7116                              <1> 	;
  7117 0000EAC3 66833D[C4030300]00  <1> 	cmp	word [u.pcount], 0
  7118 0000EACB 7705                <1> 	ja	short dskw_4
  7119                              <1> dskw_3:
  7120                              <1> 	; [u.base] = virtual address to transfer (as source address)
  7121 0000EACD E821FAFFFF          <1> 	call	trans_addr_r ; translate virtual address to physical (r)
  7122                              <1> dskw_4:
  7123 0000EAD2 BB[94070300]        <1> 	mov	ebx, writei_buffer
  7124                              <1> 	; EBX (r5) = system (I/O) buffer address
  7125 0000EAD7 E883FAFFFF          <1> 	call	sioreg
  7126                              <1> 	; ESI = file (user data) offset
  7127                              <1> 	; EDI = sector (I/O) buffer offset
  7128                              <1> 	; ECX = byte count
  7129                              <1> 	;
  7130 0000EADC F3A4                <1>   	rep	movsb
  7131                              <1> 	; 25/07/2015
  7132                              <1> 	; eax = remain bytes in buffer
  7133                              <1>         ;       (check if remain bytes in the buffer > [u.pcount])
  7134 0000EADE 09C0                <1> 	or	eax, eax
  7135 0000EAE0 75EB                <1> 	jnz	short dskw_3 ; (page end before system buffer end!)	
  7136                              <1> 
  7137                              <1> 	; 23/10/2016
  7138 0000EAE2 B101                <1> 	mov	cl, 1
  7139 0000EAE4 5E                  <1> 	pop	esi
  7140 0000EAE5 A1[F4640100]        <1> 	mov	eax, [writei.sector]
  7141                              <1> 	; esi = logical dos drive description table address
  7142                              <1> 	; eax = sector number
  7143                              <1> 	; ebx = writei buffer address
  7144                              <1> 	; ecx = sector count
  7145 0000EAEA E8350D0000          <1> 	call	disk_write ; / yes, write the block
  7146 0000EAEF 7307                <1> 	jnc	short dskw_5
  7147                              <1> 
  7148 0000EAF1 B812000000          <1> 	mov	eax, 18 ; drive not ready or WRITE ERROR !
  7149 0000EAF6 EB99                <1> 	jmp	short dskw_err
  7150                              <1> 
  7151                              <1> dskw_5:
  7152                              <1> 	; 26/10/2016
  7153 0000EAF8 0FB61D[14650100]    <1> 	movzx	ebx, byte [writei.ofn] ; open file number
  7154 0000EAFF C0E302              <1> 	shl	bl, 2 ; *4
  7155 0000EB02 8B83[E4680100]      <1> 	mov	eax, [ebx+OF_POINTER]
  7156 0000EB08 3B83[0C690100]      <1> 	cmp	eax, [ebx+OF_SIZE]
  7157 0000EB0E 7606                <1> 	jna	short dskw_6
  7158 0000EB10 8983[0C690100]      <1> 	mov	[ebx+OF_SIZE], eax
  7159                              <1> dskw_6:
  7160                              <1> 	;shr	bl, 2
  7161 0000EB16 833D[88030300]00    <1>         cmp     dword [u.count], 0 ; / any more data to write?
  7162 0000EB1D 760A                <1> 	jna	short dskw_7
  7163 0000EB1F A1[04650100]        <1> 	mov	eax, [writei.fclust]
  7164 0000EB24 E931FFFFFF          <1> 	jmp	dskw_0 ; / yes, branch
  7165                              <1> dskw_7:
  7166                              <1>  	; update last modif. date&time of the file
  7167                              <1> 	; (also updates file size as OF_SIZE)
  7168 0000EB29 E82E030000          <1> 	call	update_file_lmdt
  7169                              <1> 	;mov	byte [setfmod], 0	
  7170                              <1> 
  7171                              <1> 	; 03/08/2013
  7172 0000EB2E C605[C6030300]00    <1> 	mov	byte [u.kcall], 0
  7173                              <1> 	; 23/10/2016
  7174                              <1> 	;mov	eax, [writei.fclust]
  7175 0000EB35 C3                  <1> 	retn
  7176                              <1> 
  7177                              <1> mget_w:
  7178                              <1> 	; 02/11/2016
  7179                              <1> 	; 01/11/2016
  7180                              <1> 	; 23/10/2016, 31/10/2016
  7181                              <1> 	; 22/10/2016 - TRDOS 386 (TRDOS v2.0)
  7182                              <1> 	; 03/06/2015 (Retro UNIX 386 v1, 'mget', u.5s)
  7183                              <1> 	; 22/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
  7184                              <1> 	;
  7185                              <1> 	; Get existing or (allocate) a new disk block for file
  7186                              <1> 	; 
  7187                              <1> 	; INPUTS ->
  7188                              <1> 	;    [u.fofp] = file offset pointer
  7189                              <1> 	;    [i.size] = file size
  7190                              <1> 	;    [u.count] = byte count	 
  7191                              <1> 	;    EAX = First cluster
  7192                              <1> 	;    [cdev] = Logical dos drive number 	  
  7193                              <1> 	;    [writei.ofn] = File Number
  7194                              <1> 	;		   (Open file index, 0 based)
  7195                              <1> 	;    ([u.off] = file offset)
  7196                              <1> 	; OUTPUTS ->
  7197                              <1> 	;    EAX = logical sector number
  7198                              <1> 	;    ESI = Logical Dos Drive Description Table address
  7199                              <1> 	;
  7200                              <1> 	; Modified registers: EDX, EBX, ECX, ESI, EDI, EBP  
  7201                              <1> 
  7202 0000EB36 8B35[74030300]      <1>         mov     esi, [u.fofp]
  7203 0000EB3C 8B2E                <1> 	mov	ebp, [esi] ; u.off (or EBX*4+OF_POINTER)
  7204                              <1> 
  7205 0000EB3E 29C9                <1> 	sub	ecx, ecx
  7206 0000EB40 8A2D[46030300]      <1> 	mov	ch, [cdev]
  7207                              <1> 
  7208 0000EB46 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  7209 0000EB4B 01CE                <1> 	add	esi, ecx
  7210                              <1> 
  7211                              <1> 	; 31/10/2016
  7212 0000EB4D 89C3                <1> 	mov	ebx, eax ; First Cluster or FDT address
  7213                              <1> 
  7214 0000EB4F 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  7215 0000EB53 0F86DD010000        <1> 	jna	mget_w_14 ; Singlix FS
  7216                              <1> 
  7217 0000EB59 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
  7218 0000EB5D 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
  7219 0000EB61 8815[F2640100]      <1> 	mov	[writei.spc], dl  ; sectors per cluster
  7220 0000EB67 F7E2                <1> 	mul	edx
  7221                              <1> 	; edx = 0
  7222                              <1> 	; eax = bytes per cluster (<= 65536)
  7223                              <1> 
  7224                              <1> 	; 02/11/2016
  7225 0000EB69 89C1                <1> 	mov	ecx, eax
  7226 0000EB6B 48                  <1> 	dec	eax
  7227 0000EB6C 66A3[F8640100]      <1> 	mov	[writei.bpc], ax	
  7228                              <1> 	
  7229 0000EB72 89E8                <1> 	mov	eax, ebp
  7230 0000EB74 0305[88030300]      <1> 	add	eax, [u.count] ; next file position
  7231 0000EB7A 3B05[55040300]      <1> 	cmp	eax, [i.size] ; <= file size ?
  7232 0000EB80 0F86FC000000        <1> 	jna	mget_w_4 ; no
  7233                              <1> 
  7234 0000EB86 F7F1                <1> 	div	ecx
  7235 0000EB88 A3[00650100]        <1> 	mov	[writei.c_index], eax ; cluster index
  7236                              <1> 	; edx = byte offset in cluster (<= 65535)
  7237                              <1> 	;mov	[writei.offset], dx
  7238                              <1> 	;shr	dx, 9 ; / 512
  7239                              <1> 	;mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
  7240                              <1> 
  7241 0000EB8D 29D2                <1> 	sub	edx, edx ; 01/11/2016
  7242 0000EB8F 8915[F4640100]      <1> 	mov 	[writei.sector], edx ; 0
  7243 0000EB95 668915[FA640100]    <1> 	mov	[writei.offset], dx  ; byte offset in cluster 
  7244 0000EB9C 8815[F3640100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
  7245                              <1> 
  7246 0000EBA2 89D8                <1> 	mov	eax, ebx ; First Cluster
  7247                              <1> 
  7248                              <1> 	; is this the 1st mget_w or a next mget_w call ? (by 'writei')
  7249 0000EBA4 3815[F0640100]      <1> 	cmp	byte [writei.valid], dl ; 0 
  7250 0000EBAA 7624                <1> 	jna	short mget_w_0
  7251                              <1> 
  7252 0000EBAC 8815[F0640100]      <1> 	mov 	byte [writei.valid], dl ; 0 ; reset ('writei' will set it) 
  7253                              <1> 
  7254 0000EBB2 3B05[04650100]      <1> 	cmp	eax, [writei.fclust]
  7255 0000EBB8 7516                <1> 	jne	short mget_w_0
  7256                              <1> 
  7257 0000EBBA 8A0D[46030300]      <1> 	mov	cl, [cdev]
  7258 0000EBC0 3A0D[F1640100]      <1> 	cmp	cl, [writei.drv]
  7259 0000EBC6 7508                <1> 	jne	short mget_w_0
  7260                              <1>  	; [writei.l_clust] & [writei.l_index] are valid, 
  7261                              <1> 	;  we don't need to get last cluster & last cluster index
  7262 0000EBC8 8B0D[10650100]      <1> 	mov	ecx, [writei.l_index]
  7263 0000EBCE EB64                <1> 	jmp	short mget_w_2
  7264                              <1> mget_w_0:
  7265 0000EBD0 A3[04650100]        <1> 	mov	[writei.fclust], eax ; first cluster
  7266                              <1> 	; edx = 0
  7267 0000EBD5 A3[FC640100]        <1> 	mov	[writei.cluster], eax ; first cluster ; 01/11/2016
  7268 0000EBDA 8915[08650100]      <1> 	mov 	[writei.fs_index], edx ; 0 ; curret cluster index
  7269                              <1> 
  7270                              <1> 	; FAT file system (FAT12, FAT16, FAT32)
  7271 0000EBE0 E8B9D7FFFF          <1> 	call	get_last_cluster
  7272 0000EBE5 0F822B010000        <1> 	jc	mget_w_err ; eax = error code
  7273                              <1> 		
  7274 0000EBEB A3[0C650100]        <1> 	mov	[writei.lclust], eax ; last cluster
  7275                              <1> 
  7276 0000EBF0 8B0D[30630100]      <1> 	mov	ecx, [glc_index] ; last cluster index
  7277 0000EBF6 890D[10650100]      <1> 	mov	[writei.l_index], ecx
  7278                              <1> 
  7279 0000EBFC A0[14650100]        <1> 	mov	al, [writei.ofn]
  7280 0000EC01 FEC0                <1> 	inc	al
  7281 0000EC03 A2[4F650100]        <1> 	mov	[setfmod], al ; update lm date&time sign
  7282                              <1> 
  7283                              <1> mget_w_1:
  7284 0000EC08 3B0D[00650100]      <1> 	cmp	ecx, [writei.c_index]  ; last cluster index
  7285 0000EC0E 7324                <1> 	jnb	short mget_w_2 ; 01/11/2016
  7286                              <1> 
  7287 0000EC10 A1[0C650100]        <1> 	mov	eax, [writei.lclust]
  7288                              <1> 	; EAX = Last cluster
  7289 0000EC15 E892D8FFFF          <1> 	call	add_new_cluster
  7290 0000EC1A 0F82F6000000        <1> 	jc	mget_w_err ; eax = error code
  7291                              <1> 	; edx = 0
  7292 0000EC20 A3[0C650100]        <1> 	mov	[writei.lclust], eax ; (new) last cluster
  7293 0000EC25 8B0D[10650100]      <1> 	mov	ecx, [writei.l_index]
  7294 0000EC2B 41                  <1> 	inc	ecx ; add 1 to last cluster index
  7295 0000EC2C 890D[10650100]      <1> 	mov	[writei.l_index], ecx ; current last cluster index
  7296                              <1> 
  7297 0000EC32 EBD4                <1> 	jmp	short mget_w_1
  7298                              <1> 
  7299                              <1> mget_w_2:
  7300 0000EC34 89E9                <1> 	mov	ecx, ebp
  7301 0000EC36 030D[88030300]      <1> 	add	ecx, [u.count]
  7302 0000EC3C 890D[55040300]      <1> 	mov	[i.size], ecx ; save new file size
  7303                              <1> 	;sub	edx, edx ; 0
  7304                              <1> 
  7305 0000EC42 A0[46030300]        <1> 	mov	al, [cdev]
  7306 0000EC47 A2[F1640100]        <1> 	mov	[writei.drv], al ; physical drive number
  7307                              <1> 	; edx = 0
  7308 0000EC4C 89E8                <1> 	mov	eax, ebp ; file offset
  7309 0000EC4E 0FB70D[F8640100]    <1> 	movzx	ecx, word [writei.bpc] ; bytes per cluster - 1
  7310 0000EC55 41                  <1> 	inc	ecx ; bytes per cluster
  7311 0000EC56 F7F1                <1> 	div	ecx
  7312                              <1> 	; edx = byte offset in cluster (<= 65535)
  7313                              <1> 	; eax = cluster index
  7314 0000EC58 A3[00650100]        <1> 	mov	[writei.c_index], eax
  7315 0000EC5D 668915[FA640100]    <1> 	mov	[writei.offset], dx
  7316 0000EC64 66C1EA09            <1> 	shr	dx, 9 ; / 512
  7317 0000EC68 8815[F3640100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
  7318                              <1> 
  7319                              <1> mget_w_3:
  7320 0000EC6E 3B05[10650100]      <1> 	cmp	eax, [writei.l_index] ; last cluster index
  7321 0000EC74 752A                <1> 	jne	short mget_w_5
  7322                              <1> 
  7323 0000EC76 A3[08650100]        <1> 	mov	[writei.fs_index], eax ; cluster index (for next check)
  7324 0000EC7B A1[0C650100]        <1> 	mov	eax, [writei.lclust] ; last cluster
  7325 0000EC80 EB60                <1> 	jmp	short mget_w_10
  7326                              <1> 
  7327                              <1> mget_w_4: ; 02/11/2016
  7328                              <1> 	; eax = next file position
  7329 0000EC82 2B05[88030300]      <1> 	sub	eax, [u.count] ; current file position
  7330                              <1> 	; edx = 0
  7331                              <1> 	; ecx = bytes per cluster
  7332 0000EC88 F7F1                <1> 	div	ecx
  7333 0000EC8A A3[00650100]        <1> 	mov	[writei.c_index], eax ; cluster index
  7334 0000EC8F 668915[FA640100]    <1> 	mov	[writei.offset], dx
  7335 0000EC96 66C1EA09            <1> 	shr	dx, 9 ; / 512
  7336 0000EC9A 8815[F3640100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
  7337                              <1> 
  7338                              <1> mget_w_5:
  7339 0000ECA0 21C0                <1> 	and	eax, eax ; 0 = First Cluster's index number
  7340 0000ECA2 750C                <1> 	jnz	short mget_w_6
  7341                              <1> 
  7342 0000ECA4 A3[08650100]        <1> 	mov	[writei.fs_index], eax ; cluster index (for next check)
  7343 0000ECA9 A1[04650100]        <1> 	mov	eax, [writei.fclust] ; first cluster
  7344 0000ECAE EB32                <1> 	jmp	short mget_w_10
  7345                              <1> 
  7346                              <1> mget_w_6:
  7347 0000ECB0 3B05[08650100]      <1> 	cmp	eax, [writei.fs_index] ; current cluster index (>0)
  7348 0000ECB6 7507                <1> 	jne	short mget_w_7
  7349 0000ECB8 A1[FC640100]        <1> 	mov	eax, [writei.cluster] ; current cluster 
  7350 0000ECBD EB3A                <1> 	jmp	short mget_w_11
  7351                              <1> 
  7352                              <1> mget_w_7:
  7353 0000ECBF 89C1                <1> 	mov	ecx, eax
  7354 0000ECC1 2B0D[08650100]      <1> 	sub	ecx, [writei.fs_index]
  7355 0000ECC7 730D                <1> 	jnc	short mget_w_8
  7356                              <1> 	; get cluster by index from the first cluster
  7357 0000ECC9 A1[04650100]        <1> 	mov	eax, [writei.fclust]
  7358 0000ECCE 8B0D[00650100]      <1> 	mov	ecx, [writei.c_index]
  7359 0000ECD4 EB05                <1> 	jmp	short mget_w_9
  7360                              <1> 
  7361                              <1> mget_w_8:
  7362 0000ECD6 A1[FC640100]        <1> 	mov	eax, [writei.cluster] ; beginning cluster
  7363                              <1> 	; ecx = cluster sequence number after the beginning cluster
  7364                              <1> 	; sub	edx, edx ; 0
  7365                              <1> 
  7366                              <1> mget_w_9:
  7367                              <1> 	; EAX = Beginning cluster
  7368                              <1> 	; EDX = Sector index in disk/file section
  7369                              <1> 	;	(Only for SINGLIX file system!)
  7370                              <1> 	; ECX = Cluster sequence number after the beginning cluster
  7371                              <1> 	; ESI = Logical DOS Drive Description Table address
  7372 0000ECDB E8D2D8FFFF          <1> 	call	get_cluster_by_index
  7373 0000ECE0 7234                <1> 	jc	short mget_w_err ; error code in EAX
  7374                              <1> 	; EAX = Cluster number		
  7375                              <1> mget_w_10:
  7376 0000ECE2 A3[FC640100]        <1> 	mov	[writei.cluster], eax ; FDT number for Singlix File System
  7377                              <1> 
  7378 0000ECE7 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  7379 0000ECEB 7638                <1> 	jna	short mget_w_13
  7380                              <1> 	; 01/11/2016
  7381 0000ECED 8B15[00650100]      <1> 	mov	edx, [writei.c_index]
  7382 0000ECF3 8915[08650100]      <1> 	mov	[writei.fs_index], edx
  7383                              <1> mget_w_11:
  7384 0000ECF9 83E802              <1> 	sub	eax, 2
  7385 0000ECFC 0FB615[F2640100]    <1> 	movzx	edx, byte [writei.spc]
  7386 0000ED03 F7E2                <1> 	mul	edx
  7387                              <1> 
  7388 0000ED05 034668              <1> 	add	eax, [esi+LD_DATABegin]
  7389 0000ED08 8A15[F3640100]      <1> 	mov	dl, [writei.s_index]
  7390 0000ED0E 01D0                <1> 	add	eax, edx
  7391                              <1> mget_w_12:
  7392 0000ED10 A3[F4640100]        <1> 	mov	[writei.sector], eax
  7393                              <1> 	;; buffer validation must be done in writei
  7394                              <1> 	;;mov	byte [writei.valid], 1 
  7395 0000ED15 C3                  <1> 	retn
  7396                              <1> 
  7397                              <1> mget_w_err:
  7398 0000ED16 A3[C8030300]        <1> 	mov	[u.error], eax
  7399 0000ED1B A3[64030300]        <1> 	mov	[u.r0], eax
  7400 0000ED20 E9F4D9FFFF          <1> 	jmp	error
  7401                              <1> 
  7402                              <1> mget_w_13:
  7403                              <1> 	; EAX = FDT number (Current Section)
  7404                              <1> 	; EDX = Sector index from the first section (0,1,2,3,4...)
  7405 0000ED25 2B15[08650100]      <1> 	sub	edx, [writei.fs_index]	
  7406                              <1> 	; EDX = Sector index from current section
  7407 0000ED2B 8915[08650100]      <1> 	mov	[writei.fs_index], edx
  7408 0000ED31 40                  <1> 	inc	eax ; the first data sector in FS disk section	
  7409 0000ED32 01D0                <1> 	add	eax, edx
  7410 0000ED34 EBDA                <1> 	jmp	short mget_w_12
  7411                              <1> 
  7412                              <1> mget_w_14:
  7413 0000ED36 8A4E12              <1> 	mov	cl, [esi+LD_FS_BytesPerSec+1]
  7414 0000ED39 D0E9                <1> 	shr	cl, 1 ;  ; 1 for 512 bytes, 4 for 2048 bytes
  7415 0000ED3B 880D[F2640100]      <1> 	mov	[writei.spc], cl  ; sectors per cluster
  7416                              <1> 	; NOTE: writei bytes per sector value is always 512 ! 
  7417 0000ED41 66C705[F8640100]00- <1> 	mov	word [writei.bpc], 512
  7417 0000ED49 02                  <1>
  7418                              <1> 
  7419 0000ED4A 89E9                <1> 	mov	ecx, ebp
  7420 0000ED4C 030D[88030300]      <1> 	add	ecx, [u.count] ; next file position
  7421 0000ED52 3B0D[55040300]      <1> 	cmp	ecx, [i.size] ; <= file size ?
  7422 0000ED58 0F86C8000000        <1> 	jna	mget_w_19 ; no
  7423                              <1> 
  7424 0000ED5E 29D2                <1> 	sub	edx, edx ; 0
  7425 0000ED60 8915[F4640100]      <1> 	mov 	[writei.sector], edx ; 0
  7426 0000ED66 668915[FA640100]    <1> 	mov	[writei.offset], dx  ; byte offset in cluster 
  7427 0000ED6D 8815[F3640100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
  7428                              <1> 
  7429 0000ED73 C1E909              <1> 	shr	ecx, 9 ; 1 cluster = 512 bytes
  7430 0000ED76 890D[00650100]      <1> 	mov	[writei.c_index], ecx ; section/cluster index
  7431                              <1> 	
  7432 0000ED7C 89D8                <1> 	mov	eax, ebx ; FDT number (First FDT address)
  7433                              <1> 
  7434                              <1> 	; is this the 1st mget_w or a next mget_w call ? (by 'writei')
  7435 0000ED7E 3815[F0640100]      <1> 	cmp	byte [writei.valid], dl ; 0 
  7436 0000ED84 7624                <1> 	jna	short mget_w_15
  7437                              <1> 
  7438 0000ED86 8815[F0640100]      <1> 	mov 	byte [writei.valid], dl ; 0 ; reset ('writei' will set it) 
  7439                              <1> 
  7440 0000ED8C 3B05[04650100]      <1> 	cmp	eax, [writei.fclust]
  7441 0000ED92 7516                <1> 	jne	short mget_w_15
  7442                              <1> 
  7443 0000ED94 8A0D[46030300]      <1> 	mov	cl, [cdev]
  7444 0000ED9A 3A0D[F1640100]      <1> 	cmp	cl, [writei.drv]
  7445 0000EDA0 7508                <1> 	jne	short mget_w_15
  7446                              <1>  	; [writei.l_clust] & [writei.l_index] are valid, 
  7447                              <1> 	;  we don't need to get last cluster & last cluster index
  7448 0000EDA2 8B0D[10650100]      <1> 	mov	ecx, [writei.l_index]
  7449 0000EDA8 EB49                <1> 	jmp	short mget_w_17
  7450                              <1> mget_w_15:
  7451 0000EDAA A3[04650100]        <1> 	mov	[writei.fclust], eax ; first section (FDT number)
  7452                              <1> 	; edx = 0
  7453 0000EDAF 8915[FC640100]      <1> 	mov	[writei.cluster], edx ; 0 ; current section
  7454 0000EDB5 8915[08650100]      <1> 	mov 	[writei.fs_index], edx ; 0 ; curret section index
  7455                              <1> 
  7456                              <1> 	; eax = FDT number (section 0 header address)
  7457 0000EDBB E81CD8FFFF          <1> 	call	get_last_section
  7458 0000EDC0 0F8250FFFFFF        <1> 	jc	mget_w_err ; eax = error code
  7459                              <1> 
  7460 0000EDC6 8915[08650100]      <1> 	mov 	[writei.fs_index], edx ; sector index in last section
  7461                              <1> 		
  7462 0000EDCC A3[0C650100]        <1> 	mov	[writei.lclust], eax ; last section address
  7463                              <1> 
  7464 0000EDD1 8B0D[30630100]      <1> 	mov	ecx, [glc_index] ; last section index
  7465 0000EDD7 890D[10650100]      <1> 	mov	[writei.l_index], ecx
  7466                              <1> 
  7467 0000EDDD A0[14650100]        <1> 	mov	al, [writei.ofn]
  7468 0000EDE2 FEC0                <1> 	inc	al
  7469 0000EDE4 A2[4F650100]        <1> 	mov	[setfmod], al ; update lm date&time sign
  7470                              <1> 
  7471                              <1> mget_w_16:
  7472                              <1> 	; edx = (existing) last section (sector) index
  7473 0000EDE9 8B0D[00650100]      <1> 	mov	ecx, [writei.c_index] ; final section (sector) index
  7474 0000EDEF 29D1                <1> 	sub	ecx, edx
  7475 0000EDF1 7633                <1> 	jna	short mget_w_19
  7476                              <1> 	 ; ecx = sector count
  7477                              <1> mget_w_17:
  7478 0000EDF3 A1[0C650100]        <1> 	mov	eax, [writei.lclust]
  7479                              <1> 	; ESI = Logical dos drv desc. table address
  7480                              <1>         ; EAX = Last section
  7481                              <1>         ; (ECX = 0 for directory) 
  7482                              <1>         ; ECX = sector count (except FDT)
  7483 0000EDF8 E8A2CDFFFF          <1> 	call	add_new_fs_section
  7484 0000EDFD 7312                <1> 	jnc	short mget_w_18
  7485                              <1> 
  7486                              <1> 	; If error number = 27h (insufficient disk space)
  7487                              <1> 	; it is needed to check free consequent sectors
  7488                              <1> 	; (1 data sector at least and +1 section header sector) 
  7489                              <1> 
  7490 0000EDFF 83F827              <1> 	cmp	eax, 27h
  7491 0000EE02 0F850EFFFFFF        <1> 	jne	mget_w_err ; eax = error code
  7492                              <1> 
  7493                              <1> 	; ecx = count of free consequent sectors
  7494                              <1> 	; ecx must be > 1 (1 data + 1 header sector)
  7495 0000EE08 49                  <1> 	dec	ecx
  7496 0000EE09 0F8407FFFFFF        <1> 	jz	mget_w_err
  7497 0000EE0F EBE2                <1> 	jmp	short mget_w_17
  7498                              <1> 
  7499                              <1> mget_w_18:
  7500 0000EE11 A3[0C650100]        <1> 	mov	[writei.lclust], eax ; (new) last section
  7501                              <1> 	; ecx = sector count (except section header)
  7502 0000EE16 8B15[10650100]      <1> 	mov	edx, [writei.l_index]
  7503 0000EE1C 01CA                <1> 	add	edx, ecx ; add sector count to index
  7504 0000EE1E 8915[10650100]      <1> 	mov	[writei.l_index], edx
  7505 0000EE24 EBC3                <1> 	jmp	short mget_w_16
  7506                              <1> 
  7507                              <1> mget_w_19:
  7508 0000EE26 89E9                <1> 	mov	ecx, ebp
  7509 0000EE28 030D[88030300]      <1> 	add	ecx, [u.count]
  7510 0000EE2E 890D[55040300]      <1> 	mov	[i.size], ecx ; save new file size
  7511                              <1> 	;sub	edx, edx ; 0
  7512                              <1> 
  7513 0000EE34 A0[46030300]        <1> 	mov	al, [cdev]
  7514 0000EE39 A2[F1640100]        <1> 	mov	[writei.drv], al ; physical drive number
  7515                              <1> 	; edx = 0
  7516 0000EE3E 89E8                <1> 	mov	eax, ebp ; file offset
  7517 0000EE40 89C2                <1> 	mov	edx, eax
  7518                              <1> 	; 1 cluster = 512 bytes (for Singlix FS)
  7519 0000EE42 C1E809              <1> 	shr	eax, 9  ; / 512
  7520 0000EE45 81E2FF010000        <1> 	and	edx, 1FFh
  7521                              <1> 	; edx = byte offset in cluster/sector (<= 511)
  7522                              <1> 	; eax = section (sector/cluster) index
  7523 0000EE4B A3[00650100]        <1> 	mov	[writei.c_index], eax
  7524 0000EE50 668915[FA640100]    <1> 	mov	[writei.offset], dx
  7525                              <1> 	;mov	byte [writei.s_index], 0 ; sector index in cluster
  7526 0000EE57 E912FEFFFF          <1> 	jmp	mget_w_3
  7527                              <1> 
  7528                              <1> update_file_lmdt: ; & update file size
  7529                              <1> 	; 26/10/2016
  7530                              <1> 	; 24/10/2016
  7531                              <1> 	; 23/10/2016
  7532                              <1> 	; 22/10/2016 - TRDOS 386 (TRDOS v2.0)
  7533                              <1> 	;
  7534                              <1> 	; Update last modification date&time of file
  7535                              <1> 	; (call from syswrite -> writei)
  7536                              <1> 	; ((also updates file size)) // 26/10/2016
  7537                              <1> 	; 
  7538                              <1> 	; INPUT:
  7539                              <1> 	;      byte [setfmod] = open file number
  7540                              <1> 	; OUTPUT:
  7541                              <1> 	;      cf = 0 -> success !
  7542                              <1> 	;      cf = 1 -> lmdt update has been failed! 	 
  7543                              <1> 	;
  7544                              <1> 	; Modified registers: eax, ebx, ecx, edx, esi, edi       				
  7545                              <1> 	;
  7546                              <1> 
  7547                              <1> 	;cmp	byte [setfmod], 0
  7548                              <1> 	;jna	short uflmdt_2 ; nothing to do
  7549                              <1> 
  7550 0000EE5C 31C0                <1> 	xor	eax, eax
  7551                              <1> 
  7552 0000EE5E 0FB61D[4F650100]    <1> 	movzx	ebx, byte [setfmod]
  7553 0000EE65 FECB                <1> 	dec	bl ; open file index number (0 based)
  7554                              <1> 
  7555 0000EE67 8AA3[BC680100]      <1> 	mov	ah, [ebx+OF_DRIVE]
  7556 0000EE6D BE00010900          <1> 	mov	esi, Logical_DOSDisks
  7557 0000EE72 01C6                <1> 	add	esi, eax
  7558 0000EE74 C0E302              <1> 	shl	bl, 2 ; *4	
  7559 0000EE77 8B8B[94680100]      <1> 	mov	ecx, [ebx+OF_FCLUSTER] ; first cluster
  7560 0000EE7D 8B93[5C690100]      <1> 	mov	edx, [ebx+OF_DIRCLUSTER] ; dir cluster
  7561                              <1> 
  7562 0000EE83 D0EB                <1> 	shr	bl, 1 ; /2
  7563 0000EE85 0FB7BB[FC690100]    <1> 	movzx	edi, word [ebx+OF_DIRENTRY]
  7564                              <1> 	
  7565 0000EE8C 803D[8C600100]01    <1> 	cmp	byte [DirBuff_ValidData], 1
  7566 0000EE93 726E                <1> 	jb	short uflmdt_4
  7567                              <1> 
  7568 0000EE95 A0[8A600100]        <1> 	mov	al, [DirBuff_DRV]
  7569 0000EE9A 2C41                <1> 	sub	al, 'A'	
  7570 0000EE9C 38E0                <1> 	cmp	al, ah
  7571 0000EE9E 7563                <1> 	jne	short uflmdt_4 ; different drive
  7572 0000EEA0 8A4603              <1> 	mov	al, [esi+LD_FATType] 
  7573 0000EEA3 3A05[8B600100]      <1> 	cmp	al, [DirBuff_FATType]
  7574 0000EEA9 755B                <1> 	jne	short uflmdt_5 ; different FS type
  7575 0000EEAB 3B15[91600100]      <1> 	cmp	edx, [DirBuff_Cluster]
  7576 0000EEB1 7553                <1> 	jne	short uflmdt_5 ; different cluster
  7577                              <1> 
  7578                              <1> uflmdt_1:
  7579                              <1> 	; Directory buffer is ready here!
  7580                              <1> 	; OF_FCLUSTER must be compared/verified
  7581 0000EEB3 BE00000800          <1> 	mov	esi, Directory_Buffer
  7582 0000EEB8 66C1E705            <1> 	shl	di, 5 ; dir entry index * 32
  7583 0000EEBC 01FE                <1> 	add	esi, edi ; offset
  7584                              <1> 	;
  7585 0000EEBE F6460B18            <1> 	test	byte [esi+DirEntry_Attr], 18h ; Vol & Dir
  7586 0000EEC2 750F                <1> 	jnz	short uflmdt_2 ; not a valid file !
  7587 0000EEC4 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI]
  7588 0000EEC8 C1E010              <1> 	shl	eax, 16
  7589 0000EECB 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO]
  7590 0000EECF 39C8                <1> 	cmp	eax, ecx ; same first cluster ?
  7591 0000EED1 7407                <1> 	je	short uflmdt_3 ; yes, it is OK !!!	
  7592                              <1> 
  7593                              <1> uflmdt_2:	
  7594                              <1> 	; save directory buffer if has modified/changed sign
  7595                              <1> 	; (It is good to save dir buff even if the searched
  7596                              <1> 	; directory entry is not found !?)
  7597 0000EED3 E81BBAFFFF          <1> 	call	save_directory_buffer
  7598 0000EED8 F9                  <1> 	stc	; update failed
  7599 0000EED9 C3                  <1> 	retn
  7600                              <1> 	
  7601                              <1> uflmdt_3:
  7602                              <1> 	; Update directory entry
  7603                              <1> 	; 26/10/2016
  7604 0000EEDA D0E3                <1> 	shl	bl, 1 ; *2 
  7605 0000EEDC 8B83[0C690100]      <1> 	mov	eax, [ebx+OF_SIZE] ; file size
  7606 0000EEE2 89461C              <1> 	mov	[esi+DirEntry_FileSize], eax
  7607                              <1> 	;
  7608 0000EEE5 E86BB9FFFF          <1> 	call	convert_current_date_time
  7609                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  7610                              <1>         ; 	    AX = Time in dos dir entry format	
  7611 0000EEEA 66894616            <1> 	mov	[esi+DirEntry_WrtTime], ax
  7612 0000EEEE 66895618            <1> 	mov	[esi+DirEntry_WrtDate], dx	
  7613 0000EEF2 66895612            <1> 	mov	[esi+DirEntry_LastAccDate], dx
  7614 0000EEF6 C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  7615 0000EEFD E8F1B9FFFF          <1> 	call	save_directory_buffer
  7616 0000EF02 C3                  <1> 	retn
  7617                              <1> 
  7618                              <1> uflmdt_4:
  7619                              <1> 	; Directory buffer sector read&write
  7620                              <1> 	; 23/10/2016
  7621                              <1> 	;
  7622 0000EF03 8A4603              <1> 	mov	al, [esi+LD_FATType]
  7623                              <1> uflmdt_5:
  7624 0000EF06 BB[9C090300]        <1> 	mov	ebx, rw_buffer ; Common r/w sector buffer addr
  7625                              <1> 		
  7626 0000EF0B 20C0                <1> 	and	al, al ; 0 = Singlix FS
  7627 0000EF0D 0F8492000000        <1> 	jz	uflmdt_11
  7628                              <1> 
  7629 0000EF13 21D2                <1> 	and	edx, edx
  7630 0000EF15 7521                <1> 	jnz	short uflmdt_9
  7631                              <1> 
  7632 0000EF17 3C02                <1> 	cmp	al, 2  ; 3 = FAT32
  7633 0000EF19 771A                <1> 	ja	short uflmdt_8
  7634                              <1> 
  7635 0000EF1B 89F8                <1> 	mov	eax, edi ; directory entry index number
  7636 0000EF1D 66C1E804            <1> 	shr	ax, 4 ; 16 entries per sector	 
  7637 0000EF21 034664              <1> 	add	eax, [esi+LD_ROOTBegin]
  7638                              <1> 	; eax = root directory sector
  7639                              <1> uflmdt_6:
  7640 0000EF24 50                  <1> 	push	eax ; * ; disk sector address
  7641 0000EF25 51                  <1> 	push	ecx ; first cluster	
  7642 0000EF26 B901000000          <1> 	mov	ecx, 1
  7643                              <1> 	; ecx = sector count
  7644 0000EF2B E803090000          <1> 	call	disk_read
  7645 0000EF30 59                  <1> 	pop	ecx
  7646 0000EF31 731A                <1> 	jnc	short uflmdt_10
  7647 0000EF33 58                  <1> 	pop	eax ; *
  7648                              <1> uflmdt_7:
  7649 0000EF34 C3                  <1> 	retn	
  7650                              <1> 
  7651                              <1> uflmdt_8:
  7652 0000EF35 8B5632              <1> 	mov	edx, [esi+LD_BPB+FAT32_RootFClust]
  7653                              <1> uflmdt_9:
  7654 0000EF38 83FA02              <1> 	cmp	edx, 2
  7655 0000EF3B 72F7                <1> 	jb	short uflmdt_7 ; invalid, nothing to do
  7656                              <1> 
  7657 0000EF3D 83EA02              <1> 	sub	edx, 2
  7658 0000EF40 89D0                <1> 	mov	eax, edx
  7659 0000EF42 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
  7660 0000EF46 F7E2                <1> 	mul	edx
  7661 0000EF48 034668              <1> 	add	eax, [esi+LD_DATABegin]
  7662                              <1> 	; eax = sub directory (data) sector 
  7663 0000EF4B EBD7                <1> 	jmp	short uflmdt_6
  7664                              <1> 
  7665                              <1> uflmdt_10:
  7666                              <1> 	; Directory sector buffer is ready here!
  7667                              <1> 	; OF_FCLUSTER must be compared/verified
  7668                              <1> 	; edi = dir entry index number (<= 2047)
  7669 0000EF4D 6683E70F            <1> 	and	di, 0Fh ; 16 entries per sector
  7670 0000EF51 66C1E705            <1> 	shl	di, 5 ; dir entry index * 32
  7671 0000EF55 81C7[9C090300]      <1> 	add	edi, rw_buffer
  7672                              <1> 	;
  7673 0000EF5B F6470B18            <1> 	test	byte [edi+DirEntry_Attr], 18h ; Vol & Dir
  7674 0000EF5F 0F856EFFFFFF        <1> 	jnz	uflmdt_2 ; not a valid file !
  7675 0000EF65 668B5714            <1> 	mov	dx, [edi+DirEntry_FstClusHI]
  7676 0000EF69 C1E210              <1> 	shl	edx, 16
  7677 0000EF6C 668B571A            <1> 	mov	dx, [edi+DirEntry_FstClusLO]
  7678 0000EF70 39CA                <1> 	cmp	edx, ecx ; same first cluster ?
  7679 0000EF72 0F855BFFFFFF        <1> 	jne	uflmdt_2 ; no !?
  7680                              <1> 
  7681                              <1> 	; Update directory entry
  7682 0000EF78 E8D8B8FFFF          <1> 	call	convert_current_date_time
  7683                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  7684                              <1>         ; 	    AX = Time in dos dir entry format	
  7685 0000EF7D 66894716            <1> 	mov	[edi+DirEntry_WrtTime], ax
  7686 0000EF81 66895718            <1> 	mov	[edi+DirEntry_WrtDate], dx	
  7687 0000EF85 66895712            <1> 	mov	[edi+DirEntry_LastAccDate], dx
  7688                              <1> 	
  7689 0000EF89 58                  <1> 	pop	eax ; *
  7690                              <1> 
  7691 0000EF8A BB[9C090300]        <1> 	mov	ebx, rw_buffer ; Common r/w sector buffer addr
  7692 0000EF8F B901000000          <1> 	mov	ecx, 1
  7693                              <1> 	; esi = logical dos description table address
  7694                              <1> 	; eax = disk sector number/address (LBA)
  7695                              <1> 	; ecx = sector count
  7696                              <1> 	; ebx = buffer address
  7697 0000EF94 E88B080000          <1> 	call	disk_write
  7698 0000EF99 0F8234FFFFFF        <1> 	jc	uflmdt_2
  7699                              <1> 	
  7700                              <1> 	; save directory buffer if has modified/changed sign
  7701 0000EF9F E84FB9FFFF          <1> 	call	save_directory_buffer
  7702 0000EFA4 C3                  <1> 	retn
  7703                              <1> 
  7704                              <1> uflmdt_11:
  7705                              <1> 	; 24/10/2016
  7706                              <1> 	; Update last modification date & time of a file
  7707                              <1> 	; on a disk with Singlix File System.
  7708                              <1> 	;
  7709                              <1> 	; (Method: Read the FDT -File Description Table-
  7710                              <1> 	; sector of the file and update the lmdt data fields,
  7711                              <1> 	; then write FDT sector to the disk.
  7712                              <1> 	; /// It is easy but there is compatibility buffer
  7713                              <1> 	; method also for changing directory entry data and
  7714                              <1> 	; also there are some programming issues for Singlix
  7715                              <1> 	; file system (TRFS), which are not completed yet!)
  7716                              <1> 	;
  7717                              <1> 	; Not ready yet ! (24/10/2016)
  7718                              <1> 	; /// Temporary code for error return ! ///
  7719 0000EFA5 31C0                <1> 	xor	eax, eax
  7720 0000EFA7 F9                  <1> 	stc
  7721 0000EFA8 C3                  <1> 	retn
  7722                              <1> 
  7723                              <1> sysalloc:
  7724                              <1> 	; 14/10/2017
  7725                              <1> 	; 20/08/2017, 01/09/2017
  7726                              <1> 	; 20/02/2017, 04/03/2017, 15/05/2017
  7727                              <1> 	; 19/02/2017 - TRDOS 386 (TRDOS v2.0)
  7728                              <1> 	; (TRDOS 386 feature only!)
  7729                              <1> 	;
  7730                              <1> 	; Allocate Contiguous Memory Block/Pages (for user)
  7731                              <1> 	; (System call for DMA Buffer allocation etc.)	
  7732                              <1> 	;
  7733                              <1> 	; INPUT ->
  7734                              <1> 	;	EBX = Virtual address (for user)
  7735                              <1> 	;	     (Physical memory block/aperture
  7736                              <1> 	;	     will be mapped to this virtual address) 
  7737                              <1> 	;	ECX = Byte Count
  7738                              <1> 	;	     (will be rounded up to page border)
  7739                              <1> 	;	If ECX = 0
  7740                              <1> 	;	    System call will return with an error (cf=1)
  7741                              <1> 	;	    but ECX will contain maximum size of
  7742                              <1> 	;	    available memory aperture and physical
  7743                              <1> 	;	    (beginning) address of that aperture
  7744                              <1> 	;	    (which have maximum size) will be in EAX.
  7745                              <1> 	;	EDX = Upper limit of the requested physical memory
  7746                              <1> 	;	      block/pages.
  7747                              <1> 	;	     (The last byte address of the memory aperture 
  7748                              <1> 	;	      must not be equal to or above this limit.)	
  7749                              <1> 	;	If EDX = 0
  7750                              <1> 	; 	   there is NOLIMIT !
  7751                              <1> 	;	If EDX = 0FFFFFFFFh (-1) 
  7752                              <1> 	;	   ESI = Lower Limit !
  7753                              <1> 	;		(Beginning of the block must not be 'less'
  7754                              <1> 	;		than this.) (Must be equal to or above...)
  7755                              <1> 	;	   EDI = Upper Limit !
  7756                              <1> 	;		(End of the block must be !less! than this)
  7757                              <1> 	;		(The last byte addr of the memory aperture 
  7758                              <1> 	;		must not be equal to or above this limit.)
  7759                              <1> 	;
  7760                              <1> 	; OUTPUT ->
  7761                              <1> 	;	If CF = 0
  7762                              <1> 	;	EAX = Physical address of the allocated memory block
  7763                              <1> 	;	ECX = Allocated bytes (as rounded up to page borders)
  7764                              <1> 	;	EBX = Virtual address (as rounded up)
  7765                              <1> 	;	IF CF = 1
  7766                              <1> 	;	    Requested (size of) Memory block could not be 
  7767                              <1> 	;	    allocated to the user!	
  7768                              <1> 	;	IF CF = 1 & EAX = 0 (Insufficient memory error!)
  7769                              <1> 	;	   ECX = Total number of free bytes
  7770                              <1> 	;	         (not size of available contiguous bytes!)		 	
  7771                              <1> 	;	If CF = 1 & EAX > 0
  7772                              <1> 	;	   there is not a memory aperture with requested size
  7773                              <1> 	;	   but total free mem is not less than requested size.
  7774                              <1> 	;	   EAX = Physical addr of available memory aperture
  7775                              <1> 	;	   	 with max size 
  7776                              <1> 	;	        (but it doesn't fit to the conditions!) 	
  7777                              <1> 	;	   ECX = Size of available memory aperture in bytes.
  7778                              <1> 	;	If CF = 1 -> EAX = 0FFFFFFFFh	
  7779                              <1> 	;	   Conditions/Parameters are wrong !		 		
  7780                              <1> 	;	   ECX is same with input value.
  7781                              <1> 	;
  7782                              <1> 	; Note:	Previously allocated pages will be deallocated if
  7783                              <1> 	;       new allocation conditions are met.
  7784                              <1> 	;
  7785                              <1> 	; Note: u.break control may be included in future versions	
  7786                              <1> 	;
  7787                              <1> 
  7788 0000EFA9 31C0                <1> 	xor	eax, eax ; 0
  7789                              <1> 	; 14/10/2017
  7790 0000EFAB 4A                  <1> 	dec	edx ; is there a limit ?
  7791 0000EFAC 7810                <1> 	js	short sysalloc_1 ;  0 -> 0FFFFFFFFh -> NO LIMIT
  7792 0000EFAE 42                  <1> 	inc	edx ; > 0
  7793                              <1> 	; Check upper address limit
  7794                              <1> 	;(round up to page borders)
  7795 0000EFAF 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
  7796 0000EFB5 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
  7797 0000EFBA 39CA                <1> 	cmp	edx, ecx ; upper limit - block size
  7798 0000EFBC 7224                <1> 	jb	short sysalloc_err
  7799                              <1> sysalloc_1:
  7800                              <1> 	; EAX = Beginning address (physical)
  7801                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture	
  7802                              <1> 	; ECX = Number of bytes to be allocated		
  7803 0000EFBE E89364FFFF          <1> 	call	allocate_memory_block
  7804 0000EFC3 721D                <1> 	jc	short sysalloc_err
  7805                              <1> 	; 01/09/2017
  7806 0000EFC5 29C2                <1> 	sub	edx, eax ; upper limit address - beginning address
  7807 0000EFC7 760F                <1> 	jna	short sysalloc_3 ; begin addr not less than the limit
  7808 0000EFC9 39CA                <1> 	cmp	edx, ecx
  7809 0000EFCB 720B                <1> 	jb	short sysalloc_3 ; end address overs the limit
  7810                              <1> sysalloc_2:	
  7811                              <1> 	; EAX = Beginning (physical) addr of the allocated mem block
  7812                              <1> 	; ECX = Num of allocated bytes (rounded up to page borders) 
  7813 0000EFCD 50                  <1> 	push	eax ; * ; 04/03/2017	
  7814                              <1> 	; Here, requested contiquous memory pages have been allocated
  7815                              <1> 	; on Memory Allocation Table but user's page directory 
  7816                              <1> 	; and page tables have not been updated yet!
  7817 0000EFCE 51                  <1> 	push	ecx ; **
  7818                              <1> 	; ebx = virtual address (will be rounded up to page border)
  7819                              <1> 	; ecx = number of bytes to be deallocated
  7820                              <1> 	;	will be adjusted to ebx+ecx round down - ebx round up
  7821 0000EFCF E8DD67FFFF          <1> 	call	deallocate_user_pages 
  7822 0000EFD4 731F                <1> 	jnc	short sysalloc_4 ; EAX = Deallocated memory bytes
  7823 0000EFD6 59                  <1> 	pop	ecx ; **
  7824 0000EFD7 58                  <1> 	pop	eax ; *
  7825                              <1> sysalloc_3:
  7826                              <1> 	; error !
  7827                              <1> 	; restore Memory Allocation Table Content
  7828 0000EFD8 E88666FFFF          <1> 	call	deallocate_memory_block
  7829 0000EFDD 31C0                <1> 	xor	eax, eax ; 0
  7830 0000EFDF 48                  <1> 	dec	eax ; 0FFFFFFFFh ; 15/05/2017
  7831 0000EFE0 EB09                <1> 	jmp	short sysalloc_wrong
  7832                              <1> sysalloc_err:
  7833 0000EFE2 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  7834 0000EFE8 894D18              <1> 	mov	[ebp+24], ecx ; return to user with ecx value 
  7835                              <1> sysalloc_wrong:
  7836                              <1> 	; eax = 0FFFFFFFFh
  7837 0000EFEB A3[64030300]        <1> 	mov	[u.r0], eax
  7838 0000EFF0 E924D7FFFF          <1> 	jmp	error
  7839                              <1> sysalloc_4:
  7840 0000EFF5 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  7841 0000EFFB 894518              <1> 	mov	[ebp+24], eax ; return to user with ecx value 
  7842 0000EFFE 895D10              <1> 	mov	[ebp+16], ebx ; new value of ebx (rounded up)
  7843 0000F001 89C1                <1> 	mov	ecx, eax ; byte count (from 'deallocate_user_pages')
  7844 0000F003 5A                  <1> 	pop	edx ; ** ; discard (another) byte count
  7845 0000F004 58                  <1> 	pop	eax ; *
  7846 0000F005 A3[64030300]        <1> 	mov	[u.r0], eax ; physical address
  7847                              <1> 	
  7848 0000F00A 51                  <1> 	push	ecx ; 20/08/2017
  7849                              <1> 	;
  7850                              <1> 	; Write newly allocated contiguous (physical) pages
  7851                              <1> 	; on page dir and page tables of current user/process	
  7852                              <1> 	; as PRESENT, USER, WRITABLE
  7853                              <1> 	; (then clear allocated pages)
  7854 0000F00B E89668FFFF          <1> 	call	allocate_user_pages
  7855                              <1> 	;jnc	sysret ; OK! return to process with success...
  7856                              <1> 
  7857                              <1> 	; 20/08/2017 ('sysdma' modification)
  7858 0000F010 59                  <1> 	pop	ecx
  7859 0000F011 A1[64030300]        <1> 	mov	eax, [u.r0]   ; physical address (of the block)
  7860                              <1> 
  7861 0000F016 721D                <1> 	jc	short sysalloc_6
  7862                              <1> 
  7863 0000F018 833D[646F0100]FF    <1> 	cmp	dword [dma_addr], 0FFFFFFFFh ; -1	
  7864 0000F01F 0F8214D7FFFF        <1> 	jb	sysret
  7865                              <1> 
  7866 0000F025 A3[646F0100]        <1> 	mov	[dma_addr], eax ; save dma address for sysdma
  7867 0000F02A 890D[686F0100]      <1> 	mov	[dma_size], ecx ; save dma buff size for sysdma
  7868                              <1> 
  7869 0000F030 E904D7FFFF          <1> 	jmp	sysret
  7870                              <1> 		
  7871                              <1> sysalloc_6:
  7872                              <1> 	;
  7873                              <1> 	; unexpected error ! insufficient memory !? conflict !?
  7874                              <1> 	; (!!?there is not a free page for a new page table?!!)
  7875                              <1> 	; We need to terminate process with error message !!!  
  7876                              <1> 	;
  7877 0000F035 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  7878 0000F03B 8B4D18              <1> 	mov	ecx, [ebp+24] ; byte count
  7879                              <1> 	
  7880                              <1> 	; 20/08/2017
  7881                              <1> 	;mov	eax, [u.r0]   ; physical address (of the block)
  7882                              <1> 	
  7883                              <1> 	;
  7884                              <1> 	; restore Memory Allocation Table Content
  7885 0000F03E E82066FFFF          <1> 	call	deallocate_memory_block
  7886                              <1> 	;
  7887 0000F043 803D[F25E0000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80x25 text mode?
  7888 0000F04A 7407                <1> 	je	short sysalloc_7 ; yes
  7889                              <1> 	; Current mode is VGA (or CGA graphics) mode,
  7890                              <1> 	; We need to return to text mode for displaying
  7891                              <1> 	; error message just before 'sysexit'.  
  7892 0000F04C B003                <1> 	mov	al, 3
  7893 0000F04E E84225FFFF          <1> 	call	_set_mode
  7894                              <1> sysalloc_7:
  7895 0000F053 BE[9C100100]        <1> 	mov	esi, beep_Insufficient_Memory ; error message
  7896 0000F058 E84073FFFF          <1> 	call	print_msg ; print/display the message
  7897 0000F05D B801000000          <1> 	mov	eax, 1 ; ax=1 is needed for 'sysexit' procedure
  7898 0000F062 E959D8FFFF          <1> 	jmp	sysexit ; and terminate the process !
  7899                              <1> 
  7900                              <1> sysdalloc:
  7901                              <1> 	; 19/02/2017 - TRDOS 386 (TRDOS v2.0)
  7902                              <1> 	; (TRDOS 386 feature only!)
  7903                              <1> 	;
  7904                              <1> 	; Deallocate Memory Block/Pages (for user)
  7905                              <1> 	; (Complementary call for sysalloc.)	
  7906                              <1> 	;
  7907                              <1> 	; INPUT ->
  7908                              <1> 	;	EBX = Virtual address (for user)
  7909                              <1> 	;	      (will be rounded up to page border)
  7910                              <1> 	;	ECX = Byte Count
  7911                              <1> 	;	     (will be adjusted to page borders)
  7912                              <1> 	;	If ICX = 0
  7913                              <1> 	;	   nothing to do
  7914                              <1> 	;	If EBX + ECX > User's ESP
  7915                              <1> 	;	   nothing to do		
  7916                              <1> 	; 
  7917                              <1> 	; Note: u.break control may be included in future versions	
  7918                              <1> 	;
  7919                              <1> 	; OUTPUT ->
  7920                              <1> 	;	If CF = 0
  7921                              <1> 	;	   EAX = Deallocated memory bytes
  7922                              <1> 	;	   EBX = Virtual address (as rounded up)	
  7923                              <1> 	;	IF CF = 1
  7924                              <1> 	;	   EAX = 0
  7925                              <1> 	;
  7926                              <1> 	; Note:	Main purpose of this call is to deallocate/release
  7927                              <1> 	;	previously allocated (physically) contiguous memory
  7928                              <1> 	;	pages but beginning (virtual) address may not be
  7929                              <1> 	;	followed by physically contiguous pages. So, this
  7930                              <1> 	;	system call will deallocate user's virtually
  7931                              <1> 	;	contiguous memory pages. Also, there is not any
  7932                              <1> 	;	objections to use this system call without sysalloc
  7933                              <1> 	;	system call; only possible objection is to lost data
  7934                              <1> 	;	within user's memory space, if the beginning address
  7935                              <1> 	;	and size is not proper.
  7936                              <1> 	;
  7937                              <1> 	; Note: Empty page tables will not be deallocated!!!
  7938                              <1> 	;       (they will be deallocated at process termination)
  7939                              <1> 	;
  7940                              <1> 	; Note: When the program terminates itself or when it is 
  7941                              <1> 	;	terminated by operating system kernel, all allocated
  7942                              <1> 	;	memory pages will be deallocated during termination
  7943                              <1> 	;	stage. So, 'sysdalloc' is not necessary except 
  7944                              <1> 	;	forgiving memory block to other programs/processes.
  7945                              <1> 	;	
  7946 0000F067 8B15[5C030300]      <1> 	mov	edx, [u.sp]
  7947 0000F06D 8B420C              <1> 	mov	eax, [edx+12] ; user's stack pointer
  7948 0000F070 29C8                <1> 	sub	eax, ecx ; esp - byte count
  7949 0000F072 24FC                <1> 	and	al, 0FCh ; dword alignment
  7950 0000F074 39D8                <1> 	cmp	eax, ebx
  7951 0000F076 7220                <1> 	jb	short sysdalloc_err ; deallocation overlaps with stack 	
  7952                              <1> 
  7953 0000F078 31C0                <1> 	xor	eax, eax
  7954 0000F07A 21C9                <1> 	and	ecx, ecx
  7955 0000F07C 7407                <1> 	jz	short sysdalloc_2
  7956                              <1> 	
  7957 0000F07E E82E67FFFF          <1> 	call	deallocate_user_pages
  7958 0000F083 7213                <1> 	jc	short sysdalloc_err
  7959                              <1> 
  7960                              <1> sysdalloc_2:
  7961 0000F085 A3[64030300]        <1> 	mov	[u.r0], eax
  7962 0000F08A 8B2D[60030300]      <1> 	mov	ebp, [u.usp]
  7963 0000F090 895D10              <1> 	mov	[ebp+16], ebx ; new value of ebx
  7964 0000F093 E9A1D6FFFF          <1> 	jmp	sysret
  7965                              <1> 
  7966                              <1> sysdalloc_err:
  7967 0000F098 A3[64030300]        <1> 	mov	[u.r0], eax ; 0
  7968 0000F09D E977D6FFFF          <1> 	jmp	error
  7969                              <1> 
  7970                              <1> syscalbac:
  7971                              <1> 	; SYS CALLBACK
  7972                              <1> 	; 16/04/2017
  7973                              <1> 	; 14/04/2017
  7974                              <1> 	; 13/04/2017
  7975                              <1> 	; 28/02/2017
  7976                              <1> 	; 26/02/2017
  7977                              <1> 	; 24/02/2017
  7978                              <1> 	; 21/02/2017 - TRDOS 386 (TRDOS v2.0)
  7979                              <1> 	; (TRDOS 386 feature only!)
  7980                              <1> 	;
  7981                              <1> 	; Link or unlink IRQ callback service to/from user (ring 3)	
  7982                              <1> 	;
  7983                              <1> 	; INPUT ->
  7984                              <1> 	;	BL = IRQ number (Hardware interrupt request number)
  7985                              <1> 	;	     (0 t0 15 but IRQ 0,1,2,6,8,14,15 are prohibited)
  7986                              <1> 	;	     IRQ numbers 3,4,5,7,9,10,11,12,13 are valid
  7987                              <1> 	;	     (numbers >15 are invalid)
  7988                              <1> 	;
  7989                              <1> 	;	BH = 0 = Unlink IRQ (in BL) from user (ring 3) service
  7990                              <1> 	;	     1 = Link IRQ by using Signal Response Byte method
  7991                              <1> 	;	     2 = Link IRQ by using Callback service method 		
  7992                              <1> 	;	     3 = Link IRQ by using Auto Increment S.R.B. method 	
  7993                              <1> 	;	    >3 = invalid 
  7994                              <1> 	;	
  7995                              <1> 	;	CL = Signal Return/Response Byte value 
  7996                              <1> 	;
  7997                              <1> 	;	If BH = 2, kernel will put a counter value 
  7998                              <1> 	;	          (into the S.R.B. addr)
  7999                              <1> 	;		  between 0 to 255. (start value = CL+1)
  8000                              <1> 	;	
  8001                              <1> 	;	NOTE: counter value, for example: even and odd numbers
  8002                              <1> 	;	      may be used for -audio- DMA buffer switch 
  8003                              <1> 	;	      within double buffer method, etc. 		
  8004                              <1> 	;
  8005                              <1> 	;	EDX = Signal return (Response) byte address
  8006                              <1> 	;	       		  - or -
  8007                              <1> 	;	      Interrupt/Callback service/routine address
  8008                              <1> 	; 	
  8009                              <1> 	;	      (virtual address in user's memory space)
  8010                              <1> 	;
  8011                              <1> 	; OUTPUT ->
  8012                              <1> 	;	CF = 0 & EAX = 0 -> Successful setting
  8013                              <1> 	;	CF = 1 & EAX > 0 -> IRQ is prohibited or locked 
  8014                              <1> 	;			by another process
  8015                              <1> 	;		 eax = ERR_PERM_DENIED -> prohibited or locked
  8016                              <1> 	;		 eax = ERR_INV_PARAMETER -> 
  8017                              <1> 	;		       invalid parameter/option or bad address
  8018                              <1> 	;
  8019                              <1> 	;	NOTE: Timer callbacks are set by using 'systimer'
  8020                              <1> 	;	      system call (IRQ 0, PIT and IRQ 8, RTC)
  8021                              <1> 	;
  8022                              <1> 	;	      Direct keyboard access is performed by using
  8023                              <1> 	;	      Keyboard Interrupt (INT 32h)	 	
  8024                              <1> 	;	
  8025                              <1> 	;	      It is prohibited here because:
  8026                              <1> 	;		1) Signal Response Byte method has not advantage
  8027                              <1> 	;		   against INT 32h, function AH = 1. Also,
  8028                              <1> 	;		   keyboard service interrupt will return with
  8029                              <1> 	;		   ascii and scan codes (AL, AH) while
  8030                              <1> 	;		   SRB method has only 1 byte space for ascii code
  8031                              <1> 	;		   or scan code. One byte signal response is used 
  8032                              <1> 	;		   for ensuring very simple and very fast
  8033                              <1> 	;		   virtual to physical memory address conversion
  8034                              <1> 	;		   without any memory page crossover risk. 
  8035                              <1> 	;		   (Otherwise double page conversion or word 
  8036                              <1> 	;		   alignment would be needed.)
  8037                              <1> 	;		2) Badly written user code (callback code)
  8038                              <1> 	;		   can prevent keyboard and timesharing functions
  8039                              <1> 	;		   of the operating system via continuous and long
  8040                              <1> 	;		   keyboard event handling by callback service.
  8041                              <1> 	;		   (It can cause to lose immediate keystroke 
  8042                              <1> 	;		   response from hardware to user.)
  8043                              <1> 	;		3) If user will check any keyboard events, 'getkey'
  8044                              <1> 	;		   (or 'getchar') must have more priority than other
  8045                              <1> 	;		   (video etc.) events because only control ability
  8046                              <1> 	;		   on a procedural infinite loop is a keyboard or
  8047                              <1> 	;		   mouse event. So user can use keyboard function
  8048                              <1> 	;		   at the end or at the beginning of a loop.
  8049                              <1> 	;		   In this case, INT 32h is used for that purpose
  8050                              <1> 	;		   and timer interrupt etc. callbacks can be used
  8051                              <1> 	;		   for dynamic and synchronized data refresh/transfer
  8052                              <1> 	;		   while cpu is in a static loop (without polling).
  8053                              <1> 	;		   Keyboard Int callback is not more useful because 
  8054                              <1> 	;		   already a manual check (a key is pressed or not)
  8055                              <1> 	;		   can be performed (via INT 32h, AH = 1) efficiently
  8056                              <1> 	;		   in a loop to prevent a locked infinitive loop.
  8057                              <1> 	;
  8058                              <1> 	;	    Disk IRQs (6,14,15) have been phohibited from ring 3 
  8059                              <1> 	;	    callback because, disk operations (file system services
  8060                              <1> 	;	    etc.) are independent from user program, for fast disk r/w.
  8061                              <1> 	;	    They are not more useful at ring 3 while they are in use
  8062                              <1> 	;	    by standard diskio functions which are mandatory part of 
  8063                              <1> 	;	    (monolithic) OS kernel and mainprog command interpreter.
  8064                              <1> 	;	    INT 33h diskio functions are enough for user level disk
  8065                              <1> 	;	    r/w.				
  8066                              <1> 	;
  8067                              <1> 	; TRDOS 386 - IRQ CALLBACK structures (parameters):
  8068                              <1> 	;	
  8069                              <1> 	;	   [u.irqlock] = 1 word, IRQ flags (0-15) that indicates
  8070                              <1> 	;			which IRQs are locked by (that) user.
  8071                              <1> 	;		        Lock and unlock (by user) will change
  8072                              <1> 	;			these flags or 'terminate process' (sysexit)
  8073                              <1> 	;			will clear these flags and unlock those IRQs.
  8074                              <1> 	;			               
  8075                              <1> 	;		   	Bit 0 is for IRQ 0 and Bit 15 is for IRQ 15
  8076                              <1> 	;
  8077                              <1> 	;	   IRQ(x).owner	 : 1 byte, user, [u.uno], 0 = free (unlocked)	
  8078                              <1> 	;
  8079                              <1> 	;	   IRQ(x).method : 1 byte for callback method & status
  8080                              <1> 	;			   0 = Signal Response Byte method
  8081                              <1> 	;			   1 = Callback service method
  8082                              <1> 	;			   >1 = invalid for current 'syscalback'.
  8083                              <1> 	;			or(+) 80h = IRQ is in use by system (ring 0)
  8084                              <1> 	;			            function (audio etc.) or
  8085                              <1> 	;			   	    a device driver.	   	
  8086                              <1> 	;			(system function will ignore the lock/owner)
  8087                              <1> 	;
  8088                              <1> 	;	   IRQ(x).srb	: 1 byte, Signal Return/Response byte value
  8089                              <1> 	;			  (a fixed value by user or a counter value
  8090                              <1> 	;			 from 0 to 255, which is increased by every
  8091                              <1> 	;			 interrupt just before putting it into 
  8092                              <1> 	;			 the Signal Response byte address
  8093                              <1> 	;			 (This is not used in callback serv method)
  8094                              <1> 	;	    	  
  8095                              <1> 	;	   IRQ(x).addr	: 1 dword
  8096                              <1> 	;			  Signal Response Byte address (physical)
  8097                              <1> 	;			  		-or-
  8098                              <1> 	;			  Callback service address (virtual)
  8099                              <1> 	;
  8100                              <1> 	;	   IRQ(x).dev	: 1 byte
  8101                              <1> 	;			  0 = Default device or kernel function
  8102                              <1> 	;			  		-or-
  8103                              <1> 	;			  1-255 = Assigned device driver number
  8104                              <1> 	;
  8105                              <1> 	;	   (x) = 3,4,5,7,9,10,11,12,13
  8106                              <1> 	;
  8107                              <1> 	;	
  8108                              <1> 	;	NOTE: If user's process/program calls the kernel (INT 40h)
  8109                              <1> 	;	      while it is already running in a (ring 3) callback
  8110                              <1> 	;	      service, kernel will force (convert) system call to
  8111                              <1> 	;	      'sysrele' (sys release). So, this feature provides
  8112                              <1> 	;	      easy and simple usage of callback services without
  8113                              <1> 	;	      falling into deepless <please 'callback me' then 
  8114                              <1> 	;	      let me 'callback you'> cycles! (User must return
  8115                              <1> 	;	      from callback service by using 'sysrele' system
  8116                              <1> 	;	      call, without a significant delay. Otherwise user
  8117                              <1> 	;	      process/program may be late to catch the next event
  8118                              <1> 	;	      within same callback purpose.	    		 	
  8119                              <1> 	;
  8120                              <1> 
  8121 0000F0A2 30C0                <1> 	xor	al, al ; the caller is 'syscalbac' sign/flag
  8122 0000F0A4 E867180000          <1>  	call	set_irq_callback_service
  8123                              <1> 	; 16/04/2017
  8124 0000F0A9 A3[64030300]        <1> 	mov	[u.r0], eax
  8125 0000F0AE 0F8385D6FFFF        <1> 	jnc	sysret
  8126 0000F0B4 A3[C8030300]        <1> 	mov	dword [u.error], eax
  8127 0000F0B9 E95BD6FFFF          <1> 	jmp	error
  8128                              <1> 
  8129                              <1> sysfpstat:
  8130                              <1> 	; 28/02/2017 - TRDOS 386 (TRDOS v2.0)
  8131                              <1> 	; (TRDOS 386 feature only!)
  8132                              <1> 	;
  8133                              <1> 	; Set or reset FPU registers save/restore option (for user)
  8134                              <1> 	;	       (during software task switching, wswap-rswap)
  8135                              <1> 	;
  8136                              <1> 	; INPUT ->
  8137                              <1> 	;	BL = 0 -> reset
  8138                              <1> 	;	BL = 1 -> set (FPU register will be saved and restored)
  8139                              <1> 	;	
  8140                              <1> 	; OUTPUT ->
  8141                              <1> 	;	cf = 0 -> no error, FPU is ready... 
  8142                              <1> 	;		  (EAX = 0)
  8143                              <1> 	;	Cf = 1 -> error, 80387 FPU is not ready !
  8144                              <1> 	;		  (EAX = 0FFFFFFFFh)
  8145                              <1> 
  8146 0000F0BE 31C0                <1> 	xor	eax, eax
  8147 0000F0C0 803D[5C650100]00    <1> 	cmp	byte [fpready], 0
  8148 0000F0C7 7613                <1> 	jna	short sysfpstat_err	
  8149                              <1> 
  8150 0000F0C9 80E301              <1> 	and	bl, 1 ; use BIT 0 only !
  8151 0000F0CC 881D[DA030300]      <1> 	mov	[u.fpsave], bl
  8152 0000F0D2 A3[64030300]        <1> 	mov	[u.r0], eax ; 0
  8153 0000F0D7 E95DD6FFFF          <1> 	jmp	sysret	 	
  8154                              <1> 
  8155                              <1> sysfpstat_err:
  8156 0000F0DC 48                  <1> 	dec 	eax ; 0FFFFFFFFh
  8157 0000F0DD A3[64030300]        <1> 	mov 	[u.r0], eax ; -1
  8158 0000F0E2 E932D6FFFF          <1> 	jmp 	error
  8159                              <1> 
  8160                              <1> sysdelete: ; Delete (Remove, Unlink) File
  8161                              <1> 	; 29/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8162                              <1> 	;	
  8163                              <1>         ; INPUT ->
  8164                              <1>         ;          EBX = File name (ASCIIZ string) address
  8165                              <1> 	; OUTPUT ->
  8166                              <1> 	;          cf = 0 -> eax = 0
  8167                              <1> 	;          cf = 1 -> Error code in AL
  8168                              <1> 	;
  8169                              <1> 	; Modified Registers: EAX (at the return of system call)
  8170                              <1> 	;   
  8171                              <1> 
  8172 0000F0E7 89DE                <1> 	mov	esi, ebx
  8173                              <1> 	; file name is forced, change directory as temporary
  8174                              <1> 	;mov	ax, 1
  8175                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
  8176                              <1> 	;call	set_working_path 
  8177 0000F0E9 E8680B0000          <1> 	call	set_working_path_x
  8178 0000F0EE 731D                <1> 	jnc	short sysdelete_1
  8179                              <1> 
  8180 0000F0F0 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  8181 0000F0F2 7505                <1> 	jnz	short sysdelete_err
  8182                              <1> 	; eax = 0
  8183                              <1> sysdelete_path_err:
  8184 0000F0F4 B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'bad path name !'
  8185                              <1> sysdelete_err:
  8186 0000F0F9 A3[64030300]        <1> 	mov	[u.r0], eax
  8187 0000F0FE A3[C8030300]        <1> 	mov	[u.error], eax
  8188 0000F103 E8230C0000          <1> 	call 	reset_working_path
  8189 0000F108 E90CD6FFFF          <1> 	jmp	error
  8190                              <1> sysdelete_1:
  8191                              <1> 	;mov	esi, FindFile_Name
  8192 0000F10D 66B80018            <1> 	mov	ax, 1800h ; Only files
  8193 0000F111 E8A891FFFF          <1> 	call	find_first_file
  8194 0000F116 72E1                <1> 	jc	short sysdelete_err
  8195                              <1> sysdelete_2:
  8196                              <1> 	; check file attributes
  8197                              <1> 
  8198                              <1> 	;test	bl, 17 ; system, hidden, readonly, directory
  8199 0000F118 F6C307              <1>         test	bl, 7 ; system, hidden, readonly 
  8200 0000F11B 7407                <1>         jz	short sysdelete_3
  8201                              <1> 
  8202 0000F11D B80B000000          <1>         mov	eax, ERR_FILE_ACCESS ; 11 = 'permission denied !'
  8203 0000F122 EBD5                <1>         jmp	short sysdelete_err
  8204                              <1> sysdelete_3:
  8205 0000F124 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  8206 0000F127 7407                <1> 	jz	short sysdelete_4
  8207 0000F129 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 26 = 'invalid file name !'
  8208 0000F12E EBC9                <1>         jmp	short sysdelete_err
  8209                              <1> sysdelete_4:
  8210                              <1> 	;mov	bh, [LongName_EntryLength]
  8211 0000F130 883D[CE620100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  8212                              <1> 	; edi = Directory Entry Offset (DirBuff)
  8213                              <1> 	; esi = Directory Entry (FFF Structure)
  8214 0000F136 E800BBFFFF          <1> 	call	remove_file
  8215 0000F13B 72BC                <1> 	jc	short sysdelete_err
  8216                              <1> sysrmdir_5:
  8217 0000F13D 31C0                <1> 	xor	eax, eax ; 0
  8218 0000F13F A3[64030300]        <1> 	mov	[u.r0], eax
  8219                              <1> 	;mov	[u.error], eax
  8220 0000F144 E8E20B0000          <1> 	call 	reset_working_path
  8221 0000F149 E9EBD5FFFF          <1> 	jmp	sysret
  8222                              <1> 
  8223                              <1> 
  8224                              <1> sysrmdir: ; Remove (Unlink) Directory
  8225                              <1> 	; 29/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8226                              <1> 	;	
  8227                              <1>         ; INPUT ->
  8228                              <1>         ;          EBX = Pointer to directory name
  8229                              <1> 	; OUTPUT ->
  8230                              <1> 	;          cf = 0 -> eax = 0
  8231                              <1> 	;          cf = 1 -> Error code in AL
  8232                              <1> 	;
  8233                              <1> 	; Modified Registers: EAX (at the return of system call)
  8234                              <1> 	;  
  8235                              <1> 
  8236 0000F14E 803D[B3030300]00    <1> 	cmp	byte [u.uno], 0  ; root (super user) ?
  8237 0000F155 7614                <1> 	jna	short sysrmdir_0
  8238                              <1> 
  8239                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
  8240 0000F157 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; ERR_NOT_SUPERUSER
  8241 0000F15C A3[64030300]        <1> 	mov	[u.r0], eax
  8242 0000F161 A3[C8030300]        <1> 	mov	[u.error], eax
  8243 0000F166 E9AED5FFFF          <1> 	jmp	error
  8244                              <1> 
  8245                              <1> sysrmdir_0:
  8246 0000F16B 89DE                <1> 	mov	esi, ebx
  8247                              <1> 	; file name is forced, change directory as temporary
  8248                              <1> 	;mov	ax, 1
  8249                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
  8250                              <1> 	;call	set_working_path 
  8251 0000F16D E8E40A0000          <1> 	call	set_working_path_x
  8252 0000F172 731D                <1> 	jnc	short sysrmdir_1
  8253                              <1> 
  8254 0000F174 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  8255 0000F176 7505                <1> 	jnz	short sysrmdir_err
  8256                              <1> 	; eax = 0
  8257                              <1> sysrmdir_not_found:
  8258 0000F178 B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
  8259                              <1> sysrmdir_err:
  8260 0000F17D A3[64030300]        <1> 	mov	[u.r0], eax
  8261 0000F182 A3[C8030300]        <1> 	mov	[u.error], eax
  8262 0000F187 E89F0B0000          <1> 	call 	reset_working_path
  8263 0000F18C E988D5FFFF          <1> 	jmp	error
  8264                              <1> sysrmdir_1:
  8265                              <1> 	;mov	esi, FindFile_Name
  8266 0000F191 66B81008            <1> 	mov	ax, 0810h ; Only directories
  8267 0000F195 E82491FFFF          <1> 	call	find_first_file
  8268 0000F19A 7306                <1> 	jnc	short sysrmdir_2
  8269                              <1> 
  8270                              <1> 	; eax = 2 (File not found !)
  8271 0000F19C 3C02                <1> 	cmp	al, 2 ; ERR_NOT_FOUND
  8272 0000F19E 74D8                <1> 	je	short sysrmdir_not_found
  8273 0000F1A0 EBDB                <1> 	jmp	short sysrmdir_err
  8274                              <1> sysrmdir_2:
  8275                              <1> 	; check directory attributes
  8276                              <1> 
  8277 0000F1A2 F6C307              <1>         test	bl, 7 ; system, hidden, readonly 
  8278 0000F1A5 7407                <1>         jz	short sysrmdir_3
  8279                              <1> 
  8280 0000F1A7 B80B000000          <1>         mov	eax, ERR_DIR_ACCESS ; 11 = 'permission denied !'
  8281 0000F1AC EBCF                <1>         jmp	short sysrmdir_err
  8282                              <1> sysrmdir_3:
  8283 0000F1AE 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  8284 0000F1B1 7407                <1> 	jz	short sysrmdir_4
  8285                              <1> 	;mov	eax, ERR_NOT_DIR ; 'not a valid directory !'
  8286 0000F1B3 B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'bad path name !'
  8287 0000F1B8 EBC3                <1>         jmp	short sysrmdir_err
  8288                              <1> sysrmdir_4:
  8289                              <1> 	;mov	bh, [LongName_EntryLength]
  8290 0000F1BA 883D[CE620100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  8291                              <1> 	; edi = Directory Entry Offset (DirBuff)
  8292                              <1> 	; esi = Directory Entry (FFF Structure)
  8293 0000F1C0 E8CE97FFFF          <1> 	call	delete_sub_directory
  8294 0000F1C5 0F8372FFFFFF        <1> 	jnc	sysrmdir_5
  8295                              <1> ;	jc	short sysrmdir_6
  8296                              <1> ;
  8297                              <1> ;	xor	eax, eax ; 0
  8298                              <1> ;sysrmdir_5:
  8299                              <1> ;	mov	[u.r0], eax
  8300                              <1> ;	;mov	[u.error], eax
  8301                              <1> ;	call 	reset_working_path
  8302                              <1> ;	jmp	sysret
  8303                              <1> sysrmdir_6:
  8304 0000F1CB A3[64030300]        <1> 	mov	[u.r0], eax
  8305 0000F1D0 A3[C8030300]        <1> 	mov	[u.error], eax
  8306                              <1> 
  8307 0000F1D5 09C0                <1> 	or	eax, eax ; EAX = 0 -> Directory not empty!
  8308 0000F1D7 741C                <1> 	jz	short sysrmdir_9
  8309                              <1> 
  8310                              <1> 	; EAX > 0 -> Error code in AL (or AX or EAX)
  8311                              <1> 
  8312 0000F1D9 833D[82600100]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
  8313 0000F1E0 7209                <1> 	jb	short sysrmdir_8
  8314                              <1> sysrmdir_7:
  8315                              <1> 	; ESI = Logical DOS Drive Description Table address	
  8316 0000F1E2 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
  8317                              <1> 	           ; BL = 0 -> Recalculate free cluster count
  8318 0000F1E6 E834D0FFFF          <1> 	call	calculate_fat_freespace	
  8319                              <1> sysrmdir_8:
  8320 0000F1EB E83B0B0000          <1> 	call 	reset_working_path
  8321 0000F1F0 E924D5FFFF          <1> 	jmp	error
  8322                              <1> 
  8323                              <1> sysrmdir_9:
  8324 0000F1F5 A1[82600100]        <1> 	mov	eax, [FAT_ClusterCounter]
  8325 0000F1FA 09C0                <1> 	or	eax, eax ; 0 ?
  8326 0000F1FC 0F847BFFFFFF        <1> 	jz	sysrmdir_err
  8327                              <1> 	; ESI = Logical DOS Drive Description Table address	
  8328 0000F202 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
  8329                              <1> 	           ; BL = 1 -> add free clusters
  8330 0000F206 E814D0FFFF          <1> 	call	calculate_fat_freespace
  8331 0000F20B 09C9                <1> 	or	ecx, ecx
  8332 0000F20D 74DC                <1>         jz	short sysrmdir_8 ; ecx = 0 -> OK
  8333                              <1> 	; ecx > 0 -> Error (Recalculation is needed)
  8334 0000F20F EBD1                <1> 	jmp	short sysrmdir_7
  8335                              <1> 
  8336                              <1> 
  8337                              <1> syschdir: ; Change Current (Working) Drive & Directory (for user)
  8338                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8339                              <1> 	;	
  8340                              <1>         ; INPUT ->
  8341                              <1>         ;          EBX = Directory name (ASCIIZ string) address
  8342                              <1> 	; OUTPUT ->
  8343                              <1> 	;          cf = 0 -> eax = 0
  8344                              <1> 	;          cf = 1 -> Error code in AL
  8345                              <1> 	;
  8346                              <1> 	; Modified Registers: EAX (at the return of system call)
  8347                              <1> 	;
  8348                              <1> 	; NOTE: If drive name is not included, only the working
  8349                              <1> 	; directory (for user, not for drive/OS) will be chanded.
  8350                              <1> 	; If there is a drive name (as A:, B:, C:, D: etc.)
  8351                              <1> 	; at the beginning of the ASCIIZ (directory) string,
  8352                              <1> 	; working drive and working directory (for user) 
  8353                              <1> 	; will be changed together.
  8354                              <1> 	; (When the program is terminated, MainProg -internal 
  8355                              <1> 	; shell- will reset working directory to the previous
  8356                              <1> 	; -current- logical drive's current directory again.) 	
  8357                              <1>   
  8358 0000F211 89DE                <1> 	mov	esi, ebx
  8359                              <1> 	; file name is not forced, change directory as temporary
  8360 0000F213 31C0                <1> 	xor	eax, eax
  8361                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
  8362                              <1> 	;call	set_working_path 
  8363 0000F215 E8400A0000          <1> 	call	set_working_path_xx
  8364 0000F21A 731D                <1> 	jnc	short syschdir_ok
  8365 0000F21C 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  8366 0000F21E 7505                <1> 	jnz	short syschdir_err
  8367                              <1> 	; eax = 0
  8368                              <1> syschdir_not_found:
  8369 0000F220 B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
  8370                              <1> syschdir_err:
  8371 0000F225 A3[64030300]        <1> 	mov	[u.r0], eax
  8372 0000F22A A3[C8030300]        <1> 	mov	[u.error], eax
  8373 0000F22F E8F70A0000          <1> 	call 	reset_working_path
  8374 0000F234 E9E0D4FFFF          <1> 	jmp	error
  8375                              <1> syschdir_ok:
  8376 0000F239 31C0                <1> 	xor	eax, eax ; 0
  8377 0000F23B A3[64030300]        <1> 	mov	[u.r0], eax
  8378                              <1> 	;mov	[u.error], eax
  8379 0000F240 E9F4D4FFFF          <1> 	jmp	sysret
  8380                              <1> 
  8381                              <1> 
  8382                              <1> syschmod: ; Get & Change File (or Directory) Attributes
  8383                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8384                              <1> 	;	
  8385                              <1>         ; INPUT ->
  8386                              <1>         ;          EBX = File/Directory (ASCIIZ) name address
  8387                              <1> 	;	    CL = New attributes (if CL < 40h)
  8388                              <1> 	;	    CL >= 40h -> Get File Attributes		
  8389                              <1> 	; OUTPUT ->
  8390                              <1> 	;          cf = 0 -> EAX = File attributes (in AL)
  8391                              <1> 	;          cf = 1 -> Error code in AL
  8392                              <1> 	;
  8393                              <1> 	; Modified Registers: EAX (at the return of system call)
  8394                              <1> 	;  
  8395                              <1> 	; MSDOS File Attributes:    (bit value of attrib byte)
  8396                              <1> 	;	ATTR_READ_ONLY	=	01h  (bit 0, 'R')
  8397                              <1> 	;	ATTR_HIDDEN	=	02h  (bit 1, 'H')
  8398                              <1> 	;	ATTR_SYSTEM	=	04h  (bit 2, 'S')
  8399                              <1> 	;	ATTR_VOLUME_ID	=	08h  (bit 3)
  8400                              <1> 	;	ATTR_DIRECTORY	=	10h  (bit 4)
  8401                              <1> 	;	ATTR_ARCHIVE	=	20h  (bit 5, 'A')
  8402                              <1> 	;	ATTR_LONG_NAME	=	ATTR_READONLY |
  8403                              <1> 	;				ATTR_HIDDEN |
  8404                              <1> 	;				ATTR_SYSTEM |
  8405                              <1> 	;				ATTR_VOLUME_ID				
  8406                              <1> 	;	The upper two bits of attributes must be 0.
  8407                              <1> 
  8408                              <1> 	; Note:	* If ATTR_DIRECTORY is set, only directory names
  8409                              <1> 	;	  will be searched (and S,H,R,A attributeds of 
  8410                              <1> 	;	  the directory will be changed.)
  8411                              <1> 	;	* If ATTR_VOLUME_ID is set, 'syschmod' system call
  8412                              <1> 	;	  will return with 'permission denied' error.
  8413                              <1> 	;	* If ATTR_DIRECTORY is not set, only file names
  8414                              <1> 	;	  will be searched (and S,H,R,A attributes of the
  8415                              <1> 	;	  file will be changed.)
  8416                              <1> 	;
  8417                              <1> 	; (Ony Super User can change S,H,R attributes.) 
  8418                              <1> 
  8419 0000F245 80F940              <1> 	cmp	cl, 40h	
  8420 0000F248 7327                <1> 	jnb	short syschmod_0
  8421                              <1> 
  8422 0000F24A F6C108              <1> 	test	cl, 08h ; ATTR_VOLUME_ID
  8423 0000F24D 750E                <1> 	jnz	short syschmod_perm_err
  8424                              <1> 
  8425 0000F24F 803D[B3030300]00    <1> 	cmp	byte [u.uno], 0  ; root (super user) ?
  8426 0000F256 7619                <1> 	jna	short syschmod_0
  8427                              <1> 
  8428                              <1> 	; Not super user..
  8429 0000F258 F6C107              <1> 	test	cl, 07h	; S,H,R attributes
  8430 0000F25B 7414                <1> 	jz	short syschmod_0
  8431                              <1> 
  8432                              <1> syschmod_perm_err:
  8433                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
  8434 0000F25D B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; 'permission denied !'
  8435 0000F262 A3[64030300]        <1> 	mov	[u.r0], eax
  8436 0000F267 A3[C8030300]        <1> 	mov	[u.error], eax
  8437 0000F26C E9A8D4FFFF          <1> 	jmp	error
  8438                              <1> 
  8439                              <1> syschmod_0:
  8440 0000F271 880D[1C630100]      <1> 	mov	[Attributes], cl
  8441 0000F277 89DE                <1> 	mov	esi, ebx
  8442                              <1> 	; file name is forced, change directory as temporary
  8443                              <1> 	;mov	ax, 1
  8444                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
  8445                              <1> 	;call	set_working_path 
  8446 0000F279 E8D8090000          <1> 	call	set_working_path_x
  8447 0000F27E 731D                <1> 	jnc	short syschmod_1
  8448 0000F280 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  8449 0000F282 7505                <1> 	jnz	short syschmod_err
  8450                              <1> 	; eax = 0
  8451                              <1> syschmod_path_not_found:
  8452 0000F284 B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'Bad path name !'
  8453                              <1> syschmod_err:
  8454 0000F289 A3[64030300]        <1> 	mov	[u.r0], eax
  8455 0000F28E A3[C8030300]        <1> 	mov	[u.error], eax
  8456 0000F293 E8930A0000          <1> 	call 	reset_working_path
  8457 0000F298 E97CD4FFFF          <1> 	jmp	error
  8458                              <1> syschmod_1:
  8459 0000F29D B008                <1> 	mov	al, 08h ; Except volume labels (& long names)
  8460 0000F29F A0[1C630100]        <1> 	mov	al, [Attributes]
  8461 0000F2A4 2410                <1> 	and	al, 10h ;
  8462                              <1> 	;mov	esi, FindFile_Name
  8463                              <1> 	;mov	ax, 1800h ; Only files
  8464                              <1> 	;mov	ax, 0810h ; Only directories
  8465 0000F2A6 E81390FFFF          <1> 	call	find_first_file
  8466                              <1> 	;jnc	short syschmod_2
  8467 0000F2AB 72DC                <1> 	jc	short syschmod_err
  8468                              <1> 
  8469                              <1> 	;; eax = 2 (File not found !)
  8470                              <1> 	;cmp	al, 2 ; ERR_NOT_FOUND
  8471                              <1> 	;jne	short syschmod_err
  8472                              <1> 
  8473                              <1> 	;and	byte [Attributes], 10h
  8474                              <1> 	;jz	short syschmod_err
  8475                              <1> 
  8476                              <1> 	;; Directory not found !
  8477                              <1> 	;mov	al, 3 ; ERR_PATH_NOT_FOUND
  8478                              <1> 	;jmp	short syschmod_err
  8479                              <1> 
  8480                              <1> syschmod_2:
  8481 0000F2AD 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  8482 0000F2B0 7407                <1> 	jz	short syschmod_3
  8483 0000F2B2 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 'invalid file name !'
  8484 0000F2B7 EBD0                <1>         jmp	short syschmod_err
  8485                              <1> syschmod_3:
  8486                              <1> 	; EDI = Directory buffer entry offset/address
  8487                              <1> 	; BL = File (or Directory) Attributes 
  8488                              <1> 	; mov	bl, [EDI+0Bh]
  8489                              <1> 
  8490                              <1> 	; check directory attributes
  8491 0000F2B9 8A3D[1C630100]      <1> 	mov	bh, [Attributes] ; new attributes
  8492 0000F2BF 80FF40              <1> 	cmp	bh, 40h  ;>=40 -> get file/directory attributes
  8493 0000F2C2 732D                <1> 	jnb	short syschmod_6
  8494                              <1> 
  8495                              <1> 	; set file/directory attributes
  8496 0000F2C4 F6C307              <1> 	test	bl, 7 ; system, hidden, readonly 
  8497 0000F2C7 7409                <1>         jz	short syschmod_4
  8498                              <1> 
  8499 0000F2C9 803D[B3030300]00    <1> 	cmp	byte [u.uno], 0  ; root (super user) ?
  8500 0000F2D0 778B                <1> 	ja	short syschmod_perm_err
  8501                              <1> syschmod_4:
  8502 0000F2D2 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
  8503 0000F2D8 7424                <1> 	je	short syschmod_7
  8504                              <1> 
  8505 0000F2DA 887F0B              <1> 	mov	[edi+0Bh], bh    ; Attributes (New!)
  8506                              <1> 
  8507 0000F2DD C605[8C600100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; modified sign
  8508                              <1> 					    ; to force write	
  8509 0000F2E4 E80AB6FFFF          <1> 	call 	save_directory_buffer
  8510 0000F2E9 729E                <1> 	jc	short syschmod_err
  8511                              <1> 
  8512                              <1> syschmod_5:
  8513 0000F2EB 8A1D[1C630100]      <1> 	mov	bl, [Attributes]
  8514                              <1> syschmod_6:
  8515 0000F2F1 0FB6C3              <1> 	movzx	eax, bl
  8516 0000F2F4 A3[64030300]        <1> 	mov	[u.r0], eax
  8517                              <1> 	;mov	dword [u.error], 0
  8518 0000F2F9 E93BD4FFFF          <1> 	jmp	sysret
  8519                              <1> 
  8520                              <1> syschmod_7:
  8521 0000F2FE 29C0                <1> 	sub	eax, eax
  8522 0000F300 8A25[8A600100]      <1>         mov     ah, [DirBuff_DRV]
  8523 0000F306 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  8524 0000F30B 01C6                <1>         add     esi, eax
  8525 0000F30D 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
  8526 0000F311 7307                <1> 	jnc	short syschmod_8
  8527 0000F313 B01D                <1> 	mov	al, ERR_INV_DATA ; 29 = Invalid Data
  8528 0000F315 E96FFFFFFF          <1> 	jmp	syschmod_err
  8529                              <1> 
  8530                              <1> syschmod_8:
  8531                              <1> 	; BH = New MS-DOS File Attributes
  8532 0000F31A 88F8                <1> 	mov	al, bh ; File/Directory Attributes
  8533 0000F31C 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign	  
  8534 0000F31E E8F9A0FFFF          <1> 	call	change_fs_file_attributes
  8535 0000F323 0F8260FFFFFF        <1> 	jc	syschmod_err
  8536 0000F329 EBC0                <1> 	jmp	short syschmod_5
  8537                              <1> 
  8538                              <1> 
  8539                              <1> sysdrive: ; Get/Set Current (Working) Drive (for user)
  8540                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8541                              <1> 	;	
  8542                              <1>         ; INPUT ->
  8543                              <1>         ;          BL = Logical DOS Drive number (0=A: ... 2=C:)
  8544                              <1> 	;	   If BL = 0FFh -> Get Current Drive 	
  8545                              <1> 	; OUTPUT ->
  8546                              <1> 	;          cf = 0 -> 
  8547                              <1> 	;		   AL = Current Drive number	
  8548                              <1> 	;		   AH = The Last Logical DOS Drive no.
  8549                              <1> 	;          cf = 1 -> Error code in AL
  8550                              <1> 	;
  8551                              <1> 	; Modified Registers: EAX (at the return of system call)
  8552                              <1> 	;
  8553                              <1> 	; NOTE: If the requested logical dos drive is ready, 
  8554                              <1> 	;	it's current current directory will be the user's
  8555                              <1> 	;	(program's) current directory.
  8556                              <1> 	;	(When the program is terminated, MainProg -internal 
  8557                              <1> 	;	shell- will reset the previous -current- logical drive
  8558                              <1> 	;       as current drive again).	
  8559                              <1>   
  8560 0000F32B 80FBFF              <1> 	cmp	bl, 0FFh
  8561 0000F32E 7435                <1> 	je	short sysdrive_ok
  8562 0000F330 3A1D[3A0D0100]      <1> 	cmp	bl, [Last_DOS_DiskNo]
  8563 0000F336 771E                <1> 	ja	short sysdrive_err	
  8564                              <1> 
  8565                              <1> 	; Save current drive and reset mode
  8566                              <1> 	; for 'reset_working_path' procedure (for MainProg)
  8567 0000F338 30C0                <1> 	xor	al, al
  8568 0000F33A 66A3[58650100]      <1> 	mov	[SWP_Mode], ax ; ah = 0
  8569 0000F340 A0[6E590100]        <1> 	mov	al, [Current_Drv]
  8570 0000F345 FEC4                <1> 	inc	ah ; mov ah, 1
  8571 0000F347 66A3[5A650100]      <1> 	mov	[SWP_DRV], ax 
  8572                              <1> 
  8573 0000F34D 88DA                <1> 	mov	dl, bl
  8574 0000F34F E8C77BFFFF          <1> 	call	change_current_drive
  8575 0000F354 730F                <1> 	jnc	short sysdrive_ok
  8576                              <1> sysdrive_err:
  8577 0000F356 C705[64030300]0F00- <1> 	mov	dword [u.r0], ERR_DRV_NOT_RDY ; 'drive not ready !'
  8577 0000F35E 0000                <1>
  8578 0000F360 E9B4D3FFFF          <1> 	jmp	error
  8579                              <1> sysdrive_ok:
  8580 0000F365 A0[6E590100]        <1> 	mov	al, [Current_Drv]
  8581 0000F36A 8A25[3A0D0100]      <1> 	mov	ah, [Last_DOS_DiskNo]
  8582 0000F370 A3[64030300]        <1> 	mov	[u.r0], eax
  8583 0000F375 E9BFD3FFFF          <1> 	jmp	sysret
  8584                              <1> 
  8585                              <1> 
  8586                              <1> sysdir: ; Get Current (Working) Drive & Directory (for user)
  8587                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8588                              <1> 	;	
  8589                              <1>         ; INPUT ->
  8590                              <1>         ;          EBX = Current directory name buffer address
  8591                              <1> 	;		(Buffer length = 92 bytes)
  8592                              <1> 	; OUTPUT ->
  8593                              <1> 	;          AL = Current drive (0=A: .. 2=C:)
  8594                              <1> 	;	   If CF = 1 -> AL = error code
  8595                              <1> 	;
  8596                              <1> 	; Modified Registers: EAX (at the return of system call)
  8597                              <1> 	;
  8598                              <1> 	; Note: Required directory name buffer length may be 
  8599                              <1> 	;	<= 92 bytes for current TRDOS 386 version.
  8600                              <1> 	;	(7*12 name chars + 7 slash + 0)
  8601                              <1> 
  8602 0000F37A 89E5                <1> 	mov	ebp, esp
  8603 0000F37C 83EC60              <1> 	sub	esp, 96
  8604 0000F37F 53                  <1> 	push	ebx ; User's buffer address
  8605 0000F380 30D2                <1> 	xor	dl, dl ; 0 = current drive
  8606 0000F382 E890AAFFFF          <1>   	call	get_current_directory
  8607 0000F387 72CD                <1> 	jc	short sysdrive_err ; 'drive not ready !' error
  8608 0000F389 89E6                <1> 	mov	esi, esp ; System's buffer address
  8609 0000F38B 5F                  <1> 	pop	edi  ; User's buffer address
  8610                              <1> 	; ecx = transfer (byte) count (<=92)
  8611 0000F38C E843F4FFFF          <1> 	call	transfer_to_user_buffer
  8612 0000F391 89EC                <1> 	mov	esp, ebp
  8613 0000F393 730F                <1> 	jnc	short sysdir_ok
  8614                              <1> sysdir_err:
  8615 0000F395 C705[64030300]2E00- <1> 	mov	dword [u.r0], ERR_BUFFER  ; 'buffer error !'
  8615 0000F39D 0000                <1>
  8616 0000F39F E975D3FFFF          <1> 	jmp	error
  8617                              <1> sysdir_ok:	
  8618 0000F3A4 8A0D[6E590100]      <1> 	mov	cl, [Current_Drv]
  8619 0000F3AA 890D[64030300]      <1> 	mov	[u.r0], ecx
  8620 0000F3B0 E984D3FFFF          <1> 	jmp	sysret
  8621                              <1> 
  8622                              <1> 
  8623                              <1> sysldrvt: ; Get copy of Logical DOS Drive Description Table
  8624                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8625                              <1> 	;	
  8626                              <1>         ; INPUT ->
  8627                              <1> 	;	    BL = Logical DOS drive number (zero based)	
  8628                              <1>         ;          ECX = Logical DOS drv desc table buffer addr
  8629                              <1> 	;		(Buffer length = 256 bytes)
  8630                              <1> 	; OUTPUT ->
  8631                              <1> 	;          cf = 0 -> 
  8632                              <1> 	;		   AL = Current Drive number	
  8633                              <1> 	;		   AH = The Last Logical DOS Drive no.
  8634                              <1> 	;          cf = 1 -> Error code in AL
  8635                              <1> 	;		   AH = The Last Logical DOS Drive no.
  8636                              <1> 	;
  8637                              <1> 	; Modified Registers: EAX (at the return of system call)
  8638                              <1> 	;
  8639                              <1> 	; Note: Required description table buffer length is
  8640                              <1> 	;	256 bytes for current TRDOS 386 version.
  8641                              <1> 	
  8642 0000F3B5 89CF                <1> 	mov	edi, ecx ; Destination address (user space)
  8643 0000F3B7 88DC                <1> 	mov	ah, bl
  8644 0000F3B9 30C0                <1> 	xor	al, al
  8645 0000F3BB BE00010900          <1> 	mov	esi, Logical_DOSDisks
  8646 0000F3C0 01C6                <1> 	add	esi, eax ; Source address (system space)	 
  8647 0000F3C2 B900010000          <1> 	mov	ecx, 256 ; Byte count 
  8648                              <1> 			 ; Logical Dos Drv Desc Table size
  8649 0000F3C7 E808F4FFFF          <1> 	call	transfer_to_user_buffer
  8650 0000F3CC 72C7                <1> 	jc	short sysdir_err
  8651 0000F3CE 8A2D[3A0D0100]      <1> 	mov	ch, [Last_DOS_DiskNo]
  8652 0000F3D4 EBCE                <1> 	jmp	short sysdir_ok
  8653                              <1> 
  8654                              <1> 
  8655                              <1> systime: ; Get System Date&Time
  8656                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8657                              <1> 	;	
  8658                              <1>         ; INPUT -> BL =
  8659                              <1> 	;	    0 = Get Date&Time in Unix/Epoch format
  8660                              <1> 	;	    1 = Get Time in MSDOS format
  8661                              <1> 	;	    2 = Get Date in MSDOS format
  8662                              <1> 	;	    3 = Get Date&Time in MSDOS format
  8663                              <1> 	;	    4 & other values =
  8664                              <1> 	;		System timer ticks will be returned
  8665                              <1> 	;		in EAX and Carry Flag will be set.
  8666                              <1> 	;		(CF will not be set if BL = 4)	 	
  8667                              <1> 	; OUTPUT ->
  8668                              <1> 	;	For BL input = 3
  8669                              <1> 	;          EAX = Current Time (RTC)
  8670                              <1> 	;		AL = Second (DL in MSDOS)
  8671                              <1> 	;		AH = Minute (CL in MSDOS)
  8672                              <1> 	;	   	HW of EAX = Hour (CH in MSDOS)	
  8673                              <1> 	;	   EDX = Current System Date (RTC)
  8674                              <1> 	;		DL = Day (DL in MSDOS)
  8675                              <1> 	;		DH = Month (DH in MSDOS)
  8676                              <1> 	;		HW of EDX = Year (CX in MSDOS)	
  8677                              <1> 	;
  8678                              <1> 	;	For BL input = 2
  8679                              <1> 	;	   EAX = Current System Date (RTC)
  8680                              <1> 	;		DL = Day (DL in MSDOS)
  8681                              <1> 	;		DH = Month (DH in MSDOS)
  8682                              <1> 	;		HW of EDX = Year (CX in MSDOS)
  8683                              <1> 	;
  8684                              <1> 	;	For BL input = 1
  8685                              <1> 	;          EAX = Current Time (RTC)
  8686                              <1> 	;		AL = Second (DL in MSDOS)
  8687                              <1> 	;		AH = Minute (CL in MSDOS)
  8688                              <1> 	;	   	HW of EAX = Hour (CH in MSDOS)	
  8689                              <1> 	;
  8690                              <1> 	;	For BL input = 0
  8691                              <1> 	;          EAX = Unix (Epoch) Time Ticks/Seconds
  8692                              <1> 	;
  8693                              <1> 	;	For BL input  = 4
  8694                              <1> 	;	   EAX = System timer ticks
  8695                              <1> 	;
  8696                              <1> 	;	If CF = 1 (for other values of BL input)
  8697                              <1> 	;	   EAX = System timer ticks (no error code!)	
  8698                              <1> 	;		
  8699                              <1> 	; Modified Registers: EAX, (EDX)
  8700                              <1> 	;		 (at the return of system call)
  8701                              <1> 	;
  8702                              <1> 
  8703 0000F3D6 20DB                <1> 	and	bl, bl
  8704 0000F3D8 750F                <1> 	jnz	short systime_1
  8705 0000F3DA E82571FFFF          <1> 	call	epoch
  8706                              <1> systime_0:
  8707 0000F3DF A3[64030300]        <1> 	mov	[u.r0], eax
  8708 0000F3E4 E950D3FFFF          <1> 	jmp	sysret
  8709                              <1> systime_1:
  8710 0000F3E9 80FB04              <1> 	cmp	bl, 4
  8711 0000F3EC 7211                <1> 	jb	short systime_2
  8712 0000F3EE A1[28590100]        <1> 	mov	eax, [TIMER_LH] ; 18.2 Hz timer ticks
  8713                              <1> 				; Note: [TIMER_LH] may be set
  8714                              <1> 				; to wrong timer value due to
  8715                              <1> 				; program functions.
  8716                              <1> 				; (This value must not be
  8717                              <1> 				; accepted as [TIMER_LH]/18.2
  8718                              <1> 				; seconds since the midnight.)
  8719 0000F3F3 76EA                <1> 	jna	short systime_0
  8720 0000F3F5 A3[64030300]        <1> 	mov	[u.r0], eax	
  8721 0000F3FA E91AD3FFFF          <1> 	jmp	error ; cf = 1 & [u.r0] = eax = timer ticks 
  8722                              <1> 
  8723                              <1> systime_2:
  8724                              <1> 	;push	ebx
  8725 0000F3FF E86270FFFF          <1> 	call	get_rtc_date_time
  8726                              <1> 	;pop	ebx
  8727 0000F404 F6C301              <1> 	test	bl, 1
  8728 0000F407 7429                <1> 	jz	short systime_4
  8729 0000F409 30E4                <1> 	xor	ah, ah
  8730 0000F40B A0[9C550100]        <1> 	mov	al, [hour]
  8731 0000F410 88C2                <1> 	mov	dl, al
  8732 0000F412 C1E010              <1> 	shl	eax, 16
  8733 0000F415 A0[A0550100]        <1> 	mov	al, [second]
  8734 0000F41A 8A25[9E550100]      <1> 	mov	ah, [minute]
  8735 0000F420 F6C302              <1> 	test	bl, 2
  8736 0000F423 74BA                <1> 	jz	short systime_0
  8737                              <1> 	; Check time & date match risk 
  8738                              <1> 	; (23:59:59 may cause to wrong
  8739                              <1> 	; date -new day with previous date-...)
  8740 0000F425 80FA17              <1> 	cmp	dl, 23
  8741 0000F428 7206                <1> 	jb	short systime_3
  8742 0000F42A 663D3B3B            <1> 	cmp	ax, (59*256)+59 ; if hour is 23:59:59
  8743 0000F42E 73CF                <1> 	jnb	short systime_2 ; wait for 1 second
  8744                              <1> systime_3:
  8745                              <1> 	; eax = time
  8746 0000F430 89C6                <1> 	mov	esi, eax
  8747                              <1> systime_4:	
  8748 0000F432 66A1[96550100]      <1> 	mov	ax, [year]
  8749 0000F438 C1E010              <1> 	shl	eax, 16
  8750 0000F43B A0[9A550100]        <1> 	mov	al, [day]
  8751 0000F440 8A25[98550100]      <1> 	mov	ah, [month]
  8752                              <1> 	; eax = date
  8753 0000F446 80E301              <1> 	and	bl, 1
  8754 0000F449 7494                <1> 	jz	short systime_0
  8755 0000F44B 96                  <1> 	xchg	esi, eax
  8756                              <1> 	; eax = time, esi = date
  8757 0000F44C 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; EBP points to user's registers
  8758                              <1> 	; (user) edx <-- (system) esi
  8759 0000F452 897514              <1> 	mov	[ebp+20], esi ; return to user with EDX value 
  8760 0000F455 EB88                <1> 	jmp	short systime_0
  8761                              <1> 
  8762                              <1> 
  8763                              <1> sysstime: ; Set System Date&Time
  8764                              <1> 	; 31/12/2017
  8765                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8766                              <1> 	;	
  8767                              <1>         ; INPUT -> BL =
  8768                              <1> 	;	    0 = Set Date&Time in Unix/Epoch format
  8769                              <1> 	;	    1 = Set Time in MSDOS format
  8770                              <1> 	;	    2 = Set Date in MSDOS format
  8771                              <1> 	;	    3 = Set Date&Time in MSDOS format
  8772                              <1> 	;	    4 = Set System Timer (Ticks)
  8773                              <1> 	;	    5 = Convert/Save current time to/as
  8774                              <1> 	;		18.2 Hz system timer ticks
  8775                              <1> 	;	    6 = Convert MSDOS Date&Time to UNIX format
  8776                              <1> 	;		without setting system date&time ; (test)
  8777                              <1> 	;	    7 = Convert UNIX Date&Time to MSDOS format
  8778                              <1> 	;		without setting system date&time ; (test)
  8779                              <1> 	;	   8-0FFh = invalid !
  8780                              <1> 	;	  ECX = Time (or Timer) value in selected format  	
  8781                              <1> 	;	  EDX = Date value in MSDOS format if BL=2,3,6	
  8782                              <1> 	; 	
  8783                              <1> 	; OUTPUT ->
  8784                              <1> 	;	If CF = 0 ->
  8785                              <1> 	;          EAX = Set value
  8786                              <1> 	;	If CF = 1 -> (invalid BL input)
  8787                              <1> 	;	   EAX = Ticks count [TIMER_LH]	
  8788                              <1> 	;
  8789                              <1> 
  8790 0000F457 20DB                <1> 	and	bl, bl ; 0
  8791 0000F459 7511                <1> 	jnz	short sysstime_0
  8792 0000F45B 89C8                <1> 	mov	eax, ecx
  8793 0000F45D E82C71FFFF          <1> 	call	convert_from_epoch
  8794 0000F462 E8D871FFFF          <1> 	call	set_rtc_date_time
  8795 0000F467 E9CDD2FFFF          <1> 	jmp	sysret
  8796                              <1> sysstime_0:
  8797 0000F46C 80FB08              <1> 	cmp	bl, 8
  8798 0000F46F 722D                <1> 	jb	short sysstime_1
  8799                              <1> 	; invalid input (>7)
  8800 0000F471 A1[28590100]        <1> 	mov	eax, [TIMER_LH] ; 18.2 Hz timer ticks
  8801                              <1> 				; Note: [TIMER_LH] may be set
  8802                              <1> 				; to wrong timer value due to
  8803                              <1> 				; program functions.
  8804                              <1> 				; (This value must not be
  8805                              <1> 				; accepted as [TIMER_LH]/18.2
  8806                              <1> 				; seconds since the midnight.)
  8807 0000F476 A3[64030300]        <1> 	mov	[u.r0], eax	
  8808 0000F47B E999D2FFFF          <1> 	jmp	error ; cf = 1 & [u.r0] = eax = timer ticks 
  8809                              <1> 
  8810                              <1> sysstime_8:	
  8811                              <1> 	; BL = 7
  8812 0000F480 89C8                <1> 	mov	eax, ecx ; seconds since 1/1/1970 00:00:00
  8813 0000F482 E80771FFFF          <1> 	call	convert_from_epoch
  8814 0000F487 30E4                <1> 	xor	ah, ah
  8815 0000F489 A0[9C550100]        <1> 	mov	al, [hour]
  8816 0000F48E C1E010              <1> 	shl	eax, 16
  8817 0000F491 A0[A0550100]        <1> 	mov	al, [second]
  8818 0000F496 8A25[9E550100]      <1> 	mov	ah, [minute]
  8819 0000F49C EB92                <1> 	jmp	short systime_3
  8820                              <1> 
  8821                              <1> sysstime_1:
  8822 0000F49E 80FB04              <1> 	cmp	bl, 4
  8823 0000F4A1 743F                <1> 	je	short sysstime_2 ; set system timer ticks	
  8824 0000F4A3 80FB05              <1> 	cmp	bl, 5
  8825 0000F4A6 754B                <1> 	jne	short sysstime_4
  8826                              <1> 	; convert current time to system timer ticks (18.2Hz)
  8827 0000F4A8 E8B96FFFFF          <1> 	call	get_rtc_date_time
  8828 0000F4AD 0FB60D[9C550100]    <1> 	movzx	ecx, byte [hour]
  8829 0000F4B4 B8100E0000          <1> 	mov	eax, 60*60 ; 1 hour = 3600 seconds
  8830 0000F4B9 F7E1                <1> 	mul	ecx
  8831 0000F4BB 89C3                <1> 	mov	ebx, eax	
  8832 0000F4BD B13C                <1> 	mov	cl, 60  ; 1 minute = 60 seconds
  8833 0000F4BF 0FB605[9E550100]    <1> 	movzx	eax, byte [minute]
  8834 0000F4C6 F7E1                <1> 	mul	ecx
  8835 0000F4C8 01D8                <1> 	add	eax, ebx  
  8836 0000F4CA 8A0D[A0550100]      <1> 	mov	cl, [second]
  8837 0000F4D0 01C8                <1> 	add	eax, ecx
  8838 0000F4D2 B1B6                <1> 	mov	cl, 182
  8839 0000F4D4 F7E1                <1> 	mul	ecx
  8840 0000F4D6 83C009              <1> 	add	eax, 9
  8841 0000F4D9 83D200              <1> 	adc	edx, 0
  8842 0000F4DC B10A                <1> 	mov	cl, 10
  8843 0000F4DE F7F1                <1> 	div	ecx
  8844                              <1> 	; eax = ((182*seconds)+9)/10
  8845 0000F4E0 89C1                <1> 	mov	ecx, eax
  8846                              <1> sysstime_2:
  8847 0000F4E2 890D[28590100]      <1> 	mov	[TIMER_LH], ecx ; 18.2 * seconds
  8848                              <1> sysstime_3:
  8849 0000F4E8 890D[64030300]      <1> 	mov	[u.r0], ecx
  8850 0000F4EE E946D2FFFF          <1> 	jmp	sysret
  8851                              <1> sysstime_4:
  8852 0000F4F3 80FB06              <1> 	cmp	bl, 6
  8853 0000F4F6 7788                <1> 	ja	short sysstime_8
  8854                              <1> 
  8855 0000F4F8 890D[64030300]      <1> 	mov	[u.r0], ecx
  8856                              <1> 
  8857 0000F4FE 880D[A0550100]      <1> 	mov	[second], cl
  8858 0000F504 882D[9E550100]      <1> 	mov	[minute], ch
  8859 0000F50A C1E910              <1> 	shr	ecx, 16
  8860 0000F50D 880D[9C550100]      <1> 	mov	[hour], cl
  8861                              <1> 	; BL = 1,2,3,6
  8862 0000F513 80FB01              <1> 	cmp	bl, 1
  8863 0000F516 762A                <1> 	jna	short sysstime_5
  8864                              <1> 	; BL = 2,3,6
  8865 0000F518 8815[9A550100]      <1> 	mov	[day], dl
  8866 0000F51E 8835[98550100]      <1> 	mov	[month], dh
  8867 0000F524 C1EA10              <1> 	shr	edx, 16
  8868 0000F527 668915[96550100]    <1> 	mov	[year], dx
  8869 0000F52E 80E303              <1> 	and	bl, 3
  8870 0000F531 742D                <1> 	jz	short sysstime_7 ; 6
  8871                              <1> 	; BL = 2,3
  8872 0000F533 F6C301              <1> 	test	bl, 1
  8873 0000F536 7419                <1> 	jz	short sysstime_6 ; 2
  8874                              <1> 	; BL = 3
  8875 0000F538 E80271FFFF          <1> 	call	set_rtc_date_time
  8876 0000F53D E9F7D1FFFF          <1> 	jmp	sysret
  8877                              <1> sysstime_5:
  8878                              <1> 	; BL = 1
  8879 0000F542 E83971FFFF          <1> 	call	set_time_bcd
  8880 0000F547 E80365FFFF          <1> 	call	set_rtc_time
  8881 0000F54C E9E8D1FFFF          <1> 	jmp	sysret	
  8882                              <1> sysstime_6:
  8883                              <1> 	; BL = 2
  8884 0000F551 E8FD70FFFF          <1> 	call	set_date_bcd
  8885 0000F556 E86365FFFF          <1> 	call	set_rtc_date
  8886 0000F55B E9D9D1FFFF          <1> 	jmp	sysret
  8887                              <1> sysstime_7:
  8888                              <1> 	; BL = 6
  8889                              <1> 	; [year], [month], [day], 
  8890                              <1> 	; [hour], [minute], [second]
  8891 0000F560 E8A46FFFFF          <1> 	call	convert_to_epoch
  8892 0000F565 89C1                <1> 	mov	ecx, eax ; seconds since 1/1/1970 00:00:00
  8893 0000F567 E97CFFFFFF          <1> 	jmp	sysstime_3
  8894                              <1> 
  8895                              <1> sysrename: ; Rename File (or Directory)
  8896                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
  8897                              <1> 	;	
  8898                              <1>         ; INPUT ->
  8899                              <1>         ;          EBX = File/Directory (ASCIIZ) name address
  8900                              <1> 	;	   ECX = New name (in same dir, no path name)			
  8901                              <1> 	; OUTPUT ->
  8902                              <1> 	;          cf = 0 -> EAX = 0
  8903                              <1> 	;          cf = 1 -> Error code in AL
  8904                              <1> 
  8905 0000F56C 803D[B3030300]00    <1> 	cmp	byte [u.uno], 0  ; root (super user) ?
  8906 0000F573 7614                <1> 	jna	short sysrename_0
  8907                              <1> 
  8908                              <1> sysrename_perm_err:
  8909                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
  8910 0000F575 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; 'permission denied !'
  8911 0000F57A A3[64030300]        <1> 	mov	[u.r0], eax
  8912 0000F57F A3[C8030300]        <1> 	mov	[u.error], eax
  8913 0000F584 E990D1FFFF          <1> 	jmp	error
  8914                              <1> 
  8915                              <1> sysrename_0:
  8916 0000F589 51                  <1> 	push	ecx ; new file name address (in user space)
  8917 0000F58A 89DE                <1> 	mov	esi, ebx
  8918                              <1> 	; file name is forced, change directory as temporary
  8919                              <1> 	;mov	ax, 1
  8920                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
  8921                              <1> 	;call	set_working_path 
  8922 0000F58C E8C5060000          <1> 	call	set_working_path_x
  8923 0000F591 731E                <1> 	jnc	short sysrename_1
  8924 0000F593 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!  
  8925 0000F595 7505                <1> 	jnz	short sysrename_err
  8926                              <1> 	; eax = 0
  8927                              <1> sysrename_path_not_found:
  8928 0000F597 B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'Bad path name !'
  8929                              <1> sysrename_err:
  8930 0000F59C 59                  <1> 	pop	ecx ; new file name address (in user space)
  8931                              <1> sysrename_error:
  8932 0000F59D A3[64030300]        <1> 	mov	[u.r0], eax
  8933 0000F5A2 A3[C8030300]        <1> 	mov	[u.error], eax
  8934 0000F5A7 E87F070000          <1> 	call 	reset_working_path
  8935 0000F5AC E968D1FFFF          <1> 	jmp	error
  8936                              <1> sysrename_1:
  8937 0000F5B1 B008                <1> 	mov	al, 08h ; Except volume labels (& long names)
  8938 0000F5B3 A0[1C630100]        <1> 	mov	al, [Attributes]
  8939 0000F5B8 2410                <1> 	and	al, 10h ;
  8940                              <1> 	;mov	esi, FindFile_Name
  8941                              <1> 	;mov	ax, 1800h ; Only files
  8942                              <1> 	;mov	ax, 0810h ; Only directories
  8943 0000F5BA 66B80008            <1> 	mov	ax, 0800h ; Find File or Directory
  8944 0000F5BE E8FB8CFFFF          <1> 	call	find_first_file
  8945                              <1> 	;jnc	short sysrename_2
  8946 0000F5C3 72D7                <1> 	jc	short sysrename_err
  8947                              <1> sysrename_2:
  8948                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  8949                              <1> 	; EDI = Directory Buffer Directory Entry Location
  8950                              <1> 	; EAX = File Size
  8951                              <1> 	;  BL = Attributes of The File/Directory
  8952                              <1> 	;  BH = Long Name Yes/No Status (>0 is YES)
  8953                              <1> 	;  DX > 0 : Ambiguous filename chars are used
  8954                              <1> 
  8955 0000F5C5 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  8956 0000F5C8 7407                <1> 	jz	short sysrename_3
  8957 0000F5CA B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 'invalid file name !'
  8958 0000F5CF EBCB                <1>         jmp	short sysrename_err
  8959                              <1> sysrename_3:
  8960                              <1> 	; EDI = Directory buffer entry offset/address
  8961                              <1> 	; BL = File (or Directory) Attributes 
  8962                              <1> 	; mov	bl, [EDI+0Bh]
  8963                              <1> 
  8964 0000F5D1 5A                  <1> 	pop	edx ; new file name address (in user space)
  8965                              <1> 
  8966                              <1> 	; check file/directory attributes
  8967 0000F5D2 F6C307              <1> 	test	bl, 7 ; system, hidden, readonly 
  8968 0000F5D5 759E                <1>         jnz	short sysrename_perm_err
  8969                              <1> sysrename_4:
  8970 0000F5D7 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
  8971 0000F5DD 7496                <1> 	je	short sysrename_perm_err ; -temporary!-
  8972                              <1> 
  8973                              <1> 	; save old file name & file info (FFF structure)
  8974 0000F5DF BE[06620100]        <1> 	mov	esi, FindFile_Drv
  8975 0000F5E4 BF[4C630100]        <1> 	mov	edi, SourceFile_Drv
  8976 0000F5E9 B920000000          <1> 	mov	ecx, 128/4
  8977 0000F5EE F3A5                <1> 	rep	movsd
  8978                              <1> 
  8979 0000F5F0 89D6                <1> 	mov	esi, edx ; new file name address (in user space)
  8980 0000F5F2 BF[CC630100]        <1> 	mov	edi, DestinationFile_Drv
  8981 0000F5F7 E893AEFFFF          <1> 	call	parse_path_name
  8982 0000F5FC 729F                <1> 	jc	short sysrename_error ; eax = 1 (Bad file name)
  8983                              <1> 
  8984                              <1> 	; same drive ? 
  8985 0000F5FE A0[06620100]        <1> 	mov	al, [FindFile_Drv]
  8986 0000F603 3A05[CC630100]      <1> 	cmp	al, [DestinationFile_Drv]
  8987                              <1> 	;jne	short sysrename_perm_err ; Permission denied
  8988 0000F609 7509                <1> 	jne	short sysrename_5 ; Bad file name
  8989                              <1>  
  8990                              <1> 	; no path name !? (rename file in same directory)
  8991 0000F60B 803D[CD630100]20    <1> 	cmp	byte [DestinationFile_Directory], 20h
  8992 0000F612 7607                <1> 	jna	short sysrename_6
  8993                              <1> sysrename_5:
  8994 0000F614 B801000000          <1> 	mov	eax, ERR_BAD_CMD_ARG ; 1 = Bad file name 
  8995                              <1> 				     ; (Bad argument)
  8996 0000F619 EB82                <1> 	jmp	short sysrename_error
  8997                              <1> sysrename_6:
  8998 0000F61B 803D[0E640100]20    <1> 	cmp	byte [DestinationFile_Name], 20h
  8999 0000F622 76F0                <1> 	jna	short sysrename_5
  9000                              <1> 
  9001 0000F624 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name
  9002 0000F629 E84E90FFFF          <1> 	call	check_filename ; is it a valid msdos file name?
  9003 0000F62E 0F8269FFFFFF        <1> 	jc	sysrename_error ; 26 = ERR_INV_FILE_NAME 
  9004                              <1> 	
  9005                              <1> 	;mov	esi, DestinationFile_Name
  9006 0000F634 66B80008            <1> 	mov	ax, 0800h ; Find File or Directory
  9007 0000F638 E8818CFFFF          <1> 	call	find_first_file
  9008 0000F63D 720A                <1> 	jc	short sysrename_7
  9009                              <1> 	
  9010 0000F63F B80E000000          <1> 	mov	eax, ERR_FILE_EXISTS  ; file already exists !
  9011 0000F644 E954FFFFFF          <1> 	jmp	sysrename_error	
  9012                              <1> sysrename_7:
  9013                              <1> 	; eax = 2 (File not found !)
  9014 0000F649 3C02                <1> 	cmp	al, 2 ; ERR_NOT_FOUND
  9015 0000F64B 0F854CFFFFFF        <1> 	jne	sysrename_error
  9016                              <1> 
  9017                              <1> 	; 31/12/2017
  9018                              <1> 	; Following code is also part of 'rename_file' in
  9019                              <1> 	; 'trdosk3.s' (MainProg's 'rename' command) ; 13/11/2017
  9020 0000F651 BE[0E640100]        <1> 	mov	esi, DestinationFile_Name ; (Rename_NewName)
  9021 0000F656 668B0D[C6630100]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
  9022 0000F65D 66A1[B2630100]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
  9023 0000F663 C1E010              <1> 	shl	eax, 16
  9024 0000F666 66A1[B8630100]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
  9025 0000F66C 0FB61D[9B630100]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]  
  9026 0000F673 E85FB6FFFF          <1>    	call	rename_directory_entry
  9027 0000F678 0F821FFFFFFF        <1> 	jc	sysrename_error
  9028                              <1> 	;xor	eax, eax
  9029 0000F67E A3[64030300]        <1> 	mov	[u.r0], eax ; 0
  9030                              <1> 	;mov	[u.error], eax
  9031 0000F683 E8A3060000          <1> 	call 	reset_working_path
  9032 0000F688 E9ACD0FFFF          <1> 	jmp	sysret
  9033                              <1> 
  9034                              <1> sysmem: ; Get Total&Free Memory amount 
  9035                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
  9036                              <1> 	;	
  9037                              <1>         ; INPUT -> 
  9038                              <1> 	;	none	
  9039                              <1> 	; OUTPUT ->
  9040                              <1> 	;	EAX = Total memory count (in bytes)
  9041                              <1> 	;	EBX = Virtually available memory amount (in bytes)
  9042                              <1> 	;	      = 4GB - CORE (4MB)	
  9043                              <1> 	;	ECX = Free memory count (in bytes)
  9044                              <1> 	;	EDX = Calculated free memory count (in bytes)
  9045                              <1> 	
  9046 0000F68D A1[AC580100]        <1> 	mov	eax, [memory_size] ; in pages
  9047 0000F692 C1E00C              <1> 	shl	eax, 12		   ; in bytes
  9048 0000F695 A3[64030300]        <1> 	mov	[u.r0], eax
  9049 0000F69A E8D93CFFFF          <1> 	call	calc_free_mem
  9050                              <1> 	; edx = calculated free pages
  9051                              <1> 	; ecx = 0
  9052 0000F69F 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; EBP points to user's registers
  9053 0000F6A5 C745100000C0FF      <1> 	mov	dword [ebp+16], ECORE ; EBX (for user)
  9054                              <1> 				; 0FFC00000h ; 4GB - 4MB
  9055 0000F6AC C1E20C              <1> 	shl	edx, 12
  9056 0000F6AF 895514              <1> 	mov	[ebp+20], edx ; EDX (for user)
  9057 0000F6B2 8B0D[B0580100]      <1> 	mov 	ecx, [free_pages]
  9058 0000F6B8 C1E10C              <1> 	shl	ecx, 12	; free bytes
  9059 0000F6BB 894D18              <1> 	mov	[ebp+24], ecx ; ECX (for user)
  9060                              <1> 	;mov	[free_pages], edx	
  9061 0000F6BE E976D0FFFF          <1> 	jmp	sysret
  9062                              <1> 
  9063                              <1> sysprompt:
  9064                              <1> 	; Set TRDOS 386 Command Interpreter (MainProg) prompt 
  9065                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
  9066                              <1> 	;	
  9067                              <1>         ; INPUT -> 
  9068                              <1> 	;	EBX = 0 -> use default prompt
  9069                              <1> 	;	EBX > 0 -> prompt string (ASCIIZ) address
  9070                              <1> 	;		  (Max. 11 characters except ZERO tail)	
  9071                              <1> 	; OUTPUT ->
  9072                              <1> 	;	(EAX = 0)
  9073                              <1> 	;	CF = 0 -> Successful
  9074                              <1> 	;	CF = 1 -> Failed
  9075                              <1> 
  9076 0000F6C3 21DB                <1> 	and	ebx, ebx
  9077 0000F6C5 750A                <1> 	jnz	short sysprompt_0
  9078                              <1> 
  9079 0000F6C7 E8F685FFFF          <1> 	call	default_command_prompt ; '['+'TRDOS'+']'
  9080 0000F6CC E968D0FFFF          <1> 	jmp	sysret
  9081                              <1> 
  9082                              <1> sysprompt_0:
  9083 0000F6D1 31C0                <1> 	xor	eax, eax
  9084 0000F6D3 A3[64030300]        <1> 	mov	[u.r0], eax 
  9085 0000F6D8 89DE                <1> 	mov	esi, ebx
  9086 0000F6DA B90C000000          <1> 	mov	ecx, 12
  9087 0000F6DF 89E5                <1> 	mov	ebp, esp
  9088 0000F6E1 29CC                <1> 	sub	esp, ecx
  9089 0000F6E3 49                  <1> 	dec	ecx ; 11
  9090 0000F6E4 89E7                <1> 	mov	edi, esp
  9091 0000F6E6 E833F1FFFF          <1> 	call	transfer_from_user_buffer
  9092 0000F6EB 7211                <1> 	jc	short sysprompt_err
  9093 0000F6ED 803E20              <1> 	cmp	byte [esi], 20h
  9094 0000F6F0 760C                <1> 	jna	short sysprompt_err
  9095 0000F6F2 E8DD85FFFF          <1> 	call	set_command_prompt
  9096 0000F6F7 89EC                <1> 	mov	esp, ebp
  9097 0000F6F9 E93BD0FFFF          <1> 	jmp	sysret
  9098                              <1> sysprompt_err:
  9099                              <1> syspath_err:
  9100 0000F6FE 89EC                <1> 	mov	esp, ebp
  9101 0000F700 E914D0FFFF          <1> 	jmp	error
  9102                              <1> 
  9103                              <1> syspath:
  9104                              <1> 	; Get/Set Run Path
  9105                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
  9106                              <1> 	;	
  9107                              <1>         ; INPUT -> 
  9108                              <1> 	;	EBX = 0 -> get path (to buffer address in ECX)
  9109                              <1> 	;	EBX > 0 -> set path
  9110                              <1> 	;	    EBX = Path string buffer address (ASCIIZ)
  9111                              <1> 	;	    	  (Path description except 'PATH=')
  9112                              <1> 	;	ECX = Buffer address (if EBX = 0)
  9113                              <1> 	;	      (ECX will not be used if EBX > 0)	
  9114                              <1> 	;	DL = Buffer size (0 = 256 byte)	
  9115                              <1> 	;
  9116                              <1> 	; OUTPUT ->
  9117                              <1> 	;	CF = 0 -> Successful (EAX = String length)
  9118                              <1> 	;	CF = 1 -> Failed (EAX = 0)
  9119                              <1> 	;
  9120                              <1> 	; NOTE: 'PATH=' or 'PATH' must be excluded
  9121                              <1> 	;  (It must not be at the beginning of the string.)
  9122                              <1> 
  9123 0000F705 89E5                <1> 	mov	ebp, esp
  9124 0000F707 81EC00010000        <1> 	sub	esp, 256
  9125 0000F70D 89E7                <1> 	mov	edi, esp
  9126                              <1> 
  9127 0000F70F 31C0                <1> 	xor	eax, eax
  9128 0000F711 A3[64030300]        <1> 	mov	[u.r0], eax 
  9129                              <1> 	
  9130 0000F716 21DB                <1> 	and	ebx, ebx
  9131 0000F718 752E                <1> 	jnz	short syspath_0
  9132                              <1> 
  9133                              <1> 	; EBX = 0 -> get run path
  9134 0000F71A 89CB                <1> 	mov	ebx, ecx ; buffer addr (in user's mem space)
  9135 0000F71C BE[070E0100]        <1> 	mov	esi, Cmd_Path  ; 'PATH' address
  9136 0000F721 0FB6CA              <1> 	movzx	ecx, dl
  9137 0000F724 80E901              <1> 	sub	cl, 1 ; 0 -> 255, 1 -> 0
  9138 0000F727 6683D101            <1> 	adc	cx, 1 ; 255 -> 256, 0 -> 1
  9139                              <1> 	; EDI = Output buffer 
  9140                              <1> 	; CX = Buffer length
  9141                              <1> 	; AL = 0 -> use ASCIIZ word in [ESI]
  9142                              <1> 	; ESI = 'PATH' address (with zero tail)
  9143 0000F72B E8D89DFFFF          <1> 	call	get_environment_string
  9144 0000F730 72CC                <1> 	jc	short syspath_err
  9145 0000F732 89DF                <1> 	mov	edi, ebx ; User's buffer address
  9146 0000F734 89E6                <1> 	mov	esi, esp 
  9147                              <1> 	; EDI = User's buffer address
  9148                              <1> 	; ECX = transfer (byte) count
  9149 0000F736 E899F0FFFF          <1> 	call	transfer_to_user_buffer
  9150 0000F73B 72C1                <1> 	jc	short syspath_err
  9151 0000F73D 890D[64030300]      <1> 	mov	[u.r0], ecx 
  9152 0000F743 E9F1CFFFFF          <1> 	jmp	sysret
  9153                              <1> 
  9154                              <1> syspath_0:
  9155 0000F748 89DE                <1> 	mov	esi, ebx
  9156 0000F74A 0FB6CA              <1> 	movzx	ecx, dl
  9157 0000F74D 80E901              <1> 	sub	cl, 1 ; 0 -> 255, 1 -> 0
  9158 0000F750 6683D101            <1> 	adc	cx, 1 ; 255 -> 256, 0 -> 1
  9159 0000F754 E8C5F0FFFF          <1> 	call	transfer_from_user_buffer
  9160 0000F759 72A3                <1> 	jc	short syspath_err
  9161                              <1> 	;(*) 'PATH=' will be added to 
  9162                              <1> 	;         the head of the string
  9163 0000F75B 83EC08              <1> 	sub	esp, 8 ;(*)
  9164 0000F75E 89FE                <1> 	mov	esi, edi ;(*)
  9165 0000F760 E8879DFFFF          <1> 	call	set_path_x ;(*)
  9166 0000F765 7297                <1> 	jc	short syspath_err
  9167 0000F767 8915[64030300]      <1> 	mov	[u.r0], edx ; run path string length
  9168 0000F76D E9C7CFFFFF          <1> 	jmp	sysret	
  9169                              <1> 
  9170                              <1> sysenv:
  9171                              <1> 	; Get/Set Environment Variables
  9172                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
  9173                              <1> 	;	
  9174                              <1>         ; INPUT -> 
  9175                              <1> 	;	EBX = 0 -> get (all) environment variables
  9176                              <1> 	;	      (Required Buffer length = 512 bytes)
  9177                              <1> 	;	EBX > 0 -> set (one) environment variable
  9178                              <1> 	;	      (If there is not a '=' after
  9179                              <1> 	;	      the environment variable name, it will
  9180                              <1> 	;	      accepted as 'get environment variable'.) 
  9181                              <1> 	;	       EBX = Buffer address
  9182                              <1> 	;	ECX = Buffer address (if EBX = 0)
  9183                              <1> 	;	      (ECX will not be used if EBX > 0)	
  9184                              <1> 	;	      (Note: Buffer size is 512 bytes.)	
  9185                              <1> 	;	DL = Buffer size (0 = 256 byte)
  9186                              <1> 	;	     (For one envrionment variable)		
  9187                              <1> 	;
  9188                              <1> 	; OUTPUT ->
  9189                              <1> 	;	(EAX = 0)
  9190                              <1> 	;	CF = 0 -> Successful (EAX = String length)
  9191                              <1> 	;	CF = 1 -> Failed (EAX = 0)
  9192                              <1> 	;
  9193                              <1> 	; Note: Environment variable name, for example,
  9194                              <1> 	;	'PATH=' must be included at the beginning
  9195                              <1> 	;	of the environment string. If the variable
  9196                              <1> 	;	name is as 'PATH' but it is not as 'PATH='
  9197                              <1> 	;	the variable string (row) will be returned.
  9198                              <1> 	;	If variable name is as 'PATH=' but there is
  9199                              <1> 	;	not a following text after the variable name,
  9200                              <1> 	;	the environment variable will be reset/deleted.
  9201                              <1> 
  9202 0000F772 89E5                <1> 	mov	ebp, esp
  9203 0000F774 81EC00020000        <1> 	sub	esp, 512
  9204 0000F77A 89E7                <1> 	mov	edi, esp
  9205                              <1> 
  9206 0000F77C 31C0                <1> 	xor	eax, eax
  9207 0000F77E A3[64030300]        <1> 	mov	[u.r0], eax 
  9208                              <1> 	
  9209 0000F783 21DB                <1> 	and	ebx, ebx
  9210 0000F785 7524                <1> 	jnz	short sysenv_0
  9211                              <1> 
  9212                              <1> 	; EBX = 0 -> get (all) environment variables
  9213 0000F787 89EC                <1> 	mov	esp, ebp
  9214 0000F789 BE00300900          <1> 	mov	esi, Env_Page  ; Environment page
  9215 0000F78E 89CF                <1> 	mov	edi, ecx ; buffer addr (in user's mem space)
  9216 0000F790 B900020000          <1> 	mov	ecx, 512
  9217 0000F795 E83AF0FFFF          <1> 	call	transfer_to_user_buffer
  9218 0000F79A 0F8279CFFFFF        <1> 	jc	error
  9219 0000F7A0 890D[64030300]      <1> 	mov	[u.r0], ecx 
  9220 0000F7A6 E98ECFFFFF          <1> 	jmp	sysret
  9221                              <1> 
  9222                              <1> sysenv_0:
  9223 0000F7AB 89DE                <1> 	mov	esi, ebx ; * ; user's buffer address
  9224 0000F7AD 0FB6CA              <1> 	movzx	ecx, dl
  9225 0000F7B0 80E901              <1> 	sub	cl, 1 ; 0 -> 255, 1 -> 0
  9226 0000F7B3 6683D101            <1> 	adc	cx, 1 ; 255 -> 256, 0 -> 1
  9227 0000F7B7 E862F0FFFF          <1> 	call	transfer_from_user_buffer
  9228 0000F7BC 723F                <1> 	jc	short sysenv_err
  9229 0000F7BE 89FE                <1> 	mov	esi, edi
  9230 0000F7C0 8A06                <1> 	mov	al, [esi]
  9231 0000F7C2 3C20                <1> 	cmp	al, 20h
  9232 0000F7C4 7637                <1> 	jna	short sysenv_err
  9233 0000F7C6 3C3D                <1> 	cmp	al, '='
  9234 0000F7C8 7433                <1> 	je	short sysenv_err
  9235 0000F7CA 56                  <1> 	push	esi
  9236                              <1> sysenv_1:
  9237 0000F7CB 46                  <1> 	inc	esi
  9238 0000F7CC 803E3D              <1> 	cmp	byte [esi], '='
  9239 0000F7CF 7433                <1> 	je	short sysenv_3
  9240 0000F7D1 803E20              <1> 	cmp	byte [esi], 20h
  9241 0000F7D4 73F5                <1> 	jnb	short sysenv_1
  9242 0000F7D6 C60600              <1> 	mov	byte [esi], 0 
  9243 0000F7D9 5E                  <1> 	pop	esi
  9244                              <1> 	; EDI = Output buffer 
  9245                              <1> 	; CX = Buffer length
  9246 0000F7DA 30C0                <1> 	xor	al, al
  9247                              <1> 	; AL = 0 -> use ASCIIZ word in [ESI]
  9248                              <1> 	; ESI = Environment variable name address
  9249 0000F7DC E8279DFFFF          <1> 	call	get_environment_string
  9250 0000F7E1 721A                <1> 	jc	short sysenv_err
  9251 0000F7E3 89DF                <1> 	mov	edi, ebx ; * ; user's buffer address
  9252 0000F7E5 89C1                <1> 	mov	ecx, eax ; String length
  9253 0000F7E7 89E6                <1> 	mov	esi, esp 
  9254                              <1> 	; ESI = system buffer address
  9255                              <1> 	; EDI = User's buffer address
  9256                              <1> 	; ECX = transfer (byte) count
  9257 0000F7E9 E8E6EFFFFF          <1> 	call	transfer_to_user_buffer
  9258 0000F7EE 720D                <1> 	jc	short sysenv_err
  9259 0000F7F0 890D[64030300]      <1> 	mov	[u.r0], ecx ; transfer (byte) count
  9260                              <1> sysenv_2:
  9261 0000F7F6 89EC                <1> 	mov	esp, ebp
  9262 0000F7F8 E93CCFFFFF          <1> 	jmp	sysret
  9263                              <1> sysenv_err:
  9264 0000F7FD 89EC                <1> 	mov	esp, ebp
  9265 0000F7FF E915CFFFFF          <1> 	jmp	error
  9266                              <1> sysenv_3:
  9267 0000F804 46                  <1> 	inc	esi
  9268 0000F805 803E20              <1> 	cmp	byte [esi], 20h
  9269 0000F808 73FA                <1> 	jnb	short sysenv_3
  9270 0000F80A C60600              <1> 	mov	byte [esi], 0	
  9271 0000F80D 5E                  <1> 	pop	esi
  9272 0000F80E E8B89DFFFF          <1> 	call	set_environment_string
  9273 0000F813 72E8                <1> 	jc	short sysenv_err
  9274 0000F815 8915[64030300]      <1> 	mov	[u.r0], edx
  9275 0000F81B EBD9                <1> 	jmp	short sysenv_2
  9276                              <1> 
  9277                              <1> 
  9278                              <1> ; temporary - 24/01/2016
  9279                              <1> 
  9280                              <1> iget:
  9281 0000F81D C3                  <1> 	retn
  9282                              <1> isintr:
  9283 0000F81E C3                  <1> 	retn
  9284                              <1> iopen:
  9285 0000F81F C3                  <1> 	retn
  9286                              <1> iclose:
  9287 0000F820 C3                  <1> 	retn
  9288                              <1> sndc:
  9289 0000F821 C3                  <1> 	retn
  9290                              <1> access:
  9291 0000F822 C3                  <1> 	retn
  9292                              <1> sleep:
  9293 0000F823 C3                  <1> 	retn
  2311                                  %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 0000F824 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    20 0000F828 777B                <1>         ja      short lba_write
    21                              <1> 
    22                              <1> chs_write:
    23                              <1> 	; 25/02/2016
    24                              <1> 	; 23/02/2016
    25 0000F82A C605[55610100]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
    26 0000F831 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 0000F833 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    47 0000F837 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 0000F839 C605[55610100]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 0000F840 C605[56610100]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 0000F847 50                  <1> 	push	eax			; Linear sector #
    80 0000F848 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
    81                              <1>                 
    82 0000F849 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
    83                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
    84 0000F84D 29D2                <1> 	sub	edx, edx
    85 0000F84F 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 0000F851 6689D1              <1> 	mov	cx, dx			; Sector (zero based)
    90 0000F854 6641                <1> 	inc	cx			; To make it 1 based
    91 0000F856 6651                <1> 	push	cx
    92 0000F858 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
    93 0000F85C 6629D2              <1> 	sub	dx, dx
    94 0000F85F F7F1                <1> 	div	ecx			; Convert track to head & cyl
    95                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
    96 0000F861 88D6                <1> 	mov	dh, dl
    97 0000F863 6659                <1> 	pop	cx			; AX=Cyl, DH=Head, CX=Sector
    98 0000F865 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
    99                              <1> 
   100 0000F868 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !                   
   101 0000F86A C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
   102 0000F86D 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 0000F86F B001                <1> 	mov	al, 1 ; 25/02/2016
   113 0000F871 8A25[55610100]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
   114                              <1> 	;
   115 0000F877 E8BB49FFFF          <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 0000F87C 8825[57610100]      <1> 	mov	[disk_rw_err], ah
   122                              <1> 	
   123 0000F882 59                  <1> 	pop	ecx
   124 0000F883 58                  <1> 	pop	eax
   125 0000F884 7314                <1> 	jnc	short chs_read_ok
   126                              <1> 
   127 0000F886 803D[57610100]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
   128 0000F88D 7408                <1> 	je	short chs_read_error_retn
   129                              <1>              
   130 0000F88F FE0D[56610100]      <1> 	dec	byte [retry_count]
   131 0000F895 75B0                <1> 	jnz	short chs_read_retry
   132                              <1> 
   133                              <1> chs_read_error_retn:
   134 0000F897 F9                  <1> 	stc
   135                              <1> 	;retn
   136 0000F898 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 0000F89A 40                  <1> 	inc	eax ; next sector
   154 0000F89B 81C300020000        <1> 	add	ebx, 512
   155 0000F8A1 E29D                <1> 	loop	chs_read_next_sector
   156 0000F8A3 EB5E                <1> 	jmp	short update_drv_error_byte
   157                              <1> 
   158                              <1> lba_write:
   159                              <1> 	; 23/02/2016
   160 0000F8A5 C605[55610100]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
   161 0000F8AC 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 0000F8AE C605[55610100]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
   185                              <1> 
   186                              <1> lba_rw:
   187                              <1> 	; 17/02/2016
   188 0000F8B5 57                  <1> 	push	edi
   189                              <1> 
   190 0000F8B6 890D[58610100]      <1> 	mov	[sector_count], ecx ; total sector (read) count
   191                              <1> 
   192 0000F8BC 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 0000F8BF 81F900010000        <1> 	cmp	ecx, 256
   197 0000F8C5 7605                <1> 	jna	short lba_read_rsc
   198 0000F8C7 B900010000          <1> 	mov	ecx, 256 ; 17/02/2016
   199                              <1> lba_read_rsc:
   200 0000F8CC 290D[58610100]      <1> 	sub	[sector_count], ecx ; remain sectors
   201                              <1> 
   202 0000F8D2 89CF                <1> 	mov	edi, ecx 
   203 0000F8D4 89C1                <1> 	mov	ecx, eax ; sector number/address
   204                              <1> 
   205 0000F8D6 C605[56610100]04    <1> 	mov	byte [retry_count], 4
   206                              <1> lba_read_retry:
   207 0000F8DD 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 0000F8DF 8A25[55610100]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
   217 0000F8E5 E84D49FFFF          <1> 	call	int13h
   218                              <1> 	; al = ? (changed)
   219                              <1> 	; ah = error code
   220 0000F8EA 8825[57610100]      <1> 	mov	[disk_rw_err], ah
   221 0000F8F0 7334                <1> 	jnc	short lba_read_ok
   222 0000F8F2 80FC80              <1> 	cmp	ah, 80h ; time out?
   223 0000F8F5 740A                <1>         je      short lba_read_stc_retn
   224 0000F8F7 FE0D[56610100]      <1> 	dec	byte [retry_count]
   225 0000F8FD 7FDE                <1> 	jg	short lba_read_retry
   226 0000F8FF 743A                <1> 	jz	short lba_read_reset
   227                              <1> 	; sf =  1
   228                              <1> 
   229                              <1> lba_read_stc_retn:
   230 0000F901 F9                  <1> 	stc
   231                              <1> lba_read_retn:
   232 0000F902 5F                  <1> 	pop	edi
   233                              <1> 
   234                              <1> update_drv_error_byte:
   235 0000F903 9C                  <1> 	pushf
   236 0000F904 53                  <1> 	push	ebx
   237 0000F905 6651                <1> 	push	cx
   238                              <1> 	;or	ecx, ecx
   239                              <1> 	;jz	short udrv_errb0
   240 0000F907 8A0D[57610100]      <1> 	mov	cl, [disk_rw_err]
   241                              <1> udrv_errb0:
   242 0000F90D 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
   243 0000F911 80FB02              <1> 	cmp	bl, 2
   244 0000F914 7203                <1>         jb      short udrv_errb1
   245 0000F916 80EB7E              <1> 	sub	bl, 7Eh
   246                              <1> 	;cmp	bl, 5
   247                              <1> 	;ja	short udrv_errb2	
   248                              <1> udrv_errb1:
   249 0000F919 81C3[795D0000]      <1>         add     ebx, drv.error ; 13/02/2016
   250 0000F91F 880B                <1> 	mov	[ebx], cl ; error code
   251                              <1> udrv_errb2:
   252 0000F921 6659                <1> 	pop	cx
   253 0000F923 5B                  <1> 	pop	ebx
   254 0000F924 9D                  <1> 	popf
   255 0000F925 C3                  <1> 	retn
   256                              <1> 
   257                              <1> lba_read_ok:
   258 0000F926 89C8                <1> 	mov	eax, ecx ; sector number
   259 0000F928 01F8                <1> 	add	eax, edi ; sector number (next)
   260 0000F92A C1E709              <1> 	shl	edi, 9 ; sector count * 512
   261 0000F92D 01FB                <1> 	add	ebx, edi ; next buffer offset
   262                              <1> 
   263 0000F92F 8B0D[58610100]      <1> 	mov	ecx, [sector_count] ; remaining sectors
   264 0000F935 09C9                <1> 	or	ecx, ecx
   265 0000F937 7586                <1> 	jnz	short lba_read_next
   266 0000F939 EBC7                <1> 	jmp	short lba_read_retn
   267                              <1> 
   268                              <1> lba_read_reset:
   269 0000F93B B40D                <1> 	mov	ah, 0Dh ; Alternate reset
   270 0000F93D E8F548FFFF          <1>         call	int13h
   271                              <1> 	; al = ? (changed)
   272                              <1> 	; ah = error code
   273 0000F942 7399                <1> 	jnc	short lba_read_retry
   274 0000F944 EBBC                <1> 	jmp	short lba_read_retn
  2312                                  %include 'trdosk8.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.2) - MAIN PROGRAM : trdosk8.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 28/07/2020
     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> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    14                              <1> ; TRDOS2.ASM (09/11/2011)
    15                              <1> ; ----------------------------------------------------------------------------
    16                              <1> ; DIR.ASM (c) 2004-2011 Erdogan TAN  [07/01/2004] Last Update: 09/10/2011
    17                              <1> 
    18                              <1> set_run_sequence:
    19                              <1> 	; 23/12/2016
    20                              <1> 	; 10/06/2016
    21                              <1> 	; 22/05/2016
    22                              <1> 	; 20/05/2016
    23                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    24                              <1> 	; TRDOS 386 feature only !
    25                              <1> 	;
    26                              <1> 	; INPUT ->
    27                              <1> 	;	AL = process number (next process)
    28                              <1> 	;
    29                              <1> 	;	this process must be added to run sequence
    30                              <1> 	;
    31                              <1> 	;	[u.pri] = priority of present process
    32                              <1> 	;
    33                              <1> 	;	DL = priority (queue)
    34                              <1> 	;	     0 = background (low) ; run on background 
    35                              <1> 	;	     1 = regular (normal) ; run as regular
    36                              <1> 	;	     2 = event (high)     ; run for event
    37                              <1> 	;
    38                              <1> 	;	1) If the requested process is already running:
    39                              <1> 	;	   a) If present priority is high ([u.pri]=2) 
    40                              <1> 	;	      and requested priority is also high, 
    41                              <1> 	;	      there is nothing to do! Because it has been
    42                              <1> 	;	      done already (before this attempt).		 	
    43                              <1> 	;	   b) If present priority is high ([u.pri]=2)
    44                              <1> 	;	      and requested priority is not high, there is
    45                              <1> 	;	      nothing to do! Because, it's current
    46                              <1> 	;	      run queue is unspecified, here. (It may be in
    47                              <1> 	;	      a waiting list or in a run queue; if the new
    48                              <1> 	;	      priority would be used to add it to relavant
    49                              <1>         ;             run queue, this would be wrong, unnecessary
    50                              <1> 	;	      and destabilizing duplication!)
    51                              <1> 	;	   c) If present priority is not high ([u.pri]<2)
    52                              <1>         ;             and requested priority is high (event),
    53                              <1> 	;	      process will be added to present priority's
    54                              <1> 	;	      run queue and then, priority will be changed
    55                              <1> 	;	      to high ([u.pri]=2).
    56                              <1> 	;	   d) If present priority is not high ([u.pri]<2)
    57                              <1> 	;	      and requested priority is not high, [u.pri]
    58                              <1> 	;	      value will be changed. There is nothing to do
    59                              <1> 	;	      in addition. (The new priority value will be
    60                              <1> 	;	      used by 'tswap/tswitch' procedure at 'sysret'
    61                              <1> 	;	      or 'sysrele' stage.)
    62                              <1> 	;
    63                              <1> 	;	2) If the requested process is not running:
    64                              <1> 	;	   a) If requested priority of the requested
    65                              <1> 	;	      (next) process is high (event) and priority
    66                              <1> 	;	      of present process is not high, the requested
    67                              <1> 	;	      process will be added to ('runq_event') high
    68                              <1> 	;	      priority run queue and then present (running)
    69                              <1> 	;	      process will be stopped (swapped/switched out)
    70                              <1> 	;	      immediately if it is in user mode, or it's 
    71                              <1> 	;	      [u.quant] value will be reset to 0 and (then) 
    72                              <1> 	;	      it will be stopped at 'sysret' stage.			
    73                              <1> 	;	   b) If requested priority of the requested
    74                              <1> 	;	      (next) process is high (event) and priority
    75                              <1> 	;	      of present process is also high, the requested
    76                              <1> 	;	      process will be added to ('runq_event') high
    77                              <1> 	;	      priority run queue and present (running) 
    78                              <1> 	;	      process will be allowed to run until it's 
    79                              <1> 	;	      time quantum will be elapsed ([u.quant]=0).	
    80                              <1> 	;	   c) If requested priority of the requested
    81                              <1> 	;	      (next) process is not high ('run for event'), 
    82                              <1> 	;	      there is nothing to do. Because, it's current
    83                              <1> 	;	      run queue is unspecified, here. (It may be in
    84                              <1> 	;	      a waiting list or in a run queue; if the new
    85                              <1> 	;	      priority would be used to add it to relavant
    86                              <1>         ;             run queue, this would be wrong, unnecessary
    87                              <1> 	;	      and destabilizing duplication!) 
    88                              <1> 	;
    89                              <1> 	; OUTPUT ->
    90                              <1> 	;	none
    91                              <1> 	;
    92                              <1> 	;	[u.pri] = priority of present process
    93                              <1> 	;
    94                              <1> 	;	cf = 1, if the request could not be fulfilled.
    95                              <1> 	;			 	     	  
    96                              <1> 	;	NOTE: 
    97                              <1>         ;          * Processes in 'run as regular' queue can run
    98                              <1> 	;	     if there is no process in 'run for event' queue
    99                              <1> 	;	     ('run for event' processes have higher priority)	 		 
   100                              <1> 	;	   * When [u.quant] time quantum of a process is
   101                              <1> 	;	     elapsed, it's high priority ('run for event')
   102                              <1> 	;	     status will be disabled, it can be run in sequence
   103                              <1> 	;	     of it's actual run queue.
   104                              <1> 	;	   * A 'run on background' process will always be 
   105                              <1> 	;	     sequenced in 'run on background' (low priority)
   106                              <1> 	;	     queue, it can run only when other priority queues
   107                              <1> 	;	     are empty. (idle time processes, e.g. printing)  	 	
   108                              <1> 	;
   109                              <1> 	; Modified registers: eax, ebx, edx
   110                              <1> 	;
   111                              <1> 
   112                              <1> srunseq_0:
   113 0000F946 3A05[B3030300]      <1>         cmp     al, [u.uno]     ; same process ?
   114 0000F94C 750C                <1> 	jne	short srunseq_2 ; no
   115                              <1> 
   116 0000F94E 8A25[A9030300]      <1> 	mov	ah, [u.pri] 	; present/current priority
   117 0000F954 80FC02              <1> 	cmp	ah, 2       	; 'run for event' priority level
   118 0000F957 7221                <1> 	jb	short srunseq_6 ; no
   119                              <1> 
   120                              <1> srunseq_1:
   121                              <1> 	; there is nothing to do!
   122 0000F959 C3                  <1> 	retn
   123                              <1> 
   124                              <1> srunseq_2:
   125                              <1> 	;;this not necessary ! 23/12/2016
   126                              <1>         ;;cmp	al, nproc	; number of processes = 16 
   127                              <1> 	;;jnb	short srunseq_5	; error ! invalid process number 
   128                              <1> 
   129                              <1> 	; dl = priority
   130 0000F95A 80FA02              <1> 	cmp	dl, 2 		; event queue
   131 0000F95D 72FA                <1> 	jb	short srunseq_1 ; requested process is not present
   132                              <1> 				; process and priority of requested
   133                              <1> 				; process is not high (event), 
   134                              <1> 				; there is nothing to do!
   135                              <1> 	
   136                              <1> 	; requested process is not present process
   137                              <1> 	; & priority of requested process is high
   138 0000F95F 3A15[A9030300]      <1> 	cmp	dl, [u.pri] 	; priority of present process
   139 0000F965 7606                <1> 	jna	short srunseq_3 ; is high, also
   140                              <1> 	;
   141                              <1> 	; present process will be swapped/switched out
   142 0000F967 FE05[31650100]      <1> 	inc	byte [p_change] ; 1
   143                              <1> 
   144                              <1> srunseq_3:
   145                              <1> 	; add process to 'runq_event' queue for new event
   146 0000F96D BB[52030300]        <1> 	mov	ebx, runq_event ; high priority run queue
   147                              <1> 
   148                              <1> srunseq_4:
   149                              <1> 	; al = process number
   150                              <1> 	; ebx = run queue
   151 0000F972 E881EDFFFF          <1> 	call	putlu
   152 0000F977 C3                  <1> 	retn
   153                              <1> 
   154                              <1> srunseq_5:
   155 0000F978 F5                  <1> 	cmc
   156 0000F979 C3                  <1> 	retn
   157                              <1> 
   158                              <1> srunseq_6:
   159                              <1> 	; present priority of the process is not high
   160                              <1> 	
   161 0000F97A 8815[A9030300]      <1> 	mov	[u.pri], dl ; new priority 
   162                              <1> 			    ; (will be used by 'tswap')
   163                              <1> 
   164 0000F980 80FA02              <1> 	cmp	dl, 2 		; high priority ?
   165 0000F983 72F3                <1> 	jb	short srunseq_5 ; no, there is nothing to do
   166                              <1> 				; in addition
   167                              <1> 
   168                              <1> 	; process must be added to relevant run queue, here!
   169                              <1> 	; (new priority is high/event priority and process
   170                              <1> 	; will not be added to a run queue by 'tswap')
   171                              <1> 
   172 0000F985 BB[54030300]        <1> 	mov	ebx, runq_normal ; 'run as regular' queue
   173                              <1> 
   174 0000F98A 20E4                <1> 	and	ah, ah  ;  previous value of [u.pri]
   175 0000F98C 75E4                <1> 	jnz	short srunseq_4
   176                              <1> 
   177 0000F98E 43                  <1> 	inc	ebx
   178 0000F98F 43                  <1> 	inc	ebx
   179                              <1> 	; ebx = runq_background ; 'run on backgroud' queue 
   180                              <1> 
   181 0000F990 EBE0                <1> 	jmp	short srunseq_4
   182                              <1> clock:
   183                              <1> 	; 23/05/2016
   184                              <1> 	; 22/05/2016
   185                              <1> 	; 20/05/2016
   186                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   187                              <1> 	; 14/05/2015 - 14/10/2015 (Retro UNIX 386 v1)
   188                              <1> 	; 07/12/2013 - 10/04/2014 (Retro UNIX 8086 v1)
   189                              <1> 
   190 0000F992 803D[A8030300]00    <1> 	cmp	byte [u.quant], 0
   191 0000F999 772C                <1> 	ja	short clk_1
   192                              <1> 	;
   193 0000F99B 803D[B3030300]01    <1> 	cmp     byte [u.uno], 1 ; /etc/init ? (for Retro UNIX 8086 & 386 v1)
   194                              <1> 				; MainProg (Kernel's Command Interpreter)
   195                              <1> 				; for TRDOS 386.
   196 0000F9A2 7623                <1> 	jna	short clk_1 ; yes, do not swap out
   197                              <1> 	;
   198 0000F9A4 803D[5B030300]FF    <1> 	cmp     byte [sysflg], 0FFh ; user or system space ?
   199 0000F9AB 7520                <1> 	jne	short clk_2 	    ; system space (sysflg <> 0FFh)
   200                              <1> 	;
   201 0000F9AD 66833D[AA030300]00  <1> 	cmp	word [u.intr], 0
   202 0000F9B5 7616                <1> 	jna	short clk_2
   203                              <1> 	;
   204                              <1> 	; 23/05/2016
   205 0000F9B7 803D[32650100]00    <1> 	cmp	byte [multi_tasking], 0
   206 0000F9BE 760D                <1> 	jna	short clk_2
   207                              <1> 	;
   208 0000F9C0 FE05[31650100]      <1> 	inc	byte [p_change] ; it is time to change running process	
   209 0000F9C6 C3                  <1> 	retn
   210                              <1> clk_1:
   211 0000F9C7 FE0D[A8030300]      <1> 	dec	byte [u.quant]
   212                              <1> clk_2:
   213 0000F9CD C3                  <1> 	retn   ; return to (hardware) timer interrupt routine
   214                              <1> 
   215                              <1> ; 12/10/2017
   216                              <1> ; 15/01/2017
   217                              <1> ; 14/01/2017
   218                              <1> ; 07/01/2017
   219                              <1> ; 02/01/2017
   220                              <1> ; 17/08/2016
   221                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   222                              <1> int34h:  ; #IOCTL# (I/O port access support for ring 3)
   223                              <1> ; 23/05/2016
   224                              <1> 	; 20/06/2016
   225                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   226                              <1> 	;
   227                              <1> 	; INPUT ->
   228                              <1> 	;	AH = 0 -> read port  (physical IO port) -byte-
   229                              <1> 	;	AH = 1 -> write port (physical IO port) -byte-
   230                              <1> 	;		AL = data byte
   231                              <1> 	;	AH = 2 -> read port  (physical IO port) -word-
   232                              <1> 	;	AH = 3 -> write port (physical IO port) -word-
   233                              <1> 	;		BX = data word
   234                              <1> 	;	AH = 4 -> read port  (physical IO port) -dword-
   235                              <1> 	;	AH = 5 -> write port (physical IO port) -dword-
   236                              <1> 	;		EBX = data dword
   237                              <1> 	;	; 12/10/2017
   238                              <1> 	;	AH = 6 -> read port (physical IO port) twice -byte-
   239                              <1> 	;	AH = 7 -> write port (physical IO port) twice -byte-
   240                              <1> 	;		BX = data word	
   241                              <1> 	;
   242                              <1> 	;	DX = Port number (<= 0FFFFh)
   243                              <1> 	;
   244                              <1> 	; OUTPUT ->
   245                              <1> 	;	AL = data byte (in al, dx)
   246                              <1> 	;	AX = data word (in ax, dx)
   247                              <1> 	;	EAX = data dword (in eax, dx)
   248                              <1> 	;
   249                              <1> 	;	(ECX = actual TRANSFER COUNT for string functions)
   250                              <1> 	;
   251                              <1> 	;
   252                              <1> 	; Modified registers: EAX
   253                              <1> 	;
   254                              <1> 
   255                              <1> 	;cmp	ah, 5
   256                              <1> 	;ja	short int34h_5 ; invalid function !
   257                              <1> 
   258                              <1> 	; 12/10/2017
   259 0000F9CE 80FC07              <1> 	cmp	ah, 7
   260 0000F9D1 7743                <1> 	ja	short int34h_5 ; invalid function !
   261                              <1> 
   262                              <1> 	;; 15/01/2017
   263                              <1> 	; 14/01/2017
   264                              <1> 	; 02/01/2017
   265                              <1> 	;;mov	byte [ss:intflg], 34h	; IOCTL interrupt 
   266 0000F9D3 FB                  <1> 	sti
   267                              <1> 	
   268                              <1> 	;sti	; enable interrupts
   269 0000F9D4 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   270                              <1> 
   271 0000F9D9 80FC01              <1> 	cmp	ah, 1
   272 0000F9DC 7205                <1> 	jb	short int34h_0
   273 0000F9DE 7705                <1> 	ja	short int34h_1
   274                              <1> 
   275 0000F9E0 EE                  <1> 	out	dx, al
   276                              <1> 	;iretd
   277 0000F9E1 EB01                <1> 	jmp short int34h_iret
   278                              <1> 
   279                              <1> int34h_0:
   280 0000F9E3 EC                  <1> 	in	al, dx
   281                              <1> 	;iretd
   282                              <1> int34h_iret:
   283                              <1> 	;cli	; 07/01/2017
   284                              <1> 	;; 15/01/2017
   285                              <1> 	;;mov	byte [ss:intflg], 0 ; reset
   286 0000F9E4 CF                  <1> 	iretd 
   287                              <1> 
   288                              <1> int34h_1:
   289 0000F9E5 F6C401              <1> 	test	ah, 1
   290 0000F9E8 7516                <1> 	jnz	short int34h_3 ; out
   291                              <1> 
   292                              <1> 	; in
   293 0000F9EA 80FC02              <1> 	cmp	ah, 2
   294 0000F9ED 7707                <1> 	ja	short int34h_2
   295                              <1> 
   296 0000F9EF 6689D8              <1> 	mov	ax, bx
   297 0000F9F2 66ED                <1> 	in	ax, dx
   298                              <1> 	;iretd
   299 0000F9F4 EBEE                <1> 	jmp	short int34h_iret
   300                              <1> 
   301                              <1> int34h_2:
   302 0000F9F6 80FC04              <1> 	cmp	ah, 4
   303 0000F9F9 772C                <1> 	ja	short int34h_7	; 12/10/2017
   304                              <1> 	; ah = 4
   305 0000F9FB 89D8                <1> 	mov	eax, ebx
   306 0000F9FD ED                  <1> 	in	eax, dx
   307                              <1> 	;iretd
   308 0000F9FE EBE4                <1> 	jmp	short int34h_iret
   309                              <1> 
   310                              <1> int34h_3:
   311 0000FA00 80FC03              <1> 	cmp	ah, 3
   312 0000FA03 7707                <1> 	ja	short int34h_4
   313                              <1> 
   314 0000FA05 6689D8              <1> 	mov	ax, bx
   315 0000FA08 66EF                <1> 	out	dx, ax
   316                              <1> 	;iretd
   317 0000FA0A EBD8                <1> 	jmp	short int34h_iret
   318                              <1> 
   319                              <1> int34h_4:
   320 0000FA0C 80FC05              <1> 	cmp	ah, 5
   321 0000FA0F 770B                <1> 	ja	short int34h_6	; 12/10/2017
   322                              <1> 	; ah = 5
   323 0000FA11 89D8                <1> 	mov	eax, ebx
   324 0000FA13 EF                  <1> 	out	dx, eax
   325                              <1> 	;iretd
   326 0000FA14 EBCE                <1> 	jmp	short int34h_iret
   327                              <1> 
   328                              <1> int34h_5:
   329 0000FA16 804C240801          <1> 	or	byte [esp+8], 1	; set carry bit of eflags register
   330 0000FA1B CF                  <1> 	iretd
   331                              <1> 
   332                              <1> 	; 12/10/2017
   333                              <1> int34h_6:
   334 0000FA1C 6689D8              <1> 	mov	ax, bx
   335 0000FA1F EE                  <1> 	out	dx, al
   336 0000FA20 EB00                <1> 	jmp	short $+2
   337 0000FA22 86E0                <1> 	xchg	ah, al
   338 0000FA24 EE                  <1> 	out	dx, al
   339                              <1> 	;xchg	al, ah
   340                              <1> 	;iretd
   341 0000FA25 EB06                <1> 	jmp	short int34h_8
   342                              <1> int34h_7:
   343 0000FA27 EC                  <1> 	in	al, dx
   344 0000FA28 EB00                <1> 	jmp	short $+2
   345 0000FA2A 88C4                <1> 	mov	ah, al
   346 0000FA2C EC                  <1> 	in	al, dx
   347                              <1> int34h_8:
   348 0000FA2D 86C4                <1> 	xchg	al, ah
   349 0000FA2F CF                  <1> 	iretd
   350                              <1> 			
   351                              <1> 
   352                              <1> INT4Ah:
   353                              <1> 	; 24/01/2016
   354                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
   355 0000FA30 C3                  <1> 	retn
   356                              <1> 
   357                              <1> ; u0.s
   358                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
   359                              <1> ; Last Modification: 20/11/2015
   360                              <1> 
   361                              <1> com2_int:
   362                              <1> 	; 07/11/2015 
   363                              <1> 	; 24/10/2015
   364                              <1> 	; 23/10/2015
   365                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   366                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   367                              <1> 	; < serial port 2 interrupt handler >
   368                              <1> 	;
   369 0000FA31 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   370                              <1> 	;push	eax
   371 0000FA34 66B80900            <1> 	mov	ax, 9
   372 0000FA38 EB07                <1> 	jmp	short comm_int
   373                              <1> com1_int:
   374                              <1> 	; 07/11/2015
   375                              <1> 	; 24/10/2015
   376 0000FA3A 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   377                              <1> 	; 23/10/2015
   378                              <1> 	;push	eax
   379 0000FA3D 66B80800            <1> 	mov	ax, 8
   380                              <1> comm_int:
   381                              <1> 	; 20/11/2015
   382                              <1> 	; 18/11/2015
   383                              <1> 	; 17/11/2015
   384                              <1> 	; 16/11/2015
   385                              <1> 	; 09/11/2015
   386                              <1> 	; 08/11/2015
   387                              <1> 	; 07/11/2015
   388                              <1> 	; 06/11/2015 (serial4.asm, 'serial')	
   389                              <1> 	; 01/11/2015
   390                              <1> 	; 26/10/2015
   391                              <1> 	; 23/10/2015
   392 0000FA41 53                  <1> 	push	ebx
   393 0000FA42 56                  <1> 	push	esi
   394 0000FA43 57                  <1> 	push	edi
   395 0000FA44 1E                  <1> 	push 	ds
   396 0000FA45 06                  <1> 	push 	es
   397                              <1> 	; 18/11/2015
   398 0000FA46 0F20DB              <1> 	mov	ebx, cr3
   399 0000FA49 53                  <1> 	push	ebx ; ****
   400                              <1> 	;
   401 0000FA4A 51                  <1> 	push	ecx ; ***
   402 0000FA4B 52                  <1> 	push	edx ; **
   403                              <1> 	;
   404 0000FA4C BB10000000          <1> 	mov	ebx, KDATA
   405 0000FA51 8EDB                <1> 	mov	ds, bx
   406 0000FA53 8EC3                <1> 	mov	es, bx
   407                              <1> 	;
   408 0000FA55 8B0D[A8580100]      <1> 	mov	ecx, [k_page_dir]
   409 0000FA5B 0F22D9              <1> 	mov	cr3, ecx
   410                              <1> 	; 20/11/2015
   411                              <1> 	; Interrupt identification register
   412 0000FA5E 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
   413                              <1> 	;
   414 0000FA62 3C08                <1> 	cmp 	al, 8 
   415 0000FA64 7702                <1> 	ja 	short com_i0
   416                              <1> 	;
   417                              <1> 	; 20/11/2015
   418                              <1> 	; 17/11/2015
   419                              <1> 	; 16/11/2015
   420                              <1> 	; 15/11/2015
   421                              <1> 	; 24/10/2015
   422                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   423                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   424                              <1> 	; < serial port 1 interrupt handler >
   425                              <1> 	;
   426 0000FA66 FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
   427                              <1> com_i0:
   428                              <1> 	;push	eax ; *
   429                              <1> 	; 07/11/2015
   430 0000FA68 A2[12590100]        <1> 	mov 	byte [ccomport], al
   431                              <1> 	; 09/11/2015
   432 0000FA6D 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
   433                              <1> 	; 17/11/2015
   434                              <1>  	; reset request for response status
   435 0000FA70 88A3[08590100]      <1> 	mov	[ebx+req_resp-8], ah ; 0
   436                              <1> 	;
   437                              <1> 	; 20/11/2015
   438 0000FA76 EC                  <1> 	in	al, dx		; read interrupt id. register
   439 0000FA77 EB00                <1> 	JMP	$+2	   	; I/O DELAY
   440 0000FA79 2404                <1> 	and	al, 4		; received data available?	
   441 0000FA7B 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
   442                              <1> 	;
   443                              <1> 	; 20/11/2015
   444 0000FA7D 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
   445 0000FA80 EC                  <1> 	in	al, dx     	; read character
   446                              <1> 	;JMP	$+2	   	; I/O DELAY
   447                              <1> 	; 08/11/2015
   448                              <1> 	; 07/11/2015
   449 0000FA81 89DE                <1> 	mov	esi, ebx 
   450 0000FA83 89DF                <1> 	mov	edi, ebx
   451 0000FA85 81C6[0C590100]      <1> 	add 	esi, rchar - 8 ; points to last received char
   452 0000FA8B 81C7[0E590100]      <1> 	add	edi, schar - 8 ; points to last sent char
   453 0000FA91 8806                <1> 	mov	[esi], al ; received char (current char)
   454                              <1> 	; query
   455 0000FA93 20C0                <1> 	and	al, al
   456 0000FA95 7527                <1> 	jnz	short com_i2
   457                              <1>    	; response
   458                              <1> 	; 17/11/2015
   459                              <1> 	; set request for response status
   460 0000FA97 FE83[08590100]      <1>         inc     byte [ebx+req_resp-8] ; 1 
   461                              <1> 	;
   462 0000FA9D 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
   463 0000FAA1 EC                  <1> 	in	al, dx	   	; read line status register 
   464 0000FAA2 EB00                <1> 	JMP	$+2	   	; I/O DELAY
   465 0000FAA4 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
   466 0000FAA6 7445                <1> 	jz	short com_eoi 	; no
   467 0000FAA8 B0FF                <1> 	mov 	al, 0FFh   	; response			
   468 0000FAAA 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
   469 0000FAAE EE                  <1> 	out	dx, al	   	; send on serial port
   470                              <1> 	; 17/11/2015
   471 0000FAAF 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
   472 0000FAB2 7502                <1> 	jne 	short com_i1    ; no
   473 0000FAB4 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
   474                              <1> com_i1:
   475                              <1> 	; 17/11/2015
   476                              <1> 	; reset request for response status (again)
   477 0000FAB6 FE8B[08590100]      <1>         dec     byte [ebx+req_resp-8] ; 0 
   478 0000FABC EB2F                <1> 	jmp	short com_eoi
   479                              <1> com_i2:	
   480                              <1> 	; 08/11/2015
   481 0000FABE 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
   482 0000FAC0 7417                <1> 	je	short com_i3	; (check for response signal)
   483                              <1> 	; 07/11/2015
   484 0000FAC2 3C04                <1> 	cmp	al, 04h	; EOT
   485 0000FAC4 751C                <1> 	jne	short com_i4	
   486                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
   487                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
   488                              <1> 	; 08/11/2015
   489                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
   490 0000FAC6 861D[D6580100]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
   491 0000FACC E84569FFFF          <1> 	call 	ctrlbrk
   492 0000FAD1 861D[D6580100]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
   493                              <1> 	;mov	al, 04h ; EOT
   494                              <1> 	; 08/11/2015
   495 0000FAD7 EB09                <1> 	jmp	short com_i4	
   496                              <1> com_i3:
   497                              <1> 	; 08/11/2015
   498                              <1> 	; If 0FFh has been received just after a query
   499                              <1> 	; (schar, ZERO), it is a response signal.
   500                              <1> 	; 17/11/2015
   501 0000FAD9 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
   502 0000FADC 7704                <1> 	ja	short com_i4 ; no
   503                              <1> 	; reset query status (schar)
   504 0000FADE 8807                <1> 	mov	[edi], al ; 0FFh
   505 0000FAE0 FEC0                <1> 	inc	al ; 0
   506                              <1> com_i4:
   507                              <1> 	; 27/07/2014
   508                              <1> 	; 09/07/2014
   509 0000FAE2 D0E3                <1> 	shl	bl, 1	
   510 0000FAE4 81C3[D8580100]      <1> 	add	ebx, ttychr
   511                              <1> 	; 23/07/2014 (always overwrite)
   512                              <1> 	;;cmp	word [ebx], 0
   513                              <1> 	;;ja	short com_eoi
   514                              <1> 	;
   515 0000FAEA 668903              <1> 	mov	[ebx], ax   ; Save ascii code
   516                              <1> 			    ; scan code = 0
   517                              <1> com_eoi:
   518                              <1> 	;mov	al, 20h
   519                              <1> 	;out	20h, al	   ; end of interrupt
   520                              <1> 	;
   521                              <1> 	; 07/11/2015
   522                              <1>       	;pop	eax ; *
   523 0000FAED A0[12590100]        <1> 	mov	al, byte [ccomport] ; current COM port
   524                              <1> 	 ; al = tty number (8 or 9)
   525 0000FAF2 E85E010000          <1>         call	wakeup
   526                              <1> com_iret:
   527                              <1> 	; 23/10/2015
   528 0000FAF7 5A                  <1> 	pop	edx ; **
   529 0000FAF8 59                  <1> 	pop	ecx ; ***
   530                              <1> 	; 18/11/2015
   531                              <1> 	;pop	eax ; ****
   532                              <1> 	;mov	cr3, eax
   533                              <1> 	;jmp	iiret
   534 0000FAF9 E91210FFFF          <1> 	jmp	iiretp
   535                              <1> 
   536                              <1> ;iiretp: ; 01/09/2015
   537                              <1> ;	; 28/08/2015
   538                              <1> ;	pop	eax ; (*) page directory
   539                              <1> ;	mov	cr3, eax
   540                              <1> ;iiret:
   541                              <1> ;	; 22/08/2014
   542                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
   543                              <1> ;	out	20h, al	; 8259 PORT
   544                              <1> ;	;
   545                              <1> ;	pop	es
   546                              <1> ;	pop	ds
   547                              <1> ;	pop	edi
   548                              <1> ;	pop	esi
   549                              <1> ;	pop	ebx ; 29/08/2014
   550                              <1> ;	pop 	eax
   551                              <1> ;	iretd
   552                              <1> 
   553                              <1> sp_init:
   554                              <1> 	; 07/11/2015
   555                              <1> 	; 29/10/2015
   556                              <1> 	; 26/10/2015
   557                              <1> 	; 23/10/2015
   558                              <1> 	; 29/06/2015
   559                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
   560                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
   561                              <1> 	; Initialization of Serial Port Communication Parameters
   562                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   563                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   564                              <1> 	;
   565                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   566                              <1> 	;
   567                              <1> 	; INPUT:  (29/06/2015)
   568                              <1> 	;	AL = 0 for COM1
   569                              <1> 	;	     1 for COM2
   570                              <1> 	;	AH = Communication parameters	
   571                              <1> 	;
   572                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   573                              <1> 	;	Bit	4	3	2	1	0
   574                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
   575                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   576                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   577                              <1> 	;		11 = even
   578                              <1> 	;  Baud rate setting bits: (29/06/2015)
   579                              <1> 	;		Retro UNIX 386 v1 feature only !
   580                              <1> 	;	Bit	7    6    5  | Baud rate
   581                              <1> 	;		------------------------
   582                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   583                              <1> 	;		0    0    1  | 9600 (12)
   584                              <1> 	;		0    1    0  | 19200 (6) 
   585                              <1> 	;		0    1	  1  | 38400 (3) 
   586                              <1> 	;		1    0	  0  | 14400 (8)
   587                              <1> 	;		1    0	  1  | 28800 (4)
   588                              <1> 	;		1    1    0  | 57600 (2)
   589                              <1> 	;		1    1    1  | 115200 (1) 	
   590                              <1> 	
   591                              <1> 	; References:	
   592                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
   593                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
   594                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
   595                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
   596                              <1> 	;
   597                              <1> 	; Set communication parameters for COM1 (= 03h)	
   598                              <1> 	;
   599 0000FAFE BB[0E590100]        <1> 	mov	ebx, com1p		; COM1 parameters  
   600 0000FB03 66BAF803            <1> 	mov	dx, 3F8h		; COM1
   601                              <1> 	 ; 29/10/2015
   602 0000FB07 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   603 0000FB0B E86F000000          <1> 	call	sp_i3	; call A4	
   604 0000FB10 A880                <1> 	test	al, 80h
   605 0000FB12 7410                <1> 	jz	short sp_i0 ; OK..
   606                              <1> 		; Error !
   607                              <1> 	;mov	dx, 3F8h
   608 0000FB14 80EA05              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
   609 0000FB17 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   610 0000FB1B E85F000000          <1> 	call	sp_i3	; call A4	
   611 0000FB20 A880                <1> 	test	al, 80h
   612 0000FB22 7508                <1> 	jnz	short sp_i1
   613                              <1> sp_i0:
   614                              <1>         ; (Note: Serial port interrupts will be disabled here...)	
   615                              <1>         ; (INT 14h initialization code disables interrupts.)
   616                              <1> 	;
   617 0000FB24 C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   618 0000FB27 E8DC000000          <1> 	call	sp_i5 ; 29/06/2015
   619                              <1> sp_i1:
   620 0000FB2C 43                  <1> 	inc	ebx
   621 0000FB2D 66BAF802            <1> 	mov	dx, 2F8h		; COM2
   622                              <1> 	 ; 29/10/2015
   623 0000FB31 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   624 0000FB35 E845000000          <1> 	call	sp_i3	; call A4	
   625 0000FB3A A880                <1> 	test	al, 80h
   626 0000FB3C 7410                <1> 	jz	short sp_i2 ; OK..
   627                              <1> 		; Error !
   628                              <1> 	;mov	dx, 2F8h
   629 0000FB3E 80EA05              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
   630 0000FB41 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   631 0000FB45 E835000000          <1> 	call	sp_i3	; call A4	
   632 0000FB4A A880                <1> 	test	al, 80h
   633 0000FB4C 7530                <1> 	jnz	short sp_i7
   634                              <1> sp_i2:
   635 0000FB4E C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   636                              <1> sp_i6:
   637                              <1> 	;; COM2 - enabling IRQ 3
   638                              <1> 	; 07/11/2015
   639                              <1> 	; 26/10/2015
   640 0000FB51 9C                  <1> 	pushf
   641 0000FB52 FA                  <1> 	cli
   642                              <1> 	;
   643 0000FB53 66BAFC02            <1> 	mov	dx, 2FCh   		; modem control register
   644 0000FB57 EC                  <1> 	in	al, dx 	   		; read register
   645 0000FB58 EB00                <1> 	JMP	$+2	   		; I/O DELAY
   646 0000FB5A 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
   647 0000FB5C EE                  <1> 	out	dx, al     		; write back to register
   648 0000FB5D EB00                <1> 	JMP	$+2	   		; I/O DELAY
   649 0000FB5F 66BAF902            <1> 	mov	dx, 2F9h   		; interrupt enable register
   650 0000FB63 EC                  <1> 	in	al, dx     		; read register
   651 0000FB64 EB00                <1> 	JMP	$+2	   		; I/O DELAY
   652                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   653 0000FB66 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
   654 0000FB68 EE                  <1> 	out	dx, al 	   		; write back to register
   655 0000FB69 EB00                <1> 	JMP	$+2        		; I/O DELAY
   656 0000FB6B E421                <1> 	in	al, 21h    		; read interrupt mask register
   657 0000FB6D EB00                <1> 	JMP	$+2	   		; I/O DELAY
   658 0000FB6F 24F7                <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
   659 0000FB71 E621                <1> 	out	21h, al    		; write back to register
   660                              <1> 	;
   661                              <1> 	; 23/10/2015
   662 0000FB73 B8[31FA0000]        <1> 	mov 	eax, com2_int
   663 0000FB78 A3[50FC0000]        <1> 	mov	[com2_irq3], eax
   664                              <1> 	; 26/10/2015
   665 0000FB7D 9D                  <1> 	popf	
   666                              <1> sp_i7:
   667 0000FB7E C3                  <1> 	retn
   668                              <1> 
   669                              <1> sp_i3:
   670                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
   671                              <1> 	; 28/10/2015
   672 0000FB7F FEC2                <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
   673 0000FB81 B000                <1> 	mov	al, 0
   674 0000FB83 EE                  <1> 	out	dx, al			; disable serial port interrupt
   675 0000FB84 EB00                <1> 	JMP	$+2			; I/O DELAY
   676 0000FB86 80C202              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
   677 0000FB89 B080                <1> 	mov	al, 80h			
   678 0000FB8B EE                  <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
   679                              <1> 	;-----	SET BAUD RATE DIVISOR
   680                              <1> 	; 26/10/2015
   681 0000FB8C 80EA03              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
   682                              <1> 					; of the divisor value
   683 0000FB8F 88C8                <1> 	mov	al, cl	; 1
   684 0000FB91 EE                  <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
   685                              <1> 					; 2 = 57600 baud
   686                              <1> 					; 3 = 38400 baud
   687                              <1> 					; 6 = 19200 baud
   688                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
   689 0000FB92 EB00                <1> 	JMP	$+2			; I/O DELAY
   690 0000FB94 28C0                <1> 	sub	al, al
   691 0000FB96 FEC2                <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
   692                              <1> 					; of the divisor value
   693 0000FB98 EE                  <1> 	out	dx, al ; 0
   694 0000FB99 EB00                <1> 	JMP	$+2			; I/O DELAY
   695                              <1> 	;	
   696 0000FB9B 88E8                <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
   697                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
   698 0000FB9D 80C202              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
   699 0000FBA0 EE                  <1> 	out	dx, al			
   700 0000FBA1 EB00                <1> 	JMP	$+2			; I/O DELAY
   701                              <1> 	; 29/10/2015
   702 0000FBA3 FECA                <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
   703 0000FBA5 30C0                <1> 	xor	al, al			; 0
   704 0000FBA7 EE                  <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
   705 0000FBA8 EB00                <1> 	JMP	$+2	
   706                              <1> sp_i4:
   707                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
   708                              <1> 	; 29/06/2015 (line status after modem status)
   709 0000FBAA 80C204              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
   710                              <1> sp_i4s:
   711 0000FBAD EC                  <1> 	in	al, dx			; GET MODEM CONTROL STATUS
   712 0000FBAE EB00                <1> 	JMP	$+2			; I/O DELAY
   713 0000FBB0 88C4                <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
   714 0000FBB2 FECA                <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
   715                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
   716 0000FBB4 EC                  <1> 	in	al, dx			; GET LINE CONTROL STATUS
   717                              <1> 	; AL = Line status, AH = Modem status
   718 0000FBB5 C3                  <1> 	retn
   719                              <1> 
   720                              <1> sp_status:
   721                              <1> 	; 29/06/2015
   722                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
   723                              <1> 	; Get serial port status
   724 0000FBB6 66BAFE03            <1> 	mov	dx, 3FEh		; Modem status register (COM1)
   725 0000FBBA 28C6                <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
   726                              <1> 					; dx = 2FEh for COM2
   727 0000FBBC EBEF                <1> 	jmp	short sp_i4s
   728                              <1> 
   729                              <1> sp_setp: ; Set serial port communication parameters
   730                              <1> 	; 07/11/2015
   731                              <1> 	; 29/10/2015
   732                              <1> 	; 29/06/2015
   733                              <1> 	; Retro UNIX 386 v1 feature only !	
   734                              <1> 	;
   735                              <1> 	; INPUT:
   736                              <1> 	;	AL = 0 for COM1
   737                              <1> 	;	     1 for COM2
   738                              <1> 	;	AH = Communication parameters (*)
   739                              <1> 	; OUTPUT:
   740                              <1> 	;	CL = Line status
   741                              <1> 	;	CH = Modem status
   742                              <1> 	;   If cf = 1 -> Error code in [u.error]
   743                              <1> 	;		 'invalid parameter !' 
   744                              <1> 	;		 	 or
   745                              <1> 	;		 'device not ready !' error
   746                              <1> 	;	
   747                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   748                              <1> 	;	Bit	4	3	2	1	0
   749                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
   750                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   751                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   752                              <1> 	;		11 = even
   753                              <1> 	;  Baud rate setting bits: (29/06/2015)
   754                              <1> 	;		Retro UNIX 386 v1 feature only !
   755                              <1> 	;	Bit	7    6    5  | Baud rate
   756                              <1> 	;		------------------------
   757                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   758                              <1> 	;		0    0    1  | 9600 (12)
   759                              <1> 	;		0    1    0  | 19200 (6) 
   760                              <1> 	;		0    1	  1  | 38400 (3) 
   761                              <1> 	;		1    0	  0  | 14400 (8)
   762                              <1> 	;		1    0	  1  | 28800 (4)
   763                              <1> 	;		1    1    0  | 57600 (2)
   764                              <1> 	;		1    1    1  | 115200 (1) 
   765                              <1> 	;
   766                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   767                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   768                              <1> 	;
   769                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   770                              <1> 	;
   771 0000FBBE 66BAF803            <1> 	mov	dx, 3F8h
   772 0000FBC2 BB[0E590100]        <1> 	mov	ebx, com1p ; COM1 control byte offset
   773 0000FBC7 3C01                <1> 	cmp	al, 1
   774 0000FBC9 776B                <1> 	ja 	short sp_invp_err
   775 0000FBCB 7203                <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
   776 0000FBCD FECE                <1> 	dec	dh ; 2F8h
   777 0000FBCF 43                  <1> 	inc	ebx ; COM2 control byte offset
   778                              <1> sp_setp1:
   779                              <1> 	; 29/10/2015
   780 0000FBD0 8823                <1> 	mov	[ebx], ah
   781 0000FBD2 0FB6CC              <1> 	movzx 	ecx, ah
   782 0000FBD5 C0E905              <1> 	shr	cl, 5 ; -> baud rate index
   783 0000FBD8 80E41F              <1> 	and	ah, 1Fh ; communication parameters except baud rate
   784 0000FBDB 8A81[45FC0000]      <1> 	mov	al, [ecx+b_div_tbl]
   785 0000FBE1 6689C1              <1> 	mov	cx, ax
   786 0000FBE4 E896FFFFFF          <1> 	call	sp_i3
   787 0000FBE9 6689C1              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
   788 0000FBEC A880                <1> 	test	al, 80h
   789 0000FBEE 740F                <1> 	jz	short sp_setp2
   790 0000FBF0 C603E3              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
   791                              <1> stp_dnr_err:
   792 0000FBF3 C705[C8030300]0F00- <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
   792 0000FBFB 0000                <1>
   793                              <1> 	; CL = Line status, CH = Modem status
   794 0000FBFD F9                  <1> 	stc
   795 0000FBFE C3                  <1> 	retn
   796                              <1> sp_setp2:
   797 0000FBFF 80FE02              <1> 	cmp	dh, 2 ; COM2 (2F?h)
   798 0000FC02 0F8649FFFFFF        <1>         jna     sp_i6 
   799                              <1> 		      ; COM1 (3F?h)
   800                              <1> sp_i5: 
   801                              <1> 	; 07/11/2015
   802                              <1> 	; 26/10/2015
   803                              <1> 	; 29/06/2015
   804                              <1> 	;
   805                              <1> 	;; COM1 - enabling IRQ 4
   806 0000FC08 9C                  <1> 	pushf
   807 0000FC09 FA                  <1> 	cli
   808 0000FC0A 66BAFC03            <1> 	mov	dx, 3FCh   		; modem control register
   809 0000FC0E EC                  <1> 	in	al, dx 	   		; read register
   810 0000FC0F EB00                <1> 	JMP	$+2			; I/O DELAY
   811 0000FC11 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
   812 0000FC13 EE                  <1> 	out	dx, al     		; write back to register
   813 0000FC14 EB00                <1> 	JMP	$+2			; I/O DELAY
   814 0000FC16 66BAF903            <1> 	mov	dx, 3F9h   		; interrupt enable register
   815 0000FC1A EC                  <1> 	in	al, dx     		; read register
   816 0000FC1B EB00                <1> 	JMP	$+2			; I/O DELAY
   817                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   818 0000FC1D 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
   819 0000FC1F EE                  <1> 	out	dx, al 	   		; write back to register
   820 0000FC20 EB00                <1> 	JMP	$+2        		; I/O DELAY
   821 0000FC22 E421                <1> 	in	al, 21h    		; read interrupt mask register
   822 0000FC24 EB00                <1> 	JMP	$+2			; I/O DELAY
   823 0000FC26 24EF                <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
   824 0000FC28 E621                <1> 	out	21h, al    		; write back to register
   825                              <1> 	;
   826                              <1> 	; 23/10/2015
   827 0000FC2A B8[3AFA0000]        <1> 	mov 	eax, com1_int
   828 0000FC2F A3[4CFC0000]        <1> 	mov	[com1_irq4], eax
   829                              <1> 	; 26/10/2015
   830 0000FC34 9D                  <1> 	popf
   831 0000FC35 C3                  <1> 	retn
   832                              <1> 
   833                              <1> sp_invp_err:
   834 0000FC36 C705[C8030300]1700- <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
   834 0000FC3E 0000                <1>
   835 0000FC40 31C9                <1> 	xor	ecx, ecx
   836 0000FC42 49                  <1> 	dec	ecx ; 0FFFFh
   837 0000FC43 F9                  <1> 	stc
   838 0000FC44 C3                  <1> 	retn
   839                              <1> 
   840                              <1> ; 29/10/2015
   841                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
   842 0000FC45 010C0603080401      <1> 	db 1, 12, 6, 3, 8, 4, 1
   843                              <1> 
   844                              <1> 
   845                              <1> ; 23/10/2015
   846                              <1> com1_irq4:
   847 0000FC4C [54FC0000]          <1> 	dd dummy_retn
   848                              <1> com2_irq3:
   849 0000FC50 [54FC0000]          <1> 	dd dummy_retn
   850                              <1> 
   851                              <1> dummy_retn:
   852 0000FC54 C3                  <1> 	retn
   853                              <1> 
   854                              <1> wakeup:
   855                              <1> 	; 24/01/2016
   856 0000FC55 C3                  <1> 	retn
   857                              <1> 
   858                              <1> set_working_path_x:
   859                              <1> 		; 17/10/2016 (TRDOS 386 - FFF & FNF)
   860 0000FC56 66B80100            <1> 		mov	ax, 1 
   861                              <1> 			; File name is needed/forced (AL=1)
   862                              <1> 			; Change directory as temporary (AH=0)	
   863                              <1> 
   864                              <1> set_working_path_xx: ; 30/12/2017 (syschdir)
   865                              <1> 		; This is needed for preventing wrong Find Next File
   866                              <1> 		; system call after sysopen, syscreate, sysmkdir etc. 
   867                              <1> 		; Find Next File must immediate follow Find First File)
   868                              <1> 
   869 0000FC5A 8825[54650100]      <1> 		mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
   870                              <1> 
   871                              <1> set_working_path:
   872                              <1> 		; 16/10/2016
   873                              <1> 		; 12/10/2016
   874                              <1> 		; 10/10/2016
   875                              <1> 		; 05/10/2016 - TRDOS 386 (TRDOS v2.0)
   876                              <1> 		;
   877                              <1> 		; TRDOS v1.0 (DIR.ASM, "proc_set_working_path")
   878                              <1>                 ; 27/01/2011 - 08/02/2011 
   879                              <1> 		; Set/Changes current drive, directory and file
   880                              <1> 		; depending on command tail
   881                              <1> 		; (procedure is derivated from CMD_INTR.ASM 
   882                              <1> 		; file or dir locating code of internal commands)
   883                              <1> 		; (This procedure is prepared for INT 21H file/dir 
   884                              <1> 		; functions and also to get compact code for 
   885                              <1> 		; internal mainprog -command interpreter- commands)
   886                              <1> 		; 
   887                              <1> 		; INPUT: DS:SI -> Command tail (ASCIIZ string)
   888                              <1> 		; AL = 0 -> any, AL > 0 -> file name is forced
   889                              <1> 		; AH = CD -> Change directory permanently 
   890                              <1> 		; AH <> CD -> Change directory as temporary    
   891                              <1> 		; 
   892                              <1> 		; OUTPUT: ES=DS, FindFile structure has been set
   893                              <1> 		;        RUN_CDRV points previous current drive  
   894                              <1> 		;        DS:SI = FindFile structure address
   895                              <1> 		;        (DS=CS)       
   896                              <1> 		;        AX, BX, CX, DX, DI will be changed
   897                              <1> 		;   cf = 1 -> Error code in AX (AL)
   898                              <1> 		;        stc & AX = 0 -> Bad command or path name 
   899                              <1> 		; -----------------------------------------------
   900                              <1> 		;
   901                              <1> 		; TRDOS 386 (05/10/2016)
   902                              <1> 		; INPUT:
   903                              <1> 		;	ESI = File/Directory Path (ASCIIZ string)
   904                              <1> 		;             address in user's memory space
   905                              <1> 		;       AL = 0 -> any
   906                              <1> 		;       AL > 0 -> file name is forced
   907                              <1> 		;       AH = CD -> change directory as permanent
   908                              <1> 		;       AH <> CD -> change directory as temporary
   909                              <1> 		; 
   910                              <1> 		; OUTPUT:
   911                              <1> 		;	FindFile structure has been set
   912                              <1> 		;       RUN_CDRV points previous current drive  
   913                              <1> 		;       ESI = FindFile_Name address ; 12/10/2016
   914                              <1> 		;
   915                              <1> 		;       cf = 1 -> Error code in EAX (AL)
   916                              <1> 		;       stc & EAX = 0 -> Bad command or path name
   917                              <1> 		;  
   918                              <1> 		; Modified registers: EAX, EBX, ECX, EDX, ESI, EDI
   919                              <1> 
   920 0000FC60 66A3[58650100]      <1> 		mov	[SWP_Mode], ax
   921 0000FC66 A0[6E590100]        <1> 		mov	al, [Current_Drv]
   922 0000FC6B 30E4                <1> 		xor	ah, ah
   923 0000FC6D 66A3[5A650100]      <1> 		mov	[SWP_DRV], ax
   924                              <1> 
   925                              <1> 		; TRDOS 386 ring 3 (user's page directory)
   926                              <1> 		; to ring 0 (kernel's page directory) 
   927                              <1> 		; transfer modifications (05/10/2016).
   928                              <1> 
   929 0000FC73 55                  <1> 		push	ebp
   930 0000FC74 89E5                <1> 		mov	ebp, esp
   931                              <1> 		
   932 0000FC76 B980000000          <1> 		mov	ecx, 128 ; maximum path length = 128 bytes
   933 0000FC7B 29CC                <1> 		sub	esp, ecx ; reserve 128 bytes (buffer) on stack
   934 0000FC7D 89E7                <1> 		mov	edi, esp ; destination address (kernel space)
   935                              <1> 		; esi = source address (virtual, in user's memory space)
   936 0000FC7F E89AEBFFFF          <1> 		call	transfer_from_user_buffer
   937 0000FC84 720A                <1> 		jc	short loc_swp_xor_retn 
   938                              <1> 		
   939 0000FC86 89E6                <1> 		mov	esi, esp ; temporary buffer (the path) on stack
   940                              <1> loc_swp_fchar:
   941 0000FC88 8A06                <1> 		mov	al, [esi]
   942 0000FC8A 3C20                <1> 		cmp	al, 20h
   943 0000FC8C 7711                <1> 		ja	short loc_swp_parse_path_name
   944 0000FC8E 740C                <1> 		je	short loc_swp_fchar_next
   945                              <1> 
   946                              <1> loc_swp_xor_retn:
   947 0000FC90 31C0                <1> 		xor	eax, eax
   948 0000FC92 F9                  <1> 		stc
   949                              <1> loc_swp_retn:
   950 0000FC93 89EC                <1> 		mov	esp, ebp
   951 0000FC95 5D                  <1> 		pop	ebp
   952                              <1> 
   953                              <1> 		;mov	esi, FindFile_Drv
   954 0000FC96 BE[48620100]        <1> 		mov	esi, FindFile_Name ; 12/10/2016
   955 0000FC9B C3                  <1> 		retn 
   956                              <1> 
   957                              <1> loc_swp_fchar_next:
   958 0000FC9C 46                  <1> 		inc	esi
   959 0000FC9D EBE9                <1> 		jmp	short loc_swp_fchar  
   960                              <1> 
   961                              <1> loc_swp_parse_path_name:
   962 0000FC9F BF[06620100]        <1> 		mov	edi, FindFile_Drv
   963 0000FCA4 E8E6A7FFFF          <1> 		call	parse_path_name
   964 0000FCA9 72E8                <1> 		jc	short loc_swp_retn
   965                              <1> 
   966                              <1> loc_swp_checkfile_name:
   967 0000FCAB 803D[58650100]00    <1> 		cmp	byte [SWP_Mode], 0
   968 0000FCB2 761E                <1> 		jna	short loc_swp_drv
   969                              <1> 
   970                              <1> 		; 10/10/2016 (valid file name checking)
   971 0000FCB4 BE[48620100]        <1> 		mov	esi, FindFile_Name
   972 0000FCB9 803E20              <1> 		cmp	byte [esi], 20h
   973 0000FCBC 76D2                <1> 		jna	short loc_swp_xor_retn
   974                              <1> 
   975                              <1> 		; 16/10/2016
   976 0000FCBE C605[57650100]00    <1> 		mov	byte [SWP_inv_fname], 0 ; reset 
   977                              <1> 		; esi = file name address (ASCIIZ)
   978 0000FCC5 E8B289FFFF          <1> 		call	check_filename
   979 0000FCCA 7306                <1> 		jnc	short loc_swp_drv
   980                              <1> 
   981 0000FCCC FE05[57650100]      <1> 		inc	byte [SWP_inv_fname] ; set 	
   982                              <1> loc_swp_drv:
   983 0000FCD2 8A35[6E590100]      <1> 		mov	dh, [Current_Drv]
   984                              <1>                ;mov	[RUN_CDRV], dh
   985                              <1> 
   986 0000FCD8 8A15[06620100]      <1> 		mov	dl, [FindFile_Drv]
   987                              <1>                ;cmp	dl, dh
   988 0000FCDE 3A15[6E590100]      <1> 		cmp	dl, [Current_Drv]
   989 0000FCE4 740D                <1> 		je	short loc_swp_change_directory
   990                              <1> 
   991 0000FCE6 FE05[5B650100]      <1> 		inc	byte [SWP_DRV_chg]
   992 0000FCEC E82A72FFFF          <1> 		call	change_current_drive
   993 0000FCF1 72A0                <1> 		jc	short loc_swp_retn ; eax = error code
   994                              <1> 		; eax = 0
   995                              <1> 
   996                              <1> loc_swp_change_directory:
   997 0000FCF3 803D[07620100]21    <1> 		cmp	byte [FindFile_Directory], 21h
   998 0000FCFA F5                  <1> 		cmc
   999 0000FCFB 7396                <1> 		jnc	short loc_swp_retn
  1000                              <1> 
  1001 0000FCFD FE05[5B650100]      <1> 		inc	byte [SWP_DRV_chg]
  1002 0000FD03 FE05[3B0D0100]      <1> 		inc	byte [Restore_CDIR]
  1003 0000FD09 BE[07620100]        <1> 		mov	esi, FindFile_Directory
  1004 0000FD0E 8A25[59650100]      <1> 		mov	ah, [SWP_Mode+1] 
  1005 0000FD14 E860A1FFFF          <1> 		call	change_current_directory
  1006 0000FD19 0F8274FFFFFF        <1> 		jc	loc_swp_retn ; eax = error code
  1007                              <1> 
  1008                              <1> loc_swp_change_prompt_dir_string:
  1009                              <1> 		; esi = PATH_Array
  1010                              <1> 		; eax = Current Directory First Cluster
  1011                              <1> 		; edi = Logical DOS Drive Description Table	
  1012 0000FD1F E87AA0FFFF          <1> 		call	change_prompt_dir_str 
  1013 0000FD24 29C0                <1> 		sub	eax, eax ; 0
  1014 0000FD26 E968FFFFFF          <1> 		jmp	loc_swp_retn 
  1015                              <1> 
  1016                              <1> reset_working_path:
  1017                              <1> 		; 06/10/2016 - TRDOS 386 (TRDOS v2.0)
  1018                              <1> 		;
  1019                              <1> 		; TRDOS v1.0 (DIR.ASM, "proc_reset_working_path")
  1020                              <1> 		; 05/02/2011 - 08/02/2011 
  1021                              <1> 		;
  1022                              <1> 		; Restores current drive and directory 
  1023                              <1> 		; 
  1024                              <1> 		; INPUT: none
  1025                              <1> 		; OUTPUT: DL = SWP_DRV, EAX = 0 -> OK
  1026                              <1> 		;
  1027                              <1> 		;    AX = 0 -> ESI = Logical Dos Drv Desc. Table
  1028                              <1> 		;
  1029                              <1> 		;    EAX, EBX, ECX, EDX, ESI, EDI will be changed
  1030                              <1> 		;
  1031                              <1> 
  1032                              <1>   
  1033 0000FD2B 31C0                <1> 		xor	eax, eax
  1034 0000FD2D 48                  <1> 		dec	eax 
  1035                              <1> 
  1036 0000FD2E 668B15[5A650100]    <1> 		mov	dx, [SWP_DRV]
  1037 0000FD35 08F6                <1> 		or	dh, dh
  1038 0000FD37 742E                <1> 		jz	short loc_rwp_return
  1039                              <1> 
  1040 0000FD39 3A15[6E590100]      <1> 		cmp	dl, [Current_Drv]
  1041 0000FD3F 7407                <1> 		je	short loc_rwp_restore_cdir
  1042                              <1> loc_rwp_restore_cdrv:
  1043 0000FD41 E8D571FFFF          <1> 		call	change_current_drive 
  1044 0000FD46 EB10                <1> 		jmp	short loc_rwp_restore_ok
  1045                              <1> loc_rwp_restore_cdir:
  1046 0000FD48 31DB                <1> 		xor	ebx, ebx
  1047 0000FD4A 88D7                <1> 		mov	bh, dl
  1048 0000FD4C BE00010900          <1> 		mov	esi, Logical_DOSDisks
  1049 0000FD51 01DE                <1> 		add	esi, ebx
  1050                              <1> 
  1051 0000FD53 E87A72FFFF          <1> 		call	restore_current_directory
  1052                              <1> 
  1053                              <1> loc_rwp_restore_ok:
  1054 0000FD58 668B15[5A650100]    <1> 		mov	dx, [SWP_DRV]
  1055 0000FD5F 31C0                <1> 		xor	eax, eax  
  1056 0000FD61 66A3[5B650100]      <1> 		mov	[SWP_DRV_chg], ax
  1057                              <1> loc_rwp_return:
  1058 0000FD67 C3                  <1> 		retn
  1059                              <1> 
  1060                              <1> get_file_name:
  1061                              <1> 		; 15/10/2016 - TRDOS 386 (TRDOS v2.0)
  1062                              <1> 		; Convert file name 
  1063                              <1> 		;	from directory entry format
  1064                              <1>                 ; 	to (8.3) dot file name format 
  1065                              <1> 		;
  1066                              <1> 		; TRDOS v1.0 (DIR.ASM, "get_file_name")
  1067                              <1>                 ; 2005 - 09/10/2011 	
  1068                              <1> 		; INPUT: 
  1069                              <1> 		;	DS:SI -> Directory Entry Format File Name
  1070                              <1> 		;       ES:DI -> DOS Dot File Name Address
  1071                              <1> 		; OUTPUT:
  1072                              <1> 		;	DS:SI -> DOS Dot File Name Address
  1073                              <1>                 ;	ES:DI -> Directory Entry Format File Name
  1074                              <1> 		;	
  1075                              <1> 		; TRDOS 386 (15/10/2016)
  1076                              <1> 		; INPUT:
  1077                              <1> 		;	ESI = File name addr in dir entry format
  1078                              <1> 		;	EDI = Dot file name address (destination)
  1079                              <1> 		; OUTPUT: 
  1080                              <1> 		;	File name is converted and moved
  1081                              <1> 		;	to destination (as 8.3 dot filename)
  1082                              <1> 		;  
  1083                              <1> 		; Modified registers: EAX, ECX
  1084                              <1> 
  1085                              <1>                 ; 2005 (TRDOS 8086) - 2016 (TRDOS 386)
  1086                              <1>                             
  1087 0000FD68 57                  <1> 		push	edi
  1088 0000FD69 56                  <1> 		push	esi
  1089 0000FD6A AC                  <1> 		lodsb
  1090 0000FD6B 3C20                <1> 		cmp	al, 20h
  1091 0000FD6D 762A                <1> 		jna	short pass_gfn_ext
  1092 0000FD6F 56                  <1> 		push	esi
  1093 0000FD70 AA                  <1> 		stosb
  1094 0000FD71 B907000000          <1> 		mov	ecx, 7
  1095                              <1> loc_gfn_next_char:
  1096 0000FD76 AC                  <1> 		lodsb
  1097 0000FD77 3C20                <1> 		cmp	al, 20h
  1098 0000FD79 7603                <1> 		jna	short pass_gfn_fn
  1099 0000FD7B AA                  <1> 		stosb
  1100 0000FD7C E2F8                <1> 		loop	loc_gfn_next_char
  1101                              <1> pass_gfn_fn:
  1102 0000FD7E 5E                  <1> 		pop	esi
  1103 0000FD7F 83C607              <1> 		add	esi, 7
  1104 0000FD82 AC                  <1> 		lodsb
  1105 0000FD83 3C20                <1> 		cmp	al, 20h
  1106 0000FD85 7612                <1> 		jna	short pass_gfn_ext
  1107 0000FD87 B42E                <1> 		mov	ah, '.'
  1108 0000FD89 86E0                <1> 		xchg	ah, al
  1109 0000FD8B 66AB                <1> 		stosw
  1110 0000FD8D AC                  <1> 		lodsb
  1111 0000FD8E 3C20                <1> 		cmp	al, 20h
  1112 0000FD90 7607                <1> 		jna	short pass_gfn_ext
  1113 0000FD92 AA                  <1> 		stosb
  1114 0000FD93 AC                  <1> 		lodsb
  1115 0000FD94 3C20                <1> 		cmp	al, 20h
  1116 0000FD96 7601                <1> 		jna	short pass_gfn_ext
  1117 0000FD98 AA                  <1> 		stosb
  1118                              <1> pass_gfn_ext:		
  1119 0000FD99 30C0                <1> 		xor	al, al
  1120 0000FD9B AA                  <1> 		stosb
  1121 0000FD9C 5E                  <1> 		pop	esi
  1122 0000FD9D 5F                  <1> 		pop	edi
  1123 0000FD9E C3                  <1> 		retn
  1124                              <1> 
  1125                              <1> set_hardware_int_vector:
  1126                              <1> 		; 18/03/2017
  1127                              <1> 		; 03/03/2017
  1128                              <1> 		; 28/02/2017 - TRDOS 386 (TRDOS v2.0)
  1129                              <1> 		;
  1130                              <1> 		; SET/RESET HARDWARE INTERRUPT GATE
  1131                              <1> 		;
  1132                              <1> 		; Changes interrupt gate descriptor table
  1133                              <1> 		; (without changing default interrupt list)
  1134                              <1> 		;
  1135                              <1> 		; INPUT:
  1136                              <1> 		;	AL = IRQ number (0 to 15)
  1137                              <1> 		;	AH > 0 -> set
  1138                              <1> 		;	AH = 0 -> reset
  1139                              <1> 		;	
  1140                              <1> 		; Modified registers: eax, ebx, edx, edi 
  1141                              <1> 		;
  1142                              <1> 		
  1143 0000FD9F C0E002              <1> 		shl	al, 2 ; IRQ number * 4
  1144 0000FDA2 0FB6D8              <1> 		movzx	ebx, al
  1145                              <1> 
  1146 0000FDA5 08E4                <1> 		or	ah, ah
  1147 0000FDA7 7508                <1> 		jnz	short shintv_1 ; set (for user call service)
  1148                              <1> 		
  1149                              <1> 		; 18/03/2017
  1150 0000FDA9 81C3[38170100]      <1> 		add	ebx, IRQ_list ; reset to default interrupt list
  1151 0000FDAF EB06                <1> 		jmp	short shintv_2
  1152                              <1> shintv_1:
  1153 0000FDB1 81C3[D8FD0000]      <1> 		add	ebx, IRQ_u_list
  1154                              <1> shintv_2:	
  1155 0000FDB7 8B13                <1> 		mov	edx, [ebx] ; IRQ handler address
  1156                              <1> 		
  1157                              <1> 		; 03/03/2017
  1158 0000FDB9 D0E0                <1> 		shl	al, 1 ; IRQ number * 8 
  1159                              <1> 		; 18/03/2017
  1160 0000FDBB 0FB6F8              <1> 		movzx	edi, al 
  1161 0000FDBE 81C7[C0560100]      <1> 		add	edi, idt + (8*32) ; IRQ 0 offset = idt + 256
  1162                              <1> 		
  1163 0000FDC4 89D0                <1> 		mov	eax, edx ; IRQ handler address
  1164 0000FDC6 BB00000800          <1> 		mov	ebx, 80000h
  1165                              <1> 
  1166                              <1> 		;mov	edx, eax
  1167 0000FDCB 66BA008E            <1> 		mov	dx, 8E00h
  1168 0000FDCF 6689C3              <1> 		mov	bx, ax
  1169 0000FDD2 89D8                <1> 		mov	eax, ebx ; /* selector = 0x0008 = cs */
  1170                              <1>        			         ; /* interrupt gate - dpl=0, present */
  1171 0000FDD4 AB                  <1> 		stosd	; selector & offset bits 0-15 	
  1172 0000FDD5 8917                <1> 		mov	[edi], edx ; attributes & offset bits 16-23
  1173                              <1> 
  1174 0000FDD7 C3                  <1> 		retn
  1175                              <1> IRQ_u_list:
  1176                              <1> 		; 28/02/2017
  1177 0000FDD8 [BB060000]          <1> 		dd	timer_int
  1178 0000FDDC [2F0E0000]          <1> 		dd	kb_int
  1179 0000FDE0 [9D080000]          <1> 		dd	irq2
  1180 0000FDE4 [18FE0000]          <1> 		dd	IRQ_service3
  1181 0000FDE8 [22FE0000]          <1> 		dd	IRQ_service4
  1182 0000FDEC [2CFE0000]          <1> 		dd	IRQ_service5
  1183 0000FDF0 [E1410000]          <1> 		dd	fdc_int	
  1184 0000FDF4 [36FE0000]          <1> 		dd	IRQ_service7
  1185 0000FDF8 [26080000]          <1> 		dd	rtc_int
  1186 0000FDFC [40FE0000]          <1> 		dd	IRQ_service9
  1187 0000FE00 [4AFE0000]          <1> 		dd	IRQ_service10
  1188 0000FE04 [54FE0000]          <1> 		dd	IRQ_service11
  1189 0000FE08 [5EFE0000]          <1> 		dd	IRQ_service12
  1190 0000FE0C [68FE0000]          <1> 		dd	IRQ_service13
  1191 0000FE10 [5F4B0000]          <1> 		dd	hdc1_int
  1192 0000FE14 [864B0000]          <1> 		dd	hdc2_int
  1193                              <1> 
  1194                              <1> 		; 03/03/2017
  1195                              <1> 		; 27/02/2017
  1196                              <1> IRQ_service3:
  1197 0000FE18 36C605[1E6B0100]03  <1> 		mov	byte [ss:IRQnum], 3
  1198 0000FE20 EB4E                <1> 		jmp	short IRQ_service
  1199                              <1> IRQ_service4:
  1200 0000FE22 36C605[1E6B0100]04  <1> 		mov	byte [ss:IRQnum], 4
  1201 0000FE2A EB44                <1> 		jmp	short IRQ_service
  1202                              <1> IRQ_service5:
  1203 0000FE2C 36C605[1E6B0100]05  <1> 		mov	byte [ss:IRQnum], 5
  1204 0000FE34 EB3A                <1> 		jmp	short IRQ_service
  1205                              <1> IRQ_service7:
  1206 0000FE36 36C605[1E6B0100]07  <1> 		mov	byte [ss:IRQnum], 7
  1207 0000FE3E EB30                <1> 		jmp	short IRQ_service
  1208                              <1> IRQ_service9:
  1209 0000FE40 36C605[1E6B0100]09  <1> 		mov	byte [ss:IRQnum], 9
  1210 0000FE48 EB26                <1> 		jmp	short IRQ_service
  1211                              <1> IRQ_service10:
  1212 0000FE4A 36C605[1E6B0100]0A  <1> 		mov	byte [ss:IRQnum], 10
  1213 0000FE52 EB1C                <1> 		jmp	short IRQ_service
  1214                              <1> IRQ_service11:
  1215 0000FE54 36C605[1E6B0100]0B  <1> 		mov	byte [ss:IRQnum], 11
  1216 0000FE5C EB12                <1> 		jmp	short IRQ_service
  1217                              <1> IRQ_service12:
  1218 0000FE5E 36C605[1E6B0100]0C  <1> 		mov	byte [ss:IRQnum], 12
  1219 0000FE66 EB08                <1> 		jmp	short IRQ_service
  1220                              <1> IRQ_service13:
  1221 0000FE68 36C605[1E6B0100]0D  <1> 		mov	byte [ss:IRQnum], 13
  1222                              <1> 		;jmp	short IRQ_service
  1223                              <1> IRQ_service:
  1224                              <1> 		; 13/06/2017
  1225                              <1> 		; 11/06/2017
  1226                              <1> 		; 10/06/2017
  1227                              <1> 		; 01/03/2017, 04/03/2017
  1228                              <1> 		; 27/02/2017, 28/02/2017
  1229 0000FE70 1E                  <1> 		push	ds
  1230 0000FE71 06                  <1> 		push	es
  1231 0000FE72 0FA0                <1> 		push	fs
  1232 0000FE74 0FA8                <1> 		push	gs
  1233                              <1> 
  1234 0000FE76 60                  <1> 		pushad	; eax,ecx,edx,ebx,esp,ebp,esi,edi
  1235 0000FE77 66B91000            <1> 		mov     cx, KDATA
  1236 0000FE7B 8ED9                <1>         	mov     ds, cx
  1237 0000FE7D 8EC1                <1>         	mov     es, cx
  1238 0000FE7F 8EE1                <1>         	mov     fs, cx
  1239 0000FE81 8EE9                <1>         	mov     gs, cx
  1240                              <1> 
  1241 0000FE83 0F20D8              <1> 		mov	eax, cr3
  1242 0000FE86 A3[1A6B0100]        <1> 		mov	[IRQ_cr3], eax
  1243                              <1> 
  1244 0000FE8B A1[A8580100]        <1> 		mov	eax, [k_page_dir]
  1245 0000FE90 0F22D8              <1> 		mov	cr3, eax 
  1246                              <1> 
  1247 0000FE93 A0[1E6B0100]        <1> 		mov	al, [IRQnum]
  1248                              <1> 
  1249                              <1> 		;mov	cl, [sysflg]
  1250                              <1> 		;mov	[u.r_mode], cl  ; system (0) or user mode (FFh) 
  1251                              <1> IRQsrv_0:
  1252 0000FE98 0FB6D8              <1> 		movzx	ebx, al
  1253 0000FE9B 8A9B[70160100]      <1> 		mov	bl, [ebx+IRQenum] ; IRQ (available) index number + 1
  1254                              <1> 		; 01/03/2017
  1255 0000FEA1 FECB                <1> 		dec	bl  ; IRQ index number, 0 to 8
  1256 0000FEA3 0F8807010000        <1> 		js	IRQsrv_5 ; not available to use here!?
  1257                              <1> 		;		 
  1258 0000FEA9 80BB[E46A0100]80    <1> 		cmp	byte [ebx+IRQ.method], 80h ; using by a dev or kernel? 
  1259 0000FEB0 7205                <1> 		jb	short IRQsrv_1 ; no
  1260                              <1> 
  1261                              <1> 		; If the IRQ service is already owned by TRDOS 386 kernel
  1262                              <1> 		;	 or a Device driver
  1263                              <1> 		; we need to call 'dev_IRQ_service'
  1264                              <1> 
  1265                              <1> 		; IRQ number in AL
  1266 0000FEB2 E868020000          <1> 		call	dev_IRQ_service	 ; IRQ service for device drivers	
  1267                              <1> 		; IRQ number in AL
  1268                              <1> IRQsrv_1:		
  1269                              <1> 		; check user callback service status
  1270                              <1> 		; AL = IRQ number
  1271                              <1> 		; EBX = IRQ (Available) Index number
  1272                              <1> 
  1273 0000FEB7 A2[D7030300]        <1> 		mov	[u.irqwait], al ; set waiting IRQ flag
  1274                              <1> 
  1275 0000FEBC 8A83[D26A0100]      <1> 		mov	al, [ebx+IRQ.owner]
  1276 0000FEC2 20C0                <1> 		and	al, al
  1277 0000FEC4 0F84E6000000        <1> 		jz	IRQsrv_5 ; it is not owned by a user/proc
  1278                              <1> 
  1279                              <1> 		; 03/03/2017
  1280 0000FECA 89DA                <1> 		mov	edx, ebx
  1281 0000FECC C0E202              <1> 		shl	dl, 2
  1282 0000FECF 8B92[F66A0100]      <1> 		mov	edx, [edx+IRQ.addr] ; S.R.B. or Callback service addr
  1283                              <1> 		
  1284 0000FED5 8AA3[E46A0100]      <1> 		mov	ah, [ebx+IRQ.method]
  1285 0000FEDB F6C401              <1> 		test	ah, 1
  1286 0000FEDE 7534                <1> 		jnz	short IRQsrv_4 ; Callback service method
  1287                              <1> 
  1288                              <1> 		; Signal Response Byte method
  1289                              <1> 		;mov	edx, [edx+IRQ.addr] ; Signal Response Byte address
  1290                              <1> 		;			    ; (Physical address, non-swappable) 	
  1291 0000FEE0 80E402              <1> 		and	ah, 2 ; bit 1, (S.R.B.) counter (auto increment) method
  1292 0000FEE3 8AA3[ED6A0100]      <1> 		mov	ah, [ebx+IRQ.srb] ; Signal Response Byte value
  1293 0000FEE9 7408                <1> 		jz	short IRQsrv_2 ; fixed S.R.B. value
  1294                              <1> 		; counter method (auto increment)
  1295 0000FEEB FEC4                <1> 		inc	ah
  1296 0000FEED 88A3[ED6A0100]      <1> 		mov	[ebx+IRQ.srb], ah ; next (count) number
  1297                              <1> IRQsrv_2:
  1298 0000FEF3 8822                <1> 		mov	[edx], ah ; put S.R.B. val to the user's S.R.B. addr
  1299 0000FEF5 C605[D7030300]00    <1> 		mov	byte [u.irqwait], 0 ; clear waiting IRQ flag
  1300                              <1> 
  1301 0000FEFC 3A05[B3030300]      <1> 		cmp	al, [u.uno]
  1302 0000FF02 0F84A8000000        <1> 		je	IRQsrv_5 ; the owner is current user/process
  1303                              <1> IRQsrv_3:
  1304                              <1> 		; the owner is not current user/process
  1305                              <1> 		; AL = process number
  1306 0000FF08 B202                <1> 		mov	dl, 2 ; priority, 2 = event (high)	
  1307 0000FF0A E837FAFFFF          <1> 		call	set_run_sequence
  1308                              <1> 
  1309                              <1> 		; [u.irqwait] = waiting IRQ number for callback service
  1310                              <1> 
  1311 0000FF0F E99C000000          <1> 		jmp	IRQsrv_5
  1312                              <1> IRQsrv_4:
  1313 0000FF14 3A05[B3030300]      <1> 		cmp	al, [u.uno]  ; is the owner is current user/process?
  1314 0000FF1A 75EC                <1> 		jne	short IRQsrv_3 ; no !
  1315                              <1> 
  1316                              <1> 		; Check if an IRQ callback service already in progress
  1317 0000FF1C 803D[D8030300]00    <1> 		cmp	byte [u.r_lock], 0
  1318 0000FF23 0F8787000000        <1> 		ja	IRQsrv_5 ; nothing to do !  
  1319                              <1> 				     ; (we need to complete prev callback)
  1320 0000FF29 803D[D4030300]00    <1> 		cmp	byte [u.t_lock], 0
  1321 0000FF30 777E                <1> 		ja	short IRQsrv_5 ; nothing to do !  
  1322                              <1> 				     ; (we need to complete timer callback)
  1323                              <1> 
  1324                              <1> 		; 04/03/2017
  1325 0000FF32 C605[D7030300]00    <1> 		mov	byte [u.irqwait], 0 ; reset/clear waiting IRQ flag
  1326                              <1> 
  1327 0000FF39 FE05[D8030300]      <1> 		inc	byte [u.r_lock] ; 'IRQ callback service in progress' flag
  1328                              <1> 
  1329 0000FF3F 8A0D[5B030300]      <1> 		mov	cl, [sysflg]   ; (system call) mode flag (kernel/user)
  1330 0000FF45 880D[D9030300]      <1> 		mov	[u.r_mode], cl ; system mode (0) or user mode (FFh)
  1331                              <1> 
  1332                              <1> 		; 
  1333 0000FF4B 8B2D[44580100]      <1> 		mov	ebp, [tss.esp0] ; kernel stack address (for ring 0)
  1334 0000FF51 83ED14              <1> 		sub	ebp, 20		; eip, cs, eflags, esp, ss
  1335 0000FF54 892D[5C030300]      <1> 	 	mov	[u.sp], ebp
  1336 0000FF5A 8925[60030300]      <1> 		mov	[u.usp], esp
  1337                              <1> 
  1338                              <1> 		;or	word [ebp+8], 200h ; 22/01/2017, force enabling interrupts
  1339                              <1> 
  1340 0000FF60 8B44241C            <1> 		mov	eax, [esp+28] ; pushed eax
  1341 0000FF64 A3[64030300]        <1> 		mov	[u.r0], eax
  1342                              <1> 
  1343 0000FF69 E81AE7FFFF          <1> 		call	wswap ; save user's registers & status
  1344                              <1> 
  1345                              <1> 		; software int is in ring 0 but IRQ handler must return to ring 3
  1346                              <1> 		; so, ring 3 return address and stack registers
  1347                              <1> 		; (eip, cs, eflags, esp, ss) 
  1348                              <1> 		; must be copied to IRQ handler return
  1349                              <1> 		; eip will be replaced by callback service routine address
  1350                              <1> 
  1351 0000FF6E C605[5B030300]FF    <1> 		mov	byte [sysflg], 0FFh ; user mode
  1352                              <1> 
  1353                              <1> 		; system mode (system call)
  1354                              <1> 		;mov	ebp, [u.sp] ; EIP (u), CS (UCODE), EFLAGS (u),
  1355                              <1> 				    ; ESP (u), SS (UDATA)
  1356                              <1> 
  1357 0000FF75 8B4510              <1> 		mov	eax, [ebp+16]	; SS (UDATA)
  1358 0000FF78 89E6                <1> 		mov	esi, esp
  1359 0000FF7A 50                  <1> 		push	eax
  1360 0000FF7B 50                  <1> 		push	eax
  1361 0000FF7C 89E7                <1> 		mov	edi, esp
  1362 0000FF7E 893D[60030300]      <1> 		mov	[u.usp], edi
  1363 0000FF84 B908000000          <1> 		mov	ecx, ((ESPACE/4) - 4) ; except DS, ES, FS, GS
  1364 0000FF89 F3A5                <1> 		rep	movsd
  1365 0000FF8B B104                <1> 		mov	cl, 4	
  1366 0000FF8D F3AB                <1> 		rep	stosd
  1367 0000FF8F 893D[5C030300]      <1> 		mov	[u.sp], edi
  1368 0000FF95 89EE                <1> 		mov	esi, ebp
  1369 0000FF97 B105                <1> 		mov	cl, 5 ; EIP (u), CS (UCODE), EFLAGS (u), ESP (u), SS (UDATA)
  1370 0000FF99 F3A5                <1> 		rep	movsd
  1371                              <1> 		;
  1372                              <1> 
  1373 0000FF9B 8B0D[B8030300]      <1> 		mov	ecx, [u.pgdir]
  1374 0000FFA1 890D[1A6B0100]      <1> 		mov	[IRQ_cr3], ecx
  1375                              <1> 
  1376                              <1> set_IRQ_callback_addr:
  1377                              <1> 		;
  1378                              <1> 		; This routine sets return address
  1379                              <1> 		; to start of user's interrupt
  1380                              <1> 		; service (callback) address
  1381                              <1> 		;
  1382                              <1> 		; INPUT:
  1383                              <1> 		;	EDX = callback routine/service address
  1384                              <1> 		;	      (virtual, not physical address!)	
  1385                              <1> 		;	[u.sp] = kernel stack, points to
  1386                              <1> 		;		 user's EIP,CS,EFLAGS,ESP,SS
  1387                              <1> 		;		 registers.
  1388                              <1> 		; OUTPUT:
  1389                              <1> 		;	EIP (user) = callback (service) address
  1390                              <1> 		;	CS (user) = UCODE
  1391                              <1> 		;	EFLAGS (user) = flags before callback 	 
  1392                              <1> 		;       ESP (user) = ESP-4 (user, before callback) 
  1393                              <1> 		;	[ESP](user) = EIP (user) before callback
  1394                              <1> 		;
  1395                              <1> 		; Note: If CPU was in user mode while entering 
  1396                              <1> 		;	the timer interrupt service routine,
  1397                              <1> 		;	'IRET' will get return to callback routine
  1398                              <1> 		;	immediately. If CPU was in system/kernel mode  
  1399                              <1> 		;	'iret' will get return to system call and
  1400                              <1> 		;	then, callback routine will be return address
  1401                              <1> 		;	from system call. (User's callback/service code
  1402                              <1> 		;	will be able to return to normal return address
  1403                              <1> 		;	via a 'sysrele' system call at the end.) 
  1404                              <1> 		;
  1405                              <1> 		; Note: User's IRQ callback service code must be ended
  1406                              <1> 		;	with a 'sysrele' system call !
  1407                              <1> 		;
  1408                              <1> 		;	For example:
  1409                              <1> 		;
  1410                              <1> 		;	audio_IRQ_callback:
  1411                              <1> 		;	    ...	 
  1412                              <1> 		;	    <load DMA buffer with audio data>
  1413                              <1> 		;	    ...
  1414                              <1> 		;	    mov eax, 39 ; 'sysrele'
  1415                              <1> 		;	    int 40h ; TRDOS 386 system call (interrupt)		
  1416                              <1> 		;
  1417                              <1> 		
  1418                              <1> 		;mov	edx, [edx+IRQ.addr] ; Callback service address
  1419                              <1> 		;			    ; (Virtual address)
  1420                              <1> 		
  1421 0000FFA7 8B2D[5C030300]      <1> 		mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
  1422 0000FFAD 895500              <1> 		mov	[ebp], edx
  1423                              <1> IRQsrv_5:
  1424                              <1> 		; EOI & return
  1425                              <1> 		; 11/06/2017
  1426                              <1> 		; 10/06/2017 
  1427 0000FFB0 A0[1E6B0100]        <1> 		mov	al, [IRQnum]
  1428 0000FFB5 FA                  <1> 		cli
  1429 0000FFB6 3C07                <1> 		cmp	al, 7	
  1430 0000FFB8 7604                <1> 		jna	short IRQsrv_6
  1431                              <1> 		;
  1432                              <1> 		;mov	al, EOI	; end of interrupt
  1433 0000FFBA B020                <1> 		mov	al, 20h
  1434                              <1> 		;cli		; disable interrupts till stack cleared
  1435                              <1> 		;out	INTB00, al ; For controll2 #2
  1436 0000FFBC E6A0                <1> 		out	0A0h, al
  1437                              <1> IRQsrv_6:
  1438                              <1> 		;mov	byte [IRQnum], 0 ; reset
  1439                              <1> 		;mov	al, EOI	; end of interrupt
  1440 0000FFBE B020                <1> 		mov	al, 20h
  1441                              <1> 		;cli		; disable interrupts till stack cleared
  1442                              <1> 		;out	INTA00, al ; end of interrupt to 8259 - 1
  1443 0000FFC0 E620                <1> 		out	20h, al	
  1444                              <1> IRQsrv_7:	
  1445                              <1> 		;; 13/06/2017
  1446                              <1> 		;or	word [ebp+8], 200h ; force enabling interrupts
  1447                              <1> 		;
  1448 0000FFC2 8B0D[1A6B0100]      <1> 		mov 	ecx, [IRQ_cr3]	; previous content of cr3 register
  1449 0000FFC8 0F22D9              <1>  		mov	cr3, ecx	; restore cr3 register content
  1450                              <1> 		;
  1451 0000FFCB 61                  <1> 		popad ; edi,esi,ebp,(icrement esp by 4), ebx,edx,ecx,eax
  1452                              <1> 		;
  1453 0000FFCC 0FA9                <1> 		pop	gs
  1454 0000FFCE 0FA1                <1> 		pop	fs
  1455 0000FFD0 07                  <1> 		pop	es
  1456 0000FFD1 1F                  <1> 		pop	ds
  1457                              <1> 		;
  1458 0000FFD2 CF                  <1> 		iretd	; return from interrupt
  1459                              <1> 
  1460                              <1> get_device_number:
  1461                              <1> 		; 08/10/2016
  1462                              <1> 		; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1463                              <1> 		;
  1464                              <1> 		; This procedure compares name of requested
  1465                              <1> 		; device with kernel device names and
  1466                              <1> 		; installable device names. If names match, 
  1467                              <1> 		; the relevant device index (entry) number 
  1468                              <1> 		; will be returned the caller (sysopen) 
  1469                              <1> 		; for the requested device.
  1470                              <1> 		;
  1471                              <1> 		; NOTE: Installable device drivers must
  1472                              <1> 		; be loaded before using 'sysopen'
  1473                              <1> 		; (opendev) system call.
  1474                              <1> 		;
  1475                              <1> 		; INPUT:
  1476                              <1> 		;    ESI = device name address (ASCIIZ)
  1477                              <1> 		;         (in kernel's memory space)  
  1478                              <1>    		;    max name length = 8 without '/dev/')
  1479                              <1> 		;    Device name will be capitalized 
  1480                              <1> 		;    and if there is, '/dev/' will be
  1481                              <1> 		;    removed from name before comparising)
  1482                              <1> 		;
  1483                              <1> 		; OUTPUT:
  1484                              <1> 		;    cf = 0 -> 
  1485                              <1> 		;      EAX (AL) = device entry/index number 	 	
  1486                              <1> 		;    cf = 1 -> device not found (installed)
  1487                              <1> 		;	       or invalid device name
  1488                              <1> 		;	       (AL=0)
  1489                              <1> 		;    device_name = device name address (asciiz)
  1490                              <1> 			;
  1491                              <1> 		; Modified registers: EAX, EBX, ESI, EDI
  1492                              <1> 
  1493 0000FFD3 BF[5D650100]        <1> 		mov	edi, device_name
  1494 0000FFD8 E805010000          <1> 		call 	lodsb_capitalize
  1495 0000FFDD 88C4                <1> 		mov	ah, al
  1496 0000FFDF 3C2F                <1> 		cmp	al, '/'
  1497 0000FFE1 750E                <1> 		jne	short gdn_1
  1498 0000FFE3 BF[5D650100]        <1> 		mov	edi, device_name
  1499 0000FFE8 E8F5000000          <1> 		call 	lodsb_capitalize
  1500                              <1> gdn_0:
  1501 0000FFED 20C0                <1> 		and	al, al ; 0 ?
  1502 0000FFEF 7420                <1> 		jz	short gdn_err ; null name after '/'
  1503                              <1> gdn_1:
  1504 0000FFF1 3C44                <1> 		cmp	al, 'D'
  1505 0000FFF3 7517                <1> 		jne	short gdn_2
  1506 0000FFF5 E8E8000000          <1> 		call 	lodsb_capitalize
  1507 0000FFFA 3C45                <1> 		cmp	al, 'E'
  1508 0000FFFC 750E                <1> 		jne	short gdn_2
  1509 0000FFFE E8DF000000          <1> 		call 	lodsb_capitalize
  1510 00010003 3C56                <1> 		cmp	al, 'V'
  1511 00010005 7505                <1> 		jne	short gdn_2			
  1512 00010007 AC                  <1> 		lodsb
  1513 00010008 3C2F                <1> 		cmp	al, '/'
  1514 0001000A 740D                <1> 		je	short gdn_4
  1515                              <1> gdn_2:
  1516 0001000C 80FC2F              <1> 		cmp	ah, '/'
  1517 0001000F 750F                <1> 		jne	short gdn_5
  1518                              <1> gdn_err:		
  1519                              <1> 		; invalid device name or device not found
  1520 00010011 31C0                <1> 		xor	eax, eax ; 0
  1521 00010013 F9                  <1> 		stc
  1522 00010014 C3                  <1> 		retn
  1523                              <1> gdn_3:
  1524 00010015 3C2F                <1> 		cmp	al, '/'
  1525 00010017 7507                <1> 		jne	short gdn_5
  1526                              <1> gdn_4:
  1527 00010019 BF[5D650100]        <1> 		mov	edi, device_name
  1528 0001001E EB04                <1> 		jmp	short gdn_6
  1529                              <1> gdn_5:
  1530 00010020 3C00                <1> 		cmp	al, 0
  1531 00010022 7419                <1> 		je	short gdn_7
  1532                              <1> gdn_6:
  1533 00010024 E8B9000000          <1> 		call lodsb_capitalize
  1534 00010029 81FF[65650100]      <1> 		cmp	edi, device_name + 8
  1535 0001002F 72E4                <1> 		jb	short gdn_3
  1536 00010031 3C00                <1> 		cmp	al, 0
  1537 00010033 75DC                <1> 		jne	short gdn_err
  1538 00010035 81FF[5E650100]      <1> 		cmp	edi, device_name + 1
  1539 0001003B 76D4                <1> 		jna	short gdn_err ; null name after '/'
  1540                              <1> gdn_7:
  1541 0001003D AA                  <1> 		stosb
  1542                              <1> 		; zero padding ("NAME",0,0,0,0)
  1543 0001003E 81FF[65650100]      <1> 		cmp	edi, device_name + 8
  1544 00010044 72F7                <1> 		jb	short gdn_7
  1545                              <1> gdn_8:
  1546                              <1> 		; search for kernel device names
  1547 00010046 BE[5D650100]        <1> 		mov	esi, device_name 
  1548 0001004B BF[56140100]        <1> 		mov	edi, KDEV_NAME
  1549 00010050 31C0                <1> 		xor	eax, eax
  1550                              <1> gdn_9:
  1551 00010052 A7                  <1> 		cmpsd	
  1552 00010053 7505                <1> 		jne	short gdn_10
  1553 00010055 A7                  <1> 		cmpsd
  1554 00010056 7503                <1> 		jne	short gdn_11
  1555 00010058 EB2B                <1> 		jmp	short gdn_17 ; match
  1556                              <1> gdn_10:
  1557 0001005A A7                  <1> 		cmpsd  ; add esi, 4 & add edi, 4
  1558                              <1> gdn_11:
  1559 0001005B BE[5D650100]        <1> 		mov	esi, device_name
  1560 00010060 FEC0                <1> 		inc	al
  1561 00010062 3C16                <1> 		cmp	al, NumOfKernelDevNames
  1562 00010064 72EC                <1> 		jb	short gdn_9
  1563                              <1> gdn_12:
  1564                              <1> 		; search for installable device names
  1565                              <1> 		; esi = offset device_name 
  1566 00010066 BF[88650100]        <1> 		mov	edi, IDEV_NAME
  1567 0001006B 28C0                <1> 		sub	al, al ; 0
  1568                              <1> gdn_13:
  1569 0001006D A7                  <1> 		cmpsd	
  1570 0001006E 7505                <1> 		jne	short gdn_14
  1571 00010070 A7                  <1> 		cmpsd
  1572 00010071 7503                <1> 		jne	short gdn_15
  1573 00010073 EB3F                <1> 		jmp	short gdn_19 ; match
  1574                              <1> gdn_14:
  1575 00010075 A7                  <1> 		cmpsd  ; add esi, 4 & add edi, 4
  1576                              <1> gdn_15:
  1577 00010076 BE[5D650100]        <1> 		mov	esi, device_name
  1578 0001007B FEC0                <1> 		inc	al
  1579 0001007D 3C08                <1> 		cmp	al, NumOfInstallableDevices
  1580 0001007F 72EC                <1> 		jb	short gdn_13
  1581                              <1> 
  1582                              <1> gdn_16: 	; error: invalid device name (not found) !
  1583 00010081 30C0                <1> 		xor	al, al
  1584 00010083 F9                  <1> 		stc
  1585 00010084 C3                  <1> 		retn
  1586                              <1> 
  1587                              <1> gdn_17:		; name match (with one of kernel device names)
  1588                              <1> 		;
  1589                              <1> 		; convert KDEV_NAME index to 
  1590                              <1> 		; KDEV_NUMBER index
  1591                              <1> 		; (different names are used for same devices)
  1592                              <1> 		; (example: "COM1" & "TTY8" = device number 18) 
  1593 00010085 89C3                <1> 		mov	ebx, eax ; < 256
  1594 00010087 8A83[06150100]      <1> 		mov	al, [KDEV_NUMBER+ebx]
  1595                              <1> 
  1596                              <1> 		; check if empty dev entry in the list
  1597 0001008D 80B8[0C670100]00    <1> 		cmp	byte [DEV_OPENMODE+eax], 0
  1598 00010094 771B                <1> 		ja	short gdn_18 ; it must be already set
  1599                              <1> 
  1600                              <1> 		; (re)set device name and access flags
  1601                              <1> 		; (remain open work will be easy after that)
  1602                              <1> 		; (NOTE: here, data will be copied to bss section)
  1603 00010096 88C3                <1> 		mov	bl, al
  1604 00010098 83EF08              <1> 		sub	edi, 8 ; kernel device name address (data)
  1605 0001009B 66C1E302            <1> 		shl	bx, 2 
  1606 0001009F 89BB[2A670100]      <1> 		mov	[DEV_NAME_PTR+ebx], edi ; (all) device names
  1607 000100A5 8A98[5C160100]      <1> 		mov	bl, [KDEV_ACCESS+eax] ; kernel dev list (data)
  1608 000100AB 8898[58660100]      <1> 		mov	[DEV_ACCESS+eax], bl ; (all) device list (bss)
  1609                              <1> gdn_18:
  1610 000100B1 FEC0                <1> 		inc	al ; 1 to NumOfKernelDevNames (<=7Fh)
  1611                              <1> 		; eax = device index/entry number
  1612 000100B3 C3                  <1> 		retn		
  1613                              <1> 
  1614                              <1> gdn_19:		; name match (with one of installable device names)
  1615                              <1> 		;
  1616                              <1> 		; al = 0 to NumOfInstallableDevices - 1 (<=7Fh)
  1617                              <1> 
  1618 000100B4 89C3                <1> 		mov	ebx, eax
  1619 000100B6 80C316              <1> 		add	bl, NumOfKernelDevices 	; < NUMOFDEVICES	
  1620                              <1> 
  1621                              <1> 		; check if empty dev entry in the list
  1622 000100B9 80BB[0C670100]00    <1> 		cmp	byte [DEV_OPENMODE+ebx], 0
  1623 000100C0 771D                <1> 		ja	short gdn_20 ; it must be already set
  1624                              <1> 
  1625                              <1> 		; (re)set device name and access flags
  1626                              <1> 		; (remain open work will be easy after that)
  1627 000100C2 83EF08              <1> 		sub	edi, 8 ; installable device name address
  1628 000100C5 66C1E302            <1> 		shl	bx, 2 ;*4
  1629 000100C9 89BB[2A670100]      <1> 		mov	[DEV_NAME_PTR+ebx], edi ; (all) device names
  1630 000100CF 66C1EB02            <1> 		shr	bx, 2
  1631 000100D3 8A80[D0650100]      <1> 		mov	al, [IDEV_FLAGS+eax] ; installable dev list
  1632 000100D9 8883[58660100]      <1> 		mov	[DEV_ACCESS+ebx], al ; (all) device list
  1633                              <1> gdn_20:	
  1634 000100DF 88D8                <1> 		mov	al, bl
  1635                              <1> 		; eax = device index/entry number ; < NUMOFDEVICES  
  1636 000100E1 C3                  <1> 		retn
  1637                              <1> 
  1638                              <1> lodsb_capitalize:
  1639                              <1> 	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1640                              <1> 	; INPUT -> [esi] = character
  1641                              <1> 	;          edi = destination
  1642                              <1> 	; OUTPUT -> AL contains capitalized character
  1643                              <1> 	;	   esi = esi+1
  1644                              <1> 	;	   edi = edi+1	
  1645                              <1> 	; 
  1646 000100E2 AC                  <1> 	lodsb	
  1647 000100E3 3C61                <1> 	cmp al, 61h
  1648 000100E5 7206                <1>      	jb  short lodsb_cap_retn
  1649 000100E7 3C7A                <1>      	cmp al, 7Ah
  1650 000100E9 7702                <1>      	ja  short lodsb_cap_retn
  1651 000100EB 24DF                <1>      	and al, 0DFh
  1652                              <1> lodsb_cap_retn:
  1653 000100ED AA                  <1> 	stosb
  1654 000100EE C3                  <1> 	retn
  1655                              <1> 
  1656                              <1> device_open:
  1657                              <1> 	; 08/10/2016 - TRDOS 386 (TRDOS v2.0)
  1658                              <1> 	; Complete device opening work for sysopen (device)
  1659                              <1> 	;
  1660                              <1> 	; INPUT -> 
  1661                              <1> 	;	EAX = Device Number (AL)
  1662                              <1> 	;        CL = Open mode (1 = read, 2 = write)
  1663                              <1> 	;	 CH = Device access byte (bit 0 = 0)		
  1664                              <1> 	; OUTPUT ->
  1665                              <1> 	;	EAX = Device Number	
  1666                              <1> 	;	CF = 0 -> device has been opened
  1667                              <1> 	;	CF = 1 -> device could not be opened
  1668                              <1> 	;
  1669                              <1> 	;  Modified registers: ebx, (edx, ecx, esi, edi, ebp)
  1670                              <1> 	;
  1671                              <1> 
  1672 000100EF 89C3                <1> 	mov	ebx, eax
  1673 000100F1 66C1E302            <1> 	shl	bx, 2 ; *4
  1674                              <1> 
  1675 000100F5 F6C580              <1> 	test	ch, 80h ; bit 7, installable device driver flag
  1676 000100F8 7406                <1> 	jz	short d_open_2 ; Kernel device
  1677                              <1> 	; installable device
  1678                              <1> d_open_1:
  1679 000100FA FFA3[D4650100]      <1>         jmp	dword [ebx+IDEV_OADDR-4]
  1680                              <1> d_open_2:
  1681 00010100 FFA3[18150100]      <1> 	jmp	dword [ebx+KDEV_OADDR-4]
  1682                              <1> 
  1683                              <1> device_close:
  1684                              <1> 	; 08/10/2016 - TRDOS 386 (TRDOS v2.0)
  1685                              <1> 	; Complete device closing work for sysclose (device)
  1686                              <1> 	;
  1687                              <1> 	; INPUT -> 
  1688                              <1> 	;	EAX = Device Number (AL)
  1689                              <1> 	;        CL = Open mode (1 = read, 2 = write)
  1690                              <1> 	;	 CH = Device access byte (bit 0 = 0)		
  1691                              <1> 	; OUTPUT ->
  1692                              <1> 	;	EAX = Device Number	
  1693                              <1> 	;	CF = 0 -> device has been closed
  1694                              <1> 	;	CF = 1 -> device could not be closed
  1695                              <1> 	;
  1696                              <1> 	; Modified registers: ebx, (edx, ecx, esi, edi, ebp)
  1697                              <1> 	;
  1698                              <1> 
  1699 00010106 89C3                <1> 	mov	ebx, eax
  1700 00010108 66C1E302            <1> 	shl	bx, 2 ; *4
  1701                              <1> 
  1702 0001010C F6C580              <1> 	test	ch, 80h ; bit 7, installable device driver flag
  1703 0001010F 7406                <1> 	jz	short d_close_2 ; Kernel device
  1704                              <1> 	; installable device
  1705                              <1> d_close_1:
  1706 00010111 FFA3[F4650100]      <1>         jmp	dword [ebx+IDEV_CADDR-4]
  1707                              <1> d_close_2:
  1708 00010117 FFA3[68150100]      <1> 	jmp	dword [ebx+KDEV_CADDR-4]	
  1709                              <1> 
  1710                              <1> rnull:
  1711                              <1> 	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1712                              <1> 	; read null (read from null device)
  1713 0001011D C3                  <1> 	retn
  1714                              <1> 
  1715                              <1> wnull:
  1716                              <1> 	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1717                              <1> 	; write null (write to null device)
  1718 0001011E C3                  <1> 	retn
  1719                              <1> 
  1720                              <1> dev_IRQ_service:
  1721                              <1> 	; 12/05/2017
  1722                              <1> 	; 13/04/2017
  1723                              <1> 	; 27/02/2017 - TRDOS 386 (TRDOS v2.0)
  1724                              <1> 	; INPUT ->
  1725                              <1> 	;	AL = IRQ Number (0 to 15)
  1726                              <1> 	;	
  1727 0001011F 53                  <1> 	push	ebx
  1728 00010120 0FB6D8              <1> 	movzx	ebx, al
  1729 00010123 C0E302              <1> 	shl	bl, 2 ; * 4	
  1730 00010126 8B9B[926A0100]      <1> 	mov	ebx, [ebx+DEV_INT_HNDLR]
  1731 0001012C 21DB                <1> 	and 	ebx, ebx
  1732 0001012E 7404                <1>         jz	short dIRQ_s_retn
  1733 00010130 50                  <1> 	push	eax
  1734                              <1> 
  1735 00010131 FFD3                <1> 	call	ebx
  1736                              <1> 
  1737 00010133 58                  <1> 	pop	eax
  1738                              <1> dIRQ_s_retn:
  1739 00010134 5B                  <1> 	pop	ebx
  1740 00010135 C3                  <1> 	retn		
  1741                              <1> 
  1742                              <1> 
  1743                              <1> set_dev_IRQ_service:
  1744                              <1> 	; 13/04/2017 - TRDOS 386 (TRDOS v2.0)
  1745                              <1> 	;
  1746                              <1> 	; Set Device Interrupt Service
  1747                              <1> 	;
  1748                              <1> 	; INPUT ->
  1749                              <1> 	;	AL = IRQ Number
  1750                              <1> 	;	EBX = Hardware Interrupt Service Address
  1751                              <1> 	;
  1752                              <1> 	; Note: There is not a validation check here
  1753                              <1> 	;	because this procedure is called by
  1754                              <1> 	;	TRDOS 386 kernel !
  1755                              <1> 	;       (Even if a device driver does not exist
  1756                              <1> 	;	this setting may be used by sysaudio
  1757                              <1> 	;	and other system calls for hardware
  1758                              <1> 	;	components which use IRQ method for I/O.)
  1759                              <1> 	;
  1760                              <1> 	;push	esi
  1761 00010136 0FB6F0              <1> 	movzx	esi, al
  1762 00010139 66C1E602            <1> 	shl	si, 2 ; * 4	
  1763 0001013D 899E[926A0100]      <1> 	mov	[esi+DEV_INT_HNDLR], ebx
  1764                              <1> 	;pop	esi
  1765 00010143 C3                  <1> 	retn		
  1766                              <1> 	
  1767                              <1> 
  1768                              <1> sysaudio: ; AUDIO FUNCTIONS
  1769                              <1> 	; 28/07/2020
  1770                              <1> 	; 27/07/2020
  1771                              <1> 	; 10/10/2017
  1772                              <1> 	; 22/06/2017
  1773                              <1> 	; 28/05/2017, 04/06/2017, 05/06/2017, 10/06/2017
  1774                              <1> 	; 01/05/2017, 12/05/2017, 15/05/2017, 20/05/2017
  1775                              <1> 	; 21/04/2017, 22/04/2017, 23/04/2017, 24/04/2017
  1776                              <1> 	; 10/04/2017, 13/04/2017, 14/04/2017, 16/04/2017
  1777                              <1> 	; 03/04/2017 (VIA VT8237R)
  1778                              <1> 	; 01/04/2016 (trdosk6.s -> tdosk8.s)
  1779                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  1780                              <1> 	;
  1781                              <1> 	; Inputs:
  1782                              <1> 	;
  1783                              <1> 	;	BH = 0 -> Beep (PC Speaker)
  1784                              <1> 	;	     BL = Duration Counter (1 for 1/64 second)
  1785                              <1> 	;	     CX = Frequency Divisor (1193180/Frequency)
  1786                              <1> 	;		 (1331 for 886 Hz)
  1787                              <1> 	;
  1788                              <1> 	;	01/04/2017	
  1789                              <1> 	;
  1790                              <1> 	; 	BH = 1 -> DETECT (& ENABLE) AUDIO DEVICE
  1791                              <1> 	;	     BL = 0 : PC SPEAKER
  1792                              <1> 	;		  1 : SOUND BLASTER 16
  1793                              <1> 	;		  2 : INTEL AC'97
  1794                              <1> 	;		  3 : VIA VT8237R (VT8233)			 				
  1795                              <1> 	;		  4 : INTEL HDA
  1796                              <1> 	;	      5-FEh : unknown/invalid
  1797                              <1> 	;	        ; 04/06/2017
  1798                              <1> 	;		FFh : Get current audio device id
  1799                              <1> 	;
  1800                              <1> 	; 	BH = 2 -> ALLOCATE AUDIO BUFFER (for user)
  1801                              <1> 	;		ECX = Audio Buffer Size (must be equal to
  1802                              <1> 	;		      the half of DMA buffer size) 
  1803                              <1> 	;		EDX = Virtual Address of the buffer
  1804                              <1> 	;		      (This is not DMA buffer!)
  1805                              <1> 	;
  1806                              <1> 	;	BH = 3 -> INITIALIZE AUDIO DEVICE
  1807                              <1> 	;	     BL = 0,2 -> for Signal Response Byte	 	
  1808                              <1> 	;	     	CL = Signal Response Byte Value (fixed)
  1809                              <1> 	;				if BL = 0
  1810                              <1> 	;	             auto increment of S.R.B. value
  1811                              <1> 	;			 	if BL = 2
  1812                              <1> 	;	        EDX = Signal Response (Return) Byte Address
  1813                              <1> 	;	     	   			
  1814                              <1> 	;	     BL = 1 for CallBack Method	 	
  1815                              <1> 	;	    	EDX = CallBack Service Address (Virtual)
  1816                              <1> 	;
  1817                              <1> 	;	     BL > 2 -> invalid function	
  1818                              <1> 	;
  1819                              <1> 	;	    (Audio buffer must be allocated before
  1820                              <1> 	;	     initialization.) 		
  1821                              <1> 	;
  1822                              <1> 	;	BH = 4 -> START TO PLAY
  1823                              <1> 	;	     BL = Mode
  1824                              <1> 	;		  Bit 0 = mono/stereo (1 = stereo)		
  1825                              <1> 	;		  Bit 1 = 8 bit / 16 bit (1 = 16 bit)
  1826                              <1> 	;	     CX = Sampling Rate (Hz)
  1827                              <1> 	;
  1828                              <1> 	;	BH = 5 -> PAUSE
  1829                              <1> 	;	     BL = Any
  1830                              <1> 	;
  1831                              <1> 	;	BH = 6 -> CONTINUE TO PLAY
  1832                              <1> 	;	     BL = Any
  1833                              <1> 	;
  1834                              <1> 	;	BH = 7 -> STOP
  1835                              <1> 	;	     BL = Any
  1836                              <1> 	;
  1837                              <1> 	;	BH = 8 -> RESET 
  1838                              <1> 	;	     BL = Any
  1839                              <1> 	;
  1840                              <1> 	;	BH = 9 -> CANCEL (CALLBACK or S.R.B. SERVICE)
  1841                              <1> 	;	     BL = Any	
  1842                              <1> 	;	
  1843                              <1> 	;	BH = 10 -> DEALLOCATE AUDIO BUFFER (for user)
  1844                              <1> 	;	     BL = Any
  1845                              <1> 	;
  1846                              <1> 	;	BH = 11 -> SET VOLUME LEVEL
  1847                              <1> 	;	     BL: (Bit 0 to 6)
  1848                              <1> 	;		  0 = Master (Playback, Lineout) volume
  1849                              <1> 	;	     CL = Left Channel Volume
  1850                              <1> 	;	     CH = Right Channel Volume
  1851                              <1> 	;	
  1852                              <1> 	;	     Note: If BL >= 80h (Bit 7 of BL is set),
  1853                              <1> 	;	     volume level will be set for next playing
  1854                              <1> 	;	     (actual volume level will not be changed
  1855                              <1> 	;	     immediately)	
  1856                              <1> 	;
  1857                              <1> 	;	BH = 12 -> DISABLE AUDIO DEVICE
  1858                              <1> 	;	     (reset audio device and unlink dma buffer)	
  1859                              <1> 	;	     BL = Any	  		  	  	
  1860                              <1> 	;
  1861                              <1> 	;    	12/05/2017
  1862                              <1> 	;	BH = 13 -> MAP DMA BUFFER TO USER
  1863                              <1> 	;	    (for direct access to system's dma buffer)
  1864                              <1> 	;
  1865                              <1> 	;	     ECX = map size in bytes 
  1866                              <1> 	;		  (will be rounded up to page borders)
  1867                              <1> 	;	     EDX = Virtual Address of the buffer
  1868                              <1> 	;		  (Will be rounded up to page borders)
  1869                              <1> 	;
  1870                              <1> 	;	05/06/2017	
  1871                              <1> 	;    	04/06/2017
  1872                              <1> 	;	BH = 14 -> GET AUDIO DEVICE INFO
  1873                              <1> 	;	     BL: 0 = Audio Controller Info
  1874                              <1> 	;	       > 0 = Invalid for now! 
  1875                              <1> 	;
  1876                              <1> 	;	22/06/2017	
  1877                              <1> 	;	BH = 15 -> GET CURRENT SOUND DATA (for graphics)
  1878                              <1> 	;	     BL: 0 -> PCM OUT data
  1879                              <1> 	;	       > 0 -> Invalid for now! 
  1880                              <1> 	;	     ECX = 0 -> Get DMA Buffer Pointer
  1881                              <1> 	;		 EDX = Not Used
  1882                              <1> 	;	     ECX > 0 -> Byte count for buffer (EDX)	 	
  1883                              <1> 	;	         EDX = Buffer Address (Virtual)	
  1884                              <1> 	;
  1885                              <1> 	;	10/10/2017	
  1886                              <1> 	;	BH = 16 -> UPDATE DMA BUFFER DATA
  1887                              <1> 	;		   (by using the Audio Buffer content)
  1888                              <1> 	;	     BL = 0 : Update dma half buffer in sequence
  1889                              <1> 	;		      (automatic destination)	
  1890                              <1> 	;		  1 : Update 1st half of the dma buffer
  1891                              <1> 	;		  2 : Update 2nd half of the dma buffer
  1892                              <1> 	;		  3-FEh: Invalid!
  1893                              <1> 	;		  FFh = Get current flag value
  1894                              <1> 	;			(Half buffer number -1)
  1895                              <1> 	;
  1896                              <1> 	;
  1897                              <1> 	; Outputs:
  1898                              <1> 	;
  1899                              <1> 	;	For BH = 0 -> Beep
  1900                              <1> 	;	    None
  1901                              <1> 	;
  1902                              <1> 	;	01/04/2017
  1903                              <1> 	;
  1904                              <1> 	; 	For BH = 1 -> DETECT (& ENABLE) AUDIO DEVICE
  1905                              <1> 	;	    AH = 0 : PC SPEAKER
  1906                              <1> 	;		 1 : SOUND BLASTER 16
  1907                              <1> 	;		 2 : INTEL AC'97
  1908                              <1> 	;		 3 : VIA VT8237R (VT8233)			 				
  1909                              <1> 	;		 4 : INTEL HDA
  1910                              <1> 	;	      5-FFh : unknown/invalid
  1911                              <1> 	;	    AL = mode status
  1912                              <1> 	;		 bit 0 = mono /stereo (1 = stereo)
  1913                              <1> 	;		 bit 1 = 8 bit / 16 bit ( 1 = 16 bit)
  1914                              <1> 	;	    04/06/2017
  1915                              <1> 	;	    EBX = PCI DEVICE/VENDOR ID (if >0)
  1916                              <1> 	;		 (BX = VENDOR ID) 
  1917                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  1918                              <1> 	;
  1919                              <1> 	; 	For BH = 2 -> ALLOCATE AUDIO BUFFER (for user)
  1920                              <1> 	;	    EAX = Physical Address of the buffer
  1921                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  1922                              <1> 	;
  1923                              <1> 	;	For BH = 3 -> INITIALIZE AUDIO DEVICE
  1924                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  1925                              <1> 	;
  1926                              <1> 	;	For BH = 4 -> START TO PLAY
  1927                              <1> 	;	    none (if CF = 1 -> Error code in EAX)	
  1928                              <1> 	;
  1929                              <1> 	;	For BH = 5 -> PAUSE
  1930                              <1> 	;	    none (if CF = 1 -> Error code in EAX)	
  1931                              <1> 	;
  1932                              <1> 	;	For BH = 6 -> CONTINUE TO PLAY
  1933                              <1> 	;	    none (if CF = 1 -> Error code in EAX)	
  1934                              <1> 	;
  1935                              <1> 	;	For BH = 7 -> STOP
  1936                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1937                              <1> 	;
  1938                              <1> 	;	For BH = 8 -> RESET 
  1939                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1940                              <1> 	;
  1941                              <1> 	;	For BH = 9 -> CANCEL (CALLBACK or S.R.B. SERVICE)
  1942                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1943                              <1> 	;	
  1944                              <1> 	;	For BH = 10 -> DEALLOCATE AUDIO BUFFER (for user)
  1945                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1946                              <1> 	;
  1947                              <1> 	;	For BH = 11 -> SET VOLUME LEVEL
  1948                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1949                              <1> 	;
  1950                              <1> 	;	For BH = 12 -> DISABLE AUDIO DEVICE
  1951                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  1952                              <1> 	; 
  1953                              <1> 	;    	12/05/2017
  1954                              <1> 	;	For BH = 13 -> MAP DMA BUFFER TO USER
  1955                              <1> 	;	    EAX = Physical Address of the buffer
  1956                              <1> 	;	    (if CF = 1 -> Error code in EAX)	
  1957                              <1> 	;
  1958                              <1> 	;    	04/06/2017
  1959                              <1> 	;	For BH = 14 -> GET AUDIO DEVICE INFO
  1960                              <1> 	;	(for BL = 0) ; 05/06/2017	
  1961                              <1> 	;	    EAX = IRQ Number in AL
  1962                              <1> 	;		  Audio Device Number in AH 
  1963                              <1> 	;	    EBX = DEV/VENDOR ID
  1964                              <1> 	;		 (DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
  1965                              <1> 	;	    ECX = BUS/DEV/FN 
  1966                              <1> 	;		 (00000000BBBBBBBBDDDDDFFF00000000)
  1967                              <1> 	;	    EDX = NABMBAR/NAMBAR (for AC97)
  1968                              <1> 	;		  (Low word, DX = NAMBAR address)
  1969                              <1> 	;	    EDX = Base IO Addr (DX) for SB16 & VT8233	  			  		
  1970                              <1> 	;	    (if CF = 1 -> Error code in EAX)	
  1971                              <1> 	;	                 (ERR_DEV_NOT_RDY = 15)  
  1972                              <1> 	;
  1973                              <1> 	;	22/06/2017	
  1974                              <1> 	;	For BH = 15 -> GET CURRENT SOUND DATA
  1975                              <1> 	;			 (for graphics)
  1976                              <1> 	;	(for BL = 0)
  1977                              <1> 	;	 If ECX input is 0 
  1978                              <1> 	;	    EAX = DMA Buffer Current Position (Offset)
  1979                              <1> 	;	 If ECX input >  0
  1980                              <1> 	;	    EAX = Actual transfer count 		 	
  1981                              <1> 	;	    (Sound samples will be copied from 
  1982                              <1> 	;	     Current DMA Buffer Position to EDX
  1983                              <1> 	;	     virtual address as EAX bytes.)
  1984                              <1> 	;	 ((If CF = 1 ->  Error code in EAX))
  1985                              <1> 	;
  1986                              <1> 	;
  1987                              <1> 	;	10/10/2017	
  1988                              <1> 	;	For BH = 16 -> UPDATE DMA BUFFER DATA
  1989                              <1> 	;	    EAX = 0, if the updated (or current)
  1990                              <1> 	;		     half buffer is DMA half buffer 1
  1991                              <1> 	;	    EAX = 1, if the updated (or current)
  1992                              <1> 	; 		     half buffer is DMA half buffer 2 	  	
  1993                              <1> 	;	    (If CF = 1 -> Error code in EAX)	
  1994                              <1> 	;	
  1995                              <1> 
  1996 00010144 80FF11              <1> 	cmp	bh, AUDIO1L/4
  1997 00010147 0F83ECC5FFFF        <1> 	jnb	sysret
  1998                              <1> 
  1999 0001014D C0E702              <1> 	shl	bh, 2 ; *4	
  2000 00010150 0FB6F7              <1> 	movzx	esi, bh
  2001                              <1> 
  2002                              <1> 	; 22/04/2017
  2003 00010153 31C0                <1> 	xor	eax, eax
  2004 00010155 A3[64030300]        <1> 	mov	[u.r0], eax  ; 0
  2005                              <1> 		
  2006 0001015A FF96[65010100]      <1> 	call	dword [esi+AUDIO1]
  2007                              <1> 	;jc	error
  2008 00010160 E9D4C5FFFF          <1> 	jmp	sysret	
  2009                              <1> 
  2010 00010165 [D11D0000]          <1> AUDIO1:	dd	beep ; FUNCTION = 0 (bl = Duration Counter
  2011                              <1> 		     ; 		     cx = Frequency Divisor
  2012 00010169 [A9010100]          <1> 	dd	soundc_detect
  2013 0001016D [45020100]          <1> 	dd	sound_alloc
  2014 00010171 [03030100]          <1> 	dd	soundc_init
  2015 00010175 [BB040100]          <1> 	dd	sound_play
  2016 00010179 [57050100]          <1> 	dd	sound_pause
  2017 0001017D [81050100]          <1> 	dd	sound_continue
  2018 00010181 [AB050100]          <1> 	dd	sound_stop
  2019 00010185 [D4050100]          <1> 	dd	soundc_reset
  2020 00010189 [05060100]          <1> 	dd	soundc_cancel
  2021 0001018D [2B060100]          <1> 	dd	sound_dalloc
  2022 00010191 [56060100]          <1> 	dd	sound_volume
  2023 00010195 [A8060100]          <1> 	dd	soundc_disable
  2024 00010199 [1A070100]          <1> 	dd	sound_dma_map
  2025 0001019D [89070100]          <1> 	dd	soundc_info
  2026 000101A1 [E8070100]          <1> 	dd	sound_data
  2027 000101A5 [95080100]          <1> 	dd	sound_update
  2028                              <1> 	
  2029                              <1> AUDIO1L	EQU	$ - AUDIO1
  2030                              <1> 
  2031                              <1> soundc_detect:
  2032                              <1> 	; FUNCTION = 1
  2033                              <1> 	; bl = Audio device type number 
  2034                              <1> 	; (0= pc speaker, 1 = sound blaster 16, 2 = intel ac97
  2035                              <1> 	;  3= via vt823x, 4 = intel HDA, 0FFh= any)
  2036                              <1> 	
  2037                              <1> 	; 04/06/2017
  2038 000101A9 8A25[216B0100]      <1> 	mov	ah, [audio_device]
  2039 000101AF 80FBFF              <1> 	cmp	bl, 0FFh ; get current audio device id
  2040 000101B2 7408                <1> 	je	short sysaudio0
  2041                              <1> 
  2042 000101B4 20E4                <1> 	and	ah, ah
  2043 000101B6 741E                <1> 	jz	short soundc_get_dev
  2044                              <1> 
  2045 000101B8 38DC                <1> 	cmp	ah, bl
  2046 000101BA 7567                <1> 	jne	short soundc_dev_err
  2047                              <1> 
  2048                              <1> sysaudio0:	
  2049 000101BC A0[226B0100]        <1> 	mov	al, [audio_mode]
  2050                              <1> sysaudio1:
  2051 000101C1 A3[64030300]        <1> 	mov	[u.r0], eax
  2052 000101C6 8B1D[2C6B0100]      <1> 	mov	ebx, [audio_vendor] ; (DEVICE/VENDOR ID)
  2053 000101CC 8B2D[60030300]      <1> 	mov	ebp, [u.usp]
  2054 000101D2 895D10              <1> 	mov	[ebp+16], ebx  ; ebx
  2055 000101D5 C3                  <1> 	retn
  2056                              <1> 
  2057                              <1> soundc_get_dev:
  2058                              <1> 	; 28/05/2017
  2059                              <1> 	; 03/04/2017, 24/04/2017
  2060 000101D6 C605[206B0100]00    <1> 	mov	byte [audio_pci], 0
  2061 000101DD 80FB03              <1> 	cmp	bl, 3 ; VIA VT8233 (VT8237R) Audio Controller & AC97 Codec
  2062                              <1> 	;jne	short soundc_get_dev_sb
  2063                              <1> 	; 28/05/2017
  2064 000101E0 7220                <1> 	jb	short soundc_get_dev_sb
  2065 000101E2 773F                <1> 	ja	short soundc_dev_err  ; temporary (28/05/2017)
  2066                              <1> 	;  		
  2067 000101E4 E847180000          <1> 	call	DetectVT8233
  2068 000101E9 7238                <1> 	jc	short soundc_dev_err
  2069                              <1> 	; eax = 0
  2070                              <1> 
  2071                              <1> 	;mov	ebx, [audio_vendor]
  2072                              <1> 	; ebx = DEVICE/VENDOR ID
  2073                              <1> 	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  2074                              <1> 
  2075 000101EB B003                <1> 	mov	al, 3  ; VIA VT8237R (VT3233) Audio Controller
  2076 000101ED 88C4                <1> 	mov	ah, al
  2077                              <1> 
  2078                              <1> soundc_get_pci_dev_ok: ; 28/05/2017
  2079 000101EF FE05[206B0100]      <1> 	inc	byte [audio_pci] ; = 1
  2080                              <1> soundc_get_dev_ok:
  2081                              <1> 	
  2082                              <1> soundc_get_dev_sb16_ok:
  2083 000101F5 A2[216B0100]        <1> 	mov	[audio_device], al
  2084 000101FA 8825[226B0100]      <1> 	mov	[audio_mode], ah ; stereo (bit0), 16 bit (bit1) capability	
  2085 00010200 EBBF                <1> 	jmp	short sysaudio1
  2086                              <1> 
  2087                              <1> soundc_get_dev_sb:
  2088                              <1> 	; 24/04/2017
  2089 00010202 80FB01              <1> 	cmp	bl, 1 ; Sound Blaster 16
  2090 00010205 750E                <1> 	jne	short soundc_get_dev_ich ; 28/05/2017
  2091                              <1> 	;
  2092 00010207 E8551D0000          <1> 	call	DetectSB
  2093 0001020C 7215                <1> 	jc	short soundc_dev_err
  2094 0001020E B801030000          <1> 	mov	eax, 0301h ; Sound Blaster 16
  2095 00010213 EBE0                <1> 	jmp	short soundc_get_dev_sb16_ok
  2096                              <1> 
  2097                              <1> soundc_get_dev_ich:
  2098                              <1> 	; 28/05/2017
  2099                              <1> 	;cmp	bl, 2 ; Intel AC'97 Audio Controller (ICH)
  2100                              <1> 	;jne	short soundc_dev_err ; Temporary  (28/05/2017)
  2101                              <1> 	;			     ; (Here will be modified just after
  2102                              <1> 	;			     ; new sound card code will be ready!)  	
  2103 00010215 E809180000          <1> 	call	DetectICH
  2104 0001021A 7207                <1> 	jc	short soundc_dev_err
  2105                              <1> 	;
  2106 0001021C B802030000          <1> 	mov	eax, 0302h ; AC'97 (ICH)
  2107 00010221 EBCC                <1> 	jmp	short soundc_get_pci_dev_ok
  2108                              <1> 
  2109                              <1> soundc_dev_err:
  2110 00010223 B80F000000          <1> 	mov	eax, ERR_DEV_NOT_RDY ; Device not ready !
  2111 00010228 EB0C                <1> 	jmp	short sysaudio_err
  2112                              <1> 
  2113                              <1> sound_buff_error:
  2114 0001022A B82E000000          <1> 	mov	eax, ERR_BUFFER ; Buffer error !
  2115 0001022F EB05                <1> 	jmp	short sysaudio_err
  2116                              <1> 
  2117                              <1> soundc_respond_err:
  2118                              <1> 	; ERR_TIME_OUT ; 'time out !' error	
  2119 00010231 B819000000          <1> 	mov	eax, ERR_DEV_NOT_RESP ; 'device not responding !' error
  2120                              <1> sysaudio_err:
  2121 00010236 A3[64030300]        <1> 	mov	[u.r0], eax
  2122 0001023B A3[C8030300]        <1> 	mov	[u.error], eax
  2123 00010240 E9D4C4FFFF          <1> 	jmp	error
  2124                              <1> 
  2125                              <1> sound_alloc:
  2126                              <1> 	; FUNCTION =  2
  2127                              <1> 	; ecx = audio buffer size (in bytes)
  2128                              <1> 	; edx = audio buffer address (virtual)
  2129                              <1> 	; 27/07/2020
  2130                              <1> 	; 28/05/2017
  2131                              <1> 	; 01/05/2017, 15/05/2017
  2132                              <1> 	; 21/04/2017, 24/04/2017
  2133 00010245 803D[206B0100]00    <1> 	cmp	byte [audio_pci], 0
  2134 0001024C 7708                <1> 	ja	short snd_alloc_0
  2135                              <1> 	; Max. 64KB DMA buffer !!!
  2136 0001024E 81F900800000        <1> 	cmp	ecx, 32768
  2137 00010254 77D4                <1> 	ja	short sound_buff_error
  2138                              <1> snd_alloc_0:
  2139                              <1> 	; 15/05/2017
  2140 00010256 81F900100000        <1> 	cmp	ecx, 4096 ; PAGE_SIZE
  2141 0001025C 72CC                <1> 	jb	short sound_buff_error
  2142                              <1> 	;
  2143 0001025E A1[346B0100]        <1> 	mov	eax, [audio_buffer] ; audio buffer address (current)
  2144 00010263 09C0                <1> 	or	eax, eax
  2145 00010265 7445                <1> 	jz	short snd_alloc_2
  2146                              <1> 	; audio buffer exists !
  2147 00010267 8A1D[B3030300]      <1> 	mov	bl, [u.uno]
  2148 0001026D 3A1D[496B0100]      <1> 	cmp	bl, [audio_user]
  2149 00010273 0F85FC000000        <1> 	jne	sndc_owner_error ; not owner !
  2150 00010279 39D0                <1> 	cmp	eax, edx ; same virtual buffer address ?
  2151 0001027B 7508                <1> 	jne	short snd_alloc_1
  2152 0001027D 3B0D[3C6B0100]      <1> 	cmp	ecx, [audio_buff_size]
  2153 00010283 746C                <1> 	je	short snd_alloc_3 ; Nothing to do !
  2154                              <1> 				  ; Buffer has been set already!
  2155                              <1> snd_alloc_1:
  2156 00010285 51                  <1> 	push	ecx
  2157 00010286 52                  <1> 	push	edx
  2158 00010287 89C3                <1> 	mov	ebx, eax ; audio buffer address (current)
  2159 00010289 8B0D[3C6B0100]      <1> 	mov	ecx, [audio_buff_size]
  2160 0001028F E81D55FFFF          <1> 	call	deallocate_user_pages
  2161 00010294 5A                  <1> 	pop	edx
  2162 00010295 59                  <1> 	pop	ecx
  2163 00010296 31C0                <1> 	xor	eax, eax ; 0
  2164 00010298 A3[346B0100]        <1> 	mov	[audio_buffer], eax  ; 0
  2165 0001029D A3[386B0100]        <1>  	mov	[audio_p_buffer], eax  ; 0
  2166 000102A2 A3[3C6B0100]        <1>  	mov	[audio_buff_size], eax
  2167 000102A7 A2[496B0100]        <1> 	mov	[audio_user], al ; 0
  2168                              <1> snd_alloc_2:
  2169 000102AC 89D3                <1> 	mov	ebx, edx
  2170                              <1> 	; 01/05/2017
  2171 000102AE BA00F0FFFF          <1> 	mov	edx, ~PAGE_OFF ; truncating page offsets
  2172                              <1> 			       ; for aligning to page borders	
  2173                              <1> 	;and	eax, edx
  2174 000102B3 21D3                <1> 	and	ebx, edx
  2175 000102B5 21D1                <1> 	and	ecx, edx
  2176                              <1> 	; 15/05/2017
  2177                              <1> 	; EAX = Beginning address (physical)
  2178                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture	
  2179                              <1> 	; ECX = Number of bytes to be allocated		
  2180 000102B7 E89A51FFFF          <1> 	call	allocate_memory_block
  2181 000102BC 0F8268FFFFFF        <1> 	jc	sound_buff_error
  2182                              <1> 	; EAX = Physical address of the allocated memory block
  2183                              <1> 	; ECX = Allocated bytes (as truncated to page border)
  2184                              <1> 	; EBX = Virtual address (as truncated to page border)
  2185 000102C2 50                  <1> 	push	eax
  2186 000102C3 53                  <1> 	push	ebx
  2187 000102C4 51                  <1> 	push	ecx
  2188 000102C5 E8DC55FFFF          <1> 	call	allocate_user_pages
  2189 000102CA 59                  <1> 	pop	ecx
  2190 000102CB 5B                  <1> 	pop	ebx
  2191 000102CC 58                  <1> 	pop	eax
  2192 000102CD 722A                <1> 	jc	short snd_alloc_4  ; insufficient memory, buff error
  2193                              <1> 	; eax = physical address of the user's audio buffer
  2194                              <1> 	; ebx = virtual address of the user's audio buffer
  2195                              <1> 	; ecx = buffer size (in bytes)
  2196 000102CF A3[386B0100]        <1> 	mov	[audio_p_buffer], eax
  2197 000102D4 891D[346B0100]      <1> 	mov	[audio_buffer], ebx
  2198 000102DA 890D[3C6B0100]      <1>  	mov	[audio_buff_size], ecx
  2199 000102E0 8A15[B3030300]      <1> 	mov	dl, [u.uno]
  2200 000102E6 8815[496B0100]      <1> 	mov	[audio_user], dl
  2201 000102EC A3[64030300]        <1> 	mov	[u.r0], eax
  2202                              <1> snd_alloc_3:
  2203                              <1> 	; 27/07/2020
  2204 000102F1 C605[486B0100]00    <1> 	mov	byte [audio_flag], 0 ; clear dma half buffer flag
  2205                              <1> 	;	
  2206 000102F8 C3                  <1> 	retn
  2207                              <1> snd_alloc_4:
  2208                              <1> 	; 15/05/2017
  2209                              <1> 	; EAX = Beginning address (physical)
  2210                              <1> 	; ECX = Number of bytes to be deallocated
  2211 000102F9 E86553FFFF          <1> 	call	deallocate_memory_block
  2212 000102FE E927FFFFFF          <1> 	jmp	sound_buff_error  ; insufficient memory, buff error
  2213                              <1> 
  2214                              <1> soundc_init:
  2215                              <1> 	; FUNCTION = 3 
  2216                              <1> 	; bl = method (0= s.r.b., 1= callback, 2= auto incr s.r.b.)
  2217                              <1> 	; cl = signal response byte (initial or fixed) value
  2218                              <1> 	; edx = signal response byte or callback address
  2219                              <1> 	; 27/07/2020
  2220                              <1> 	; 28/05/2017
  2221                              <1> 	; 12/05/2017, 20/05/2017
  2222                              <1> 	; 22/04/2017, 23/04/2017, 24/04/2017
  2223                              <1> 	; 13/04/2017, 14/04/2017, 16/04/2017, 21/04/2017
  2224                              <1> 	; 03/04/2017, 10/04/2017
  2225                              <1> 
  2226 00010303 A0[216B0100]        <1> 	mov	al, [audio_device]
  2227 00010308 20C0                <1> 	and	al, al
  2228 0001030A 7549                <1> 	jnz	short sndc_init_6
  2229                              <1> 	;
  2230 0001030C C605[206B0100]00    <1> 	mov	byte [audio_pci], 0
  2231 00010313 52                  <1> 	push	edx
  2232 00010314 53                  <1> 	push	ebx
  2233 00010315 51                  <1> 	push	ecx
  2234 00010316 E8461C0000          <1> 	call	DetectSB
  2235 0001031B 7213                <1> 	jc	short sndc_init_8
  2236 0001031D 66B80103            <1> 	mov	ax, 0301h ; Sound Blaster 16
  2237 00010321 EB1E                <1> 	jmp	short sndc_init_7
  2238                              <1> 
  2239                              <1> sndc_init_11:
  2240                              <1> 	; 28/05/2017
  2241 00010323 E8FB160000          <1> 	call	DetectICH ; Detect AC'97 (ICH) Audio Controller
  2242 00010328 7217                <1> 	jc	short sndc_init_7
  2243 0001032A 66B80203            <1> 	mov	ax, 0302h ; Intel AC'97 Audio Device
  2244 0001032E EB0B                <1> 	jmp	short sndc_init_12 ; (PCI device)
  2245                              <1> 
  2246                              <1> sndc_init_8:
  2247 00010330 E8FB160000          <1> 	call	DetectVT8233
  2248                              <1> 	;jc	short sndc_init_7
  2249 00010335 72EC                <1> 	jc	sndc_init_11 ; 28/05/2017
  2250                              <1> 	; eax = 0
  2251 00010337 B003                <1> 	mov	al, 3	; VIA VT8237R (VT3233) Audio Controller
  2252 00010339 88C4                <1> 	mov	ah, al
  2253                              <1> 
  2254                              <1> sndc_init_12:
  2255 0001033B FE05[206B0100]      <1> 	inc	byte [audio_pci] ; = 1
  2256                              <1> sndc_init_7:
  2257 00010341 59                  <1> 	pop	ecx
  2258 00010342 5B                  <1> 	pop	ebx
  2259 00010343 5A                  <1> 	pop	edx
  2260 00010344 0F82D9FEFFFF        <1> 	jc	soundc_dev_err
  2261                              <1> 	;
  2262 0001034A A2[216B0100]        <1> 	mov	[audio_device], al
  2263 0001034F 8825[226B0100]      <1> 	mov	[audio_mode], ah ; stereo (bit0), 16 bit (bit1) capability
  2264                              <1> 
  2265                              <1> sndc_init_6:
  2266 00010355 833D[346B0100]00    <1> 	cmp	dword [audio_buffer], 0
  2267 0001035C 0F86C8FEFFFF        <1> 	jna	sound_buff_error
  2268                              <1> 
  2269 00010362 A0[B3030300]        <1> 	mov	al, [u.uno]
  2270 00010367 8A25[496B0100]      <1> 	mov	ah, [audio_user]
  2271 0001036D 08E4                <1> 	or	ah, ah
  2272 0001036F 7418                <1> 	jz	short sndc_init0
  2273 00010371 38E0                <1> 	cmp	al, ah
  2274 00010373 7419                <1> 	je	short sndc_init1
  2275                              <1> 
  2276                              <1> sndc_owner_error:
  2277 00010375 B80B000000          <1> 	mov	eax, ERR_NOT_OWNER ; 'permission denied !' error
  2278                              <1> sndc_perm_error:
  2279 0001037A A3[64030300]        <1> 	mov	[u.r0], eax
  2280 0001037F A3[C8030300]        <1> 	mov	[u.error], eax
  2281 00010384 E990C3FFFF          <1> 	jmp	error
  2282                              <1> sndc_init0:
  2283 00010389 A2[496B0100]        <1> 	mov	[audio_user], al
  2284                              <1> sndc_init1:
  2285 0001038E 8915[4C6B0100]      <1> 	mov	[audio_cb_addr], edx
  2286 00010394 881D[4A6B0100]      <1> 	mov	[audio_cb_mode], bl
  2287 0001039A 880D[4B6B0100]      <1> 	mov	[audio_srb], cl
  2288                              <1> 
  2289                              <1> 	; 27/07/2020
  2290                              <1> 	;mov	byte [audio_flag], 0  ; clear dma half buffer flag
  2291                              <1> 
  2292                              <1> 	; 24/04/2017
  2293 000103A0 803D[216B0100]03    <1> 	cmp	byte [audio_device], 3 ; VT8233 (VT8237R)
  2294 000103A7 7438                <1> 	je	short sndc_init_9
  2295                              <1> 	;ja	short soundc_respond_err ; temporary (28/05/2017)
  2296 000103A9 803D[216B0100]01    <1> 	cmp	byte [audio_device], 1 ; SB 16
  2297 000103B0 7510                <1> 	jne	short sndc_init_13
  2298 000103B2 BB[86210100]        <1> 	mov	ebx, sb16_int_handler
  2299                              <1> 	; Note: 'SbInit' is at 'Start to Play' stage
  2300                              <1> 	; 20/05/2017
  2301 000103B7 66C705[566B0100]08- <1> 	mov	word [audio_master_volume], 0808h ; 2/8
  2301 000103BF 08                  <1>
  2302 000103C0 EB3F                <1> 	jmp	short sndc_init_10
  2303                              <1> sndc_init_13:
  2304                              <1> 	; 28/05/2017
  2305 000103C2 803D[216B0100]02    <1> 	cmp	byte [audio_device], 2 ; AC 97 (ICH)	
  2306 000103C9 0F8562FEFFFF        <1> 	jne	soundc_respond_err ; temporary (28/05/2017)
  2307                              <1> 
  2308 000103CF E8071F0000          <1> 	call	ac97_codec_config
  2309 000103D4 0F8257FEFFFF        <1> 	jc	soundc_respond_err ; codec error !
  2310                              <1> 
  2311 000103DA BB[C2240100]        <1> 	mov	ebx, ac97_int_handler
  2312 000103DF EB20                <1> 	jmp	short sndc_init_10	
  2313                              <1> 
  2314                              <1> sndc_init_9:
  2315                              <1> 	;call	reset_codec
  2316                              <1> 	;; eax = 1
  2317                              <1> 	;call	codec_io_w16 ; w32
  2318 000103E1 E8C1170000          <1> 	call	init_codec ; 28/05/2017
  2319 000103E6 0F8245FEFFFF        <1> 	jc	soundc_respond_err ; codec error !
  2320                              <1> 
  2321 000103EC E8F4190000          <1> 	call	channel_reset
  2322                              <1> 
  2323                              <1> 	; setup the Codec (actually mixer registers) 
  2324 000103F1 E814190000          <1>         call    codec_config  ; unmute codec, set rates.
  2325 000103F6 0F8235FEFFFF        <1> 	jc	soundc_respond_err ; codec error !
  2326                              <1> 
  2327 000103FC BB[771D0100]        <1> 	mov	ebx, vt8233_int_handler
  2328                              <1> sndc_init_10:
  2329                              <1> 	; 13/04/2017
  2330 00010401 A0[236B0100]        <1> 	mov	al, [audio_intr] ; IRQ number	
  2331 00010406 E82BFDFFFF          <1> 	call	set_dev_IRQ_service
  2332                              <1> 
  2333                              <1> 	; SETUP (audio) INTERRUPT CALLBACK SERVICE
  2334 0001040B 8A1D[236B0100]      <1> 	mov	bl, [audio_intr] ; IRQ number
  2335 00010411 8A3D[4A6B0100]      <1> 	mov	bh, [audio_cb_mode]
  2336 00010417 FEC7                <1> 	inc	bh  ; 1 = Signal Response Byte method (fixed value)
  2337                              <1> 		    ; 2 = Callback service method
  2338                              <1> 		    ; 3 = Auto Increment S.R.B. method 	
  2339 00010419 8A0D[4B6B0100]      <1> 	mov	cl, [audio_srb]
  2340 0001041F 8B15[4C6B0100]      <1> 	mov	edx, [audio_cb_addr]
  2341 00010425 A0[496B0100]        <1> 	mov	al, [audio_user]
  2342                              <1> 	; 14/04/2017
  2343 0001042A E8E1040000          <1>  	call	set_irq_callback_service
  2344                              <1> 	; 16/04/2017
  2345 0001042F A3[64030300]        <1> 	mov	[u.r0], eax
  2346                              <1> 	;jnc	sysret
  2347 00010434 7316                <1> 	jnc	short sndc_init2 ; 21/04/2017
  2348                              <1> 	;
  2349 00010436 A3[C8030300]        <1> 	mov	dword [u.error], eax
  2350                              <1> 
  2351 0001043B A0[236B0100]        <1> 	mov	al, [audio_intr] ; IRQ number	
  2352 00010440 31DB                <1> 	xor	ebx, ebx ; reset IRQ handler address
  2353 00010442 E8EFFCFFFF          <1> 	call	set_dev_IRQ_service
  2354                              <1> 
  2355 00010447 E9CDC2FFFF          <1> 	jmp	error
  2356                              <1> 
  2357                              <1> sndc_init2:
  2358                              <1> 	; 21/04/2017
  2359 0001044C 8B0D[3C6B0100]      <1> 	mov	ecx, [audio_buff_size] ; audio buffer size
  2360 00010452 D1E1                <1> 	shl	ecx, 1 ; *2
  2361 00010454 A1[406B0100]        <1> 	mov	eax, [audio_dma_buff]
  2362 00010459 21C0                <1> 	and	eax, eax
  2363 0001045B 7415                <1> 	jz	short sndc_init3
  2364                              <1> 
  2365 0001045D 8B15[446B0100]      <1> 	mov	edx, [audio_dmabuff_size] ; dma buffer size
  2366 00010463 39D1                <1> 	cmp	ecx, edx
  2367 00010465 744D                <1> 	je	short sndc_init5
  2368                              <1> 
  2369 00010467 87CA                <1> 	xchg	ecx, edx
  2370 00010469 E8F551FFFF          <1> 	call	deallocate_memory_block
  2371 0001046E 87D1                <1> 	xchg	edx, ecx
  2372 00010470 31C0                <1> 	xor	eax, eax
  2373                              <1> sndc_init3:
  2374                              <1> 	; 12/05/2017
  2375 00010472 803D[216B0100]01    <1> 	cmp	byte [audio_device], 1 ; SB 16
  2376 00010479 7515                <1> 	jne	short sndc_init4
  2377 0001047B C705[406B0100]-     <1> 	mov	dword [audio_dma_buff], sb16_dma_buffer
  2377 00010481 [00000200]          <1>
  2378 00010485 C705[446B0100]0000- <1> 	mov	dword [audio_dmabuff_size], 65536
  2378 0001048D 0100                <1>
  2379                              <1> 	;xor	eax, eax
  2380                              <1> 	;mov	[u.r0], eax ; 0 = no error, successful
  2381 0001048F C3                  <1> 	retn 
  2382                              <1> 
  2383                              <1> sndc_init4:
  2384                              <1> 	; EAX = Beginning address (physical)
  2385                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture	
  2386                              <1> 	; ECX = Number of bytes to be allocated	(>0)	
  2387 00010490 E8C14FFFFF          <1> 	call	allocate_memory_block
  2388 00010495 0F828FFDFFFF        <1> 	jc	sound_buff_error
  2389                              <1> 
  2390                              <1> 	; set dma buffer address and size parameters
  2391 0001049B A3[406B0100]        <1> 	mov	[audio_dma_buff], eax ; dma buffer address
  2392 000104A0 890D[446B0100]      <1> 	mov	[audio_dmabuff_size], ecx ; dma buffer size
  2393                              <1> ;	; EAX = Beginning (physical) addr of the allocated mem block
  2394                              <1> ;	; ECX = Num of allocated bytes (rounded up to page borders)
  2395                              <1> ;	cmp	byte [audio_pci], 0 ; AC97 audio controller ?
  2396                              <1> ;	ja	short sndc_init4
  2397                              <1> ;
  2398                              <1> ;	; Sound Blaster 16 uses classic DMA
  2399                              <1> ;	mov	edx, eax
  2400                              <1> ;	add	edx, ecx
  2401                              <1> ;	cmp	edx, 1000000h ; 1st 16 MB
  2402                              <1> ;	jna	short sndc_init4
  2403                              <1> ;
  2404                              <1> ;	; error !
  2405                              <1> ;	; restore Memory Allocation Table Content
  2406                              <1> ;	; EAX = Beginning address (physical)
  2407                              <1> ;	; ECX = Number of bytes to be deallocated
  2408                              <1> ;	call	deallocate_memory_block
  2409                              <1> ;	; reset dma buffer address and size parameters
  2410                              <1> ;	xor	eax, eax ; 0
  2411                              <1> ;	mov	[audio_dma_buff], eax ; 0
  2412                              <1> ;	mov	[audio_dmabuff_size], ecx ; 0
  2413                              <1> ;	jmp	sound_buff_error				
  2414                              <1> ;
  2415                              <1> ;sndc_init4:
  2416 000104A6 803D[216B0100]03    <1> 	cmp	byte [audio_device], 3
  2417                              <1> 	;jne	short sndc_init5
  2418 000104AD 7506                <1> 	jne	short sndc_init14 ; 28/05/2017
  2419 000104AF E872190000          <1> 	call	set_vt8233_bdl	
  2420                              <1> sndc_init5:
  2421                              <1> 	;sub	eax, eax ; 0
  2422                              <1> 	;mov	[u.r0], eax ; 0 = no error, successful
  2423 000104B4 C3                  <1> 	retn
  2424                              <1> sndc_init14:
  2425 000104B5 E83A1F0000          <1> 	call	set_ac97_bdl
  2426                              <1> 	;jmp	short sndc_init5
  2427 000104BA C3                  <1> 	retn
  2428                              <1> 
  2429                              <1> sound_play:
  2430                              <1> 	; FUNCTION = 4 
  2431                              <1> 	; bl = Mode 
  2432                              <1> 	;      bit 0 = mono/stereo (1 = stereo)		
  2433                              <1> 	;      bit 1 = 8 bit / 16 bit (1 = 16 bit)
  2434                              <1> 	; cx = Sampling Rate (Hz)
  2435                              <1> 
  2436                              <1> 	; 13/06/2017
  2437                              <1> 	; Note: Even if Mode bits are not 11b,
  2438                              <1> 	; 	AC'97 Audio Controller (&Codec)
  2439                              <1> 	;	will play audio samples as 16 bit, stereo
  2440                              <1> 	;	samples.
  2441                              <1> 	;	(Program must fill the audio buffer
  2442                              <1> 	;	as required; 8 bit samples must be converted
  2443                              <1> 	;	to 16 bit samples and mono samples must be
  2444                              <1> 	;	converted to stereo samples...)
  2445                              <1> 	; 
  2446                              <1> 	; 28/07/2020
  2447                              <1> 	; 27/07/2020	 	
  2448                              <1> 	; 28/05/2017
  2449                              <1> 	; 15/05/2017, 20/05/2017
  2450                              <1> 	; 21/04/2017, 24/04/2017
  2451                              <1> 	; ... device check at first
  2452 000104BB A0[216B0100]        <1> 	mov	al, [audio_device]
  2453 000104C0 08C0                <1> 	or	al, al ; 0 ; pc speaker or invalid 
  2454 000104C2 0F840319FFFF        <1> 	jz	beeper_gfx ; 'video.s' ; temporary !
  2455                              <1> ;	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2456                              <1> ;	je	short snd_play_1
  2457                              <1> ;	cmp	al, 1 ; SB 16
  2458                              <1> ;	jne	soundc_dev_err ; temporary !
  2459                              <1> ;snd_play_0:
  2460                              <1> 	; ... buffer & (buffer) owner check at second
  2461 000104C8 833D[346B0100]00    <1> 	cmp	dword [audio_buffer], 0
  2462 000104CF 0F8655FDFFFF        <1> 	jna	sound_buff_error
  2463 000104D5 A0[B3030300]        <1> 	mov	al, [u.uno]
  2464 000104DA 3A05[496B0100]      <1> 	cmp	al, [audio_user]
  2465 000104E0 0F858FFEFFFF        <1> 	jne	sndc_owner_error
  2466                              <1> 
  2467 000104E6 66890D[526B0100]    <1> 	mov	[audio_freq], cx ; sample frequency (Hertz)
  2468 000104ED 88D8                <1> 	mov	al, bl
  2469 000104EF 2401                <1> 	and	al, 1 ; mono/stereo (1= stereo)
  2470 000104F1 FEC0                <1> 	inc	al ; channels
  2471 000104F3 A2[516B0100]        <1> 	mov	[audio_stmo], al ; sound channels (1 or 2)
  2472 000104F8 B008                <1> 	mov	al, 8
  2473 000104FA F6C302              <1> 	test	bl, 2 ; bits per sample (1= 16 bit)
  2474 000104FD 7402                <1> 	jz	short snd_play_bps
  2475 000104FF D0E0                <1> 	shl	al, 1  
  2476                              <1> snd_play_bps:	
  2477 00010501 A2[506B0100]        <1> 	mov	[audio_bps], al
  2478                              <1> 
  2479                              <1> 	; Transfer ring 3 (user's) audio buffer content to dma buffer
  2480 00010506 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff] ; dma buffer (ring 0)
  2481 0001050C 09FF                <1> 	or	edi, edi
  2482 0001050E 0F8416FDFFFF        <1> 	jz	sound_buff_error
  2483                              <1> 
  2484                              <1> 	; 27/07/2020
  2485                              <1> 
  2486 00010514 8B35[386B0100]      <1> 	mov	esi, [audio_p_buffer] ; physical address (ring 3)
  2487                              <1> 	;mov	ecx, [audio_buff_size] ; 15/05/2017
  2488 0001051A 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size] ; 27/07/2020
  2489                              <1> 	;or	ecx, ecx 
  2490                              <1> 	;jz	sound_buff_error
  2491                              <1> 	; 28/07/2020
  2492 00010520 D1E9                <1> 	shr	ecx, 1  ; dma half buffer size
  2493                              <1> 
  2494 00010522 8035[486B0100]01    <1> 	xor	byte [audio_flag], 1 ;  0 -> 1, 1 -> 0
  2495 00010529 7502                <1> 	jnz	short snd_play_0 ; [audio_flag] = 1
  2496                              <1> 				 ; fill dma half buffer 1
  2497                              <1> 	; [audio_flag] = 0
  2498                              <1> 	
  2499                              <1> 	; fill dma half buffer 2
  2500 0001052B 01CF                <1> 	add	edi, ecx
  2501                              <1> 
  2502                              <1> snd_play_0:
  2503                              <1> 	;rep	movsb
  2504 0001052D C1E902              <1> 	shr	ecx, 2  ; convert byte count to dword count
  2505 00010530 F3A5                <1> 	rep	movsd
  2506                              <1> 
  2507                              <1> 	; here, if [audio_flag] = 0, interrupt handler will update
  2508                              <1> 				; dma half buffer 2 
  2509                              <1> 				; (user's audio buffer data will be 
  2510                              <1> 				; copied into dma half buffer 2) 
  2511                              <1> 	;; 20/05/2017
  2512                              <1> 	;mov	byte [audio_flag], 1 ; next half (on next time)
  2513                              <1> 
  2514                              <1> 	; 24/04/2017
  2515 00010532 A0[216B0100]        <1> 	mov	al, [audio_device]
  2516 00010537 3C03                <1> 	cmp	al, 3 ; VT8233 (VT8237R) 
  2517 00010539 7410                <1> 	je	short snd_play_1
  2518 0001053B 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2519 0001053D 7512                <1> 	jne	short snd_play_2  ; 28/05/2017
  2520 0001053F E8EB1A0000          <1> 	call	SbInit_play
  2521 00010544 0F82E7FCFFFF        <1> 	jc	soundc_respond_err
  2522 0001054A C3                  <1> 	retn
  2523                              <1> 
  2524                              <1> snd_play_1:	
  2525 0001054B E80D190000          <1> 	call	vt8233_start_play
  2526 00010550 C3                  <1> 	retn
  2527                              <1> 
  2528                              <1> snd_play_2:
  2529                              <1> 	; 28/05/2017
  2530                              <1> 	;cmp	al, 2 ; AC'97
  2531                              <1> 	;jne	short snd_play_3
  2532                              <1> 
  2533 00010551 E8D21E0000          <1> 	call	ac97_start_play
  2534 00010556 C3                  <1> 	retn
  2535                              <1> 
  2536                              <1> ;snd_play_3:
  2537                              <1> ;	;call	hda_start_play
  2538                              <1> ;	retn
  2539                              <1> 
  2540                              <1> sound_pause:
  2541                              <1> 	; FUNCTION = 5
  2542                              <1> 	; Pause
  2543                              <1> 	; 28/05/2017
  2544                              <1> 	; 24/04/2017
  2545                              <1> 	; 22/04/2017
  2546 00010557 E814030000          <1> 	call	snd_dev_check
  2547 0001055C 7275                <1> 	jc	short snd_nothing ; temporary.
  2548 0001055E E81A030000          <1> 	call	snd_buf_check
  2549 00010563 726E                <1> 	jc	short snd_nothing ; temporary.
  2550 00010565 A0[216B0100]        <1> 	mov	al, [audio_device]
  2551 0001056A 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2552 0001056C 7409                <1> 	je	short snd_pause_1
  2553 0001056E 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2554 00010570 750A                <1> 	jne	short snd_pause_2 ; 28/05/2017
  2555 00010572 E9961C0000          <1> 	jmp	sb16_pause
  2556                              <1> snd_pause_1:
  2557 00010577 E99B190000          <1> 	jmp	vt8233_pause
  2558                              <1> snd_pause_2:
  2559                              <1> 	; 28/05/2017
  2560                              <1> 	;cmp	al, 2 ; AC'97
  2561                              <1> 	;jne	short snd_nothing ; temporary.
  2562 0001057C E935200000          <1> 	jmp	ac97_pause
  2563                              <1> 
  2564                              <1> sound_continue:
  2565                              <1> 	; FUNCTION = 6
  2566                              <1> 	; Continue to play
  2567                              <1> 	; 28/05/2017
  2568                              <1> 	; 22/04/2017
  2569 00010581 E8EA020000          <1> 	call	snd_dev_check
  2570 00010586 724B                <1> 	jc	short snd_nothing ; temporary.
  2571 00010588 E8F0020000          <1> 	call	snd_buf_check
  2572 0001058D 7244                <1> 	jc	short snd_nothing ; temporary.
  2573 0001058F A0[216B0100]        <1> 	mov	al, [audio_device]
  2574 00010594 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2575 00010596 7409                <1> 	je	short snd_cont_1
  2576 00010598 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2577 0001059A 750A                <1> 	jne	short snd_cont_2 ; 28/05/2017
  2578 0001059C E98F1C0000          <1> 	jmp	sb16_continue
  2579                              <1> snd_cont_1:
  2580 000105A1 E922190000          <1> 	jmp	vt8233_play
  2581                              <1> snd_cont_2:
  2582                              <1> 	; 28/05/2017
  2583                              <1> 	;cmp	al, 2 ; AC'97
  2584                              <1> 	;jne	short snd_nothing ; temporary.
  2585 000105A6 E9D31E0000          <1> 	jmp	ac97_play
  2586                              <1> 
  2587                              <1> sound_stop:
  2588                              <1> 	; FUNCTION = 7
  2589                              <1> 	; Stop playing
  2590                              <1> 	; 28/05/2017
  2591                              <1> 	; 24/05/2017
  2592                              <1> 	; 21/04/2017, 22/04/2017, 24/04/2017
  2593 000105AB E8C0020000          <1> 	call	snd_dev_check
  2594 000105B0 7221                <1> 	jc	short snd_nothing ; temporary.
  2595                              <1> 	;call	snd_buf_check
  2596 000105B2 E8CF020000          <1> 	call	snd_user_check ; 24/05/2017
  2597 000105B7 721A                <1> 	jc	short snd_nothing ; temporary.	
  2598                              <1> 	
  2599 000105B9 A0[216B0100]        <1> 	mov	al, [audio_device]
  2600 000105BE 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2601 000105C0 0F8457180000        <1> 	je	vt8233_stop
  2602                              <1> 	; 28/05/2017
  2603                              <1> 	;ja	short snd_nothing
  2604 000105C6 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2605 000105C8 0F84851C0000        <1> 	je	sb16_stop
  2606                              <1> 	;cmp	al, 2 
  2607                              <1> 	;je	short ac97_stop
  2608 000105CE E9B51F0000          <1> 	jmp	ac97_stop ; temporary.
  2609                              <1> 	;jmp	hda_stop
  2610                              <1> 
  2611                              <1> snd_nothing:
  2612                              <1> 	; 21/04/2017
  2613 000105D3 C3                  <1> 	retn
  2614                              <1> 
  2615                              <1> soundc_reset:
  2616                              <1> 	; FUNCTION = 8
  2617                              <1> 	; Reset Audio Controller
  2618                              <1> 	; 28/05/2017
  2619                              <1> 	; 22/04/2017
  2620 000105D4 E897020000          <1> 	call	snd_dev_check
  2621 000105D9 72F8                <1> 	jc	snd_nothing ; temporary.
  2622 000105DB E89D020000          <1> 	call	snd_buf_check
  2623 000105E0 72F1                <1> 	jc	snd_nothing ; temporary.	
  2624                              <1> 	
  2625 000105E2 A0[216B0100]        <1> 	mov	al, [audio_device]
  2626 000105E7 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2627 000105E9 0F8434190000        <1> 	je	vt8233_reset
  2628 000105EF 77E2                <1> 	ja	short snd_nothing ; temporary.
  2629                              <1> 	;ja	hda_reset	
  2630 000105F1 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2631 000105F3 0F850E200000        <1> 	jne	ac97_reset	
  2632 000105F9 E8A71C0000          <1> 	call	sb16_reset
  2633 000105FE 0F822DFCFFFF        <1> 	jc	soundc_respond_err
  2634 00010604 C3                  <1> 	retn
  2635                              <1> 
  2636                              <1> soundc_cancel:
  2637                              <1> 	; FUNCTION = 9
  2638                              <1> 	; Cancel audio callback service
  2639                              <1> 	; 22/04/2017
  2640 00010605 A0[496B0100]        <1> 	mov	al, [audio_user]	
  2641 0001060A 3A05[B3030300]      <1> 	cmp	al, [u.uno]
  2642 00010610 75C1                <1> 	jne	short snd_nothing
  2643                              <1> 	; RESET (audio) INTERRUPT CALLBACK SERVICE
  2644 00010612 8A1D[236B0100]      <1> 	mov	bl, [audio_intr] ; IRQ number
  2645 00010618 A0[B3030300]        <1> 	mov	al, [u.uno]
  2646 0001061D 28FF                <1> 	sub	bh, bh ; 0 ; unlink IRQ from user service
  2647 0001061F E8EC020000          <1>  	call	set_irq_callback_service
  2648 00010624 0F8250FDFFFF        <1> 	jc	sndc_perm_error ; 'permission denied' error
  2649 0001062A C3                  <1> 	retn
  2650                              <1> 
  2651                              <1> sound_dalloc:
  2652                              <1> 	; FUNCTION = 10
  2653                              <1> 	; Deallocate (ring 3) audio buffer
  2654                              <1> 	; 22/04/2017
  2655 0001062B A0[496B0100]        <1> 	mov	al, [audio_user]	
  2656 00010630 3A05[B3030300]      <1> 	cmp	al, [u.uno]
  2657 00010636 759B                <1> 	jne	short snd_nothing
  2658 00010638 8B1D[346B0100]      <1> 	mov	ebx, [audio_buffer]
  2659                              <1> 	;or	ebx, ebx
  2660                              <1> 	;jz	short snd_nothing
  2661 0001063E 8B0D[3C6B0100]      <1> 	mov	ecx, [audio_buff_size]
  2662 00010644 E86851FFFF          <1> 	call	deallocate_user_pages
  2663 00010649 31C0                <1> 	xor	eax, eax
  2664 0001064B A3[346B0100]        <1> 	mov	[audio_buffer], eax ; 0
  2665 00010650 A2[496B0100]        <1> 	mov	[audio_user], al ; 0
  2666 00010655 C3                  <1> 	retn
  2667                              <1> 
  2668                              <1> sound_volume:
  2669                              <1> 	; FUNCTION = 11
  2670                              <1> 	; Set sound volume level
  2671                              <1> 	; 28/05/2017
  2672                              <1> 	; 20/05/2017
  2673                              <1> 	; 22/04/2017, 24/04/2017
  2674                              <1> 	; bl = component (0 = master/playback/lineout volume)
  2675                              <1> 	; cl = left channel volume level (0 to 31)
  2676                              <1> 	; ch = right channel volume level (0 to 31)
  2677                              <1> 
  2678 00010656 80FB80              <1> 	cmp	bl, 80h
  2679 00010659 720E                <1> 	jb	short snd_vol_1
  2680 0001065B 0F8772FFFFFF        <1> 	ja	snd_nothing ; temporary.
  2681                              <1> 	; Set volume level for next play (BL>= 80h)
  2682 00010661 66890D[566B0100]    <1> 	mov	[audio_master_volume], cx
  2683 00010668 C3                  <1> 	retn
  2684                              <1> snd_vol_1:
  2685                              <1> 	; set volume level immediate (BL< 80h)
  2686 00010669 80FB00              <1> 	cmp	bl, 0
  2687 0001066C 0F8761FFFFFF        <1> 	ja	snd_nothing ; temporary.
  2688                              <1> 
  2689 00010672 E8F9010000          <1> 	call	snd_dev_check
  2690 00010677 0F8256FFFFFF        <1> 	jc	snd_nothing ; temporary.
  2691 0001067D E8FB010000          <1> 	call	snd_buf_check
  2692 00010682 0F824BFFFFFF        <1> 	jc	snd_nothing ; temporary.	
  2693                              <1> 
  2694 00010688 A0[216B0100]        <1> 	mov	al, [audio_device]
  2695 0001068D 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2696 0001068F 0F84A7180000        <1> 	je	vt8233_volume
  2697                              <1> 	; 28/05/2017
  2698 00010695 0F8738FFFFFF        <1> 	ja	snd_nothing ; temporary.
  2699                              <1> 	;ja	hda_volume	
  2700                              <1> 	; Sound Blaster 16
  2701 0001069B 3C01                <1> 	cmp	al, 1 ; SB 16
  2702 0001069D 0F84351B0000        <1> 	je	sb16_volume
  2703 000106A3 E9F21D0000          <1> 	jmp	ac97_volume
  2704                              <1> 
  2705                              <1> soundc_disable:
  2706                              <1> 	; FUNCTION = 12 
  2707                              <1> 	; Disable audio device (and unlink DMA memory)
  2708                              <1> 	; 28/05/2017
  2709                              <1> 	; 24/05/2017
  2710                              <1> 	; 22/04/2017
  2711 000106A8 E8C3010000          <1> 	call	snd_dev_check
  2712 000106AD 0F8270FBFFFF        <1> 	jc	soundc_dev_err ; temporary.
  2713                              <1> 	;call	snd_buf_check
  2714                              <1> 	;jc	sndc_owner_error ; temporary.
  2715                              <1> 
  2716 000106B3 A0[216B0100]        <1> 	mov	al, [audio_device]
  2717 000106B8 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2718 000106BA 7418                <1> 	je	short snd_disable_1
  2719 000106BC 0F8711FFFFFF        <1> 	ja	snd_nothing ; temporary.
  2720 000106C2 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2721 000106C4 7507                <1> 	jne	short snd_disable_0
  2722 000106C6 E8881B0000          <1> 	call	sb16_stop
  2723 000106CB EB0C                <1> 	jmp	short snd_disable_2
  2724                              <1> snd_disable_0:
  2725 000106CD E8B61E0000          <1> 	call	ac97_stop
  2726 000106D2 EB05                <1> 	jmp	short snd_disable_2
  2727                              <1> snd_disable_1:
  2728 000106D4 E844170000          <1> 	call	vt8233_stop
  2729                              <1> snd_disable_2:
  2730 000106D9 A0[236B0100]        <1> 	mov	al, [audio_intr]
  2731 000106DE 29DB                <1> 	sub	ebx, ebx ; 0 = reset
  2732 000106E0 E851FAFFFF          <1> 	call	set_dev_IRQ_service
  2733                              <1> 
  2734                              <1> 	;mov	al, [audio_intr]
  2735 000106E5 28E4                <1> 	sub	ah, ah ; 0 = reset
  2736 000106E7 E8B3F6FFFF          <1> 	call	set_hardware_int_vector
  2737                              <1> 
  2738 000106EC 31C0                <1> 	xor	eax, eax
  2739 000106EE A2[216B0100]        <1> 	mov	byte [audio_device], al
  2740 000106F3 A2[236B0100]        <1> 	mov	byte [audio_intr], al
  2741 000106F8 8705[406B0100]      <1> 	xchg	eax, [audio_dma_buff]
  2742                              <1> 	; 24/05/2017
  2743                              <1> 	;or	eax, eax
  2744                              <1> 	;jz	short snd_disable_3
  2745                              <1> 	;cmp	eax, sb16_dma_buffer ; default DMA buffer
  2746                              <1> 	;je	short snd_disable_3
  2747 000106FE 803D[206B0100]00    <1> 	cmp	byte [audio_pci], 0 ; AC97 audio controller ?
  2748 00010705 7612                <1> 	jna	short snd_disable_3
  2749 00010707 C605[206B0100]00    <1> 	mov	byte [audio_pci], 0
  2750                              <1> 	;sub	ecx, ecx
  2751                              <1> 	;xchg	ecx, [audio_dmabuff_size]
  2752 0001070E 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  2753 00010714 E84A4FFFFF          <1> 	call	deallocate_memory_block
  2754                              <1> snd_disable_3:
  2755 00010719 C3                  <1> 	retn
  2756                              <1> 
  2757                              <1> sound_dma_map:
  2758                              <1> 	; FUNCTION = 13 
  2759                              <1> 	; Map audio dma buff addr to user's buffer addr
  2760                              <1> 	; 12/05/2017
  2761 0001071A 21C9                <1> 	and	ecx, ecx
  2762 0001071C 0F8408FBFFFF        <1> 	jz	sound_buff_error
  2763 00010722 803D[216B0100]01    <1> 	cmp	byte [audio_device], 1
  2764 00010729 7229                <1> 	jb	short snd_dma_map_1
  2765                              <1> snd_dma_map_0:
  2766 0001072B A1[406B0100]        <1> 	mov	eax, [audio_dma_buff]
  2767 00010730 21C0                <1> 	and	eax, eax
  2768 00010732 7420                <1> 	jz	short snd_dma_map_1
  2769                              <1> 	;
  2770 00010734 8A1D[496B0100]      <1> 	mov	bl, [audio_user]
  2771 0001073A 08DB                <1> 	or	bl, bl
  2772 0001073C 7416                <1> 	jz	short snd_dma_map_1
  2773 0001073E 3A1D[B3030300]      <1> 	cmp	bl, [u.uno]
  2774 00010744 0F852BFCFFFF        <1> 	jne	sndc_owner_error
  2775                              <1> 	;
  2776 0001074A 8B1D[446B0100]      <1> 	mov	ebx, [audio_dmabuff_size]
  2777 00010750 21DB                <1> 	and	ebx, ebx
  2778 00010752 750A                <1> 	jnz	short snd_dma_map_2
  2779                              <1> snd_dma_map_1:
  2780 00010754 B8[00000200]        <1> 	mov	eax, sb16_dma_buffer
  2781 00010759 BB00000100          <1> 	mov	ebx, 65536
  2782                              <1> snd_dma_map_2:	
  2783 0001075E 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
  2784 00010764 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
  2785 00010769 39D9                <1> 	cmp	ecx, ebx
  2786 0001076B 0F87B9FAFFFF        <1> 	ja	sound_buff_error
  2787 00010771 50                  <1> 	push	eax
  2788 00010772 89D3                <1> 	mov	ebx, edx
  2789 00010774 C1E90C              <1> 	shr	ecx, 12 ; byte count to page count
  2790                              <1> 	; eax = physical address of (audio) dma buffer
  2791                              <1> 	; ebx = virtual address of (audio) dma buffer (user's pgdir) 
  2792                              <1> 	; ecx = page count (>0)
  2793 00010777 E8574FFFFF          <1> 	call	direct_memory_access
  2794 0001077C 58                  <1> 	pop	eax
  2795 0001077D 0F82A7FAFFFF        <1> 	jc	sound_buff_error
  2796 00010783 A3[64030300]        <1> 	mov	[u.r0], eax
  2797 00010788 C3                  <1> 	retn
  2798                              <1> 
  2799                              <1> soundc_info:
  2800                              <1> 	; FUNCTION = 14 
  2801                              <1> 	; Get Audio Controller Info
  2802                              <1> 	; 10/06/2017
  2803                              <1> 	; 05/06/2017
  2804 00010789 20DB                <1> 	and	bl, bl ; 0
  2805 0001078B 740A                <1> 	jz	short sndc_info_0
  2806                              <1> 	; invalid parameter !
  2807 0001078D B817000000          <1> 	mov	eax, ERR_INV_PARAMETER ; 23
  2808                              <1> ;sndc_inf_error:
  2809                              <1> ;	mov	[u.r0], eax
  2810                              <1> ;	mov	[u.error], eax
  2811                              <1> ;	jmp	error
  2812 00010792 E99FFAFFFF          <1> 	jmp	sysaudio_err
  2813                              <1> 
  2814                              <1> sndc_info_0:
  2815 00010797 E8D4000000          <1> 	call	snd_dev_check
  2816 0001079C 0F8281FAFFFF        <1> 	jc	soundc_dev_err
  2817                              <1> 
  2818 000107A2 8B1D[2C6B0100]      <1> 	mov	ebx, [audio_vendor]
  2819 000107A8 8B0D[286B0100]      <1> 	mov	ecx, [audio_dev_id]
  2820                              <1> 	;mov	al,  [audio_device]
  2821 000107AE 3C02                <1> 	cmp	al, 2 ; AC'97 (ICH)
  2822 000107B0 7513                <1> 	jne	short sndc_info_1
  2823                              <1> 	; Intel AC97 (ICH) Audio Controller (=2)	
  2824 000107B2 668B15[5A6B0100]    <1> 	mov	dx, [NABMBAR]
  2825 000107B9 C1E210              <1> 	shl	edx, 16
  2826 000107BC 668B15[586B0100]    <1> 	mov	dx, [NAMBAR]
  2827 000107C3 EB07                <1> 	jmp	short sndc_info_2
  2828                              <1> sndc_info_1:
  2829                              <1> 	; 05/06/2017
  2830                              <1> 	; Note: Intel HDA code (here) is not ready yet!
  2831                              <1> 	; !!! SB16 or VT8233 (VT8237R) !!!
  2832 000107C5 0FB715[266B0100]    <1> 	movzx	edx, word [audio_io_base]	
  2833                              <1> sndc_info_2:
  2834 000107CC 88C4                <1> 	mov	ah, al ;  [audio_device]
  2835 000107CE A0[236B0100]        <1> 	mov	al, [audio_intr] 
  2836                              <1> 
  2837                              <1> 	; EAX = IRQ Number in AL
  2838                              <1> 	;	Audio Device Number in AH 
  2839                              <1> 	; EBX = DEV/VENDOR ID
  2840                              <1> 	;	(DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
  2841                              <1> 	; ECX = BUS/DEV/FN 
  2842                              <1> 	;	(00000000BBBBBBBBDDDDDFFF00000000)
  2843                              <1> 	; EDX = NABMBAR/NAMBAR (for AC97)
  2844                              <1> 	;	(Low word, DX = NAMBAR address)
  2845                              <1> 	; EDX = Base IO Addr (DX) for SB16 & VT8233
  2846                              <1> 
  2847                              <1> 	; 10/06/2017
  2848 000107D3 A3[64030300]        <1> 	mov	[u.r0], eax
  2849 000107D8 8B2D[60030300]      <1> 	mov	ebp, [u.usp]
  2850 000107DE 895D10              <1> 	mov	[ebp+16], ebx  ; ebx
  2851 000107E1 895514              <1> 	mov	[ebp+20], edx  ; edx
  2852 000107E4 894D18              <1> 	mov	[ebp+24], ecx  ; ecx
  2853                              <1>   			  		
  2854 000107E7 C3                  <1>  	retn
  2855                              <1> 
  2856                              <1> sound_data:
  2857                              <1> 	; FUNCTION = 15 
  2858                              <1> 	; Get Current Sound data for graphics
  2859                              <1> 	; 22/06/2017
  2860                              <1> 	;
  2861 000107E8 E883000000          <1> 	call	snd_dev_check
  2862 000107ED 0F8230FAFFFF        <1> 	jc	soundc_dev_err ; Device not ready !
  2863                              <1> 
  2864 000107F3 80FB00              <1> 	cmp	bl, 0
  2865 000107F6 760A                <1> 	jna	short sound_data_0
  2866                              <1> 
  2867                              <1> 	; Only PCM OUT buffer data is valid for now!
  2868 000107F8 B817000000          <1> 	mov	eax, ERR_INV_PARAMETER  ; 23
  2869 000107FD E934FAFFFF          <1> 	jmp	sysaudio_err
  2870                              <1> 
  2871                              <1> sound_data_0:
  2872 00010802 A1[406B0100]        <1> 	mov	eax, [audio_dma_buff]
  2873 00010807 09C0                <1> 	or	eax, eax
  2874 00010809 0F841BFAFFFF        <1> 	jz	sound_buff_error
  2875                              <1> 
  2876 0001080F 803D[216B0100]04    <1> 	cmp	byte [audio_device], 4 ; Intel HDA
  2877 00010816 744F                <1> 	je	short sound_data_4 ; temporary ! (22/06/2017)
  2878                              <1> 
  2879 00010818 21C9                <1> 	and	ecx, ecx
  2880                              <1> 	;jnz	short sound_data_1 ; sample tranfer
  2881                              <1> 	
  2882                              <1> 	; Return only DMA Buffer pointer/offset... 
  2883                              <1> 	; (If DMA Buffer has been mapped to user's
  2884                              <1> 	;  memory space; program can get graphics
  2885                              <1> 	;  data by using only this pointer value.)
  2886                              <1> 	   	
  2887                              <1> 	;call	get_dma_buffer_offset
  2888                              <1> 	;; eax = DMA buffer offset
  2889                              <1> 	;;	(!not half buffer offset!)
  2890                              <1> 	;mov	[u.r0], eax
  2891                              <1> 	;retn
  2892                              <1> 
  2893 0001081A 0F845F1F0000        <1> 	jz	get_dma_buffer_offset	
  2894                              <1> 	
  2895                              <1> sound_data_1:
  2896                              <1> 	;mov	eax, [audio_dmabuff_size]
  2897                              <1> 	;shr	eax, 1 ; half buffer size
  2898                              <1> 	;cmp	ecx, eax
  2899                              <1> 	;ja	short sound_buff_error	
  2900                              <1> 
  2901 00010820 3B0D[446B0100]      <1> 	cmp	ecx, [audio_dmabuff_size]
  2902 00010826 0F87FEF9FFFF        <1> 	ja	sound_buff_error
  2903                              <1> 
  2904 0001082C 89D0                <1> 	mov	eax, edx
  2905 0001082E 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 4095 (0FFFh)
  2906 00010833 81F900100000        <1> 	cmp	ecx, 4096
  2907 00010839 7605                <1> 	jna	short sound_data_2
  2908 0001083B B900100000          <1> 	mov	ecx, 4096 ; max. 1 page
  2909                              <1> sound_data_2:
  2910 00010840 01C8                <1> 	add	eax, ecx
  2911 00010842 3D00100000          <1> 	cmp	eax, 4096
  2912 00010847 7606                <1> 	jna	short sound_data_3
  2913 00010849 6625FF0F            <1> 	and	ax, PAGE_OFF ; 4095 (0FFFh)
  2914 0001084D 29C1                <1> 	sub	ecx, eax
  2915                              <1> 	; here, ECX has been adjusted to fit 
  2916                              <1> 	;	in page border..  (<= 4096, >0)
  2917                              <1> sound_data_3:
  2918 0001084F 51                  <1> 	push	ecx
  2919 00010850 52                  <1> 	push	edx
  2920 00010851 89D3                <1> 	mov	ebx, edx 
  2921 00010853 E8694AFFFF          <1> 	call	get_physical_addr
  2922 00010858 5A                  <1> 	pop	edx
  2923 00010859 59                  <1> 	pop	ecx
  2924 0001085A 0F82CAF9FFFF        <1> 	jc	sound_buff_error	
  2925                              <1> 	
  2926                              <1> 	; eax = physical address of user's buffer
  2927 00010860 89C3                <1> 	mov	ebx, eax  
  2928                              <1> 	; ecx = byte (transfer) count
  2929                              <1> 	;call	get_current_sound_data
  2930                              <1> 	;retn
  2931 00010862 E9751E0000          <1> 	jmp	get_current_sound_data
  2932                              <1> 
  2933                              <1> sound_data_4:
  2934                              <1> 	; Intel HDA code is not ready yet !
  2935                              <1> 	; 22/06/2017
  2936 00010867 31C0                <1> 	xor	eax, eax
  2937 00010869 48                  <1> 	dec	eax
  2938 0001086A A3[64030300]        <1> 	mov	[u.r0], eax ; 0FFFFFFFFh
  2939 0001086F C3                  <1> 	retn 
  2940                              <1> 
  2941                              <1> snd_dev_check:
  2942                              <1> 	; 10/06/2017
  2943                              <1> 	; 05/06/2017
  2944                              <1> 	; 24/05/2017
  2945                              <1> 	; 22/04/2017
  2946                              <1> 	; 21/04/2017
  2947                              <1> 	; ... device check at first
  2948 00010870 A0[216B0100]        <1> 	mov	al, [audio_device]
  2949 00010875 3C01                <1> 	cmp	al, 1 ; SB 16
  2950 00010877 7203                <1> 	jb	short snd_dev_chk_retn ; error !
  2951                              <1> 	;cmp	al, 4 ; Intel HDA
  2952                              <1> 	;ja	short snd_dbchk_stc ; invalid !
  2953                              <1> 	; 10/06/2017
  2954 00010879 3C05                <1> 	cmp	al, 5
  2955 0001087B F5                  <1> 	cmc
  2956                              <1> snd_dev_chk_retn:
  2957 0001087C C3                  <1> 	retn
  2958                              <1> 
  2959                              <1> snd_buf_check:
  2960                              <1> 	; 10/06/2017
  2961                              <1> 	; 22/04/2017
  2962                              <1> 	; 21/04/2017
  2963                              <1> 	; ... buffer & (buffer) owner check at second
  2964 0001087D 833D[346B0100]00    <1> 	cmp	dword [audio_buffer], 0
  2965 00010884 760D                <1> 	jna	short snd_dbchk_stc
  2966                              <1> snd_user_check:
  2967 00010886 A0[B3030300]        <1> 	mov	al, [u.uno]
  2968 0001088B 3A05[496B0100]      <1> 	cmp	al, [audio_user]
  2969                              <1> 	;jne	short snd_dbchk_stc
  2970                              <1> 	;retn
  2971 00010891 74E9                <1> 	je	short snd_dev_chk_retn
  2972                              <1> 
  2973                              <1> snd_dbchk_stc:
  2974 00010893 F9                  <1> 	stc
  2975 00010894 C3                  <1> 	retn
  2976                              <1> 
  2977                              <1> sound_update:
  2978                              <1> 	; FUNCTION = 16 
  2979                              <1> 	; bl = 
  2980                              <1> 	;    0 = automatic (sequental) update (with flag switch!)
  2981                              <1> 	;    1 = update dma half buffer 1 (without flag switch!)		
  2982                              <1> 	;    2 = update dma half buffer 2 (without flag switch!)
  2983                              <1> 	;  FFh = get current flag value	
  2984                              <1> 	;      0 = dma half buffer 1 (will be played next)
  2985                              <1> 	;      1 = dma half buffer 2 (will be played next)
  2986                              <1> 	
  2987                              <1> 	; 10/10/2017
  2988                              <1> 	
  2989                              <1> 	; ... device check at first
  2990 00010895 A0[216B0100]        <1> 	mov	al, [audio_device]
  2991 0001089A 08C0                <1> 	or	al, al ; 0 ; pc speaker or invalid 
  2992 0001089C 0F8481F9FFFF        <1> 	jz	soundc_dev_err
  2993                              <1> 
  2994                              <1> 	; ... buffer & (buffer) owner check at second
  2995 000108A2 833D[346B0100]00    <1> 	cmp	dword [audio_buffer], 0
  2996 000108A9 0F867BF9FFFF        <1> 	jna	sound_buff_error
  2997 000108AF A0[B3030300]        <1> 	mov	al, [u.uno]
  2998 000108B4 3A05[496B0100]      <1> 	cmp	al, [audio_user]
  2999 000108BA 0F85B5FAFFFF        <1> 	jne	sndc_owner_error
  3000                              <1> 
  3001                              <1> 	; Transfer ring 3 (user's) audio buffer content to dma buffer
  3002 000108C0 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff] ; dma buffer (ring 0)
  3003 000108C6 09FF                <1> 	or	edi, edi
  3004 000108C8 0F845CF9FFFF        <1> 	jz	sound_buff_error
  3005 000108CE 8B35[386B0100]      <1> 	mov	esi, [audio_p_buffer] ; physical address (ring 3)
  3006 000108D4 8B0D[3C6B0100]      <1> 	mov	ecx, [audio_buff_size]
  3007                              <1> 	
  3008                              <1> 	;movzx	eax, byte [audio_flag]
  3009 000108DA A0[486B0100]        <1> 	mov	al, [audio_flag]
  3010                              <1> 
  3011 000108DF FEC3                <1> 	inc	bl
  3012 000108E1 7427                <1> 	jz	short snd_update_3 ; bl = 0FFh
  3013 000108E3 FECB                <1> 	dec	bl 
  3014 000108E5 7411                <1> 	jz	short snd_update_0 ; bl = 0
  3015                              <1> 
  3016 000108E7 80FB02              <1> 	cmp	bl, 2
  3017 000108EA 7417                <1> 	je	short snd_update_1 ; dma half buffer 2
  3018 000108EC 7217                <1> 	jb	short snd_update_2 ; dma half buffer 1
  3019                              <1>  
  3020                              <1> 	; invalid parameter !
  3021 000108EE B817000000          <1> 	mov	eax, ERR_INV_PARAMETER ; 23
  3022                              <1> ;	mov	[u.r0], eax
  3023                              <1> ;	mov	[u.error], eax
  3024                              <1> ;	jmp	error
  3025 000108F3 E93EF9FFFF          <1> 	jmp	sysaudio_err
  3026                              <1> 	
  3027                              <1> snd_update_0:
  3028 000108F8 8035[486B0100]01    <1> 	xor	byte [audio_flag], 1 ; update flag !!!
  3029 000108FF 3C01                <1> 	cmp	al, 1
  3030 00010901 7202                <1> 	jb	short snd_update_2 ; dma half buffer 1
  3031                              <1> snd_update_1:
  3032                              <1> 	; dma half buffer 2
  3033 00010903 01CF                <1> 	add	edi, ecx
  3034                              <1> snd_update_2:
  3035                              <1> 	;rep	movsb
  3036 00010905 C1E902              <1> 	shr	ecx, 2
  3037 00010908 F3A5                <1> 	rep	movsd
  3038                              <1> snd_update_3:
  3039 0001090A A3[64030300]        <1> 	mov	[u.r0], eax
  3040                              <1> 
  3041 0001090F C3                  <1> 	retn
  3042                              <1> 	
  3043                              <1> set_irq_callback_service:
  3044                              <1> 	; 10/06/2017
  3045                              <1> 	; 12/05/2017
  3046                              <1> 	; 24/04/2017
  3047                              <1> 	; 22/04/2017
  3048                              <1> 	; caller: 'syscalbac' or 'sysaudio' or ...
  3049                              <1> 	; 13/04/2017, 14/04/2017, 17/04/2017
  3050                              <1> 	; 24/02/2017, 26/02/2017, 28/02/2017
  3051                              <1> 	; 21/02/2017 - TRDOS 386 (TRDOS v2.0)
  3052                              <1> 	;
  3053                              <1> 	; Link or unlink IRQ callback service to/from user (ring 3)	
  3054                              <1> 	;
  3055                              <1> 	; INPUT ->
  3056                              <1> 	;	If AL = 0, the caller is 'syscalbac';
  3057                              <1> 	;	   otherwise, the caller is 'sysaudio' or ...
  3058                              <1> 	;	   (AL = user number) 
  3059                              <1> 	; 	 
  3060                              <1> 	;	BL = IRQ number (Hardware interrupt request number)
  3061                              <1> 	;	     (0 t0 15 but IRQ 0,1,2,6,8,14,15 are prohibited)
  3062                              <1> 	;	     IRQ numbers 3,4,5,7,9,10,11,12,13 are valid
  3063                              <1> 	;	     (numbers >15 are invalid)
  3064                              <1> 	;
  3065                              <1> 	;	BH = 0 = Unlink IRQ (in BL) from user (ring 3) service
  3066                              <1> 	;	     1 = Link IRQ by using Signal Response Byte method
  3067                              <1> 	;	     2 = Link IRQ by using Callback service method 		
  3068                              <1> 	;	     3 = Link IRQ by using Auto Increment S.R.B. method 	
  3069                              <1> 	;	    >3 = invalid 
  3070                              <1> 	;		 (syscallback version will return to user) 	
  3071                              <1> 	;	
  3072                              <1> 	;	CL = Signal Return/Response Byte value 
  3073                              <1> 	;
  3074                              <1> 	;	If BH = 2, kernel will put a counter value 
  3075                              <1> 	;	          (into the S.R.B. addr)
  3076                              <1> 	;		  between 0 to 255. (start value = CL+1)
  3077                              <1> 	;	
  3078                              <1> 	;	NOTE: counter value, for example: even and odd numbers
  3079                              <1> 	;	      may be used for -audio- DMA buffer switch 
  3080                              <1> 	;	      within double buffer method, etc. 		
  3081                              <1> 	;
  3082                              <1> 	;	EDX = Signal return (Response) byte address
  3083                              <1> 	;	       		  - or -
  3084                              <1> 	;	      Interrupt/Callback service/routine address
  3085                              <1> 	; 	
  3086                              <1> 	;	      (virtual address in user's memory space)
  3087                              <1> 	;
  3088                              <1> 	; OUTPUT ->
  3089                              <1> 	;	CF = 0 & EAX = 0 -> Successful setting
  3090                              <1> 	;	CF = 1 & EAX > 0 -> IRQ is prohibited or locked 
  3091                              <1> 	;			by another process
  3092                              <1> 	;		 eax = ERR_PERM_DENIED -> prohibited or locked
  3093                              <1> 	;		 eax = ERR_INV_PARAMETER -> 
  3094                              <1> 	;		       invalid parameter/option or bad address
  3095                              <1> 	;
  3096                              <1> 	; TRDOS 386 - IRQ CALLBACK structures (parameters):
  3097                              <1> 	;	
  3098                              <1> 	;	   [u.irqlock] = 1 word, IRQ flags (0-15) that indicates
  3099                              <1> 	;			which IRQs are locked by (that) user.
  3100                              <1> 	;		        Lock and unlock (by user) will change
  3101                              <1> 	;			these flags or 'terminate process' (sysexit)
  3102                              <1> 	;			will clear these flags and unlock those IRQs.
  3103                              <1> 	;			               
  3104                              <1> 	;		   	Bit 0 is for IRQ 0 and Bit 15 is for IRQ 15
  3105                              <1> 	;
  3106                              <1> 	;	   IRQ(x).owner	 : 1 byte, user, [u.uno], 0 = free (unlocked)	
  3107                              <1> 	;
  3108                              <1> 	;	   IRQ(x).method : 1 byte for callback method & status
  3109                              <1> 	;			   0 = Signal Response Byte method
  3110                              <1> 	;			   1 = Callback service method
  3111                              <1> 	;			   >1 = invalid for current 'syscalback'.
  3112                              <1> 	;			or(+) 80h = IRQ is in use by system (ring 0)
  3113                              <1> 	;			            function (audio etc.) or
  3114                              <1> 	;			   	    a device driver.	   	
  3115                              <1> 	;			(system function will ignore the lock/owner)
  3116                              <1> 	;
  3117                              <1> 	;	   IRQ(x).srb	: 1 byte, Signal Return/Response byte value
  3118                              <1> 	;			  (a fixed value by user or a counter value
  3119                              <1> 	;			 from 0 to 255, which is increased by every
  3120                              <1> 	;			 interrupt just before putting it into 
  3121                              <1> 	;			 the Signal Response byte address
  3122                              <1> 	;			 (This is not used in callback serv method)
  3123                              <1> 	;	    	  
  3124                              <1> 	;	   IRQ(x).addr	: 1 dword
  3125                              <1> 	;			  Signal Response Byte address (physical)
  3126                              <1> 	;			  		-or-
  3127                              <1> 	;			  Callback service address (virtual)
  3128                              <1> 	;
  3129                              <1> 	;	   IRQ(x).dev	: 1 byte
  3130                              <1> 	;			  0 = Default device or kernel function
  3131                              <1> 	;			  		-or-
  3132                              <1> 	;			  1-255 = Assigned device driver number
  3133                              <1> 	;
  3134                              <1> 	;	   (x) = 3,4,5,7,9,10,11,12,13
  3135                              <1> 	;
  3136                              <1> 	
  3137 00010910 80FB0F              <1> 	cmp	bl, 15
  3138 00010913 7729                <1> 	ja	short scbs_2
  3139                              <1> 	
  3140 00010915 80FF03              <1> 	cmp	bh, 3
  3141 00010918 7724                <1> 	ja	short scbs_2  ; invalid parameter
  3142                              <1> 
  3143 0001091A 0FB6FB              <1> 	movzx	edi, bl ; save IRQ number
  3144                              <1> 
  3145                              <1> 		;  IRQ 0,1,2,6,8,14,15 are prohibited
  3146                              <1> 	;IRQenum: ; 'trdosk9.s'
  3147                              <1> 	;	db  0,0,0,1,2,3,0,4,0,5,6,7,8,9,0,0
  3148                              <1> 
  3149 0001091D 0FB6B7[70160100]    <1> 	movzx	esi, byte [edi+IRQenum] ; IRQ availability 
  3150                              <1> 					; enumeration/index
  3151                              <1> 	;dec	esi
  3152 00010924 664E                <1> 	dec	si
  3153 00010926 780F                <1> 	js	short scbs_1 ;  0 -> 0FFFFh  
  3154                              <1> 
  3155                              <1> 	; ESI = IRQ callback parameters index number (0 to 8)
  3156                              <1> 
  3157 00010928 08FF                <1> 	or	bh, bh
  3158 0001092A 7419                <1> 	jz	short scbs_4 ; unlink the IRQ (in BL)
  3159                              <1> 
  3160 0001092C FECF                <1> 	dec	bh
  3161                              <1> 	; bh = method (0 = signal response byte, 1 = callback)
  3162                              <1> 	;	      (2 = auto increment of signal response byte) 
  3163                              <1> 
  3164 0001092E 80BE[D26A0100]00    <1> 	cmp	byte [esi+IRQ.owner], 0 ; locked ?
  3165 00010935 7637                <1> 	jna	short scbs_6	; no... OK...	
  3166                              <1> 
  3167                              <1> scbs_1:
  3168                              <1> 	; permission denied (prohibited IRQ)
  3169 00010937 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED
  3170 0001093C F9                  <1> 	stc
  3171 0001093D C3                  <1> 	retn
  3172                              <1> scbs_2:
  3173 0001093E F9                  <1> 	stc
  3174                              <1> scbs_3:
  3175 0001093F B817000000          <1> 	mov	eax, ERR_INV_PARAMETER
  3176 00010944 C3                  <1> 	retn
  3177                              <1> 
  3178                              <1> scbs_4: ; unlink the requested IRQ (if it belongs to current user)
  3179                              <1> 	; 10/06/2017
  3180                              <1> 	; 22/04/2017
  3181                              <1> 	; 14/04/2017
  3182                              <1> 	; If AL = 0 -> The caller is 'syscalbac'
  3183 00010945 8AA6[D26A0100]      <1> 	mov	ah, [esi+IRQ.owner]
  3184 0001094B 3A25[B3030300]      <1> 	cmp	ah, [u.uno]
  3185 00010951 75E4                <1> 	jne	short scbs_1
  3186                              <1> 
  3187 00010953 FE0D[D6030300]      <1> 	dec	byte [u.irqc] ; decrease IRQ count (in use)
  3188                              <1> 
  3189                              <1> 	;sub	ah, ah
  3190                              <1> 	;mov	[esi+IRQ.owner], ah ; 0 ; free !!!
  3191                              <1> 	;and	byte [esi+IRQ.method], 80h
  3192                              <1> 	;mov	[esi+IRQ.srb], ah ; 0
  3193                              <1> 	;mov	[esi+IRQ.dev], ah ; 0
  3194                              <1> 	;mov	dword [esi+IRQ.addr], 0
  3195                              <1> 	;mov	dword [u.r0], 0
  3196                              <1> 
  3197                              <1> 	;mov	byte [esi+IRQ.owner], 0
  3198                              <1> 
  3199                              <1> 	; 22/04/2017
  3200 00010959 29C0                <1> 	sub	eax, eax
  3201 0001095B 8886[D26A0100]      <1> 	mov	[esi+IRQ.owner], al ; 0
  3202                              <1> 	; 10/06/2017
  3203 00010961 8686[E46A0100]      <1> 	xchg	al, [esi+IRQ.method]
  3204 00010967 2480                <1> 	and	al, 80h
  3205 00010969 745E                <1> 	jz	short scbs_12 
  3206                              <1> 	; Audio device must be disabled -later- ! ([IRQ.medhod] = 80h)
  3207                              <1> 
  3208                              <1> ;	cmp	byte [esi+IRQ.method], 80h ; device drv or kernel extension ?
  3209                              <1> ;	jb	short scbs_12 ; bh = 0 reset to default IRQ handler
  3210                              <1> ;
  3211                              <1> ;	and	al, al
  3212                              <1> ;	jz	short  scbs_5  ; the caller is 'syscalbac'
  3213                              <1> ;	; The caller is 'sysaudio' or ...
  3214 0001096B 30C0                <1> 	xor	al, al
  3215                              <1> ;	mov	[esi+IRQ.method], al ; 0 ; reset kernel extension flag
  3216                              <1> ;scbs_5:
  3217                              <1> ;	sub	ah, ah
  3218                              <1> 	;mov	[u.r0], eax ; 0
  3219 0001096D C3                  <1> 	retn	
  3220                              <1> 
  3221                              <1> scbs_6:
  3222                              <1> 	; 14/04/2017
  3223 0001096E 20C0                <1> 	and	al, al
  3224 00010970 7405                <1> 	jz	short scbs_7  ; the caller is 'syscalbac'
  3225                              <1> 	; AL = user number ([u.uno] or [audio.user] or ...)
  3226                              <1> 	; The caller is 'sysaudio' or ...
  3227                              <1> 	;	
  3228                              <1> 	; bh = method (0 = signal response byte, 1 = callback)
  3229                              <1> 	;	      (2 = auto increment of signal response byte) 
  3230                              <1> 
  3231 00010972 80CF80              <1> 	or	bh, 80h		; Kernel extension flag !
  3232 00010975 EB0A                <1> 	jmp	short scbs_8
  3233                              <1> scbs_7:	
  3234 00010977 8A86[E46A0100]      <1> 	mov	al, [esi+IRQ.method] ; >= 80h = kernel is using this IRQ
  3235 0001097D 2480                <1> 	and	al, 80h ; use only bit 7 (kernel function flag)
  3236 0001097F 08C7                <1> 	or	bh, al		 ; method 
  3237                              <1> 				 ; 0 = signal response byte, 1 = callback
  3238                              <1> 				 ; 2 = auto increment of s.r.b.
  3239                              <1> scbs_8:
  3240 00010981 A0[B3030300]        <1> 	mov	al, [u.uno] ; user (process) number (1 to 16)
  3241 00010986 8886[D26A0100]      <1> 	mov	[esi+IRQ.owner], al ; lock the IRQ for user
  3242 0001098C 88BE[E46A0100]      <1> 	mov	[esi+IRQ.method], bh
  3243                              <1> 
  3244                              <1> ;	test	bh, 1
  3245                              <1> ;	jnz	short scbs_9 	 ; Callback method, CX will not be used 
  3246                              <1> ;			
  3247                              <1> ;	test	bh, 2		 ; use auto increment (counter) method
  3248                              <1> ;	jz	short scbs_10	 ; (count can be used for buffer switch)
  3249                              <1> ;scbs_9:
  3250                              <1> ;	xor	ecx, ecx ; 0
  3251                              <1> scbs_10:			      	
  3252                              <1> 	;mov	[esi+IRQ.method], bh
  3253 00010992 888E[ED6A0100]      <1> 	mov	[esi+IRQ.srb], cl
  3254 00010998 C686[DB6A0100]00    <1> 	mov	byte [esi+IRQ.dev], 0 ; device number is always 0 
  3255                              <1> 				 ; for this system call
  3256                              <1> 	;test	bh, 1
  3257 0001099F 80E701              <1> 	and	bh, 1 ; 17/04/2017
  3258 000109A2 7513                <1> 	jnz	short scbs_11	 ; callback method, use virtual address 
  3259                              <1> 
  3260 000109A4 53                  <1> 	push	ebx ; IRQ number (in BL)
  3261 000109A5 89D3                <1> 	mov	ebx, edx
  3262                              <1> 	; ebx = virtual address
  3263                              <1> 	; [u.pgdir] = page directory's physical address
  3264 000109A7 FE05[726A0100]      <1> 	inc	 byte [no_page_swap] ; 1 
  3265                              <1> 			; Do not add this page to swap queue
  3266                              <1> 			; and remove it from swap queue if it is
  3267                              <1> 			; on the queue.
  3268 000109AD E80F49FFFF          <1> 	call	get_physical_addr
  3269 000109B2 5B                  <1> 	pop	ebx
  3270 000109B3 728A                <1> 	jc	scbs_3 ; invalid address !
  3271                              <1> 	; eax = physical address of the virtual address in user's space
  3272 000109B5 89C2                <1> 	mov	edx, eax
  3273                              <1> scbs_11:
  3274 000109B7 66C1E602            <1> 	shl	si, 2		; byte (index) to dword (offset)
  3275 000109BB 8996[F66A0100]      <1> 	mov	[esi+IRQ.addr], edx
  3276                              <1> 
  3277 000109C1 FE05[D6030300]      <1> 	inc	byte [u.irqc]	; increase IRQ (in use) count
  3278                              <1> 
  3279 000109C7 FEC7                <1> 	inc	 bh ; 17/04/2017
  3280                              <1> 	; bh > 0 -> set to requested IRQ handler (IRQ_u_list)
  3281                              <1> scbs_12:
  3282 000109C9 88D8                <1> 	mov	al, bl ; IRQ number
  3283 000109CB 88FC                <1> 	mov	ah, bh ; 0 = reset, >0 = set
  3284 000109CD E8CDF3FFFF          <1> 	call	set_hardware_int_vector
  3285                              <1> 
  3286 000109D2 31C0                <1> 	xor	eax, eax
  3287                              <1> 	;mov 	[u.r0], eax ; 0	
  3288                              <1> 
  3289 000109D4 C3                  <1> 	retn	; return with success (cf=0, eax=0)
  3290                              <1> 
  3291                              <1> 
  3292                              <1> sysdma: ; DMA FUNCTIONS
  3293                              <1> 	; 02/09/2017
  3294                              <1> 	; 28/08/2017
  3295                              <1> 	; 20/08/2017 - TRDOS 386 (TRDOS v2.0)
  3296                              <1> 	;
  3297                              <1> 	; Inputs:
  3298                              <1> 	;	BH = 0 -> Allocate DMA buffer
  3299                              <1> 	;	   BL = 0 -> Use the system's default DMA
  3300                              <1> 	;		     (SB16) Buffer
  3301                              <1> 	;	        Buffer Size (max.) = 65536 bytes
  3302                              <1> 	;	   BL > 0 -> Allocate (a new) DMA buffer
  3303                              <1>  	;	   ECX = DMA Buffer Size in bytes (<=128KB)
  3304                              <1> 	;	   EDX = Virtual Address of DMA buffer 	
  3305                              <1> 	;		
  3306                              <1> 	;	BH = 1 -> Initialize (Start) DMA service
  3307                              <1> 	;	     BL, bit 0 to 3 = Channel Number (0 to 7)	
  3308                              <1> 	;	     BL, bit 7 = Auto Initialized Mode 
  3309                              <1> 	;			(If bit 7 is set)
  3310                              <1> 	;		 bit 6 = Record (read) mode (0= playback)
  3311                              <1> 	;	     ECX = byte count (0 = use dma buffer size)
  3312                              <1> 	;	     EDX = physical buffer address
  3313                              <1> 	;	     	   (0 = use dma buffer -start- address)		
  3314                              <1> 	;
  3315                              <1> 	;	BH = 2 -> Get Current DMA Buffer Offset
  3316                              <1> 	;	     BL = DMA channel number	
  3317                              <1> 	;		
  3318                              <1> 	;	BH = 3 -> Get Current DMA count down value
  3319                              <1> 	;	     BL = DMA channel number (0 tO 7)	
  3320                              <1> 	;
  3321                              <1> 	;	BH = 4 -> Get Current DMA channel (in progress)
  3322                              <1> 	;
  3323                              <1> 	;	BH = 5 -> Get System's Default DMA Buffer Address
  3324                              <1> 	;
  3325                              <1> 	;	BH = 6 -> Get Current DMA Buffer Address	
  3326                              <1> 	;
  3327                              <1> 	;	BH = 7 -> Stop DMA service
  3328                              <1> 	;
  3329                              <1> 	;
  3330                              <1> 	; Outputs:
  3331                              <1> 	;
  3332                              <1> 	;	For BH = 0 ; Allocate DMA buffer
  3333                              <1> 	;	    EAX = Physical address of DMA buffer
  3334                              <1> 	;	    ECX = Allocated buffer size in bytes
  3335                              <1> 	;		  - page count * 4096 -
  3336                              <1> 	;		  (may be bigger than requested)	
  3337                              <1> 	;	    If BL input > 0,
  3338                              <1> 	;	       'sysalloc:' system call will be used with
  3339                              <1>   	;	       EBX (for 'sysalloc') = EDX (for 'sysdma')
  3340                              <1> 	;	       ECX is same, byte count (buffer size)
  3341                              <1> 	;	       EDX = 1024*1024*16 ; 16 MB upper limit	 		        	 
  3342                              <1> 	;	    If BL input = 0,
  3343                              <1> 	;	       Default DMA buffer (SB16 buffer) will be
  3344                              <1> 	;	       checked and if it is free, it's address
  3345                              <1> 	;	       will be returned in EAX and it's size
  3346                              <1> 	;	       will be returned in ECX (as 65536)
  3347                              <1> 	;
  3348                              <1> 	;	    If CF = 1, error code is in EAX
  3349                              <1> 	;	       EAX = -1 ; DMA buffer allocation error! 		
  3350                              <1> 	;	       EAX = 11 ; 'Permission Denied' error !
  3351                              <1> 	;
  3352                              <1> 	;	       Note: 'sysalloc' error return method
  3353                              <1> 	;		      will be applied if BL input > 0 !		
  3354                              <1> 	;
  3355                              <1> 	; 	 For BH = 1 ; Initialize (Start) DMA
  3356                              <1> 	;	     EAX = 0 (Successful)	
  3357                              <1> 	;	     If CF = 1, error code is in EAX
  3358                              <1> 	;
  3359                              <1> 	; 	 For BH = 2 ; Get Current DMA Buffer Offset
  3360                              <1> 	;	     EAX = DMA Buffer Offset (in bytes)
  3361                              <1> 	;	     ;
  3362                              <1> 	;	      AX = DMA buffer offset
  3363                              <1> 	;	     EAX bits 16 to 23 = Page register value
  3364                              <1> 	;		   	
  3365                              <1> 	; 	 For BH = 3 ; Get Current DMA count down value
  3366                              <1> 	;	     EAX = Count down value (remain bytes)
  3367                              <1> 	;	
  3368                              <1> 	;	 For BH = 4 ; Get Current DMA channel (in progress)
  3369                              <1> 	;	     EAX = DMA channel number (0 to 7)
  3370                              <1> 	;		AH = 0 if the owner is the caller process
  3371                              <1> 	;		AH > 0 if the dma channel is in use by
  3372                              <1> 	;		       another user/process
  3373                              <1> 	;	     EAX = -1 (0FFFFFFFFh) 
  3374                              <1> 	;		    if DMA service is not in use	    		
  3375                              <1> 	;	 	    (stopped or not initialized/started)	
  3376                              <1> 	;
  3377                              <1> 	;	 For BH = 5 ; Get System's Default DMA Buff Addr
  3378                              <1> 	;	     EAX = Default DMA Buffer Address (Physical)
  3379                              <1> 	;		 = offset 'sb16_dma_buffer:'	
  3380                              <1> 	;	     ECX = Buffer size
  3381                              <1> 	;		 = 65536 
  3382                              <1> 	;
  3383                              <1> 	;	 For BH = 6 ; Get Current DMA Buffer Address
  3384                              <1> 	;	     EAX = Current DMA buffer address (Physical)
  3385                              <1> 	;	     ECX = Current DMA buffer size (setting value)	   		  	 		
  3386                              <1> 	;	     Note: These values are for current dma channel
  3387                              <1> 	;		   settings for the user/process
  3388                              <1> 	;	     ** For now (for current TRDOS 386 version)
  3389                              <1> 	;		only one user/process can use only one
  3390                              <1> 	;		dma channel & one dma buffer at same time
  3391                              <1> 	;		(no multi tasking on DMA service) !!! **
  3392                              <1> 	;	     (Once, current DMA user must stop it's own DMA
  3393                              <1> 	;	      DMA service, than another user/program 
  3394                              <1> 	;	      can use DMA service with same dma channel 
  3395                              <1> 	;	      or with another DMA channel.)	 			      		
  3396                              <1> 	;
  3397                              <1> 	;	 For BH = 7 ; Stop DMA service (for current user
  3398                              <1> 	;	     and current DMA channel)	
  3399                              <1> 	;	     EAX = 0 ; successful
  3400                              <1> 	;	     CF = 1 & EAX > 0 (= -1) -> Error		
  3401                              <1> 
  3402 000109D5 80FF07              <1> 	cmp	bh, 7
  3403 000109D8 7612                <1> 	jna	short sysdma_0
  3404                              <1> 
  3405                              <1> sysdma_err:
  3406 000109DA 31C0                <1> 	xor	eax, eax
  3407 000109DC 48                  <1> 	dec	eax ; -1
  3408                              <1> sysdma_perm_err:
  3409 000109DD A3[64030300]        <1> 	mov	[u.r0], eax
  3410 000109E2 A3[C8030300]        <1> 	mov	[u.error], eax ; DMA service error !
  3411 000109E7 E92DBDFFFF          <1> 	jmp	error
  3412                              <1> 
  3413                              <1> sysdma_0:
  3414 000109EC 08FF                <1> 	or	bh, bh
  3415 000109EE 0F85BA000000        <1> 	jnz	sysdma_1
  3416                              <1> 	
  3417 000109F4 20DB                <1> 	and	bl, bl
  3418 000109F6 7416                <1> 	jz	short sysdma_01
  3419                              <1> 
  3420                              <1> 	; redirect system call to 'sysalloc'
  3421 000109F8 89D3                <1> 	mov	ebx, edx ; virtual address of DMA buffer
  3422                              <1> 	;ecx = Buffer size in bytes
  3423                              <1> 	; DMA buffer address <= 16MB upper limit
  3424 000109FA BA00000001          <1> 	mov	edx, 1024*1024*16 ; 16MB limit for DMA buff
  3425                              <1> 
  3426 000109FF C705[646F0100]FFFF- <1> 	mov	dword [dma_addr], 0FFFFFFFFh ; -1
  3426 00010A07 FFFF                <1>
  3427                              <1> 
  3428 00010A09 E99BE5FFFF          <1> 	jmp	sysalloc
  3429                              <1> 
  3430                              <1> sysdma_01:
  3431 00010A0E B8[00000200]        <1> 	mov	eax, sb16_dma_buffer
  3432                              <1> 
  3433 00010A13 803D[216B0100]01    <1> 	cmp	byte [audio_device], 1
  3434 00010A1A 722A                <1> 	jb	short sysdma_03
  3435                              <1> 
  3436 00010A1C 3B05[406B0100]      <1> 	cmp	eax, [audio_dma_buff]
  3437 00010A22 7507                <1> 	jne	short sysdma_02
  3438                              <1> 
  3439                              <1> sysdma_0_err:
  3440 00010A24 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED
  3441 00010A29 EBB2                <1> 	jmp	short sysdma_perm_err
  3442                              <1> 
  3443                              <1> sysdma_02:
  3444                              <1> 	; Only one user is permitted for audio/dma functions
  3445                              <1> 
  3446 00010A2B 833D[406B0100]00    <1> 	cmp	dword [audio_dma_buff], 0
  3447 00010A32 7612                <1> 	jna	short sysdma_03
  3448                              <1> 
  3449 00010A34 8A1D[496B0100]      <1> 	mov	bl, [audio_user]
  3450 00010A3A 08DB                <1> 	or	bl, bl
  3451 00010A3C 7408                <1> 	jz	short sysdma_03
  3452                              <1> 
  3453 00010A3E 3A1D[B3030300]      <1> 	cmp	bl, [u.uno]
  3454 00010A44 75DE                <1> 	jne	short sysdma_0_err
  3455                              <1> 
  3456                              <1> sysdma_03: 
  3457 00010A46 8A1D[616F0100]      <1> 	mov	bl, [dma_user]
  3458 00010A4C 20DB                <1> 	and	bl, bl
  3459 00010A4E 750E                <1> 	jnz	short sysdma_04
  3460                              <1> 	
  3461 00010A50 8A1D[B3030300]      <1> 	mov	bl, [u.uno]
  3462 00010A56 881D[616F0100]      <1> 	mov	[dma_user], bl
  3463                              <1> 
  3464 00010A5C EB15                <1> 	jmp	short sysdma_05
  3465                              <1> 
  3466                              <1> sysdma_04:
  3467 00010A5E 8B35[646F0100]      <1> 	mov	esi, [dma_addr]
  3468 00010A64 21F6                <1> 	and	esi, esi
  3469 00010A66 740B                <1> 	jz	short sysdma_05
  3470                              <1> 
  3471 00010A68 46                  <1> 	inc	esi ; -1 -> 0
  3472 00010A69 7408                <1> 	jz	short sysdma_05
  3473                              <1> 
  3474 00010A6B 3A1D[B3030300]      <1> 	cmp	bl, [u.uno]
  3475 00010A71 75B1                <1> 	jne	short sysdma_0_err
  3476                              <1> 	
  3477                              <1> sysdma_05:
  3478                              <1> 	; edx = virtual address (user's buffer address)
  3479                              <1> 	; 
  3480 00010A73 81F900000100        <1> 	cmp	ecx, 65536   ; byte count (buffer size)
  3481 00010A79 0F875BFFFFFF        <1> 	ja	sysdma_err	
  3482                              <1> 	;
  3483 00010A7F 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
  3484 00010A85 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
  3485                              <1> 	;cmp	ecx, 65536
  3486                              <1> 	;ja	sysdma_err ;
  3487 00010A8A 51                  <1> 	push	ecx	; buffer size (allocated pages * 4096) 
  3488 00010A8B 50                  <1> 	push	eax	; offset sb16_dma_buffer
  3489 00010A8C 89D3                <1> 	mov	ebx, edx
  3490 00010A8E C1E90C              <1> 	shr	ecx, 12 ; byte count to page count
  3491                              <1> 	; eax = physical address of (audio) dma buffer
  3492                              <1> 	; ebx = virtual address of (audio) dma buffer (user's pgdir) 
  3493                              <1> 	; ecx = page count (>0)
  3494 00010A91 E83D4CFFFF          <1> 	call	direct_memory_access
  3495 00010A96 58                  <1> 	pop	eax
  3496 00010A97 59                  <1> 	pop	ecx
  3497 00010A98 0F823CFFFFFF        <1> 	jc	sysdma_err
  3498                              <1> 
  3499 00010A9E A3[646F0100]        <1> 	mov	[dma_addr], eax
  3500 00010AA3 890D[686F0100]      <1> 	mov	[dma_size], ecx ; dma buffer size (in bytes)
  3501                              <1> 
  3502                              <1> 	;mov	[u.r0], eax ; DMA Buffer Address (Physical)
  3503                              <1> 
  3504                              <1> 	;mov	ebp, [u.usp]  ; ebp points to user's registers
  3505                              <1> 	;mov	[ebp+24], ecx ; return to user with ecx value
  3506                              <1> 
  3507                              <1> 	;jmp	sysret
  3508                              <1> 
  3509                              <1> 	; 28/08/2017
  3510 00010AA9 E9C4000000          <1> 	jmp	sysdma_51
  3511                              <1> 
  3512                              <1> sysdma_1:
  3513 00010AAE 80FF01              <1> 	cmp	bh, 1
  3514 00010AB1 0F87A6000000        <1> 	ja	sysdma_5
  3515                              <1> 
  3516 00010AB7 F6C340              <1> 	test	bl, 40h	; record (read) mode -BL, bit 6-
  3517 00010ABA 0F851AFFFFFF        <1> 	jnz	sysdma_err ; not ready yet!
  3518                              <1> 
  3519 00010AC0 A1[646F0100]        <1> 	mov	eax, [dma_addr] ; physical address of dma buffer
  3520 00010AC5 21C0                <1> 	and	eax, eax
  3521 00010AC7 0F840DFFFFFF        <1> 	jz	sysdma_err
  3522                              <1> 
  3523 00010ACD 09D2                <1> 	or	edx, edx
  3524 00010ACF 7504                <1> 	jnz	short sysdma_11
  3525                              <1> 
  3526 00010AD1 89C2                <1> 	mov	edx, eax
  3527 00010AD3 EB08                <1> 	jmp	short sysdma_12	
  3528                              <1> sysdma_11:
  3529 00010AD5 39C2                <1> 	cmp	edx, eax
  3530 00010AD7 0F82FDFEFFFF        <1> 	jb	sysdma_err
  3531                              <1> sysdma_12:
  3532 00010ADD 21C9                <1> 	and	ecx, ecx
  3533 00010ADF 7508                <1> 	jnz	short sysdma_13
  3534                              <1> 
  3535 00010AE1 8B0D[686F0100]      <1> 	mov	ecx, [dma_size]
  3536 00010AE7 EB0C                <1> 	jmp	short sysdma_14
  3537                              <1> sysdma_13:
  3538 00010AE9 3B0D[686F0100]      <1> 	cmp	ecx, [dma_size]
  3539 00010AEF 0F87E5FEFFFF        <1> 	ja	sysdma_err
  3540                              <1> sysdma_14:
  3541 00010AF5 89C6                <1> 	mov	esi, eax
  3542 00010AF7 0335[686F0100]      <1> 	add	esi, [dma_size]
  3543                              <1> 
  3544 00010AFD 89D0                <1> 	mov	eax, edx
  3545 00010AFF 01C8                <1> 	add	eax, ecx
  3546 00010B01 0F82D3FEFFFF        <1> 	jc	sysdma_err ; 02/09/2017	
  3547                              <1> 		
  3548 00010B07 39F0                <1> 	cmp	eax, esi
  3549 00010B09 0F87CBFEFFFF        <1> 	ja	sysdma_err
  3550                              <1> 
  3551 00010B0F 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff]
  3552 00010B15 8B35[646F0100]      <1> 	mov	esi, [dma_addr]
  3553                              <1> 
  3554 00010B1B 09FF                <1> 	or	edi, edi
  3555 00010B1D 7424                <1> 	jz	short sysdma_16
  3556                              <1> 	
  3557 00010B1F 803D[216B0100]01    <1> 	cmp	byte [audio_device], 1
  3558 00010B26 7208                <1> 	jb	short sysdma_15
  3559                              <1> 
  3560                              <1> 	; Sound Blaster 16
  3561 00010B28 39FE                <1> 	cmp	esi, edi
  3562 00010B2A 0F84F4FEFFFF        <1> 	je	sysdma_0_err ; permmission denied !
  3563                              <1> 
  3564                              <1> sysdma_15:
  3565 00010B30 C605[636F0100]48    <1> 	mov	byte [dma_mode], 48h ; single mode playback	
  3566                              <1> 
  3567 00010B37 F6C380              <1> 	test	bl, 80h ; DMA mode - BL, bit 7, auto init -
  3568 00010B3A 7407                <1> 	jz	short sysdma_16	
  3569                              <1> 	; Auto initialized playback (write) mode
  3570 00010B3C 8005[636F0100]10    <1> 	add	byte [dma_mode], 10h ; = 58h
  3571                              <1> sysdma_16:
  3572 00010B43 80E307              <1> 	and	bl, 07h
  3573 00010B46 881D[626F0100]      <1> 	mov	[dma_channel], bl
  3574 00010B4C 8915[6C6F0100]      <1> 	mov	[dma_start], edx
  3575 00010B52 890D[706F0100]      <1> 	mov	[dma_count], ecx
  3576                              <1> 	 
  3577                              <1> 	; 28/08/2017
  3578                              <1> 	;call	dma_init
  3579                              <1> 	;jmp	sysret
  3580 00010B58 E94B010000          <1> 	jmp	dma_init
  3581                              <1> 
  3582                              <1> sysdma_5:
  3583 00010B5D 80FF05              <1> 	cmp	bh, 5
  3584 00010B60 7223                <1> 	jb	short sysdma_3
  3585 00010B62 0F87CE000000        <1> 	ja	sysdma_6	
  3586                              <1> 
  3587                              <1> 	; Get the system's default dma buffer addr and size
  3588 00010B68 B8[00000200]        <1> 	mov	eax, sb16_dma_buffer
  3589 00010B6D B900000100          <1> 	mov	ecx, 65536 ; Buffer size in bytes
  3590                              <1> 
  3591                              <1> sysdma_51:
  3592                              <1> 	; 0 = there is not a dma buffer (in use or available)
  3593 00010B72 A3[64030300]        <1> 	mov	[u.r0], eax
  3594                              <1> 
  3595 00010B77 8B2D[60030300]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  3596 00010B7D 894D18              <1> 	mov	[ebp+24], ecx ; return to user with ecx value
  3597                              <1> 
  3598 00010B80 E9B4BBFFFF          <1> 	jmp	sysret
  3599                              <1> 
  3600                              <1> sysdma_3:
  3601 00010B85 80FF03              <1> 	cmp	bh, 3
  3602 00010B88 7231                <1> 	jb	short sysdma_2
  3603 00010B8A 776B                <1> 	ja	short sysdma_4
  3604                              <1> 
  3605                              <1> 	; Get current dma count down value (remain bytes)
  3606                              <1> 	; 28/08/2017
  3607 00010B8C 0FB635[626F0100]    <1> 	movzx	esi, byte [dma_channel]
  3608 00010B93 0FB696[A8160100]    <1> 	movzx	edx, byte [dma_flip+esi]
  3609 00010B9A EE                  <1> 	out	dx, al			; flip-flop clear
  3610 00010B9B 8A96[88160100]      <1> 	mov	dl, [dma_cnt+esi] ; dma count register addr
  3611 00010BA1 EC                  <1> 	in	al, dx
  3612 00010BA2 0FB6D8              <1> 	movzx	ebx, al	
  3613 00010BA5 EC                  <1> 	in	al, dx
  3614 00010BA6 88C7                <1> 	mov     bh, al
  3615                              <1> 	
  3616 00010BA8 6683FE04            <1> 	cmp	si, 4 ; channel number ?
  3617 00010BAC 7202                <1> 	jb	short sysdma_31 ; 8 bit dma channel
  3618                              <1> 
  3619 00010BAE D1E3                <1> 	shl	ebx, 1	; word count to byte count
  3620                              <1> 
  3621                              <1> sysdma_31:
  3622 00010BB0 891D[64030300]      <1> 	mov	[u.r0], ebx
  3623                              <1> 
  3624 00010BB6 E97EBBFFFF          <1> 	jmp	sysret	
  3625                              <1> 
  3626                              <1> sysdma_2:
  3627                              <1> 	; Get current dma buffer offset (& page)
  3628                              <1> 	; 28/08/2017
  3629 00010BBB 0FB635[626F0100]    <1> 	movzx	esi, byte [dma_channel]
  3630 00010BC2 0FB696[A8160100]    <1> 	movzx	edx, byte [dma_flip+esi]
  3631 00010BC9 EE                  <1> 	out	dx, al			; flip-flop clear
  3632 00010BCA 8A96[80160100]      <1> 	mov	dl, [dma_adr+esi]
  3633 00010BD0 EC                  <1> 	in	al, dx			; get dma position
  3634 00010BD1 0FB6D8              <1> 	movzx	ebx, al
  3635 00010BD4 EC                  <1> 	in	al, dx			
  3636 00010BD5 88C7                <1> 	mov	bh, al
  3637                              <1> 
  3638 00010BD7 6683FE04            <1> 	cmp	si, 4 ; channel number ?
  3639 00010BDB 7202                <1> 	jb	short sysdma_21 ; 8 bit dma channel
  3640                              <1> 
  3641 00010BDD D1E3                <1> 	shl	ebx, 1	; word offset to byte offset
  3642                              <1> 
  3643                              <1> sysdma_21:
  3644 00010BDF 891D[64030300]      <1> 	mov	[u.r0], ebx
  3645                              <1> 
  3646 00010BE5 8A96[90160100]      <1> 	mov	dl, [dma_page+esi]
  3647 00010BEB EC                  <1> 	in	al, dx			; get dma page
  3648                              <1> 
  3649                              <1> 	;add	[u.ro+2], al
  3650 00010BEC 0805[66030300]      <1> 	or	[u.r0+2], al
  3651                              <1> 
  3652 00010BF2 E942BBFFFF          <1> 	jmp	sysret
  3653                              <1> 
  3654                              <1> sysdma_4:
  3655                              <1> 	; Get current DMA channel number
  3656                              <1> 	; 28/08/2017
  3657 00010BF7 8A25[616F0100]      <1> 	mov	ah, [dma_user]
  3658 00010BFD 20E4                <1> 	and	ah, ah
  3659 00010BFF 750F                <1> 	jnz	short sysdma_42
  3660                              <1> 
  3661                              <1> sysdma_41:	
  3662                              <1> 	; Not a valid dma channel (in use)
  3663 00010C01 C705[64030300]FFFF- <1> 	mov	dword [u.r0], -1 ; 0FFFFFFFFh
  3663 00010C09 FFFF                <1>
  3664 00010C0B E929BBFFFF          <1> 	jmp	sysret
  3665                              <1> 
  3666                              <1> sysdma_42:
  3667 00010C10 8B35[646F0100]      <1> 	mov	esi, [dma_addr]
  3668 00010C16 21F6                <1> 	and	esi, esi
  3669 00010C18 74E7                <1> 	jz	short sysdma_41
  3670                              <1> 
  3671 00010C1A 46                  <1> 	inc	esi ; -1 -> 0
  3672 00010C1B 74E4                <1> 	jz	short sysdma_41
  3673                              <1> 
  3674 00010C1D A0[626F0100]        <1> 	mov	al, [dma_channel]
  3675                              <1> 
  3676 00010C22 3A25[B3030300]      <1> 	cmp	ah, [u.uno]
  3677 00010C28 7502                <1> 	jne	short sysdma_43
  3678                              <1> 
  3679 00010C2A 30E4                <1> 	xor	ah, ah ; DMA channel in use by current user
  3680                              <1> 
  3681                              <1> sysdma_43:
  3682 00010C2C A3[64030300]        <1> 	mov	[u.r0], eax ; AL = dma channel number
  3683                              <1> 			    ; AH > 0 if the the channel
  3684                              <1> 			    ; in use by another user/process
  3685 00010C31 E903BBFFFF          <1> 	jmp	sysret
  3686                              <1> 
  3687                              <1> sysdma_6:
  3688 00010C36 80FF06              <1> 	cmp	bh, 6
  3689 00010C39 7710                <1> 	ja	short sysdma_7
  3690                              <1> 
  3691                              <1> 	; 28/08/2017
  3692                              <1> 	; Get current DMA buffer addr and size
  3693 00010C3B A1[646F0100]        <1> 	mov	eax, [dma_addr] ; dma buffer address
  3694 00010C40 8B0D[686F0100]      <1> 	mov	ecx, [dma_size] ; dma buffer size (in bytes)
  3695                              <1> 
  3696 00010C46 E927FFFFFF          <1> 	jmp	sysdma_51
  3697                              <1> 
  3698                              <1> sysdma_7:
  3699                              <1> 	; DMA service STOP
  3700 00010C4B A0[B3030300]        <1> 	mov	al, [u.uno]
  3701 00010C50 3A05[616F0100]      <1> 	cmp	al, [dma_user]
  3702 00010C56 751D                <1> 	jne	short sysdma_72
  3703                              <1> 	
  3704 00010C58 28C0                <1> 	sub	al, al ; 0
  3705                              <1> 
  3706 00010C5A A2[616F0100]        <1> 	mov	[dma_user], al ; clear user
  3707                              <1> 
  3708 00010C5F 8605[636F0100]      <1> 	xchg	al, [dma_mode]
  3709 00010C65 20C0                <1> 	and	al, al
  3710                              <1> 	;jz	short sysdma_err
  3711 00010C67 7527                <1> 	jnz	short sysdma_73	
  3712                              <1> 
  3713                              <1> sysdma_71:
  3714 00010C69 31C0                <1> 	xor	eax, eax
  3715 00010C6B A3[64030300]        <1> 	mov	[u.r0], eax; 0
  3716 00010C70 E9C4BAFFFF          <1> 	jmp	sysret
  3717                              <1> 
  3718                              <1> sysdma_72:
  3719                              <1> 	; 28/08/2017
  3720 00010C75 803D[616F0100]00    <1> 	cmp	byte [dma_user], 0
  3721 00010C7C 76EB                <1> 	jna	short sysdma_71 ; Nothing to do !
  3722                              <1> 
  3723 00010C7E 833D[646F0100]00    <1> 	cmp	dword [dma_addr], 0
  3724 00010C85 0F8799FDFFFF        <1> 	ja	sysdma_0_err
  3725                              <1> 	
  3726 00010C8B A2[616F0100]        <1> 	mov	[dma_user], al ; reset to current user
  3727                              <1> 
  3728                              <1> sysdma_73:
  3729                              <1> 	; 28/08/2017
  3730 00010C90 0FB635[626F0100]    <1> 	movzx	esi, byte [dma_channel]
  3731 00010C97 0FB696[98160100]    <1> 	movzx	edx, byte [dma_mask+esi]
  3732 00010C9E A0[626F0100]        <1> 	mov	al, [dma_channel]
  3733 00010CA3 0C04                <1> 	or	al, 4
  3734 00010CA5 EE                  <1> 	out	dx, al
  3735                              <1> 
  3736 00010CA6 EBC1                <1> 	jmp	short sysdma_71
  3737                              <1> 
  3738                              <1> dma_init:
  3739                              <1> 	; 28/08/2017
  3740                              <1> 	; 20/08/2017
  3741                              <1> 	; DMA initialization
  3742                              <1> 	; 14/08/2017
  3743                              <1> 	; 03/08/2017, 06/08/2017, 08/08/2017
  3744                              <1> 	; 02/07/2017, 13/07/2017, 16/07/2017, 30/07/2017
  3745                              <1> 	; (Derived from 'DMA_INIT' procedure in SB16MOD.ASM)
  3746                              <1> 	; Modified for TRDOS 386 DMA buffer allocation & initialization !
  3747                              <1> 
  3748 00010CA8 8B1D[6C6F0100]      <1> 	mov	ebx, [dma_start]
  3749 00010CAE 8B0D[706F0100]      <1> 	mov	ecx, [dma_count]
  3750                              <1> 
  3751 00010CB4 0FB635[626F0100]    <1> 	movzx	esi, byte [dma_channel]
  3752                              <1> 
  3753 00010CBB 6683FE04            <1> 	cmp	si, 4
  3754 00010CBF 7205                <1> 	jb	short gdmi1
  3755                              <1> 	; 08/08/2017
  3756 00010CC1 66D1E9              <1> 	shr	cx, 1 ; word count
  3757 00010CC4 D1EB                <1> 	shr	ebx, 1 ; convert byte offset to word offset
  3758                              <1> gdmi1:
  3759                              <1> 	;mov	[dma_poff], bx ; 08/08/2017
  3760 00010CC6 6649                <1> 	dec	cx			; dma size = block size - 1
  3761                              <1> 	
  3762 00010CC8 0FB696[98160100]    <1> 	movzx	edx, byte [dma_mask+esi] ; 30/07/2017
  3763 00010CCF A0[626F0100]        <1> 	mov	al, [dma_channel]
  3764 00010CD4 0C04                <1> 	or	al, 4
  3765 00010CD6 EE                  <1> 	out	dx, al			; dma channel mask
  3766                              <1> 
  3767 00010CD7 30C0                <1> 	xor	al, al ; 0 ; any value ! 08/08/2017
  3768 00010CD9 8A96[A8160100]      <1> 	mov	dl, [dma_flip+esi]
  3769 00010CDF EE                  <1> 	out	dx, al			; flip-flop clear
  3770                              <1> 	
  3771 00010CE0 8A96[A0160100]      <1> 	mov	dl, [dma_mod+esi]
  3772 00010CE6 A0[626F0100]        <1> 	mov	al, [dma_channel]  ; 13/07/2017
  3773 00010CEB 2403                <1> 	and	al, 3
  3774                              <1> 	; 08/08/2017
  3775 00010CED 0A05[636F0100]      <1> 	or	al, [dma_mode] ; 58h    ; dma mode for SB16
  3776 00010CF3 EE                  <1> 	out	dx, al			
  3777                              <1> 
  3778 00010CF4 8A96[80160100]      <1> 	mov	dl, [dma_adr+esi]	
  3779 00010CFA 88D8                <1> 	mov	al, bl			
  3780 00010CFC EE                  <1> 	out	dx, al			; offset low
  3781                              <1> 
  3782 00010CFD 88F8                <1> 	mov	al, bh
  3783 00010CFF EE                  <1> 	out	dx, al			; offset high
  3784                              <1> 
  3785 00010D00 8A96[88160100]      <1> 	mov	dl, [dma_cnt+esi]
  3786 00010D06 88C8                <1> 	mov	al, cl
  3787 00010D08 EE                  <1> 	out	dx, al			; size low
  3788                              <1> 
  3789 00010D09 88E8                <1> 	mov	al, ch
  3790 00010D0B EE                  <1> 	out	dx, al			; size high
  3791                              <1> 
  3792 00010D0C 8A96[90160100]      <1> 	mov	dl, [dma_page+esi]
  3793                              <1> 	; 14/08/2017 
  3794 00010D12 6683FE04            <1> 	cmp	si, 4
  3795 00010D16 7305                <1> 	jnb	short gdmi2
  3796 00010D18 C1EB10              <1> 	shr	ebx, 16
  3797 00010D1B EB06                <1> 	jmp	short gdmi3
  3798                              <1> gdmi2:
  3799                              <1> 	; 09/08/2017
  3800 00010D1D C1EB0F              <1> 	shr	ebx, 15	 ; complete 16 bit shift
  3801 00010D20 80E3FE              <1> 	and	bl, 0FEh ; clear bit 0 (not necessary)
  3802                              <1> gdmi3:	
  3803 00010D23 88D8                <1> 	mov	al, bl
  3804 00010D25 EE                  <1> 	out	dx, al			; page			
  3805                              <1> 	
  3806 00010D26 8A96[98160100]      <1> 	mov	dl, [dma_mask+esi]
  3807 00010D2C A0[626F0100]        <1> 	mov	al, [dma_channel]  ; 13/07/2017
  3808 00010D31 2403                <1> 	and	al, 3
  3809 00010D33 EE                  <1> 	out	dx, al			; dma channel unmask
  3810                              <1> 
  3811                              <1> 	;retn
  3812                              <1> 	; 28/08/2017
  3813 00010D34 E900BAFFFF          <1> 	jmp	sysret
  3814                              <1> 
  3815                              <1> otty:
  3816                              <1> sret:
  3817                              <1> ocvt:
  3818                              <1> ctty:
  3819                              <1> cret:
  3820                              <1> ccvt:
  3821                              <1> rtty:
  3822                              <1> wtty:
  3823                              <1> rmem:
  3824                              <1> wmem:
  3825                              <1> rfd:
  3826                              <1> rhd:
  3827                              <1> wfd:
  3828                              <1> whd:
  3829                              <1> rlpt:
  3830                              <1> wlpt:
  3831                              <1> rcvt:
  3832                              <1> xmtt:
  3833 00010D39 C3                  <1> 	retn
  2313                                  %include 'trdosk9.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.2) - INITIALIZED DATA : trdosk9.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 28/07/2020
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; ----------------------------------------------------------------------------
     9                              <1> ; Assembler: NASM version 2.14 (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 00010D3A 01                  <1> 		db 1 ; A: = 0 & B: = 1
    22                              <1> 
    23                              <1> Restore_CDIR:	
    24 00010D3B FF                  <1> 		db 0FFh ; Initial value -> any number except 0
    25                              <1> 
    26                              <1> msg_CRLF_temp:  
    27 00010D3C 070D0A00            <1> 		db 07h, 0Dh, 0Ah, 0
    28                              <1> 
    29                              <1> Magic_Bytes:
    30 00010D40 04                  <1> 		db 4
    31 00010D41 01                  <1> 		db 1
    32                              <1> mainprog_Version:
    33 00010D42 07                  <1> 		db 7
    34 00010D43 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.280720"
    34 00010D4C 61696E2050726F6772- <1>
    34 00010D55 616D2076322E302E32- <1>
    34 00010D5E 3830373230          <1>
    35 00010D63 0D0A                <1> 		db 0Dh, 0Ah
    36 00010D65 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2020"
    36 00010D6E 616E2054616E203230- <1>
    36 00010D77 30352D32303230      <1>
    37 00010D7E 0D0A00              <1> 		db 0Dh, 0Ah, 0
    38                              <1> 
    39                              <1> MainProgCfgFile: ; 14/04/2016
    40 00010D81 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
    40 00010D8A 43464700            <1>
    41                              <1> 
    42                              <1> TRDOSPromptLabel:
    43 00010D8E 5452444F53          <1> 		db "TRDOS"
    44 00010D93 00                  <1> 		db 0
    45 00010D94 00<rept>            <1>                 times 5 db 0
    46 00010D99 00                  <1> 		db 0
    47                              <1> 
    48                              <1> ; INTERNAL COMMANDS
    49                              <1> Command_List:
    50 00010D9A 44495200            <1> Cmd_Dir:	db "DIR", 0
    51 00010D9E 434400              <1> Cmd_Cd:		db "CD", 0
    52 00010DA1 433A00              <1> Cmd_Drive:	db "C:", 0
    53 00010DA4 56455200            <1> Cmd_Ver:	db "VER", 0
    54 00010DA8 4558495400          <1> Cmd_Exit:	db "EXIT", 0
    55 00010DAD 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
    56 00010DB4 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
    57 00010DBB 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
    58 00010DC4 4441544500          <1> Cmd_Date:	db "DATE", 0
    59 00010DC9 54494D4500          <1> Cmd_Time:	db "TIME", 0
    60 00010DCE 52554E00            <1> Cmd_Run:	db "RUN", 0
    61 00010DD2 53455400            <1> Cmd_Set:	db "SET", 0 
    62 00010DD6 434C5300            <1> Cmd_Cls:	db "CLS", 0
    63 00010DDA 53484F5700          <1> Cmd_Show:	db "SHOW", 0
    64 00010DDF 44454C00            <1> Cmd_Del:	db "DEL", 0
    65 00010DE3 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
    66 00010DEA 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
    67 00010DF1 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
    68 00010DF7 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
    69 00010DFD 434F505900          <1> Cmd_Copy:	db "COPY", 0
    70 00010E02 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
    71 00010E07 5041544800          <1> Cmd_Path:	db "PATH", 0
    72 00010E0C 4D454D00            <1> Cmd_Mem:	db "MEM", 0
    73 00010E10 00                  <1> 		db 0
    74 00010E11 46494E4400          <1> Cmd_Find:	db "FIND", 0
    75 00010E16 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
    76 00010E1B 2A00                <1> Cmd_Remark:	db "*", 0
    77 00010E1D 3F00                <1> Cmd_Help:	db "?", 0
    78 00010E1F 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
    79 00010E26 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
    80 00010E2E 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
    81 00010E34 4245455000          <1> Cmd_Beep:	db "BEEP", 0
    82                              <1> 		
    83 00010E39 00                  <1> 		db 0
    84                              <1> 
    85                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
    86                              <1> invalid_fname_chars:
    87 00010E3A 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
    88 00010E42 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
    89 00010E49 5B5C5D5E60          <1> 		db 5Bh, 5Ch, 5Dh, 5Eh, 60h
    90                              <1> sizeInvFnChars  equ ($ - invalid_fname_chars)                
    91                              <1> ;
    92                              <1> 
    93                              <1> Msg_Enter_Date:
    94 00010E4E 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
    94 00010E57 206461746520286464- <1>
    94 00010E60 2D6D6D2D7979293A20  <1>
    95 00010E69 00                  <1>                 db 0
    96                              <1> Msg_Show_Date:
    97 00010E6A 43757272656E742064- <1>                 db   'Current date is '
    97 00010E73 61746520697320      <1>
    98 00010E7A 30                  <1> Day:            db   '0'
    99 00010E7B 30                  <1> 		db   '0'
   100 00010E7C 2F                  <1>                 db   '/'
   101 00010E7D 30                  <1> Month:          db   '0'
   102 00010E7E 30                  <1> 		db   '0'
   103 00010E7F 2F                  <1>                 db   '/'
   104 00010E80 30                  <1> Century:        db   '0'
   105 00010E81 30                  <1>                 db   '0'
   106 00010E82 30                  <1> Year:           db   '0'
   107 00010E83 30                  <1> 		db   '0'
   108 00010E84 0D0A00              <1>                 db   0Dh, 0Ah, 0
   109                              <1> 
   110                              <1> Msg_Enter_Time:
   111 00010E87 456E746572206E6577- <1> 		db 'Enter new time: '
   111 00010E90 2074696D653A20      <1>
   112 00010E97 00                  <1> 		db 0
   113                              <1> Msg_Show_Time:
   114 00010E98 43757272656E742074- <1> 		db   'Current time is '
   114 00010EA1 696D6520697320      <1>
   115 00010EA8 30                  <1> Hour:           db   '0'
   116 00010EA9 30                  <1> 		db   '0'
   117 00010EAA 3A                  <1> 		db   ':'
   118 00010EAB 30                  <1> Minute:         db   '0'
   119 00010EAC 30                  <1> 		db   '0'
   120 00010EAD 3A                  <1> 		db   ':'
   121 00010EAE 30                  <1> Second:         db   '0'
   122 00010EAF 30                  <1> 		db   '0'
   123 00010EB0 0D0A00              <1> 		db   0Dh, 0Ah, 0
   124                              <1> 
   125                              <1> ;VolSize_Unit1:   dd 0
   126                              <1> ;VolSize_Unit2:   dd 0
   127                              <1> 
   128                              <1> VolSize_KiloBytes:
   129 00010EB3 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
   129 00010EBC 730D0A00            <1>
   130                              <1> VolSize_Bytes:
   131 00010EC0 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
   132                              <1> Volume_in_drive:
   133 00010EC9 0D0A                <1> 		db 0Dh, 0Ah
   134                              <1> Vol_FS_Name:
   135 00010ECB 54522046533120      <1> 		db "TR FS1 "
   136 00010ED2 566F6C756D6520696E- <1> 		db "Volume in drive "
   136 00010EDB 20647269766520      <1>
   137 00010EE2 30                  <1> Vol_Drv_Name:   db 30h
   138 00010EE3 3A                  <1> 		db ":"
   139 00010EE4 20697320            <1> 		db " is "
   140 00010EE8 0D0A00              <1> 		db 0Dh, 0Ah, 0
   141                              <1> Dir_Drive_Str:
   142 00010EEB 54522D444F53204472- <1>                 db "TR-DOS Drive "
   142 00010EF4 69766520            <1>
   143                              <1> Dir_Drive_Name:
   144 00010EF8 303A                <1>                 db "0:"
   145 00010EFA 0D0A                <1>                 db  0Dh, 0Ah
   146                              <1> Vol_Str_Header:
   147 00010EFC 566F6C756D65204E61- <1>                 db "Volume Name: "
   147 00010F05 6D653A20            <1>
   148                              <1> Vol_Name:
   149 00010F09 00<rept>            <1> 		times 64 db 0
   150 00010F49 00                  <1> 		db 0
   151                              <1> Vol_Serial_Header:
   152 00010F4A 0D0A                <1> 		db 0Dh, 0Ah
   153 00010F4C 566F6C756D65205365- <1> 		db "Volume Serial No: "
   153 00010F55 7269616C204E6F3A20  <1>
   154                              <1> Vol_Serial1:
   155 00010F5E 30303030            <1> 		db "0000"
   156 00010F62 2D                  <1> 		db "-"
   157                              <1> Vol_Serial2:
   158 00010F63 30303030            <1> 		db "0000"
   159 00010F67 0D0A00              <1> 		db 0Dh, 0Ah, 0
   160                              <1> 
   161                              <1> ;Vol_Tot_Sec_Str_Start:
   162                              <1> ;		dd 0
   163                              <1> Vol_Total_Sector_Header:
   164 00010F6A 0D0A                <1> 		db 0Dh, 0Ah
   165 00010F6C 566F6C756D65205369- <1> 		db "Volume Size : ", 0
   165 00010F75 7A65203A2000        <1>
   166                              <1> ;Vol_Tot_Sec_Str: 
   167                              <1> ;		db "0000000000"
   168                              <1> ;Vol_Tot_Sec_Str_End:
   169                              <1> ;		db 0
   170                              <1> ;Vol_Free_Sectors_Str_Start:
   171                              <1> ;		dd 0
   172                              <1> Vol_Free_Sectors_Header:
   173 00010F7B 467265652053706163- <1> 		db "Free Space  : ", 0
   173 00010F84 6520203A2000        <1>
   174                              <1> ;Vol_Free_Sectors_Str:
   175                              <1> ;		db "0000000000"
   176                              <1> ;Vol_Free_Sectors_Str_End:
   177                              <1> ;		db 0
   178                              <1> 
   179                              <1> Dir_Str_Header:
   180 00010F8A 4469726563746F7279- <1>                 db "Directory: "
   180 00010F93 3A20                <1>
   181 00010F95 2F                  <1> Dir_Str_Root:   db "/"
   182 00010F96 00<rept>            <1> Dir_Str:        times 64 db 0
   183 00010FD6 00000000            <1>                 dd 0
   184 00010FDA 00                  <1>                 db 0
   185                              <1> 
   186                              <1> Msg_Bad_Command:
   187 00010FDB 42616420636F6D6D61- <1>                 db "Bad command or file name!"
   187 00010FE4 6E64206F722066696C- <1>
   187 00010FED 65206E616D6521      <1>
   188 00010FF4 0D0A00              <1>                 db 0Dh, 0Ah, 0
   189                              <1> 
   190                              <1> msgl_drv_not_ready: 
   191 00010FF7 070D0A              <1> 		db 07h, 0Dh, 0Ah
   192                              <1> 
   193                              <1> ; CMD_INTR.ASM - 09/11/2011 - Messages
   194                              <1> 
   195                              <1> Msg_Not_Ready_Read_Err:
   196 00010FFA 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
   196 00011003 207265616479206F72- <1>
   196 0001100C 207265616420657272- <1>
   196 00011015 6F7221              <1>
   197 00011018 0D0A00              <1>                 db 0Dh, 0Ah, 0
   198                              <1> 
   199                              <1> Msg_Not_Ready_Write_Err:
   200 0001101B 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
   200 00011024 207265616479206F72- <1>
   200 0001102D 207772697465206572- <1>
   200 00011036 726F7221            <1>
   201 0001103A 0D0A00              <1>                 db 0Dh, 0Ah, 0
   202                              <1> 
   203                              <1> Msg_Dir_Not_Found:
   204 0001103D 4469726563746F7279- <1>                 db "Directory not found!"
   204 00011046 206E6F7420666F756E- <1>
   204 0001104F 6421                <1>
   205 00011051 0D0A00              <1>                 db 0Dh, 0Ah, 0
   206                              <1> 
   207                              <1> Msg_File_Not_Found:
   208 00011054 46696C65206E6F7420- <1>                 db "File not found!"
   208 0001105D 666F756E6421        <1>
   209 00011063 0D0A00              <1>                 db 0Dh, 0Ah, 0
   210                              <1> 
   211                              <1> Msg_File_Directory_Not_Found:
   212 00011066 46696C65206F722064- <1>                 db "File or directory not found!"
   212 0001106F 69726563746F727920- <1>
   212 00011078 6E6F7420666F756E64- <1>
   212 00011081 21                  <1>
   213 00011082 0D0A00              <1>                 db 0Dh, 0Ah, 0
   214                              <1> 
   215                              <1> Msg_LongName_Not_Found:
   216 00011085 4C6F6E67206E616D65- <1>                 db "Long name not found!"
   216 0001108E 206E6F7420666F756E- <1>
   216 00011097 6421                <1>
   217 00011099 0D0A00              <1>                 db 0Dh, 0Ah, 0
   218                              <1> 
   219                              <1> beep_Insufficient_Memory: ; 20/02/2017
   220 0001109C 0D0A                <1> 		db 0Dh, 0Ah
   221 0001109E 07                  <1> 		db 07h
   222                              <1> Msg_Insufficient_Memory:
   223 0001109F 496E73756666696369- <1>                 db "Insufficient memory!"
   223 000110A8 656E74206D656D6F72- <1>
   223 000110B1 7921                <1>
   224 000110B3 0D0A00              <1>                 db 0Dh, 0Ah, 0
   225                              <1> 
   226                              <1> Msg_Error_Code:
   227 000110B6 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
   227 000110BF 61696C656421204572- <1>
   227 000110C8 726F7220636F646520- <1>
   227 000110D1 3A20                <1>
   228 000110D3 303068              <1> error_code_hex: db '00h'
   229 000110D6 0A0A00              <1>                 db 0Ah, 0Ah, 0
   230                              <1> 
   231 000110D9 90                  <1> align 2
   232                              <1> 
   233                              <1> ; 10/02/2016
   234                              <1> ; DIR.ASM - 09/10/2011
   235                              <1> 
   236 000110DA 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
   236 000110E3 20                  <1>
   237                              <1> 
   238                              <1> File_Name:
   239 000110E4 20<rept>            <1>                 times 12 db 20h
   240 000110F0 20                  <1> 		db 20h
   241                              <1> Dir_Or_FileSize:
   242 000110F1 20<rept>            <1>                 times 10 db 20h
   243 000110FB 20                  <1> 		db 20h
   244                              <1> File_Attribute:
   245 000110FC 20202020            <1> 		dd 20202020h
   246 00011100 20                  <1> 		db 20h
   247                              <1> File_Day:
   248 00011101 3030                <1>                 db '0','0'
   249 00011103 2F                  <1> 		db '/'
   250                              <1> File_Month:
   251 00011104 3030                <1>                 db '0','0'
   252 00011106 2F                  <1> 		db '/'
   253                              <1> File_Year:
   254 00011107 30303030            <1>                 db '0','0','0','0'
   255 0001110B 20                  <1> 		db 20h
   256                              <1> File_Hour:
   257 0001110C 3030                <1>                 db '0','0'
   258 0001110E 3A                  <1> 		db ':'
   259                              <1> File_Minute:
   260 0001110F 3030                <1>                 db '0','0'
   261 00011111 00                  <1> 		db 0
   262                              <1> 
   263                              <1> Decimal_File_Count_Header:
   264 00011112 0D0A                <1> 		db 0Dh, 0Ah
   265                              <1> Decimal_File_Count:
   266 00011114 00<rept>            <1> 		times 6 db 0
   267                              <1> 
   268 0001111A 2066696C6528732920- <1> str_files:	db " file(s) & "
   268 00011123 2620                <1>
   269                              <1> Decimal_Dir_Count: 
   270 00011125 00<rept>            <1> 		times 6 db 0
   271                              <1> str_dirs:       
   272 0001112B 206469726563746F72- <1> 		db " directory(s) "
   272 00011134 7928732920          <1>
   273 00011139 0D0A00              <1> 		db 0Dh, 0Ah, 0
   274                              <1> 
   275 0001113C 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
   275 00011145 696E2066696C652873- <1>
   275 0001114E 29                  <1>
   276 0001114F 0D0A00              <1> 		db 0Dh, 0Ah, 0
   277                              <1> 
   278                              <1> ; CMD_INTR.ASM - 09/11/2011
   279                              <1> ; 07/10/2010
   280                              <1> Msg_invalid_name_chars:
   281 00011152 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
   281 0001115B 696C65206F72206469- <1>
   281 00011164 726563746F7279206E- <1>
   281 0001116D 616D65206368617261- <1>
   281 00011176 637465727321        <1>
   282 0001117C 0D0A00              <1>         	db 0Dh, 0Ah, 0
   283                              <1> ; 21/02/2016
   284 0001117F 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
   284 00011188 69726563746F727920- <1>
   284 00011191 6E616D652065786973- <1>
   284 0001119A 747321              <1>
   285 0001119D 0D0A00              <1>                 db 0Dh, 0Ah, 0
   286                              <1> Msg_DoYouWantMkdir:
   287 000111A0 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
   287 000111A9 6E7420746F206D616B- <1>
   287 000111B2 65206469726563746F- <1>
   287 000111BB 72792000            <1>
   288 000111BF 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
   288 000111C8 00                  <1>
   289 000111C9 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
   290 000111CD 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
   291                              <1> 
   292                              <1> ; 27/02/2016
   293                              <1> Msg_DoYouWantRmDir:
   294 000111D3 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
   294 000111DC 6E7420746F2064656C- <1>
   294 000111E5 657465206469726563- <1>
   294 000111EE 746F72792000        <1>
   295                              <1> Msg_Dir_Not_Empty:
   296 000111F4 4469726563746F7279- <1>                 db "Directory not empty!"
   296 000111FD 206E6F7420656D7074- <1>
   296 00011206 7921                <1>
   297 00011208 0D0A00              <1>                 db 0Dh, 0Ah, 0
   298                              <1> 
   299                              <1> Msg_DoYouWantDelete:
   300 0001120B 446F20796F75207761- <1>                 db "Do you want to delete file ",0
   300 00011214 6E7420746F2064656C- <1>
   300 0001121D 6574652066696C6520- <1>
   300 00011226 00                  <1>
   301                              <1> 
   302 00011227 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
   302 00011230 2E0D0A00            <1>
   303                              <1> 
   304                              <1> Msg_Permission_Denied:
   305 00011234 07                  <1>                 db 7
   306 00011235 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
   306 0001123E 6E2064656E69656421- <1>
   306 00011247 0D0A00              <1>
   307                              <1> 
   308                              <1> ; 04/03/2016
   309 0001124A 4E657720            <1> Msg_New:        db "New "
   310 0001124E 00                  <1>                 db 0
   311                              <1> Str_Attributes:
   312 0001124F 417474726962757465- <1>                 db "Attributes : "
   312 00011258 73203A20            <1>
   313 0001125C 4E4F524D414C        <1> Attr_Chars:     db "NORMAL"
   314 00011262 00                  <1>                 db 0
   315                              <1> 
   316                              <1> ; 06/03/2016
   317                              <1> ; CMD_INTR.ASM - 16/11/2010 
   318                              <1> Msg_DoYouWantRename:
   319 00011263 446F20796F75207761- <1>                 db "Do you want to rename ", 0
   319 0001126C 6E7420746F2072656E- <1>
   319 00011275 616D652000          <1>
   320 0001127A 66696C652000        <1> Rename_File:    db "file ", 0
   321 00011280 6469726563746F7279- <1> Rename_Directory: db "directory ", 0
   321 00011289 2000                <1>
   322 0001128B 00<rept>            <1> Rename_OldName: times 13 db 0
   323 00011298 20617320            <1> Msg_File_rename_as: db " as "
   324 0001129C 00<rept>            <1> Rename_NewName: times 13 db 0
   325                              <1> 
   326                              <1> ; 08/03/2016
   327                              <1> ; CMD_INTR.ASM - 01/08/2010 - 23/04/2011
   328                              <1> msg_not_same_drv:
   329 000112A9 4E6F742073616D6520- <1>                 db "Not same drive!" 
   329 000112B2 647269766521        <1>
   330 000112B8 0D0A00              <1>                 db 0Dh, 0Ah, 0 
   331                              <1> 
   332                              <1> Msg_DoYouWantMoveFile:
   333 000112BB 446F20796F75207761- <1>                 db "Do you want to move file", 0
   333 000112C4 6E7420746F206D6F76- <1>
   333 000112CD 652066696C6500      <1>
   334                              <1> 
   335                              <1> msg_insufficient_disk_space:
   336 000112D4 496E73756666696369- <1>                 db "Insufficient disk space!" 
   336 000112DD 656E74206469736B20- <1>
   336 000112E6 737061636521        <1>
   337 000112EC 0D0A00              <1>                 db 0Dh, 0Ah, 0
   338                              <1> 
   339                              <1> ; 01/08/2010
   340                              <1> msg_source_file: 
   341 000112EF 0D0A536F7572636520- <1> 		db 0Dh, 0Ah, "Source file name      :   "
   341 000112F8 66696C65206E616D65- <1>
   341 00011301 2020202020203A2020- <1>
   341 0001130A 20                  <1>
   342                              <1> msg_source_file_drv: 
   343 0001130B 203A00              <1> 		db " :", 0
   344                              <1> msg_destination_file: 
   345 0001130E 0D0A44657374696E61- <1> 		db 0Dh, 0Ah, "Destination file name :   "
   345 00011317 74696F6E2066696C65- <1>
   345 00011320 206E616D65203A2020- <1>
   345 00011329 20                  <1>
   346                              <1> msg_destination_file_drv: 
   347 0001132A 203A00              <1> 		db " :", 0
   348                              <1> msg_copy_nextline: 
   349 0001132D 0D0A00              <1> 		db 0Dh, 0Ah, 0
   350                              <1> 
   351                              <1> ; 15/03/2016
   352                              <1> ; CMD_INTR.ASM
   353                              <1> 
   354                              <1> Msg_DoYouWantOverWriteFile:
   355 00011330 446F20796F75207761- <1>                 db "Do you want to overwrite file ",0
   355 00011339 6E7420746F206F7665- <1>
   355 00011342 727772697465206669- <1>
   355 0001134B 6C652000            <1>
   356                              <1>   
   357                              <1> Msg_DoYouWantCopyFile:
   358 0001134F 446F20796F75207761- <1>                 db "Do you want to copy file",0
   358 00011358 6E7420746F20636F70- <1>
   358 00011361 792066696C6500      <1>
   359                              <1> 
   360                              <1> Msg_read_file_error_before_EOF:
   361 00011368 46696C652072656164- <1> 		db "File reading error! (before EOF)"
   361 00011371 696E67206572726F72- <1>
   361 0001137A 2120286265666F7265- <1>
   361 00011383 20454F4629          <1>
   362 00011388 0A0A00              <1> 		db 0Ah, 0Ah, 0
   363                              <1> 
   364                              <1> ; 18/03/2016
   365                              <1> ; TRDOS 386 (v2.0) mainprog copy procedure
   366                              <1> msg_reading:
   367 0001138B 52656164696E672E2E- <1> 		db "Reading... ", 0
   367 00011394 2E2000              <1>
   368                              <1> msg_writing:
   369 00011397 57726974696E672E2E- <1> 		db "Writing... ", 0
   369 000113A0 2E2000              <1>
   370                              <1> percentagestr:
   371 000113A3 2020202500          <1> 		db "   %", 0  ; "  0%" .. "100%"
   372                              <1> ; 11/04/2016
   373                              <1> Msg_No_Set_Space:
   374 000113A8 496E73756666696369- <1>                 db "Insufficient environment space!"
   374 000113B1 656E7420656E766972- <1>
   374 000113BA 6F6E6D656E74207370- <1>
   374 000113C3 61636521            <1>
   375 000113C7 0D0A00              <1>                 db 0Dh, 0Ah, 0
   376                              <1> ; 18/04/2016
   377                              <1> isc_msg:	
   378 000113CA 0D0A                <1> 		db 0Dh, 0Ah
   379 000113CC 494E56414C49442053- <1> 		db "INVALID SYSTEM CALL", 0
   379 000113D5 595354454D2043414C- <1>
   379 000113DE 4C00                <1>
   380                              <1> usi_msg:
   381 000113E0 0D0A                <1> 		db 0Dh, 0Ah
   382 000113E2 554E444546494E4544- <1> 		db "UNDEFINED SOFTWARE INTERRUPT", 0
   382 000113EB 20534F465457415245- <1>
   382 000113F4 20494E544552525550- <1>
   382 000113FD 5400                <1>
   383                              <1> ifc_msg:
   384 000113FF 0D0A                <1> 		db 0Dh, 0Ah
   385 00011401 494E56414C49442046- <1> 		db "INVALID FUNCTION CALL"
   385 0001140A 554E4354494F4E2043- <1>
   385 00011413 414C4C              <1>
   386                              <1> inv_msg_for_trdos_v2:
   387 00011416 20                  <1> 		db 20h
   388 00011417 666F72205452444F53- <1> 		db "for TRDOS v2!"
   388 00011420 20763221            <1>
   389 00011424 07                  <1> 		db 07h
   390 00011425 0D0A                <1> 		db 0Dh, 0Ah
   391 00011427 0D0A                <1> 		db 0Dh, 0Ah
   392 00011429 494E5420            <1> 		db "INT "
   393 0001142D 303068              <1> int_num_str:	db "00h"
   394 00011430 0D0A                <1> 		db 0Dh, 0Ah
   395 00011432 454158203A20        <1> 		db "EAX : "
   396 00011438 303030303030303068- <1> eax_str:	db "00000000h", 0Dh, 0Ah
   396 00011441 0D0A                <1>
   397 00011443 454950203A20        <1> 		db "EIP : "
   398 00011449 303030303030303068- <1> eip_str:	db "00000000h", 0Dh, 0Ah, 0
   398 00011452 0D0A00              <1>
   399                              <1> 
   400                              <1> ; 07/10/2016
   401                              <1> ; Device names & parameters (for kernel devices)
   402                              <1> 
   403 00011455 90                  <1> align 2
   404                              <1> KDEV_NAME:
   405 00011456 5454590000000000    <1> 		db 'TTY',0,0,0,0,0 ; 1
   406 0001145E 4D454D0000000000    <1> 		db 'MEM',0,0,0,0,0 ; 2
   407 00011466 4644300000000000    <1> 		db 'FD0',0,0,0,0,0 ; 3
   408 0001146E 4644310000000000    <1> 		db 'FD1',0,0,0,0,0 ; 4
   409 00011476 4844300000000000    <1> 		db 'HD0',0,0,0,0,0 ; 5
   410 0001147E 4844310000000000    <1> 		db 'HD1',0,0,0,0,0 ; 6
   411 00011486 4844320000000000    <1> 		db 'HD2',0,0,0,0,0 ; 7
   412 0001148E 4844330000000000    <1> 		db 'HD3',0,0,0,0,0 ; 8
   413 00011496 4C50540000000000    <1> 		db 'LPT',0,0,0,0,0 ; 9
   414 0001149E 5454593000000000    <1> 		db 'TTY0',0,0,0,0 ; 10
   415 000114A6 5454593100000000    <1> 		db 'TTY1',0,0,0,0 ; 11
   416 000114AE 5454593200000000    <1> 		db 'TTY2',0,0,0,0 ; 12
   417 000114B6 5454593300000000    <1> 		db 'TTY3',0,0,0,0 ; 13
   418 000114BE 5454593400000000    <1> 		db 'TTY4',0,0,0,0 ; 14
   419 000114C6 5454593500000000    <1> 		db 'TTY5',0,0,0,0 ; 15
   420 000114CE 5454593600000000    <1> 		db 'TTY6',0,0,0,0 ; 16
   421 000114D6 5454593700000000    <1> 		db 'TTY7',0,0,0,0 ; 17
   422 000114DE 5454593800000000    <1> 		db 'TTY8',0,0,0,0 ; 18
   423 000114E6 5454593900000000    <1> 		db 'TTY9',0,0,0,0 ; 19
   424 000114EE 434F4D3100000000    <1> 		db 'COM1',0,0,0,0 ; 18
   425 000114F6 434F4D3200000000    <1> 		db 'COM2',0,0,0,0 ; 19
   426                              <1> 		;db 'CONSOLE',0	  ; 1
   427                              <1> 		;db 'PRINTER',0   ; 9
   428                              <1> 		;db 'CDROM'	  ; 20
   429                              <1> 		;db 'CDROM0'	  ; 20
   430                              <1> 		;db 'CDROM1'	  ; 21		
   431                              <1> 		;db 'DVD'	  ; 22
   432                              <1> 		;db 'DVD0'	  ; 22
   433                              <1> 		;db 'DVD1'	  ; 23		
   434                              <1> 		;db 'USB'	  ; 24
   435                              <1> 		;db 'USB0'	  ; 24
   436                              <1> 		;db 'USB1'	  ; 25
   437                              <1> 		;db 'USB2'	  ; 26
   438                              <1> 		;db 'USB3'        ; 27
   439                              <1> 		;db 'KEYBOARD'	  ; 1	
   440                              <1> 		;db 'MOUSE'	  ; 28
   441                              <1> 		;db 'SOUND'	  ; 29
   442                              <1> 		;db 'VGA',0,0,0,0 ; 30
   443                              <1> 		;db 'CGA',0,0,0,0 ; 31
   444                              <1> 		;db 'AUDIO',0,0,0 ; 29
   445                              <1> 		;db 'VIDEO',0,0,0 ; 32
   446                              <1> 		;db 'MUSIC',0,0,0 ; 33
   447                              <1> 		;db 'ETHERNET'	  ; 34 		
   448                              <1> 		;db 'SD0',0,0,0,0,0 ; 35
   449                              <1> 		;db 'SD1',0,0,0,0,0 ; 36
   450                              <1> 		;db 'SD2',0,0,0,0,0 ; 37
   451                              <1> 		;db 'SD3',0,0,0,0,0 ; 38
   452                              <1> 		;db 'SATA0'	  ; 35
   453                              <1> 		;db 'SATA1'	  ; 36
   454                              <1> 		;db 'SATA2'        ; 37
   455                              <1> 		;db 'SATA3'        ; 38
   456                              <1> 		;db 'PATA0',0,0,0  ; 5
   457                              <1> 		;db 'PATA1',0,0,0  ; 6
   458                              <1> 		;db 'PATA2',0,0,0  ; 7
   459                              <1> 		;db 'PATA3',0,0,0  ; 8
   460                              <1> 		;db 'WIRELESS'	  ; 39
   461                              <1> 		;db 'HDMI',0,0,0,0 ; 40
   462 000114FE 4E554C4C00000000    <1> 		db 'NULL',0,0,0,0 ; 0
   463                              <1> 
   464                              <1> NumOfKernelDevNames equ ($-KDEV_NAME) / 8 ; 20 (07/10/2016)
   465                              <1> 
   466                              <1> KDEV_NUMBER:
   467 00011506 010203040506070809  <1> 		db 1,2,3,4,5,6,7,8,9
   468 0001150F 0A0B0C0D0E0F101112- <1> 		db 10,11,12,13,14,15,16,17,18,19
   468 00011518 13                  <1>
   469 00011519 121300              <1> 		db 18,19,0
   470                              <1> 
   471                              <1> NumOfKernelDevices equ $ - KDEV_NUMBER
   472                              <1> 
   473                              <1> KDEV_OADDR:
   474 0001151C [390D0100]          <1> 		dd otty ;tty  ; 1
   475 00011520 [390D0100]          <1> 		dd sret ;mem  ; 2
   476 00011524 [390D0100]          <1>  		dd sret ;fd0  ; 3
   477 00011528 [390D0100]          <1>  		dd sret ;fd1  ; 4
   478 0001152C [390D0100]          <1>  		dd sret ;hd0  ; 5
   479 00011530 [390D0100]          <1>  		dd sret ;hd1  ; 6
   480 00011534 [390D0100]          <1>  		dd sret ;hd2  ; 7
   481 00011538 [390D0100]          <1>  		dd sret ;hd3  ; 8
   482 0001153C [390D0100]          <1>  		dd sret ;lpt  ; 9
   483 00011540 [390D0100]          <1>  		dd ocvt ;tty0 ; 10
   484 00011544 [390D0100]          <1> 		dd ocvt ;tty1 ; 11
   485 00011548 [390D0100]          <1>  		dd ocvt ;tty2 ; 12
   486 0001154C [390D0100]          <1>  		dd ocvt ;tty3 ; 13
   487 00011550 [390D0100]          <1>  		dd ocvt ;tty4 ; 14
   488 00011554 [390D0100]          <1>  		dd ocvt ;tty5 ; 15
   489 00011558 [390D0100]          <1>  		dd ocvt ;tty6 ; 16
   490 0001155C [390D0100]          <1>  		dd ocvt ;tty7 ; 17
   491 00011560 [390D0100]          <1>  		dd ocvt ;tty8 ; 18
   492 00011564 [390D0100]          <1>  		dd ocvt ;tty9 ; 19
   493                              <1>  		;dd ocvt ;com1 ; 18
   494                              <1>  		;dd ocvt ;com2 ; 19
   495 00011568 [390D0100]          <1> 		dd sret ;null ; 20  
   496                              <1> KDEV_CADDR:
   497 0001156C [390D0100]          <1> 		dd ctty ;tty  ; 1
   498 00011570 [390D0100]          <1> 		dd cret ;mem  ; 2
   499 00011574 [390D0100]          <1>  		dd cret ;fd0  ; 3
   500 00011578 [390D0100]          <1>  		dd cret ;fd1  ; 4
   501 0001157C [390D0100]          <1>  		dd cret ;hd0  ; 5
   502 00011580 [390D0100]          <1>  		dd cret ;hd1  ; 6
   503 00011584 [390D0100]          <1>  		dd cret ;hd2  ; 7
   504 00011588 [390D0100]          <1>  		dd cret ;hd3  ; 8
   505 0001158C [390D0100]          <1>  		dd cret ;lpt  ; 9
   506 00011590 [390D0100]          <1>  		dd ocvt ;tty0 ; 10
   507 00011594 [390D0100]          <1> 		dd ccvt ;tty1 ; 11
   508 00011598 [390D0100]          <1>  		dd ccvt ;tty2 ; 12
   509 0001159C [390D0100]          <1>  		dd ccvt ;tty3 ; 13
   510 000115A0 [390D0100]          <1>  		dd ccvt ;tty4 ; 14
   511 000115A4 [390D0100]          <1>  		dd ccvt ;tty5 ; 15
   512 000115A8 [390D0100]          <1>  		dd ccvt ;tty6 ; 16
   513 000115AC [390D0100]          <1>  		dd ccvt ;tty7 ; 17
   514 000115B0 [390D0100]          <1>  		dd ccvt ;tty8 ; 18
   515 000115B4 [390D0100]          <1>  		dd ccvt ;tty9 ; 19
   516                              <1>  		;dd ccvt ;com1 ; 18
   517                              <1>  		;dd ccvt ;com2 ; 19
   518 000115B8 [390D0100]          <1> 		dd cret ;null ; 20
   519                              <1> 
   520                              <1> KDEV_RADDR:
   521 000115BC [390D0100]          <1> 		dd rtty ;tty  ; 1
   522 000115C0 [390D0100]          <1> 		dd rmem ;mem  ; 2
   523 000115C4 [390D0100]          <1>  		dd rfd  ;fd0  ; 3
   524 000115C8 [390D0100]          <1>  		dd rfd  ;fd1  ; 4
   525 000115CC [390D0100]          <1>  		dd rhd  ;hd0  ; 5
   526 000115D0 [390D0100]          <1>  		dd rhd  ;hd1  ; 6
   527 000115D4 [390D0100]          <1>  		dd rhd  ;hd2  ; 7
   528 000115D8 [390D0100]          <1>  		dd rhd  ;hd3  ; 8
   529 000115DC [390D0100]          <1>  		dd rlpt ;lpt  ; 9
   530 000115E0 [390D0100]          <1>  		dd rcvt ;tty0 ; 10
   531 000115E4 [390D0100]          <1> 		dd rcvt ;tty1 ; 11
   532 000115E8 [390D0100]          <1>  		dd rcvt ;tty2 ; 12
   533 000115EC [390D0100]          <1>  		dd rcvt ;tty3 ; 13
   534 000115F0 [390D0100]          <1>  		dd rcvt ;tty4 ; 14
   535 000115F4 [390D0100]          <1>  		dd rcvt ;tty5 ; 15
   536 000115F8 [390D0100]          <1>  		dd rcvt ;tty6 ; 16
   537 000115FC [390D0100]          <1>  		dd rcvt ;tty7 ; 17
   538 00011600 [390D0100]          <1>  		dd rcvt ;tty8 ; 18
   539 00011604 [390D0100]          <1>  		dd rcvt ;tty9 ; 19
   540                              <1>  		;dd rcvt ;com1 ; 18
   541                              <1>  		;dd rcvt ;com2 ; 19
   542 00011608 [1D010100]          <1> 		dd rnull ;null ; 20  
   543                              <1> KDEV_WADDR:
   544 0001160C [390D0100]          <1> 		dd wtty ;tty  ; 1
   545 00011610 [390D0100]          <1> 		dd wmem ;mem  ; 2
   546 00011614 [390D0100]          <1>  		dd wfd  ;fd0  ; 3
   547 00011618 [390D0100]          <1>  		dd wfd  ;fd1  ; 4
   548 0001161C [390D0100]          <1>  		dd whd  ;hd0  ; 5
   549 00011620 [390D0100]          <1>  		dd whd  ;hd1  ; 6
   550 00011624 [390D0100]          <1>  		dd whd  ;hd2  ; 7
   551 00011628 [390D0100]          <1>  		dd whd  ;hd3  ; 8
   552 0001162C [390D0100]          <1>  		dd wlpt ;lpt  ; 9
   553 00011630 [390D0100]          <1>  		dd xmtt ;tty0 ; 10
   554 00011634 [390D0100]          <1> 		dd xmtt ;tty1 ; 11
   555 00011638 [390D0100]          <1>  		dd xmtt ;tty2 ; 12
   556 0001163C [390D0100]          <1>  		dd xmtt ;tty3 ; 13
   557 00011640 [390D0100]          <1>  		dd xmtt ;tty4 ; 14
   558 00011644 [390D0100]          <1>  		dd xmtt ;tty5 ; 15
   559 00011648 [390D0100]          <1>  		dd xmtt ;tty6 ; 16
   560 0001164C [390D0100]          <1>  		dd xmtt ;tty7 ; 17
   561 00011650 [390D0100]          <1>  		dd xmtt ;tty8 ; 18
   562 00011654 [390D0100]          <1>  		dd xmtt ;tty9 ; 19
   563                              <1>  		;dd xmtt ;com1 ; 18
   564                              <1>  		;dd xmtt ;com2 ; 19
   565 00011658 [1E010100]          <1> 		dd wnull ;null ; 20  
   566                              <1> 
   567                              <1> ; DEV_ACCESS bits:
   568                              <1> 	; bit 0 = accessable by normal users
   569                              <1> 	; bit 1 = read access permission
   570                              <1> 	; bit 2 = write access permission
   571                              <1> 	; bit 3 = IOCTL permission to users
   572                              <1> 	; bit 4 = block device if it is set
   573                              <1> 	; bit 5 = 16 bit or 1024 byte data
   574                              <1> 	; bit 6 = 32 bit or 2048 byte data
   575                              <1> 	; bit 7 = installable device driver	
   576                              <1> 
   577                              <1> KDEV_ACCESS: ; 08/10/2016
   578 0001165C 07                  <1> 		db  00000111b	; tty, 1
   579 0001165D 07                  <1> 		db  00000111b	; mem, 2	
   580 0001165E 8F                  <1> 		db  10001111b	; fd0, 3	
   581 0001165F 8F                  <1> 		db  10001111b	; fd1, 4
   582 00011660 8F                  <1> 		db  10001111b	; hd0, 5
   583 00011661 8F                  <1> 		db  10001111b	; hd1, 6
   584 00011662 8F                  <1> 		db  10001111b	; hd2, 7
   585 00011663 8F                  <1> 		db  10001111b	; hd3, 8
   586 00011664 07                  <1> 		db  00000111b   ; lpt, 9
   587 00011665 07                  <1> 		db  00000111b	; tty0, 10
   588 00011666 07                  <1> 		db  00000111b	; tty1, 11
   589 00011667 07                  <1> 		db  00000111b	; tty2, 12
   590 00011668 07                  <1> 		db  00000111b	; tty3, 13
   591 00011669 07                  <1> 		db  00000111b	; tty4, 14
   592 0001166A 07                  <1> 		db  00000111b	; tty5, 15
   593 0001166B 07                  <1> 		db  00000111b	; tty6, 16
   594 0001166C 07                  <1> 		db  00000111b	; tty7, 17
   595 0001166D 07                  <1> 		db  00000111b	; tty8, 18
   596 0001166E 07                  <1> 		db  00000111b	; tty9, 19
   597                              <1> 		;db 00000111b	; com1, 18
   598                              <1> 		;db 00000111b	; com2, 19
   599 0001166F 00                  <1> 		db  00000000b   ; null, 0
   600                              <1> 
   601                              <1> ; 07/10/2016
   602                              <1> NumOfInstallableDevices equ 8
   603                              <1> NUMIDEV		equ NumOfInstallableDevices ; 8
   604                              <1> NUMOFDEVICES	equ NumOfKernelDevices + NumOfInstallableDevices
   605                              <1> 
   606                              <1> ; 26/02/2017
   607                              <1> ; IRQ Callback (& Signal Response Byte) service availibity
   608                              <1> ; 'syscalbac'
   609                              <1> ; ***************************************************
   610                              <1> ; IRQ 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
   611                              <1> ; --- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
   612                              <1> ; --- 00 00 00 01 02 03 00 04 00 05 06 07 08 09 00 00
   613                              <1> ; ***************************************************
   614                              <1> IRQenum:
   615 00011670 000000010203000400- <1> 	db  0,0,0,1,2,3,0,4,0,5,6,7,8,9,0,0
   615 00011679 05060708090000      <1>
   616                              <1> 
   617                              <1> ; 28/08/2017
   618                              <1> ; 20/08/2017
   619                              <1> ; DMA Registers (for 'sysdma')
   620                              <1> ; 02/07/2017 (sb16mod.s)
   621 00011680 00020406C0C4C8CC    <1> dma_adr:	db 0,2,4,6,0C0h,0C4h,0C8h,0CCh
   622 00011688 01030507C2C6CACE    <1> dma_cnt:	db 1,3,5,7,0C2h,0C6h,0CAh,0CEh
   623 00011690 878381828F8B898A    <1> dma_page:	db 87h,83h,81h,82h,8Fh,8Bh,89h,8Ah ; 03/08/2017
   624 00011698 0A0A0A0AD4D4D4D4    <1> dma_mask:	db 0Ah,0Ah,0Ah,0Ah,0D4h,0D4h,0D4h,0D4h
   625 000116A0 0B0B0B0BD6D6D6D6    <1> dma_mod:	db 0Bh,0Bh,0Bh,0Bh,0D6h,0D6h,0D6h,0D6h
   626 000116A8 0C0C0C0CD8D8D8D8    <1> dma_flip:	db 0Ch,0Ch,0Ch,0Ch,0D8h,0D8h,0D8h,0D8h	
  2314                                  
  2315                                  ; 27/08/2014
  2316                                  scr_row:
  2317 000116B0 E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
  2318                                  scr_col:
  2319 000116B4 00000000                	dd 0
  2320                                  
  2321                                  Align 4
  2322                                  	; 15/04/2016
  2323                                  	; TRDOS 386 (TRDOS v2.0)
  2324                                  
  2325                                  	; 21/08/2014
  2326                                  ilist:
  2327                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
  2328                                  	;
  2329                                  	; Exception list
  2330                                  	; 25/08/2014	
  2331 000116B8 [47090000]              	dd	exc0	; 0h,  Divide-by-zero Error
  2332 000116BC [4E090000]              	dd	exc1	
  2333 000116C0 [55090000]              	dd 	exc2	
  2334 000116C4 [5C090000]              	dd	exc3	
  2335 000116C8 [60090000]              	dd	exc4	
  2336 000116CC [64090000]              	dd	exc5	
  2337 000116D0 [68090000]              	dd 	exc6	; 06h,  Invalid Opcode
  2338 000116D4 [6C090000]              	dd	exc7	
  2339 000116D8 [70090000]              	dd	exc8	
  2340 000116DC [74090000]              	dd	exc9	
  2341 000116E0 [78090000]              	dd 	exc10	
  2342 000116E4 [7C090000]              	dd	exc11
  2343 000116E8 [80090000]              	dd	exc12
  2344 000116EC [84090000]              	dd	exc13	; 0Dh, General Protection Fault
  2345 000116F0 [88090000]              	dd 	exc14	; 0Eh, Page Fault
  2346 000116F4 [8C090000]              	dd	exc15
  2347 000116F8 [90090000]              	dd	exc16
  2348 000116FC [94090000]              	dd	exc17
  2349 00011700 [98090000]              	dd 	exc18
  2350 00011704 [9C090000]              	dd	exc19
  2351 00011708 [A0090000]              	dd 	exc20
  2352 0001170C [A4090000]              	dd	exc21
  2353 00011710 [A8090000]              	dd	exc22
  2354 00011714 [AC090000]              	dd	exc23
  2355 00011718 [B0090000]              	dd 	exc24
  2356 0001171C [B4090000]              	dd	exc25
  2357 00011720 [B8090000]              	dd	exc26
  2358 00011724 [BC090000]              	dd	exc27
  2359 00011728 [C0090000]              	dd 	exc28
  2360 0001172C [C4090000]              	dd	exc29
  2361 00011730 [C8090000]              	dd 	exc30
  2362 00011734 [CC090000]              	dd	exc31
  2363                                  IRQ_list: ; 28/02/2017 ('syscalbac')
  2364                                  	; Interrupt list
  2365 00011738 [BB060000]              	dd	timer_int	; INT 20h
  2366                                  		;dd	irq0	
  2367 0001173C [2F0E0000]              	dd	kb_int		; 24/01/2016
  2368                                  		;dd	irq1
  2369 00011740 [9D080000]              	dd	irq2
  2370                                  		; COM2 int
  2371 00011744 [A1080000]              	dd	irq3
  2372                                  		; COM1 int
  2373 00011748 [AC080000]              	dd	irq4
  2374 0001174C [B7080000]              	dd	irq5
  2375                                  ;DISKETTE_INT: ;06/02/2015
  2376 00011750 [E1410000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
  2377                                  		;dd	irq6
  2378                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  2379                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  2380 00011754 [260C0000]              	dd	default_irq7	; 25/02/2015
  2381                                  		;dd	irq7
  2382                                  ; Real Time Clock Interrupt
  2383 00011758 [26080000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
  2384                                  		;dd	irq8	; INT 28h
  2385 0001175C [C7080000]              	dd	irq9
  2386 00011760 [CB080000]              	dd	irq10
  2387 00011764 [CF080000]              	dd	irq11
  2388 00011768 [D3080000]              	dd	irq12
  2389 0001176C [D7080000]              	dd	irq13
  2390                                  ;HDISK_INT1:  ;06/02/2015 	
  2391 00011770 [5F4B0000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
  2392                                  		;dd	irq14
  2393                                  ;HDISK_INT2:  ;06/02/2015
  2394 00011774 [864B0000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
  2395                                  		;dd	irq15	; INT 2Fh
  2396                                  		; 14/08/2015
  2397                                  	;dd	sysent		; INT 30h (system calls)
  2398                                  
  2399                                  	; 15/04/2016
  2400                                  	; TRDOS 386(TRDOS v2.0) Software Interrupts
  2401                                  
  2402 00011778 [D5170100]              	dd	int30h		; Reserved for
  2403                                  				; !!! Retro UNIX (RUNIX) !!!
  2404                                  				; !!! SINGLIX !!! System Calls
  2405 0001177C [22150000]              	dd	int31h		; Video BIOS (IBM PC/AT, Int 10h)
  2406 00011780 [4E0C0000]              	dd	int32h		; Keyboard Functions (IBM PC/AT, Int 16h)
  2407 00011784 [98420000]              	dd	int33h		; DISK I/O (IBM PC/AT, Int 13h)
  2408 00011788 [CEF90000]              	dd	int34h		; #IOCTL# (I/O port access support for ring 3)
  2409 0001178C [B4590000]              	dd	int35h		; Time/Date Functions (IBM PC/AT, Int 1Ah)
  2410 00011790 [DA0A0000]              	dd	ignore_int	; INT 36h : Timer Functions	
  2411 00011794 [DA0A0000]              	dd	ignore_int	; INT 37h	
  2412 00011798 [DA0A0000]              	dd	ignore_int	; INT 38h
  2413 0001179C [DA0A0000]              	dd	ignore_int	; INT 39h
  2414 000117A0 [DA0A0000]              	dd	ignore_int	; INT 3Ah	
  2415 000117A4 [DA0A0000]              	dd	ignore_int	; INT 3Bh
  2416 000117A8 [DA0A0000]              	dd	ignore_int	; INT 3Ch
  2417 000117AC [DA0A0000]              	dd	ignore_int	; INT 3Dh	
  2418 000117B0 [DA0A0000]              	dd	ignore_int	; INT 3Eh
  2419 000117B4 [DA0A0000]              	dd	ignore_int	; INT 3Fh
  2420 000117B8 [E7C50000]              	dd	sysent		; INT 40h : !!! TRDOS 386 System Calls !!!
  2421                                  	;dd	ignore_int
  2422 000117BC 00000000                	dd	0
  2423                                  
  2424                                  ; 20/08/2014
  2425                                    ; /* This is the default interrupt "handler" :-) */ 
  2426                                    ; Linux v0.12 (head.s)
  2427                                  int_msg:
  2428 000117C0 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
  2428 000117C9 6E7465727275707420-
  2428 000117D2 212000             
  2429                                  
  2430                                  ; 15/04/2016
  2431                                  ; TRDOS 386 (TRDOS v2.0)
  2432                                  
  2433                                  ; 29/04/2016
  2434                                  int30h:
  2435                                  trdos_isc_routine:
  2436                                  	; 02/05/2016
  2437                                  	; 01/05/2016
  2438                                  	; 29/04/2016
  2439                                  	; 18/04/2016
  2440                                  	; 15/04/2016 (TRDOS 386 = TRDOS v2.0)
  2441                                  	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
  2442                                  	; 03/02/2011 ('trdos_ifc_routine')
  2443                                  	;
  2444 000117D5 8B1C24                  	mov	ebx, [esp] ; EIP (next)
  2445 000117D8 83EB02                  	sub	ebx, 2 ; EIP (CD ##h)
  2446                                  
  2447 000117DB 89C1                    	mov	ecx, eax
  2448 000117DD 8A4301                  	mov	al, [ebx+1] ; CDh ##h
  2449                                  
  2450 000117E0 66BA1000                	mov	dx, KDATA
  2451 000117E4 8EDA                    	mov	ds, dx
  2452 000117E6 8EC2                    	mov	es, dx
  2453                                  
  2454 000117E8 FC                      	cld
  2455 000117E9 8B15[A8580100]          	mov	edx, [k_page_dir]
  2456 000117EF 0F22DA                  	mov	cr3, edx
  2457                                  
  2458 000117F2 E8021BFFFF              	call	bytetohex
  2459 000117F7 66A3[2D140100]          	mov	[int_num_str], ax
  2460                                  
  2461 000117FD 89D8                    	mov	eax, ebx ; EIP
  2462 000117FF E8351BFFFF              	call	dwordtohex
  2463 00011804 8915[49140100]          	mov	[eip_str], edx
  2464 0001180A A3[4D140100]            	mov	[eip_str+4], eax
  2465                                  
  2466 0001180F 89C8                    	mov	eax, ecx
  2467 00011811 E8231BFFFF              	call	dwordtohex
  2468 00011816 8915[38140100]          	mov	[eax_str], edx
  2469 0001181C A3[3C140100]            	mov	[eax_str+4], eax 	
  2470                                  
  2471 00011821 43                      	inc	ebx
  2472 00011822 8A03                    	mov	al, [ebx] ; Interrupt number
  2473                                  
  2474                                  trdos_isc_handler:
  2475 00011824 80FE30                  	cmp	dh, 30h ; Retro UNIX, SINGLIX System calls
  2476 00011827 7507                    	jne	short trdos_usi_handler
  2477 00011829 BE[CA130100]            	mov	esi, isc_msg
  2478 0001182E EB05                    	jmp	short loc_write_inv_system_call_msg
  2479                                  
  2480                                  trdos_usi_handler:
  2481 00011830 BE[E0130100]            	mov	esi, usi_msg
  2482                                  
  2483                                  loc_write_inv_system_call_msg:
  2484 00011835 E8634BFFFF              	call	print_msg
  2485                                  	; 29/04/2016
  2486 0001183A BE[16140100]            	mov	esi, inv_msg_for_trdos_v2
  2487 0001183F E8594BFFFF              	call	print_msg
  2488                                  
  2489                                  loc_ifc_terminate_process:
  2490                                  	; u.uno = process number
  2491                                  	; 29/04/2016
  2492                                  
  2493                                  	; 02/05/2016
  2494 00011844 FE05[5B030300]          	inc	byte [sysflg] ; 0FFh -> 0
  2495                                  
  2496 0001184A B801000000              	mov	eax, 1
  2497 0001184F E96CB0FFFF              	jmp	sysexit
  2498                                  
  2499                                  ; 07/03/2015
  2500                                  ; Temporary Code
  2501                                  display_disks:
  2502 00011854 803D[265D0000]00        	cmp 	byte [fd0_type], 0
  2503 0001185B 7605                    	jna 	short ddsks1
  2504 0001185D E87D000000              	call	pdskm
  2505                                  ddsks1:
  2506 00011862 803D[275D0000]00        	cmp	byte [fd1_type], 0
  2507 00011869 760C                    	jna	short ddsks2
  2508 0001186B C605[AF190100]31        	mov	byte [dskx], '1'
  2509 00011872 E868000000              	call	pdskm
  2510                                  ddsks2:
  2511 00011877 803D[285D0000]00        	cmp	byte [hd0_type], 0
  2512 0001187E 7654                    	jna	short ddsk6
  2513 00011880 66C705[AD190100]68-     	mov	word [dsktype], 'hd'
  2513 00011888 64                 
  2514 00011889 C605[AF190100]30        	mov	byte [dskx], '0'
  2515 00011890 E84A000000              	call	pdskm
  2516                                  ddsks3:
  2517 00011895 803D[295D0000]00        	cmp	byte [hd1_type], 0
  2518 0001189C 7636                    	jna	short ddsk6
  2519 0001189E C605[AF190100]31        	mov	byte [dskx], '1'
  2520 000118A5 E835000000              	call	pdskm
  2521                                  ddsks4:
  2522 000118AA 803D[2A5D0000]00        	cmp	byte [hd2_type], 0
  2523 000118B1 7621                    	jna	short ddsk6
  2524 000118B3 C605[AF190100]32        	mov	byte [dskx], '2'
  2525 000118BA E820000000              	call	pdskm
  2526                                  ddsks5:
  2527 000118BF 803D[2B5D0000]00        	cmp	byte [hd3_type], 0
  2528 000118C6 760C                    	jna	short ddsk6
  2529 000118C8 C605[AF190100]33        	mov	byte [dskx], '3'
  2530 000118CF E80B000000              	call	pdskm
  2531                                  ddsk6:
  2532 000118D4 BE[D7190100]            	mov	esi, nextline
  2533 000118D9 E806000000              	call	pdskml
  2534                                  pdskm_ok:
  2535 000118DE C3                      	retn
  2536                                  pdskm:
  2537 000118DF BE[AB190100]            	mov	esi, dsk_ready_msg
  2538                                  pdskml:	
  2539 000118E4 AC                      	lodsb
  2540 000118E5 08C0                    	or	al, al
  2541 000118E7 74F5                    	jz	short pdskm_ok
  2542 000118E9 56                      	push	esi
  2543                                  	; 13/05/2016
  2544 000118EA BB07000000                      mov     ebx, 7  ; Black background, 
  2545                                  			; light gray forecolor
  2546                                  			; Video page 0 (bh=0)
  2547 000118EF E8EE03FFFF              	call	_write_tty
  2548 000118F4 5E                      	pop	esi
  2549 000118F5 EBED                    	jmp	short pdskml
  2550                                  
  2551 000118F7 90                      Align 2
  2552                                  	; 21/08/2014
  2553                                  exc_msg:
  2554 000118F8 435055206578636570-     	db "CPU exception ! "
  2554 00011901 74696F6E202120     
  2555                                  excnstr: 		; 25/08/2014
  2556 00011908 3F3F68202045495020-     	db "??h", "  EIP : "
  2556 00011911 3A20               
  2557                                  EIPstr: ; 29/08/2014
  2558 00011913 00<rept>                	times 12 db 0
  2559                                  
  2560                                  	; 23/02/2015
  2561                                  	; 25/08/2014
  2562                                  ;scounter:
  2563                                  ;	db 5
  2564                                  ;	db 19
  2565                                  
  2566                                  ; 06/11/2014
  2567                                  ; Memory Information message
  2568                                  ; 14/08/2015
  2569                                  msg_memory_info:
  2570 0001191F 07                      	db	07h
  2571 00011920 0D0A                    	db	0Dh, 0Ah
  2572                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
  2573 00011922 546F74616C206D656D-     	db	"Total memory : "
  2573 0001192B 6F7279203A20       
  2574                                  mem_total_b_str: ; 10 digits
  2575 00011931 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
  2575 0001193A 302062797465730D0A 
  2576 00011943 202020202020202020-     	db	"               ", 20h, 20h, 20h
  2576 0001194C 202020202020202020 
  2577                                  mem_total_p_str: ; 7 digits
  2578 00011955 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
  2578 0001195E 616765730D0A       
  2579 00011964 0D0A                    	db 	0Dh, 0Ah
  2580 00011966 46726565206D656D6F-     	db	"Free memory  : "
  2580 0001196F 727920203A20       
  2581                                  free_mem_b_str:  ; 10 digits
  2582 00011975 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
  2582 0001197E 3F2062797465730D0A 
  2583 00011987 202020202020202020-     	db	"               ", 20h, 20h, 20h
  2583 00011990 202020202020202020 
  2584                                  free_mem_p_str:  ; 7 digits
  2585 00011999 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
  2585 000119A2 616765730D0A       
  2586 000119A8 0D0A00                  	db	0Dh, 0Ah, 0
  2587                                  
  2588                                  dsk_ready_msg:
  2589 000119AB 0D0A                    	db 	0Dh, 0Ah
  2590                                  dsktype:
  2591 000119AD 6664                    	db	'fd'
  2592                                  dskx:
  2593 000119AF 30                      	db	'0'
  2594 000119B0 20                      	db	20h
  2595 000119B1 697320524541445920-     	db 	'is READY ...'
  2595 000119BA 2E2E2E             
  2596 000119BD 00                      	db 	0
  2597                                  
  2598                                  setup_error_msg:
  2599 000119BE 0D0A                    	db 0Dh, 0Ah
  2600 000119C0 4469736B2053657475-     	db 'Disk Setup Error !' 
  2600 000119C9 70204572726F722021 
  2601 000119D2 0D0A00                  	db 0Dh, 0Ah,0
  2602                                  
  2603                                  next2line: ; 08/02/2016
  2604 000119D5 0D0A                    	db	0Dh, 0Ah
  2605                                  nextline:
  2606 000119D7 0D0A00                  	db 	0Dh, 0Ah, 0
  2607                                  
  2608                                  ; KERNEL - SYSINIT Messages
  2609                                  ; 24/08/2015
  2610                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
  2611                                  ; 14/07/2013
  2612                                  ;kernel_init_err_msg:
  2613                                  ;	db 0Dh, 0Ah
  2614                                  ;	db 07h
  2615                                  ;	db 'Kernel initialization ERROR !'
  2616                                  ;	db 0Dh, 0Ah, 0 
  2617                                  
  2618                                  ;welcome_msg: 
  2619                                  ;	db 0Dh, 0Ah
  2620                                  ;	db 07h
  2621                                  ;	db 'Welcome to TRDOS 386 Operating System !'
  2622                                  ;	db 0Dh, 0Ah
  2623                                  ;	db 'by Erdogan Tan - 31/12/2017 (v2.0.0)'
  2624                                  ;	db 0Dh, 0Ah, 0
  2625                                  
  2626                                  panic_msg:
  2627 000119DA 0D0A07                  	db 0Dh, 0Ah, 07h
  2628 000119DD 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
  2628 000119E6 726E656C2050616E69-
  2628 000119EF 632021             
  2629 000119F2 0D0A00                  	db 0Dh, 0Ah, 0
  2630                                  
  2631                                  ;msgl_drv_not_ready: 
  2632                                  ;	db 07h, 0Dh, 0Ah
  2633                                  ;       db 'Drive not ready or read error !'
  2634                                  ;       db 0Dh, 0Ah, 0
  2635                                  
  2636                                  starting_msg:
  2637 000119F5 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [28/07/2020] ...", 0
  2637 000119FE 6174696F6E616C2044-
  2637 00011A07 4F532076322E30205B-
  2637 00011A10 32382F30372F323032-
  2637 00011A19 305D202E2E2E00     
  2638                                  NextLine:
  2639 00011A20 0D0A00                  	db 0Dh, 0Ah, 0
  2640                                  
  2641                                  %include 'audio.s' ; 03/04/2017
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.2 - audio.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 27/07/2020
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 03/04/2017
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
     9                              <1> ; ****************************************************************************
    10                              <1> 
    11                              <1> ; AUDIO CONTROLLER & CODEC DEFINITIONS & CODE FOR TRDOS 386
    12                              <1> 
    13                              <1> ;=============================================================================
    14                              <1> ;               EQUATES
    15                              <1> ;=============================================================================
    16                              <1> 
    17                              <1> ; PCI EQUATES
    18                              <1> 
    19                              <1> BIT0  EQU 1
    20                              <1> BIT1  EQU 2
    21                              <1> BIT2  EQU 4
    22                              <1> BIT3  EQU 8
    23                              <1> BIT4  EQU 10h
    24                              <1> BIT5  EQU 20h
    25                              <1> BIT6  EQU 40h
    26                              <1> BIT7  EQU 80h
    27                              <1> BIT8  EQU 100h
    28                              <1> BIT9  EQU 200h
    29                              <1> BIT10 EQU 400h
    30                              <1> BIT11 EQU 800h
    31                              <1> BIT12 EQU 1000h
    32                              <1> BIT13 EQU 2000h
    33                              <1> BIT14 EQU 4000h
    34                              <1> BIT15 EQU 8000h
    35                              <1> BIT16 EQU 10000h
    36                              <1> BIT17 EQU 20000h
    37                              <1> BIT18 EQU 40000h
    38                              <1> BIT19 EQU 80000h
    39                              <1> BIT20 EQU 100000h
    40                              <1> BIT21 EQU 200000h
    41                              <1> BIT22 EQU 400000h
    42                              <1> BIT23 EQU 800000h
    43                              <1> BIT24 EQU 1000000h
    44                              <1> BIT25 EQU 2000000h
    45                              <1> BIT26 EQU 4000000h
    46                              <1> BIT27 EQU 8000000h
    47                              <1> BIT28 EQU 10000000h
    48                              <1> BIT29 EQU 20000000h
    49                              <1> BIT30 EQU 40000000h
    50                              <1> BIT31 EQU 80000000h
    51                              <1> NOT_BIT31 EQU 7FFFFFFFh
    52                              <1> 
    53                              <1> ; PCI equates
    54                              <1> ; PCI function address (PFA)
    55                              <1> ; bit 31 = 1
    56                              <1> ; bit 23:16 = bus number     (0-255)
    57                              <1> ; bit 15:11 = device number  (0-31)
    58                              <1> ; bit 10:8 = function number (0-7)
    59                              <1> ; bit 7:0 = register number  (0-255)
    60                              <1> 
    61                              <1> IO_ADDR_MASK    EQU     0FFFEh	; mask off bit 0 for reading BARs
    62                              <1> PCI_INDEX_PORT  EQU     0CF8h
    63                              <1> PCI_DATA_PORT   EQU     0CFCh
    64                              <1> PCI32           EQU     BIT31	; bitflag to signal 32bit access
    65                              <1> PCI16           EQU     BIT30	; bitflag for 16bit access
    66                              <1> NOT_PCI32_PCI16	EQU	03FFFFFFFh ; NOT BIT31+BIT30 ; 19/03/2017
    67                              <1> 
    68                              <1> PCI_FN0         EQU     0 << 8
    69                              <1> PCI_FN1         EQU     1 << 8
    70                              <1> PCI_FN2         EQU     2 << 8
    71                              <1> PCI_FN3         EQU     3 << 8
    72                              <1> PCI_FN4         EQU     4 << 8
    73                              <1> PCI_FN5         EQU     5 << 8
    74                              <1> PCI_FN6         EQU     6 << 8
    75                              <1> PCI_FN7         EQU     7 << 8
    76                              <1> 
    77                              <1> PCI_CMD_REG	EQU	04h	; reg 04, command reg
    78                              <1> IO_ENA		EQU	BIT0	; i/o decode enable
    79                              <1> MEM_ENA		EQU	BIT1	; memory decode enable
    80                              <1> BM_ENA		EQU     BIT2	; bus master enable
    81                              <1> 
    82                              <1> ; VIA VT8233 EQUATES
    83                              <1> 
    84                              <1> VIA_VID		equ 1106h	; VIA's PCI vendor ID
    85                              <1> VT8233_DID      equ 3059h	; VT8233 (VT8235) device ID
    86                              <1> 		
    87                              <1> PCI_IO_BASE          equ 10h
    88                              <1> AC97_INT_LINE        equ 3Ch
    89                              <1> VIA_ACLINK_CTRL      equ 41h
    90                              <1> VIA_ACLINK_STAT      equ 40h
    91                              <1> VIA_ACLINK_C00_READY equ 01h ; primary codec ready
    92                              <1> 	
    93                              <1> VIA_REG_AC97	     equ 80h ; dword
    94                              <1> 
    95                              <1> VIA_ACLINK_CTRL_ENABLE	equ   80h ; 0: disable, 1: enable
    96                              <1> VIA_ACLINK_CTRL_RESET	equ   40h ; 0: assert, 1: de-assert
    97                              <1> VIA_ACLINK_CTRL_SYNC	equ   20h ; 0: release SYNC, 1: force SYNC hi
    98                              <1> VIA_ACLINK_CTRL_VRA	equ   08h ; 0: disable VRA, 1: enable VRA
    99                              <1> VIA_ACLINK_CTRL_PCM	equ   04h ; 0: disable PCM, 1: enable PCM
   100                              <1> 					; 3D Audio Channel slots 3/4
   104                              <1> VIA_ACLINK_CTRL_INIT	equ  (VIA_ACLINK_CTRL_ENABLE +                               VIA_ACLINK_CTRL_RESET +                               VIA_ACLINK_CTRL_PCM +                               VIA_ACLINK_CTRL_VRA)
   105                              <1> 
   106                              <1> CODEC_AUX_VOL		equ   04h
   107                              <1> VIA_REG_AC97_BUSY	equ   01000000h ;(1<<24) 
   108                              <1> VIA_REG_AC97_CMD_SHIFT	equ   10h ; 16
   109                              <1> VIA_REG_AC97_PRIMARY_VALID equ 02000000h ;(1<<25)
   110                              <1> VIA_REG_AC97_READ	equ   00800000h ;(1<<23)
   111                              <1> VIA_REG_AC97_CODEC_ID_SHIFT   equ  1Eh ; 30
   112                              <1> VIA_REG_AC97_CODEC_ID_PRIMARY equ  0
   113                              <1> VIA_REG_AC97_DATA_SHIFT equ   0
   114                              <1> VIADEV_PLAYBACK         equ   0
   115                              <1> VIA_REG_OFFSET_STATUS   equ   0    ;; byte - channel status
   116                              <1> VIA_REG_OFFSET_CONTROL  equ   01h  ;; byte - channel control
   117                              <1> VIA_REG_CTRL_START	equ   80h  ;; WO
   118                              <1> VIA_REG_CTRL_TERMINATE  equ   40h  ;; WO
   119                              <1> VIA_REG_CTRL_PAUSE      equ   08h  ;; RW
   120                              <1> VIA_REG_CTRL_RESET      equ   01h  ;; RW - probably reset? undocumented
   121                              <1> VIA_REG_OFFSET_STOP_IDX equ   08h  ;; dword - stop index, channel type, sample rate
   122                              <1> VIA8233_REG_TYPE_16BIT  equ   200000h ;; RW
   123                              <1> VIA8233_REG_TYPE_STEREO equ   100000h ;; RW
   124                              <1> VIA_REG_OFFSET_CURR_INDEX equ 0Fh ;; byte - channel current index (for via8233 only)
   125                              <1> VIA_REG_OFFSET_TABLE_PTR equ  04h  ;; dword - channel table pointer
   126                              <1> VIA_REG_OFFSET_CURR_PTR equ   04h  ;; dword - channel current pointer
   127                              <1> VIA_REG_OFS_PLAYBACK_VOLUME_L equ  02h ;; byte
   128                              <1> VIA_REG_OFS_PLAYBACK_VOLUME_R equ  03h ;; byte
   129                              <1> VIA_REG_CTRL_AUTOSTART	equ   20h
   130                              <1> VIA_REG_CTRL_INT_EOL	equ   02h
   131                              <1> VIA_REG_CTRL_INT_FLAG	equ   01h
   134                              <1> VIA_REG_CTRL_INT	equ  (VIA_REG_CTRL_INT_FLAG +                               VIA_REG_CTRL_INT_EOL +                               VIA_REG_CTRL_AUTOSTART)
   135                              <1> 
   136                              <1> VIA_REG_STAT_STOP_IDX	equ   10h    ;; RO ; 27/07/2020
   137                              <1> 				     ; current index = stop index
   138                              <1> VIA_REG_STAT_STOPPED	equ   04h    ;; RWC
   139                              <1> VIA_REG_STAT_EOL	equ   02h    ;; RWC
   140                              <1> VIA_REG_STAT_FLAG	equ   01h    ;; RWC
   141                              <1> VIA_REG_STAT_ACTIVE	equ   80h    ;; RO
   142                              <1> ; 28/11/2016
   143                              <1> VIA_REG_STAT_LAST	equ   40h    ;; RO
   144                              <1> VIA_REG_STAT_TRIGGER_QUEUED equ 08h  ;; RO
   145                              <1> VIA_REG_CTRL_INT_STOP	equ   04h  ; Interrupt on Current Index = Stop Index
   146                              <1> 		   		   ; and End of Block
   147                              <1> 
   148                              <1> VIA_REG_OFFSET_CURR_COUNT equ 0Ch ;; dword - channel current count, index
   149                              <1> 
   150                              <1> PORTB		EQU	061h
   151                              <1> REFRESH_STATUS	EQU	010h	; Refresh signal status
   152                              <1> 
   153                              <1> ; AC97 Codec registers.
   154                              <1> 
   155                              <1> ; 22/07/2020
   156                              <1> ; REALTEK ALC655 and ADI SOUNDMAX AD1980 CODEC MIXER REGISTERS
   157                              <1> 
   158                              <1> ; each codec/mixer register is 16bits
   159                              <1> 
   160                              <1> CODEC_RESET_REG                 equ     00h	; reset codec
   161                              <1> CODEC_MASTER_VOL_REG            equ     02h	; master volume
   162                              <1> CODEC_HP_VOL_REG                equ     04h	; headphone volume ; AD1980
   163                              <1> CODEC_MASTER_MONO_VOL_REG       equ     06h	; master mono volume (mono-out)
   164                              <1> ;CODEC_MASTER_TONE_REG          equ     08h	; master tone (R+L) ; (not used)
   165                              <1> CODEC_PCBEEP_VOL_REG            equ     0Ah	; PC beep volume ; ALC655
   166                              <1> CODEC_PHONE_VOL_REG             equ     0Ch	; phone volume
   167                              <1> CODEC_MIC_VOL_REG               equ     0Eh	; mic volume
   168                              <1> CODEC_LINE_IN_VOL_REG           equ     10h	; line in volume
   169                              <1> CODEC_CD_VOL_REG                equ     12h	; CD volume
   170                              <1> ;CODEC_VID_VOL_REG              equ     14h	; video volume ; (not used)
   171                              <1> CODEC_AUX_VOL_REG               equ     16h	; aux volume
   172                              <1> CODEC_PCM_OUT_REG               equ     18h	; PCM out volume
   173                              <1> CODEC_RECORD_SELECT_REG         equ     1Ah	; record select
   174                              <1> CODEC_RECORD_VOL_REG            equ     1Ch	; record volume (record gain)
   175                              <1> ;CODEC_RECORD_MIC_VOL_REG       equ     1Eh	; record mic volume ; (not used)
   176                              <1> CODEC_GP_REG                    equ     20h	; general purpose
   177                              <1> ;CODEC_3D_CONTROL_REG           equ     22h	; 3D control
   178                              <1> ;;CODEC_AUDIO_INT_PAGING_REG    equ	24h	; audio int & paging ; (not used) 
   179                              <1> CODEC_POWER_CTRL_REG            equ     26h	; power down control
   180                              <1> CODEC_EXT_AUDIO_REG             equ     28h	; extended audio ID
   181                              <1> CODEC_EXT_AUDIO_CTRL_REG        equ     2Ah	; extended audio status/control
   182                              <1> CODEC_PCM_FRONT_DACRATE_REG     equ     2Ch	; PCM front sample rate
   183                              <1> CODEC_PCM_SURND_DACRATE_REG     equ     2Eh	; PCM surround sample rate
   184                              <1> CODEC_PCM_LFE_DACRATE_REG       equ     30h	; PCM Center/LFE sample rate
   185                              <1> CODEC_LR_ADCRATE_REG            equ     32h	; PCM input sample rate
   186                              <1> CODEC_MIC_ADCRATE_REG           equ     34h	; mic in sample rate  ; AD1980
   187                              <1> CODEC_PCM_LFE_VOL_REG           equ     36h	; PCM Center/LFE volume
   188                              <1> CODEC_PCM_SURND_VOL_REG         equ     38h	; PCM surround volume
   189                              <1> ;CODEC_SPDIF_CTRL_REG           equ     3Ah	; S/PDIF control
   190                              <1> ; 22/07/2020
   191                              <1> CODEC_MISC_CRTL_BITS_REG	equ	76h	; misc control bits ; AD1980
   192                              <1> ;	
   193                              <1> CODEC_VENDOR_ID1		equ	7Ch	; REALTEK: 414Ch, ADI: 4144h	
   194                              <1> CODEC_VENDOR_ID2		equ	7Eh	; REALTEK: 4760h, ADI: 5370h	
   195                              <1> 
   196                              <1> ; VT8233 SGD bits (21/04/2017)
   197                              <1> FLAG	EQU BIT30
   198                              <1> EOL	EQU BIT31
   199                              <1> 
   200                              <1> ; INTEL ICH EQUATES
   201                              <1> ; 28/05/2017
   202                              <1> INTEL_VID	equ	8086h	; Intel's PCI vendor ID
   203                              <1> ICH_DID		equ	2415h	; ICH (82801AA) device ID
   204                              <1> NAMBAR_REG      equ	10h	; native audio mixer Base Address Register
   205                              <1> NABMBAR_REG     equ	14h	; native audio bus mastering Base Addr Reg
   206                              <1> 
   207                              <1> PI_CR_REG       equ     0Bh     ; PCM in Control Register
   208                              <1> PO_CR_REG	equ     1Bh     ; PCM out Control Register
   209                              <1> MC_CR_REG	equ     2Bh     ; MIC in Control Register
   210                              <1> 
   211                              <1> PI_SR_REG	equ     6       ; PCM in Status register
   212                              <1> PO_SR_REG	equ     16h     ; PCM out Status register
   213                              <1> MC_SR_REG	equ     26h     ; MIC in Status register
   214                              <1> 
   215                              <1> IOCE 		equ     BIT4    ; interrupt on complete enable.
   216                              <1> FEIFE		equ     BIT3    ; set if you want an interrupt to fire
   217                              <1> LVBIE		equ     BIT2    ; last valid buffer interrupt enable.
   218                              <1> RR 		equ     BIT1    ; reset registers.  Nukes all regs
   219                              <1>                                 ; except bits 4:2 of this register.
   220                              <1>                                 ; Only set this bit if BIT 0 is 0
   221                              <1> RPBM		equ     BIT0    ; Run/Pause
   222                              <1> 				; set this bit to start the codec!
   223                              <1> 
   224                              <1> PI_BDBAR_REG	equ     0       ; PCM in buffer descriptor BAR
   225                              <1> PO_BDBAR_REG	equ     10h     ; PCM out buffer descriptor BAR
   226                              <1> MC_BDBAR_REG	equ     20h     ; MIC in buffer descriptor BAR
   227                              <1> 
   228                              <1> PI_CIV_REG	equ     4       ; PCM in current Index value (RO)
   229                              <1> PO_CIV_REG	equ     14h     ; PCM out current Index value (RO)
   230                              <1> MC_CIV_REG 	equ     24h     ; MIC in current Index value (RO)
   231                              <1> 
   232                              <1> PI_LVI_REG	equ     5       ; PCM in Last Valid Index
   233                              <1> PO_LVI_REG	equ     15h     ; PCM out Last Valid Index
   234                              <1> MC_LVI_REG	equ     25h     ; MIC in Last Valid Index
   235                              <1> 
   236                              <1> IOC		equ     BIT31	; Fire an interrupt whenever this
   237                              <1>                 		; buffer is complete.
   238                              <1> BUP		equ     BIT30	; Buffer Underrun Policy.
   239                              <1> 
   240                              <1> GLOB_CNT_REG	equ     2Ch     ; Global Control Register
   241                              <1> GLOB_STS_REG	equ     30h     ; Global Status register (RO)
   242                              <1> 
   243                              <1> CTRL_ST_CREADY	equ   BIT8+BIT9+BIT28 ; Primary Codec Ready
   244                              <1> 
   245                              <1> CODEC_REG_POWERDOWN   equ 26h
   246                              <1> CODEC_REG_ST          equ 26h
   247                              <1> 
   248                              <1> ; 22/06/2017
   249                              <1> PO_PICB_REG	equ 18h	; PCM Out Position In Current Buffer Register
   250                              <1> 
   251                              <1> ;=============================================================================
   252                              <1> ;               CODE
   253                              <1> ;=============================================================================
   254                              <1> 
   255                              <1> ; CODE for INTEL ICH AC'97 AUDIO CONTROLLER
   256                              <1> 
   257                              <1> DetectICH:
   258                              <1> 	; 10/06/2017
   259                              <1> 	; 05/06/2017
   260                              <1> 	; 29/05/2017
   261                              <1> 	; 28/05/2017
   262 00011A23 B886801524          <1> 	mov     eax, (ICH_DID << 16) + INTEL_VID
   263 00011A28 E876000000          <1>         call    pciFindDevice
   264 00011A2D 730D                <1>         jnc     short d_ac97_1
   265                              <1> d_ac97_0:
   266                              <1> ; couldn't find the audio device!
   267 00011A2F C3                  <1> 	retn
   268                              <1> 
   269                              <1> ; CODE for VIA VT8233 AUDIO CONTROLLER
   270                              <1> 
   271                              <1> DetectVT8233:
   272                              <1> 	; 10/06/2017
   273                              <1> 	; 05/06/2017
   274                              <1> 	; 29/05/2017
   275                              <1> 	; 03/04/2017
   276 00011A30 B806115930          <1> 	mov     eax, (VT8233_DID << 16) + VIA_VID
   277 00011A35 E869000000          <1>         call    pciFindDevice
   278                              <1> ;       jnc     short d_vt8233_0
   279                              <1> ; couldn't find the audio device!
   280                              <1> ;	retn
   281 00011A3A 72F3                <1> 	jc	short d_ac97_0  ; 28/05/2017
   282                              <1> d_vt8233_0:
   283                              <1> 	; 24/03/2017 ('player.asm')
   284                              <1> 	; 12/11/2016 
   285                              <1> 	; Erdogan Tan - 8/11/2016
   286                              <1> 	; References: Kolibrios - vt823x.asm (2016)
   287                              <1> 	;	      VIA VT8235 V-Link South Bridge (VT8235-VIA.PDF)(2002)
   288                              <1> 	;	      lowlevel.eu - AC97 (2016)
   289                              <1> 	;	      .wav player for DOS by Jeff Leyda (2002) -this file-
   290                              <1> 	;	      Linux kernel - via82xx.c (2016)
   291                              <1> d_ac97_1:
   292                              <1> 	; eax = BUS/DEV/FN
   293                              <1> 	;	00000000BBBBBBBBDDDDDFFF00000000
   294                              <1> 	; edx = DEV/VENDOR
   295                              <1> 	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   296                              <1> 
   297 00011A3C A3[286B0100]        <1> 	mov	[audio_dev_id], eax
   298 00011A41 8915[2C6B0100]      <1> 	mov	[audio_vendor], edx
   299                              <1> 
   300                              <1> 	; init controller
   301 00011A47 B004                <1> 	mov	al, PCI_CMD_REG ; command register (04h)
   302 00011A49 E8E2000000          <1> 	call	pciRegRead32
   303                              <1> 
   304                              <1> 	; eax = BUS/DEV/FN/REG
   305                              <1> 	; edx = STATUS/COMMAND
   306                              <1> 	; 	SSSSSSSSSSSSSSSSCCCCCCCCCCCCCCCC
   307 00011A4E 8915[306B0100]      <1> 	mov	[audio_stats_cmd], edx
   308                              <1> 
   309 00011A54 B010                <1> 	mov	al, PCI_IO_BASE ; IO base address register (10h)
   310                              <1> 	;mov	al, NAMBAR_REG	; Native Audio Mixer BAR (10h)
   311 00011A56 E8D5000000          <1> 	call	pciRegRead32
   312                              <1> 
   313 00011A5B 66813D[2C6B0100]86- <1> 	cmp	word [audio_vendor], 8086h ; AC'97 ?
   313 00011A63 80                  <1>
   314 00011A64 751F                <1> 	jne	short d_vt8233_1
   315                              <1> 
   316 00011A66 6683E2FE            <1> 	and	dx, 0FFFEh ; Audio Codec IO_ADDR_MASK
   317 00011A6A 668915[586B0100]    <1> 	mov	[NAMBAR], dx
   318                              <1> 
   319 00011A71 B014                <1> 	mov	al, NABMBAR_REG ; Native Audio Bus Mastering BAR (14h)
   320 00011A73 E8B8000000          <1> 	call	pciRegRead32	
   321                              <1> 
   322 00011A78 6683E2C0            <1> 	and	dx, 0FFC0h ; Audio Controller IO_ADDR_MASK
   323 00011A7C 668915[5A6B0100]    <1> 	mov	[NABMBAR], dx
   324                              <1>         ;mov	[audio_io_base], dx
   325                              <1> 	
   326 00011A83 EB0B                <1> 	jmp	short d_ac97_2
   327                              <1> 
   328                              <1> d_vt8233_1:
   329 00011A85 6683E2C0            <1> 	and     dx, 0FFC0h ; Audio Controller IO_ADDR_MASK 
   330 00011A89 668915[266B0100]    <1>         mov     [audio_io_base], dx
   331                              <1> 
   332                              <1> d_ac97_2:
   333                              <1> 	; 10/06/2017
   334 00011A90 B03C                <1> 	mov	al, AC97_INT_LINE ; Interrupt Line Register (3Ch)
   335                              <1> 	;call	pciRegRead32
   336 00011A92 E886000000          <1> 	call	pciRegRead8
   337                              <1> 
   338                              <1> 	;and 	edx, 0FFh
   339 00011A97 6681E2FF00          <1> 	and	dx, 0FFh
   340                              <1> 
   341 00011A9C 8815[236B0100]      <1>   	mov     [audio_intr], dl
   342                              <1> 
   343 00011AA2 C3                  <1> 	retn
   344                              <1> 
   345                              <1> 	;; (Note: Interrupts are already enabled by TRDOS 386 kernel!)
   346                              <1> 	;mov	cx, dx
   347                              <1> 	
   348                              <1> 	;in	al, 0A1h ; irq 8-15
   349                              <1> 	;mov	ah, al
   350                              <1> 	;in	al, 21h  ; irq 0-7 
   351                              <1> 	;btr	ax, dx	 ; unmask ; 17/03/2017
   352                              <1> 	;;bts	ax, dx   ; MASK interrupt ; 10/06/2017 
   353                              <1> 	;out	21h, al  ; irq <= 7
   354                              <1> 	;mov	al, ah
   355                              <1> 	;out	0A1h, al ; irq > 7
   356                              <1> 	;
   357                              <1> 	
   358                              <1> 	; 10/06/2017
   359                              <1> 	; === Intel ICH I/O Controller Hub Datasheet, Section 8.1.16 ===
   360                              <1> 	; PRQ[n]_ROUT Register (61h, PRQB) Bit 7:
   361                              <1> 	; Interrupt Routing Enable (IRQEN).
   362                              <1> 	; 0 = The corresponding PIRQ is routed to one of the ISA-compatible
   363                              <1> 	;     interrupts specified in bits[3:0].
   364                              <1> 	; 1 = The PIRQ is not routed to the 8259.
   365                              <1> 	; Note: If the PIRQ is intended to cause an interrupt to the ICHs 
   366                              <1> 	;	integrated I/O APIC, then this bit should be set to 0 and 
   367                              <1> 	;	the APIC_EN bit should be set to 1. 
   368                              <1> 	;	The IRQEN must be set to 0 and the PIRQ routed to 
   369                              <1> 	;	an 8259 interrupt via the IRQ Routing filed (bits[3:0).
   370                              <1> 	;	The corresponding 8259 interrupt must be masked via the 
   371                              <1> 	;	appropriated bit in the 8259s OCW1 (Interrupt Mask)
   372                              <1> 	;	register. The IOAPIC must then be enabled by setting 
   373                              <1> 	;	the APIC_EN bit in the GEN_CNTL register.
   374                              <1> 
   375                              <1> 	;mov	eax, 0F861h  ; D31:F0
   376                              <1> 		;AL=61h : PIRQ[B] Routing Control Reg, LPC interface
   377                              <1> 	;;mov	dl, [audio_intr]
   378                              <1> 	;call	pciRegWrite8
   379                              <1> 	;;mov	al, 0D0h ; General Control Register (GEN_CTL)
   380                              <1> 	;;call	pciRegRead32
   381                              <1> 	;;or	edx, 100h ; Bit 8, APIC_EN (Enable I/O APIC) 
   382                              <1> 	;;;call	pciRegWrite32
   383                              <1> 	;;and	edx, ~100h
   384                              <1> 	;;call	pciRegWrite32 ; ; Bit 8, APIC_EN (Disable I/O APIC) 
   385                              <1> 	;
   386                              <1> 
   387                              <1> 	;mov	dx, 4D1h	; 8259 ELCR2
   388                              <1>     	;in	al, dx
   389                              <1> 	;mov	ah, al
   390                              <1> 	;;mov	dx, 4D0h 	; 8259 ELCR1
   391                              <1> 	;dec	dl
   392                              <1> 	;in	al, dx
   393                              <1> 	;bts	ax, cx
   394                              <1> 	;;mov	dx, 4D0h
   395                              <1> 	;out	dx, al		; set level-triggered mode
   396                              <1> 	;mov	al, ah ; 29/05/2017
   397                              <1> 	;;mov	dx, 4D1h
   398                              <1> 	;inc	dl
   399                              <1> 	;out	dx, al		; set level-triggered mode
   400                              <1> 
   401                              <1> 	;xor	eax, eax ; 0
   402                              <1> 
   403                              <1> 	;retn
   404                              <1> 
   405                              <1> ; CODE for PCI
   406                              <1> 
   407                              <1> pciFindDevice:
   408                              <1> 	; 03/04/2017 ('pci.asm', 20/03/2017)
   409                              <1> 	;
   410                              <1> 	; scan through PCI space looking for a device+vendor ID
   411                              <1> 	;
   412                              <1> 	; Entry: EAX=Device+Vendor ID
   413                              <1> 	;
   414                              <1> 	; Exit: EAX=PCI address if device found
   415                              <1> 	;	 EDX=Device+Vendor ID
   416                              <1> 	;        CY clear if found, set if not found. EAX invalid if CY set.
   417                              <1> 	;
   418                              <1> 	; Destroys: ebx, esi, edi, cl
   419                              <1> 	;
   420                              <1> 
   421                              <1> 	;push	ecx
   422 00011AA3 50                  <1> 	push	eax
   423                              <1> 	;push	esi
   424                              <1> 	;push	edi
   425                              <1> 
   426 00011AA4 89C6                <1>         mov     esi, eax                ; save off vend+device ID
   427 00011AA6 BF00FFFF7F          <1>         mov     edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
   428                              <1> 
   429                              <1> nextPCIdevice:
   430 00011AAB 81C700010000        <1>         add     edi, 100h
   431 00011AB1 81FF00F8FF80        <1>         cmp     edi, 80FFF800h		; scanned all devices?
   432 00011AB7 F9                  <1>         stc
   433 00011AB8 740C                <1>         je      short PCIScanExit       ; not found
   434                              <1> 
   435 00011ABA 89F8                <1>         mov     eax, edi                ; read PCI registers
   436 00011ABC E86F000000          <1>         call    pciRegRead32
   437 00011AC1 39F2                <1>         cmp     edx, esi                ; found device?
   438 00011AC3 75E6                <1>         jne     short nextPCIdevice
   439 00011AC5 F8                  <1>         clc
   440                              <1> 
   441                              <1> PCIScanExit:
   442 00011AC6 9C                  <1> 	pushf
   443 00011AC7 B8FFFFFF7F          <1> 	mov	eax, NOT_BIT31 	; 19/03/2017
   444 00011ACC 21F8                <1> 	and	eax, edi	; return only bus/dev/fn #
   445 00011ACE 9D                  <1> 	popf
   446                              <1> 
   447                              <1> 	;pop	edi
   448                              <1> 	;pop	esi
   449 00011ACF 5A                  <1> 	pop	edx
   450                              <1> 	;pop	ecx
   451 00011AD0 C3                  <1> 	retn
   452                              <1> 
   453                              <1> pciRegRead:
   454                              <1> 	; 03/04/2017 ('pci.asm', 20/03/2017)
   455                              <1> 	;
   456                              <1> 	; 8/16/32bit PCI reader
   457                              <1> 	;
   458                              <1> 	; Entry: EAX=PCI Bus/Device/fn/register number
   459                              <1> 	;           BIT30 set if 32 bit access requested
   460                              <1> 	;           BIT29 set if 16 bit access requested
   461                              <1> 	;           otherwise defaults to 8 bit read
   462                              <1> 	;
   463                              <1> 	; Exit:  DL,DX,EDX register data depending on requested read size
   464                              <1> 	;
   465                              <1> 	; Note1: this routine is meant to be called via pciRegRead8,
   466                              <1> 	;	 pciRegread16 or pciRegRead32, listed below.
   467                              <1> 	;
   468                              <1> 	; Note2: don't attempt to read 32 bits of data from a non dword
   469                              <1> 	;	 aligned reg number.  Likewise, don't do 16 bit reads from
   470                              <1> 	;	 non word aligned reg #
   471                              <1> 	
   472 00011AD1 53                  <1> 	push	ebx
   473 00011AD2 51                  <1> 	push	ecx
   474 00011AD3 89C3                <1>         mov     ebx, eax		; save eax, dh
   475 00011AD5 88F1                <1>         mov     cl, dh
   476                              <1> 
   477 00011AD7 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   478 00011ADC 0D00000080          <1>         or      eax, BIT31		; make a PCI access request
   479 00011AE1 24FC                <1>         and     al, ~3 ; NOT 3		; force index to be dword
   480                              <1> 
   481 00011AE3 66BAF80C            <1>         mov     dx, PCI_INDEX_PORT
   482 00011AE7 EF                  <1>         out	dx, eax			; write PCI selector
   483                              <1> 	
   484 00011AE8 66BAFC0C            <1>         mov     dx, PCI_DATA_PORT
   485 00011AEC 88D8                <1>         mov     al, bl
   486 00011AEE 2403                <1>         and     al, 3			; figure out which port to
   487 00011AF0 00C2                <1>         add     dl, al			; read to
   488                              <1> 
   489 00011AF2 F7C3000000C0        <1> 	test    ebx, PCI32+PCI16
   490 00011AF8 7507                <1>         jnz     short _pregr0
   491 00011AFA EC                  <1> 	in	al, dx			; return 8 bits of data
   492 00011AFB 88C2                <1>         mov	dl, al
   493 00011AFD 88CE                <1> 	mov     dh, cl			; restore dh for 8 bit read
   494 00011AFF EB12                <1> 	jmp	short _pregr2
   495                              <1> _pregr0:	
   496 00011B01 F7C300000080        <1> 	test    ebx, PCI32
   497 00011B07 7507                <1>         jnz	short _pregr1
   498 00011B09 66ED                <1> 	in	ax, dx
   499 00011B0B 6689C2              <1>         mov     dx, ax			; return 16 bits of data
   500 00011B0E EB03                <1> 	jmp	short _pregr2
   501                              <1> _pregr1:
   502 00011B10 ED                  <1> 	in	eax, dx			; return 32 bits of data
   503 00011B11 89C2                <1> 	mov	edx, eax
   504                              <1> _pregr2:
   505 00011B13 89D8                <1> 	mov     eax, ebx		; restore eax
   506 00011B15 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   507 00011B1A 59                  <1> 	pop	ecx
   508 00011B1B 5B                  <1> 	pop	ebx
   509 00011B1C C3                  <1> 	retn
   510                              <1> 
   511                              <1> pciRegRead8:
   512 00011B1D 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 8 bit read size
   513 00011B22 EBAD                <1>         jmp     short pciRegRead	; call generic PCI access
   514                              <1> 
   515                              <1> pciRegRead16:
   516 00011B24 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 16 bit read size
   517 00011B29 0D00000040          <1>         or      eax, PCI16		; call generic PCI access
   518 00011B2E EBA1                <1>         jmp     short pciRegRead
   519                              <1> 
   520                              <1> pciRegRead32:
   521 00011B30 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 32 bit read size
   522 00011B35 0D00000080          <1>         or      eax, PCI32		; call generic PCI access
   523 00011B3A EB95                <1>         jmp     pciRegRead
   524                              <1> 
   525                              <1> pciRegWrite:
   526                              <1> 	; 03/04/2017 ('pci.asm', 29/11/2016)
   527                              <1> 	;
   528                              <1> 	; 8/16/32bit PCI writer
   529                              <1> 	;
   530                              <1> 	; Entry: EAX=PCI Bus/Device/fn/register number
   531                              <1> 	;           BIT31 set if 32 bit access requested
   532                              <1> 	;           BIT30 set if 16 bit access requested
   533                              <1> 	;           otherwise defaults to 8bit read
   534                              <1> 	;        DL/DX/EDX data to write depending on size
   535                              <1> 	;
   536                              <1> 	; Note1: this routine is meant to be called via pciRegWrite8, 
   537                              <1> 	;	 pciRegWrite16 or pciRegWrite32 as detailed below.
   538                              <1> 	;
   539                              <1> 	; Note2: don't attempt to write 32bits of data from a non dword
   540                              <1> 	;	 aligned reg number. Likewise, don't do 16 bit writes from
   541                              <1> 	;	 non word aligned reg #
   542                              <1> 
   543 00011B3C 53                  <1> 	push	ebx
   544 00011B3D 51                  <1> 	push	ecx
   545 00011B3E 89C3                <1>         mov     ebx, eax		; save eax, edx
   546 00011B40 89D1                <1>         mov     ecx, edx
   547 00011B42 25FFFFFF3F          <1> 	and     eax, NOT_PCI32_PCI16	; clear out data size request
   548 00011B47 0D00000080          <1>         or      eax, BIT31		; make a PCI access request
   549 00011B4C 24FC                <1>         and     al, ~3 ; NOT 3		; force index to be dword
   550                              <1> 
   551 00011B4E 66BAF80C            <1>         mov     dx, PCI_INDEX_PORT
   552 00011B52 EF                  <1>         out	dx, eax			; write PCI selector
   553                              <1> 	
   554 00011B53 66BAFC0C            <1>         mov     dx, PCI_DATA_PORT
   555 00011B57 88D8                <1>         mov     al, bl
   556 00011B59 2403                <1>         and     al, 3			; figure out which port to
   557 00011B5B 00C2                <1>         add     dl, al			; write to
   558                              <1> 
   559 00011B5D F7C3000000C0        <1> 	test    ebx, PCI32+PCI16
   560 00011B63 7505                <1>         jnz     short _pregw0
   561 00011B65 88C8                <1> 	mov	al, cl 			; put data into al
   562 00011B67 EE                  <1> 	out	dx, al
   563 00011B68 EB12                <1> 	jmp	short _pregw2
   564                              <1> _pregw0:
   565 00011B6A F7C300000080        <1> 	test    ebx, PCI32
   566 00011B70 7507                <1>         jnz     short _pregw1
   567 00011B72 6689C8              <1> 	mov	ax, cx			; put data into ax
   568 00011B75 66EF                <1> 	out	dx, ax
   569 00011B77 EB03                <1> 	jmp	short _pregw2
   570                              <1> _pregw1:
   571 00011B79 89C8                <1> 	mov	eax, ecx		; put data into eax 		
   572 00011B7B EF                  <1> 	out	dx, eax
   573                              <1> _pregw2:
   574 00011B7C 89D8                <1>         mov     eax, ebx		; restore eax
   575 00011B7E 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   576 00011B83 89CA                <1>         mov     edx, ecx		; restore dx
   577 00011B85 59                  <1> 	pop	ecx
   578 00011B86 5B                  <1> 	pop	ebx
   579 00011B87 C3                  <1> 	retn
   580                              <1> 
   581                              <1> pciRegWrite8:
   582 00011B88 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 8 bit write size
   583 00011B8D EBAD                <1>         jmp	short pciRegWrite	; call generic PCI access
   584                              <1> 
   585                              <1> pciRegWrite16:
   586 00011B8F 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 16 bit write size
   587 00011B94 0D00000040          <1>         or      eax, PCI16		; call generic PCI access
   588 00011B99 EBA1                <1>         jmp	short pciRegWrite
   589                              <1> 
   590                              <1> pciRegWrite32:
   591 00011B9B 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 32 bit write size
   592 00011BA0 0D00000080          <1>         or      eax, PCI32		; call generic PCI access
   593 00011BA5 EB95                <1>         jmp	pciRegWrite
   594                              <1> 
   595                              <1> init_codec:
   596                              <1> 	; 05/06/2017
   597                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   598                              <1> 	;
   599 00011BA7 A1[286B0100]        <1> 	mov	eax, [audio_dev_id]	
   600 00011BAC B041                <1> 	mov	al, VIA_ACLINK_CTRL
   601 00011BAE E86AFFFFFF          <1> 	call	pciRegRead8
   602                              <1> 	; ?
   603 00011BB3 B040                <1> 	mov	al, VIA_ACLINK_STAT
   604 00011BB5 E863FFFFFF          <1> 	call	pciRegRead8
   605 00011BBA F6C201              <1> 	test	dl, VIA_ACLINK_C00_READY
   606 00011BBD 7508                <1>         jnz     short _codec_ready_1
   607 00011BBF E80E000000          <1> 	call	reset_codec
   608 00011BC4 7306                <1> 	jnc	short _codec_ready_2 ; eax = 1
   609 00011BC6 C3                  <1> 	retn
   610                              <1> _codec_ready_1:
   611 00011BC7 B801000000          <1> 	mov	eax, 1
   612                              <1> _codec_ready_2:
   613 00011BCC E892000000          <1> 	call	codec_io_w16
   614                              <1> detect_codec:
   615 00011BD1 C3                  <1> 	retn
   616                              <1> 
   617                              <1> reset_codec:
   618                              <1> 	; 16/04/2017
   619                              <1> 	; 23/03/2017 
   620                              <1> 	; ('codec.asm')
   621                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   622 00011BD2 A1[286B0100]        <1> 	mov	eax, [audio_dev_id]
   623 00011BD7 B041                <1>  	mov	al, VIA_ACLINK_CTRL
   624 00011BD9 B2E0                <1>        	mov	dl, VIA_ACLINK_CTRL_ENABLE + VIA_ACLINK_CTRL_RESET + VIA_ACLINK_CTRL_SYNC
   625 00011BDB E8A8FFFFFF          <1> 	call	pciRegWrite8
   626                              <1> 
   627 00011BE0 E855000000          <1> 	call	delay_100ms 	; wait 100 ms
   628                              <1> _rc_cold:
   629 00011BE5 E820000000          <1>         call    cold_reset
   630 00011BEA 7301                <1>         jnc     short _reset_codec_ok
   631                              <1> 	
   632                              <1> 	; 16/04/2017
   633                              <1>         ;xor     eax, eax         ; timeout error
   634                              <1>        	;stc
   635 00011BEC C3                  <1> 	retn
   636                              <1> 
   637                              <1> _reset_codec_ok:
   638                              <1> 	; 27/07/2020
   639                              <1> 	; also reset codec by using index control register 0 of AD1980 or ALC655
   640                              <1> 	; (to fix line out -2 channels audio playing- problem on AD1980 codec)  
   641                              <1> 
   642 00011BED 29C0                <1> 	sub	eax, eax
   643 00011BEF BA00000000          <1> 	mov	edx, CODEC_RESET_REG ; 00h ; Reset register
   644 00011BF4 E8D6000000          <1> 	call	codec_write
   645                              <1> 
   646 00011BF9 29C0                <1> 	sub	eax, eax 
   647 00011BFB BA76000000          <1> 	mov	edx, CODEC_MISC_CRTL_BITS_REG ; 76h ; Misc Ctrl Bits ; AD1980
   648 00011C00 E8CA000000          <1> 	call	codec_write
   649                              <1> 	;
   650                              <1> 
   651 00011C05 31C0                <1>         xor     eax, eax
   652                              <1>         ;mov	al, VIA_ACLINK_C00_READY ; 1
   653 00011C07 FEC0                <1>         inc	al
   654 00011C09 C3                  <1> 	retn
   655                              <1> 
   656                              <1> cold_reset:
   657                              <1> 	; 16/04/2017
   658                              <1> 	; 23/03/2017
   659                              <1> 	; ('codec.asm')
   660                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   661                              <1> 	;mov	eax, [audio_dev_id]
   662                              <1> 	;mov	al, VIA_ACLINK_CTRL
   663 00011C0A 30D2                <1> 	xor	dl, dl ; 0
   664 00011C0C E877FFFFFF          <1> 	call	pciRegWrite8
   665                              <1> 
   666 00011C11 E824000000          <1> 	call	delay_100ms 	; wait 100 ms
   667                              <1> 
   668                              <1> 	;; ACLink on, deassert ACLink reset, VSR, SGD data out
   669                              <1>         ;; note - FM data out has trouble with non VRA codecs !!
   670                              <1>         
   671                              <1> 	;mov	eax, [audio_dev_id]
   672                              <1> 	;mov	al, VIA_ACLINK_CTRL
   673 00011C16 B2CC                <1> 	mov	dl, VIA_ACLINK_CTRL_INIT
   674 00011C18 E86BFFFFFF          <1> 	call	pciRegWrite8
   675                              <1> 
   676 00011C1D B910000000          <1> 	mov	ecx, 16	; total 2s
   677                              <1> 
   678                              <1> _crst_wait:
   679                              <1> 	;mov	eax, [audio_dev_id]
   680 00011C22 B040                <1> 	mov	al, VIA_ACLINK_STAT
   681 00011C24 E8F4FEFFFF          <1> 	call	pciRegRead8	
   682                              <1> 
   683 00011C29 F6C201              <1>         test    dl, VIA_ACLINK_C00_READY
   684 00011C2C 750B                <1>         jnz     short _crst_ok
   685                              <1> 
   686 00011C2E 51                  <1> 	push	ecx
   687 00011C2F E806000000          <1> 	call	delay_100ms
   688 00011C34 59                  <1> 	pop	ecx
   689                              <1> 
   690 00011C35 49                  <1>         dec     ecx
   691 00011C36 75EA                <1>         jnz     short _crst_wait
   692                              <1> 
   693                              <1> _crst_fail:
   694 00011C38 F9                  <1>         stc
   695                              <1> _crst_ok:
   696 00011C39 C3                  <1> 	retn
   697                              <1> 
   698                              <1> delay_100ms:
   699                              <1> 	; 29/05/2017
   700                              <1> 	; 24/03/2017 ('codec.asm')
   701                              <1> 	; wait 100 ms
   702 00011C3A B990010000          <1> 	mov	ecx, 400  ; 400*0.25ms
   703                              <1> _delay_x_ms:
   704 00011C3F E803000000          <1> 	call	delay1_4ms
   705 00011C44 E2F9                <1>         loop	_delay_x_ms
   706 00011C46 C3                  <1> 	retn
   707                              <1> 
   708                              <1> ;       delay1_4ms - Delay for 1/4 millisecond.
   709                              <1> ;	    1mS = 1000us
   710                              <1> ;       Entry:
   711                              <1> ;         None
   712                              <1> ;       Exit:
   713                              <1> ;	  None
   714                              <1> ;
   715                              <1> ;       Modified:
   716                              <1> ;         None
   717                              <1> ;
   718                              <1> 
   719                              <1> 	; 29/05/2017
   720                              <1> 	; 23/04/2017
   721                              <1> 	; 05/03/2017 (TRDOS 386)
   722                              <1> 	; ('UTILS.ASM')
   723                              <1> delay1_4ms:
   724 00011C47 50                  <1>         push    eax 
   725 00011C48 51                  <1>         push    ecx
   726 00011C49 B110                <1>         mov	cl, 16		; close enough.
   727                              <1> 
   728 00011C4B E461                <1> 	in	al, PORTB ; 61h
   729                              <1> 		
   730 00011C4D 2410                <1> 	and	al, REFRESH_STATUS ; 10h
   731 00011C4F 88C5                <1> 	mov	ch, al		; Start toggle state
   732                              <1> _d4ms1:	
   733 00011C51 E461                <1> 	in	al, PORTB	; Read system control port
   734                              <1> 	
   735 00011C53 2410                <1> 	and	al, REFRESH_STATUS ; Refresh toggles 15.085 microseconds
   736 00011C55 38C5                <1> 	cmp	ch, al
   737 00011C57 74F8                <1> 	je	short _d4ms1	; Wait for state change
   738                              <1> 
   739 00011C59 88C5                <1> 	mov	ch, al		; Update with new state
   740 00011C5B FEC9                <1> 	dec	cl
   741 00011C5D 75F2                <1> 	jnz	short _d4ms1
   742                              <1> 
   743 00011C5F F8                  <1> 	clc	; 29/05/2017
   744                              <1> 
   745 00011C60 59                  <1>         pop     ecx
   746 00011C61 58                  <1>         pop     eax
   747 00011C62 C3                  <1>         retn
   748                              <1> 
   749                              <1> ; 10/04/2017 (TRDOS 386)
   750                              <1> ; 12/11/2016
   751                              <1> 
   752                              <1> codec_io_w16: ;w32
   753                              <1> 	; ('codec.asm')
   754 00011C63 668B15[266B0100]    <1>         mov	dx, [audio_io_base]
   755 00011C6A 6681C28000          <1>         add     dx, VIA_REG_AC97
   756 00011C6F EF                  <1> 	out	dx, eax
   757 00011C70 C3                  <1>         retn
   758                              <1> 
   759                              <1> codec_io_r16: ;r32
   760                              <1> 	; ('codec.asm')
   761 00011C71 668B15[266B0100]    <1>         mov     dx, [audio_io_base]
   762 00011C78 6681C28000          <1>         add     dx, VIA_REG_AC97
   763 00011C7D ED                  <1>         in	eax, dx
   764 00011C7E C3                  <1>         retn
   765                              <1> 
   766                              <1> ctrl_io_w8:
   767                              <1> 	; ('codec.asm')
   768 00011C7F 660315[266B0100]    <1>         add     dx, [audio_io_base]
   769 00011C86 EE                  <1>         out	dx, al
   770 00011C87 C3                  <1>         retn
   771                              <1> 
   772                              <1> ctrl_io_r8:
   773                              <1> 	; ('codec.asm')
   774 00011C88 660315[266B0100]    <1>         add     dx, [audio_io_base]
   775 00011C8F EC                  <1>         in	al, dx
   776 00011C90 C3                  <1>         retn
   777                              <1> 
   778                              <1> ctrl_io_w32:
   779                              <1> 	; ('codec.asm')
   780 00011C91 660315[266B0100]    <1>         add     dx, [audio_io_base]
   781 00011C98 EF                  <1>         out	dx, eax
   782 00011C99 C3                  <1>         retn
   783                              <1> 
   784                              <1> ctrl_io_r32:
   785                              <1> 	; ('codec.asm')
   786 00011C9A 660315[266B0100]    <1>         add	dx, [audio_io_base]
   787 00011CA1 ED                  <1> 	in	eax, dx
   788 00011CA2 C3                  <1>         retn
   789                              <1> 
   790                              <1> codec_read:
   791                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   792                              <1>         ; Use only primary codec.
   793                              <1>         ; eax = register
   794 00011CA3 C1E010              <1>         shl     eax, VIA_REG_AC97_CMD_SHIFT
   795 00011CA6 0D00008002          <1>         or      eax, VIA_REG_AC97_PRIMARY_VALID + VIA_REG_AC97_READ
   796                              <1> 
   797 00011CAB E8B3FFFFFF          <1> 	call    codec_io_w16
   798                              <1> 
   799                              <1>       	; codec_valid
   800 00011CB0 E831000000          <1> 	call	codec_check_ready
   801 00011CB5 7301                <1>         jnc	short _cr_ok
   802                              <1> 
   803 00011CB7 C3                  <1> 	retn
   804                              <1> 
   805                              <1> _cr_ok:
   806                              <1> 	; wait 25 ms
   807 00011CB8 B950000000          <1> 	mov	ecx, 80 ; (100*0.25 ms)
   808                              <1> _cr_wloop:
   809 00011CBD E885FFFFFF          <1> 	call	delay1_4ms
   810 00011CC2 E2F9                <1> 	loop	_cr_wloop
   811                              <1> 
   812 00011CC4 E8A8FFFFFF          <1>         call    codec_io_r16
   813 00011CC9 25FFFF0000          <1>         and     eax, 0FFFFh
   814 00011CCE C3                  <1>         retn
   815                              <1> 
   816                              <1> codec_write:
   817                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   818                              <1>         ; Use only primary codec.
   819                              <1>         
   820                              <1> 	; eax = data (volume)
   821                              <1> 	; edx = register (mixer register)
   822                              <1> 	
   823 00011CCF C1E210              <1> 	shl     edx, VIA_REG_AC97_CMD_SHIFT
   824                              <1> 
   825 00011CD2 C1E000              <1>         shl     eax, VIA_REG_AC97_DATA_SHIFT ; shl eax, 0
   826 00011CD5 09C2                <1>         or      edx, eax
   827                              <1> 
   828 00011CD7 B800000000          <1>         mov     eax, VIA_REG_AC97_CODEC_ID_PRIMARY
   829 00011CDC C1E01E              <1>         shl     eax, VIA_REG_AC97_CODEC_ID_SHIFT
   830 00011CDF 09D0                <1>         or      eax, edx
   831                              <1> 
   832 00011CE1 E87DFFFFFF          <1>         call    codec_io_w16
   833                              <1>         ;mov    [codec.regs+esi], ax
   834                              <1> 
   835                              <1>         ;call	codec_check_ready
   836                              <1>        	;retn
   837                              <1> 	;jmp	short _codec_check_ready	
   838                              <1> 
   839                              <1> codec_check_ready:
   840                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   841                              <1> 
   842                              <1> _codec_check_ready:
   843 00011CE6 B914000000          <1> 	mov	ecx, 20	; total 2s
   844                              <1> _ccr_wait:
   845 00011CEB 51                  <1> 	push	ecx
   846                              <1> 
   847 00011CEC E880FFFFFF          <1>         call    codec_io_r16
   848 00011CF1 A900000001          <1>         test    eax, VIA_REG_AC97_BUSY
   849 00011CF6 740B                <1>         jz      short _ccr_ok
   850                              <1> 
   851 00011CF8 E83DFFFFFF          <1> 	call	delay_100ms
   852                              <1> 
   853 00011CFD 59                  <1> 	pop	ecx
   854                              <1> 
   855 00011CFE 49                  <1> 	dec     ecx
   856 00011CFF 75EA                <1>         jnz     short _ccr_wait
   857                              <1> 
   858 00011D01 F9                  <1>         stc
   859 00011D02 C3                  <1>         retn
   860                              <1> 
   861                              <1> _ccr_ok:
   862 00011D03 59                  <1> 	pop	ecx
   863 00011D04 25FFFF0000          <1> 	and     eax, 0FFFFh
   864 00011D09 C3                  <1>         retn
   865                              <1> 
   866                              <1> codec_config:
   867                              <1> 	; 10/06/2017
   868                              <1> 	; 29/05/2017
   869                              <1> 	; 24/04/2017
   870                              <1> 	; 21/04/2017
   871                              <1> 	; 16/04/2017 (TRDOS 386 Kernel) 
   872                              <1> 	; 15/11/2016 ('codec.asm', 'player.com')
   873                              <1> 	; 14/11/2016
   874                              <1> 	; 12/11/2016 - Erdogan Tan
   875                              <1> 	;	     (Ref: KolibriOS, 'setup_codec', codec.inc)
   876                              <1> 
   877 00011D0A B802020000          <1> 	mov     eax, 0202h
   878 00011D0F 66A3[566B0100]      <1> 	mov	[audio_master_volume], ax
   879 00011D15 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31,31
   880 00011D19 BA02000000          <1> 	mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
   881 00011D1E E8ACFFFFFF          <1> 	call	codec_write
   882                              <1> 	;jc	short cconfig_error
   883                              <1> 
   884                              <1>  	;mov    eax, 0202h
   885 00011D23 66B80202            <1> 	mov     ax, 0202h
   886 00011D27 BA18000000          <1> 	mov	edx, CODEC_PCM_OUT_REG ; 18h ; Wave Output (Stereo)
   887 00011D2C E89EFFFFFF          <1> 	call	codec_write
   888                              <1> 	;jc	short cconfig_error
   889                              <1>       
   890                              <1>  	;mov    eax, 0202h
   891 00011D31 66B80202            <1> 	mov	ax, 0202h
   892 00011D35 BA04000000          <1> 	mov	edx, CODEC_AUX_VOL ; 04h ; CODEC_HP_VOL_REG ; HeadPhone
   893 00011D3A E890FFFFFF          <1> 	call	codec_write
   894                              <1> 	;jc	short cconfig_error
   895                              <1> 
   896                              <1>  	;mov    eax, 08h
   897                              <1>         ;mov    ax,  08h
   898 00011D3F 66B80880            <1> 	mov	ax, 8008h ; Mute
   899 00011D43 BA0C000000          <1> 	mov	edx, 0Ch  ; AC97_PHONE_VOL ; TAD Input (Mono)
   900 00011D48 E882FFFFFF          <1> 	call	codec_write
   901                              <1> 	;jc	short cconfig_error
   902                              <1> 
   903                              <1>  	;mov    eax, 0808h
   904 00011D4D 66B80808            <1>         mov     ax,  0808h
   905 00011D51 BA10000000          <1>         mov	edx, CODEC_LINE_IN_VOL_REG ; 10h ; Line Input (Stereo)	
   906 00011D56 E874FFFFFF          <1> 	call	codec_write
   907                              <1> 	;jc	short cconfig_error
   908                              <1> 
   909                              <1>  	;mov    eax, 0808h
   910 00011D5B 66B80808            <1> 	mov     ax,  0808h
   911 00011D5F BA12000000          <1>         mov	edx, CODEC_CD_VOL_REG ; 12h ; CR Input (Stereo)
   912 00011D64 E866FFFFFF          <1> 	call	codec_write
   913                              <1> 	;jc	short cconfig_error
   914                              <1> 
   915                              <1>  	;mov    eax, 0808h
   916 00011D69 66B80808            <1> 	mov     ax,  0808h
   917 00011D6D BA16000000          <1>         mov	edx, CODEC_AUX_VOL_REG ; 16h ; Aux Input (Stereo)
   918                              <1> 	;call	codec_write
   919                              <1> 	;;jc	short cconfig_error
   920 00011D72 E958FFFFFF          <1> 	jmp	codec_write ; 10/06/2017
   921                              <1> 
   922                              <1> ;	; Extended Audio Status (2Ah)
   923                              <1> ;	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah 
   924                              <1> ;	call	codec_read
   925                              <1> ;	and     eax, 0FFFFh - 2		; clear DRA (BIT1)
   926                              <1> ;	;or     eax, 1			; set VRA (BIT0)
   927                              <1> ;	or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
   928                              <1> ;	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
   929                              <1> ;	call	codec_write
   930                              <1> ;	;jc	short cconfig_error
   931                              <1> ;
   932                              <1> ;set_sample_rate:
   933                              <1> ;	;movzx	eax, word [audio_freq]
   934                              <1> ;	mov	ax, [audio_freq]
   935                              <1> ;	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
   936                              <1> ;	;call	codec_write
   937                              <1> ;	;retn
   938                              <1> ;	jmp	codec_write
   939                              <1> 	
   940                              <1> ;cconfig_error:
   941                              <1> ;	retn
   942                              <1> 
   943                              <1> vt8233_int_handler:
   944                              <1> 	; 27/07/2020
   945                              <1> 	; 22/07/2020
   946                              <1> 	; Interrupt Handler for VIA VT8237R Audio Controller
   947                              <1> 	; Note: called by 'dev_IRQ_service'
   948                              <1> 	; 14/10/2017 
   949                              <1> 	; 09/10/2017, 10/10/2017, 12/10/2017
   950                              <1> 	; 13/06/2017
   951                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
   952                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('player.asm') 
   953                              <1> 
   954                              <1> 	;push	eax ; * must be saved !
   955                              <1> 	;push	edx
   956                              <1> 	;push	ecx
   957                              <1> 	;push	ebx ; * must be saved !
   958                              <1> 	;push	esi
   959                              <1> 	;push	edi
   960                              <1> 
   961                              <1> 	;cmp	byte [audio_busy], 1
   962                              <1> 	;jnb	short _ih0 ; 09/10/2017
   963                              <1> 
   964                              <1> 	;mov	byte [audio_flag_eol], 0
   965                              <1> 
   966 00011D77 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   967 00011D7B E808FFFFFF          <1>         call    ctrl_io_r8
   968                              <1> 
   969 00011D80 A880                <1> 	test    al, VIA_REG_STAT_ACTIVE
   970 00011D82 7417                <1>         jz      short _ih0 ; 09/10/2017
   971                              <1> 
   972 00011D84 2407                <1>         and     al, VIA_REG_STAT_EOL + VIA_REG_STAT_FLAG + VIA_REG_STAT_STOPPED
   973 00011D86 A2[556B0100]        <1> 	mov	[audio_flag_eol], al
   974 00011D8B 740E                <1>         jz	short _ih0 ; 09/10/2017
   975                              <1> 
   976                              <1> 	; 09/10/2017
   977                              <1> 	;mov	byte [audio_busy], 1
   978                              <1> 
   979 00011D8D 803D[546B0100]01    <1> 	cmp	byte [audio_play_cmd], 1
   980 00011D94 7315                <1> 	jnb	short _ih1 ; 10/10/2017
   981                              <1> 
   982 00011D96 E84A000000          <1> 	call	channel_reset
   983                              <1> _ih0:
   984                              <1> 	; 09/10/2017
   985 00011D9B A0[556B0100]        <1>         mov     al, [audio_flag_eol]   ;; ack ;;
   986 00011DA0 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   987 00011DA4 E8D6FEFFFF          <1>         call    ctrl_io_w8
   988 00011DA9 EB39                <1> 	jmp	short _ih4
   989                              <1> _ih1:
   990                              <1> vt8233_tuneLoop:
   991 00011DAB A0[556B0100]        <1>         mov     al, [audio_flag_eol]   ;; ack ;;
   992 00011DB0 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   993 00011DB4 E8C6FEFFFF          <1>         call    ctrl_io_w8
   994                              <1> 
   995                              <1> 	; 22/07/2020
   996                              <1> 	;; 12/10/2017
   997                              <1> 	;mov	byte [audio_flag], 0 ; Reset	
   998                              <1> 
   999                              <1> 	; 10/10/2017
  1000                              <1> 	; 09/10/2017
  1001                              <1> 	;test	byte [audio_flag_eol], VIA_REG_STAT_FLAG
  1002                              <1> 	;jz	short _ih2 ; EOL
  1003                              <1> 
  1004                              <1> 	; 22/07/2020
  1005                              <1> 	; 14/10/2017
  1006                              <1> 	;test	byte [audio_flag_eol], VIA_REG_STAT_EOL
  1007                              <1> 	;jnz	short _ih2 ; EOL
  1008                              <1> 	;		   ; (Half Buffer 2 has been completed 
  1009                              <1> 	;		   ; and Half Buffer 1 will be played.)
  1010                              <1> 	
  1011                              <1> 	; FLAG  
  1012                              <1> 	; (Half Buffer 1 has been completed 
  1013                              <1> 	;  and Half Buffer 2 will be played.)
  1014                              <1> 
  1015                              <1> 	; 14/10/2017
  1016                              <1> 	;; (Continue to play.)
  1017                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1018                              <1>        	;or	al, VIA_REG_CTRL_START
  1019                              <1>        	;mov	dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1020                              <1>         ;call	ctrl_io_w8
  1021                              <1> 	; 12/10/2017
  1022                              <1> 	;mov	byte [audio_flag], 1 
  1023                              <1> 
  1024                              <1> 	; 22/07/2020
  1025                              <1> 	;inc	byte [audio_flag] ; = 1
  1026                              <1> _ih2: 
  1027                              <1> 	; 10/10/2017
  1028 00011DB9 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff]
  1029 00011DBF 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  1030 00011DC5 D1E9                <1> 	shr	ecx, 1 ; dma buff size / 2 = half buffer size
  1031                              <1> 	
  1032                              <1> 	; 22/07/2020
  1033                              <1> 	; 12/10/2017
  1034                              <1> 	;cmp	byte [audio_flag], 0
  1035                              <1> 	;ja	short _ih3 ; Playing Half Buffer 2 (Current: FLAG)
  1036                              <1> 	
  1037                              <1> 	; 27/07/2020
  1038                              <1> 	; 22/07/2020
  1039 00011DC7 F605[486B0100]01    <1> 	test	byte [audio_flag], 1  ; Current flag value
  1040 00011DCE 7402                <1> 	jz	short _ih3 ; Half Buffer 1 must be filled
  1041                              <1> 
  1042                              <1> 	; Half Buffer 2 must be filled
  1043 00011DD0 01CF                <1> 	add	edi, ecx
  1044                              <1> _ih3:
  1045                              <1> 	; Update half buffer 2 while playing half buffer 1
  1046                              <1> 	; Update half buffer 1 while playing half buffer 2
  1047                              <1> 
  1048 00011DD2 8B35[386B0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  1049 00011DD8 C1E902              <1> 	shr	ecx, 2 ; half buff size / 4
  1050 00011DDB F3A5                <1> 	rep	movsd
  1051                              <1> 
  1052                              <1> 	; switch flag value ;
  1053 00011DDD 8035[486B0100]01    <1> 	xor	byte [audio_flag], 1
  1054                              <1> 	; 12/10/2017
  1055                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2
  1056                              <1> 			   ; Next buffer (to update) is dma half buff 1
  1057                              <1> 	; 	       = 1 : Playing dma half buffer 1
  1058                              <1> 			   ; Next buffer (to update) is dma half buff 2
  1059                              <1> _ih4:	
  1060                              <1> 	; 28/05/2017
  1061                              <1> 	;mov	byte [audio_busy], 0 ; 09/10/2017
  1062                              <1> 	;
  1063                              <1> 	;pop	edi
  1064                              <1> 	;pop	esi
  1065                              <1> 	;pop	ebx ; * must be restored !
  1066                              <1> 	;pop	ecx
  1067                              <1> 	;pop	edx
  1068                              <1> 	;pop	eax ; * must be restored !
  1069                              <1> 
  1070 00011DE4 C3                  <1> 	retn
  1071                              <1> 
  1072                              <1> channel_reset:
  1073                              <1> 	; 24/06/2017
  1074                              <1> 	; 29/05/2017
  1075                              <1> 	; 23/03/2017
  1076                              <1> 	; 14/11/2016 - Erdogan Tan
  1077                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1078 00011DE5 BA01000000          <1>         mov	edx, VIA_REG_OFFSET_CONTROL
  1079                              <1>         ;mov	eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE + VIA_REG_CTRL_RESET
  1080 00011DEA B848000000          <1>         mov	eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE ; 24/06/2017       
  1081 00011DEF E88BFEFFFF          <1> 	call    ctrl_io_w8
  1082                              <1> 
  1083                              <1>         ;mov	edx, VIA_REG_OFFSET_CONTROL
  1084                              <1>         ;call   ctrl_io_r8
  1085                              <1> 
  1086                              <1> 	; wait for 50 ms
  1087 00011DF4 B9A0000000          <1> 	mov	ecx, 160 ; (200*0.25 ms) ; 29/05/2017	
  1088                              <1> _ch_rst_wait:
  1089 00011DF9 E849FEFFFF          <1> 	call	delay1_4ms
  1090 00011DFE 49                  <1> 	dec	ecx
  1091 00011DFF 75F8                <1> 	jnz	short _ch_rst_wait     
  1092                              <1> 
  1093                              <1>         ; disable interrupts
  1094 00011E01 BA01000000          <1>         mov	edx, VIA_REG_OFFSET_CONTROL
  1095 00011E06 31C0                <1>         xor     eax, eax
  1096 00011E08 E872FEFFFF          <1>         call    ctrl_io_w8
  1097                              <1> 
  1098                              <1>         ; clear interrupts
  1099 00011E0D BA00000000          <1>         mov	edx, VIA_REG_OFFSET_STATUS
  1100 00011E12 B803000000          <1> 	mov	eax, 3
  1101 00011E17 E863FEFFFF          <1>         call	ctrl_io_w8
  1102                              <1> 
  1103                              <1> 	;mov	edx, VIA_REG_OFFSET_CURR_PTR
  1104                              <1> 	;xor	eax, eax
  1105                              <1> 	;call	ctrl_io_w32
  1106                              <1> 
  1107 00011E1C C3                  <1>         retn	
  1108                              <1> 
  1109                              <1> vt8233_stop: ; 22/04/2017
  1110 00011E1D C605[546B0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  1111                              <1> _tlp2:
  1112                              <1> 	; 24/06/2017
  1113                              <1>         ; finished with song, stop everything
  1114                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1115                              <1>         ;or	al, VIA_REG_CTRL_TERMINATE
  1116                              <1> 	;mov	dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1117                              <1>         ;call	ctrl_io_w8
  1118                              <1> 
  1119                              <1>         ;call	channel_reset
  1120                              <1> 	;retn
  1121                              <1> 
  1122 00011E24 EBBF                <1> 	jmp	short channel_reset
  1123                              <1> 
  1124                              <1> set_vt8233_bdl: ; Set VT8237R Buffer Descriptor List
  1125                              <1> 	; 22/07/2020 - TRDOS 386 v2.0.2
  1126                              <1> 	; 28/05/2017
  1127                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1128                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016) 
  1129                              <1> 	
  1130                              <1> 	; eax = dma buffer address = [audio_DMA_buff]
  1131                              <1> 	; ecx = dma buffer buffer size = [audio_dmabuff_size]
  1132                              <1> 
  1133 00011E26 D1E9                <1> 	shr	ecx, 1 ; dma half buffer size
  1134 00011E28 89CE                <1> 	mov	esi, ecx
  1135                              <1> 
  1136 00011E2A BF[5C6B0100]        <1>         mov     edi, audio_bdl_buff	; get BDL address
  1137 00011E2F B910000000          <1>         mov     ecx, 32 / 2		; make 32 entries in BDL
  1138                              <1> 
  1139 00011E34 EB05                <1> 	jmp	short s_vt8233_bdl1 
  1140                              <1> 
  1141                              <1> s_vt8233_bdl0:
  1142                              <1> 	; set buffer descriptor 0 to start of data file in memory
  1143                              <1> 
  1144 00011E36 A1[406B0100]        <1>  	mov	eax, [audio_dma_buff]	; Physical address of DMA buffer
  1145                              <1>  
  1146                              <1> s_vt8233_bdl1:
  1147 00011E3B AB                  <1> 	stosd				; store dmabuffer1 address
  1148                              <1> 
  1149 00011E3C 89C2                <1> 	mov	edx, eax
  1150                              <1> 
  1151                              <1> ; VIA VT8235.PDF: (Page 110) (Erdogan Tan, 29/11/2016)
  1152                              <1> 	;
  1153                              <1> 	; 	Audio SGD Table Format
  1154                              <1> 	;	-------------------------------
  1155                              <1> 	;	63   62    61-56    55-32  31-0
  1156                              <1> 	;	--   --   --------  -----  ----
  1157                              <1> 	;	EOL FLAG -reserved- Base   Base
  1158                              <1> 	;		    	    Count  Address
  1159                              <1> 	;		            [23:0] [31:0]
  1160                              <1> 	;	EOL: End Of Link. 
  1161                              <1> 	;	     1 indicates this block is the last of the link.
  1162                              <1> 	;	     If the channel Interrupt on EOL bit is set, then
  1163                              <1> 	;	     an interrupt is generated at the end of the transfer.
  1164                              <1> 	;
  1165                              <1> 	;	FLAG: Block Flag. If set, transfer pauses at the end of this
  1166                              <1> 	;	      block. If the channel Interrupt on FLAG bit is set,
  1167                              <1> 	;	      then an interrupt is generated at the end of this block.
  1168                              <1> 
  1169 00011E3E 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  1170 00011E40 01C2                <1> 	add	edx, eax
  1171 00011E42 0D00000040          <1> 	or	eax, FLAG
  1172                              <1> 	;or	eax, EOL
  1173 00011E47 AB                  <1> 	stosd
  1174                              <1> 
  1175                              <1> ; 2nd buffer:
  1176                              <1> 
  1177 00011E48 89D0                <1>         mov	eax, edx ; Physical address of the 2nd half of DMA buffer	
  1178 00011E4A AB                  <1> 	stosd		 ; store dmabuffer2 address
  1179                              <1> 
  1180                              <1> ; set length to [audio_dmabuff_size]/2
  1181                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  1182                              <1> ; 
  1183 00011E4B 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  1184                              <1> 	; 22/07/2020
  1185                              <1> 	;or	eax, EOL
  1186 00011E4D 0D00000040          <1> 	or	eax, FLAG
  1187 00011E52 AB                  <1> 	stosd
  1188                              <1> 
  1189 00011E53 E2E1                <1> 	loop    s_vt8233_bdl0
  1190                              <1> 
  1191                              <1> 	; 22/07/2020
  1192 00011E55 814FFC00000080      <1> 	or	dword [edi-4], EOL
  1193                              <1> 	
  1194 00011E5C C3                  <1> 	retn
  1195                              <1> 
  1196                              <1> vt8233_start_play: 
  1197                              <1> 	; 22/07/2020 
  1198                              <1> 	; start to play audio data via VT8233 audio controller
  1199                              <1> 	; 13/06/2017
  1200                              <1> 	; 10/06/2017
  1201                              <1> 	; 24/04/2017 
  1202                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1203                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016) 
  1204                              <1> 	; write buffer descriptor list address
  1205                              <1> 
  1206                              <1> 	; Extended Audio Status (2Ah)
  1207 00011E5D B82A000000          <1> 	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah 
  1208 00011E62 E83CFEFFFF          <1> 	call	codec_read
  1209 00011E67 25FDFF0000          <1> 	and     eax, 0FFFFh - 2		; clear DRA (BIT1)
  1210                              <1> 	;or     eax, 1			; set VRA (BIT0)
  1211 00011E6C 83C805              <1> 	or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
  1212 00011E6F BA2A000000          <1> 	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
  1213 00011E74 E856FEFFFF          <1> 	call	codec_write
  1214                              <1> 	;jc	short cconfig_error
  1215                              <1> 
  1216                              <1> set_sample_rate:
  1217                              <1> 	;movzx	eax, word [audio_freq]
  1218 00011E79 66A1[526B0100]      <1> 	mov	ax, [audio_freq]
  1219 00011E7F BA2C000000          <1> 	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
  1220 00011E84 E846FEFFFF          <1> 	call	codec_write
  1221                              <1> 
  1222 00011E89 B8[5C6B0100]        <1>         mov	eax, audio_bdl_buff
  1223                              <1>   
  1224                              <1> 	; 12/11/2016 - Erdogan Tan 
  1225                              <1> 	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1226 00011E8E BA04000000          <1> 	mov	edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_TABLE_PTR
  1227 00011E93 E8F9FDFFFF          <1>         call	ctrl_io_w32
  1228                              <1> 
  1229                              <1> 	;call	codec_check_ready
  1230                              <1> 
  1231 00011E98 66BA0200            <1>   	mov	dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_L
  1232                              <1>         ;mov	eax, 2	; 31
  1233 00011E9C B01F                <1> 	mov	al, 31
  1234 00011E9E 2A05[566B0100]      <1>         sub	al, [audio_master_volume_l]
  1235 00011EA4 E8D6FDFFFF          <1> 	call	ctrl_io_w8
  1236                              <1> 
  1237                              <1> 	;call	codec_check_ready
  1238                              <1> 
  1239 00011EA9 66BA0300            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_R
  1240                              <1>         ;mov	ax, 2	; 31
  1241 00011EAD B01F                <1> 	mov	al, 31
  1242 00011EAF 2A05[576B0100]      <1>         sub	al, [audio_master_volume_r]
  1243 00011EB5 E8C5FDFFFF          <1> 	call    ctrl_io_w8
  1244                              <1> 
  1245                              <1> 	;call	codec_check_ready
  1246                              <1> ;
  1247                              <1> ;
  1248                              <1> ; All set.  Let's play some music.
  1249                              <1> ;
  1250                              <1> ;
  1251                              <1>        	;mov    dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1252                              <1>         ;mov    ax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
  1253                              <1>         ;call   ctrl_io_w32
  1254                              <1> 
  1255                              <1> 	;call	codec_check_ready
  1256                              <1> 
  1257                              <1> 	; 08/12/2016
  1258                              <1> 	; 07/10/2016
  1259                              <1>         ;;mov    al, 1
  1260                              <1>         ;mov	al, 31
  1261                              <1> 	; 22/07/2020
  1262 00011EBA B0FF                <1> 	mov	al, 0FFh
  1263 00011EBC E813000000          <1> 	call    set_VT8233_LastValidIndex
  1264                              <1> 
  1265 00011EC1 C605[546B0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  1266                              <1> 
  1267                              <1> 	; 22/07/2020
  1268                              <1> 	;mov	byte [audio_flag], 0  ; clear half buffer flag
  1269                              <1> 
  1270                              <1> vt8233_play: ; continue to play
  1271                              <1> 	; 22/04/2017
  1272                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1273                              <1>        	;or	al, VIA_REG_CTRL_START
  1274                              <1>         ;;mov	al, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START
  1275                              <1> 	; 22/07/2020	
  1276 00011EC8 B0A1                <1> 	mov	al, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START + VIA_REG_CTRL_INT_FLAG
  1277                              <1> 
  1278 00011ECA 66BA0100            <1> 	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1279 00011ECE E8ACFDFFFF          <1>         call    ctrl_io_w8
  1280                              <1> 	;call	codec_check_ready
  1281                              <1> 	;retn
  1282                              <1> 	;jmp	codec_check_ready
  1283 00011ED3 C3                  <1> 	retn
  1284                              <1> 
  1285                              <1> ;input AL = index # to stop on
  1286                              <1> set_VT8233_LastValidIndex:
  1287                              <1> 	; 23/07/2020
  1288                              <1> 	; 10/06/2017
  1289                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1290                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016) 
  1291                              <1> 	; 19/11/2016
  1292                              <1> 	; 14/11/2016 - Erdogan Tan (Ref: VIA VT8235.PDF, Page 110)
  1293                              <1> 	; 12/11/2016 - Erdogan Tan
  1294                              <1> 	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1295                              <1> 	;push	edx
  1296                              <1> 	;push	ax
  1297 00011ED4 50                  <1> 	push	eax ; 23/07/2020
  1298                              <1> 	;push	ecx
  1299 00011ED5 0FB705[526B0100]    <1> 	movzx	eax, word [audio_freq] ; Hertz
  1300 00011EDC BA00001000          <1> 	mov	edx, 100000h ; 2^20 = 1048576
  1301 00011EE1 F7E2                <1> 	mul	edx
  1302 00011EE3 B980BB0000          <1> 	mov	ecx, 48000	
  1303 00011EE8 F7F1                <1> 	div	ecx
  1304                              <1> 	;and	eax, 0FFFFFh
  1305                              <1> 	;pop	ecx
  1306                              <1> 	;pop	dx 
  1307 00011EEA 5A                  <1> 	pop	edx ; 23/07/2020
  1308 00011EEB C1E218              <1> 	shl	edx, 24  ; STOP Index Setting: Bit 24 to 31
  1309 00011EEE 09D0                <1> 	or	eax, edx
  1310                              <1> 	; 19/11/2016
  1311 00011EF0 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16
  1312 00011EF7 7505                <1> 	jne	short sLVI_1
  1313 00011EF9 0D00002000          <1> 	or	eax, VIA8233_REG_TYPE_16BIT
  1314                              <1> sLVI_1:
  1315 00011EFE 803D[516B0100]02    <1> 	cmp	byte [audio_stmo], 2
  1316 00011F05 7505                <1> 	jne	short sLVI_2
  1317 00011F07 0D00001000          <1> 	or	eax, VIA8233_REG_TYPE_STEREO
  1318                              <1> sLVI_2:
  1319 00011F0C BA08000000          <1> 	mov     edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1320 00011F11 E87BFDFFFF          <1>         call    ctrl_io_w32
  1321                              <1> 	;call	codec_check_ready
  1322                              <1> 	;pop	edx
  1323 00011F16 C3                  <1> 	retn
  1324                              <1> 
  1325                              <1> vt8233_pause: ; pause
  1326                              <1> 	; 10/06/2017
  1327                              <1> 	; 22/04/2017
  1328                              <1> 	;mov     al, VIA_REG_CTRL_INT
  1329                              <1>         ;or      al, VIA_REG_CTRL_PAUSE
  1330                              <1> 	; 23/07/2020
  1331 00011F17 B029                <1> 	mov	al, VIA_REG_CTRL_PAUSE+VIA_REG_CTRL_INT_FLAG+VIA_REG_CTRL_AUTOSTART
  1332                              <1> 	
  1333 00011F19 66BA0100            <1> 	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1334 00011F1D E85DFDFFFF          <1>         call    ctrl_io_w8
  1335                              <1> 	;call	codec_check_ready
  1336                              <1> 	;retn
  1337                              <1> 	;jmp	codec_check_ready
  1338 00011F22 C3                  <1> 	retn
  1339                              <1> 
  1340                              <1> vt8233_reset: 
  1341                              <1> 	; 22/04/2017
  1342                              <1> 	; reset VT8237R (vt8233) Audio Controller
  1343                              <1> 	;cmp	byte [audio_play_cmd], 1
  1344                              <1> 	;jna	short vt8233_rst_0
  1345 00011F23 C605[546B0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  1346                              <1> vt8233_rst_0:
  1347 00011F2A E8A3FCFFFF          <1> 	call	reset_codec
  1348 00011F2F 720A                <1> 	jc	short vt8233_rst_1 ; codec error !
  1349                              <1> 	; eax = 1
  1350 00011F31 E82DFDFFFF          <1> 	call	codec_io_w16 ; w32
  1351 00011F36 E8AAFEFFFF          <1> 	call	channel_reset
  1352                              <1> vt8233_rst_1:
  1353 00011F3B C3                  <1> 	retn
  1354                              <1> 
  1355                              <1> vt8233_volume:
  1356                              <1> 	; set VT8237R (vt8233) sound volume level
  1357                              <1> 	; 24/04/2017
  1358                              <1> 	; 22/04/2017
  1359                              <1> 	; bl = component (0 = master/playback/lineout volume)
  1360                              <1> 	; cl = left channel volume level (0 to 31)
  1361                              <1> 	; ch = right channel volume level (0 to 31)
  1362                              <1> 
  1363 00011F3C 08DB                <1> 	or	bl, bl
  1364 00011F3E 7520                <1> 	jnz	short vt8233_vol_1 ; temporary !
  1365 00011F40 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31,31
  1366 00011F44 38C1                <1> 	cmp	cl, al
  1367 00011F46 7718                <1> 	ja	short vt8233_vol_1 ; temporary !
  1368 00011F48 38E5                <1> 	cmp	ch, ah
  1369 00011F4A 7714                <1> 	ja	short vt8233_vol_1 ; temporary !
  1370 00011F4C 66890D[566B0100]    <1> 	mov	[audio_master_volume], cx
  1371 00011F53 6629C8              <1> 	sub	ax, cx
  1372 00011F56 BA02000000          <1> 	mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
  1373 00011F5B E86FFDFFFF          <1> 	call	codec_write
  1374                              <1> vt8233_vol_1:
  1375 00011F60 C3                  <1> 	retn
  1376                              <1> 
  1377                              <1> ; CODE for SOUND BLASTER 16
  1378                              <1> 
  1379                              <1> DetectSB:
  1380                              <1> 	; 24/04/2017
  1381                              <1> 	;pushad
  1382                              <1> ScanPort:
  1383 00011F61 66BB1002            <1> 	mov     bx, 210h	; start scanning ports
  1384                              <1> 				; 210h, 220h, .. 260h
  1385                              <1> ResetDSP:       
  1386 00011F65 6689DA              <1> 	mov     dx, bx		; try to reset the DSP.
  1387 00011F68 6683C206            <1> 	add     dx, 06h
  1388 00011F6C B001                <1> 	mov	al, 1
  1389 00011F6E EE                  <1> 	out	dx, al
  1390                              <1> 
  1391 00011F6F EC                  <1> 	in	al, dx
  1392 00011F70 EC                  <1> 	in	al, dx
  1393 00011F71 EC                  <1> 	in	al, dx
  1394 00011F72 EC                  <1> 	in	al, dx
  1395                              <1> 
  1396 00011F73 30C0                <1> 	xor     al, al
  1397 00011F75 EE                  <1> 	out	dx, al
  1398                              <1> 
  1399 00011F76 6683C208            <1> 	add     dx, 08h
  1400 00011F7A 66B96400            <1> 	mov	cx, 100
  1401                              <1> WaitID:
  1402 00011F7E EC                  <1> 	in	al, dx
  1403 00011F7F 08C0                <1> 	or      al, al
  1404 00011F81 7804                <1> 	js      short GetID
  1405 00011F83 E2F9                <1> 	loop    WaitID
  1406 00011F85 EB0F                <1> 	jmp     short NextPort
  1407                              <1> GetID:          
  1408 00011F87 6683EA04            <1> 	sub     dx, 04h
  1409 00011F8B EC                  <1> 	in	al, dx
  1410 00011F8C 3CAA                <1> 	cmp     al, 0AAh
  1411 00011F8E 7413                <1> 	je      short Found
  1412 00011F90 6683C204            <1> 	add     dx, 04h
  1413 00011F94 E2E8                <1> 	loop    WaitID
  1414                              <1> NextPort:
  1415 00011F96 6683C310            <1> 	add     bx, 10h		; if not response,
  1416 00011F9A 6681FB6002          <1> 	cmp     bx, 260h	; try the next port.
  1417 00011F9F 76C4                <1> 	jbe     short ResetDSP
  1418 00011FA1 F9                  <1> 	stc
  1419 00011FA2 C3                  <1> 	retn
  1420                              <1> Found:
  1421 00011FA3 66891D[266B0100]    <1> 	mov     [audio_io_base], bx	; SB Port Address Found!
  1422                              <1> ScanIRQ:
  1423                              <1> SetIrqs:
  1424 00011FAA 28C0                <1> 	sub 	al, al ; 0
  1425 00011FAC A2[1E6B0100]        <1> 	mov 	[IRQnum], al ; reset
  1426 00011FB1 A2[236B0100]        <1> 	mov	[audio_intr], al ; reset
  1427                              <1> 
  1428                              <1> 	; ah > 0 -> set IRQ vector
  1429                              <1> 	; al = IRQ number
  1430                              <1> 	;mov	ax, 103h ; IRQ 3
  1431                              <1> 	;call	set_hardware_int_vector
  1432                              <1> 	;mov	ax, 104h ; IRQ 4
  1433                              <1> 	;call	set_hardware_int_vector
  1434 00011FB6 66B80501            <1> 	mov	ax, 105h ; IRQ 5
  1435 00011FBA E8E0DDFFFF          <1> 	call	set_hardware_int_vector
  1436 00011FBF 66B80701            <1> 	mov	ax, 107h ; IRQ 7
  1437 00011FC3 E8D7DDFFFF          <1> 	call	set_hardware_int_vector
  1438                              <1> 
  1439 00011FC8 668B15[266B0100]    <1> 	mov     dx, [audio_io_base] ; tells to the SB to
  1440 00011FCF 6683C20C            <1> 	add     dx, 0Ch		    ; generate a IRQ!
  1441                              <1> WaitSb:
  1442 00011FD3 EC                  <1> 	in	al, dx
  1443 00011FD4 08C0                <1> 	or      al, al
  1444 00011FD6 78FB                <1> 	js      short WaitSb
  1445 00011FD8 B0F2                <1> 	mov     al, 0F2h
  1446 00011FDA EE                  <1> 	out	dx, al
  1447                              <1> 
  1448 00011FDB 31C9                <1> 	xor     ecx, ecx	; wait until IRQ level
  1449                              <1> WaitIRQ: 
  1450 00011FDD A0[1E6B0100]        <1> 	mov	al, [IRQnum]
  1451 00011FE2 3C00                <1> 	cmp     al, 0 ; is changed or timeout.
  1452 00011FE4 7706                <1> 	ja	short IrqOk
  1453 00011FE6 6649                <1> 	dec	cx
  1454 00011FE8 75F3                <1> 	jnz	short WaitIRQ
  1455 00011FEA EB15                <1> 	jmp	short RestoreIrqs
  1456                              <1> IrqOk:
  1457 00011FEC A2[236B0100]        <1> 	mov	[audio_intr], al ; set   
  1458 00011FF1 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1459 00011FF8 6683C20E            <1> 	add     dx, 0Eh
  1460 00011FFC EC                  <1> 	in	al, dx	; SB acknowledge.
  1461 00011FFD B020                <1> 	mov	al, 20h
  1462 00011FFF E620                <1> 	out	20h, al	; Hardware acknowledge.
  1463                              <1> 
  1464                              <1> RestoreIrqs:
  1465                              <1> 	; ah = 0 -> reset IRQ vector
  1466                              <1> 	; al = IRQ number
  1467                              <1> 	;mov	ax, 3 ; IRQ 3
  1468                              <1> 	;call	set_hardware_int_vector
  1469                              <1> 	;mov	ax, 4 ; IRQ 4
  1470                              <1> 	;call	set_hardware_int_vector
  1471 00012001 66B80500            <1> 	mov	ax, 5 ; IRQ 5
  1472 00012005 E895DDFFFF          <1> 	call	set_hardware_int_vector
  1473 0001200A 66B80700            <1> 	mov	ax, 7 ; IRQ 7
  1474 0001200E E88CDDFFFF          <1> 	call	set_hardware_int_vector
  1475                              <1> 
  1476 00012013 31D2                <1> 	xor	edx, edx
  1477 00012015 8915[286B0100]      <1> 	mov	[audio_dev_id], edx ; 0
  1478 0001201B 8915[2C6B0100]      <1> 	mov	[audio_vendor], edx ; 0
  1479 00012021 8915[306B0100]      <1> 	mov	[audio_stats_cmd], edx ; 0
  1480                              <1> 
  1481                              <1> 	;popad
  1482                              <1> 
  1483 00012027 803D[236B0100]01    <1> 	cmp     byte [audio_intr], 1 ; IRQ level was changed?
  1484                              <1> 	
  1485 0001202E C3                  <1> 	retn
  1486                              <1> 
  1487                              <1> %macro	SbOut	1
  1488                              <1> %%Wait:
  1489                              <1> 	in	al, dx
  1490                              <1> 	or	al, al
  1491                              <1> 	js	short %%Wait
  1492                              <1> 	mov	al, %1
  1493                              <1> 	out	dx, al
  1494                              <1> %endmacro
  1495                              <1> 
  1496                              <1> SbInit_play:
  1497                              <1> 	; 22/10/2017
  1498                              <1> 	; 20/10/2017
  1499                              <1> 	; 06/10/2017
  1500                              <1> 	; 13/07/2017, 09/08/2017
  1501                              <1> 	; 24/04/2017, 15/05/2017, 24/06/2017
  1502                              <1> 	;pushad
  1503                              <1> SetBuffer:
  1504                              <1> 	;mov	byte [DmaFlag], 0
  1505                              <1> 
  1506 0001202F 8B1D[406B0100]      <1> 	mov	ebx, [audio_dma_buff] ; physical addr of DMA buff
  1507 00012035 89DF                <1> 	mov	edi, ebx
  1508 00012037 8B0D[446B0100]      <1> 	mov     ecx, [audio_dmabuff_size]
  1509                              <1> 
  1510 0001203D 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16
  1511 00012044 7531                <1> 	jne	short sbInit_0 ; set 8 bit DMA buffer
  1512                              <1> 	
  1513                              <1> 	; 09/08/2017
  1514                              <1> 	; convert byte count to word count
  1515 00012046 D1E9                <1> 	shr	ecx, 1
  1516 00012048 49                  <1> 	dec	ecx ; word count - 1
  1517                              <1> 	; convert byte offset to word offset
  1518 00012049 D1EB                <1> 	shr	ebx, 1
  1519                              <1> 
  1520                              <1> 	; 16 bit DMA buffer setting (DMA channel 5)
  1521 0001204B B005                <1> 	mov     al, 05h  ; set mask bit for channel 5  (4+1)
  1522 0001204D E6D4                <1> 	out	0D4h, al
  1523                              <1> 	
  1524 0001204F 30C0                <1> 	xor     al, al   ; stops all DMA processes on selected channel
  1525 00012051 E6D8                <1> 	out	0D8h, al ; clear selected channel register
  1526                              <1> 
  1527 00012053 88D8                <1> 	mov     al, bl	 ; byte 0 of DMA buffer offset in words (physical) 
  1528 00012055 E6C4                <1> 	out	0C4h, al ; DMA channel 5 port number
  1529                              <1> 
  1530 00012057 88F8                <1> 	mov     al, bh   ; byte 1 of DMA buffer offset in words (physical)   
  1531 00012059 E6C4                <1> 	out	0C4h, al
  1532                              <1> 	
  1533                              <1> 	; 09/08/2017
  1534 0001205B C1EB0F              <1> 	shr	ebx, 15	 ; complete 16 bit shift
  1535 0001205E 80E3FE              <1> 	and	bl, 0FEh ; clear bit 0 (not necessary, it will be ignored)
  1536                              <1> 
  1537 00012061 88D8                <1> 	mov     al, bl   ; byte 2 of DMA buffer address (physical) 
  1538 00012063 E68B                <1> 	out	8Bh, al  ; page register port addr for channel 5 ; 13/07/2017
  1539                              <1> 
  1540 00012065 88C8                <1> 	mov     al, cl   ; low byte of DMA count - 1
  1541 00012067 E6C6                <1> 	out	0C6h, al ; count register port addr for channel 1
  1542                              <1> 
  1543 00012069 88E8                <1> 	mov     al, ch   ; high byte of DMA count - 1
  1544 0001206B E6C6                <1> 	out	0C6h, al
  1545                              <1> 
  1546                              <1> 	; channel 5, read, autoinitialized, single mode
  1547                              <1> 	;mov	al, 49h
  1548 0001206D B059                <1> 	mov	al, 59h  ; 06/10/2017 
  1549 0001206F E6D6                <1> 	out	0D6h, al ; DMA mode register port address
  1550                              <1> 
  1551 00012071 B001                <1> 	mov     al, 01h  ; clear mask bit for channel 1
  1552 00012073 E6D4                <1> 	out	0D4h, al ; DMA mask register port address
  1553                              <1> 
  1554 00012075 EB28                <1> 	jmp	short ClearBuffer
  1555                              <1> 
  1556                              <1> sbInit_0:    
  1557 00012077 49                  <1> 	dec     ecx ; 09/08/2017
  1558                              <1> 
  1559                              <1> 	; 8 bit DMA buffer setting (DMA channel 1)
  1560 00012078 B005                <1> 	mov     al, 05h ; set mask bit for channel 1  (4+1)
  1561 0001207A E60A                <1> 	out	0Ah, al ; DMA mask register
  1562                              <1> 
  1563 0001207C 30C0                <1> 	xor     al, al  ; stops all DMA processes on selected channel
  1564 0001207E E60C                <1> 	out	0Ch, al ; clear selected channel register
  1565                              <1> 
  1566 00012080 88D8                <1> 	mov     al, bl	; byte 0 of DMA buffer address (physical)   
  1567 00012082 E602                <1> 	out	02h, al ; DMA channel 1 port number
  1568                              <1> 
  1569 00012084 88F8                <1> 	mov     al, bh  ; byte 1 of DMA buffer address (physical)   
  1570 00012086 E602                <1> 	out	02h, al
  1571                              <1> 
  1572 00012088 C1EB10              <1> 	shr	ebx, 16
  1573                              <1> 
  1574 0001208B 88D8                <1> 	mov     al, bl  ; byte 2 of DMA buffer address (physical)   
  1575 0001208D E683                <1> 	out	83h, al ; page register port addr for channel 1
  1576                              <1> 
  1577 0001208F 88C8                <1> 	mov     al, cl  ; low byte of DMA count - 1
  1578 00012091 E603                <1> 	out	03h, al ; count register port addr for channel 1
  1579                              <1> 
  1580 00012093 88E8                <1> 	mov     al, ch  ; high byte of DMA count - 1
  1581 00012095 E603                <1> 	out	03h, al
  1582                              <1> 
  1583                              <1> 	; channel 1, read, autoinitialized, single mode
  1584                              <1> 	;mov	al, 49h
  1585 00012097 B059                <1> 	mov	al, 59h ; 06/10/2017 
  1586 00012099 E60B                <1> 	out	0Bh, al ; DMA mode register port address
  1587                              <1> 
  1588 0001209B B001                <1> 	mov     al, 01h ; clear mask bit for channel 1
  1589 0001209D E60A                <1> 	out	0Ah, al ; DMA mask register port address
  1590                              <1> 
  1591                              <1> ClearBuffer:
  1592                              <1> 	;;mov	edi, [audio_dma_buff]
  1593                              <1> 	;;mov	ecx, [audio_dmabuff_size]
  1594                              <1> 	;inc	ecx
  1595                              <1> 	;mov     al, 80h
  1596                              <1> 	;;cld
  1597                              <1> 	;rep     stosb
  1598                              <1> SetIrq:
  1599                              <1> 	;mov	ebx, SbIrqhandler
  1600                              <1> 	;mov	al, [audio_intr] ; IRQ number	
  1601                              <1> 	;call	set_dev_IRQ_service
  1602                              <1> 	;; SETUP (audio) INTERRUPT CALLBACK SERVICE
  1603                              <1> 	;mov	bl, [audio_intr] ; IRQ number
  1604                              <1> 	;mov	bh, [audio_cb_mode]
  1605                              <1> 	;inc	bh  ; 1 = Signal Response Byte method (fixed value)
  1606                              <1> 	;	    ; 2 = Callback service method
  1607                              <1> 	;	    ; 3 = Auto Increment S.R.B. method 	
  1608                              <1> 	;mov	cl, [audio_srb]
  1609                              <1> 	;mov	edx, [audio_cb_addr]
  1610                              <1> 	;mov	al, [audio_user]
  1611                              <1>  	;call	set_irq_callback_service
  1612                              <1> ResetDsp:
  1613 0001209F 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1614 000120A6 6683C206            <1> 	add     dx, 06h
  1615 000120AA B001                <1> 	mov     al, 1
  1616 000120AC EE                  <1> 	out	dx, al
  1617                              <1> 
  1618 000120AD EC                  <1> 	in	al, dx
  1619 000120AE EC                  <1> 	in	al, dx
  1620 000120AF EC                  <1> 	in	al, dx
  1621 000120B0 EC                  <1> 	in	al, dx
  1622                              <1> 
  1623 000120B1 30C0                <1> 	xor     al, al
  1624 000120B3 EE                  <1> 	out	dx, al
  1625                              <1> 
  1626 000120B4 66B96400            <1> 	mov     cx, 100
  1627 000120B8 28E4                <1> 	sub	ah, ah ; 0
  1628                              <1> WaitId:         
  1629 000120BA 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1630 000120C1 6683C20E            <1> 	add     dx, 0Eh
  1631 000120C5 EC                  <1> 	in	al, dx
  1632 000120C6 08C0                <1> 	or      al, al
  1633 000120C8 7807                <1> 	js      short sb_GetId
  1634 000120CA E2EE                <1> 	loop    WaitId
  1635 000120CC E9B4000000          <1> 	jmp     sb_Exit
  1636                              <1> sb_GetId:
  1637 000120D1 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1638 000120D8 6683C20A            <1> 	add     dx, 0Ah
  1639 000120DC EC                  <1> 	in	al, dx
  1640 000120DD 3CAA                <1> 	cmp     al, 0AAh
  1641 000120DF 7407                <1> 	je      short SbOk
  1642 000120E1 E2D7                <1> 	loop    WaitId
  1643 000120E3 E99D000000          <1> 	jmp	sb_Exit
  1644                              <1> SbOk:
  1645 000120E8 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1646 000120EF 6683C20C            <1> 	add     dx, 0Ch
  1647                              <1> 	SbOut   0D1h ; Turn on speaker
  1647                              <2> %%Wait:
  1647 000120F3 EC                  <2>  in al, dx
  1647 000120F4 08C0                <2>  or al, al
  1647 000120F6 78FB                <2>  js short %%Wait
  1647 000120F8 B0D1                <2>  mov al, %1
  1647 000120FA EE                  <2>  out dx, al
  1648                              <1> 	SbOut   41h ; 8 bit or 16 bit transfer
  1648                              <2> %%Wait:
  1648 000120FB EC                  <2>  in al, dx
  1648 000120FC 08C0                <2>  or al, al
  1648 000120FE 78FB                <2>  js short %%Wait
  1648 00012100 B041                <2>  mov al, %1
  1648 00012102 EE                  <2>  out dx, al
  1649 00012103 668B1D[526B0100]    <1> 	mov	bx, [audio_freq] ; sampling rate (Hz)
  1650                              <1> 	SbOut	bh ; sampling rate high byte
  1650                              <2> %%Wait:
  1650 0001210A EC                  <2>  in al, dx
  1650 0001210B 08C0                <2>  or al, al
  1650 0001210D 78FB                <2>  js short %%Wait
  1650 0001210F 88F8                <2>  mov al, %1
  1650 00012111 EE                  <2>  out dx, al
  1651                              <1> 	SbOut	bl ; sampling rate low byte
  1651                              <2> %%Wait:
  1651 00012112 EC                  <2>  in al, dx
  1651 00012113 08C0                <2>  or al, al
  1651 00012115 78FB                <2>  js short %%Wait
  1651 00012117 88D8                <2>  mov al, %1
  1651 00012119 EE                  <2>  out dx, al
  1652                              <1> 
  1653                              <1> 	; 22/05/2017
  1654 0001211A E8C0000000          <1> 	call	sb16_volume_initial ; 15/05/2017
  1655                              <1> 	; 20/05/2017
  1656                              <1> 	;call	sb16_volume
  1657                              <1> 
  1658                              <1> StartDma:  
  1659                              <1> 	; autoinitialized mode
  1660 0001211F 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  1661 00012126 7411                <1> 	je	short sb_play_1
  1662                              <1> 	; 8 bit samples
  1663 00012128 66BBC600            <1> 	mov	bx, 0C6h ; 8 bit output (0C6h)
  1664 0001212C 803D[516B0100]02    <1> 	cmp	byte [audio_stmo], 2 ; 1 = mono, 2 = stereo
  1665 00012133 7214                <1> 	jb	short sb_play_2
  1666 00012135 B720                <1> 	mov	bh, 20h	; 8 bit stereo (20h)
  1667 00012137 EB10                <1> 	jmp	short sb_play_2
  1668                              <1> sb_play_1:
  1669                              <1> 	; 16 bit samples
  1670 00012139 66BBB610            <1> 	mov	bx, 10B6h ; 16 bit output (0B6h)
  1671 0001213D 803D[516B0100]02    <1> 	cmp	byte [audio_stmo], 2 ; 1 = mono, 2 = stereo
  1672 00012144 7203                <1> 	jb	short sb_play_2
  1673 00012146 80C720              <1> 	add	bh, 20h	; 16 bit stereo (30h)
  1674                              <1> sb_play_2:     
  1675                              <1> 	; PCM output (8/16 bit mono autoinitialized transfer)
  1676                              <1> 	SbOut   bl ; bCommand
  1676                              <2> %%Wait:
  1676 00012149 EC                  <2>  in al, dx
  1676 0001214A 08C0                <2>  or al, al
  1676 0001214C 78FB                <2>  js short %%Wait
  1676 0001214E 88D8                <2>  mov al, %1
  1676 00012150 EE                  <2>  out dx, al
  1677                              <1> 	SbOut	bh ; bMode
  1677                              <2> %%Wait:
  1677 00012151 EC                  <2>  in al, dx
  1677 00012152 08C0                <2>  or al, al
  1677 00012154 78FB                <2>  js short %%Wait
  1677 00012156 88F8                <2>  mov al, %1
  1677 00012158 EE                  <2>  out dx, al
  1678 00012159 8B1D[446B0100]      <1> 	mov	ebx, [audio_dmabuff_size]  ; 15/05/2017
  1679 0001215F D1EB                <1> 	shr	ebx, 1 ; half buffer size
  1680                              <1> 	; 20/10/2017	
  1681 00012161 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit DMA
  1682 00012168 7502                <1> 	jne	short sb_play_3
  1683 0001216A D1EB                <1> 	shr	ebx, 1 ; byte count to word count
  1684                              <1> sb_play_3: 
  1685 0001216C 664B                <1> 	dec	bx  ; wBlkSize is one less than the actual size 
  1686                              <1> 	SbOut   bl
  1686                              <2> %%Wait:
  1686 0001216E EC                  <2>  in al, dx
  1686 0001216F 08C0                <2>  or al, al
  1686 00012171 78FB                <2>  js short %%Wait
  1686 00012173 88D8                <2>  mov al, %1
  1686 00012175 EE                  <2>  out dx, al
  1687                              <1> 	SbOut   bh
  1687                              <2> %%Wait:
  1687 00012176 EC                  <2>  in al, dx
  1687 00012177 08C0                <2>  or al, al
  1687 00012179 78FB                <2>  js short %%Wait
  1687 0001217B 88F8                <2>  mov al, %1
  1687 0001217D EE                  <2>  out dx, al
  1688                              <1> 
  1689 0001217E C605[546B0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; playing !
  1690                              <1> 
  1691                              <1> 	;; Set Voice and master volumes
  1692                              <1> 	;mov	dx, [audio_io_base]
  1693                              <1> 	;add	dl, 4 ; Mixer chip Register Address Port
  1694                              <1> 	;SbOut	30h   ; select Master Volume Register (L)
  1695                              <1> 	;inc	dl    ; Mixer chip Register Data Port
  1696                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  1697                              <1> 	;dec	dl
  1698                              <1> 	;SbOut	31h   ; select Master Volume Register (R)
  1699                              <1> 	;inc	dl
  1700                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  1701                              <1> 	;dec	dl
  1702                              <1> 	;SbOut	32h   ; select Voice Volume Register (L)
  1703                              <1> 	;inc	dl
  1704                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  1705                              <1> 	;dec	dl
  1706                              <1> 	;SbOut	33h   ; select Voice Volume Register (R)
  1707                              <1> 	;inc	dl
  1708                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)	
  1709                              <1> 	;;
  1710                              <1> 	;dec	dl
  1711                              <1> 	;SbOut	44h   ; select Treble Register (L)
  1712                              <1> 	;inc	dl
  1713                              <1> 	;SbOut	0F0h  ; Max. Treble value is 15 (15*16)
  1714                              <1> 	;dec	dl
  1715                              <1> 	;SbOut	45h   ; select Treble Register (R)
  1716                              <1> 	;inc	dl
  1717                              <1> 	;SbOut	0F0h  ; Max. Treble value is 15 (15*16)
  1718                              <1> 	;dec	dl
  1719                              <1> 	;SbOut	46h   ; select Bass Register (L)
  1720                              <1> 	;inc	dl
  1721                              <1> 	;SbOut	0F0h  ; Max. Bass value is 15 (15*16)
  1722                              <1> 	;dec	dl
  1723                              <1> 	;SbOut	47h   ; select Bass Register (R)
  1724                              <1> 	;inc	dl
  1725                              <1> 	;SbOut	0F0h  ; Max. Bass value is 15 (15*16)	
  1726                              <1> 
  1727                              <1> sb_Exit:           
  1728                              <1> 	;popad
  1729 00012185 C3                  <1> 	retn
  1730                              <1> 
  1731                              <1> sb16_int_handler:
  1732                              <1> 	; Interrupt Handler for Sound Blaster 16 Audio Card
  1733                              <1> 	; Note: called by 'dev_IRQ_service'
  1734                              <1> 	; 20/10/2017
  1735                              <1> 	; 12/10/2017
  1736                              <1> 	; 10/10/2017 
  1737                              <1> 	; 12/05/2017, 09/10/2017
  1738                              <1> 	; 24/04/2017 (TRDOS 386 kernel, 'audio.s')
  1739                              <1> 	; 10/03/2017 - 'PLAYWAV.PRG' ('playwav.s') 
  1740                              <1> 
  1741                              <1> 	;push	eax ; * must be saved !
  1742                              <1> 	;push	ebx ; * must be saved !
  1743                              <1> 	;push	ecx
  1744                              <1> 	;push	edx
  1745                              <1> 	;push	esi
  1746                              <1> 	;push	edi
  1747                              <1> 
  1748 00012186 668B15[266B0100]    <1> 	mov     dx, [audio_io_base]
  1749                              <1> 	; 20/10/2017
  1750 0001218D 80C20F              <1> 	add     dl, 0Fh ; 2xFh (DSP 16 bit intr ack)
  1751 00012190 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16
  1752 00012197 7402                <1> 	je	short sb_irq_16bit_ack
  1753                              <1> sb_irq_8bit_ack:
  1754 00012199 FECA                <1> 	dec	dl  ; 2xEh (DSP 8 bit intr ack)
  1755                              <1> sb_irq_16bit_ack:
  1756 0001219B EC                  <1> 	in	al, dx
  1757                              <1> 
  1758                              <1> 	;cmp	byte [audio_busy], 0
  1759                              <1> 	;ja	short sb_irq_h3
  1760                              <1> 
  1761                              <1> 	;mov	byte [audio_busy], 1
  1762                              <1> 
  1763 0001219C 803D[546B0100]01    <1> 	cmp	byte [audio_play_cmd], 1
  1764 000121A3 7307                <1> 	jnb	short sb_irq_h1
  1765                              <1> sb_irq_h0:
  1766 000121A5 E8A9000000          <1> 	call	sb16_stop
  1767 000121AA EB2B                <1> 	jmp	short sb_irq_h3
  1768                              <1> sb_irq_h1:
  1769                              <1> 	;call	sb16_tuneloop
  1770                              <1> 	; 09/10/2017
  1771                              <1> sb16_tuneloop:
  1772 000121AC 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff]
  1773 000121B2 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  1774 000121B8 D1E9                <1> 	shr	ecx, 1 ; dma buff size / 2 = half buffer size
  1775                              <1> 
  1776                              <1> 	; 22/05/2017
  1777 000121BA F605[486B0100]01    <1> 	test	byte [audio_flag], 1  ; Current flag value
  1778 000121C1 7402                <1> 	jz	short sb_tlp1 ; EOL (Half Buffer 1 must be filled)
  1779                              <1> 	; FLAG (Half Buffer 2 must be filled)
  1780 000121C3 01CF                <1> 	add	edi, ecx
  1781                              <1> 	; 15/05/2017
  1782                              <1> sb_tlp1: 
  1783 000121C5 8B35[386B0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  1784                              <1> 	;rep	movsb
  1785 000121CB C1E902              <1> 	shr	ecx, 2 ; half buff size / 4
  1786 000121CE F3A5                <1> 	rep	movsd 
  1787                              <1> 	;retn
  1788                              <1> 
  1789                              <1> 	; 10/10/2017
  1790                              <1> 	; switch flag value
  1791 000121D0 8035[486B0100]01    <1> 	xor	byte [audio_flag], 1
  1792                              <1> 
  1793                              <1> 	; 12/10/2017
  1794                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2 (odd intr count)
  1795                              <1> 			   ; Next buffer (to update) is dma half buff 1
  1796                              <1> 	; 	       = 1 : Playing dma half buffer 1 (even intr count)
  1797                              <1> 			   ; Next buffer (to update) is dma half buff 2
  1798                              <1> 
  1799                              <1> sb_irq_h3:
  1800                              <1> 	;mov	byte [audio_busy], 0
  1801                              <1> 
  1802                              <1> 	;pop	edi
  1803                              <1> 	;pop	esi
  1804                              <1> 	;pop	edx
  1805                              <1> 	;pop	ecx
  1806                              <1> 	;pop	ebx ; * must be restored !
  1807                              <1> 	;pop	eax ; * must be restored !
  1808                              <1> 	
  1809 000121D7 C3                  <1> 	retn
  1810                              <1> 
  1811                              <1> sb16_volume:
  1812                              <1> 	; 22/10/2017
  1813                              <1> 	; mov [audio_master_volume_l], cl 
  1814                              <1> 	; mov [audio_master_volume_h], ch 
  1815 000121D8 66890D[566B0100]    <1> 	mov	[audio_master_volume], cx
  1816                              <1> sb16_volume_initial:
  1817 000121DF 6652                <1> 	push	dx ; DX (port address) must be saved
  1818 000121E1 668B15[266B0100]    <1> 	mov	dx, [audio_io_base]
  1819 000121E8 6683C204            <1> 	add	dx, 4 ; Mixer chip address port
  1820 000121EC B022                <1> 	mov	al, 22h ; master volume
  1821 000121EE EE                  <1> 	out	dx, al
  1822 000121EF 6642                <1> 	inc	dx
  1823 000121F1 8A25[566B0100]      <1> 	mov	ah, [audio_master_volume_l]
  1824 000121F7 C0EC02              <1> 	shr	ah, 2 ; 32 -> 8 level
  1825 000121FA C0E405              <1> 	shl	ah, 5 ; bit 5 to 7
  1826 000121FD A0[576B0100]        <1> 	mov	al, [audio_master_volume_r]	
  1827 00012202 C0E802              <1> 	shr	al, 2 ; 32 -> 8 level
  1828                              <1> 	;and	al, 0Fh
  1829 00012205 D0E0                <1> 	shl	al, 1 ; bit 1 to 3
  1830 00012207 08E0                <1> 	or	al, ah
  1831 00012209 EE                  <1> 	out	dx, al
  1832 0001220A 665A                <1> 	pop	dx ; DX (port address) must be restored
  1833 0001220C C3                  <1> 	retn
  1834                              <1> 
  1835                              <1> sb16_pause:
  1836 0001220D 668B15[266B0100]    <1> 	mov	dx, [audio_io_base]
  1837 00012214 6683C20C            <1> 	add	dx, 0Ch ; Command & Data Port
  1838 00012218 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  1839 0001221F 7404                <1> 	je	short sb_pause_1
  1840                              <1> 	; 8 bit samples
  1841 00012221 B3D0                <1> 	mov	bl, 0D0h ; 8 bit DMA mode
  1842 00012223 EB02                <1> 	jmp	short sb_pause_2
  1843                              <1> sb_pause_1:
  1844                              <1> 	; 16 bit samples
  1845 00012225 B3D5                <1> 	mov	bl, 0D5h ; 16 bit DMA mode
  1846                              <1> sb_pause_2:     
  1847                              <1> 	SbOut   bl ; bCommand
  1847                              <2> %%Wait:
  1847 00012227 EC                  <2>  in al, dx
  1847 00012228 08C0                <2>  or al, al
  1847 0001222A 78FB                <2>  js short %%Wait
  1847 0001222C 88D8                <2>  mov al, %1
  1847 0001222E EE                  <2>  out dx, al
  1848                              <1> sb_pause_3:
  1849 0001222F C3                  <1> 	retn
  1850                              <1> 
  1851                              <1> sb16_continue:
  1852 00012230 668B15[266B0100]    <1> 	mov	dx, [audio_io_base]
  1853 00012237 6683C20C            <1> 	add	dx, 0Ch ; Command & Data Port
  1854 0001223B 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  1855 00012242 7404                <1> 	je	short sb_cont_1
  1856                              <1> 	; 8 bit samples
  1857 00012244 B3D4                <1> 	mov	bl, 0D4h ; 8 bit DMA mode
  1858 00012246 EB02                <1> 	jmp	short sb_cont_2
  1859                              <1> sb_cont_1:
  1860                              <1> 	; 16 bit samples
  1861 00012248 B3D6                <1> 	mov	bl, 0D6h ; 16 bit DMA mode
  1862                              <1> sb_cont_2:     
  1863                              <1> 	SbOut   bl ; bCommand
  1863                              <2> %%Wait:
  1863 0001224A EC                  <2>  in al, dx
  1863 0001224B 08C0                <2>  or al, al
  1863 0001224D 78FB                <2>  js short %%Wait
  1863 0001224F 88D8                <2>  mov al, %1
  1863 00012251 EE                  <2>  out dx, al
  1864                              <1> sb_cont_3:
  1865 00012252 C3                  <1> 	retn
  1866                              <1> 
  1867                              <1> sb16_stop:
  1868                              <1> 	; 24/04/2017
  1869 00012253 803D[546B0100]00    <1> 	cmp	byte [audio_play_cmd], 0
  1870 0001225A 7648                <1> 	jna	short sb16_stop_4
  1871                              <1> 
  1872                              <1> 	; 22/05/2017
  1873 0001225C 668B15[266B0100]    <1> 	mov	dx, [audio_io_base]
  1874 00012263 6683C20C            <1> 	add	dx, 0Ch
  1875                              <1> 
  1876 00012267 B3D9                <1> 	mov	bl, 0D9h ; exit auto-initialize 16 bit transfer
  1877                              <1> 	; stop  autoinitialized DMA transfer mode 
  1878 00012269 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  1879 00012270 7402                <1> 	je	short sb16_stop_1
  1880                              <1> 	;mov	bl, 0DAh ; exit auto-initialize 8 bit transfer
  1881 00012272 FEC3                <1> 	inc	bl
  1882                              <1> sb16_stop_1:
  1883                              <1> 	SbOut	bl ; exit auto-initialize transfer command
  1883                              <2> %%Wait:
  1883 00012274 EC                  <2>  in al, dx
  1883 00012275 08C0                <2>  or al, al
  1883 00012277 78FB                <2>  js short %%Wait
  1883 00012279 88D8                <2>  mov al, %1
  1883 0001227B EE                  <2>  out dx, al
  1884                              <1> 
  1885 0001227C 30C0                <1> 	xor     al, al ; stops all DMA processes on selected channel
  1886                              <1> 
  1887 0001227E 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  1888 00012285 7404                <1> 	je	short sb16_stop_2
  1889 00012287 E60C                <1> 	out	0Ch, al ; clear selected channel register
  1890 00012289 EB02                <1> 	jmp	short sb16_stop_3
  1891                              <1> 
  1892                              <1> sb16_stop_2:
  1893 0001228B E6D8                <1> 	out	0D8h, al ; clear selected channel register
  1894                              <1> 
  1895                              <1> sb16_stop_3:
  1896 0001228D C605[546B0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  1897                              <1> SbDone:
  1898                              <1> 	;mov	dx, [audio_io_base]
  1899                              <1> 	;add	dx, 0Ch
  1900                              <1> 	SbOut   0D0h
  1900                              <2> %%Wait:
  1900 00012294 EC                  <2>  in al, dx
  1900 00012295 08C0                <2>  or al, al
  1900 00012297 78FB                <2>  js short %%Wait
  1900 00012299 B0D0                <2>  mov al, %1
  1900 0001229B EE                  <2>  out dx, al
  1901                              <1> 	SbOut   0D3h
  1901                              <2> %%Wait:
  1901 0001229C EC                  <2>  in al, dx
  1901 0001229D 08C0                <2>  or al, al
  1901 0001229F 78FB                <2>  js short %%Wait
  1901 000122A1 B0D3                <2>  mov al, %1
  1901 000122A3 EE                  <2>  out dx, al
  1902                              <1> sb16_stop_4:
  1903 000122A4 C3                  <1> 	retn
  1904                              <1> 
  1905                              <1> sb16_reset:
  1906                              <1> 	; 24/04/2017      
  1907 000122A5 668B15[266B0100]    <1> 	mov     dx, [audio_io_base] ; try to reset the DSP.
  1908 000122AC 6683C206            <1> 	add     dx, 06h
  1909 000122B0 B001                <1> 	mov	al, 1
  1910 000122B2 EE                  <1> 	out	dx, al
  1911                              <1> 
  1912 000122B3 EC                  <1> 	in	al, dx
  1913 000122B4 EC                  <1> 	in	al, dx
  1914 000122B5 EC                  <1> 	in	al, dx
  1915 000122B6 EC                  <1> 	in	al, dx
  1916                              <1> 
  1917 000122B7 30C0                <1> 	xor     al, al
  1918 000122B9 EE                  <1> 	out	dx, al
  1919                              <1> 
  1920 000122BA 6683C208            <1> 	add     dx, 08h
  1921 000122BE 66B96400            <1> 	mov	cx, 100
  1922                              <1> sbrstWaitID:
  1923 000122C2 EC                  <1> 	in	al, dx
  1924 000122C3 08C0                <1> 	or      al, al
  1925 000122C5 7804                <1> 	js      short sbrstGetID
  1926 000122C7 E2F9                <1> 	loop    sbrstWaitID
  1927 000122C9 F9                  <1> 	stc
  1928 000122CA C3                  <1> 	retn
  1929                              <1> sbrstGetID:          
  1930 000122CB 6683EA04            <1> 	sub     dx, 04h
  1931 000122CF EC                  <1> 	in	al, dx
  1932 000122D0 3CAA                <1> 	cmp     al, 0AAh
  1933 000122D2 7406                <1> 	je      short sb_rst_retn
  1934 000122D4 6683C204            <1> 	add     dx, 04h
  1935 000122D8 E2E8                <1> 	loop    sbrstWaitID
  1936                              <1> sb_rst_retn:
  1937 000122DA C3                  <1> 	retn
  1938                              <1> 
  1939                              <1> ac97_codec_config:
  1940                              <1> 	; 10/06/2017
  1941                              <1> 	; 05/06/2017
  1942                              <1> 	; 29/05/2017
  1943                              <1> 	; 28/05/2017 (TRDOS 386, 'audio.s')
  1944                              <1> 	; 07/11/2016 (Erdogan Tan)
  1945                              <1> 	; Derived from 'codecConfig' procedure in 'CODEC.ASM'
  1946                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  1947                              <1> 
  1948                              <1> 	;; 'PLAYER.ASM'
  1949                              <1> 	;; get ICH base address regs for mixer and bus master
  1950                              <1> 
  1951                              <1> init_ac97_controller: ; 10/06/2017
  1952 000122DB A1[286B0100]        <1> 	mov	eax, [audio_dev_id]
  1953                              <1>         ;mov	al, NAMBAR_REG
  1954                              <1>         ;;call  pciRegRead16			; read PCI registers 10-11
  1955                              <1>         ;call	pciRegRead32
  1956                              <1> 	;and	dx, IO_ADDR_MASK 		; mask off BIT0
  1957                              <1> 	;;and	edx, IO_ADDR_MASK 
  1958                              <1> 
  1959                              <1>         ;mov	[NAMBAR], dx			; save audio mixer base addr
  1960                              <1> 
  1961                              <1>         ;mov    al, NABMBAR_REG
  1962                              <1>         ;;call	pciRegRead16
  1963                              <1>         ;call	pciRegRead32
  1964                              <1> 	;and	dx, 0FFC0h ; IO_ADDR_MASK
  1965                              <1> 	;;and	edx, 0FFC0h
  1966                              <1> 
  1967                              <1>         ;mov    [NABMBAR], dx			; save bus master base addr
  1968                              <1> 
  1969                              <1> 	;mov	eax, [audio_dev_id]
  1970 000122E0 B004                <1>         mov     al, PCI_CMD_REG
  1971                              <1>         ;call	pciRegRead8			; read PCI command register
  1972 000122E2 E83DF8FFFF          <1>         call	pciRegRead16
  1973 000122E7 80CA05              <1> 	or      dl, IO_ENA+BM_ENA               ; enable IO and bus master
  1974                              <1>         ;call 	pciRegWrite8
  1975 000122EA E8A0F8FFFF          <1> 	call	pciRegWrite16
  1976                              <1> 
  1977                              <1> 	; 'CODEC.ASM'
  1978                              <1> 
  1979                              <1> 	; enable codec, unmute stuff, set output rate
  1980                              <1> ;	; entry: [audio_freq] = desired sample rate
  1981                              <1> 		
  1982                              <1> ;	mov    	dx, [NAMBAR]               	
  1983                              <1> ;	add    	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah  	  
  1984                              <1> ;	in     	ax, dx
  1985                              <1> ;	or	ax, 1
  1986                              <1> ;	out	dx, ax 				; Enable variable rate audio
  1987                              <1> 
  1988                              <1> ;       ;call    delay1_4ms
  1989                              <1> ;       ;call    delay1_4ms
  1990                              <1> ;       ;call    delay1_4ms
  1991                              <1> ;       ;call    delay1_4ms
  1992                              <1> 
  1993                              <1> ;	mov	ax, [audio_freq]		; sample rate
  1994                              <1> 
  1995                              <1> ;	mov    	dx, [NAMBAR]               	
  1996                              <1> ;	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
  1997                              <1> ;	out	dx, ax 				; out sample rate
  1998                              <1> 		
  1999                              <1> ;       ;call	delay1_4ms
  2000                              <1> ;       ;call	delay1_4ms
  2001                              <1> ;       ;call	delay1_4ms
  2002                              <1> ;       ;call	delay1_4ms
  2003                              <1> 
  2004                              <1> 	;mov	dx, [NAMBAR]			; mixer base address
  2005                              <1>         ;add	dx, CODEC_RESET_REG  		; reset register
  2006                              <1>         ;mov	ax, 42
  2007                              <1> 	;out	dx, ax                          ; reset
  2008                              <1> 
  2009                              <1> 	;mov    dx, [NABMBAR]			; bus master base address
  2010                              <1>         ;add	dx, GLOB_STS_REG
  2011                              <1>         ;mov	ax, 2
  2012                              <1> 	;out	dx, ax                         
  2013                              <1> 
  2014 000122EF E846F9FFFF          <1>         call    delay_100ms ; 29/05/2017
  2015                              <1> 
  2016                              <1> init_ac97_codec:
  2017                              <1> 	; 10/06/2017
  2018                              <1> 	; 29/05/2017
  2019                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  2020                              <1> 	;	
  2021 000122F4 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2022 000122F8 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2023 000122FF ED                  <1> 	in	eax, dx
  2024                              <1> 	; ?
  2025 00012300 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  2026 00012304 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2027 0001230B ED                  <1> 	in	eax, dx
  2028                              <1> 
  2029 0001230C 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; -1
  2030 0001230F 744B                <1> 	je	short init_ac97_codec_err1
  2031                              <1> 
  2032 00012311 A900030010          <1> 	test	eax, CTRL_ST_CREADY
  2033 00012316 7507                <1> 	jnz	short _ac97_codec_ready
  2034                              <1> 
  2035 00012318 E8EF020000          <1> 	call	reset_ac97_codec
  2036 0001231D 723E                <1> 	jc	short init_ac97_codec_err2
  2037                              <1> 
  2038                              <1> _ac97_codec_ready:
  2039 0001231F 668B15[586B0100]    <1> 	mov	dx, [NAMBAR]
  2040                              <1> 	;add	dx, 0 ; ac_reg_0 ; reset register
  2041 00012326 66EF                <1> 	out	dx, ax
  2042                              <1> 
  2043 00012328 31C0                <1> 	xor	eax, eax ; 0
  2044 0001232A 668B15[586B0100]    <1> 	mov	dx, [NAMBAR]
  2045 00012331 6683C226            <1> 	add	dx, CODEC_REG_POWERDOWN	
  2046 00012335 66EF                <1> 	out	dx, ax
  2047                              <1> 
  2048                              <1> 	; 10/06/2017
  2049                              <1> 	; 29/05/2017
  2050                              <1> 	; wait for 1 second
  2051 00012337 B9E8030000          <1> 	mov	ecx, 1000 ; 1000*0.25ms = 1s
  2052                              <1> _ac97_codec_rloop:
  2053 0001233C E806F9FFFF          <1> 	call	delay1_4ms
  2054 00012341 E801F9FFFF          <1> 	call	delay1_4ms
  2055 00012346 E8FCF8FFFF          <1> 	call	delay1_4ms
  2056 0001234B E8F7F8FFFF          <1> 	call	delay1_4ms
  2057                              <1> 	;mov	dx, [NAMBAR]
  2058                              <1> 	;add	dx, CODEC_REG_POWERDOWN
  2059 00012350 66ED                <1> 	in	ax, dx	
  2060 00012352 6683E00F            <1> 	and	ax, 0Fh
  2061 00012356 3C0F                <1> 	cmp	al, 0Fh
  2062 00012358 7404                <1> 	je	short _ac97_codec_init_ok
  2063 0001235A E2E0                <1> 	loop	_ac97_codec_rloop 
  2064                              <1> 
  2065                              <1> init_ac97_codec_err1:
  2066 0001235C F9                  <1> 	stc
  2067                              <1> init_ac97_codec_err2:
  2068 0001235D C3                  <1> 	retn
  2069                              <1> 
  2070                              <1> _ac97_codec_init_ok:
  2071 0001235E B002                <1>         mov     al, 2 ; force set 16-bit 2-channel PCM
  2072 00012360 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2073 00012364 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2074 0001236B EF                  <1> 	out	dx, eax
  2075                              <1> 
  2076                              <1> 	;call	delay1_4ms
  2077                              <1> 
  2078                              <1> 	; 10/06/2017
  2079 0001236C E849020000          <1> 	call 	reset_ac97_controller
  2080                              <1> 
  2081                              <1> ;	call 	setup_ac97_codec
  2082                              <1> ;
  2083                              <1> ;detect_ac97_codec:
  2084                              <1> ;	retn
  2085                              <1> 
  2086                              <1> setup_ac97_codec:
  2087                              <1> 	; 22/07/2020
  2088                              <1> 	; 10/06/2017
  2089                              <1> 	; 29/05/2017
  2090 00012371 B802020000          <1> 	mov     eax, 0202h
  2091 00012376 66A3[566B0100]      <1> 	mov	[audio_master_volume], ax
  2092 0001237C 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31, 31
  2093                              <1> 	
  2094 00012380 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2095 00012387 6683C202            <1>   	add     dx, CODEC_MASTER_VOL_REG	;02h 
  2096 0001238B 6631C0              <1>   	xor	ax, ax 	; volume attenuation = 0 (max. volume)
  2097 0001238E 66EF                <1>   	out     dx, ax
  2098                              <1>  
  2099 00012390 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2100 00012397 6683C206            <1>   	add     dx, CODEC_MASTER_MONO_VOL_REG	;06h 
  2101                              <1> 	;xor	ax, ax
  2102 0001239B 66EF                <1>   	out     dx, ax
  2103                              <1> 
  2104 0001239D 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2105 000123A4 6683C20A            <1>   	add     dx, CODEC_PCBEEP_VOL_REG	;0Ah 
  2106                              <1>   	;xor    ax, ax
  2107 000123A8 66EF                <1>   	out     dx, ax
  2108                              <1> 
  2109 000123AA 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2110 000123B1 6683C218            <1>   	add     dx, CODEC_PCM_OUT_REG		;18h 
  2111                              <1>   	;xor    ax, ax
  2112 000123B5 66EF                <1>   	out     dx, ax
  2113                              <1> 
  2114 000123B7 66B80880            <1> 	mov     ax, 8008h ; Mute
  2115 000123BB 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2116                              <1> 	; 22/07/2020
  2117 000123C2 6683C20C            <1> 	add	dx, CODEC_PHONE_VOL_REG		;0Ch
  2118                              <1> 				 ; AC97_PHONE_VOL ; TAD Input (Mono)
  2119 000123C6 66EF                <1>   	out     dx, ax
  2120                              <1> 
  2121 000123C8 66B80808            <1>         mov	ax, 0808h
  2122 000123CC 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2123 000123D3 6683C210            <1>         add	dx, CODEC_LINE_IN_VOL_REG ;10h ; Line Input (Stereo)	
  2124 000123D7 66EF                <1>   	out     dx, ax
  2125                              <1> 
  2126                              <1> 	;mov	ax, 0808h
  2127 000123D9 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2128 000123E0 6683C212            <1>         add	dx, CODEC_CD_VOL_REG ;12h ; CR Input (Stereo)
  2129 000123E4 66EF                <1>   	out     dx, ax
  2130                              <1> 
  2131                              <1> 	;mov	ax, 0808h
  2132 000123E6 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2133 000123ED 6683C216            <1>         add	dx, CODEC_AUX_VOL_REG ;16h ; Aux Input (Stereo)
  2134 000123F1 66EF                <1>   	out     dx, ax
  2135                              <1> 
  2136                              <1>         ;call    delay1_4ms
  2137                              <1>         ;call    delay1_4ms
  2138                              <1>         ;call    delay1_4ms
  2139                              <1>         ;call    delay1_4ms
  2140                              <1> 
  2141                              <1> detect_ac97_codec:
  2142 000123F3 C3                  <1>         retn
  2143                              <1> 
  2144                              <1> set_ac97_bdl: ; Set AC97 (ICH) Buffer Descriptor List
  2145                              <1> 	; 17/06/2017
  2146                              <1> 	; 11/06/2017
  2147                              <1> 	; 28/05/2017
  2148                              <1> 	; eax = dma buffer address = [audio_DMA_buff]
  2149                              <1> 	; ecx = dma buffer buffer size = [audio_dmabuff_size]
  2150                              <1> 
  2151 000123F4 D1E9                <1> 	shr	ecx, 1 ; dma half buffer size
  2152 000123F6 89CE                <1> 	mov	esi, ecx
  2153                              <1> 
  2154 000123F8 BF[5C6B0100]        <1>         mov     edi, audio_bdl_buff	; get BDL address
  2155 000123FD B910000000          <1>         mov     ecx, 32 / 2		; make 32 entries in BDL
  2156                              <1> 
  2157 00012402 EB05                <1> 	jmp	short s_ac97_bdl1 
  2158                              <1> 
  2159                              <1> s_ac97_bdl0:
  2160                              <1> 	; set buffer descriptor 0 to start of data file in memory
  2161                              <1> 
  2162 00012404 A1[406B0100]        <1>  	mov	eax, [audio_dma_buff]	; Physical address of DMA buffer
  2163                              <1>  
  2164                              <1> s_ac97_bdl1:
  2165 00012409 AB                  <1> 	stosd				; store dmabuffer1 address
  2166                              <1> 
  2167 0001240A 89C2                <1> 	mov	edx, eax
  2168                              <1> 
  2169                              <1> ;
  2170                              <1> ; Buffer Descriptors List
  2171                              <1> ; As stated earlier, each buffer descriptor list is a set of (up to) 32 
  2172                              <1> ; descriptors, each 8 bytes in length.  Bytes 0-3 of a descriptor entry point
  2173                              <1> ; to a chunk of memory to either play from or record to.  Bytes 4-7 of an
  2174                              <1> ; entry describe various control things detailed below.
  2175                              <1> ; 
  2176                              <1> ; Buffer pointers must always be aligned on a Dword boundry.
  2177                              <1> ;
  2178                              <1> ;
  2179                              <1> 
  2180                              <1> ;IOC                     equ     BIT31	; Fire an interrupt whenever this
  2181                              <1>                                         ; buffer is complete.
  2182                              <1> 
  2183                              <1> ;BUP                     equ     BIT30  ; Buffer Underrun Policy.
  2184                              <1>                                         ; if this buffer is the last buffer
  2185                              <1>                                         ; in a playback, fill the remaining
  2186                              <1>                                         ; samples with 0 (silence) or not.
  2187                              <1>                                         ; It's a good idea to set this to 1
  2188                              <1>                                         ; for the last buffer in playback,
  2189                              <1>                                         ; otherwise you're likely to get a lot
  2190                              <1>                                         ; of noise at the end of the sound.
  2191                              <1> 
  2192                              <1> ;
  2193                              <1> ; Bits 15:0 contain the length of the buffer, in number of samples, which
  2194                              <1> ; are 16 bits each, coupled in left and right pairs, or 32bits each.
  2195                              <1> ; Luckily for us, that's the same format as .wav files.
  2196                              <1> ;
  2197                              <1> ; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
  2198                              <1> ; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
  2199                              <1> ;
  2200                              <1> ; A value of 0 in these bits means play no samples.
  2201                              <1> ;
  2202                              <1> 
  2203 0001240C 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  2204 0001240E 01C2                <1> 	add	edx, eax
  2205 00012410 D1E8                <1> 	shr	eax, 1 ; count of 16 bit samples
  2206                              <1> 	;or	eax, IOC+BUP
  2207 00012412 0D00000080          <1> 	or	eax, IOC ; 11/06/2017
  2208 00012417 AB                  <1> 	stosd
  2209                              <1> 
  2210                              <1> ; 2nd buffer:
  2211                              <1> 
  2212 00012418 89D0                <1>         mov	eax, edx ; Physical address of the 2nd half of DMA buffer	
  2213 0001241A AB                  <1> 	stosd		 ; store dmabuffer2 address
  2214                              <1> 
  2215                              <1> ; set length to [audio_dmabuff_size]/2
  2216                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  2217                              <1> ; 
  2218 0001241B 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  2219 0001241D D1E8                <1> 	shr	eax, 1 ; count of 16 bit samples
  2220                              <1> 	;or	eax, IOC+BUP
  2221 0001241F 0D00000080          <1> 	or	eax, IOC ; 11/06/2017
  2222 00012424 AB                  <1> 	stosd
  2223                              <1> 
  2224 00012425 E2DD                <1> 	loop    s_ac97_bdl0
  2225                              <1> 	
  2226 00012427 C3                  <1> 	retn
  2227                              <1> 
  2228                              <1> ac97_start_play:  
  2229                              <1> 	; 28/05/2017
  2230                              <1> 	; Derived from 'playWav' procedure in 'ICHWAV.ASM'
  2231                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  2232                              <1> 
  2233                              <1> 	; set output rate
  2234                              <1> 	; entry: [audio_freq] = desired sample rate
  2235                              <1> 		
  2236 00012428 668B15[586B0100]    <1> 	mov    	dx, [NAMBAR]               	
  2237 0001242F 6683C22A            <1> 	add    	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah  	  
  2238 00012433 66ED                <1> 	in     	ax, dx
  2239 00012435 6683C801            <1> 	or	ax, 1
  2240 00012439 66EF                <1> 	out	dx, ax 				; Enable variable rate audio
  2241                              <1> 
  2242                              <1>        ;call    delay1_4ms
  2243                              <1>        ;call    delay1_4ms
  2244                              <1>        ;call    delay1_4ms
  2245                              <1>        ;call    delay1_4ms
  2246                              <1> 
  2247 0001243B 66A1[526B0100]      <1> 	mov	ax, [audio_freq]		; sample rate
  2248                              <1> 
  2249 00012441 668B15[586B0100]    <1> 	mov    	dx, [NAMBAR]               	
  2250 00012448 6683C22C            <1> 	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
  2251 0001244C 66EF                <1> 	out	dx, ax 				; out sample rate
  2252                              <1> 		
  2253                              <1>        ;call    delay1_4ms
  2254                              <1>        ;call    delay1_4ms
  2255                              <1>        ;call    delay1_4ms
  2256                              <1>        ;call    delay1_4ms
  2257                              <1> 
  2258                              <1> ;
  2259                              <1> ; register reset the DMA engine. This may cause a pop noise on the output
  2260                              <1> ; lines when the device is reset. Prolly a better idea to mute output, then
  2261                              <1> ; reset.
  2262                              <1> ;
  2263 0001244E 668B15[5A6B0100]    <1>         mov     dx, [NABMBAR]
  2264 00012455 6683C21B            <1>         add     dx, PO_CR_REG                  ; set pointer to Cntl reg
  2265 00012459 B002                <1>         mov     al, RR                         ; set reset
  2266 0001245B EE                  <1>         out     dx, al                         ; self clearing bit
  2267                              <1> ;
  2268                              <1> ;	mov	edi, audio_bdl_buff
  2269                              <1> ;	mov	edx, [audio_dmabuff_size]
  2270                              <1> ;	shr	edx, 1
  2271                              <1> ;	mov	ecx, 32/2
  2272                              <1> ;ac97_set_bdl_buffer:
  2273                              <1> ;	; 1st half of DMA buffer
  2274                              <1> ;	mov	eax, [audio_dma_buff]
  2275                              <1> ;	push	eax
  2276                              <1> ;	stosd
  2277                              <1> ;	mov	eax, edx ; dma buffer size / 2
  2278                              <1> ;	or	eax, IOC+BUP
  2279                              <1> ;	stosd
  2280                              <1> ;	pop	eax
  2281                              <1> ;	; 2nd half of DMA buffer
  2282                              <1> ;	add	eax, edx
  2283                              <1> ;	stosd
  2284                              <1> ;	mov	eax, edx ; dma buffer size / 2
  2285                              <1> ;	or	eax, IOC+BUP
  2286                              <1> ;	stosd
  2287                              <1> ;	loop	ac97_set_bdl_buffer
  2288                              <1>  	
  2289                              <1> ; tell the DMA engine where to find our list of Buffer Descriptors.
  2290                              <1> ; this 32bit value is a flat mode memory offset (ie no segment:offset)
  2291                              <1> ;
  2292                              <1> ; write NABMBAR+10h with offset of buffer descriptor list
  2293                              <1> ;
  2294 0001245C B8[5C6B0100]        <1>         mov	eax, audio_bdl_buff
  2295 00012461 668B15[5A6B0100]    <1> 	mov	dx, [NABMBAR]
  2296 00012468 6683C210            <1> 	add	dx, PO_BDBAR_REG
  2297 0001246C EF                  <1> 	out	dx, eax
  2298                              <1> ;
  2299                              <1> ; All set.  Let's play some music.
  2300                              <1> ;
  2301                              <1> ;
  2302 0001246D B81F000000          <1> 	mov	eax, 31
  2303 00012472 E816000000          <1> 	call    set_ac97_LastValidIndex
  2304                              <1> 
  2305 00012477 C605[546B0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  2306                              <1> 
  2307                              <1> ac97_play: ; continue to play (after pause)
  2308                              <1> 	; 11/06/2017
  2309                              <1> 	; 29/05/2017
  2310                              <1> 	; 28/05/2017
  2311 0001247E 668B15[5A6B0100]    <1>         mov     dx, [NABMBAR]
  2312 00012485 6683C21B            <1>         add     dx, PO_CR_REG		; PCM out control register
  2313 00012489 B011                <1>         mov	al, IOCE+RPBM ; 29/05/2017
  2314                              <1>         ;mov	al, 1Dh ; (Ref: KolibriOS, intelac97.asm, 'play:')
  2315 0001248B EE                  <1> 	out     dx, al			; set start!
  2316                              <1> 
  2317                              <1> 	;mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  2318                              <1> 
  2319 0001248C C3                  <1> 	retn
  2320                              <1> 
  2321                              <1> ;input AL = index # to stop on
  2322                              <1> set_ac97_LastValidIndex:
  2323                              <1> 	; 28/05/2017
  2324                              <1> 	; Derived from 'setLastValidIndex' procedure in 'ICHWAV.ASM'
  2325                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  2326 0001248D 668B15[5A6B0100]    <1> 	mov	dx, [NABMBAR]
  2327 00012494 6683C215            <1> 	add	dx, PO_LVI_REG
  2328 00012498 EE                  <1>         out     dx, al
  2329                              <1> 	;mov	[audio_lvi], al ; for ac97_int_handler
  2330 00012499 C3                  <1> 	retn
  2331                              <1> 
  2332                              <1> ac97_volume:
  2333                              <1> 	; 28/05/2017
  2334                              <1> 	; bl = component (0 = master/playback/lineout volume)
  2335                              <1> 	; cl = left channel volume level (0 to 31)
  2336                              <1> 	; ch = right channel volume level (0 to 31)
  2337                              <1> 
  2338 0001249A 08DB                <1> 	or	bl, bl
  2339 0001249C 7523                <1> 	jnz	short ac97_vol_1 ; temporary !
  2340 0001249E 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31,31
  2341 000124A2 38C1                <1> 	cmp	cl, al
  2342 000124A4 771B                <1> 	ja	short ac97_vol_1 ; temporary !
  2343 000124A6 38E5                <1> 	cmp	ch, ah
  2344 000124A8 7717                <1> 	ja	short ac97_vol_1 ; temporary !
  2345 000124AA 66890D[566B0100]    <1> 	mov	[audio_master_volume], cx
  2346 000124B1 6629C8              <1> 	sub	ax, cx
  2347 000124B4 668B15[586B0100]    <1>   	mov     dx, [NAMBAR]
  2348 000124BB 6683C202            <1>   	add     dx, CODEC_MASTER_VOL_REG  ; 02h ; Line Out 
  2349 000124BF 66EF                <1>   	out     dx, ax
  2350                              <1> ac97_vol_1:
  2351 000124C1 C3                  <1> 	retn
  2352                              <1> 
  2353                              <1> ac97_int_handler:
  2354                              <1> 	; 12/10/2017
  2355                              <1> 	; 10/10/2017
  2356                              <1> 	; 09/10/2017
  2357                              <1> 	; 13/06/2017, 13/06/2017
  2358                              <1> 	; 10/06/2017, 11/06/2017
  2359                              <1> 	; Interrupt Handler for AC97 (ICH) Audio Controller
  2360                              <1> 	; Note: called by 'dev_IRQ_service' 
  2361                              <1> 	; 28/05/2017
  2362                              <1> 
  2363                              <1> 	;push	eax ; * must be saved !
  2364                              <1> 	;push	edx
  2365                              <1> 	;push	ecx
  2366                              <1> 	;push	ebx ; * must be saved !
  2367                              <1> 	;push	esi
  2368                              <1> 	;push	edi
  2369                              <1> 
  2370                              <1> 	;cmp	byte [audio_busy], 1
  2371                              <1> 	;jnb	_ac97_ih2	; busy !
  2372                              <1> 
  2373 000124C2 66BA3000            <1>         mov     dx, GLOB_STS_REG
  2374 000124C6 660315[5A6B0100]    <1>         add	dx, [NABMBAR]
  2375 000124CD ED                  <1> 	in	eax, dx
  2376                              <1> 
  2377 000124CE 83F8FF              <1>         cmp     eax, 0FFFFFFFFh ; -1
  2378 000124D1 0F849A000000        <1>         je      _ac97_ih3 ; exit
  2379                              <1> 
  2380 000124D7 A940000000          <1>         test    eax, 40h ; PCM Out Interrupt
  2381 000124DC 750E                <1>         jnz     short _ac97_ih0
  2382                              <1> 
  2383 000124DE 85C0                <1> 	test	eax, eax
  2384 000124E0 0F848B000000        <1> 	jz	_ac97_ih3 ; exit
  2385                              <1> 
  2386                              <1>  	;mov	dx, GLOB_STS_REG
  2387                              <1>         ;add	dx, [NABMBAR]
  2388 000124E6 EF                  <1> 	out	dx, eax
  2389                              <1> 
  2390 000124E7 E985000000          <1> 	jmp	_ac97_ih3 ; exit
  2391                              <1> 
  2392                              <1> _ac97_ih0:
  2393 000124EC 50                  <1> 	push	eax
  2394                              <1> 	; 09/10/2017
  2395 000124ED 803D[546B0100]01    <1> 	cmp	byte [audio_play_cmd], 1
  2396 000124F4 727C                <1> 	jb	short _ac97_ih4 ; stop command !
  2397                              <1> 
  2398                              <1> 	;mov	byte [audio_busy], 1
  2399                              <1> 
  2400                              <1> 	;mov	al, 10h
  2401                              <1> 	;mov	dx, PO_CR_REG
  2402                              <1>         ;add	dx, [NABMBAR]
  2403                              <1> 	;out	dx, al
  2404                              <1> 
  2405 000124F6 66B81C00            <1> 	mov	ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
  2406 000124FA 66BA1600            <1> 	mov	dx, PO_SR_REG
  2407 000124FE 660315[5A6B0100]    <1>         add	dx, [NABMBAR]
  2408 00012505 66EF                <1> 	out	dx, ax
  2409                              <1> 
  2410 00012507 66BA1400            <1> 	mov	dx, PO_CIV_REG
  2411 0001250B 660315[5A6B0100]    <1>         add	dx, [NABMBAR]
  2412 00012512 EC                  <1> 	in	al, dx
  2413                              <1> 
  2414                              <1> 	;cmp	al, [audio_civ] ; [audio_flag]
  2415                              <1> 	;je	short _ac97_ih2
  2416                              <1> 
  2417 00012513 A2[556B0100]        <1> 	mov	[audio_civ], al
  2418 00012518 FEC8                <1> 	dec	al
  2419                              <1> 	;inc	al ; 11/06/2017
  2420 0001251A 241F                <1> 	and	al, 1Fh
  2421                              <1> 
  2422 0001251C 66BA1500            <1>         mov     dx, PO_LVI_REG
  2423 00012520 660315[5A6B0100]    <1>         add	dx, [NABMBAR]
  2424 00012527 EE                  <1>         out	dx, al
  2425                              <1> 
  2426                              <1> 	; 12/10/2017
  2427 00012528 A0[556B0100]        <1> 	mov	al, [audio_civ]
  2428 0001252D FEC0                <1> 	inc	al
  2429 0001252F 2401                <1> 	and	al, 1
  2430 00012531 A2[486B0100]        <1> 	mov	[audio_flag], al 
  2431                              <1> 	;; [audio_flag] : 0 = Buffer 1, 1 = Buffer 2
  2432                              <1> 	;
  2433 00012536 58                  <1> 	pop	eax
  2434                              <1> 	;
  2435 00012537 83E040              <1> 	and     eax, 40h
  2436 0001253A 668B15[5A6B0100]    <1>         mov	dx, [NABMBAR]
  2437 00012541 6683C230            <1> 	add	dx, GLOB_STS_REG
  2438 00012545 EF                  <1> 	out	dx, eax
  2439                              <1> 
  2440                              <1> 	;; 13/06/2017
  2441                              <1> 	;mov	al, 11h ; IOCE + RPBM
  2442                              <1> 	;mov	dx, PO_CR_REG
  2443                              <1>         ;add	dx, [NABMBAR]
  2444                              <1> 	;out	dx, al
  2445                              <1> 
  2446                              <1> ac97_tuneloop:
  2447                              <1> 	; 09/10/2017
  2448 00012546 8B3D[406B0100]      <1> 	mov	edi, [audio_dma_buff]
  2449 0001254C 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  2450 00012552 D1E9                <1> 	shr	ecx, 1 ; dma buff size / 2 = half buffer size
  2451                              <1> 
  2452                              <1> 	; 12/10/2017
  2453 00012554 803D[486B0100]00    <1> 	cmp 	byte [audio_flag], 0
  2454 0001255B 7702                <1> 	ja	short _ac97_ih1  ; Playing Half Buffer 2 (Current: FLAG)
  2455                              <1> 	; Playing Half Buffer 1 (Current: EOL)	
  2456 0001255D 01CF                <1> 	add	edi, ecx
  2457                              <1> _ac97_ih1: 
  2458                              <1> 	; Update half buffer 2 while playing half buffer 1 (next: FLAG)
  2459                              <1> 	; Update half buffer 1 while playing half buffer 2 (next: EOL)
  2460                              <1> 
  2461 0001255F 8B35[386B0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  2462 00012565 C1E902              <1> 	shr	ecx, 2 ; half buff size / 4
  2463 00012568 F3A5                <1> 	rep	movsd 
  2464                              <1> 
  2465                              <1> 	; 10/10/2017
  2466                              <1> 	; switch flag value
  2467 0001256A 8035[486B0100]01    <1> 	xor	byte [audio_flag], 1
  2468                              <1> 	; 12/10/2017
  2469                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2 (even index value)
  2470                              <1> 			   ; Next buffer (to update) is dma half buff 1
  2471                              <1> 	; 	       = 1 : Playing dma half buffer 1 (odd index value)
  2472                              <1> 			   ; Next buffer (to update) is dma half buff 2
  2473                              <1> 
  2474                              <1> _ac97_ih2:
  2475                              <1> 	;mov	byte [audio_busy], 0
  2476                              <1> _ac97_ih3:
  2477                              <1> 	;pop	edi
  2478                              <1> 	;pop	esi
  2479                              <1> 	;pop	ebx ; * must be restored !
  2480                              <1> 	;pop	ecx
  2481                              <1> 	;pop	edx
  2482                              <1> 	;pop	eax ; * must be restored !
  2483                              <1> 
  2484 00012571 C3                  <1> 	retn
  2485                              <1> 
  2486                              <1> _ac97_ih4:
  2487                              <1> 	; 09/10/2017
  2488 00012572 E818000000          <1> 	call	_ac97_stop
  2489                              <1> 	;
  2490 00012577 58                  <1> 	pop	eax
  2491                              <1> 	;
  2492 00012578 83E040              <1> 	and     eax, 40h
  2493 0001257B 668B15[5A6B0100]    <1>         mov	dx, [NABMBAR]
  2494 00012582 6683C230            <1> 	add	dx, GLOB_STS_REG
  2495 00012586 EF                  <1> 	out	dx, eax
  2496                              <1> 
  2497                              <1> 	;; 13/06/2017
  2498                              <1> 	;mov	al, 11h ; IOCE + RPBM
  2499                              <1> 	;dx, PO_CR_REG
  2500                              <1>         ;add	dx, [NABMBAR]
  2501                              <1> 	;out	dx, al
  2502                              <1> 
  2503                              <1> 	; 10/10/2017
  2504                              <1> 	;jmp	short _ac97_ih3  ; exit
  2505 00012587 C3                  <1> 	retn
  2506                              <1> 
  2507                              <1> ac97_stop: 
  2508                              <1> 	; 28/05/2017
  2509 00012588 C605[546B0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  2510                              <1> _ac97_stop: ; 09/10/2017
  2511                              <1> 	; 29/05/2017
  2512                              <1> 	;mov	dx, [NABMBAR]
  2513                              <1> 	;add	dx, PO_CR_REG
  2514                              <1> 	;mov	al, 0
  2515                              <1> 	;out	dx, al
  2516                              <1> 
  2517                              <1> 	; 11/06/2017
  2518 0001258F 30C0                <1> 	xor	al, al ; 0
  2519 00012591 E813000000          <1> 	call	ac97_po_cmd
  2520                              <1> 
  2521                              <1> 	; (Ref: KolibriOS, intelac97.asm, 'stop:')
  2522                              <1> 	; Clear FIFOE, BCIS, LVBCI (Ref: Intel ICH hub manual)
  2523 00012596 66B81C00            <1> 	mov     ax, 1Ch
  2524 0001259A 668B15[5A6B0100]    <1> 	mov     dx, [NABMBAR]
  2525 000125A1 6683C216            <1> 	add     dx, PO_SR_REG
  2526 000125A5 66EF                <1> 	out     dx, ax
  2527                              <1> 
  2528                              <1> 	;retn
  2529                              <1> 
  2530                              <1> 	; 11/06/2017
  2531 000125A7 B002                <1> 	mov     al, RR
  2532                              <1> ac97_po_cmd:
  2533                              <1> 	 ;11/06/2017
  2534                              <1> 	; 29/05/2017
  2535 000125A9 668B15[5A6B0100]    <1> 	mov     dx, [NABMBAR]
  2536 000125B0 6683C21B            <1>         add     dx, PO_CR_REG		; PCM out control register
  2537 000125B4 EE                  <1> 	out	dx, al
  2538 000125B5 C3                  <1> 	retn
  2539                              <1> 
  2540                              <1> ac97_pause:
  2541                              <1> 	; 11/06/2017
  2542                              <1> 	; 29/05/2017
  2543 000125B6 B010                <1> 	mov 	al, IOCE
  2544 000125B8 EBEF                <1> 	jmp	short ac97_po_cmd
  2545                              <1> 
  2546                              <1> reset_ac97_controller:
  2547                              <1> 	; 10/06/2017
  2548                              <1> 	; 29/05/2017
  2549                              <1> 	; 28/05/2017
  2550                              <1> 	; reset AC97 audio controller registers
  2551 000125BA 31C0                <1> 	xor     eax, eax
  2552 000125BC 66BA0B00            <1>         mov	dx, PI_CR_REG
  2553 000125C0 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2554 000125C7 EE                  <1> 	out     dx, al
  2555                              <1> 
  2556 000125C8 66BA1B00            <1>         mov     dx, PO_CR_REG
  2557 000125CC 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2558 000125D3 EE                  <1> 	out     dx, al
  2559                              <1> 
  2560 000125D4 66BA2B00            <1>         mov     dx, MC_CR_REG
  2561 000125D8 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2562 000125DF EE                  <1> 	out     dx, al
  2563                              <1> 
  2564 000125E0 B002                <1>         mov     al, RR
  2565 000125E2 66BA0B00            <1>         mov     dx, PI_CR_REG
  2566 000125E6 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2567 000125ED EE                  <1> 	out     dx, al
  2568                              <1> 
  2569 000125EE 66BA1B00            <1>         mov     dx, PO_CR_REG
  2570 000125F2 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2571 000125F9 EE                  <1> 	out     dx, al
  2572                              <1> 
  2573 000125FA 66BA2B00            <1>         mov     dx, MC_CR_REG
  2574 000125FE 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2575 00012605 EE                  <1> 	out     dx, al
  2576                              <1> 
  2577 00012606 C3                  <1> 	retn
  2578                              <1> 
  2579                              <1> ac97_reset:
  2580                              <1> 	; 10/06/2017
  2581                              <1> 	; 29/05/2017
  2582                              <1> 	; 28/05/2017
  2583 00012607 E8AEFFFFFF          <1> 	call	reset_ac97_controller
  2584                              <1> 	; 29/05/2017
  2585                              <1> 	;jmp	reset_ac97_codec
  2586                              <1> reset_ac97_codec:
  2587                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  2588 0001260C 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2589 00012610 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2590 00012617 ED                  <1> 	in	eax, dx
  2591                              <1> 
  2592 00012618 A902000000          <1> 	test	eax, 2
  2593 0001261D 7407                <1> 	jz	short _r_ac97codec_cold	
  2594                              <1> 
  2595 0001261F E80F000000          <1> 	call	warm_ac97codec_reset
  2596 00012624 7308                <1> 	jnc	short _r_ac97codec_ok
  2597                              <1> _r_ac97codec_cold:
  2598 00012626 E83D000000          <1>         call    cold_ac97codec_reset
  2599 0001262B 7301                <1>         jnc     short _r_ac97codec_ok
  2600                              <1> 	
  2601                              <1> 	; 16/04/2017
  2602                              <1>         ;xor     eax, eax         ; timeout error
  2603                              <1>        	;stc
  2604 0001262D C3                  <1> 	retn
  2605                              <1> 
  2606                              <1> _r_ac97codec_ok:
  2607 0001262E 31C0                <1>         xor     eax, eax
  2608                              <1>         ;mov	al, VIA_ACLINK_C00_READY ; 1
  2609 00012630 FEC0                <1>         inc	al
  2610 00012632 C3                  <1> 	retn
  2611                              <1> 
  2612                              <1> warm_ac97codec_reset:
  2613                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  2614 00012633 B806000000          <1>         mov     eax, 6
  2615 00012638 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2616 0001263C 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2617 00012643 EF                  <1> 	out	dx, eax
  2618                              <1> 
  2619 00012644 B90A000000          <1> 	mov	ecx, 10	; total 1s
  2620                              <1> _warm_ac97c_rst_wait:
  2621 00012649 51                  <1> 	push	ecx
  2622 0001264A E8EBF5FFFF          <1> 	call	delay_100ms
  2623 0001264F 59                  <1> 	pop	ecx
  2624                              <1> 
  2625 00012650 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  2626 00012654 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2627 0001265B ED                  <1> 	in	eax, dx
  2628                              <1> 
  2629 0001265C A900030010          <1> 	test	eax, CTRL_ST_CREADY
  2630 00012661 7504                <1> 	jnz	short _warm_ac97c_rst_ok
  2631                              <1> 
  2632 00012663 49                  <1>         dec     ecx
  2633 00012664 75E3                <1>         jnz     short _warm_ac97c_rst_wait
  2634                              <1> 
  2635                              <1> _warm_ac97c_rst_fail:
  2636 00012666 F9                  <1>         stc
  2637                              <1> _warm_ac97c_rst_ok:
  2638 00012667 C3                  <1> 	retn
  2639                              <1> 
  2640                              <1> cold_ac97codec_reset:
  2641                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  2642 00012668 B802000000          <1>         mov     eax, 2
  2643 0001266D 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2644 00012671 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2645 00012678 EF                  <1> 	out	dx, eax
  2646                              <1> 
  2647 00012679 E8BCF5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  2648 0001267E E8B7F5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  2649 00012683 E8B2F5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  2650 00012688 E8ADF5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  2651                              <1> 
  2652 0001268D B910000000          <1> 	mov	ecx, 16	; total 20*100 ms = 2s
  2653                              <1> _cold_ac97c_rst_wait:
  2654 00012692 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  2655 00012696 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2656 0001269D ED                  <1> 	in	eax, dx
  2657                              <1> 
  2658 0001269E A900030010          <1> 	test	eax, CTRL_ST_CREADY
  2659 000126A3 750B                <1> 	jnz	short _cold_ac97c_rst_ok
  2660                              <1> 
  2661 000126A5 51                  <1> 	push	ecx
  2662 000126A6 E88FF5FFFF          <1> 	call	delay_100ms
  2663 000126AB 59                  <1> 	pop	ecx
  2664                              <1> 
  2665 000126AC 49                  <1>         dec     ecx
  2666 000126AD 75E3                <1>         jnz     short _cold_ac97c_rst_wait
  2667                              <1> 
  2668                              <1> _cold_ac97c_rst_fail:
  2669 000126AF F9                  <1>         stc
  2670                              <1> _cold_ac97c_rst_ok:
  2671 000126B0 C3                  <1> 	retn
  2672                              <1> 
  2673                              <1> sb16_current_sound_data:
  2674                              <1> 	; 20/08/2017
  2675                              <1> 	; 24/06/2017
  2676                              <1> 	; 22/06/2017
  2677                              <1> 	; get current sound (PCM out) data for graphics
  2678                              <1> 	; (for Sound Blaster 16)
  2679                              <1> 	; ebx = Physical address (on page boundary)
  2680                              <1> 	; ecx = Byte count
  2681                              <1> 	; [audio_buff_size]
  2682                              <1> 
  2683                              <1> 	;;mov	edi, [audio_buff_size]
  2684                              <1> 	;mov	edi, [audio_dmabuff_size]
  2685                              <1> 	;mov	esi, [audio_dma_buff]
  2686 000126B1 39CF                <1> 	cmp	edi, ecx
  2687 000126B3 7302                <1> 	jnb	short sb16_gcd_0
  2688 000126B5 89F9                <1> 	mov	ecx, edi
  2689                              <1> sb16_gcd_0:
  2690                              <1> 	; 20/08/2017
  2691 000126B7 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16
  2692 000126BE 750F                <1> 	jne	short sb16_gcd_1 ; 8 bit DMA channel
  2693 000126C0 E4C6                <1> 	in	al, 0C6h ; DMA channel 5 count register
  2694 000126C2 88C2                <1> 	mov	dl, al	
  2695 000126C4 E4C6                <1> 	in	al, 0C6h
  2696 000126C6 88C6                <1> 	mov     dh, al
  2697 000126C8 0FB7C2              <1> 	movzx	eax, dx
  2698 000126CB D1E0                <1> 	shl	eax, 1 ; word count -> byte count
  2699 000126CD EB4E                <1> 	jmp	short sb16_gcd_2	
  2700                              <1> sb16_gcd_1:
  2701 000126CF E403                <1> 	in	al, 03h ; DMA channel 1 count register
  2702 000126D1 88C2                <1> 	mov	dl, al	
  2703 000126D3 E403                <1> 	in	al, 03h
  2704 000126D5 88C6                <1> 	mov     dh, al
  2705 000126D7 0FB7C2              <1> 	movzx	eax, dx
  2706 000126DA EB41                <1> 	jmp	short sb16_gcd_2
  2707                              <1> ;sb16_gcd_2:	
  2708                              <1> ;	cmp	eax, ecx
  2709                              <1> ;	jnb	short sb16_gcd_3 
  2710                              <1> ;	; remain count < graphics bytes
  2711                              <1> ;	mov	eax, ecx ; fix remain count to data size
  2712                              <1> ;sb16_gcd_3:	
  2713                              <1> ;	sub	edi, eax
  2714                              <1> ;	jna	short sb16_gcd_4
  2715                              <1> ;	add	esi, edi ; dma buffer offset
  2716                              <1> ;sb16_gcd_4:
  2717                              <1> ;	mov	edi, ebx ; buffer address (for graphics) 
  2718                              <1> ;	mov	[u.r0], ecx
  2719                              <1> ;	rep	movsb
  2720                              <1> ;	retn
  2721                              <1> 
  2722                              <1> get_current_sound_data:
  2723                              <1> 	; 24/06/2017
  2724                              <1> 	; 22/06/2017
  2725                              <1> 	; get current sound (PCM out) data for graphics
  2726                              <1> 	;
  2727                              <1> 	; ebx = Physical address (on page boundary)
  2728                              <1> 	; ecx = Byte count
  2729                              <1> 	; [audio_buff_size]
  2730                              <1> 
  2731                              <1> 	;mov	edi, [audio_buff_size]
  2732 000126DC 8B3D[446B0100]      <1> 	mov	edi, [audio_dmabuff_size]
  2733 000126E2 8B35[406B0100]      <1> 	mov	esi, [audio_dma_buff]
  2734 000126E8 803D[216B0100]02    <1> 	cmp	byte [audio_device], 2
  2735 000126EF 72C0                <1> 	jb	short sb16_current_sound_data ; = 1
  2736 000126F1 D1EF                <1> 	shr	edi, 1
  2737 000126F3 39CF                <1> 	cmp	edi, ecx
  2738 000126F5 7302                <1> 	jnb	short gcd_0
  2739 000126F7 89F9                <1> 	mov	ecx, edi
  2740                              <1> gcd_0:
  2741 000126F9 803D[216B0100]03    <1> 	cmp	byte [audio_device], 3
  2742 00012700 7232                <1> 	jb	short ac97_current_sound_data ; = 2
  2743                              <1> 	; = 3
  2744                              <1> vt8233_current_sound_data:
  2745                              <1> 	; 22/06/2017
  2746                              <1> 	; 21/06/2017
  2747                              <1> 	; get current sound (PCM out) data for graphics
  2748                              <1> 	; (for VT 8233, VT 8237R)
  2749                              <1> 	; ebx = Physical address (on page boundary)
  2750                              <1> 	; ecx = Byte count
  2751                              <1> 	; [audio_buff_size]
  2752                              <1> 	
  2753                              <1> 	;;mov	edi, [audio_buff_size]
  2754                              <1> 	;mov	edi, [audio_dmabuff_size]
  2755                              <1> 	;mov	esi, [audio_dma_buff]
  2756                              <1> 	;shr	edi, 1
  2757                              <1> 	;cmp	edi, ecx
  2758                              <1> 	;jnb	short vt8233_gcd_1
  2759                              <1> 	;mov	ecx, edi
  2760                              <1> vt8233_gcd_1:
  2761 00012702 BA0C000000          <1> 	mov	edx, VIA_REG_OFFSET_CURR_COUNT
  2762 00012707 E88EF5FFFF          <1> 	call	ctrl_io_r32
  2763 0001270C 89C2                <1> 	mov	edx, eax ; remain count (bits 23-0),
  2764                              <1> 			 ; SGD index (bits 31-24) 
  2765 0001270E 81E200000001        <1> 	and	edx, 1000000h ; SGD index (0 = 1st half)
  2766 00012714 7402                <1> 	jz	short vt8233_gcd_2
  2767                              <1> 	; the second half of DMA buffer
  2768 00012716 01FE                <1> 	add	esi, edi 
  2769                              <1> vt8233_gcd_2:	
  2770 00012718 25FFFFFF00          <1> 	and	eax, 0FFFFFFh ; bits 23-0
  2771                              <1> ac97_gcd_2:
  2772                              <1> sb16_gcd_2:
  2773 0001271D 39C8                <1> 	cmp	eax, ecx
  2774 0001271F 7302                <1> 	jnb	short vt8233_gcd_3 
  2775                              <1> 	; remain count < graphics bytes
  2776 00012721 89C8                <1> 	mov	eax, ecx ; fix remain count to data size
  2777                              <1> vt8233_gcd_3:
  2778 00012723 29C7                <1> 	sub	edi, eax
  2779 00012725 7602                <1> 	jna	short vt8233_gcd_4
  2780 00012727 01FE                <1> 	add	esi, edi ; dma buffer offset
  2781                              <1> vt8233_gcd_4:
  2782 00012729 89DF                <1> 	mov	edi, ebx ; buffer address (for graphics) 
  2783 0001272B 890D[64030300]      <1> 	mov	[u.r0], ecx
  2784 00012731 F3A4                <1> 	rep	movsb
  2785                              <1> vt8233_gcd_5:
  2786 00012733 C3                  <1> 	retn
  2787                              <1> 
  2788                              <1> ac97_current_sound_data:
  2789                              <1> 	; 23/06/2017
  2790                              <1> 	; 22/06/2017
  2791                              <1> 	; get current sound (PCM out) data for graphics
  2792                              <1> 	; (for AC'97, ICH)
  2793                              <1> 	; ebx = Physical address (on page boundary)
  2794                              <1> 	; ecx = Byte count
  2795                              <1> 	; [audio_buff_size]
  2796                              <1> 	
  2797                              <1> 	;;mov	edi, [audio_buff_size]
  2798                              <1> 	;mov	edi, [audio_dmabuff_size]
  2799                              <1> 	;mov	esi, [audio_dma_buff]
  2800                              <1> 	;shr	edi, 1
  2801                              <1> 	;cmp	edi, ecx
  2802                              <1> 	;jnb	short ac97_gcd_0
  2803                              <1> 	;mov	ecx, edi
  2804                              <1> ac97_gcd_0:
  2805 00012734 66BA1400            <1> 	mov	dx, PO_CIV_REG ; Position In Current Buff Reg
  2806 00012738 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2807 0001273F EC                  <1> 	in	al, dx ; current index value
  2808 00012740 A801                <1> 	test	al, 1
  2809 00012742 7402                <1> 	jz	short ac97_gcd_1
  2810 00012744 01FE                <1> 	add	esi, edi
  2811                              <1> ac97_gcd_1:
  2812 00012746 31C0                <1> 	xor	eax, eax
  2813 00012748 66BA1800            <1> 	mov	dx, PO_PICB_REG ; Position In Current Buff Reg
  2814 0001274C 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2815 00012753 66ED                <1> 	in	ax, dx ; remain dwords
  2816 00012755 C1E002              <1> 	shl	eax, 2 ; remain bytes ; 23/06/2017 
  2817 00012758 EBC3                <1> 	jmp	short ac97_gcd_2
  2818                              <1> ;	cmp	eax, ecx
  2819                              <1> ;	jnb	short ac97_gcd_2 
  2820                              <1> ;	; remain count < graphics bytes
  2821                              <1> ;	mov	eax, ecx ; fix remain count to data size
  2822                              <1> ;ac97_gcd_2:	
  2823                              <1> ;	sub	edi, eax
  2824                              <1> ;	jna	short ac97_gcd_3
  2825                              <1> ;	add	esi, edi ; dma buffer offset
  2826                              <1> ;ac97_gcd_3:
  2827                              <1> ;	mov	edi, ebx ; buffer address (for graphics) 
  2828                              <1> ;	mov	[u.r0], ecx
  2829                              <1> ;	rep	movsb
  2830                              <1> ;	retn
  2831                              <1> 
  2832                              <1> sb16_get_dma_buff_off:
  2833                              <1> 	; 28/10/2017
  2834                              <1> 	; 24/06/2017
  2835                              <1> 	; 22/06/2017
  2836                              <1> 	; get current (PCM OUT DMA buffer) pointer
  2837                              <1> 	; (for Sound Blaster 16)
  2838                              <1> 
  2839                              <1> 	;mov	ecx, [audio_dmabuff_size]
  2840                              <1> 	;xor	ebx, ebx
  2841                              <1> 	;shr	ecx, 1
  2842                              <1> sb16_gdmabo_0:
  2843                              <1> 	; 28/10/2017
  2844 0001275A 803D[506B0100]10    <1> 	cmp	byte [audio_bps], 16
  2845 00012761 750F                <1> 	jne	short sb16_gdmabo_1 ; 8 bit DMA channel
  2846                              <1> 	; 16 bit DMA channel
  2847 00012763 E4C6                <1> 	in	al, 0C6h ; DMA channel 5 count register
  2848 00012765 88C2                <1> 	mov	dl, al	
  2849 00012767 E4C6                <1> 	in	al, 0C6h
  2850 00012769 88C6                <1> 	mov     dh, al
  2851 0001276B 0FB7C2              <1> 	movzx	eax, dx
  2852 0001276E D1E0                <1> 	shl	eax, 1 ; word count -> byte count
  2853 00012770 EB3D                <1> 	jmp	short sb16_gdmabo_2	
  2854                              <1> sb16_gdmabo_1:
  2855 00012772 E403                <1> 	in	al, 03h ; DMA channel 1 count register
  2856 00012774 88C2                <1> 	mov	dl, al	
  2857 00012776 E403                <1> 	in	al, 03h
  2858 00012778 88C6                <1> 	mov     dh, al
  2859 0001277A 0FB7C2              <1> 	movzx	eax, dx
  2860 0001277D EB30                <1> 	jmp	short sb16_gdmabo_2
  2861                              <1> 
  2862                              <1> get_dma_buffer_offset:
  2863                              <1> 	; 24/06/2017
  2864                              <1> 	; 22/06/2017
  2865                              <1> 	; get current sound (PCM out) data for graphics
  2866                              <1> 	;
  2867                              <1> 	; ebx = Physical address (on page boundary)
  2868                              <1> 	; ecx = Byte count
  2869                              <1> 	; [audio_buff_size]
  2870                              <1> 
  2871 0001277F 8B0D[446B0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  2872 00012785 31DB                <1> 	xor	ebx, ebx
  2873                              <1> gdmabo_0:
  2874 00012787 803D[216B0100]02    <1> 	cmp	byte [audio_device], 2
  2875 0001278E 72CA                <1> 	jb	short sb16_get_dma_buff_off
  2876 00012790 742A                <1> 	je	short ac97_get_dma_buff_off
  2877                              <1> 
  2878                              <1> vt8233_get_dma_buff_off:
  2879                              <1> 	; 24/06/2017
  2880                              <1> 	; 22/06/2017
  2881                              <1> 	; get current (PCM OUT DMA buffer) pointer
  2882                              <1> 	; (for VT 8233, VT 8237R)
  2883                              <1> 	
  2884                              <1> 	;mov	ecx, [audio_dmabuff_size]
  2885                              <1> 	;xor	ebx, ebx
  2886 00012792 D1E9                <1> 	shr	ecx, 1
  2887                              <1> vt8233_gdmabo_0:
  2888 00012794 BA0C000000          <1> 	mov	edx, VIA_REG_OFFSET_CURR_COUNT
  2889 00012799 E8FCF4FFFF          <1> 	call	ctrl_io_r32
  2890 0001279E 89C2                <1> 	mov	edx, eax ; remain count (bits 23-0),
  2891                              <1> 			 ; SGD index (bits 31-24) 
  2892 000127A0 81E200000001        <1> 	and	edx, 1000000h ; SGD index (0 = 1st half)
  2893 000127A6 7402                <1> 	jz	short vt8233_gdmabo_1
  2894                              <1> 	; the second half of DMA buffer
  2895 000127A8 89CB                <1> 	mov	ebx, ecx 
  2896                              <1> vt8233_gdmabo_1:	
  2897 000127AA 25FFFFFF00          <1> 	and	eax, 0FFFFFFh ; bits 23-0
  2898                              <1> sb16_gdmabo_2:
  2899                              <1> ac97_gdmabo_2:
  2900 000127AF 29C1                <1> 	sub	ecx, eax
  2901 000127B1 7602                <1> 	jna	short vt8233_gdmabo_2
  2902 000127B3 01CB                <1> 	add	ebx, ecx ; dma buffer offset
  2903                              <1> vt8233_gdmabo_2:
  2904 000127B5 891D[64030300]      <1> 	mov	[u.r0], ebx
  2905 000127BB C3                  <1> 	retn
  2906                              <1> 
  2907                              <1> ac97_get_dma_buff_off:
  2908                              <1> 	; 24/06/2017
  2909                              <1> 	; 22/06/2017
  2910                              <1> 	; get current (PCM OUT DMA buffer) pointer
  2911                              <1> 	; (for AC'97, ICH)
  2912                              <1> 	; ebx = Physical address (on page boundary)
  2913                              <1> 	; ecx = Byte count
  2914                              <1> 	; [audio_buff_size]
  2915                              <1> 	
  2916                              <1> 	;mov	ecx, [audio_dmabuff_size]
  2917                              <1> 	;xor	ebx, ebx
  2918 000127BC D1E9                <1> 	shr	ecx, 1
  2919                              <1> ac97_gdmabo_0:
  2920 000127BE 66BA1400            <1> 	mov	dx, PO_CIV_REG ; Position In Current Buff Reg
  2921 000127C2 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2922 000127C9 EC                  <1> 	in	al, dx ; current index value
  2923 000127CA A801                <1> 	test	al, 1
  2924 000127CC 7402                <1> 	jz	short ac97_gdmabo_1
  2925 000127CE 89CB                <1> 	mov	ebx, ecx
  2926                              <1> ac97_gdmabo_1:
  2927 000127D0 31C0                <1> 	xor	eax, eax
  2928 000127D2 66BA1800            <1> 	mov	dx, PO_PICB_REG ; Position In Current Buff Reg
  2929 000127D6 660315[5A6B0100]    <1> 	add	dx, [NABMBAR]
  2930 000127DD 66ED                <1> 	in	ax, dx ; remain dwords
  2931 000127DF EBCE                <1> 	jmp	short ac97_gdmabo_2
  2642                                  
  2643 000127E1 90<rept>                align 4
  2644                                  
  2645                                  %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 000127E4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    28 000127ED 00000000000000      <1>
    29 000127F4 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    29 000127FD 2A2A2A2A2A2A2A      <1>
    30 00012804 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    30 0001280D 2A2A2A2A2A2A2A      <1>
    31 00012814 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    31 0001281D 2A2A2A2A2A2A2A      <1>
    32 00012824 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    32 0001282D 3F3F3F3F3F3F3F      <1>
    33 00012834 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    33 0001283D 3F3F3F3F3F3F3F      <1>
    34 00012844 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    34 0001284D 00000000000000      <1>
    35 00012854 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    35 0001285D 2A2A2A2A2A2A2A      <1>
    36 00012864 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    36 0001286D 2A2A2A2A2A2A2A      <1>
    37 00012874 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    37 0001287D 2A2A2A2A2A2A2A      <1>
    38 00012884 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    38 0001288D 3F3F3F3F3F3F3F      <1>
    39 00012894 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    39 0001289D 3F3F3F3F3F3F3F      <1>
    40                              <1> palette1:
    41 000128A4 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    41 000128AD 002A2A2A00002A      <1>
    42 000128B4 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    42 000128BD 000000002A002A      <1>
    43 000128C4 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    43 000128CD 2A2A15002A2A2A      <1>
    44 000128D4 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    44 000128DD 153F3F3F15153F      <1>
    45 000128E4 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    45 000128ED 151515153F153F      <1>
    46 000128F4 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    46 000128FD 3F3F3F153F3F3F      <1>
    47 00012904 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    47 0001290D 002A2A2A00002A      <1>
    48 00012914 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    48 0001291D 000000002A002A      <1>
    49 00012924 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    49 0001292D 2A2A15002A2A2A      <1>
    50 00012934 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    50 0001293D 153F3F3F15153F      <1>
    51 00012944 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    51 0001294D 151515153F153F      <1>
    52 00012954 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    52 0001295D 3F3F3F153F3F3F      <1>
    53                              <1> palette2:
    54 00012964 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    54 0001296D 002A2A2A00002A      <1>
    55 00012974 002A2A2A002A2A2A00- <1>     db  000h, 02ah, 02ah, 02ah, 000h, 02ah, 02ah, 02ah, 000h, 000h, 015h, 000h, 000h, 03fh, 000h, 02ah
    55 0001297D 001500003F002A      <1>
    56 00012984 15002A3F2A00152A00- <1>     db  015h, 000h, 02ah, 03fh, 02ah, 000h, 015h, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 02ah, 02ah, 03fh
    56 0001298D 3F2A2A152A2A3F      <1>
    57 00012994 00150000152A003F00- <1>     db  000h, 015h, 000h, 000h, 015h, 02ah, 000h, 03fh, 000h, 000h, 03fh, 02ah, 02ah, 015h, 000h, 02ah
    57 0001299D 003F2A2A15002A      <1>
    58 000129A4 152A2A3F002A3F2A00- <1>     db  015h, 02ah, 02ah, 03fh, 000h, 02ah, 03fh, 02ah, 000h, 015h, 015h, 000h, 015h, 03fh, 000h, 03fh
    58 000129AD 151500153F003F      <1>
    59 000129B4 15003F3F2A15152A15- <1>     db  015h, 000h, 03fh, 03fh, 02ah, 015h, 015h, 02ah, 015h, 03fh, 02ah, 03fh, 015h, 02ah, 03fh, 03fh
    59 000129BD 3F2A3F152A3F3F      <1>
    60 000129C4 15000015002A152A00- <1>     db  015h, 000h, 000h, 015h, 000h, 02ah, 015h, 02ah, 000h, 015h, 02ah, 02ah, 03fh, 000h, 000h, 03fh
    60 000129CD 152A2A3F00003F      <1>
    61 000129D4 002A3F2A003F2A2A15- <1>     db  000h, 02ah, 03fh, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 000h, 015h, 015h, 000h, 03fh, 015h, 02ah
    61 000129DD 001515003F152A      <1>
    62 000129E4 15152A3F3F00153F00- <1>     db  015h, 015h, 02ah, 03fh, 03fh, 000h, 015h, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 03fh, 02ah, 03fh
    62 000129ED 3F3F2A153F2A3F      <1>
    63 000129F4 15150015152A153F00- <1>     db  015h, 015h, 000h, 015h, 015h, 02ah, 015h, 03fh, 000h, 015h, 03fh, 02ah, 03fh, 015h, 000h, 03fh
    63 000129FD 153F2A3F15003F      <1>
    64 00012A04 152A3F3F003F3F2A15- <1>     db  015h, 02ah, 03fh, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    64 00012A0D 151515153F153F      <1>
    65 00012A14 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    65 00012A1D 3F3F3F153F3F3F      <1>
    66                              <1> palette3:
    67 00012A24 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    67 00012A2D 002A2A2A00002A      <1>
    68 00012A34 002A2A15002A2A2A15- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    68 00012A3D 151515153F153F      <1>
    69 00012A44 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    69 00012A4D 3F3F3F153F3F3F      <1>
    70 00012A54 000000050505080808- <1>     db  000h, 000h, 000h, 005h, 005h, 005h, 008h, 008h, 008h, 00bh, 00bh, 00bh, 00eh, 00eh, 00eh, 011h
    70 00012A5D 0B0B0B0E0E0E11      <1>
    71 00012A64 11111414141818181C- <1>     db  011h, 011h, 014h, 014h, 014h, 018h, 018h, 018h, 01ch, 01ch, 01ch, 020h, 020h, 020h, 024h, 024h
    71 00012A6D 1C1C2020202424      <1>
    72 00012A74 242828282D2D2D3232- <1>     db  024h, 028h, 028h, 028h, 02dh, 02dh, 02dh, 032h, 032h, 032h, 038h, 038h, 038h, 03fh, 03fh, 03fh
    72 00012A7D 323838383F3F3F      <1>
    73 00012A84 00003F10003F1F003F- <1>     db  000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 03fh, 03fh
    73 00012A8D 2F003F3F003F3F      <1>
    74 00012A94 002F3F001F3F00103F- <1>     db  000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh
    74 00012A9D 00003F10003F1F      <1>
    75 00012AA4 003F2F003F3F002F3F- <1>     db  000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h
    75 00012AAD 001F3F00103F00      <1>
    76 00012AB4 003F00003F10003F1F- <1>     db  000h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h
    76 00012ABD 003F2F003F3F00      <1>
    77 00012AC4 2F3F001F3F00103F1F- <1>     db  02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh
    77 00012ACD 1F3F271F3F2F1F      <1>
    78 00012AD4 3F371F3F3F1F3F3F1F- <1>     db  03fh, 037h, 01fh, 03fh, 03fh, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h
    78 00012ADD 373F1F2F3F1F27      <1>
    79 00012AE4 3F1F1F3F271F3F2F1F- <1>     db  03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h
    79 00012AED 3F371F3F3F1F37      <1>
    80 00012AF4 3F1F2F3F1F273F1F1F- <1>     db  03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh, 01fh, 01fh, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh
    80 00012AFD 3F1F1F3F271F3F      <1>
    81 00012B04 2F1F3F371F3F3F1F37- <1>     db  02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh
    81 00012B0D 3F1F2F3F1F273F      <1>
    82 00012B14 2D2D3F312D3F362D3F- <1>     db  02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03fh, 03fh
    82 00012B1D 3A2D3F3F2D3F3F      <1>
    83 00012B24 2D3A3F2D363F2D313F- <1>     db  02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h
    83 00012B2D 2D2D3F312D3F36      <1>
    84 00012B34 2D3F3A2D3F3F2D3A3F- <1>     db  02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh
    84 00012B3D 2D363F2D313F2D      <1>
    85 00012B44 2D3F2D2D3F312D3F36- <1>     db  02dh, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh
    85 00012B4D 2D3F3A2D3F3F2D      <1>
    86 00012B54 3A3F2D363F2D313F00- <1>     db  03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h
    86 00012B5D 001C07001C0E00      <1>
    87 00012B64 1C15001C1C001C1C00- <1>     db  01ch, 015h, 000h, 01ch, 01ch, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h
    87 00012B6D 151C000E1C0007      <1>
    88 00012B74 1C00001C07001C0E00- <1>     db  01ch, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h
    88 00012B7D 1C15001C1C0015      <1>
    89 00012B84 1C000E1C00071C0000- <1>     db  01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch, 000h, 000h, 01ch, 000h, 000h, 01ch, 007h, 000h, 01ch
    89 00012B8D 1C00001C07001C      <1>
    90 00012B94 0E001C15001C1C0015- <1>     db  00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch
    90 00012B9D 1C000E1C00071C      <1>
    91 00012BA4 0E0E1C110E1C150E1C- <1>     db  00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 01ch, 01ch
    91 00012BAD 180E1C1C0E1C1C      <1>
    92 00012BB4 0E181C0E151C0E111C- <1>     db  00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h
    92 00012BBD 0E0E1C110E1C15      <1>
    93 00012BC4 0E1C180E1C1C0E181C- <1>     db  00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh
    93 00012BCD 0E151C0E111C0E      <1>
    94 00012BD4 0E1C0E0E1C110E1C15- <1>     db  00eh, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh
    94 00012BDD 0E1C180E1C1C0E      <1>
    95 00012BE4 181C0E151C0E111C14- <1>     db  018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h
    95 00012BED 141C16141C1814      <1>
    96 00012BF4 1C1A141C1C141C1C14- <1>     db  01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h
    96 00012BFD 1A1C14181C1416      <1>
    97 00012C04 1C14141C16141C1814- <1>     db  01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah
    97 00012C0D 1C1A141C1C141A      <1>
    98 00012C14 1C14181C14161C1414- <1>     db  01ch, 014h, 018h, 01ch, 014h, 016h, 01ch, 014h, 014h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch
    98 00012C1D 1C14141C16141C      <1>
    99 00012C24 18141C1A141C1C141A- <1>     db  018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h, 01ch
    99 00012C2D 1C14181C14161C      <1>
   100 00012C34 000010040010080010- <1>     db  000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h, 010h, 010h
   100 00012C3D 0C001010001010      <1>
   101 00012C44 000C10000810000410- <1>     db  000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h
   101 00012C4D 00001004001008      <1>
   102 00012C54 00100C001010000C10- <1>     db  000h, 010h, 00ch, 000h, 010h, 010h, 000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h
   102 00012C5D 00081000041000      <1>
   103 00012C64 001000001004001008- <1>     db  000h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h
   103 00012C6D 00100C00101000      <1>
   104 00012C74 0C1000081000041008- <1>     db  00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h
   104 00012C7D 08100A08100C08      <1>
   105 00012C84 100E08101008101008- <1>     db  010h, 00eh, 008h, 010h, 010h, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah
   105 00012C8D 0E10080C10080A      <1>
   106 00012C94 100808100A08100C08- <1>     db  010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh
   106 00012C9D 100E081010080E      <1>
   107 00012CA4 10080C10080A100808- <1>     db  010h, 008h, 00ch, 010h, 008h, 00ah, 010h, 008h, 008h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h
   107 00012CAD 100808100A0810      <1>
   108 00012CB4 0C08100E081010080E- <1>     db  00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah, 010h
   108 00012CBD 10080C10080A10      <1>
   109 00012CC4 0B0B100C0B100D0B10- <1>     db  00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 010h, 010h
   109 00012CCD 0F0B10100B1010      <1>
   110 00012CD4 0B0F100B0D100B0C10- <1>     db  00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh
   110 00012CDD 0B0B100C0B100D      <1>
   111 00012CE4 0B100F0B10100B0F10- <1>     db  00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh
   111 00012CED 0B0D100B0C100B      <1>
   112 00012CF4 0B100B0B100C0B100D- <1>     db  00bh, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh
   112 00012CFD 0B100F0B10100B      <1>
   113 00012D04 0F100B0D100B0C1000- <1>     db  00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   113 00012D0D 00000000000000      <1>
   114 00012D14 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   114 00012D1D 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 00012D24 00000000000000007E- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 081h, 0a5h, 081h, 0bdh, 099h, 081h, 07eh
   122 00012D2D 81A581BD99817E      <1>
   123 00012D34 7EFFDBFFC3E7FF7E6C- <1>     db  07eh, 0ffh, 0dbh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 06ch, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h
   123 00012D3D FEFEFE7C381000      <1>
   124 00012D44 10387CFE7C38100038- <1>     db  010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 038h, 07ch, 038h, 0feh, 0feh, 07ch, 038h, 07ch
   124 00012D4D 7C38FEFE7C387C      <1>
   125 00012D54 1010387CFE7C387C00- <1>     db  010h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 07ch, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h
   125 00012D5D 00183C3C180000      <1>
   126 00012D64 FFFFE7C3C3E7FFFF00- <1>     db  0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h
   126 00012D6D 3C664242663C00      <1>
   127 00012D74 FFC399BDBD99C3FF0F- <1>     db  0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 00fh, 007h, 00fh, 07dh, 0cch, 0cch, 0cch, 078h
   127 00012D7D 070F7DCCCCCC78      <1>
   128 00012D84 3C6666663C187E183F- <1>     db  03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 03fh, 033h, 03fh, 030h, 030h, 070h, 0f0h, 0e0h
   128 00012D8D 333F303070F0E0      <1>
   129 00012D94 7F637F636367E6C099- <1>     db  07fh, 063h, 07fh, 063h, 063h, 067h, 0e6h, 0c0h, 099h, 05ah, 03ch, 0e7h, 0e7h, 03ch, 05ah, 099h
   129 00012D9D 5A3CE7E73C5A99      <1>
   130 00012DA4 80E0F8FEF8E0800002- <1>     db  080h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 080h, 000h, 002h, 00eh, 03eh, 0feh, 03eh, 00eh, 002h, 000h
   130 00012DAD 0E3EFE3E0E0200      <1>
   131 00012DB4 183C7E18187E3C1866- <1>     db  018h, 03ch, 07eh, 018h, 018h, 07eh, 03ch, 018h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 000h
   131 00012DBD 66666666006600      <1>
   132 00012DC4 7FDBDB7B1B1B1B003E- <1>     db  07fh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 000h, 03eh, 063h, 038h, 06ch, 06ch, 038h, 0cch, 078h
   132 00012DCD 63386C6C38CC78      <1>
   133 00012DD4 000000007E7E7E0018- <1>     db  000h, 000h, 000h, 000h, 07eh, 07eh, 07eh, 000h, 018h, 03ch, 07eh, 018h, 07eh, 03ch, 018h, 0ffh
   133 00012DDD 3C7E187E3C18FF      <1>
   134 00012DE4 183C7E181818180018- <1>     db  018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h
   134 00012DED 1818187E3C1800      <1>
   135 00012DF4 00180CFE0C18000000- <1>     db  000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h
   135 00012DFD 3060FE60300000      <1>
   136 00012E04 0000C0C0C0FE000000- <1>     db  000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h
   136 00012E0D 2466FF66240000      <1>
   137 00012E14 00183C7EFFFF000000- <1>     db  000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 000h, 000h, 000h, 0ffh, 0ffh, 07eh, 03ch, 018h, 000h, 000h
   137 00012E1D FFFF7E3C180000      <1>
   138 00012E24 000000000000000030- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 078h, 078h, 030h, 030h, 000h, 030h, 000h
   138 00012E2D 78783030003000      <1>
   139 00012E34 6C6C6C00000000006C- <1>     db  06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 0feh, 06ch, 06ch, 000h
   139 00012E3D 6CFE6CFE6C6C00      <1>
   140 00012E44 307CC0780CF8300000- <1>     db  030h, 07ch, 0c0h, 078h, 00ch, 0f8h, 030h, 000h, 000h, 0c6h, 0cch, 018h, 030h, 066h, 0c6h, 000h
   140 00012E4D C6CC183066C600      <1>
   141 00012E54 386C3876DCCC760060- <1>     db  038h, 06ch, 038h, 076h, 0dch, 0cch, 076h, 000h, 060h, 060h, 0c0h, 000h, 000h, 000h, 000h, 000h
   141 00012E5D 60C00000000000      <1>
   142 00012E64 183060606030180060- <1>     db  018h, 030h, 060h, 060h, 060h, 030h, 018h, 000h, 060h, 030h, 018h, 018h, 018h, 030h, 060h, 000h
   142 00012E6D 30181818306000      <1>
   143 00012E74 00663CFF3C66000000- <1>     db  000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 000h
   143 00012E7D 3030FC30300000      <1>
   144 00012E84 000000000030306000- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 060h, 000h, 000h, 000h, 0fch, 000h, 000h, 000h, 000h
   144 00012E8D 0000FC00000000      <1>
   145 00012E94 000000000030300006- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 000h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h
   145 00012E9D 0C183060C08000      <1>
   146 00012EA4 7CC6CEDEF6E67C0030- <1>     db  07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 07ch, 000h, 030h, 070h, 030h, 030h, 030h, 030h, 0fch, 000h
   146 00012EAD 7030303030FC00      <1>
   147 00012EB4 78CC0C3860CCFC0078- <1>     db  078h, 0cch, 00ch, 038h, 060h, 0cch, 0fch, 000h, 078h, 0cch, 00ch, 038h, 00ch, 0cch, 078h, 000h
   147 00012EBD CC0C380CCC7800      <1>
   148 00012EC4 1C3C6CCCFE0C1E00FC- <1>     db  01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 01eh, 000h, 0fch, 0c0h, 0f8h, 00ch, 00ch, 0cch, 078h, 000h
   148 00012ECD C0F80C0CCC7800      <1>
   149 00012ED4 3860C0F8CCCC7800FC- <1>     db  038h, 060h, 0c0h, 0f8h, 0cch, 0cch, 078h, 000h, 0fch, 0cch, 00ch, 018h, 030h, 030h, 030h, 000h
   149 00012EDD CC0C1830303000      <1>
   150 00012EE4 78CCCC78CCCC780078- <1>     db  078h, 0cch, 0cch, 078h, 0cch, 0cch, 078h, 000h, 078h, 0cch, 0cch, 07ch, 00ch, 018h, 070h, 000h
   150 00012EED CCCC7C0C187000      <1>
   151 00012EF4 003030000030300000- <1>     db  000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 060h
   151 00012EFD 30300000303060      <1>
   152 00012F04 183060C06030180000- <1>     db  018h, 030h, 060h, 0c0h, 060h, 030h, 018h, 000h, 000h, 000h, 0fch, 000h, 000h, 0fch, 000h, 000h
   152 00012F0D 00FC0000FC0000      <1>
   153 00012F14 6030180C1830600078- <1>     db  060h, 030h, 018h, 00ch, 018h, 030h, 060h, 000h, 078h, 0cch, 00ch, 018h, 030h, 000h, 030h, 000h
   153 00012F1D CC0C1830003000      <1>
   154 00012F24 7CC6DEDEDEC0780030- <1>     db  07ch, 0c6h, 0deh, 0deh, 0deh, 0c0h, 078h, 000h, 030h, 078h, 0cch, 0cch, 0fch, 0cch, 0cch, 000h
   154 00012F2D 78CCCCFCCCCC00      <1>
   155 00012F34 FC66667C6666FC003C- <1>     db  0fch, 066h, 066h, 07ch, 066h, 066h, 0fch, 000h, 03ch, 066h, 0c0h, 0c0h, 0c0h, 066h, 03ch, 000h
   155 00012F3D 66C0C0C0663C00      <1>
   156 00012F44 F86C6666666CF800FE- <1>     db  0f8h, 06ch, 066h, 066h, 066h, 06ch, 0f8h, 000h, 0feh, 062h, 068h, 078h, 068h, 062h, 0feh, 000h
   156 00012F4D 6268786862FE00      <1>
   157 00012F54 FE6268786860F0003C- <1>     db  0feh, 062h, 068h, 078h, 068h, 060h, 0f0h, 000h, 03ch, 066h, 0c0h, 0c0h, 0ceh, 066h, 03eh, 000h
   157 00012F5D 66C0C0CE663E00      <1>
   158 00012F64 CCCCCCFCCCCCCC0078- <1>     db  0cch, 0cch, 0cch, 0fch, 0cch, 0cch, 0cch, 000h, 078h, 030h, 030h, 030h, 030h, 030h, 078h, 000h
   158 00012F6D 30303030307800      <1>
   159 00012F74 1E0C0C0CCCCC7800E6- <1>     db  01eh, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 0e6h, 066h, 06ch, 078h, 06ch, 066h, 0e6h, 000h
   159 00012F7D 666C786C66E600      <1>
   160 00012F84 F06060606266FE00C6- <1>     db  0f0h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 000h
   160 00012F8D EEFEFED6C6C600      <1>
   161 00012F94 C6E6F6DECEC6C60038- <1>     db  0c6h, 0e6h, 0f6h, 0deh, 0ceh, 0c6h, 0c6h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h
   161 00012F9D 6CC6C6C66C3800      <1>
   162 00012FA4 FC66667C6060F00078- <1>     db  0fch, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 078h, 0cch, 0cch, 0cch, 0dch, 078h, 01ch, 000h
   162 00012FAD CCCCCCDC781C00      <1>
   163 00012FB4 FC66667C6C66E60078- <1>     db  0fch, 066h, 066h, 07ch, 06ch, 066h, 0e6h, 000h, 078h, 0cch, 0e0h, 070h, 01ch, 0cch, 078h, 000h
   163 00012FBD CCE0701CCC7800      <1>
   164 00012FC4 FCB4303030307800CC- <1>     db  0fch, 0b4h, 030h, 030h, 030h, 030h, 078h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 0fch, 000h
   164 00012FCD CCCCCCCCCCFC00      <1>
   165 00012FD4 CCCCCCCCCC783000C6- <1>     db  0cch, 0cch, 0cch, 0cch, 0cch, 078h, 030h, 000h, 0c6h, 0c6h, 0c6h, 0d6h, 0feh, 0eeh, 0c6h, 000h
   165 00012FDD C6C6D6FEEEC600      <1>
   166 00012FE4 C6C66C38386CC600CC- <1>     db  0c6h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 030h, 078h, 000h
   166 00012FED CCCC7830307800      <1>
   167 00012FF4 FEC68C183266FE0078- <1>     db  0feh, 0c6h, 08ch, 018h, 032h, 066h, 0feh, 000h, 078h, 060h, 060h, 060h, 060h, 060h, 078h, 000h
   167 00012FFD 60606060607800      <1>
   168 00013004 C06030180C06020078- <1>     db  0c0h, 060h, 030h, 018h, 00ch, 006h, 002h, 000h, 078h, 018h, 018h, 018h, 018h, 018h, 078h, 000h
   168 0001300D 18181818187800      <1>
   169 00013014 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   169 0001301D 000000000000FF      <1>
   170 00013024 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 076h, 000h
   170 0001302D 00780C7CCC7600      <1>
   171 00013034 E060607C6666DC0000- <1>     db  0e0h, 060h, 060h, 07ch, 066h, 066h, 0dch, 000h, 000h, 000h, 078h, 0cch, 0c0h, 0cch, 078h, 000h
   171 0001303D 0078CCC0CC7800      <1>
   172 00013044 1C0C0C7CCCCC760000- <1>     db  01ch, 00ch, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   172 0001304D 0078CCFCC07800      <1>
   173 00013054 386C60F06060F00000- <1>     db  038h, 06ch, 060h, 0f0h, 060h, 060h, 0f0h, 000h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 0f8h
   173 0001305D 0076CCCC7C0CF8      <1>
   174 00013064 E0606C766666E60030- <1>     db  0e0h, 060h, 06ch, 076h, 066h, 066h, 0e6h, 000h, 030h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   174 0001306D 00703030307800      <1>
   175 00013074 0C000C0C0CCCCC78E0- <1>     db  00ch, 000h, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 0e0h, 060h, 066h, 06ch, 078h, 06ch, 0e6h, 000h
   175 0001307D 60666C786CE600      <1>
   176 00013084 703030303030780000- <1>     db  070h, 030h, 030h, 030h, 030h, 030h, 078h, 000h, 000h, 000h, 0cch, 0feh, 0feh, 0d6h, 0c6h, 000h
   176 0001308D 00CCFEFED6C600      <1>
   177 00013094 0000F8CCCCCCCC0000- <1>     db  000h, 000h, 0f8h, 0cch, 0cch, 0cch, 0cch, 000h, 000h, 000h, 078h, 0cch, 0cch, 0cch, 078h, 000h
   177 0001309D 0078CCCCCC7800      <1>
   178 000130A4 0000DC66667C60F000- <1>     db  000h, 000h, 0dch, 066h, 066h, 07ch, 060h, 0f0h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 01eh
   178 000130AD 0076CCCC7C0C1E      <1>
   179 000130B4 0000DC766660F00000- <1>     db  000h, 000h, 0dch, 076h, 066h, 060h, 0f0h, 000h, 000h, 000h, 07ch, 0c0h, 078h, 00ch, 0f8h, 000h
   179 000130BD 007CC0780CF800      <1>
   180 000130C4 10307C303034180000- <1>     db  010h, 030h, 07ch, 030h, 030h, 034h, 018h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   180 000130CD 00CCCCCCCC7600      <1>
   181 000130D4 0000CCCCCC78300000- <1>     db  000h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 000h, 000h, 000h, 0c6h, 0d6h, 0feh, 0feh, 06ch, 000h
   181 000130DD 00C6D6FEFE6C00      <1>
   182 000130E4 0000C66C386CC60000- <1>     db  000h, 000h, 0c6h, 06ch, 038h, 06ch, 0c6h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 07ch, 00ch, 0f8h
   182 000130ED 00CCCCCC7C0CF8      <1>
   183 000130F4 0000FC983064FC001C- <1>     db  000h, 000h, 0fch, 098h, 030h, 064h, 0fch, 000h, 01ch, 030h, 030h, 0e0h, 030h, 030h, 01ch, 000h
   183 000130FD 3030E030301C00      <1>
   184 00013104 1818180018181800E0- <1>     db  018h, 018h, 018h, 000h, 018h, 018h, 018h, 000h, 0e0h, 030h, 030h, 01ch, 030h, 030h, 0e0h, 000h
   184 0001310D 30301C3030E000      <1>
   185 00013114 76DC00000000000000- <1>     db  076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h
   185 0001311D 10386CC6C6FE00      <1>
   186 00013124 78CCC0CC78180C7800- <1>     db  078h, 0cch, 0c0h, 0cch, 078h, 018h, 00ch, 078h, 000h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   186 0001312D CC00CCCCCC7E00      <1>
   187 00013134 1C0078CCFCC078007E- <1>     db  01ch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 07eh, 0c3h, 03ch, 006h, 03eh, 066h, 03fh, 000h
   187 0001313D C33C063E663F00      <1>
   188 00013144 CC00780C7CCC7E00E0- <1>     db  0cch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 0e0h, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h
   188 0001314D 00780C7CCC7E00      <1>
   189 00013154 3030780C7CCC7E0000- <1>     db  030h, 030h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 000h, 000h, 078h, 0c0h, 0c0h, 078h, 00ch, 038h
   189 0001315D 0078C0C0780C38      <1>
   190 00013164 7EC33C667E603C00CC- <1>     db  07eh, 0c3h, 03ch, 066h, 07eh, 060h, 03ch, 000h, 0cch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   190 0001316D 0078CCFCC07800      <1>
   191 00013174 E00078CCFCC07800CC- <1>     db  0e0h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 0cch, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   191 0001317D 00703030307800      <1>
   192 00013184 7CC6381818183C00E0- <1>     db  07ch, 0c6h, 038h, 018h, 018h, 018h, 03ch, 000h, 0e0h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   192 0001318D 00703030307800      <1>
   193 00013194 C6386CC6FEC6C60030- <1>     db  0c6h, 038h, 06ch, 0c6h, 0feh, 0c6h, 0c6h, 000h, 030h, 030h, 000h, 078h, 0cch, 0fch, 0cch, 000h
   193 0001319D 300078CCFCCC00      <1>
   194 000131A4 1C00FC607860FC0000- <1>     db  01ch, 000h, 0fch, 060h, 078h, 060h, 0fch, 000h, 000h, 000h, 07fh, 00ch, 07fh, 0cch, 07fh, 000h
   194 000131AD 007F0C7FCC7F00      <1>
   195 000131B4 3E6CCCFECCCCCE0078- <1>     db  03eh, 06ch, 0cch, 0feh, 0cch, 0cch, 0ceh, 000h, 078h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h
   195 000131BD CC0078CCCC7800      <1>
   196 000131C4 00CC0078CCCC780000- <1>     db  000h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 0e0h, 000h, 078h, 0cch, 0cch, 078h, 000h
   196 000131CD E00078CCCC7800      <1>
   197 000131D4 78CC00CCCCCC7E0000- <1>     db  078h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h, 000h, 0e0h, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   197 000131DD E000CCCCCC7E00      <1>
   198 000131E4 00CC00CCCC7C0CF8C3- <1>     db  000h, 0cch, 000h, 0cch, 0cch, 07ch, 00ch, 0f8h, 0c3h, 018h, 03ch, 066h, 066h, 03ch, 018h, 000h
   198 000131ED 183C66663C1800      <1>
   199 000131F4 CC00CCCCCCCC780018- <1>     db  0cch, 000h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 018h, 018h, 07eh, 0c0h, 0c0h, 07eh, 018h, 018h
   199 000131FD 187EC0C07E1818      <1>
   200 00013204 386C64F060E6FC00CC- <1>     db  038h, 06ch, 064h, 0f0h, 060h, 0e6h, 0fch, 000h, 0cch, 0cch, 078h, 0fch, 030h, 0fch, 030h, 030h
   200 0001320D CC78FC30FC3030      <1>
   201 00013214 F8CCCCFAC6CFC6C70E- <1>     db  0f8h, 0cch, 0cch, 0fah, 0c6h, 0cfh, 0c6h, 0c7h, 00eh, 01bh, 018h, 03ch, 018h, 018h, 0d8h, 070h
   201 0001321D 1B183C1818D870      <1>
   202 00013224 1C00780C7CCC7E0038- <1>     db  01ch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 038h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   202 0001322D 00703030307800      <1>
   203 00013234 001C0078CCCC780000- <1>     db  000h, 01ch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 01ch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   203 0001323D 1C00CCCCCC7E00      <1>
   204 00013244 00F800F8CCCCCC00FC- <1>     db  000h, 0f8h, 000h, 0f8h, 0cch, 0cch, 0cch, 000h, 0fch, 000h, 0cch, 0ech, 0fch, 0dch, 0cch, 000h
   204 0001324D 00CCECFCDCCC00      <1>
   205 00013254 3C6C6C3E007E000038- <1>     db  03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h
   205 0001325D 6C6C38007C0000      <1>
   206 00013264 30003060C0CC780000- <1>     db  030h, 000h, 030h, 060h, 0c0h, 0cch, 078h, 000h, 000h, 000h, 000h, 0fch, 0c0h, 0c0h, 000h, 000h
   206 0001326D 0000FCC0C00000      <1>
   207 00013274 000000FC0C0C0000C3- <1>     db  000h, 000h, 000h, 0fch, 00ch, 00ch, 000h, 000h, 0c3h, 0c6h, 0cch, 0deh, 033h, 066h, 0cch, 00fh
   207 0001327D C6CCDE3366CC0F      <1>
   208 00013284 C3C6CCDB376FCF0318- <1>     db  0c3h, 0c6h, 0cch, 0dbh, 037h, 06fh, 0cfh, 003h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 000h
   208 0001328D 18001818181800      <1>
   209 00013294 003366CC6633000000- <1>     db  000h, 033h, 066h, 0cch, 066h, 033h, 000h, 000h, 000h, 0cch, 066h, 033h, 066h, 0cch, 000h, 000h
   209 0001329D CC663366CC0000      <1>
   210 000132A4 228822882288228855- <1>     db  022h, 088h, 022h, 088h, 022h, 088h, 022h, 088h, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   210 000132AD AA55AA55AA55AA      <1>
   211 000132B4 DB77DBEEDB77DBEE18- <1>     db  0dbh, 077h, 0dbh, 0eeh, 0dbh, 077h, 0dbh, 0eeh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   211 000132BD 18181818181818      <1>
   212 000132C4 18181818F818181818- <1>     db  018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h
   212 000132CD 18F818F8181818      <1>
   213 000132D4 36363636F636363600- <1>     db  036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h
   213 000132DD 000000FE363636      <1>
   214 000132E4 0000F818F818181836- <1>     db  000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h
   214 000132ED 36F606F6363636      <1>
   215 000132F4 363636363636363600- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h
   215 000132FD 00FE06F6363636      <1>
   216 00013304 3636F606FE00000036- <1>     db  036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h
   216 0001330D 363636FE000000      <1>
   217 00013314 1818F818F800000000- <1>     db  018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h
   217 0001331D 000000F8181818      <1>
   218 00013324 181818181F00000018- <1>     db  018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h
   218 0001332D 181818FF000000      <1>
   219 00013334 00000000FF18181818- <1>     db  000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h
   219 0001333D 1818181F181818      <1>
   220 00013344 00000000FF00000018- <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h
   220 0001334D 181818FF181818      <1>
   221 00013354 18181F181F18181836- <1>     db  018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h
   221 0001335D 36363637363636      <1>
   222 00013364 363637303F00000000- <1>     db  036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h
   222 0001336D 003F3037363636      <1>
   223 00013374 3636F700FF00000000- <1>     db  036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h
   223 0001337D 00FF00F7363636      <1>
   224 00013384 363637303736363600- <1>     db  036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   224 0001338D 00FF00FF000000      <1>
   225 00013394 3636F700F736363618- <1>     db  036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   225 0001339D 18FF00FF000000      <1>
   226 000133A4 36363636FF00000000- <1>     db  036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h
   226 000133AD 00FF00FF181818      <1>
   227 000133B4 00000000FF36363636- <1>     db  000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h
   227 000133BD 3636363F000000      <1>
   228 000133C4 18181F181F00000000- <1>     db  018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h
   228 000133CD 001F181F181818      <1>
   229 000133D4 000000003F36363636- <1>     db  000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h
   229 000133DD 363636FF363636      <1>
   230 000133E4 1818FF18FF18181818- <1>     db  018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h
   230 000133ED 181818F8000000      <1>
   231 000133F4 000000001F181818FF- <1>     db  000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   231 000133FD FFFFFFFFFFFFFF      <1>
   232 00013404 00000000FFFFFFFFF0- <1>     db  000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   232 0001340D F0F0F0F0F0F0F0      <1>
   233 00013414 0F0F0F0F0F0F0F0FFF- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h
   233 0001341D FFFFFF00000000      <1>
   234 00013424 000076DCC8DC760000- <1>     db  000h, 000h, 076h, 0dch, 0c8h, 0dch, 076h, 000h, 000h, 078h, 0cch, 0f8h, 0cch, 0f8h, 0c0h, 0c0h
   234 0001342D 78CCF8CCF8C0C0      <1>
   235 00013434 00FCCCC0C0C0C00000- <1>     db  000h, 0fch, 0cch, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   235 0001343D FE6C6C6C6C6C00      <1>
   236 00013444 FCCC603060CCFC0000- <1>     db  0fch, 0cch, 060h, 030h, 060h, 0cch, 0fch, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 070h, 000h
   236 0001344D 007ED8D8D87000      <1>
   237 00013454 00666666667C60C000- <1>     db  000h, 066h, 066h, 066h, 066h, 07ch, 060h, 0c0h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 000h
   237 0001345D 76DC1818181800      <1>
   238 00013464 FC3078CCCC7830FC38- <1>     db  0fch, 030h, 078h, 0cch, 0cch, 078h, 030h, 0fch, 038h, 06ch, 0c6h, 0feh, 0c6h, 06ch, 038h, 000h
   238 0001346D 6CC6FEC66C3800      <1>
   239 00013474 386CC6C66C6CEE001C- <1>     db  038h, 06ch, 0c6h, 0c6h, 06ch, 06ch, 0eeh, 000h, 01ch, 030h, 018h, 07ch, 0cch, 0cch, 078h, 000h
   239 0001347D 30187CCCCC7800      <1>
   240 00013484 00007EDBDB7E000006- <1>     db  000h, 000h, 07eh, 0dbh, 0dbh, 07eh, 000h, 000h, 006h, 00ch, 07eh, 0dbh, 0dbh, 07eh, 060h, 0c0h
   240 0001348D 0C7EDBDB7E60C0      <1>
   241 00013494 3860C0F8C060380078- <1>     db  038h, 060h, 0c0h, 0f8h, 0c0h, 060h, 038h, 000h, 078h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 000h
   241 0001349D CCCCCCCCCCCC00      <1>
   242 000134A4 00FC00FC00FC000030- <1>     db  000h, 0fch, 000h, 0fch, 000h, 0fch, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 0fch, 000h
   242 000134AD 30FC303000FC00      <1>
   243 000134B4 603018306000FC0018- <1>     db  060h, 030h, 018h, 030h, 060h, 000h, 0fch, 000h, 018h, 030h, 060h, 030h, 018h, 000h, 0fch, 000h
   243 000134BD 3060301800FC00      <1>
   244 000134C4 0E1B1B181818181818- <1>     db  00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 070h
   244 000134CD 18181818D8D870      <1>
   245 000134D4 303000FC0030300000- <1>     db  030h, 030h, 000h, 0fch, 000h, 030h, 030h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h
   245 000134DD 76DC0076DC0000      <1>
   246 000134E4 386C6C380000000000- <1>     db  038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h
   246 000134ED 00001818000000      <1>
   247 000134F4 00000000180000000F- <1>     db  000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 0ech, 06ch, 03ch, 01ch
   247 000134FD 0C0C0CEC6C3C1C      <1>
   248 00013504 786C6C6C6C00000070- <1>     db  078h, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 070h, 018h, 030h, 060h, 078h, 000h, 000h, 000h
   248 0001350D 18306078000000      <1>
   249 00013514 00003C3C3C3C000000- <1>     db  000h, 000h, 03ch, 03ch, 03ch, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   249 0001351D 00000000000000      <1>
   250                              <1> vgafont14:
   251 00013524 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   251 0001352D 00000000000000      <1>
   252 00013534 7E81A58181BD99817E- <1>     db  07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 07eh, 000h, 000h, 000h, 000h, 000h, 07eh, 0ffh
   252 0001353D 00000000007EFF      <1>
   253 00013544 DBFFFFC3E7FF7E0000- <1>     db  0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 0feh, 0feh
   253 0001354D 000000006CFEFE      <1>
   254 00013554 FEFE7C381000000000- <1>     db  0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch
   254 0001355D 000010387CFE7C      <1>
   255 00013564 381000000000000018- <1>     db  038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h
   255 0001356D 3C3CE7E7E71818      <1>
   256 00013574 3C0000000000183C7E- <1>     db  03ch, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h
   256 0001357D FFFF7E18183C00      <1>
   257 00013584 00000000000000183C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   257 0001358D 3C180000000000      <1>
   258 00013594 FFFFFFFFFFE7C3C3E7- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h
   258 0001359D FFFFFFFFFF0000      <1>
   259 000135A4 00003C664242663C00- <1>     db  000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh
   259 000135AD 000000FFFFFFFF      <1>
   260 000135B4 C399BDBD99C3FFFFFF- <1>     db  0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 01eh, 00eh, 01ah, 032h
   260 000135BD FF00001E0E1A32      <1>
   261 000135C4 78CCCCCC7800000000- <1>     db  078h, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 066h, 066h, 03ch, 018h
   261 000135CD 003C6666663C18      <1>
   262 000135D4 7E181800000000003F- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 070h, 0f0h
   262 000135DD 333F30303070F0      <1>
   263 000135E4 E000000000007F637F- <1>     db  0e0h, 000h, 000h, 000h, 000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h
   263 000135ED 63636367E7E6C0      <1>
   264 000135F4 000000001818DB3CE7- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h
   264 000135FD 3CDB1818000000      <1>
   265 00013604 000080C0E0F8FEF8E0- <1>     db  000h, 000h, 080h, 0c0h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h, 000h
   265 0001360D C0800000000000      <1>
   266 00013614 02060E3EFE3E0E0602- <1>     db  002h, 006h, 00eh, 03eh, 0feh, 03eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch
   266 0001361D 0000000000183C      <1>
   267 00013624 7E1818187E3C180000- <1>     db  07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h
   267 0001362D 00000066666666      <1>
   268 00013634 666600666600000000- <1>     db  066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh
   268 0001363D 007FDBDBDB7B1B      <1>
   269 00013644 1B1B1B000000007CC6- <1>     db  01bh, 01bh, 01bh, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h
   269 0001364D 60386CC6C66C38      <1>
   270 00013654 0CC67C000000000000- <1>     db  00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 000h
   270 0001365D 000000FEFEFE00      <1>
   271 00013664 00000000183C7E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h
   271 0001366D 187E3C187E0000      <1>
   272 00013674 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   272 0001367D 18180000000000      <1>
   273 00013684 1818181818187E3C18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   273 0001368D 00000000000000      <1>
   274 00013694 180CFE0C1800000000- <1>     db  018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 060h
   274 0001369D 00000000003060      <1>
   275 000136A4 FE6030000000000000- <1>     db  0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h
   275 000136AD 00000000C0C0C0      <1>
   276 000136B4 FE0000000000000000- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 028h, 06ch, 0feh, 06ch, 028h, 000h
   276 000136BD 00286CFE6C2800      <1>
   277 000136C4 000000000000001038- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h
   277 000136CD 387C7CFEFE0000      <1>
   278 000136D4 0000000000FEFE7C7C- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h
   278 000136DD 38381000000000      <1>
   279 000136E4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   279 000136ED 00000000000000      <1>
   280 000136F4 183C3C3C1818001818- <1>     db  018h, 03ch, 03ch, 03ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 066h, 066h, 066h
   280 000136FD 00000000666666      <1>
   281 00013704 240000000000000000- <1>     db  024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch
   281 0001370D 0000006C6CFE6C      <1>
   282 00013714 6C6CFE6C6C00000018- <1>     db  06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h
   282 0001371D 187CC6C2C07C06      <1>
   283 00013724 86C67C181800000000- <1>     db  086h, 0c6h, 07ch, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 066h
   283 0001372D 00C2C60C183066      <1>
   284 00013734 C60000000000386C6C- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 076h, 000h
   284 0001373D 3876DCCCCC7600      <1>
   285 00013744 000000303030600000- <1>     db  000h, 000h, 000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   285 0001374D 00000000000000      <1>
   286 00013754 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h, 000h
   286 0001375D 180C0000000000      <1>
   287 00013764 30180C0C0C0C0C1830- <1>     db  030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   287 0001376D 00000000000000      <1>
   288 00013774 663CFF3C6600000000- <1>     db  066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   288 0001377D 00000000001818      <1>
   289 00013784 7E1818000000000000- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   289 0001378D 00000000000000      <1>
   290 00013794 181818300000000000- <1>     db  018h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h
   290 0001379D 000000FE000000      <1>
   291 000137A4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   291 000137AD 00000000181800      <1>
   292 000137B4 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   292 000137BD 60C08000000000      <1>
   293 000137C4 00007CC6CEDEF6E6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   293 000137CD C67C0000000000      <1>
   294 000137D4 18387818181818187E- <1>     db  018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h
   294 000137DD 00000000007CC6      <1>
   295 000137E4 060C183060C6FE0000- <1>     db  006h, 00ch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 006h, 006h
   295 000137ED 0000007CC60606      <1>
   296 000137F4 3C0606C67C00000000- <1>     db  03ch, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh
   296 000137FD 000C1C3C6CCCFE      <1>
   297 00013804 0C0C1E0000000000FE- <1>     db  00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 0c6h
   297 0001380D C0C0C0FC0606C6      <1>
   298 00013814 7C00000000003860C0- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 07ch, 000h
   298 0001381D C0FCC6C6C67C00      <1>
   299 00013824 00000000FEC6060C18- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c6h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h
   299 0001382D 30303030000000      <1>
   300 00013834 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   300 0001383D C67C0000000000      <1>
   301 00013844 7CC6C6C67E06060C78- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h, 000h, 000h, 018h
   301 0001384D 00000000000018      <1>
   302 00013854 180000001818000000- <1>     db  018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   302 0001385D 00000000181800      <1>
   303 00013864 000018183000000000- <1>     db  000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h
   303 0001386D 00060C18306030      <1>
   304 00013874 180C06000000000000- <1>     db  018h, 00ch, 006h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h
   304 0001387D 00007E00007E00      <1>
   305 00013884 000000000000603018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h
   305 0001388D 0C060C18306000      <1>
   306 00013894 000000007CC6C60C18- <1>     db  000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h
   306 0001389D 18001818000000      <1>
   307 000138A4 00007CC6C6DEDEDEDC- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h, 000h
   307 000138AD C07C0000000000      <1>
   308 000138B4 10386CC6C6FEC6C6C6- <1>     db  010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h, 0fch, 066h
   308 000138BD 0000000000FC66      <1>
   309 000138C4 66667C666666FC0000- <1>     db  066h, 066h, 07ch, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h
   309 000138CD 0000003C66C2C0      <1>
   310 000138D4 C0C0C2663C00000000- <1>     db  0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h
   310 000138DD 00F86C66666666      <1>
   311 000138E4 666CF80000000000FE- <1>     db  066h, 06ch, 0f8h, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 062h, 066h
   311 000138ED 66626878686266      <1>
   312 000138F4 FE0000000000FE6662- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 0f0h, 000h
   312 000138FD 6878686060F000      <1>
   313 00013904 000000003C66C2C0C0- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 066h, 03ah, 000h, 000h, 000h
   313 0001390D DEC6663A000000      <1>
   314 00013914 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   314 0001391D C6C60000000000      <1>
   315 00013924 3C181818181818183C- <1>     db  03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 01eh, 00ch
   315 0001392D 00000000001E0C      <1>
   316 00013934 0C0C0C0CCCCC780000- <1>     db  00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 0e6h, 066h, 06ch, 06ch
   316 0001393D 000000E6666C6C      <1>
   317 00013944 786C6C66E600000000- <1>     db  078h, 06ch, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h
   317 0001394D 00F06060606060      <1>
   318 00013954 6266FE0000000000C6- <1>     db  062h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 0c6h
   318 0001395D EEFEFED6C6C6C6      <1>
   319 00013964 C60000000000C6E6F6- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h
   319 0001396D FEDECEC6C6C600      <1>
   320 00013974 00000000386CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h
   320 0001397D C6C66C38000000      <1>
   321 00013984 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h
   321 0001398D 60F00000000000      <1>
   322 00013994 7CC6C6C6C6D6DE7C0C- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h, 000h, 000h, 0fch, 066h
   322 0001399D 0E00000000FC66      <1>
   323 000139A4 66667C6C6666E60000- <1>     db  066h, 066h, 07ch, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 060h
   323 000139AD 0000007CC6C660      <1>
   324 000139B4 380CC6C67C00000000- <1>     db  038h, 00ch, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 07eh, 07eh, 05ah, 018h, 018h, 018h
   324 000139BD 007E7E5A181818      <1>
   325 000139C4 18183C0000000000C6- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h
   325 000139CD C6C6C6C6C6C6C6      <1>
   326 000139D4 7C0000000000C6C6C6- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 010h, 000h
   326 000139DD C6C6C66C381000      <1>
   327 000139E4 00000000C6C6C6C6D6- <1>     db  000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 07ch, 06ch, 000h, 000h, 000h
   327 000139ED D6FE7C6C000000      <1>
   328 000139F4 0000C6C66C3838386C- <1>     db  000h, 000h, 0c6h, 0c6h, 06ch, 038h, 038h, 038h, 06ch, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   328 000139FD C6C60000000000      <1>
   329 00013A04 666666663C1818183C- <1>     db  066h, 066h, 066h, 066h, 03ch, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h
   329 00013A0D 0000000000FEC6      <1>
   330 00013A14 8C183060C2C6FE0000- <1>     db  08ch, 018h, 030h, 060h, 0c2h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 03ch, 030h, 030h, 030h
   330 00013A1D 0000003C303030      <1>
   331 00013A24 303030303C00000000- <1>     db  030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch
   331 00013A2D 0080C0E070381C      <1>
   332 00013A34 0E060200000000003C- <1>     db  00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch
   332 00013A3D 0C0C0C0C0C0C0C      <1>
   333 00013A44 3C00000010386CC600- <1>     db  03ch, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   333 00013A4D 00000000000000      <1>
   334 00013A54 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h
   334 00013A5D 0000000000FF00      <1>
   335 00013A64 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   335 00013A6D 00000000000000      <1>
   336 00013A74 000000780C7CCCCC76- <1>     db  000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0e0h, 060h
   336 00013A7D 0000000000E060      <1>
   337 00013A84 60786C6666667C0000- <1>     db  060h, 078h, 06ch, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   337 00013A8D 0000000000007C      <1>
   338 00013A94 C6C0C0C67C00000000- <1>     db  0c6h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch
   338 00013A9D 001C0C0C3C6CCC      <1>
   339 00013AA4 CCCC76000000000000- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h
   339 00013AAD 00007CC6FEC0C6      <1>
   340 00013AB4 7C0000000000386C64- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 0f0h, 000h
   340 00013ABD 60F0606060F000      <1>
   341 00013AC4 0000000000000076CC- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   341 00013ACD CCCC7C0CCC7800      <1>
   342 00013AD4 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h
   342 00013ADD 66E60000000000      <1>
   343 00013AE4 18180038181818183C- <1>     db  018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 006h, 006h
   343 00013AED 00000000000606      <1>
   344 00013AF4 000E0606060666663C- <1>     db  000h, 00eh, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h, 000h, 000h, 0e0h, 060h, 060h, 066h
   344 00013AFD 000000E0606066      <1>
   345 00013B04 6C786C66E600000000- <1>     db  06ch, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h
   345 00013B0D 00381818181818      <1>
   346 00013B14 18183C000000000000- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ech, 0feh, 0d6h, 0d6h, 0d6h
   346 00013B1D 0000ECFED6D6D6      <1>
   347 00013B24 C60000000000000000- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 000h
   347 00013B2D DC666666666600      <1>
   348 00013B34 000000000000007CC6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h
   348 00013B3D C6C6C67C000000      <1>
   349 00013B44 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 000h, 000h
   349 00013B4D 7C6060F0000000      <1>
   350 00013B54 00000076CCCCCC7C0C- <1>     db  000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h
   350 00013B5D 0C1E0000000000      <1>
   351 00013B64 00DC76666060F00000- <1>     db  000h, 0dch, 076h, 066h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   351 00013B6D 0000000000007C      <1>
   352 00013B74 C6701CC67C00000000- <1>     db  0c6h, 070h, 01ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h
   352 00013B7D 00103030FC3030      <1>
   353 00013B84 30361C000000000000- <1>     db  030h, 036h, 01ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch
   353 00013B8D 0000CCCCCCCCCC      <1>
   354 00013B94 760000000000000000- <1>     db  076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 03ch, 018h, 000h
   354 00013B9D 666666663C1800      <1>
   355 00013BA4 00000000000000C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 06ch, 000h, 000h, 000h
   355 00013BAD D6D6FE6C000000      <1>
   356 00013BB4 0000000000C66C3838- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h
   356 00013BBD 6CC60000000000      <1>
   357 00013BC4 000000C6C6C6C67E06- <1>     db  000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h, 000h, 000h, 000h, 000h
   357 00013BCD 0CF80000000000      <1>
   358 00013BD4 00FECC183066FE0000- <1>     db  000h, 0feh, 0cch, 018h, 030h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 00eh, 018h, 018h, 018h
   358 00013BDD 0000000E181818      <1>
   359 00013BE4 701818180E00000000- <1>     db  070h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h
   359 00013BED 00181818180018      <1>
   360 00013BF4 181818000000000070- <1>     db  018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h
   360 00013BFD 1818180E181818      <1>
   361 00013C04 70000000000076DC00- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   361 00013C0D 00000000000000      <1>
   362 00013C14 00000000000010386C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   362 00013C1D C6C6FE00000000      <1>
   363 00013C24 00003C66C2C0C0C266- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h, 000h
   363 00013C2D 3C0C067C000000      <1>
   364 00013C34 CCCC00CCCCCCCCCC76- <1>     db  0cch, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h
   364 00013C3D 000000000C1830      <1>
   365 00013C44 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 078h
   365 00013C4D 000010386C0078      <1>
   366 00013C54 0C7CCCCC7600000000- <1>     db  00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 000h, 078h, 00ch, 07ch
   366 00013C5D 00CCCC00780C7C      <1>
   367 00013C64 CCCC76000000006030- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch
   367 00013C6D 1800780C7CCCCC      <1>
   368 00013C74 7600000000386C3800- <1>     db  076h, 000h, 000h, 000h, 000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h
   368 00013C7D 780C7CCCCC7600      <1>
   369 00013C84 0000000000003C6660- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h
   369 00013C8D 663C0C063C0000      <1>
   370 00013C94 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   370 00013C9D C67C0000000000      <1>
   371 00013CA4 CCCC007CC6FEC0C67C- <1>     db  0cch, 0cch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h
   371 00013CAD 00000000603018      <1>
   372 00013CB4 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 000h, 038h
   372 00013CBD 00000066660038      <1>
   373 00013CC4 181818183C00000000- <1>     db  018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h
   373 00013CCD 183C6600381818      <1>
   374 00013CD4 18183C000000006030- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h
   374 00013CDD 18003818181818      <1>
   375 00013CE4 3C00000000C6C61038- <1>     db  03ch, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h
   375 00013CED 6CC6C6FEC6C600      <1>
   376 00013CF4 0000386C3800386CC6- <1>     db  000h, 000h, 038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h, 000h, 000h
   376 00013CFD C6FEC6C6000000      <1>
   377 00013D04 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h
   377 00013D0D 66FE0000000000      <1>
   378 00013D14 0000CC76367ED8D86E- <1>     db  000h, 000h, 0cch, 076h, 036h, 07eh, 0d8h, 0d8h, 06eh, 000h, 000h, 000h, 000h, 000h, 03eh, 06ch
   378 00013D1D 00000000003E6C      <1>
   379 00013D24 CCCCFECCCCCCCE0000- <1>     db  0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 07ch
   379 00013D2D 000010386C007C      <1>
   380 00013D34 C6C6C6C67C00000000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h, 07ch, 0c6h, 0c6h
   380 00013D3D 00C6C6007CC6C6      <1>
   381 00013D44 C6C67C000000006030- <1>     db  0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h
   381 00013D4D 18007CC6C6C6C6      <1>
   382 00013D54 7C000000003078CC00- <1>     db  07ch, 000h, 000h, 000h, 000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   382 00013D5D CCCCCCCCCC7600      <1>
   383 00013D64 00000060301800CCCC- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h
   383 00013D6D CCCCCC76000000      <1>
   384 00013D74 0000C6C600C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h, 000h, 0c6h
   384 00013D7D 7E060C780000C6      <1>
   385 00013D84 C6386CC6C6C6C66C38- <1>     db  0c6h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h
   385 00013D8D 00000000C6C600      <1>
   386 00013D94 C6C6C6C6C6C67C0000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 018h, 03ch, 066h, 060h
   386 00013D9D 000018183C6660      <1>
   387 00013DA4 60663C181800000000- <1>     db  060h, 066h, 03ch, 018h, 018h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h
   387 00013DAD 386C6460F06060      <1>
   388 00013DB4 60E6FC000000000066- <1>     db  060h, 0e6h, 0fch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 03ch, 018h, 07eh, 018h, 07eh, 018h
   388 00013DBD 663C187E187E18      <1>
   389 00013DC4 1800000000F8CCCCF8- <1>     db  018h, 000h, 000h, 000h, 000h, 0f8h, 0cch, 0cch, 0f8h, 0c4h, 0cch, 0deh, 0cch, 0cch, 0c6h, 000h
   389 00013DCD C4CCDECCCCC600      <1>
   390 00013DD4 0000000E1B1818187E- <1>     db  000h, 000h, 000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h
   390 00013DDD 18181818D87000      <1>
   391 00013DE4 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch
   391 00013DED CC76000000000C      <1>
   392 00013DF4 18300038181818183C- <1>     db  018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h
   392 00013DFD 00000000183060      <1>
   393 00013E04 007CC6C6C6C67C0000- <1>     db  000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h, 000h, 0cch
   393 00013E0D 000018306000CC      <1>
   394 00013E14 CCCCCCCC7600000000- <1>     db  0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h
   394 00013E1D 0076DC00DC6666      <1>
   395 00013E24 66666600000076DC00- <1>     db  066h, 066h, 066h, 000h, 000h, 000h, 076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h
   395 00013E2D C6E6F6FEDECEC6      <1>
   396 00013E34 C6000000003C6C6C3E- <1>     db  0c6h, 000h, 000h, 000h, 000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h
   396 00013E3D 007E0000000000      <1>
   397 00013E44 000000386C6C38007C- <1>     db  000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   397 00013E4D 00000000000000      <1>
   398 00013E54 0000303000303060C6- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   398 00013E5D C67C0000000000      <1>
   399 00013E64 00000000FEC0C0C000- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   399 00013E6D 00000000000000      <1>
   400 00013E74 0000FE060606000000- <1>     db  000h, 000h, 0feh, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h
   400 00013E7D 0000C0C0C6CCD8      <1>
   401 00013E84 3060DC860C183E0000- <1>     db  030h, 060h, 0dch, 086h, 00ch, 018h, 03eh, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h, 030h, 066h
   401 00013E8D C0C0C6CCD83066      <1>
   402 00013E94 CE9E3E060600000018- <1>     db  0ceh, 09eh, 03eh, 006h, 006h, 000h, 000h, 000h, 018h, 018h, 000h, 018h, 018h, 03ch, 03ch, 03ch
   402 00013E9D 180018183C3C3C      <1>
   403 00013EA4 180000000000000036- <1>     db  018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h
   403 00013EAD 6CD86C36000000      <1>
   404 00013EB4 000000000000D86C36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h
   404 00013EBD 6CD80000000000      <1>
   405 00013EC4 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 055h, 0aah
   405 00013ECD 441144114455AA      <1>
   406 00013ED4 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 0ddh, 077h, 0ddh, 077h
   406 00013EDD AA55AADD77DD77      <1>
   407 00013EE4 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 018h, 018h, 018h, 018h, 018h, 018h
   407 00013EED 77181818181818      <1>
   408 00013EF4 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h
   408 00013EFD 181818181818F8      <1>
   409 00013F04 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h
   409 00013F0D 1818F818F81818      <1>
   410 00013F14 181818183636363636- <1>     db  018h, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h
   410 00013F1D 3636F636363636      <1>
   411 00013F24 363600000000000000- <1>     db  036h, 036h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h
   411 00013F2D FE363636363636      <1>
   412 00013F34 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 036h, 036h
   412 00013F3D 18181818183636      <1>
   413 00013F44 363636F606F6363636- <1>     db  036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   413 00013F4D 36363636363636      <1>
   414 00013F54 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0feh
   414 00013F5D 360000000000FE      <1>
   415 00013F64 06F636363636363636- <1>     db  006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh
   415 00013F6D 36363636F606FE      <1>
   416 00013F74 000000000000363636- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h
   416 00013F7D 36363636FE0000      <1>
   417 00013F84 000000001818181818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h
   417 00013F8D F818F800000000      <1>
   418 00013F94 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h
   418 00013F9D F8181818181818      <1>
   419 00013FA4 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   419 00013FAD 00000000001818      <1>
   420 00013FB4 1818181818FF000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   420 00013FBD 00000000000000      <1>
   421 00013FC4 000000FF1818181818- <1>     db  000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   421 00013FCD 18181818181818      <1>
   422 00013FD4 181F18181818181800- <1>     db  018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   422 00013FDD 000000000000FF      <1>
   423 00013FE4 000000000000181818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h
   423 00013FED 18181818FF1818      <1>
   424 00013FF4 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h
   424 00013FFD 1F181F18181818      <1>
   425 00014004 181836363636363636- <1>     db  018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h
   425 0001400D 37363636363636      <1>
   426 00014014 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   426 0001401D 00000000000000      <1>
   427 00014024 0000003F3037363636- <1>     db  000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   427 0001402D 36363636363636      <1>
   428 00014034 36F700FF0000000000- <1>     db  036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   428 0001403D 000000000000FF      <1>
   429 00014044 00F736363636363636- <1>     db  000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h
   429 0001404D 36363636373037      <1>
   430 00014054 363636363636000000- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h
   430 0001405D 0000FF00FF0000      <1>
   431 00014064 000000003636363636- <1>     db  000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h
   431 0001406D F700F736363636      <1>
   432 00014074 36361818181818FF00- <1>     db  036h, 036h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h
   432 0001407D FF000000000000      <1>
   433 00014084 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   433 0001408D 00000000000000      <1>
   434 00014094 000000FF00FF181818- <1>     db  000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   434 0001409D 18181800000000      <1>
   435 000140A4 000000FF3636363636- <1>     db  000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   435 000140AD 36363636363636      <1>
   436 000140B4 363F00000000000018- <1>     db  036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh
   436 000140BD 181818181F181F      <1>
   437 000140C4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h
   437 000140CD 00001F181F1818      <1>
   438 000140D4 181818180000000000- <1>     db  018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h
   438 000140DD 00003F36363636      <1>
   439 000140E4 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h
   439 000140ED FF363636363636      <1>
   440 000140F4 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   440 000140FD 18181818181818      <1>
   441 00014104 1818181818F8000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   441 0001410D 00000000000000      <1>
   442 00014114 0000001F1818181818- <1>     db  000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   442 0001411D 18FFFFFFFFFFFF      <1>
   443 00014124 FFFFFFFFFFFFFFFF00- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   443 0001412D 000000000000FF      <1>
   444 00014134 FFFFFFFFFFFFF0F0F0- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   444 0001413D F0F0F0F0F0F0F0      <1>
   445 00014144 F0F0F0F00F0F0F0F0F- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   445 0001414D 0F0F0F0F0F0F0F      <1>
   446 00014154 0F0FFFFFFFFFFFFFFF- <1>     db  00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   446 0001415D 00000000000000      <1>
   447 00014164 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h, 000h
   447 0001416D DC760000000000      <1>
   448 00014174 00007CC6FCC6C6FCC0- <1>     db  000h, 000h, 07ch, 0c6h, 0fch, 0c6h, 0c6h, 0fch, 0c0h, 0c0h, 040h, 000h, 000h, 000h, 0feh, 0c6h
   448 0001417D C040000000FEC6      <1>
   449 00014184 C6C0C0C0C0C0C00000- <1>     db  0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 06ch
   449 0001418D 0000000000FE6C      <1>
   450 00014194 6C6C6C6C6C00000000- <1>     db  06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h
   450 0001419D 00FEC660301830      <1>
   451 000141A4 60C6FE000000000000- <1>     db  060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h
   451 000141AD 00007ED8D8D8D8      <1>
   452 000141B4 700000000000000066- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h
   452 000141BD 6666667C6060C0      <1>
   453 000141C4 00000000000076DC18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h
   453 000141CD 18181818000000      <1>
   454 000141D4 00007E183C6666663C- <1>     db  000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h, 000h
   454 000141DD 187E0000000000      <1>
   455 000141E4 386CC6C6FEC6C66C38- <1>     db  038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch
   455 000141ED 0000000000386C      <1>
   456 000141F4 C6C6C66C6C6CEE0000- <1>     db  0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h, 000h, 01eh, 030h, 018h, 00ch
   456 000141FD 0000001E30180C      <1>
   457 00014204 3E6666663C00000000- <1>     db  03eh, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh
   457 0001420D 000000007EDBDB      <1>
   458 00014214 7E0000000000000003- <1>     db  07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h
   458 0001421D 067EDBDBF37E60      <1>
   459 00014224 C000000000001C3060- <1>     db  0c0h, 000h, 000h, 000h, 000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 030h, 01ch, 000h
   459 0001422D 607C6060301C00      <1>
   460 00014234 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h
   460 0001423D C6C6C6C6000000      <1>
   461 00014244 000000FE0000FE0000- <1>     db  000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   461 0001424D FE000000000000      <1>
   462 00014254 0018187E18180000FF- <1>     db  000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 030h, 018h
   462 0001425D 00000000003018      <1>
   463 00014264 0C060C1830007E0000- <1>     db  00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h, 060h
   463 0001426D 0000000C183060      <1>
   464 00014274 30180C007E00000000- <1>     db  030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h
   464 0001427D 000E1B1B181818      <1>
   465 00014284 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h
   465 0001428D 1818181818D8D8      <1>
   466 00014294 700000000000001818- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h
   466 0001429D 007E0018180000      <1>
   467 000142A4 00000000000076DC00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h
   467 000142AD 76DC0000000000      <1>
   468 000142B4 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   468 000142BD 00000000000000      <1>
   469 000142C4 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   469 000142CD 00000000000000      <1>
   470 000142D4 000000180000000000- <1>     db  000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 00ch
   470 000142DD 00000F0C0C0C0C      <1>
   471 000142E4 0CEC6C3C1C00000000- <1>     db  00ch, 0ech, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   471 000142ED D86C6C6C6C6C00      <1>
   472 000142F4 0000000000000070D8- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h
   472 000142FD 3060C8F8000000      <1>
   473 00014304 00000000000000007C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h
   473 0001430D 7C7C7C7C7C0000      <1>
   474 00014314 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   474 0001431D 00000000000000      <1>
   475                              <1> vgafont16:
   476 00014324 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   476 0001432D 00000000000000      <1>
   477 00014334 00007E81A58181BD99- <1>     db  000h, 000h, 07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 081h, 07eh, 000h, 000h, 000h, 000h
   477 0001433D 81817E00000000      <1>
   478 00014344 00007EFFDBFFFFC3E7- <1>     db  000h, 000h, 07eh, 0ffh, 0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 0ffh, 07eh, 000h, 000h, 000h, 000h
   478 0001434D FFFF7E00000000      <1>
   479 00014354 000000006CFEFEFEFE- <1>     db  000h, 000h, 000h, 000h, 06ch, 0feh, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h
   479 0001435D 7C381000000000      <1>
   480 00014364 0000000010387CFE7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   480 0001436D 38100000000000      <1>
   481 00014374 000000183C3CE7E7E7- <1>     db  000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   481 0001437D 18183C00000000      <1>
   482 00014384 000000183C7EFFFF7E- <1>     db  000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   482 0001438D 18183C00000000      <1>
   483 00014394 000000000000183C3C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   483 0001439D 18000000000000      <1>
   484 000143A4 FFFFFFFFFFFFE7C3C3- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   484 000143AD E7FFFFFFFFFFFF      <1>
   485 000143B4 00000000003C664242- <1>     db  000h, 000h, 000h, 000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h
   485 000143BD 663C0000000000      <1>
   486 000143C4 FFFFFFFFFFC399BDBD- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   486 000143CD 99C3FFFFFFFFFF      <1>
   487 000143D4 00001E0E1A3278CCCC- <1>     db  000h, 000h, 01eh, 00eh, 01ah, 032h, 078h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   487 000143DD CCCC7800000000      <1>
   488 000143E4 00003C666666663C18- <1>     db  000h, 000h, 03ch, 066h, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   488 000143ED 7E181800000000      <1>
   489 000143F4 00003F333F30303030- <1>     db  000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 030h, 070h, 0f0h, 0e0h, 000h, 000h, 000h, 000h
   489 000143FD 70F0E000000000      <1>
   490 00014404 00007F637F63636363- <1>     db  000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h, 000h, 000h, 000h
   490 0001440D 67E7E6C0000000      <1>
   491 00014414 0000001818DB3CE73C- <1>     db  000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h, 000h
   491 0001441D DB181800000000      <1>
   492 00014424 0080C0E0F0F8FEF8F0- <1>     db  000h, 080h, 0c0h, 0e0h, 0f0h, 0f8h, 0feh, 0f8h, 0f0h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h
   492 0001442D E0C08000000000      <1>
   493 00014434 0002060E1E3EFE3E1E- <1>     db  000h, 002h, 006h, 00eh, 01eh, 03eh, 0feh, 03eh, 01eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   493 0001443D 0E060200000000      <1>
   494 00014444 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   494 0001444D 3C180000000000      <1>
   495 00014454 000066666666666666- <1>     db  000h, 000h, 066h, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h
   495 0001445D 00666600000000      <1>
   496 00014464 00007FDBDBDB7B1B1B- <1>     db  000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 01bh, 01bh, 000h, 000h, 000h, 000h
   496 0001446D 1B1B1B00000000      <1>
   497 00014474 007CC660386CC6C66C- <1>     db  000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h
   497 0001447D 380CC67C000000      <1>
   498 00014484 0000000000000000FE- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 0feh, 000h, 000h, 000h, 000h
   498 0001448D FEFEFE00000000      <1>
   499 00014494 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   499 0001449D 3C187E00000000      <1>
   500 000144A4 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   500 000144AD 18181800000000      <1>
   501 000144B4 000018181818181818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h
   501 000144BD 7E3C1800000000      <1>
   502 000144C4 0000000000180CFE0C- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   502 000144CD 18000000000000      <1>
   503 000144D4 00000000003060FE60- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h
   503 000144DD 30000000000000      <1>
   504 000144E4 000000000000C0C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   504 000144ED FE000000000000      <1>
   505 000144F4 00000000002466FF66- <1>     db  000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h
   505 000144FD 24000000000000      <1>
   506 00014504 000000001038387C7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h, 000h, 000h, 000h
   506 0001450D FEFE0000000000      <1>
   507 00014514 00000000FEFE7C7C38- <1>     db  000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   507 0001451D 38100000000000      <1>
   508 00014524 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   508 0001452D 00000000000000      <1>
   509 00014534 0000183C3C3C181818- <1>     db  000h, 000h, 018h, 03ch, 03ch, 03ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   509 0001453D 00181800000000      <1>
   510 00014544 006666662400000000- <1>     db  000h, 066h, 066h, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   510 0001454D 00000000000000      <1>
   511 00014554 0000006C6CFE6C6C6C- <1>     db  000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 000h
   511 0001455D FE6C6C00000000      <1>
   512 00014564 18187CC6C2C07C0606- <1>     db  018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h, 006h, 086h, 0c6h, 07ch, 018h, 018h, 000h, 000h
   512 0001456D 86C67C18180000      <1>
   513 00014574 00000000C2C60C1830- <1>     db  000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 060h, 0c6h, 086h, 000h, 000h, 000h, 000h
   513 0001457D 60C68600000000      <1>
   514 00014584 0000386C6C3876DCCC- <1>     db  000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   514 0001458D CCCC7600000000      <1>
   515 00014594 003030306000000000- <1>     db  000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   515 0001459D 00000000000000      <1>
   516 000145A4 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h
   516 000145AD 30180C00000000      <1>
   517 000145B4 000030180C0C0C0C0C- <1>     db  000h, 000h, 030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h
   517 000145BD 0C183000000000      <1>
   518 000145C4 0000000000663CFF3C- <1>     db  000h, 000h, 000h, 000h, 000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h
   518 000145CD 66000000000000      <1>
   519 000145D4 000000000018187E18- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   519 000145DD 18000000000000      <1>
   520 000145E4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 030h, 000h, 000h, 000h
   520 000145ED 18181830000000      <1>
   521 000145F4 00000000000000FE00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   521 000145FD 00000000000000      <1>
   522 00014604 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   522 0001460D 00181800000000      <1>
   523 00014614 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   523 0001461D 60C08000000000      <1>
   524 00014624 00003C66C3C3DBDBC3- <1>     db  000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h, 000h, 000h
   524 0001462D C3663C00000000      <1>
   525 00014634 000018387818181818- <1>     db  000h, 000h, 018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h
   525 0001463D 18187E00000000      <1>
   526 00014644 00007CC6060C183060- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   526 0001464D C0C6FE00000000      <1>
   527 00014654 00007CC606063C0606- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 006h, 03ch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   527 0001465D 06C67C00000000      <1>
   528 00014664 00000C1C3C6CCCFE0C- <1>     db  000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h
   528 0001466D 0C0C1E00000000      <1>
   529 00014674 0000FEC0C0C0FC0606- <1>     db  000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   529 0001467D 06C67C00000000      <1>
   530 00014684 00003860C0C0FCC6C6- <1>     db  000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   530 0001468D C6C67C00000000      <1>
   531 00014694 0000FEC606060C1830- <1>     db  000h, 000h, 0feh, 0c6h, 006h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h, 000h
   531 0001469D 30303000000000      <1>
   532 000146A4 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   532 000146AD C6C67C00000000      <1>
   533 000146B4 00007CC6C6C67E0606- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h
   533 000146BD 060C7800000000      <1>
   534 000146C4 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   534 000146CD 18180000000000      <1>
   535 000146D4 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h
   535 000146DD 18183000000000      <1>
   536 000146E4 000000060C18306030- <1>     db  000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 006h, 000h, 000h, 000h, 000h
   536 000146ED 180C0600000000      <1>
   537 000146F4 00000000007E00007E- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   537 000146FD 00000000000000      <1>
   538 00014704 0000006030180C060C- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h, 000h, 000h, 000h
   538 0001470D 18306000000000      <1>
   539 00014714 00007CC6C60C181818- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   539 0001471D 00181800000000      <1>
   540 00014724 0000007CC6C6DEDEDE- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h
   540 0001472D DCC07C00000000      <1>
   541 00014734 000010386CC6C6FEC6- <1>     db  000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   541 0001473D C6C6C600000000      <1>
   542 00014744 0000FC6666667C6666- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 066h, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h
   542 0001474D 6666FC00000000      <1>
   543 00014754 00003C66C2C0C0C0C0- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h
   543 0001475D C2663C00000000      <1>
   544 00014764 0000F86C6666666666- <1>     db  000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h, 066h, 066h, 06ch, 0f8h, 000h, 000h, 000h, 000h
   544 0001476D 666CF800000000      <1>
   545 00014774 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   545 0001477D 6266FE00000000      <1>
   546 00014784 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   546 0001478D 6060F000000000      <1>
   547 00014794 00003C66C2C0C0DEC6- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 0c6h, 066h, 03ah, 000h, 000h, 000h, 000h
   547 0001479D C6663A00000000      <1>
   548 000147A4 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   548 000147AD C6C6C600000000      <1>
   549 000147B4 00003C181818181818- <1>     db  000h, 000h, 03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   549 000147BD 18183C00000000      <1>
   550 000147C4 00001E0C0C0C0C0CCC- <1>     db  000h, 000h, 01eh, 00ch, 00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   550 000147CD CCCC7800000000      <1>
   551 000147D4 0000E666666C78786C- <1>     db  000h, 000h, 0e6h, 066h, 066h, 06ch, 078h, 078h, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   551 000147DD 6666E600000000      <1>
   552 000147E4 0000F0606060606060- <1>     db  000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   552 000147ED 6266FE00000000      <1>
   553 000147F4 0000C3E7FFFFDBC3C3- <1>     db  000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   553 000147FD C3C3C300000000      <1>
   554 00014804 0000C6E6F6FEDECEC6- <1>     db  000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   554 0001480D C6C6C600000000      <1>
   555 00014814 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   555 0001481D C6C67C00000000      <1>
   556 00014824 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   556 0001482D 6060F000000000      <1>
   557 00014834 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h
   557 0001483D D6DE7C0C0E0000      <1>
   558 00014844 0000FC6666667C6C66- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 06ch, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   558 0001484D 6666E600000000      <1>
   559 00014854 00007CC6C660380C06- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 060h, 038h, 00ch, 006h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   559 0001485D C6C67C00000000      <1>
   560 00014864 0000FFDB9918181818- <1>     db  000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   560 0001486D 18183C00000000      <1>
   561 00014874 0000C6C6C6C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   561 0001487D C6C67C00000000      <1>
   562 00014884 0000C3C3C3C3C3C3C3- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   562 0001488D 663C1800000000      <1>
   563 00014894 0000C3C3C3C3C3DBDB- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 000h
   563 0001489D FF666600000000      <1>
   564 000148A4 0000C3C3663C18183C- <1>     db  000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   564 000148AD 66C3C300000000      <1>
   565 000148B4 0000C3C3C3663C1818- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   565 000148BD 18183C00000000      <1>
   566 000148C4 0000FFC3860C183060- <1>     db  000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h
   566 000148CD C1C3FF00000000      <1>
   567 000148D4 00003C303030303030- <1>     db  000h, 000h, 03ch, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h
   567 000148DD 30303C00000000      <1>
   568 000148E4 00000080C0E070381C- <1>     db  000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   568 000148ED 0E060200000000      <1>
   569 000148F4 00003C0C0C0C0C0C0C- <1>     db  000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 03ch, 000h, 000h, 000h, 000h
   569 000148FD 0C0C3C00000000      <1>
   570 00014904 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   570 0001490D 00000000000000      <1>
   571 00014914 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h
   571 0001491D 00000000FF0000      <1>
   572 00014924 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   572 0001492D 00000000000000      <1>
   573 00014934 0000000000780C7CCC- <1>     db  000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   573 0001493D CCCC7600000000      <1>
   574 00014944 0000E06060786C6666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 078h, 06ch, 066h, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h
   574 0001494D 66667C00000000      <1>
   575 00014954 00000000007CC6C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c0h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   575 0001495D C0C67C00000000      <1>
   576 00014964 00001C0C0C3C6CCCCC- <1>     db  000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   576 0001496D CCCC7600000000      <1>
   577 00014974 00000000007CC6FEC0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   577 0001497D C0C67C00000000      <1>
   578 00014984 0000386C6460F06060- <1>     db  000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   578 0001498D 6060F000000000      <1>
   579 00014994 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   579 0001499D CCCC7C0CCC7800      <1>
   580 000149A4 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   580 000149AD 6666E600000000      <1>
   581 000149B4 000018180038181818- <1>     db  000h, 000h, 018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   581 000149BD 18183C00000000      <1>
   582 000149C4 00000606000E060606- <1>     db  000h, 000h, 006h, 006h, 000h, 00eh, 006h, 006h, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h
   582 000149CD 06060666663C00      <1>
   583 000149D4 0000E06060666C7878- <1>     db  000h, 000h, 0e0h, 060h, 060h, 066h, 06ch, 078h, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h
   583 000149DD 6C66E600000000      <1>
   584 000149E4 000038181818181818- <1>     db  000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   584 000149ED 18183C00000000      <1>
   585 000149F4 0000000000E6FFDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h
   585 000149FD DBDBDB00000000      <1>
   586 00014A04 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   586 00014A0D 66666600000000      <1>
   587 00014A14 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   587 00014A1D C6C67C00000000      <1>
   588 00014A24 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h
   588 00014A2D 66667C6060F000      <1>
   589 00014A34 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h
   589 00014A3D CCCC7C0C0C1E00      <1>
   590 00014A44 0000000000DC766660- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 076h, 066h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   590 00014A4D 6060F000000000      <1>
   591 00014A54 00000000007CC66038- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h
   591 00014A5D 0CC67C00000000      <1>
   592 00014A64 0000103030FC303030- <1>     db  000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h, 030h, 030h, 036h, 01ch, 000h, 000h, 000h, 000h
   592 00014A6D 30361C00000000      <1>
   593 00014A74 0000000000CCCCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   593 00014A7D CCCC7600000000      <1>
   594 00014A84 0000000000C3C3C3C3- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   594 00014A8D 663C1800000000      <1>
   595 00014A94 0000000000C3C3C3DB- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h
   595 00014A9D DBFF6600000000      <1>
   596 00014AA4 0000000000C3663C18- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h
   596 00014AAD 3C66C300000000      <1>
   597 00014AB4 0000000000C6C6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h
   597 00014ABD C6C67E060CF800      <1>
   598 00014AC4 0000000000FECC1830- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0cch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   598 00014ACD 60C6FE00000000      <1>
   599 00014AD4 00000E181818701818- <1>     db  000h, 000h, 00eh, 018h, 018h, 018h, 070h, 018h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h
   599 00014ADD 18180E00000000      <1>
   600 00014AE4 000018181818001818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   600 00014AED 18181800000000      <1>
   601 00014AF4 0000701818180E1818- <1>     db  000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h, 018h, 070h, 000h, 000h, 000h, 000h
   601 00014AFD 18187000000000      <1>
   602 00014B04 000076DC0000000000- <1>     db  000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   602 00014B0D 00000000000000      <1>
   603 00014B14 0000000010386CC6C6- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h
   603 00014B1D C6FE0000000000      <1>
   604 00014B24 00003C66C2C0C0C0C2- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h
   604 00014B2D 663C0C067C0000      <1>
   605 00014B34 0000CC0000CCCCCCCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   605 00014B3D CCCC7600000000      <1>
   606 00014B44 000C1830007CC6FEC0- <1>     db  000h, 00ch, 018h, 030h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   606 00014B4D C0C67C00000000      <1>
   607 00014B54 0010386C00780C7CCC- <1>     db  000h, 010h, 038h, 06ch, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   607 00014B5D CCCC7600000000      <1>
   608 00014B64 0000CC0000780C7CCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   608 00014B6D CCCC7600000000      <1>
   609 00014B74 0060301800780C7CCC- <1>     db  000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   609 00014B7D CCCC7600000000      <1>
   610 00014B84 00386C3800780C7CCC- <1>     db  000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   610 00014B8D CCCC7600000000      <1>
   611 00014B94 000000003C66606066- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 060h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h, 000h
   611 00014B9D 3C0C063C000000      <1>
   612 00014BA4 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   612 00014BAD C0C67C00000000      <1>
   613 00014BB4 0000C600007CC6FEC0- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   613 00014BBD C0C67C00000000      <1>
   614 00014BC4 00603018007CC6FEC0- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   614 00014BCD C0C67C00000000      <1>
   615 00014BD4 000066000038181818- <1>     db  000h, 000h, 066h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   615 00014BDD 18183C00000000      <1>
   616 00014BE4 00183C660038181818- <1>     db  000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   616 00014BED 18183C00000000      <1>
   617 00014BF4 006030180038181818- <1>     db  000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   617 00014BFD 18183C00000000      <1>
   618 00014C04 00C60010386CC6C6FE- <1>     db  000h, 0c6h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   618 00014C0D C6C6C600000000      <1>
   619 00014C14 386C3800386CC6C6FE- <1>     db  038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   619 00014C1D C6C6C600000000      <1>
   620 00014C24 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 060h, 066h, 0feh, 000h, 000h, 000h, 000h
   620 00014C2D 6066FE00000000      <1>
   621 00014C34 00000000006E3B1B7E- <1>     db  000h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h
   621 00014C3D D8DC7700000000      <1>
   622 00014C44 00003E6CCCCCFECCCC- <1>     db  000h, 000h, 03eh, 06ch, 0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h
   622 00014C4D CCCCCE00000000      <1>
   623 00014C54 0010386C007CC6C6C6- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   623 00014C5D C6C67C00000000      <1>
   624 00014C64 0000C600007CC6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   624 00014C6D C6C67C00000000      <1>
   625 00014C74 00603018007CC6C6C6- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   625 00014C7D C6C67C00000000      <1>
   626 00014C84 003078CC00CCCCCCCC- <1>     db  000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   626 00014C8D CCCC7600000000      <1>
   627 00014C94 0060301800CCCCCCCC- <1>     db  000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   627 00014C9D CCCC7600000000      <1>
   628 00014CA4 0000C60000C6C6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h
   628 00014CAD C6C67E060C7800      <1>
   629 00014CB4 00C6007CC6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   629 00014CBD C6C67C00000000      <1>
   630 00014CC4 00C600C6C6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   630 00014CCD C6C67C00000000      <1>
   631 00014CD4 0018187EC3C0C0C0C3- <1>     db  000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   631 00014CDD 7E181800000000      <1>
   632 00014CE4 00386C6460F0606060- <1>     db  000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0e6h, 0fch, 000h, 000h, 000h, 000h
   632 00014CED 60E6FC00000000      <1>
   633 00014CF4 0000C3663C18FF18FF- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   633 00014CFD 18181800000000      <1>
   634 00014D04 00FC66667C62666F66- <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h, 000h
   634 00014D0D 6666F300000000      <1>
   635 00014D14 000E1B1818187E1818- <1>     db  000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h, 000h
   635 00014D1D 181818D8700000      <1>
   636 00014D24 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   636 00014D2D CCCC7600000000      <1>
   637 00014D34 000C18300038181818- <1>     db  000h, 00ch, 018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   637 00014D3D 18183C00000000      <1>
   638 00014D44 00183060007CC6C6C6- <1>     db  000h, 018h, 030h, 060h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   638 00014D4D C6C67C00000000      <1>
   639 00014D54 0018306000CCCCCCCC- <1>     db  000h, 018h, 030h, 060h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   639 00014D5D CCCC7600000000      <1>
   640 00014D64 000076DC00DC666666- <1>     db  000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   640 00014D6D 66666600000000      <1>
   641 00014D74 76DC00C6E6F6FEDECE- <1>     db  076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   641 00014D7D C6C6C600000000      <1>
   642 00014D84 003C6C6C3E007E0000- <1>     db  000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   642 00014D8D 00000000000000      <1>
   643 00014D94 00386C6C38007C0000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   643 00014D9D 00000000000000      <1>
   644 00014DA4 0000303000303060C0- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c0h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   644 00014DAD C6C67C00000000      <1>
   645 00014DB4 000000000000FEC0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h
   645 00014DBD C0C00000000000      <1>
   646 00014DC4 000000000000FE0606- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 006h, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h
   646 00014DCD 06060000000000      <1>
   647 00014DD4 00C0C0C2C6CC183060- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh, 000h, 000h
   647 00014DDD CE9B060C1F0000      <1>
   648 00014DE4 00C0C0C2C6CC183066- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h, 006h, 000h, 000h
   648 00014DED CE963E06060000      <1>
   649 00014DF4 00001818001818183C- <1>     db  000h, 000h, 018h, 018h, 000h, 018h, 018h, 018h, 03ch, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h
   649 00014DFD 3C3C1800000000      <1>
   650 00014E04 0000000000366CD86C- <1>     db  000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h, 000h, 000h, 000h
   650 00014E0D 36000000000000      <1>
   651 00014E14 0000000000D86C366C- <1>     db  000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h, 000h
   651 00014E1D D8000000000000      <1>
   652 00014E24 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h
   652 00014E2D 44114411441144      <1>
   653 00014E34 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   653 00014E3D AA55AA55AA55AA      <1>
   654 00014E44 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h
   654 00014E4D 77DD77DD77DD77      <1>
   655 00014E54 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   655 00014E5D 18181818181818      <1>
   656 00014E64 18181818181818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   656 00014E6D 18181818181818      <1>
   657 00014E74 1818181818F818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   657 00014E7D 18181818181818      <1>
   658 00014E84 36363636363636F636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   658 00014E8D 36363636363636      <1>
   659 00014E94 00000000000000FE36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   659 00014E9D 36363636363636      <1>
   660 00014EA4 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   660 00014EAD 18181818181818      <1>
   661 00014EB4 3636363636F606F636- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   661 00014EBD 36363636363636      <1>
   662 00014EC4 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   662 00014ECD 36363636363636      <1>
   663 00014ED4 0000000000FE06F636- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   663 00014EDD 36363636363636      <1>
   664 00014EE4 3636363636F606FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   664 00014EED 00000000000000      <1>
   665 00014EF4 36363636363636FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   665 00014EFD 00000000000000      <1>
   666 00014F04 1818181818F818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   666 00014F0D 00000000000000      <1>
   667 00014F14 00000000000000F818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   667 00014F1D 18181818181818      <1>
   668 00014F24 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   668 00014F2D 00000000000000      <1>
   669 00014F34 18181818181818FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   669 00014F3D 00000000000000      <1>
   670 00014F44 00000000000000FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   670 00014F4D 18181818181818      <1>
   671 00014F54 181818181818181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   671 00014F5D 18181818181818      <1>
   672 00014F64 00000000000000FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   672 00014F6D 00000000000000      <1>
   673 00014F74 18181818181818FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   673 00014F7D 18181818181818      <1>
   674 00014F84 18181818181F181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   674 00014F8D 18181818181818      <1>
   675 00014F94 363636363636363736- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   675 00014F9D 36363636363636      <1>
   676 00014FA4 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   676 00014FAD 00000000000000      <1>
   677 00014FB4 00000000003F303736- <1>     db  000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   677 00014FBD 36363636363636      <1>
   678 00014FC4 3636363636F700FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   678 00014FCD 00000000000000      <1>
   679 00014FD4 0000000000FF00F736- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   679 00014FDD 36363636363636      <1>
   680 00014FE4 363636363637303736- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   680 00014FED 36363636363636      <1>
   681 00014FF4 0000000000FF00FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   681 00014FFD 00000000000000      <1>
   682 00015004 3636363636F700F736- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   682 0001500D 36363636363636      <1>
   683 00015014 1818181818FF00FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   683 0001501D 00000000000000      <1>
   684 00015024 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   684 0001502D 00000000000000      <1>
   685 00015034 0000000000FF00FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   685 0001503D 18181818181818      <1>
   686 00015044 00000000000000FF36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   686 0001504D 36363636363636      <1>
   687 00015054 363636363636363F00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   687 0001505D 00000000000000      <1>
   688 00015064 18181818181F181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   688 0001506D 00000000000000      <1>
   689 00015074 00000000001F181F18- <1>     db  000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   689 0001507D 18181818181818      <1>
   690 00015084 000000000000003F36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   690 0001508D 36363636363636      <1>
   691 00015094 36363636363636FF36- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   691 0001509D 36363636363636      <1>
   692 000150A4 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   692 000150AD 18181818181818      <1>
   693 000150B4 18181818181818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   693 000150BD 00000000000000      <1>
   694 000150C4 000000000000001F18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   694 000150CD 18181818181818      <1>
   695 000150D4 FFFFFFFFFFFFFFFFFF- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   695 000150DD FFFFFFFFFFFFFF      <1>
   696 000150E4 00000000000000FFFF- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   696 000150ED FFFFFFFFFFFFFF      <1>
   697 000150F4 F0F0F0F0F0F0F0F0F0- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   697 000150FD F0F0F0F0F0F0F0      <1>
   698 00015104 0F0F0F0F0F0F0F0F0F- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   698 0001510D 0F0F0F0F0F0F0F      <1>
   699 00015114 FFFFFFFFFFFFFF0000- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   699 0001511D 00000000000000      <1>
   700 00015124 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h
   700 0001512D D8DC7600000000      <1>
   701 00015134 000078CCCCCCD8CCC6- <1>     db  000h, 000h, 078h, 0cch, 0cch, 0cch, 0d8h, 0cch, 0c6h, 0c6h, 0c6h, 0cch, 000h, 000h, 000h, 000h
   701 0001513D C6C6CC00000000      <1>
   702 00015144 0000FEC6C6C0C0C0C0- <1>     db  000h, 000h, 0feh, 0c6h, 0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h
   702 0001514D C0C0C000000000      <1>
   703 00015154 00000000FE6C6C6C6C- <1>     db  000h, 000h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h
   703 0001515D 6C6C6C00000000      <1>
   704 00015164 000000FEC660301830- <1>     db  000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   704 0001516D 60C6FE00000000      <1>
   705 00015174 00000000007ED8D8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   705 0001517D D8D87000000000      <1>
   706 00015184 000000006666666666- <1>     db  000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h, 000h, 000h, 000h
   706 0001518D 7C6060C0000000      <1>
   707 00015194 0000000076DC181818- <1>     db  000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   707 0001519D 18181800000000      <1>
   708 000151A4 0000007E183C666666- <1>     db  000h, 000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   708 000151AD 3C187E00000000      <1>
   709 000151B4 000000386CC6C6FEC6- <1>     db  000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h
   709 000151BD C66C3800000000      <1>
   710 000151C4 0000386CC6C6C66C6C- <1>     db  000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h
   710 000151CD 6C6CEE00000000      <1>
   711 000151D4 00001E30180C3E6666- <1>     db  000h, 000h, 01eh, 030h, 018h, 00ch, 03eh, 066h, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h
   711 000151DD 66663C00000000      <1>
   712 000151E4 00000000007EDBDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh, 0dbh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h
   712 000151ED 7E000000000000      <1>
   713 000151F4 00000003067EDBDBF3- <1>     db  000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h, 0c0h, 000h, 000h, 000h, 000h
   713 000151FD 7E60C000000000      <1>
   714 00015204 00001C3060607C6060- <1>     db  000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 060h, 030h, 01ch, 000h, 000h, 000h, 000h
   714 0001520D 60301C00000000      <1>
   715 00015214 0000007CC6C6C6C6C6- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   715 0001521D C6C6C600000000      <1>
   716 00015224 00000000FE0000FE00- <1>     db  000h, 000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h
   716 0001522D 00FE0000000000      <1>
   717 00015234 0000000018187E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h
   717 0001523D 0000FF00000000      <1>
   718 00015244 00000030180C060C18- <1>     db  000h, 000h, 000h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h
   718 0001524D 30007E00000000      <1>
   719 00015254 0000000C1830603018- <1>     db  000h, 000h, 000h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h
   719 0001525D 0C007E00000000      <1>
   720 00015264 00000E1B1B18181818- <1>     db  000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   720 0001526D 18181818181818      <1>
   721 00015274 1818181818181818D8- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   721 0001527D D8D87000000000      <1>
   722 00015284 000000001818007E00- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   722 0001528D 18180000000000      <1>
   723 00015294 000000000076DC0076- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h
   723 0001529D DC000000000000      <1>
   724 000152A4 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   724 000152AD 00000000000000      <1>
   725 000152B4 000000000000001818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   725 000152BD 00000000000000      <1>
   726 000152C4 000000000000000018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   726 000152CD 00000000000000      <1>
   727 000152D4 000F0C0C0C0C0CEC6C- <1>     db  000h, 00fh, 00ch, 00ch, 00ch, 00ch, 00ch, 0ech, 06ch, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h
   727 000152DD 6C3C1C00000000      <1>
   728 000152E4 00D86C6C6C6C6C0000- <1>     db  000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   728 000152ED 00000000000000      <1>
   729 000152F4 0070D83060C8F80000- <1>     db  000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   729 000152FD 00000000000000      <1>
   730 00015304 000000007C7C7C7C7C- <1>     db  000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h, 000h, 000h, 000h
   730 0001530D 7C7C0000000000      <1>
   731 00015314 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   731 0001531D 00000000000000      <1>
   732                              <1> vgafont14alt:
   733 00015324 1D000000002466FF66- <1>     db  01dh, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 022h
   733 0001532D 24000000000022      <1>
   734 00015334 006363632200000000- <1>     db  000h, 063h, 063h, 063h, 022h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02bh, 000h
   734 0001533D 00000000002B00      <1>
   735 00015344 0000181818FF181818- <1>     db  000h, 000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 02dh, 000h, 000h
   735 0001534D 000000002D0000      <1>
   736 00015354 00000000FF00000000- <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 04dh, 000h, 000h, 0c3h
   736 0001535D 0000004D0000C3      <1>
   737 00015364 E7FFDBC3C3C3C3C300- <1>     db  0e7h, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh
   737 0001536D 0000540000FFDB      <1>
   738 00015374 9918181818183C0000- <1>     db  099h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h
   738 0001537D 00560000C3C3C3      <1>
   739 00015384 C3C3C3663C18000000- <1>     db  0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h
   739 0001538D 570000C3C3C3C3      <1>
   740 00015394 DBDBFF666600000058- <1>     db  0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h
   740 0001539D 0000C3C3663C18      <1>
   741 000153A4 3C66C3C30000005900- <1>     db  03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   741 000153AD 00C3C3C3663C18      <1>
   742 000153B4 18183C0000005A0000- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 061h
   742 000153BD FFC3860C183061      <1>
   743 000153C4 C3FF0000006D000000- <1>     db  0c3h, 0ffh, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh
   743 000153CD 0000E6FFDBDBDB      <1>
   744 000153D4 DB0000007600000000- <1>     db  0dbh, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   744 000153DD 00C3C3C3663C18      <1>
   745 000153E4 000000770000000000- <1>     db  000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h
   745 000153ED C3C3DBDBFF6600      <1>
   746 000153F4 000091000000006E3B- <1>     db  000h, 000h, 091h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h
   746 000153FD 1B7ED8DC770000      <1>
   747 00015404 009B0018187EC3C0C0- <1>     db  000h, 09bh, 000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h
   747 0001540D C37E1818000000      <1>
   748 00015414 9D0000C3663C18FF18- <1>     db  09dh, 000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 000h, 000h, 000h, 09eh
   748 0001541D FF18180000009E      <1>
   749 00015424 00FC66667C62666F66- <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 0f3h, 000h, 000h, 000h, 0f1h, 000h
   749 0001542D 66F3000000F100      <1>
   750 00015434 00181818FF18181800- <1>     db  000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 0ffh, 000h, 000h, 000h, 0f6h, 000h, 000h
   750 0001543D FF000000F60000      <1>
   751 00015444 18180000FF00001818- <1>     db  018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   751 0001544D 00000000            <1>
   752                              <1> vgafont16alt:
   753 00015451 1D00000000002466FF- <1>     db  01dh, 000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h
   753 0001545A 66240000000000      <1>
   754 00015461 003000003C66C3C3DB- <1>     db  000h, 030h, 000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h
   754 0001546A DBC3C3663C0000      <1>
   755 00015471 00004D0000C3E7FFFF- <1>     db  000h, 000h, 04dh, 000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h
   755 0001547A DBC3C3C3C3C300      <1>
   756 00015481 000000540000FFDB99- <1>     db  000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch
   756 0001548A 1818181818183C      <1>
   757 00015491 00000000560000C3C3- <1>     db  000h, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch
   757 0001549A C3C3C3C3C3663C      <1>
   758 000154A1 1800000000570000C3- <1>     db  018h, 000h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh
   758 000154AA C3C3C3C3DBDBFF      <1>
   759 000154B1 666600000000580000- <1>     db  066h, 066h, 000h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch
   759 000154BA C3C3663C18183C      <1>
   760 000154C1 66C3C3000000005900- <1>     db  066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   760 000154CA 00C3C3C3663C18      <1>
   761 000154D1 1818183C000000005A- <1>     db  018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h
   761 000154DA 0000FFC3860C18      <1>
   762 000154E1 3060C1C3FF00000000- <1>     db  030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h
   762 000154EA 6D0000000000E6      <1>
   763 000154F1 FFDBDBDBDBDB000000- <1>     db  0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h
   763 000154FA 00760000000000      <1>
   764 00015501 C3C3C3C3663C180000- <1>     db  0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h
   764 0001550A 00007700000000      <1>
   765 00015511 00C3C3C3DBDBFF6600- <1>     db  000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h, 078h, 000h, 000h, 000h
   765 0001551A 00000078000000      <1>
   766 00015521 0000C3663C183C66C3- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h, 091h, 000h, 000h
   766 0001552A 00000000910000      <1>
   767 00015531 0000006E3B1B7ED8DC- <1>     db  000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h, 09bh, 000h
   767 0001553A 77000000009B00      <1>
   768 00015541 18187EC3C0C0C0C37E- <1>     db  018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 09dh
   768 0001554A 1818000000009D      <1>
   769 00015551 0000C3663C18FF18FF- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   769 0001555A 18181800000000      <1>
   770 00015561 9E00FC66667C62666F- <1>     db  09eh, 000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h
   770 0001556A 666666F3000000      <1>
   771 00015571 00AB00C0C0C2C6CC18- <1>     db  000h, 0abh, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh
   771 0001557A 3060CE9B060C1F      <1>
   772 00015581 0000AC00C0C0C2C6CC- <1>     db  000h, 000h, 0ach, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h
   772 0001558A 183066CE963E06      <1>
   773 00015591 06000000            <1>     db  006h, 000h, 000h, 000h
  2646                                  
  2647 00015595 90                      align 2
  2648                                  
  2649                                  ; EPOCH Variables
  2650                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
  2651                                  ; 09/04/2013 epoch variables
  2652                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
  2653                                  ;
  2654 00015596 B207                    year: 	dw 1970
  2655 00015598 0100                    month: 	dw 1
  2656 0001559A 0100                    day: 	dw 1
  2657 0001559C 0000                    hour: 	dw 0
  2658 0001559E 0000                    minute: dw 0
  2659 000155A0 0000                    second: dw 0
  2660                                  
  2661                                  DMonth:
  2662 000155A2 0000                    	dw 0
  2663 000155A4 1F00                    	dw 31
  2664 000155A6 3B00                    	dw 59
  2665 000155A8 5A00                    	dw 90
  2666 000155AA 7800                    	dw 120
  2667 000155AC 9700                    	dw 151
  2668 000155AE B500                    	dw 181
  2669 000155B0 D400                    	dw 212
  2670 000155B2 F300                    	dw 243
  2671 000155B4 1101                    	dw 273
  2672 000155B6 3001                    	dw 304
  2673 000155B8 4E01                    	dw 334
  2674                                  
  2675                                  ; 20/02/2017
  2676                                  KERNELFSIZE  equ $  ; 04/07/2016
  2677                                  
  2678                                  bss_start:
  2679                                  
  2680                                  ABSOLUTE bss_start
  2681                                  
  2682 000155BA <res 00000006>          alignb 8 ; 25/12/2016
  2683                                  
  2684                                  	; 15/04/2016
  2685                                  	; TRDOS 386 (TRDOS v2.0)
  2686                                  	; 	80 interrupts 	
  2687                                  	; 11/03/2015
  2688                                  	; Interrupt Descriptor Table (20/08/2014)
  2689                                  idt:
  2690                                  	;resb	64*8 ; INT 0 to INT 3Fh
  2691                                  	; 15/04/2016
  2692 000155C0 <res 00000280>          	resb	80*8 ; INT 0 to INT 4Fh
  2693                                  
  2694                                  idt_end:
  2695                                  
  2696                                  ;alignb 4
  2697                                  
  2698                                  task_state_segment:
  2699                                  	; 24/03/2015
  2700 00015840 <res 00000002>          tss.link:   resw 1
  2701 00015842 <res 00000002>          	    resw 1
  2702                                  ; tss offset 4	
  2703 00015844 <res 00000004>          tss.esp0:   resd 1
  2704 00015848 <res 00000002>          tss.ss0:    resw 1
  2705 0001584A <res 00000002>          	    resw 1	
  2706 0001584C <res 00000004>          tss.esp1:   resd 1
  2707 00015850 <res 00000002>          tss.ss1:    resw 1
  2708 00015852 <res 00000002>          	    resw 1 	
  2709 00015854 <res 00000004>          tss.esp2:   resd 1
  2710 00015858 <res 00000002>          tss.ss2:    resw 1
  2711 0001585A <res 00000002>          	    resw 1
  2712                                  ; tss offset 28
  2713 0001585C <res 00000004>          tss.CR3:    resd 1
  2714 00015860 <res 00000004>          tss.eip:    resd 1
  2715 00015864 <res 00000004>          tss.eflags: resd 1
  2716                                  ; tss offset 40
  2717 00015868 <res 00000004>          tss.eax:    resd 1		 		
  2718 0001586C <res 00000004>          tss.ecx:    resd 1
  2719 00015870 <res 00000004>          tss.edx:    resd 1
  2720 00015874 <res 00000004>          tss.ebx:    resd 1
  2721 00015878 <res 00000004>          tss.esp:    resd 1
  2722 0001587C <res 00000004>          tss.ebp:    resd 1
  2723 00015880 <res 00000004>          tss.esi:    resd 1
  2724 00015884 <res 00000004>          tss.edi:    resd 1
  2725                                  ; tss offset 72
  2726 00015888 <res 00000002>          tss.ES:     resw 1
  2727 0001588A <res 00000002>          	    resw 1	
  2728 0001588C <res 00000002>          tss.CS:	    resw 1
  2729 0001588E <res 00000002>          	    resw 1
  2730 00015890 <res 00000002>          tss.SS:	    resw 1
  2731 00015892 <res 00000002>          	    resw 1
  2732 00015894 <res 00000002>          tss.DS:	    resw 1
  2733 00015896 <res 00000002>          	    resw 1
  2734 00015898 <res 00000002>          tss.FS:	    resw 1
  2735 0001589A <res 00000002>          	    resw 1
  2736 0001589C <res 00000002>          tss.GS:	    resw 1
  2737 0001589E <res 00000002>          	    resw 1		
  2738 000158A0 <res 00000002>          tss.LDTR:   resw 1
  2739 000158A2 <res 00000002>          	    resw 1
  2740                                  ; tss offset 100		
  2741 000158A4 <res 00000002>          	    resw 1		
  2742 000158A6 <res 00000002>          tss.IOPB:   resw 1
  2743                                  ; tss offset 104 
  2744                                  tss_end:
  2745                                  
  2746 000158A8 <res 00000004>          k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
  2747                                  		    ; (Physical address = Virtual address)	 	
  2748 000158AC <res 00000004>          memory_size: resd 1 ; memory size in pages
  2749 000158B0 <res 00000004>          free_pages:  resd 1 ; number of free pages		
  2750 000158B4 <res 00000004>          next_page:   resd 1 ; offset value in M.A.T. for
  2751                                  		    ; first free page search
  2752 000158B8 <res 00000004>          last_page:   resd 1 ; offset value in M.A.T. which
  2753                                  		    ; next free page search will be
  2754                                  		    ; stopped after it. (end of M.A.T.)
  2755 000158BC <res 00000004>          first_page:  resd 1 ; offset value in M.A.T. which
  2756                                  		    ; first free page search
  2757                                  		    ; will be started on it. (for user)
  2758 000158C0 <res 00000004>          mat_size:    resd 1 ; Memory Allocation Table size in pages		
  2759                                  
  2760                                  ; 02/09/2014 (Retro UNIX 386 v1)
  2761                                  ; 04/12/2013 (Retro UNIX 8086 v1)
  2762 000158C4 <res 00000002>          CRT_START:   resw 1 	  ; starting address in regen buffer
  2763                                  			  ; NOTE: active page only	
  2764 000158C6 <res 00000010>          CURSOR_POSN: resw 8 ; cursor positions for video pages
  2765                                  ACTIVE_PAGE: 
  2766 000158D6 <res 00000001>          ptty: 	     resb 1 ; current tty
  2767                                  ; 01/07/2015 - 29/01/2016
  2768 000158D7 <res 00000001>          ccolor:	     resb 1 ; current color attribute
  2769                                  ; 26/10/2015
  2770                                  ; 07/09/2014
  2771 000158D8 <res 00000014>          ttychr:      resw ntty+2 ; Character buffer (multiscreen)
  2772                                  
  2773                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
  2774 000158EC <res 00000004>          p_time:      resd 1     ; present time (for systime & sysmdate)
  2775                                  
  2776                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
  2777                                  ; (open mode locks for pseudo TTYs)
  2778                                  ; [ major tty locks (return error in any conflicts) ]
  2779 000158F0 <res 00000014>          ttyl:        resw ntty+2 ; opening locks for TTYs.
  2780                                  
  2781                                  ; 15/04/2015 (Retro UNIX 386 v1)
  2782                                  ; 22/09/2013 (Retro UNIX 8086 v1)
  2783 00015904 <res 0000000A>          wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
  2784                                  ; 15/04/2015 (Retro UNIX 386 v1)
  2785                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
  2786                                  ;; 0 means serial port is not available 
  2787                                  ;;comprm: ; 25/06/2014
  2788 0001590E <res 00000001>          com1p:       resb 1  ;;0E3h
  2789 0001590F <res 00000001>          com2p:       resb 1  ;;0E3h
  2790                                  
  2791                                  ; 17/11/2015
  2792                                  ; request for response (from the terminal)	
  2793 00015910 <res 00000002>          req_resp:    resw 1 			
  2794                                  ; 07/11/2015
  2795 00015912 <res 00000001>          ccomport:    resb 1 ; current COM (serial) port
  2796                                  		    ; (0= COM1, 1= COM2)
  2797                                  ; 09/11/2015
  2798 00015913 <res 00000001>          comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
  2799                                  ; 07/11/2015
  2800 00015914 <res 00000002>          rchar:	     resw 1 ; last received char for COM 1 and COM 2		
  2801 00015916 <res 00000002>          schar:	     resw 1 ; last sent char for COM 1 and COM 2
  2802                                  
  2803                                  ; 22/08/2014 (RTC)
  2804                                  ; (Packed BCD)
  2805 00015918 <res 00000001>          time_seconds: resb 1
  2806 00015919 <res 00000001>          time_minutes: resb 1
  2807 0001591A <res 00000001>          time_hours:   resb 1
  2808 0001591B <res 00000001>          date_wday:    resb 1
  2809 0001591C <res 00000001>          date_day:     resb 1
  2810 0001591D <res 00000001>          date_month:   resb 1			
  2811 0001591E <res 00000001>          date_year:    resb 1
  2812 0001591F <res 00000001>          date_century: resb 1
  2813                                  
  2814                                  ; 24/01/2016
  2815 00015920 <res 00000004>          RTC_LH:	       resd 1
  2816 00015924 <res 00000001>          RTC_WAIT_FLAG: resb 1
  2817 00015925 <res 00000001>          USER_FLAG:     resb 1
  2818                                  ; 19/05/2016
  2819                                  ;RTC_second:
  2820 00015926 <res 00000001>          RTC_2Hz:       resb 1 ;  from 2Hz interrupt to 1Hz timer event function	
  2821                                  
  2822                                  %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 00015927 <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 00015928 <res 00000002>      <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
    31 0001592A <res 00000002>      <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
    32 0001592C <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 0001592D <res 00000001>      <1> SEEK_STATUS:	resb	1
    39 0001592E <res 00000001>      <1> MOTOR_STATUS:	resb	1
    40 0001592F <res 00000001>      <1> MOTOR_COUNT:	resb	1
    41 00015930 <res 00000001>      <1> DSKETTE_STATUS:	resb	1
    42 00015931 <res 00000007>      <1> NEC_STATUS:	resb	7
    43                              <1> 
    44                              <1> ;----------------------------------------
    45                              <1> ;	ADDITIONAL MEDIA DATA		:
    46                              <1> ;----------------------------------------
    47                              <1> 
    48 00015938 <res 00000001>      <1> LASTRATE:	resb 	1
    49 00015939 <res 00000001>      <1> HF_STATUS:	resb 	1
    50 0001593A <res 00000001>      <1> HF_ERROR:	resb 	1
    51 0001593B <res 00000001>      <1> HF_INT_FLAG:	resb 	1
    52 0001593C <res 00000001>      <1> HF_CNTRL:	resb 	1
    53 0001593D <res 00000004>      <1> DSK_STATE:	resb 	4
    54 00015941 <res 00000002>      <1> DSK_TRK:	resb 	2
    55                              <1> 
    56                              <1> ;----------------------------------------
    57                              <1> ;	FIXED DISK DATA AREAS		:
    58                              <1> ;----------------------------------------
    59                              <1> 
    60 00015943 <res 00000001>      <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
    61 00015944 <res 00000001>      <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
    62 00015945 <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 00015946 <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 00015948 <res 00000004>      <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
    73 0001594C <res 00000004>      <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
    74 00015950 <res 00000004>      <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
    75 00015954 <res 00000004>      <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
    76                              <1> 
    77                              <1> ; 03/01/2015
    78 00015958 <res 00000001>      <1> LBAMode:     	resb	1
    79                              <1> 
    80                              <1> ; *****************************************************************************
  2823                                  
  2824                                  ;;; Real Mode Data (10/07/2015 - BSS)
  2825                                  
  2826                                  ;alignb 2
  2827                                  
  2828                                  ; 10/01/2016
  2829                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.2) - UNINITIALIZED DATA : trdoskx.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 20/07/2020
     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 00015959 <res 00000003>      <1> alignb 4
    20                              <1> 
    21                              <1> ; MAINPROG.ASM
    22 0001595C <res 00000004>      <1> MainProgCfg_FileSize:   resd 1 ; 14/04/2016
    23 00015960 <res 00000004>      <1> MainProgCfg_LineOffset: resd 1 ; 14/04/2016
    24                              <1> 
    25 00015964 <res 00000004>      <1> Current_VolSerial: resd 1
    26                              <1> 
    27 00015968 <res 00000004>      <1> Current_Dir_FCluster: resd 1
    28                              <1> 
    29 0001596C <res 00000001>      <1> Current_Dir_Level: resb 1
    30 0001596D <res 00000001>      <1> Current_FATType: resb 1
    31 0001596E <res 00000001>      <1> Current_Drv: resb 1
    32 0001596F <res 00000001>      <1> Current_Dir_Drv:   resb 1 ; '?'
    33 00015970 <res 00000001>      <1>                    resb 1 ; ':'
    34 00015971 <res 00000001>      <1> Current_Dir_Root:  resb 1 ; '/' 
    35 00015972 <res 0000005A>      <1> Current_Directory: resb 90
    36 000159CC <res 00000001>      <1> End_Of_Current_Dir_Str: resb 1
    37 000159CD <res 00000001>      <1> Current_Dir_StrLen: resb 1   
    38                              <1> 
    39 000159CE <res 00000001>      <1> CursorColumn: 	resb 1
    40 000159CF <res 00000001>      <1> CmdArgStart:    resb 1
    41                              <1> 
    42                              <1> ; 03/02/2016
    43 000159D0 <res 0000004E>      <1> Remark:		resb 78
    44                              <1> 
    45 00015A1E <res 00000050>      <1> CommandBuffer: 	resb 80
    46                              <1> 
    47 00015A6E <res 00000100>      <1> TextBuffer:	resb 256
    48                              <1> 
    49                              <1> MasterBootBuff:
    50 00015B6E <res 000001BE>      <1> MasterBootCode: resb 1BEh
    51 00015D2C <res 00000040>      <1> PartitionTable: resb 64
    52 00015D6C <res 00000002>      <1> MBIDCode: resw 1
    53                              <1> 
    54                              <1> PTable_Buffer:
    55 00015D6E <res 00000040>      <1> PTable_hd0: resb 64
    56 00015DAE <res 00000040>      <1> PTable_hd1: resb 64
    57 00015DEE <res 00000040>      <1> PTable_hd2: resb 64
    58 00015E2E <res 00000040>      <1> PTable_hd3: resb 64
    59                              <1> ; 15/07/2020
    60                              <1> ;PTable_ep0: resb 64
    61                              <1> ;PTable_ep1: resb 64
    62                              <1> ;PTable_ep2: resb 64
    63                              <1> ;PTable_ep3: resb 64
    64                              <1> 
    65 00015E6E <res 00000001>      <1> scount:	resb 1 ; 16/05/2016 (diskio.s, 'int33h:')	
    66 00015E6F <res 00000001>      <1> HD_LBA_yes: resb 1
    67 00015E70 <res 00000001>      <1> PP_Counter: resb 1
    68 00015E71 <res 00000001>      <1> EP_Counter: resb 1
    69                              <1> 
    70 00015E72 <res 00000004>      <1> EP_StartSector: resd 1
    71                              <1> 	; 15/07/2020	
    72                              <1>                 ;resd 1
    73                              <1>                 ;resd 1
    74                              <1>                 ;resd 1
    75                              <1> 
    76                              <1> ; 20/07/2020
    77 00015E76 <res 00000200>      <1> DOSBootSectorBuff: resb 512
    78                              <1> ; 15/07/2020
    79                              <1> ;DOSBootSectorBuff: resb 446 ; 1BEh
    80                              <1> ;MiniPartitionTable: resb 64 ;  40h
    81                              <1> ;MiniPartitionMagic: resw  1 ;  02h 		
    82                              <1> 
    83                              <1> FAT_BuffDescriptor:
    84 00016076 <res 00000004>      <1> FAT_CurrentCluster: resd 1
    85 0001607A <res 00000001>      <1> FAT_BuffValidData: resb 1
    86 0001607B <res 00000001>      <1> FAT_BuffDrvName: resb 1
    87 0001607C <res 00000002>      <1> FAT_BuffOffset: resw 1
    88 0001607E <res 00000004>      <1> FAT_BuffSector: resd 1
    89                              <1> 
    90 00016082 <res 00000004>      <1> FAT_ClusterCounter: resd 1
    91 00016086 <res 00000004>      <1> LastCluster: resd 1
    92                              <1> 
    93                              <1> ; 16/05/2016
    94                              <1> ;; 18/03/2016 (TRDOS v2.0)
    95                              <1> ;ClusterBuffer_Valid: resb 1
    96                              <1> 
    97                              <1> Dir_BuffDescriptor:
    98 0001608A <res 00000001>      <1> DirBuff_DRV: resb 1
    99 0001608B <res 00000001>      <1> DirBuff_FATType: resb 1
   100 0001608C <res 00000001>      <1> DirBuff_ValidData: resb 1
   101 0001608D <res 00000002>      <1> DirBuff_CurrentEntry: resw 1
   102 0001608F <res 00000002>      <1> DirBuff_LastEntry: resw 1
   103 00016091 <res 00000004>      <1> DirBuff_Cluster: resd 1 
   104 00016095 <res 00000002>      <1> DirBuffer_Size: resw 1
   105                              <1> ;DirBuff_EntryCounter: resw 1
   106                              <1> 
   107                              <1> ; 01/02/2016
   108                              <1> ; these are on (real mode) segment 8000h and later
   109                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
   110                              <1> ; Dir_Buffer:	resb 512*32
   111                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
   112                              <1> 
   113                              <1> ; 18/01/2016
   114                              <1> 
   115 00016097 <res 00000004>      <1> FreeClusterCount: resd 1
   116                              <1> 
   117 0001609B <res 00000004>      <1> VolSize_Unit1:   resd 1
   118 0001609F <res 00000004>      <1> VolSize_Unit2:   resd 1
   119                              <1> 
   120 000160A3 <res 00000004>      <1> Vol_Tot_Sec_Str_Start:	    resd 1
   121 000160A7 <res 0000000A>      <1> Vol_Tot_Sec_Str: 	    resb 10
   122 000160B1 <res 00000001>      <1> Vol_Tot_Sec_Str_End:	    resb 1
   123 000160B2 <res 00000001>      <1> resb 1
   124 000160B3 <res 00000004>      <1> Vol_Free_Sectors_Str_Start: resd 1
   125 000160B7 <res 0000000A>      <1> Vol_Free_Sectors_Str:	    resb 10				
   126 000160C1 <res 00000001>      <1> Vol_Free_Sectors_Str_End:   resb 1
   127                              <1> 
   128                              <1> ; 10/02/2016
   129 000160C2 <res 00000001>      <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   130                              <1> 
   131                              <1> ; 24/01/2016
   132 000160C3 <res 00000080>      <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
   133                              <1> ; 06/02/2016
   134 00016143 <res 00000004>      <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
   135 00016147 <res 00000001>      <1> CCD_Level:	resb 1 ; DIR.ASM
   136 00016148 <res 00000001>      <1> Last_Dir_Level:	resb 1 ; DIR.ASM
   137                              <1> ;
   138 00016149 <res 00000002>      <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
   139 0001614B <res 00000004>      <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
   140 0001614F <res 00000002>      <1> CDLF_DEType:	resw 1 ; DIR.ASM
   141                              <1> ;
   142 00016151 <res 00000001>      <1> CD_COMMAND:	resb 1 ; DIR.ASM
   143                              <1> 
   144 00016152 <res 00000002>      <1> alignb 4
   145                              <1> 
   146                              <1> ; 29/01/2016
   147 00016154 <res 00000001>      <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   148                              <1> 
   149                              <1> ;alignb 4
   150                              <1> ; 23/02/2016
   151 00016155 <res 00000001>      <1> disk_rw_op:	resb 1 ;  0 = disk read, 1 = disk write
   152                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
   153                              <1> ; 31/01/2016
   154 00016156 <res 00000001>      <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
   155 00016157 <res 00000001>      <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
   156 00016158 <res 00000004>      <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
   157                              <1> 
   158                              <1> ; 06/02/2016 (long name)
   159 0001615C <res 00000002>      <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
   160 0001615E <res 00000002>      <1> AmbiguousFileName: resw 1 ; DIR.ASM
   161 00016160 <res 00000001>      <1> PreviousAttr:	   resb 1 ; DIR.ASM
   162                              <1> ;	
   163 00016161 <res 00000001>      <1> LongNameFound:   resb 1	  ; DIR.ASM
   164 00016162 <res 00000001>      <1> LFN_EntryLength: resb 1   ; DIR.ASM
   165 00016163 <res 00000001>      <1> LFN_CheckSum:    resb 1   ; DIR.ASM
   166 00016164 <res 00000084>      <1> LongFileName:    resb 132 ; DIR.ASM
   167                              <1> 
   168                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
   169 000161E8 <res 00000001>      <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
   170 000161E9 <res 00000001>      <1> PATH_Level:	 resb 1 ; DIR.ASM
   171                              <1> 
   172                              <1> ; 07/02/2016
   173 000161EA <res 0000000D>      <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
   174                              <1> 
   175                              <1> ; 10/02/2016
   176 000161F7 <res 0000000D>      <1> Dir_Entry_Name:	resb 13 ; DIR.ASM
   177                              <1> 
   178                              <1> alignb 2
   179                              <1> 
   180 00016204 <res 00000002>      <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
   181                              <1> 
   182                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
   183                              <1> ; 08/02/2016
   184                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
   185 00016206 <res 00000001>      <1> FindFile_Drv:		  resb 1
   186 00016207 <res 00000041>      <1> FindFile_Directory:	  resb 65
   187 00016248 <res 0000000D>      <1> FindFile_Name:		  resb 13
   188                              <1> FindFile_LongNameEntryLength:
   189 00016255 <res 00000001>      <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
   190                              <1> ;Above 80 bytes form
   191                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
   192 00016256 <res 00000002>      <1> FindFile_AttributesMask:  resw 1
   193 00016258 <res 00000020>      <1> FindFile_DirEntry:	  resb 32
   194 00016278 <res 00000004>      <1> FindFile_DirFirstCluster: resd 1
   195 0001627C <res 00000004>      <1> FindFile_DirCluster:	  resd 1
   196 00016280 <res 00000002>      <1> FindFile_DirEntryNumber:  resw 1
   197 00016282 <res 00000002>      <1> FindFile_MatchCounter:	  resw 1
   198 00016284 <res 00000002>      <1> FindFile_Reserved:	  resw 1 ; 06/03/2016
   199                              <1> 
   200 00016286 <res 00000004>      <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
   201 0001628A <res 00000004>      <1> Last_Slash_Pos: resd 1	; DIR.ASM 
   202                              <1> 
   203                              <1> ; 10/02/2016
   204 0001628E <res 00000002>      <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
   205 00016290 <res 00000002>      <1> Dir_Count:      resw 1
   206 00016292 <res 00000004>      <1> Total_FSize:    resd 1
   207 00016296 <res 00000004>      <1> TFS_Dec_Begin:  resd 1
   208 0001629A <res 0000000A>      <1>                 resb 10
   209 000162A4 <res 00000001>      <1> TFS_Dec_End:    resb 1
   210                              <1> 
   211 000162A5 <res 00000001>      <1> PrintDir_RowCounter: resb 1
   212                              <1> 
   213 000162A6 <res 00000002>      <1> alignb 4
   214                              <1> ; 15/02/2015 ('show' command variables)
   215 000162A8 <res 00000004>      <1> Show_FDT:	resd 1
   216 000162AC <res 00000004>      <1> Show_LDDDT:	resd 1
   217 000162B0 <res 00000004>      <1> Show_Cluster:	resd 1
   218 000162B4 <res 00000004>      <1> Show_FileSize:	resd 1
   219 000162B8 <res 00000004>      <1> Show_FilePointer: resd 1
   220 000162BC <res 00000002>      <1> Show_ClusterPointer: resw 1
   221 000162BE <res 00000002>      <1> Show_ClusterSize: resw 1
   222 000162C0 <res 00000001>      <1> Show_RowCount:	resb 1
   223                              <1> 
   224 000162C1 <res 00000003>      <1> alignb 4
   225                              <1> ; 21/02/2016
   226 000162C4 <res 00000004>      <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
   227                              <1> ; 27/02/2016
   228                              <1> ; DIR.ASM (09/10/2011)
   229 000162C8 <res 00000004>      <1> DelFile_FCluster:	resd 1
   230 000162CC <res 00000002>      <1> DelFile_EntryCounter:	resw 1
   231 000162CE <res 00000001>      <1> DelFile_LNEL:		resb 1
   232 000162CF <res 00000001>      <1> resb 1
   233                              <1> 
   234                              <1> ; DIR.ASM
   235 000162D0 <res 00000004>      <1> mkdir_DirName_Offset: 	resd 1
   236 000162D4 <res 00000004>      <1> mkdir_FFCluster:	resd 1
   237 000162D8 <res 00000004>      <1> mkdir_LastDirCluster:	resd 1
   238 000162DC <res 00000004>      <1> mkdir_FreeSectors:	resd 1
   239 000162E0 <res 00000002>      <1> mkdir_attrib:		resw 1 
   240 000162E2 <res 00000001>      <1> mkdir_SecPerClust:	resb 1
   241 000162E3 <res 00000001>      <1> mkdir_add_new_cluster:	resb 1
   242 000162E4 <res 0000000D>      <1> mkdir_Name:		resb 13
   243 000162F1 <res 00000002>      <1> resw 1 ; 01/03/2016
   244                              <1> ; 27/02/2016
   245 000162F3 <res 00000001>      <1> RmDir_MultiClusters:	resb 1  
   246 000162F4 <res 00000004>      <1> RmDir_DirEntryOffset:	resd 1 ; 01/03/2016 (word -> dword)
   247 000162F8 <res 00000004>      <1> RmDir_ParentDirCluster: resd 1
   248 000162FC <res 00000004>      <1> RmDir_DirLastCluster:   resd 1
   249 00016300 <res 00000004>      <1> RmDir_PreviousCluster:  resd 1
   250                              <1> ; 22/02/2016
   251 00016304 <res 00000001>      <1> UPDLMDT_CDirLevel:	resb 1
   252 00016305 <res 00000004>      <1> UPDLMDT_CDirFCluster:	resd 1
   253                              <1> 	
   254 00016309 <res 00000003>      <1> alignb 4
   255                              <1> ; DRV_FAT.ASM ; 21/08/2011
   256 0001630C <res 00000004>      <1> gffc_next_free_cluster:  resd 1
   257 00016310 <res 00000004>      <1> gffc_first_free_cluster: resd 1
   258 00016314 <res 00000004>      <1> gffc_last_free_cluster:  resd 1
   259                              <1> 
   260                              <1> ;29/04/2016
   261                              <1> Cluster_Index: ; resd 1
   262                              <1> ; 22/02/2016
   263 00016318 <res 00000004>      <1> ClusterValue:	resd 1
   264                              <1> ; 04/03/2016
   265 0001631C <res 00000001>      <1> Attributes:	resb 1 
   266                              <1> ;;CFS_error:  resb 1 ;; 01/03/2016
   267 0001631D <res 00000001>      <1> resb 1
   268 0001631E <res 00000001>      <1> CFS_OPType: resb 1
   269 0001631F <res 00000001>      <1> CFS_Drv:    resb 1
   270 00016320 <res 00000004>      <1> CFS_CC:	    resd 1
   271 00016324 <res 00000004>      <1> CFS_FAT32FSINFOSEC: resd 1
   272 00016328 <res 00000004>      <1> CFS_FAT32FC: resd 1
   273                              <1> 
   274                              <1> ; 27/02/2016
   275                              <1> ;alignb 4
   276 0001632C <res 00000004>      <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
   277                              <1> ; 22/10/2016
   278 00016330 <res 00000004>      <1> glc_index:	 resd 1 ;  Last Cluster Index (22/10/2016)	
   279                              <1> 
   280                              <1> ; DIR.ASM
   281 00016334 <res 00000002>      <1> DLN_EntryNumber: resw 1
   282 00016336 <res 00000001>      <1> DLN_40h:	 resb 1
   283                              <1> ; 28/02/2016
   284 00016337 <res 00000001>      <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
   285                              <1> 
   286                              <1> alignb 4
   287                              <1> ; DIR.ASM (09/10/2011)
   288 00016338 <res 00000002>      <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
   289 0001633A <res 00000002>      <1> LCDE_ClusterSN:  resw 1
   290 0001633C <res 00000004>      <1> LCDE_Cluster: 	 resd 1
   291 00016340 <res 00000004>      <1> LCDE_ByteOffset: resd 1
   292                              <1> 
   293                              <1> ;alignb4
   294                              <1> ; 06/03/2016 (word -> dword)
   295                              <1> ; CMD_INTR.ASM (01/08/2010)
   296 00016344 <res 00000004>      <1> SourceFilePath:	     resd 1
   297 00016348 <res 00000004>      <1> DestinationFilePath: resd 1
   298                              <1> 
   299                              <1> ;alignb 4
   300                              <1> ; 06/03/2016
   301                              <1> ; FILE.ASM (09/10/2011)
   302                              <1> ;Source File Structure (same with 'Find File' Structure)
   303 0001634C <res 00000001>      <1> SourceFile_Drv:			resb 1
   304 0001634D <res 00000041>      <1> SourceFile_Directory:		resb 65
   305 0001638E <res 0000000D>      <1> SourceFile_Name:		resb 13
   306                              <1> SourceFile_LongNameEntryLength: 
   307 0001639B <res 00000001>      <1> SourceFile_LongNameYes:		resb 1 ; Sign for longname procedures
   308                              <1> ;Above 80 bytes
   309                              <1> ;is TR-DOS Source File FullName Format/Structure
   310 0001639C <res 00000002>      <1> SourceFile_AttributesMask:	resw 1
   311 0001639E <res 00000020>      <1> SourceFile_DirEntry:		resb 32
   312 000163BE <res 00000004>      <1> SourceFile_DirFirstCluster:	resd 1
   313 000163C2 <res 00000004>      <1> SourceFile_DirCluster:		resd 1
   314 000163C6 <res 00000002>      <1> SourceFile_DirEntryNumber:	resw 1
   315 000163C8 <res 00000002>      <1> SourceFile_MatchCounter:	resw 1
   316                              <1> ; 16/03/2016
   317 000163CA <res 00000001>      <1> SourceFile_SecPerClust:		resb 1
   318 000163CB <res 00000001>      <1> SourceFile_Reserved:		resb 1
   319                              <1> ; Above is 128 bytes
   320                              <1> 
   321                              <1> ;Destination File Structure (same with 'Find File' Structure)
   322 000163CC <res 00000001>      <1> DestinationFile_Drv:		resb 1
   323 000163CD <res 00000041>      <1> DestinationFile_Directory: 	resb 65
   324 0001640E <res 0000000D>      <1> DestinationFile_Name:		resb 13
   325                              <1> DestinationFile_LongNameEntryLength:
   326 0001641B <res 00000001>      <1> DestinationFile_LongNameYes:	resb 1 ; Sign for longname procedures
   327                              <1> ;Above 80 bytes
   328                              <1> ;is TR-DOS Destination File FullName Format/Structure
   329 0001641C <res 00000002>      <1> DestinationFile_AttributesMask: resw 1
   330 0001641E <res 00000020>      <1> DestinationFile_DirEntry:	resb 32
   331 0001643E <res 00000004>      <1> DestinationFile_DirFirstCluster: resd 1
   332 00016442 <res 00000004>      <1> DestinationFile_DirCluster:	resd 1
   333 00016446 <res 00000002>      <1> DestinationFile_DirEntryNumber: resw 1
   334 00016448 <res 00000002>      <1> DestinationFile_MatchCounter:	resw 1
   335                              <1> ; 16/03/2016
   336 0001644A <res 00000001>      <1> DestinationFile_SecPerClust:	resb 1
   337 0001644B <res 00000001>      <1> DestinationFile_Reserved:	resb 1
   338                              <1> ; Above is 128 bytes
   339                              <1> 
   340                              <1> ; 24/04/2016
   341 0001644C <res 00000002>      <1> resw 1
   342                              <1> 
   343                              <1> ; 10/03/2016
   344                              <1> ; FILE.ASM
   345 0001644E <res 00000001>      <1> move_cmd_phase:	   resb 1
   346 0001644F <res 00000001>      <1> msftdf_sf_df_drv:  resb 1
   347 00016450 <res 00000004>      <1> msftdf_drv_offset: resd 1
   348                              <1> 
   349                              <1> ; 11/03/2016
   350                              <1> ; DRV_FAT.ASM (21/08/2011)
   351 00016454 <res 00000004>      <1> FAT_anc_LCluster:  resd 1
   352 00016458 <res 00000004>      <1> FAT_anc_FFCluster: resd 1
   353                              <1> 
   354                              <1> ;alignb 4
   355                              <1> 
   356                              <1> ; 14/03/2016
   357                              <1> ; TRDOS 386 = TRDOS v2.0 feature only !
   358                              <1> ; 'allocate_memory_block' in 'memory.s'
   359 0001645C <res 00000004>      <1> mem_ipg_count:	resd 1 ; page count (for contiguous allocation)
   360 00016460 <res 00000004>      <1> mem_pg_count:	resd 1 ; page count (for count down)
   361 00016464 <res 00000004>      <1> mem_aperture:	resd 1 ; contiguous free pages (current)
   362 00016468 <res 00000004>      <1> mem_max_aperture: resd 1 ; maximum value of contiguous free pages
   363 0001646C <res 00000004>      <1> mem_pg_pos:	resd 1 ; mem. position (page #) of current aperture
   364 00016470 <res 00000004>      <1> mem_max_pg_pos: resd 1 ; mem. position (page #) of max. aperture
   365                              <1> 
   366                              <1> ; 15/03/2016
   367                              <1> ; FILE.ASM ('copy_source_file_to_destination_file')
   368 00016474 <res 00000001>      <1> copy_cmd_phase:       resb 1
   369 00016475 <res 00000001>      <1> csftdf_rw_err:	      resb 1
   370 00016476 <res 00000001>      <1> DestinationFileFound: resb 1
   371 00016477 <res 00000001>      <1> csftdf_cdrv: 	      resb 1
   372 00016478 <res 00000004>      <1> csftdf_filesize:      resd 1
   373                              <1> ; TRDOS386 (TRDOS v2.0)
   374 0001647C <res 00000004>      <1> csftdf_sf_mem_addr:   resd 1
   375 00016480 <res 00000004>      <1> csftdf_sf_mem_bsize:  resd 1
   376                              <1> ;
   377                              <1> 
   378 00016484 <res 00000004>      <1> csftdf_sf_cluster:    resd 1 ; 16/03/2016
   379 00016488 <res 00000004>      <1> csftdf_df_cluster:    resd 1
   380                              <1> ; 16/03/2016
   381 0001648C <res 00000004>      <1> csftdf_r_size:        resd 1
   382 00016490 <res 00000004>      <1> csftdf_w_size:        resd 1
   383 00016494 <res 00000004>      <1> csftdf_sf_rbytes:     resd 1
   384 00016498 <res 00000004>      <1> csftdf_df_wbytes:     resd 1
   385 0001649C <res 00000001>      <1> csftdf_percentage:    resb 1
   386                              <1> ; 17/03/2016
   387 0001649D <res 00000001>      <1> csftdf_videopage:     resb 1
   388 0001649E <res 00000002>      <1> csftdf_cursorpos:     resw 1
   389 000164A0 <res 00000004>      <1> csftdf_sf_drv_dt:     resd 1
   390 000164A4 <res 00000004>      <1> csftdf_df_drv_dt:     resd 1
   391                              <1> 
   392                              <1> ; 21/03/2016
   393                              <1> ; 20/03/2016
   394                              <1> ; FILE.ASM
   395 000164A8 <res 00000004>      <1> createfile_Name_Offset:  resd 1
   396 000164AC <res 00000004>      <1> createfile_FreeSectors:  resd 1 
   397 000164B0 <res 00000004>      <1> createfile_size:         resd 1
   398 000164B4 <res 00000004>      <1> createfile_FFCluster:    resd 1 ; 11/03/2016
   399 000164B8 <res 00000004>      <1> createfile_LastDirCluster: resd 1
   400 000164BC <res 00000004>      <1> createfile_Cluster:      resd 1
   401 000164C0 <res 00000004>      <1> createfile_PCluster:     resd 1
   402 000164C4 <res 00000001>      <1> createfile_attrib:	 resb 1
   403 000164C5 <res 00000001>      <1> createfile_SecPerClust:  resb 1
   404 000164C6 <res 00000002>      <1> createfile_DirIndex:     resw 1
   405 000164C8 <res 00000004>      <1> createfile_CCount:	 resd 1
   406 000164CC <res 00000002>      <1> createfile_BytesPerSec:	 resw 1 ; 23/03/2016
   407 000164CE <res 00000001>      <1> createfile_wfc:	         resb 1
   408 000164CF <res 00000001>      <1> createfile_UpdatePDir:	 resb 1 ; 31/03/2016
   409                              <1> 
   410                              <1> ;alignb 4
   411                              <1> 
   412                              <1> ; 11/04/2016
   413 000164D0 <res 00000002>      <1> env_var_length:	   resw 1
   414                              <1> 
   415 000164D2 <res 00000002>      <1> alignb 4
   416                              <1> 
   417                              <1> ; 25/04/2016
   418 000164D4 <res 00000001>      <1> readi.valid:	resb 1 ; valid data (>0 = valid for readi)
   419 000164D5 <res 00000001>      <1> readi.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   420 000164D6 <res 00000001>      <1> readi.spc:	resb 1 ; sectors per cluster for 'readi' drive
   421 000164D7 <res 00000001>      <1> readi.s_index:  resb 1 ; sector index in current cluster (buffer)
   422 000164D8 <res 00000004>      <1> readi.sector:	resd 1 ; current disk sector
   423 000164DC <res 00000002>      <1> readi.bpc:	resw 1 ; bytes per cluster - 1
   424 000164DE <res 00000002>      <1> readi.offset:	resw 1 ; byte offset in cluster buffer
   425 000164E0 <res 00000004>      <1> readi.cluster:  resd 1 ; current cluster number
   426 000164E4 <res 00000004>      <1> readi.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   427 000164E8 <res 00000004>      <1> readi.fclust:	resd 1 ; first cluster of the current cluster
   428 000164EC <res 00000004>      <1> readi.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   429                              <1> ;readi.buffer:	resd 1 ; readi sector buffer address
   430                              <1> 
   431                              <1> ;alignb 4
   432                              <1> 
   433 000164F0 <res 00000001>      <1> writei.valid:	resb 1 ; valid data (>0 = valid for writei)
   434 000164F1 <res 00000001>      <1> writei.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   435 000164F2 <res 00000001>      <1> writei.spc:	resb 1 ; sectors per cluster for 'writei' drive
   436 000164F3 <res 00000001>      <1> writei.s_index: resb 1 ; sector index in current cluster (buffer)
   437 000164F4 <res 00000004>      <1> writei.sector:	resd 1 ; current disk sector
   438 000164F8 <res 00000002>      <1> writei.bpc:	resw 1 ; bytes per cluster - 1
   439 000164FA <res 00000002>      <1> writei.offset:	resw 1 ; byte offset in cluster buffer
   440 000164FC <res 00000004>      <1> writei.cluster: resd 1 ; current cluster number
   441 00016500 <res 00000004>      <1> writei.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   442 00016504 <res 00000004>      <1> writei.fclust:  resd 1 ; first cluster of the current cluster
   443 00016508 <res 00000004>      <1> writei.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   444                              <1> ;writei.buffer:	resd 1 ; writei sector buffer address
   445 0001650C <res 00000004>      <1> writei.lclust:	resd 1 ; writei last cluster (mget_w) ; 23/10/2016
   446 00016510 <res 00000004>      <1> writei.l_index:	resd 1 ; writei last cluster index (mget_w) ; 23/10/2016
   447 00016514 <res 00000001>      <1> writei.ofn:	resb 1 ; open file number (to be written) ; 23/10/2016
   448                              <1> 
   449 00016515 <res 00000003>      <1> alignb 4
   450                              <1> 
   451                              <1> ; 29/04/2016
   452 00016518 <res 00000004>      <1> Run_CDirFC:	resd 1
   453 0001651C <res 00000001>      <1> Run_Auto_Path:	resb 1
   454 0001651D <res 00000001>      <1> Run_Manual_Path: resb 1 ; 0 -> auto path sequence needed
   455 0001651E <res 00000001>      <1> EXE_ID:		resb 1	
   456 0001651F <res 00000001>      <1> EXE_dot:	resb 1
   457                              <1> 
   458                              <1> ; 06/05/2016
   459 00016520 <res 00000004>      <1> mainprog_return_addr: resd 1
   460 00016524 <res 00000004>      <1> last_error:	resd 1  ; this will be used to return error code to MainProg
   461                              <1> 			; 'lasterror' keyword will be used later to get the
   462                              <1> 			; last error code/number/status.
   463                              <1> ; 12/05/2016
   464 00016528 <res 00000004>      <1> video_eax:	resd 1  ; eax return value of video function
   465                              <1> 
   466                              <1> ; 01/06/2016
   467 0001652C <res 00000004>      <1> user_buffer:	resd 1  ; 'diskio.s' (INT 33h, Function 08h, floppy disk type)
   468                              <1> 
   469                              <1> ; 21/05/2016 - TRDOS 386 ('swap/switch', 'rswap', [u.pri])
   470 00016530 <res 00000001>      <1> priority:	resb 1  ; running priority level of process (0,1,2)
   471                              <1> 			; (run queue which is process comes from)
   472                              <1> ; 22/05/2016 - TRDOS 386 ('set_run_sequence', 'rtc_int', 'u_timer')
   473 00016531 <res 00000001>      <1> p_change:	resb 1  ; process change status (for timer events)
   474                              <1> ; 23/05/2016 - TRDOS 386 ('clock')
   475 00016532 <res 00000001>      <1> multi_tasking:	resb 1   ; Multi Tasking status (0 = disabled, >0 = enabled)
   476                              <1> 			; (EBX will return with user buffer addr or disk type)
   477                              <1> ; 07/06/2016
   478 00016533 <res 00000001>      <1> timer_events:	resb 1  ; number of (active) timer events, <= 16		
   479                              <1> 
   480                              <1> ; 24/06/2016
   481 00016534 <res 00000001>      <1> w_str_cmd:	resb 1	; WRITE_STRING command (0,1,2,3) ; video.s
   482 00016535 <res 00000001>      <1> p_crt_mode:	resb 1  ; previous video mode (=3 or 0), backup mark/sign
   483                              <1> ; 26/06/2016
   484 00016536 <res 00000001>      <1> p_crt_page:	resb 1  ; previous active page (for 'set_mode')
   485                              <1> ; 04/07/2016
   486 00016537 <res 00000001>      <1> noclearmem:	resb 1  ; if set, 'SET MODE' (INT 31h) function (AH = 4)
   487                              <1> 			; will not clear the video memory
   488                              <1> 			; (usable for graphics modes only)
   489                              <1> alignb 2
   490 00016538 <res 00000002>      <1> CRT_LEN:	resw 1  ; length of regen buffer in bytes
   491 0001653A <res 00000010>      <1> cursor_pposn:	resw 8  ; cursor positions backup
   492                              <1> 
   493                              <1> ; 10/07/2016 ('VGA_FONT_SETUP', INT 43H address for x86 real mode bios)
   494 0001654A <res 00000004>      <1> VGA_INT43H:	resd 1	; 0 = default (not configured by user)
   495                              <1> 			; 0FFFFFFFFh = user defined fonts
   496                              <1> 			; address:
   497                              <1> 			; 	vgafont8
   498                              <1> 			; 	vgafont16
   499                              <1> 			; 	vgafont14
   500                              <1> 
   501                              <1> ; 25/07/2016
   502 0001654E <res 00000001>      <1> VGA_MTYPE:	resb 1  ; 0=CTEXT,1=MTEXT,2=CGA,3=PLANAR1,4=PLANAR4,5=LINEAR 
   503                              <1> 
   504                              <1> ; 23/10/2016
   505 0001654F <res 00000001>      <1> setfmod		resb 1	; update last modification date&time sign (if >0)
   506                              <1> 			; (it is Open File Number + 1, if > 0)
   507                              <1> alignb 4
   508                              <1> 
   509                              <1> ; 16/10/2016
   510 00016550 <res 00000004>      <1> FFF_UBuffer:	resd 1  ; User's buffer address for FFF & FNF system calls 
   511                              <1> ; 15/10/2016
   512 00016554 <res 00000001>      <1> FFF_Valid:	resb 1  ; Find First File Structure validation byte
   513                              <1> 			; 0  = invalid (Find Next File can't use FFF struct)
   514                              <1> 			; >0 = valid, return type for FFF and Find Next File
   515                              <1> 			; 24 = basic parameters, 24 bytes
   516                              <1> 			; 128 = entire FFF structure/table, 128 bytes
   517                              <1> ; 16/10/2016 (FFF_Attrib: resw 1)
   518 00016555 <res 00000001>      <1> FFF_Attrib:	resb 1	; Find First File attributes for Find Next File (LB)
   519 00016556 <res 00000001>      <1> FFF_RType:	resb 1  ; FFF return type (0 = Basic, >0 = complete) (HB)
   520                              <1> ; 16/10/2016 - 05/10/2016 (Set Working Path)
   521 00016557 <res 00000001>      <1> SWP_inv_fname:	resb 1	; Set Working Path - Invalid File Name
   522 00016558 <res 00000002>      <1> SWP_Mode:	resw 1	; Set Working Path - Mode
   523 0001655A <res 00000001>      <1> SWP_DRV:	resb 1	; Set Working Path - Drive	
   524 0001655B <res 00000001>      <1> SWP_DRV_chg:	resb 1	; Set Working Path - Drive Change
   525                              <1> 
   526                              <1> ; 27/02/2017
   527 0001655C <res 00000001>      <1> fpready:	resb 1	; '80387 fpu is ready' flag	
   528                              <1> 
   529                              <1> ; 08/10/2016
   530 0001655D <res 00000009>      <1> device_name:    resb 9  ; capitalized (and zero padded) device canem 
   531                              <1> 			; (example: "TTY0",0,0,0,0,0")
   532                              <1> 
   533 00016566 <res 00000002>      <1> alignb 4
   534                              <1> 
   535                              <1> ; 08/10/2016
   536                              <1> ; 07/10/2016
   537                              <1> ; Table of kernel devices (which do not use installable device drivers)
   538                              <1> ; has been coded into KERNEL (trdosk9.s) 
   539                              <1> ; 07/10/2016
   540                              <1> ; 8 installable device drivers available to install (NUMIDEV)
   541 00016568 <res 00000020>      <1> IDEV_PGDIR: resd NUMIDEV
   542                              <1> 			; Page directories of installable device drivers
   543                              <1> 			;
   544                              <1> 			; Note: Virtual start address is always 400000h
   545                              <1> 			; (end of the 1st 4MB). [org 400000h]
   546                              <1> 			; Segments: KCODE, KDATA
   547                              <1> 			; Method: call 400000h (after changing page dir) 	
   548                              <1> 			; Query code located at the start (400000h).
   549                              <1> 			; Query code returns with
   550                              <1> 			;   eax = device type and driver version
   551                              <1> 			;         AL = Device Type minor
   552                              <1> 			;         AH = Device Type major
   553                              <1> 			;         Byte 16-23 : Version minor
   554                              <1> 			;	  Byte 24-31 : Version major - 1
   555                              <1> 			;		       (0:0 -> 1.0)
   556                              <1> 			;   ebx = initialization code address
   557                              <1> 			;   ecx = configuration table address
   558                              <1> 			;   edx = description table address
   559                              <1> 			;   esi = device (default) name address (ASCIIZ)
   560                              <1> 			;	 (name has "/DEV/" prefix)		
   561                              <1> 			;   edi = dispatch table address
   562                              <1> 			;        (for calling kernel-device functions)
   563                              <1> 			;   ebp = address table address
   564                              <1> 			; Initialization code returns with
   565                              <1> 			;   eax = open code address
   566                              <1> 			;   ecx = close code address 
   567                              <1> 			;   ebx = read code address
   568                              <1> 			;   edx = write code address 	
   569                              <1> 			;   esi = IOCTL code address
   570                              <1> 			;   edi = dispatch table address
   571                              <1> 			;   ebp = address table address
   572                              <1> 			; Address Table:
   573                              <1> 			;    Offset 0  : open code address
   574                              <1> 			;    Offset 4  : read code address
   575                              <1> 			;    Offset 8  : write code address
   576                              <1> 			;    Offset 12 : close code address
   577                              <1> 			;    Offset 16 : IOCTL code address
   578                              <1> 			;    Offset 20 : initialization code address
   579                              <1> 			;    Offset 24 : description table address
   580                              <1> 			;    Offset 28 : configuration table address
   581                              <1> 			;    Offset 32 : device name address
   582                              <1> 			;    Offset 36 : dispatch table address
   583                              <1> 			;          (for calling kernel-device functions)
   584                              <1> 
   585 00016588 <res 00000040>      <1> IDEV_NAME:  resb 8*NUMIDEV 
   586                              <1> 			; 8 byte names of installable device drivers
   587                              <1> 
   588 000165C8 <res 00000008>      <1> IDEV_TYPE:  resb NUMIDEV ; Driver type of installable device drivers
   589 000165D0 <res 00000008>      <1> IDEV_FLAGS: resb NUMIDEV ; Device access parameters for installable
   590                              <1>                          ; device drivers (These values are set while
   591                              <1> 			 ; the device driver is being loaded.)
   592 000165D8 <res 00000020>      <1> IDEV_OADDR: resd NUMIDEV ; open function addr for installable dev driver
   593 000165F8 <res 00000020>      <1> IDEV_CADDR: resd NUMIDEV ; close function addr for installable dev driver
   594 00016618 <res 00000020>      <1> IDEV_RADDR: resd NUMIDEV ; read function addr for installable dev driver
   595 00016638 <res 00000020>      <1> IDEV_WADDR: resd NUMIDEV ; write function addr for installable dev driver
   596                              <1> 	
   597                              <1> ; 08/10/2016	
   598                              <1> ; 07/10/2016
   599                              <1> ; Device Open and Access parameters
   600 00016658 <res 0000001E>      <1> DEV_ACCESS:	 resb NUMOFDEVICES   ; bit 0 = accessable by normal users
   601                              <1> 				     ; bit 1 = read access permission
   602                              <1> 				     ; bit 2 = write access permission
   603                              <1> 				     ; bit 3 = IOCTL permission to users
   604                              <1> 				     ; bit 4 = block device if it is set	
   605                              <1> 				     ; bit 5 = 16 bit or 1024 byte data
   606                              <1> 				     ; bit 6 = 32 bit or 2048 byte data
   607                              <1> 				     ; bit 7 = installable device driver
   608 00016676 <res 0000001E>      <1> DEV_R_OWNER:	 resb NUMOFDEVICES   ; Reading owner no (u.uid) of devices		
   609 00016694 <res 0000001E>      <1> DEV_R_OPENCOUNT: resb NUMOFDEVICES   ; Reading open count 
   610 000166B2 <res 0000001E>      <1> DEV_W_OWNER:	 resb NUMOFDEVICES   ; Writing owner no (u.uid) of devices		
   611 000166D0 <res 0000001E>      <1> DEV_W_OPENCOUNT: resb NUMOFDEVICES   ; Writing open count
   612 000166EE <res 0000001E>      <1> DEV_DRIVER:	 resb NUMOFDEVICES   ; device driver number (1 to 7Fh)
   613                              <1> 				     ; *if bit 7 is set (80 to FFh)
   614                              <1> 				     ; *if it is installable device driver
   615                              <1> 				     ; *index (0 to 7Fh)
   616                              <1> 				     ; otherwise it is kernel device index
   617 0001670C <res 0000001E>      <1> DEV_OPENMODE:	 resb NUMOFDEVICES   ; 1 = read mode
   618                              <1> 				     ; 2 = write mode
   619                              <1> 				     ; 3 = read & write 	  
   620                              <1> 				     ; 0 = not open (free)		
   621 0001672A <res 00000078>      <1> DEV_NAME_PTR:    resd NUMOFDEVICES   ; pointers to name addresses of drivers
   622                              <1> 				     ; Address base: KDEV_NAME+		
   623                              <1> 				     ; or IDEV_NAME+
   624 000167A2 <res 00000078>      <1> DEV_R_POINTER:	 resd NUMOFDEVICES   ; reading pointer, writing pointer	
   625 0001681A <res 00000078>      <1> DEV_W_POINTER:	 resd NUMOFDEVICES   ; sector number if block device
   626                              <1> 				     ; character offset if char device
   627 00016892 <res 00000002>      <1> alignb 4
   628                              <1> 
   629                              <1> ; 06/10/2016
   630                              <1> ; Open File Parameters
   631 00016894 <res 00000028>      <1> OF_FCLUSTER:	resd OPENFILES  ; First clusters of open files
   632 000168BC <res 0000000A>      <1> OF_DRIVE:	resb OPENFILES  ; Logical DOS drive numbers of open files 
   633 000168C6 <res 0000000A>      <1> OF_MODE:	resb OPENFILES  ; Open mode (1 = read, 2 = write, 3 = r&w) 
   634 000168D0 <res 0000000A>      <1> OF_STATUS:	resb OPENFILES  ; (bit 0 = read, bit 1 = write)
   635 000168DA <res 0000000A>      <1> OF_OPENCOUNT:	resb OPENFILES  ; Open counts of open files
   636 000168E4 <res 00000028>      <1> OF_POINTER:	resd OPENFILES	; File seek/read/write pointer
   637 0001690C <res 00000028>      <1> OF_SIZE:	resd OPENFILES	; File sizes of open files (in bytes)
   638 00016934 <res 00000028>      <1> OF_DIRFCLUSTER:	resd OPENFILES  ; Directory First Clusters of open files
   639 0001695C <res 00000028>      <1> OF_DIRCLUSTER:	resd OPENFILES  ; Directory (Entry) Clusters of open files
   640 00016984 <res 00000028>      <1> OF_VOLUMEID:	resd OPENFILES  ; Vol ID for removable drives of open files
   641 000169AC <res 00000028>      <1> OF_CCLUSTER:	resd OPENFILES  ; Current clusters of open files
   642 000169D4 <res 00000028>      <1> OF_CCINDEX:	resd OPENFILES  ; Cluster index numbers of current clusters
   643                              <1> ; 24/10/2016
   644 000169FC <res 00000014>      <1> OF_DIRENTRY:	resw OPENFILES  ; Directory entry index no. in dir cluster 
   645                              <1> 				; Sector index = entry index / 16
   646                              <1> ;alignb 2
   647                              <1> 
   648 00016A10 <res 00000060>      <1> DTA:		resd 24		; Find First File data transfer area
   649                              <1> 
   650                              <1> ; 19/12/2016
   651 00016A70 <res 00000001>      <1> tcallback:	resb 1		; Timer callback method flag for 'systimer'
   652 00016A71 <res 00000001>      <1> trtc:		resb 1		; Timer interrupt type flag for 'systimer'
   653                              <1> ; 20/02/2017
   654 00016A72 <res 00000001>      <1> no_page_swap:	resb 1		; Swap lock for Signal Response Byte pages 
   655                              <1> ;;15/01/2017
   656                              <1> ; 02/01/2017
   657                              <1> ;;intflg:	resb 1		; software interrupt in progress signal
   658                              <1> 				; (for timer interrupt)
   659                              <1> 
   660 00016A73 <res 00000001>      <1> alignb 4
   661                              <1> ; 13/04/2017
   662 00016A74 <res 0000001E>      <1> DEV_INTR:	resb NUMOFDEVICES ; Device Interrupt (IRQ) number + 1	
   663                              <1> 				; (0= not available, 1= IRQ 0, 16= IRQ 15)
   664 00016A92 <res 00000040>      <1> DEV_INT_HNDLR:	resd 16		; Device Interrupt Handler addr, if > 0 	
   665                              <1> 
   666                              <1> 
   667                              <1> ;alignb 4
   668                              <1> 
   669                              <1> ; 26/02/2017 ; IRQ Callback parameters ('syscalbac')
   670                              <1> ;Index: ; 0 to 8
   671                              <1> ;	0 = IRQ3, 1 = IRQ4, 2 = IRQ5, 3 = IRQ7
   672                              <1> ;	4 = IRQ9, 5 = IRQ10, 6 = IRQ11, 7 = IRQ12, 8 = IRQ13  
   673 00016AD2 <res 00000009>      <1> IRQ.owner:	resb 9		; owner, 0 = free, >0 = [u.uno]
   674 00016ADB <res 00000009>      <1> IRQ.dev:	resb 9		; 0 = default/kernel, >0 = device number
   675 00016AE4 <res 00000009>      <1> IRQ.method:	resb 9 		; 0 = Signal Response Byte, 1 = Callback
   676 00016AED <res 00000009>      <1> IRQ.srb:	resb 9 		; Signal Response/Return Byte value
   677 00016AF6 <res 00000024>      <1> IRQ.addr:	resd 9		; Rignal Response Byte address (physical)
   678                              <1> 				; or Callback service address (virtual)
   679                              <1> ; 28/02/2017
   680 00016B1A <res 00000004>      <1> IRQ_cr3:	resd 1		; for saving cr3 register in IRQ handler
   681 00016B1E <res 00000001>      <1> IRQnum:		resb 1		; IRQ number for IRQ handler (trdosk8.s)
   682                              <1> 
   683                              <1> ; 10/04/2017
   684                              <1> ; 03/04/2017
   685                              <1> ; UNINITIALIZED AUDIO DATA
   686 00016B1F <res 00000001>      <1> alignb 4
   687 00016B20 <res 00000001>      <1> audio_pci:	resb 1
   688 00016B21 <res 00000001>      <1> audio_device:	resb 1
   689 00016B22 <res 00000001>      <1> audio_mode:	resb 1
   690 00016B23 <res 00000001>      <1> audio_intr:	resb 1
   691 00016B24 <res 00000001>      <1> audio_busy:	resb 1  ; Busy flag for audio irq ; 21/04/2017
   692 00016B25 <res 00000001>      <1> audio_reserved: resb 1
   693 00016B26 <res 00000002>      <1> audio_io_base:	resw 1 	; Base I/O address of audio device
   694 00016B28 <res 00000004>      <1> audio_dev_id:	resd 1	; BUS/DEV/FN ; 00000000BBBBBBBBDDDDDFFF00000000
   695 00016B2C <res 00000004>      <1> audio_vendor:	resd 1
   696 00016B30 <res 00000004>      <1> audio_stats_cmd: resd 1
   697                              <1> ;
   698 00016B34 <res 00000004>      <1> audio_buffer:	resd 1	; virtual address of user's audio buffer
   699 00016B38 <res 00000004>      <1> audio_p_buffer:	resd 1	; Physical address of user's audio buffer
   700 00016B3C <res 00000004>      <1> audio_buff_size: resd 1 ; user's audio buffer size (half buffer size) 
   701 00016B40 <res 00000004>      <1> audio_dma_buff: resd 1  ; dma buffer address
   702 00016B44 <res 00000004>      <1> audio_dmabuff_size: resd 1 ; dma buffer size (2 * half buffer size)
   703 00016B48 <res 00000001>      <1> audio_flag:	resb 1  ; dma buffer flag (1st half = 0, 2nd half = 1)
   704 00016B49 <res 00000001>      <1> audio_user:	resb 1	; user number of the owner
   705 00016B4A <res 00000001>      <1> audio_cb_mode:	resb 1	; 0 = signal response byte method
   706                              <1> 			; 1 = callback method
   707                              <1> 			; 2 = s.r.b. method with auto increment
   708 00016B4B <res 00000001>      <1> audio_srb:	resb 1	; signal response byte value
   709 00016B4C <res 00000004>      <1> audio_cb_addr:	resd 1  ; callback service address or s.r.b. address
   710                              <1> 			; (s.r.b. addr is physical, cbs addr is virtual)
   711                              <1> 
   712 00016B50 <res 00000001>      <1> audio_bps:	resb 1  ; selected mode: 8 bit, 16 bit
   713 00016B51 <res 00000001>      <1> audio_stmo:	resb 1	; selected mode: mono /stereo
   714 00016B52 <res 00000002>      <1> audio_freq: 	resw 1	; sampling rate
   715                              <1> 
   716                              <1> ; 21/04/2017
   717 00016B54 <res 00000001>      <1> audio_play_cmd: resb 1  ; Play/Stop command (1 = play, 0 = stop)
   718                              <1> audio_civ: ; 28/05/2017 ; Current Buffer Index (AC'97)
   719 00016B55 <res 00000001>      <1> audio_flag_eol:	resb 1  ; End of Link status (vt8233, EOL/FLAG)
   720                              <1> 
   721                              <1> audio_master_volume:
   722 00016B56 <res 00000001>      <1> audio_master_volume_l: resb 1 ; sound volume (lineout) left channel
   723 00016B57 <res 00000001>      <1> audio_master_volume_r: resb 1 ; sound volume (lineout) right channel
   724                              <1> 
   725                              <1> alignb 4
   726                              <1> ; 28/05/2017
   727                              <1> ; AC'97 Audio Controller Base Adress Registers
   728 00016B58 <res 00000002>      <1> NAMBAR:		resw 1	; Native Audio Mixer Base Address
   729 00016B5A <res 00000002>      <1> NABMBAR:	resw 1	; Native Audio Bus Mastering Base Address
   730                              <1> 	
   731                              <1> ;alignb 4
   732                              <1> ; 21/04/2017
   733 00016B5C <res 00000400>      <1> audio_bdl_buff:	resd 32*8  ; VT8233 (AC97) BDL Buffer Size
   734                              <1> ; 12/05/2017
   735 00016F5C <res 00000004>      <1> base_addr:	resd 1	; 'direct_memory_access' (memory.s)
   736                              <1> 
   737                              <1> ; 28/08/2017
   738                              <1> ; 20/08/2017
   739 00016F60 <res 00000001>      <1> 		resb 1  ;
   740 00016F61 <res 00000001>      <1> dma_user:	resb 1	; user number for sysdma
   741 00016F62 <res 00000001>      <1> dma_channel:	resb 1	; dma channel for sysdma
   742 00016F63 <res 00000001>      <1> dma_mode:	resb 1  ; dma mode for sysdma	
   743 00016F64 <res 00000004>      <1> dma_addr:	resd 1	; dma buffer physical addr for sysdma
   744 00016F68 <res 00000004>      <1> dma_size:	resd 1  ; dma buffer size (in bytes) for sysdma
   745 00016F6C <res 00000004>      <1> dma_start:	resd 1  ; dma start address for sysdma
   746 00016F70 <res 00000004>      <1> dma_count:	resd 1  ; dma count (in bytes) for sysdma 
   747                              <1> 
   748 00016F74 <res 0000908C>      <1> alignb 65536
   749                              <1> ; 09/08/2017
   750                              <1> ; 12/05/2017
   751 00020000 <res 00010000>      <1> sb16_dma_buffer: resb 65536 ; DMA buffer for sb16 audio playing.
  2830                                  ; 24/01/2016
  2831                                  %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: 28/02/2017
     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                              <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 00030000 <res 00000002>      <1> 	i.flgs:	 resw 1
    37 00030002 <res 00000001>      <1> 	i.nlks:	 resb 1
    38 00030003 <res 00000001>      <1> 	i.uid:	 resb 1
    39                              <1>         ;i.size:  resw 1 ; size
    40 00030004 <res 00000002>      <1> 	resw 1 ; 29/04/2016
    41 00030006 <res 00000010>      <1> 	i.dskp:	 resw 8 ; 16 bytes
    42 00030016 <res 00000004>      <1> 	i.ctim:	 resd 1
    43 0003001A <res 00000004>      <1> 	i.mtim:	 resd 1
    44 0003001E <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> 	; 19/12/2016
    50                              <1> 	; 21/05/2016
    51                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    52                              <1> 	; 06/05/2015 - Retro UNIX 386 v1
    53                              <1> 	; 11/03/2013 - 05/02/2014 (Retro UNIX 8086 v1)
    54                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
    55                              <1> 	;p.
    56                              <1> 	
    57 00030020 <res 00000020>      <1>         p.pid:   resw nproc
    58 00030040 <res 00000020>      <1>         p.ppid:  resw nproc
    59 00030060 <res 00000020>      <1>         p.break: resw nproc
    60 00030080 <res 00000010>      <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
    61 00030090 <res 00000010>      <1> 	p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
    62 000300A0 <res 00000010>      <1> 	p.link:	 resb nproc
    63 000300B0 <res 00000010>      <1> 	p.stat:	 resb nproc
    64                              <1> 
    65                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 feature only !) 
    66 000300C0 <res 00000040>      <1> 	p.upage: resd nproc ; Physical address of the process's
    67                              <1> 			    ; 'user' structure
    68                              <1> 	; 21/05/2016	
    69                              <1> 	; 19/05/2016 (TRDOS 386 feature only!)
    70 00030100 <res 00000010>      <1> 	p.timer: resb nproc ; number of timer events of the processs
    71                              <1> 
    72                              <1> 	; 19/12/2016
    73 00030110 <res 00000040>      <1> 	p.tcb:	resd nproc ; timer callback service address (if > 0)
    74                              <1> 			  		 			 	  
    75                              <1> P_SIZE	equ $ - process
    76                              <1> 
    77                              <1> ; fsp table (original UNIX v1)
    78                              <1> ;
    79                              <1> ;Entry
    80                              <1> ;          15                                      0
    81                              <1> ;  1     |---|---------------------------------------|
    82                              <1> ;        |r/w|       i-number of open file           |
    83                              <1> ;        |---|---------------------------------------| 
    84                              <1> ;        |               device number               |
    85                              <1> ;        |-------------------------------------------|
    86                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
    87                              <1> ;        |-------------------------------------------| 
    88                              <1> ;        |  flag that says    | number of processes  |
    89                              <1> ;        |   file deleted     | that have file open  |
    90                              <1> ;        |-------------------------------------------| 
    91                              <1> ;  2     |                                           |
    92                              <1> ;        |-------------------------------------------| 
    93                              <1> ;        |                                           |
    94                              <1> ;        |-------------------------------------------|
    95                              <1> ;        |                                           |
    96                              <1> ;        |-------------------------------------------|
    97                              <1> ;        |                                           |
    98                              <1> ;        |-------------------------------------------| 
    99                              <1> ;  3     |                                           | 
   100                              <1> ;        |                                           |  
   101                              <1> ;
   102                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer 
   103                              <1> 
   104                              <1> 
   105                              <1> ; 15/04/2015
   106 00030150 <res 000001F4>      <1> fsp:	 resb nfiles * 10 ; 11/05/2015 (8 -> 10)
   107 00030344 <res 00000002>      <1> idev:	 resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   108 00030346 <res 00000002>      <1> cdev:    resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   109                              <1> ; 18/05/2015
   110                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
   111                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
   112                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
   113                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
   114                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
   115                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
   116                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
   117                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
   118                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
   119                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
   120                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
   121 00030348 <res 00000001>      <1> rdev:	 resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
   122                              <1> 	        ; as above, for physical drives numbers in following table
   123 00030349 <res 00000001>      <1> mdev:	 resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
   124                              <1> ; 15/04/2015
   125 0003034A <res 00000001>      <1> active:	 resb 1 
   126 0003034B <res 00000001>      <1> 	 resb 1 ; 09/06/2015
   127 0003034C <res 00000002>      <1> mnti:	 resw 1
   128 0003034E <res 00000002>      <1> mpid:	 resw 1
   129 00030350 <res 00000002>      <1> rootdir: resw 1
   130                              <1> 
   131                              <1> ; 21/05/2016 - TRDOS 386 (TRDOS v2.0) - priority levels, 3 run queues 
   132                              <1> runq:
   133 00030352 <res 00000002>      <1> runq_event:	 resw 1 ; high priority, 'run for event'            ; 2
   134 00030354 <res 00000002>      <1> runq_normal:	 resw 1 ; normal/regular priority, 'run as reqular' ; 1
   135 00030356 <res 00000002>      <1> runq_background: resw 1 ; low priority, 'run on background'         ; 0
   136                              <1> ;
   137 00030358 <res 00000001>      <1> imod:	 resb 1
   138 00030359 <res 00000001>      <1> smod:	 resb 1
   139 0003035A <res 00000001>      <1> mmod:	 resb 1
   140 0003035B <res 00000001>      <1> sysflg:	 resb 1
   141                              <1> 
   142                              <1> alignb 4
   143                              <1> 
   144                              <1> user:
   145                              <1> 	; 13/01/2017
   146                              <1> 	; 19/12/2016
   147                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0) 
   148                              <1> 	; 	       [u.pri] usage method modification
   149                              <1> 	; 04/12/2015 
   150                              <1> 	; 18/10/2015
   151                              <1> 	; 12/10/2015
   152                              <1> 	; 21/09/2015
   153                              <1> 	; 24/07/2015
   154                              <1> 	; 16/06/2015
   155                              <1> 	; 09/06/2015
   156                              <1> 	; 11/05/2015
   157                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
   158                              <1> 	; 10/10/2013
   159                              <1> 	; 11/03/2013. 
   160                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
   161                              <1> 	;u.
   162                              <1> 
   163 0003035C <res 00000004>      <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
   164 00030360 <res 00000004>      <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
   165 00030364 <res 00000004>      <1> 	u.r0:	  resd 1 ; eax
   166 00030368 <res 00000002>      <1> 	u.cdir:	  resw 1
   167 0003036A <res 0000000A>      <1> 	u.fp:	  resb 10
   168 00030374 <res 00000004>      <1> 	u.fofp:	  resd 1
   169 00030378 <res 00000004>      <1> 	u.dirp:	  resd 1
   170 0003037C <res 00000004>      <1> 	u.namep:  resd 1
   171 00030380 <res 00000004>      <1> 	u.off:	  resd 1
   172 00030384 <res 00000004>      <1> 	u.base:	  resd 1
   173 00030388 <res 00000004>      <1> 	u.count:  resd 1
   174 0003038C <res 00000004>      <1> 	u.nread:  resd 1
   175 00030390 <res 00000004>      <1> 	u.break:  resd 1 ; break
   176 00030394 <res 00000002>      <1> 	u.ttyp:	  resw 1 
   177                              <1> 	; 10/01/2017 (TRDOS 386, relocation and dword alignment)
   178                              <1> 	; tty number (rtty, rcvt, wtty)
   179 00030396 <res 00000001>      <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
   180 00030397 <res 00000001>      <1> 	u.resb:   resb 1 ; 10/01/2017 (TRDOS 386, temporary)
   181 00030398 <res 00000010>      <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16) 
   182                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
   183 000303A8 <res 00000001>      <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
   184 000303A9 <res 00000001>      <1> 	u.pri:	  resb 1 ; Modification: 21/05/2016 (priority levels: 0, 1, 2)
   185 000303AA <res 00000002>      <1> 	u.intr:	  resw 1
   186 000303AC <res 00000002>      <1> 	u.quit:	  resw 1
   187                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
   188                              <1> 	;u.ilgins: resw 1 ; 10/01/2017
   189 000303AE <res 00000002>      <1> 	u.cdrv:	  resw 1 ; cdev
   190 000303B0 <res 00000001>      <1> 	u.uid:	  resb 1 ; uid
   191 000303B1 <res 00000001>      <1> 	u.ruid:	  resb 1
   192 000303B2 <res 00000001>      <1> 	u.bsys:	  resb 1
   193 000303B3 <res 00000001>      <1> 	u.uno:	  resb 1
   194 000303B4 <res 00000004>      <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
   195 000303B8 <res 00000004>      <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
   196 000303BC <res 00000004>      <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
   197 000303C0 <res 00000004>      <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
   198 000303C4 <res 00000002>      <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
   199                              <1> 	;u.pncount: resw 1 
   200                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
   201                              <1> 	;u.pnbase:  resd 1 
   202                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
   203                              <1> 			 ; 09/06/2015
   204 000303C6 <res 00000001>      <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign		
   205 000303C7 <res 00000001>      <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
   206                              <1> 			 ; 24/07/2015 - 24/06/2015
   207                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
   208                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
   209                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
   210                              <1>  			 ; 24/06/2015	  	
   211                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
   212                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
   213                              <1> 	; last error number
   214 000303C8 <res 00000004>      <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
   215                              <1> 		        ; Retro UNIX 8086/386 v1 feature only!
   216                              <1> 			; 21/09/2015 (debugging - page fault analyze)
   217 000303CC <res 00000004>      <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
   218                              <1> 		; 19/12/2016 (TRDOS 386)	
   219 000303D0 <res 00000004>      <1> 	u.tcb:	  resd 1 ; Timer callback address/flag which will be used by timer int
   220                              <1> 		; 13/01/2017 (TRDOS 386)
   221 000303D4 <res 00000001>      <1> 	u.t_lock: resb 1 ; Timer interrupt (callback) lock (unlocked by 'sysrele')
   222 000303D5 <res 00000001>      <1> 	u.t_mode: resb 1 ; running mode during timer interrupt (0= system, 0FFh= user)
   223                              <1> 		; 26/02/2017 (TRDOS 386)
   224 000303D6 <res 00000001>      <1> 	u.irqc:	  resb 1  ; Count of IRQ callback services (IRQs in use)
   225                              <1> 		; 28/02/2017 (TRDOS 386) 
   226 000303D7 <res 00000001>      <1> 	u.irqwait: resb 1 ; IRQ waiting for callback service flag (IRQ number, If > 0)
   227 000303D8 <res 00000001>      <1> 	u.r_lock:  resb 1 ; 'IRQ callback service is in progress' flag (IRQ lock)
   228 000303D9 <res 00000001>      <1> 	u.r_mode:  resb 1 ; running mode during hadware interrupt	
   229                              <1> 		; 27/02/2017 (TRDOS 386) 
   230 000303DA <res 00000001>      <1> 	u.fpsave: resb 1  ; TRDOS 386, 'save/restore FPU registers' flag
   231 000303DB <res 00000001>      <1> alignb 4
   232 000303DC <res 0000005E>      <1> 	u.fpregs: resb 94 ; 94 byte area for saving and restoring FPU registers	
   233                              <1> 
   234 0003043A <res 00000002>      <1> alignb 4
   235                              <1> 
   236                              <1> U_SIZE	equ $ - user
   237                              <1> 
   238                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
   239 0003043C <res 00000004>      <1> pcore:  resd 1  ; physical start address of user's memory space (for sys exec)
   240 00030440 <res 00000004>      <1> ecore:  resd 1  ; physical address of user's stack/last page (for sys exec)
   241 00030444 <res 00000004>      <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
   242 00030448 <res 00000002>      <1> ncount: resw 1	; remain byte count in page for 'namei' & 'sysexec'
   243 0003044A <res 00000002>      <1> argc:	resw 1	; argument count for 'sysexec'
   244 0003044C <res 00000004>      <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
   245                              <1> 
   246                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
   247                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
   248 00030450 <res 00000001>      <1> rw: 	 resb 1 ;; Read/Write sign (iget)
   249                              <1> 
   250                              <1> ;alignb 4
   251                              <1> 
   252                              <1> ; 24/04/2016
   253 00030451 <res 00000004>      <1> ii:		resd 1 ; first cluster of the program file
   254 00030455 <res 00000004>      <1> i.size:		resd 1 ; size of the program file
  2832                                  
  2833 00030459 <res 00000003>          alignb 4
  2834                                  
  2835                                  ; 23/05/2016 (TRDOS 386)
  2836                                  ; 14/10/2015 (Retro UNIX 386 v1, 'unix386.s')
  2837 0003045C <res 00000004>          cr3reg:	 resd 1  ; cr3 register content at the beginning of the timer
  2838                                  		 ; (or RTC) interrupt handler.
  2839                                  
  2840                                  ; 10/12/2016 (callback)
  2841                                  ; 10/06/2016
  2842                                  ; 19/05/2016
  2843                                  ; 18/05/2016 - TRDOS 386 feature only !
  2844 00030460 <res 00000100>          timer_set: resd 16*4   ; 256 bytes memory space for 16 timer events
  2845                                  	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  2846                                  	;       Owner:	        resb 1 ; 0 = free
  2847                                  	;		  	       ;>0 = process number (u.uno)
  2848                                  	;	Callback:	resb 1 ; 0 = response byte address (phy)
  2849                                  	;				 1 = callback address (virtual)				
  2850                                  	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  2851                                  	;		   	       ; 1 = Real Time Clock interrupt 
  2852                                  	;	Response:       resb 1 ; 0 to 255, signal return value
  2853                                  	;	Count Limit:	resd 1 ; count of ticks (total/set)
  2854                                  	;	Current Count: 	resd 1 ; count of ticks (current)
  2855                                  	;	Response Addr:  resd 1 ; response byte (pointer) address
  2856                                  	;			       ; (or callback -user service- address)	
  2857                                  
  2858                                  ;; Memory (swap) Data (11/03/2015)
  2859                                  ; 09/03/2015
  2860 00030560 <res 00000002>          swpq_count: resw 1 ; count of pages on the swap queue
  2861 00030562 <res 00000004>          swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
  2862 00030566 <res 00000004>          swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  2863 0003056A <res 00000004>          swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  2864 0003056E <res 00000004>          swpd_next:  resd 1 ; next free page block
  2865 00030572 <res 00000004>          swpd_last:  resd 1 ; last swap page block	
  2866                                  
  2867 00030576 <res 00000002>          alignb 4
  2868                                  
  2869                                  ; 10/07/2015
  2870                                  ; 28/08/2014
  2871 00030578 <res 00000004>          error_code:	resd 1
  2872                                  ; 29/08/2014
  2873 0003057C <res 00000004>          FaultOffset: 	resd 1
  2874                                  ; 21/09/2015
  2875 00030580 <res 00000004>          PF_Count:	resd 1	; total page fault count
  2876                                  		       	; (for debugging - page fault analyze)
  2877                                  		 	; 'page_fault_handler' (memory.inc)
  2878                                  			; 'sysgeterr' (u9.s)
  2879                                  
  2880                                  ; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  2881                                  ; 22/08/2015 (Retro UNIX 386 v1)
  2882                                  buffer: 
  2883 00030584 <res 00000008>          	resb	8 
  2884                                  readi_buffer:
  2885 0003058C <res 00000200>          	resb 	512
  2886 0003078C <res 00000008>          	resb	8
  2887                                  writei_buffer:
  2888 00030794 <res 00000200>          	resb	512	
  2889                                  ; 24/10/2016
  2890 00030994 <res 00000008>          	resb	8 
  2891                                  rw_buffer:
  2892 0003099C <res 00000800>          	resb 	2048  ; general purposed, r/w sector buffer
  2893                                  
  2894                                  bss_end:
  2895                                  
  2896                                  ; 27/12/2013
  2897                                  _end:  ; end of kernel code
